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)
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.
18 * Robin Gareus <robin@gareus.org>
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];
38 # include <lash/lash.h>
39 //------------------------------------------------
40 // extern Globals (main.c)
41 //------------------------------------------------
43 extern lash_client_t
*lash_client
;
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
) {
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);
76 void lcs_long(char *key
, long int value
) {
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);
85 void lcs_int(char *key
, int value
) {
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);
95 void lcs_dbl(char *key
, double value
) {
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);
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
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
) {
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
++) {
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
++) {
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
) {
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;
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
);
187 printf("Warning: unhandled mem: %s=%f\n",key
+7,lash_config_get_value_double(conf
));
190 } else if (!strncmp(key
,"keybinding_",11)) {
191 int mykey
= atoi(key
+11);
192 if (mykey
< 1 || mykey
> 6) return;
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
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
);
227 unsigned long val_size
= lash_config_get_value_size(conf
);
229 printf ("WARNING: unhandled LASH Config. Key = %s size: %ld\n",key
,val_size
);
234 /*************************
235 * public LASH functions
238 void lash_setup(void) {
241 event
= lash_event_new_with_type(LASH_Client_Name
);
242 lash_event_set_string(event
, "gjacktransport");
243 lash_send_event(lash_client
, event
);
248 void lash_process(void) {
250 lash_event_t
* ev
= NULL
;
251 lash_config_t
* conf
= NULL
;
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
);
257 while ((ev
= lash_get_event(lash_client
)) != NULL
) {
259 lash_event_destroy(ev
);
261 while ((conf
= lash_get_config(lash_client
)) != NULL
) {
263 lash_config_destroy(conf
);
265 // TODO do only if changed! -> flag
269 gtk_window_resize(GTK_WINDOW(window1
),my_width
,my_height
);
270 gtk_window_move(GTK_WINDOW(window1
),my_root_x
,my_root_y
);