missing commit in generator.h
[galan.git] / plugins / libdiff.c
blobea343a09c5321e7ac5db9f83b46525efa5eaccc0
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>
22 #include <stddef.h>
24 #include <gdk/gdk.h>
25 #include <gtk/gtk.h>
26 #include <gmodule.h>
28 #include "global.h"
29 #include "generator.h"
30 #include "comp.h"
31 #include "control.h"
32 #include "gencomp.h"
34 #define GENERATOR_CLASS_NAME "filter_diff"
35 #define GENERATOR_CLASS_PATH "Filter/Differentiator Coeffs"
37 #define EVT_TYPE 0
38 #define NUM_EVENT_INPUTS 1
40 #define EVT_COEFFS 0
41 #define NUM_EVENT_OUTPUTS 1
43 typedef struct Data {
44 } Data;
48 #define NUM_COEFFS 4
50 /**
51 * \brief Calculate the coefficients for a normal Integrator
52 * And emit them.
54 * \param g The Generator we send from.
55 * \param event The event we received.
57 * The intgrator has its coefficients [1,1,1,0]
59 * That the event is passed here is only for convenience.
60 * i change the type of the event from AE_NUMBER to AE_NUMARRAY
61 * this makes eventq_free() believe it must free the number array also
62 * so i change the type back to AE_NONE...
64 * This is to remove the segfault for now.
65 * but i dont know how i should handle this in the future.
69 PRIVATE void calc_coeffs_and_send(Generator *g, AEvent *event) {
70 gdouble coeffs[NUM_COEFFS] = { 1,0,1,-1 };
72 gen_init_aevent(event, AE_DBLARRAY, NULL, 0, NULL, 0, event->time);
74 event->d.darray.len = NUM_COEFFS;
75 event->d.darray.numbers = coeffs;
77 gen_send_events(g, EVT_COEFFS, -1, event);
78 event->kind = AE_NONE;
82 PRIVATE ControlDescriptor controls[] = {
83 /* { kind, name, min,max,step,page, size,editable, is_dst,queue_number,
84 init,destroy,refresh,refresh_data }, */
85 // { CONTROL_KIND_KNOB, "bias", -1,1,0.1,0.01, 0,TRUE, TRUE,EVT_ADDEND,
86 // NULL,NULL, control_double_updater, (gpointer) offsetof(Data, addend) },
87 { CONTROL_KIND_NONE, }
90 PRIVATE void setup_class(void) {
91 GeneratorClass *k = gen_new_generatorclass(GENERATOR_CLASS_NAME, FALSE,
92 NUM_EVENT_INPUTS, NUM_EVENT_OUTPUTS,
93 NULL, NULL, controls,
94 NULL, NULL, NULL, NULL);
96 gen_configure_event_input(k, EVT_TYPE, "Type", calc_coeffs_and_send);
97 gen_configure_event_output(k, EVT_COEFFS, "Coefficients");
99 gencomp_register_generatorclass(k, FALSE, GENERATOR_CLASS_PATH,
100 NULL,
101 NULL);
104 PUBLIC void init_plugin(void) {
105 setup_class();