missing commit in generator.h
[galan.git] / plugins / libmidiclock.c
bloba26a58ab6a9819ae5057faf22589da24920617df
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 <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <unistd.h>
29 #include <linux/joystick.h>
31 #include <gdk/gdk.h>
32 #include <gtk/gtk.h>
34 #include "global.h"
35 #include "generator.h"
36 #include "comp.h"
37 #include "control.h"
38 #include "gencomp.h"
39 #include "msgbox.h"
41 #define GENERATOR_CLASS_NAME "midiclock"
42 #define GENERATOR_CLASS_PATH "Misc/MIDI Clock"
46 /*
47 * Here is the Data....
51 enum EVT_INPUTS {
52 NUM_EVENT_INPUTS = 0
55 enum EVT_OUTPUTS {
56 EVT_CLOCK = 0,
57 EVT_START,
58 NUM_EVENT_OUTPUTS
61 typedef struct Data {
62 gint fd;
63 gint input_tag;
64 } 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;
80 AEvent event;
82 read( source, &midibyte, 1 );
84 if( midibyte == 0xf8 ) {
86 gen_init_aevent(&event, AE_NUMBER, NULL, 0, NULL, 0, gen_get_sampletime() );
87 event.d.number = 1;
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() );
93 event.d.number = 1;
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));
114 g->data = 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 );
118 return 1;
121 PRIVATE void destroy_instance(Generator *g) {
122 Data *data = g->data;
124 gdk_input_remove( data->input_tag );
125 close( data->fd );
127 free(g->data);
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));
140 g->data = 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;
151 * controls....
153 * Shall there ever be controls ???
154 * i am a control :-)
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, }
166 * setup Class
168 * much TODO here....
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) {
187 setup_class();