1 /* gAlan - Graphical Audio Language
2 * Copyright (C) 1999 Tony Garnock-Jones
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "generator.h"
37 SAMPLETIME location
[POLYPHONY
];
41 #define LOCATION(g) ((SAMPLETIME) ((g)->data))
43 PRIVATE gboolean
init_instance(Generator
*g
) {
44 Data
*data
= safe_malloc(sizeof(Data
));
46 data
->num_playing
= 0;
47 /* location[] doesn't need initialising because num_playing is zero. */
53 PRIVATE
void done_instance(Generator
*g
) {
57 PRIVATE gboolean
output_generator(Generator
*g
, SAMPLE
*buf
, int buflen
) {
59 SAMPLE tmpbuf
[MAXIMUM_REALTIME_STEP
];
63 if (data
->num_playing
== 0)
66 memset(buf
, 0, sizeof(SAMPLE
) * buflen
);
67 range
= gen_get_randomaccess_input_range(g
, 0, 0);
70 while (i
< data
->num_playing
) {
71 if (gen_read_randomaccess_input(g
, 0, 0, data
->location
[i
], tmpbuf
, buflen
)) {
73 for (j
= 0; j
< buflen
; j
++)
77 data
->location
[i
] += buflen
;
79 if (data
->location
[i
] >= range
) {
81 data
->location
[i
] = data
->location
[data
->num_playing
];
90 PRIVATE
void evt_reset_handler(Generator
*g
, AEvent
*event
) {
93 if (data
->num_playing
>= POLYPHONY
) {
96 for (i
= 0; i
< POLYPHONY
- 1; i
++) {
97 data
->location
[i
] = data
->location
[i
+1];
100 data
->location
[POLYPHONY
- 1] = 0;
102 data
->location
[data
->num_playing
++] = 0;
106 PRIVATE InputSignalDescriptor input_sigs
[] = {
107 { "Input", SIG_FLAG_RANDOMACCESS
},
111 PRIVATE OutputSignalDescriptor output_sigs
[] = {
112 { "Output", SIG_FLAG_REALTIME
, { output_generator
, } },
116 PRIVATE ControlDescriptor controls
[] = {
117 /* { kind, name, min,max,step,page, size,editable, is_dst,queue_number,
118 init,destroy,refresh,refresh_data }, */
119 { CONTROL_KIND_NONE
, }
122 PRIVATE
void setup_class(void) {
123 GeneratorClass
*k
= gen_new_generatorclass("polyrart", FALSE
, 1, 0,
124 input_sigs
, output_sigs
, controls
,
125 init_instance
, done_instance
,
126 (AGenerator_pickle_t
) init_instance
, NULL
);
128 gen_configure_event_input(k
, 0, "Reset", evt_reset_handler
);
130 gencomp_register_generatorclass(k
, FALSE
, "Misc/Polyphonic Randomaccess Streamer", NULL
, NULL
);
133 PUBLIC
void init_plugin(void) {