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
24 #include <sys/types.h>
29 #include <linux/joystick.h>
35 #include "generator.h"
41 #define GENERATOR_CLASS_NAME "midiclock"
42 #define GENERATOR_CLASS_PATH "Misc/MIDI Clock"
47 * Here is the Data....
68 * This is the input callback....
69 * Seems to bo ok for now..
71 * now with the buttons its ok...
72 * (??? Is sending the number ok with evtcomp)
77 PRIVATE
void input_callback( Generator
*g
, gint source
, GdkInputCondition condition
) {
79 unsigned char midibyte
;
82 read( source
, &midibyte
, 1 );
84 if( midibyte
== 0xf8 ) {
86 gen_init_aevent(&event
, AE_NUMBER
, NULL
, 0, NULL
, 0, gen_get_sampletime() );
88 gen_send_events(g
, EVT_CLOCK
, -1, &event
);
90 if( midibyte
== 0xfa ) {
92 gen_init_aevent(&event
, AE_NUMBER
, NULL
, 0, NULL
, 0, gen_get_sampletime() );
94 gen_send_events(g
, EVT_START
, -1, &event
);
101 * Constuctor and Destructor
103 * I have to add a global-property to get /dev/input/js0 from config.
104 * Of course make it configurable in plugin-properties.
106 * then i need asserts... But hey it works now :-)
107 * Instance can be added even if configured for js1 and only js0
108 * available (??? confusing having non working component )
112 PRIVATE
int init_instance(Generator
*g
) {
113 Data
*data
= safe_malloc(sizeof(Data
));
116 data
->fd
= open( "/dev/midi00", O_RDONLY
| O_NONBLOCK
);
117 data
->input_tag
= gdk_input_add( data
->fd
, GDK_INPUT_READ
, (GdkInputFunction
) input_callback
, (gpointer
) g
);
121 PRIVATE
void destroy_instance(Generator
*g
) {
122 Data
*data
= g
->data
;
124 gdk_input_remove( data
->input_tag
);
132 * pickle and unpickle
134 * are straight forward....
138 PRIVATE
void unpickle_instance(Generator
*g
, ObjectStoreItem
*item
, ObjectStore
*db
) {
139 Data
*data
= safe_malloc(sizeof(Data
));
142 data
->fd
= open( "/dev/midi00", O_RDONLY
);
143 data
->input_tag
= gdk_input_add( data
->fd
, GDK_INPUT_READ
, (GdkInputFunction
) input_callback
, g
);
146 PRIVATE
void pickle_instance(Generator
*g
, ObjectStoreItem
*item
, ObjectStore
*db
) {
147 //Data *data = g->data;
153 * Shall there ever be controls ???
158 PRIVATE ControlDescriptor controls
[] = {
159 /* { kind, name, min,max,step,page, size,editable, is_dst,queue_number,
160 init,destroy,refresh,refresh_data }, */
161 { CONTROL_KIND_NONE
, }
170 * check how many buttons and axes we have...
171 * can i change this dynamicly ???
175 PRIVATE
void setup_class(void) {
176 GeneratorClass
*k
= gen_new_generatorclass(GENERATOR_CLASS_NAME
, FALSE
, NUM_EVENT_INPUTS
, NUM_EVENT_OUTPUTS
,
177 NULL
, NULL
, controls
,
178 init_instance
, destroy_instance
,
179 unpickle_instance
, pickle_instance
);
181 gen_configure_event_output(k
, EVT_CLOCK
, "Clock");
182 gen_configure_event_output(k
, EVT_START
, "Start");
183 gencomp_register_generatorclass(k
, FALSE
, GENERATOR_CLASS_PATH
, NULL
, NULL
);
186 PUBLIC
void init_plugin(void) {