missing commit in generator.h
[galan.git] / plugins / libdcbias.c
blob0442324965e2ebc604061a4fdb2ad86aaf645e25
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>
27 #include "global.h"
28 #include "generator.h"
29 #include "comp.h"
30 #include "control.h"
31 #include "gencomp.h"
33 #define GENERATOR_CLASS_NAME "bias"
34 #define GENERATOR_CLASS_PATH "Levels/DC Bias"
36 #define SIG_INPUT 0
37 #define SIG_OUTPUT 0
39 #define EVT_BIAS 0
40 #define NUM_EVENT_INPUTS 1
42 #define NUM_EVENT_OUTPUTS 0
44 typedef struct Data {
45 gdouble bias;
46 } Data;
48 PRIVATE int init_instance(Generator *g) {
49 Data *data = safe_malloc(sizeof(Data));
50 g->data = data;
52 data->bias = 0;
54 return 1;
57 PRIVATE void destroy_instance(Generator *g) {
58 free(g->data);
61 PRIVATE void unpickle_instance(Generator *g, ObjectStoreItem *item, ObjectStore *db) {
62 Data *data = safe_malloc(sizeof(Data));
63 g->data = data;
65 data->bias = objectstore_item_get_double(item, "dcbias_bias", 0);
68 PRIVATE void pickle_instance(Generator *g, ObjectStoreItem *item, ObjectStore *db) {
69 Data *data = g->data;
70 objectstore_item_set_double(item, "dcbias_bias", data->bias);
73 PRIVATE gboolean output_generator(Generator *g, SAMPLE *buf, int buflen) {
74 Data *data = g->data;
75 SAMPLE delta = data->bias * SAMPLE_UNIT;
76 int i;
78 if (!gen_read_realtime_input(g, SIG_INPUT, 0, buf, buflen)) {
79 for (i = 0; i < buflen; i++)
80 buf[i] = delta;
81 } else {
82 for (i = 0; i < buflen; i++)
83 buf[i] += delta;
86 return TRUE;
89 PRIVATE void evt_bias_handler(Generator *g, AEvent *event) {
90 Data *data = g->data;
91 data->bias = event->d.number;
92 gen_update_controls(g, 0);
95 PRIVATE InputSignalDescriptor input_sigs[] = {
96 { "Input", SIG_FLAG_REALTIME },
97 { NULL, }
100 PRIVATE OutputSignalDescriptor output_sigs[] = {
101 { "Output", SIG_FLAG_REALTIME, { output_generator, } },
102 { NULL, }
105 PRIVATE ControlDescriptor controls[] = {
106 { CONTROL_KIND_KNOB, "bias", -1, 1, 0.1, 0.01, 0,TRUE, 1,EVT_BIAS,
107 NULL, NULL, control_double_updater, (gpointer) offsetof(Data, bias) },
108 { CONTROL_KIND_NONE, }
111 PRIVATE void setup_class(void) {
112 GeneratorClass *k = gen_new_generatorclass(GENERATOR_CLASS_NAME, FALSE,
113 NUM_EVENT_INPUTS, NUM_EVENT_OUTPUTS,
114 input_sigs, output_sigs, controls,
115 init_instance, destroy_instance,
116 unpickle_instance, pickle_instance);
118 gen_configure_event_input(k, EVT_BIAS, "Bias", evt_bias_handler);
120 gencomp_register_generatorclass(k, FALSE, GENERATOR_CLASS_PATH, NULL, NULL);
123 PUBLIC void init_plugin(void) {
124 setup_class();