added keybindings to control jack transport.
[gjacktransport.git] / src / lash.c
blobb81cc6f2b67850ab14a2c71f9b04dab3ce5306ad
1 /* gjacktransport - LASH interface
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * (c) 2007
18 * Robin Gareus <robin@gareus.org>
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
26 #include <gnome.h>
27 #include "gjack.h"
28 #include "gjacktransport.h"
29 #include "framerate.h"
31 extern FrameRate *fffr;
32 extern FrameRate *uffr;
33 extern FrameRate *jffr;
35 extern gint key_cfg[6];
37 #ifdef HAVE_LASH
38 # include <lash/lash.h>
39 //------------------------------------------------
40 // extern Globals (main.c)
41 //------------------------------------------------
42 // defined in main.c
43 extern lash_client_t *lash_client;
44 extern int mem;
45 extern gjtdata stg[MAX_MEM];
46 extern GtkWidget *window1;
48 extern int want_quiet;
50 /* restore config functions - see callbacks.c */
51 void select_mem (int newmem);
52 void showhide (char *togglebtn, char *widget, gboolean display);
53 gboolean ishidden (char *widget); //toggle-btn name
54 void dothejack (gboolean onoff);
55 void update_spinbtns(void);
57 // LASH extension - long int - use with lcs_long()
58 long int lash_config_get_value_long (const lash_config_t * config) {
59 const void *data = lash_config_get_value(config);
60 return(*((long*) data));
63 /*************************************
64 * lcs_*() - LASH Config Set functions
67 void lcs_str(char *key, char *value) {
68 #ifdef HAVE_LASH
69 lash_config_t *lc = lash_config_new_with_key(key);
70 lash_config_set_value_string (lc, value);
71 lash_send_config(lash_client, lc);
72 //printf("DEBUG - LASH config str: %s -> %i\n",key,value);
73 #endif
76 void lcs_long(char *key, long int value) {
77 #ifdef HAVE_LASH
78 lash_config_t *lc;
79 lc = lash_config_new_with_key(key);
80 lash_config_set_value (lc, (void*) &value, sizeof(long int));
81 lash_send_config(lash_client, lc);
82 //printf("DEBUG - LASH config long %ld -> %i\n",key,value);
83 #endif
85 void lcs_int(char *key, int value) {
86 #ifdef HAVE_LASH
87 lash_config_t *lc;
88 lc = lash_config_new_with_key(key);
89 lash_config_set_value_int (lc, value);
90 lash_send_config(lash_client, lc);
91 //printf("DEBUG - LASH config int: %i -> %i\n",key,value);
92 #endif
95 void lcs_dbl(char *key, double value) {
96 #ifdef HAVE_LASH
97 lash_config_t *lc;
98 lc = lash_config_new_with_key(key);
99 lash_config_set_value_double (lc, value);
100 lash_send_config(lash_client, lc);
101 //printf("DEBUG - LASH config dbl %g -> %i\n",key,value);
102 #endif
105 /*************************
106 * private LASH functions
108 gint my_root_x, my_root_y, my_width, my_height;
110 void handle_event(lash_event_t* ev) {
111 int type = lash_event_get_type(ev);
112 const char* str = lash_event_get_string(ev);
114 if (type == LASH_Restore_Data_Set) {
115 // FIXME - send this AFTER recv. config
116 if (!want_quiet)
117 printf("LASH restore data set\n");
118 //lash_send_event(lash_client, lash_event_new_with_type(LASH_Restore_Data_Set));
119 } else if (type == LASH_Save_Data_Set) {
120 int i;
121 if (!want_quiet)
122 printf("LASH saving data set\n");
124 if (jack_connected()) lcs_int("syncsource",1);
125 else lcs_int("syncsource",0);
127 for (i=0; i< MAX_MEM; i++) {
128 char tmp[32];
129 snprintf(tmp,31,"memory_%02i_start",i+1);
130 lcs_dbl(tmp,stg[i].start);
131 snprintf(tmp,31,"memory_%02i_end",i+1);
132 lcs_dbl(tmp,stg[i].end);
133 snprintf(tmp,31,"memory_%02i_unit",i+1);
134 lcs_int(tmp,stg[i].unit);
136 lcs_int("cur_mem",mem);
137 lcs_int("tb_status", ishidden("checkbutton5"));
138 lcs_int("tb_zoom", ishidden("checkbutton3"));
139 lcs_int("tb_memory", ishidden("checkbutton7"));
140 lcs_int("tb_all", ishidden("checkbutton6"));
141 lcs_int("tb_transport", ishidden("checkbutton4"));
142 lcs_int("tb_unit", ishidden("checkbutton2"));
143 lcs_int("tb_timelabels", ishidden("checkbutton8"));
144 gint root_x, root_y, width, height;
145 gtk_window_get_position (GTK_WINDOW(window1), &root_x, &root_y);
146 gtk_window_get_size (GTK_WINDOW(window1), &width, &height);
147 lcs_int("win_x", root_x);
148 lcs_int("win_y", root_y);
149 lcs_int("win_w", width);
150 lcs_int("win_h", height);
152 for (i=0; i< 6; i++) {
153 char tmp[32];
154 snprintf(tmp,31,"keybinding_%02i",i+1);
155 lcs_int(tmp,key_cfg[i]);
158 lcs_int("FR_mode",(jffr==fffr)?1:0);
159 lcs_int("FR_flags",uffr->flags);
160 //lcs_int("FR_num",uffr->num);
161 //lcs_int("FR_den",uffr->den);
163 lash_send_event(lash_client, lash_event_new_with_type(LASH_Save_Data_Set));
164 } else if (type == LASH_Quit) {
165 //loop_flag=0;
166 gtk_main_quit();
167 } else
168 if (!want_quiet)
169 printf ("WARNING: unhandled LASH Event t:%i s:'%s'\n",type,str);
172 void handle_config(lash_config_t* conf) {
173 const char* key = NULL;
174 key = lash_config_get_key(conf);
175 if (!strncmp(key,"memory_",7)) {
176 int mymem = atoi(key+7);
177 if (mymem < 1 || mymem > MAX_MEM) return;
178 mymem--;
179 if (!strcmp(key+9,"_start")) {
180 stg[mymem].start=lash_config_get_value_double(conf);
181 } else if (!strcmp(key+9,"_end")) {
182 stg[mymem].end=lash_config_get_value_double(conf);
183 } else if (!strcmp(key+9,"_unit")) {
184 stg[mymem].unit=lash_config_get_value_int(conf);
185 } else {
186 if (!want_quiet)
187 printf("Warning: unhandled mem: %s=%f\n",key+7,lash_config_get_value_double(conf));
189 update_spinbtns();
190 } else if (!strncmp(key,"keybinding_",11)) {
191 int mykey = atoi(key+11);
192 if (mykey < 1 || mykey > 6) return;
193 mykey--;
194 key_cfg[mykey]=lash_config_get_value_int(conf);
195 } else if (!strcmp(key,"syncsource")) {
196 dothejack(lash_config_get_value_int(conf));
197 } else if (!strcmp(key,"cur_mem")) {
198 select_mem(lash_config_get_value_int(conf));
199 } else if (!strcmp(key,"tb_status")) {
200 showhide("checkbutton5","statusbar1",lash_config_get_value_int(conf));
201 } else if (!strcmp(key,"tb_zoom")) {
202 showhide("checkbutton3","handlebox3",lash_config_get_value_int(conf));
203 } else if (!strcmp(key,"tb_memory")) {
204 showhide("checkbutton7","handlebox4",lash_config_get_value_int(conf));
205 } else if (!strcmp(key,"tb_all")) {
206 showhide("checkbutton6","table1",lash_config_get_value_int(conf));
207 } else if (!strcmp(key,"tb_transport")) {
208 showhide("checkbutton4","handlebox1",lash_config_get_value_int(conf));
209 } else if (!strcmp(key,"tb_unit")) {
210 showhide("checkbutton2","handlebox2",lash_config_get_value_int(conf));
211 } else if (!strcmp(key,"tb_timelabels")) {
212 showhide("checkbutton8","hbox_labels",lash_config_get_value_int(conf));
213 } else if (!strcmp(key,"FR_mode")) {
214 if (lash_config_get_value_int(conf)) fffr=jffr; // XXX
215 else fffr=uffr;
216 } else if (!strcmp(key,"FR_flags")) {
217 uffr->flags=lash_config_get_value_int(conf);
218 } else if (!strcmp(key,"win_x")) {
219 my_root_x=lash_config_get_value_int(conf);
220 } else if (!strcmp(key,"win_y")) {
221 my_root_y=lash_config_get_value_int(conf);
222 } else if (!strcmp(key,"win_w")) {
223 my_width=lash_config_get_value_int(conf);
224 } else if (!strcmp(key,"win_h")) {
225 my_height=lash_config_get_value_int(conf);
226 } else {
227 unsigned long val_size = lash_config_get_value_size(conf);
228 if (!want_quiet)
229 printf ("WARNING: unhandled LASH Config. Key = %s size: %ld\n",key,val_size);
234 /*************************
235 * public LASH functions
238 void lash_setup(void) {
239 lash_event_t *event;
240 //lash_config_t *lc;
241 event = lash_event_new_with_type(LASH_Client_Name);
242 lash_event_set_string(event, "gjacktransport");
243 lash_send_event(lash_client, event);
245 #endif
248 void lash_process(void) {
249 #ifdef HAVE_LASH
250 lash_event_t* ev = NULL;
251 lash_config_t* conf = NULL;
252 int flag =0;
253 #if 1
254 gtk_window_get_size (GTK_WINDOW(window1), &my_width, &my_height);
255 gtk_window_get_position (GTK_WINDOW(window1), &my_root_x, &my_root_y);
256 #endif
257 while ((ev = lash_get_event(lash_client)) != NULL) {
258 handle_event(ev);
259 lash_event_destroy(ev);
261 while ((conf = lash_get_config(lash_client)) != NULL) {
262 handle_config(conf);
263 lash_config_destroy(conf);
264 flag=1;
265 // TODO do only if changed! -> flag
267 if (flag) {
268 update_spinbtns();
269 gtk_window_resize(GTK_WINDOW(window1),my_width,my_height);
270 gtk_window_move(GTK_WINDOW(window1),my_root_x,my_root_y);
272 #endif