Hash :
94046104
Author :
Thomas de Grivel
Date :
2020-02-24T15:19:27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
/*
This is part of Patchwork13! the real-time data synthesis toolkit.
http://patchwork13.sourceforge.net/
pw13 - the patchwork13 core library
Copyright (C) 2005 Thomas de Grivel <billitch@yahoo.fr>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
input.c - data input
*/
#include <stdlib.h> /* malloc */
#include "patch.h"
#include "output.h"
#include "input.h"
#include "any.h"
#include "error.h"
/* initialize an allocated input */
void
pw13_input_init (const char *name, Pw13_Input *input, Pw13_Patch *patch,
Pw13_DataType *data_type, Pw13_Data *defval)
{
input->name = name;
input->patch = patch;
input->data_type = data_type;
input->from = NULL;
input->defval = defval;
input->custom_data = NULL;
}
/* destruct an input, without freeing it */
void
pw13_input_destroy (Pw13_Input *input)
{
if (input && input->from)
pw13_disconnect (input);
}
/* return the value of an input */
Pw13_Data * pw13_input_val (Pw13_Input *i)
{
if (i->from)
return i->from->data;
return i->defval;
}
int pw13_can_connect (Pw13_Output *from, Pw13_Input *to)
{
if (!from) {
pw13_error ("pw13_connect: NULL output");
return 0;
}
if (!to) {
pw13_error ("pw13_connect: NULL input");
return 0;
}
if (from->data_type != to->data_type
&& from->data_type->name[0] != '\''
&& to->data_type->name[0] != '\'') {
pw13_error ("pw13_connect: incompatible data types");
return 0;
}
if (to->from == from) {
pw13_error ("pw13_connect: already connected");
return 0;
}
return 1;
}
/* connect an output to an input */
Pw13_Result
pw13_connect (Pw13_Output *from, Pw13_Input *to)
{
Pw13_Output *old_from;
if ((old_from = to->from))
pw13_list_remove_one (&old_from->connected_to, to);
to->from = from;
from->connected_to = pw13_list (to, from->connected_to);
return PW13_SUCCESS;
}
/* disconnect an input */
Pw13_Result
pw13_disconnect (Pw13_Input *B)
{
Pw13_Output *A;
if (!B)
return pw13_error ("pw13_disconnect: NULL input");
A = B->from;
if (pw13_list_remove_one (& A->connected_to, (void*) B) != PW13_SUCCESS)
pw13_fatal_error ("pw13_disconnect: list_remove_one");
B->from = NULL;
return PW13_SUCCESS;
}
/* pump an input if it is connected */
int pw13_pump_input(Pw13_Input *i, Pw13_Time *t)
{
if (i->from) {
pw13_patch_pump(i->from->patch, t);
return 1;
}
return 0;
}
/* force pump an input if it is connected */
int pw13_force_pump_input(Pw13_Input *i, Pw13_Time *t)
{
if (i->from) {
pw13_patch_force_pump(i->from->patch, t);
return 1;
}
return 0;
}
void
pw13_input_print_infos (Pw13_Input *i)
{
printf ("input %p\n", i);
if (i) {
printf (" name \"%s\"\n"
" from %p\n"
" custom data %p\n",
i->name,
i->from,
i->custom_data);
}
printf ("/input\n\n");
}