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>
30 #include "gjacktransport.h"
31 #include "framerate.h"
33 extern FrameRate
*fffr
;
34 extern FrameRate
*uffr
;
35 extern FrameRate
*jffr
;
37 extern gint key_cfg
[MAX_KEYBINDING
];
41 # include <lash/lash.h>
42 //------------------------------------------------
43 // extern Globals (main.c)
44 //------------------------------------------------
46 extern lash_client_t
*lash_client
;
50 extern GtkWidget
*window1
;
52 extern int want_quiet
;
54 /* restore config functions - see callbacks.c */
55 void select_mem (int newmem
);
56 void showhide (char *togglebtn
, char *widget
, gboolean display
);
57 gboolean
ishidden (char *widget
); //toggle-btn name
58 void dothejack (gboolean onoff
);
59 void update_combotxt (int pos
);
60 int realloc_mem (int newmax
);
62 // LASH extension - long int - use with lcs_long()
63 long int lash_config_get_value_long (const lash_config_t
* config
) {
64 const void *data
= lash_config_get_value(config
);
65 return(*((long*) data
));
68 /*************************************
69 * lcs_*() - LASH Config Set functions
72 void lcs_str(char *key
, char *value
) {
74 lash_config_t
*lc
= lash_config_new_with_key(key
);
75 lash_config_set_value_string (lc
, value
);
76 lash_send_config(lash_client
, lc
);
77 //printf("DEBUG - LASH config str: %s -> %i\n",key,value);
81 void lcs_long(char *key
, long int value
) {
84 lc
= lash_config_new_with_key(key
);
85 lash_config_set_value (lc
, (void*) &value
, sizeof(long int));
86 lash_send_config(lash_client
, lc
);
87 //printf("DEBUG - LASH config long %ld -> %i\n",key,value);
91 void lcs_int(char *key
, int value
) {
94 lc
= lash_config_new_with_key(key
);
95 lash_config_set_value_int (lc
, value
);
96 lash_send_config(lash_client
, lc
);
97 //printf("DEBUG - LASH config int: %i -> %i\n",key,value);
101 void lcs_dbl(char *key
, double value
) {
104 lc
= lash_config_new_with_key(key
);
105 lash_config_set_value_double (lc
, value
);
106 lash_send_config(lash_client
, lc
);
107 //printf("DEBUG - LASH config dbl %g -> %i\n",key,value);
111 /*************************
112 * private LASH functions
114 gint my_root_x
, my_root_y
, my_width
, my_height
;
116 void handle_event(lash_event_t
* ev
) {
117 int type
= lash_event_get_type(ev
);
118 const char* str
= lash_event_get_string(ev
);
120 if (type
== LASH_Restore_Data_Set
) {
121 // FIXME - send this AFTER recv. config
123 printf("LASH restore data set\n");
124 //lash_send_event(lash_client, lash_event_new_with_type(LASH_Restore_Data_Set));
125 } else if (type
== LASH_Save_Data_Set
) {
128 printf("LASH saving data set\n");
130 if (jack_connected()) lcs_int("syncsource",1);
131 else lcs_int("syncsource",0);
133 for (i
=0; i
< max_mem
; i
++) {
135 snprintf(tmp
,31,"memory_%02i_start",i
+1);
136 lcs_dbl(tmp
,stg
[i
].start
);
137 snprintf(tmp
,31,"memory_%02i_end",i
+1);
138 lcs_dbl(tmp
,stg
[i
].end
);
139 snprintf(tmp
,31,"memory_%02i_unit",i
+1);
140 lcs_int(tmp
,stg
[i
].unit
);
141 snprintf(tmp
,31,"memory_%02i_name",i
+1);
142 lcs_str(tmp
,stg
[i
].name
?stg
[i
].name
:"");
144 lcs_int("cur_mem",mem
);
145 lcs_dbl("seek_stride",stride
);
146 lcs_int("tb_status", ishidden("checkbutton5"));
147 lcs_int("tb_zoom", ishidden("checkbutton3"));
148 lcs_int("tb_memory", ishidden("checkbutton7"));
149 lcs_int("tb_all", ishidden("checkbutton6"));
150 lcs_int("tb_transport", ishidden("checkbutton4"));
151 lcs_int("tb_unit", ishidden("checkbutton2"));
152 lcs_int("tb_timelabels", ishidden("checkbutton8"));
153 gint root_x
, root_y
, width
, height
;
154 gtk_window_get_position (GTK_WINDOW(window1
), &root_x
, &root_y
);
155 gtk_window_get_size (GTK_WINDOW(window1
), &width
, &height
);
156 lcs_int("win_x", root_x
);
157 lcs_int("win_y", root_y
);
158 lcs_int("win_w", width
);
159 lcs_int("win_h", height
);
161 for (i
=0; i
< MAX_KEYBINDING
; i
++) {
163 snprintf(tmp
,31,"keybinding_%02i",i
+1);
164 lcs_int(tmp
,key_cfg
[i
]);
167 lcs_int("FR_mode",(jffr
==fffr
)?1:0);
168 lcs_int("FR_flags",uffr
->flags
);
169 //lcs_int("FR_num",uffr->num);
170 //lcs_int("FR_den",uffr->den);
172 lash_send_event(lash_client
, lash_event_new_with_type(LASH_Save_Data_Set
));
173 } else if (type
== LASH_Quit
) {
178 printf ("WARNING: unhandled LASH Event t:%i s:'%s'\n",type
,str
);
181 void handle_config(lash_config_t
* conf
) {
182 const char* key
= NULL
;
183 key
= lash_config_get_key(conf
);
184 if (!strncmp(key
,"memory_",7)) {
185 int mymem
= atoi(key
+7);
186 if (mymem
< 1) return;
187 if (mymem
> max_mem
) {
188 if (realloc_mem(mymem
)) return;
191 if (!strcmp(key
+9,"_start")) {
192 stg
[mymem
].start
=lash_config_get_value_double(conf
);
193 } else if (!strcmp(key
+9,"_end")) {
194 stg
[mymem
].end
=lash_config_get_value_double(conf
);
195 } else if (!strcmp(key
+9,"_unit")) {
196 stg
[mymem
].unit
=lash_config_get_value_int(conf
);
197 } else if (!strcmp(key
+9,"_name")) {
198 if (stg
[mymem
].name
) free(stg
[mymem
].name
);
199 stg
[mymem
].name
=strdup(lash_config_get_value_string(conf
));
200 if (strlen(stg
[mymem
].name
) == 0) {free(stg
[mymem
].name
); stg
[mymem
].name
=NULL
;}
201 update_combotxt(mymem
);
204 printf("Warning: unhandled mem: %s=%f\n",key
+7,lash_config_get_value_double(conf
));
206 } else if (!strncmp(key
,"keybinding_",11)) {
207 int mykey
= atoi(key
+11);
208 if (mykey
< 1 || mykey
> MAX_KEYBINDING
) return;
210 key_cfg
[mykey
]=lash_config_get_value_int(conf
);
211 } else if (!strcmp(key
,"syncsource")) {
212 dothejack(lash_config_get_value_int(conf
));
213 } else if (!strcmp(key
,"cur_mem")) {
214 select_mem(lash_config_get_value_int(conf
));
215 } else if (!strcmp(key
,"seek_stride")) {
216 stride
=lash_config_get_value_double(conf
);
217 } else if (!strcmp(key
,"tb_status")) {
218 showhide("checkbutton5","statusbar1",lash_config_get_value_int(conf
));
219 } else if (!strcmp(key
,"tb_zoom")) {
220 showhide("checkbutton3","handlebox3",lash_config_get_value_int(conf
));
221 } else if (!strcmp(key
,"tb_memory")) {
222 showhide("checkbutton7","handlebox4",lash_config_get_value_int(conf
));
223 } else if (!strcmp(key
,"tb_all")) {
224 showhide("checkbutton6","table1",lash_config_get_value_int(conf
));
225 } else if (!strcmp(key
,"tb_transport")) {
226 showhide("checkbutton4","handlebox1",lash_config_get_value_int(conf
));
227 } else if (!strcmp(key
,"tb_unit")) {
228 showhide("checkbutton2","handlebox2",lash_config_get_value_int(conf
));
229 } else if (!strcmp(key
,"tb_timelabels")) {
230 showhide("checkbutton8","hbox_labels",lash_config_get_value_int(conf
));
231 } else if (!strcmp(key
,"FR_mode")) {
232 if (lash_config_get_value_int(conf
)) fffr
=jffr
; // XXX
234 } else if (!strcmp(key
,"FR_flags")) {
235 uffr
->flags
=lash_config_get_value_int(conf
);
236 } else if (!strcmp(key
,"win_x")) {
237 my_root_x
=lash_config_get_value_int(conf
);
238 } else if (!strcmp(key
,"win_y")) {
239 my_root_y
=lash_config_get_value_int(conf
);
240 } else if (!strcmp(key
,"win_w")) {
241 my_width
=lash_config_get_value_int(conf
);
242 } else if (!strcmp(key
,"win_h")) {
243 my_height
=lash_config_get_value_int(conf
);
245 unsigned long val_size
= lash_config_get_value_size(conf
);
247 printf ("WARNING: unhandled LASH Config. Key = %s size: %ld\n",key
,val_size
);
252 /*************************
253 * public LASH functions
256 void lash_setup(void) {
259 event
= lash_event_new_with_type(LASH_Client_Name
);
260 lash_event_set_string(event
, "gjacktransport");
261 lash_send_event(lash_client
, event
);
266 void lash_process(void) {
268 lash_event_t
* ev
= NULL
;
269 lash_config_t
* conf
= NULL
;
272 gtk_window_get_size (GTK_WINDOW(window1
), &my_width
, &my_height
);
273 gtk_window_get_position (GTK_WINDOW(window1
), &my_root_x
, &my_root_y
);
275 while ((ev
= lash_get_event(lash_client
)) != NULL
) {
277 lash_event_destroy(ev
);
279 while ((conf
= lash_get_config(lash_client
)) != NULL
) {
281 lash_config_destroy(conf
);
283 // TODO do only if changed! -> flag
286 gtk_window_resize(GTK_WINDOW(window1
),my_width
,my_height
);
287 gtk_window_set_gravity(GTK_WINDOW(window1
), GDK_GRAVITY_STATIC
);
288 gtk_window_move(GTK_WINDOW(window1
),my_root_x
,my_root_y
);