missing commit in generator.h
[galan.git] / plugins / libra2evt.c
blobb7d8e7a869cde3e0851522ad35e90c95a7636518
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
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdio.h>
23 #include <gdk/gdk.h>
24 #include <gtk/gtk.h>
25 #include <glib.h>
27 #include "global.h"
28 #include "generator.h"
29 #include "comp.h"
30 #include "control.h"
31 #include "gencomp.h"
33 #define SIG_INPUT 0
34 #define EVT_TRIGGER 0
35 #define EVT_OUTPUT 0
37 PRIVATE void evt_trigger_handler(Generator *g, AEvent *event) {
38 SAMPLE *buffer;
39 SAMPLETIME now = event->time;
41 int len = gen_get_randomaccess_input_range( g, SIG_INPUT, 0 );
44 if( len != 0 ) {
45 buffer = g_alloca( sizeof( SAMPLE ) * len );
47 if (!gen_read_randomaccess_input(g, SIG_INPUT, 0, 0, buffer, len))
48 g_warning( "Error\n" );
50 gen_init_aevent(event, AE_NUMARRAY, NULL, 0, NULL, 0, now);
51 event->d.array.len = len;
52 event->d.array.numbers = buffer;
53 gen_send_events(g, EVT_OUTPUT, -1, event);
54 event->kind = AE_NUMBER;
59 PRIVATE gboolean init_instance(Generator *g) {
60 return TRUE;
63 PRIVATE void done_instance(Generator *g) {
66 PRIVATE InputSignalDescriptor input_sigs[] = {
67 { "Input", SIG_FLAG_RANDOMACCESS },
68 { NULL, }
71 PRIVATE void setup_class(void) {
72 GeneratorClass *k = gen_new_generatorclass("ra2evt", FALSE, 1, 1,
73 input_sigs, NULL, NULL,
74 init_instance, done_instance,
75 (AGenerator_pickle_t) init_instance, NULL);
77 gen_configure_event_input(k, EVT_TRIGGER, "Trigger", evt_trigger_handler);
78 gen_configure_event_output(k, EVT_OUTPUT, "Output");
80 gencomp_register_generatorclass(k, FALSE, "Misc/Randomacces-to-event Converter", NULL, NULL);
83 PUBLIC void init_plugin(void) {
84 setup_class();