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
28 #include "generator.h"
33 #define GENERATOR_CLASS_NAME "bias"
34 #define GENERATOR_CLASS_PATH "Levels/DC Bias"
40 #define NUM_EVENT_INPUTS 1
42 #define NUM_EVENT_OUTPUTS 0
48 PRIVATE
int init_instance(Generator
*g
) {
49 Data
*data
= safe_malloc(sizeof(Data
));
57 PRIVATE
void destroy_instance(Generator
*g
) {
61 PRIVATE
void unpickle_instance(Generator
*g
, ObjectStoreItem
*item
, ObjectStore
*db
) {
62 Data
*data
= safe_malloc(sizeof(Data
));
65 data
->bias
= objectstore_item_get_double(item
, "dcbias_bias", 0);
68 PRIVATE
void pickle_instance(Generator
*g
, ObjectStoreItem
*item
, ObjectStore
*db
) {
70 objectstore_item_set_double(item
, "dcbias_bias", data
->bias
);
73 PRIVATE gboolean
output_generator(Generator
*g
, SAMPLE
*buf
, int buflen
) {
75 SAMPLE delta
= data
->bias
* SAMPLE_UNIT
;
78 if (!gen_read_realtime_input(g
, SIG_INPUT
, 0, buf
, buflen
)) {
79 for (i
= 0; i
< buflen
; i
++)
82 for (i
= 0; i
< buflen
; i
++)
89 PRIVATE
void evt_bias_handler(Generator
*g
, AEvent
*event
) {
91 data
->bias
= event
->d
.number
;
92 gen_update_controls(g
, 0);
95 PRIVATE InputSignalDescriptor input_sigs
[] = {
96 { "Input", SIG_FLAG_REALTIME
},
100 PRIVATE OutputSignalDescriptor output_sigs
[] = {
101 { "Output", SIG_FLAG_REALTIME
, { output_generator
, } },
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) {