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"
35 #define GENERATOR_CLASS_NAME "evtsgn"
36 #define GENERATOR_CLASS_PATH "Events/Sgn"
45 PRIVATE
int init_instance(Generator
*g
) {
47 Data
*data
= safe_malloc( sizeof(Data
) );
56 PRIVATE
void destroy_instance(Generator
*g
) {
62 PRIVATE
void unpickle_instance(Generator
*g
, ObjectStoreItem
*item
, ObjectStore
*db
) {
63 Data
*data
= safe_malloc(sizeof(Data
));
66 data
->oldvalue
= objectstore_item_get_double(item
, "sgn_oldvalue", 0);
69 PRIVATE
void pickle_instance(Generator
*g
, ObjectStoreItem
*item
, ObjectStore
*db
) {
71 objectstore_item_set_double(item
, "sgn_oldvalue", data
->oldvalue
);
76 PRIVATE
void evt_value_handler(Generator
*g
, AEvent
*event
) {
80 event
->d
.number
= event
->d
.number
== 0 ? 0 : (event
->d
.number
< 0 ? -1 : 1);
81 if( event
->d
.number
!= data
->oldvalue
) {
82 data
->oldvalue
= event
->d
.number
;
83 gen_send_events(g
, EVT_OUTPUT
, -1, event
);
87 PRIVATE ControlDescriptor controls
[] = {
88 { CONTROL_KIND_NONE
, }
93 PRIVATE
void setup_class(void) {
94 GeneratorClass
*k
= gen_new_generatorclass(GENERATOR_CLASS_NAME
, FALSE
, 1, 1,
96 init_instance
, destroy_instance
,
97 unpickle_instance
, pickle_instance
);
99 gen_configure_event_input(k
, EVT_VALUE
, "Input", evt_value_handler
);
100 gen_configure_event_output(k
, EVT_OUTPUT
, "Sgn");
102 gencomp_register_generatorclass(k
, FALSE
, GENERATOR_CLASS_PATH
, NULL
, NULL
);
105 PUBLIC
void init_plugin(void) {