XML serialization for set files, bug fixes and a new full screen mode
[terminatorX.git] / src / tX_vttgui.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2002  Alexander K├Ânig
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     File: tX_vttgui.cc
20  
21     Description: This implements the gtk+ GUI for the virtual turntable
22                  class implemented in tX_vtt.cc. This code is not in tX_vtt.cc
23                  for mainly to keep the GUI code divided from the audio-rendering
24                  code and as gtk+ callback to C++ method call wrapper.
25                  
26     Changes:
27     
28     before 11-26-2001: too many changes.
29     
30     11-26-2001: applied Adrian's solo/mute patch - Alex
31     
32     11-27-2001: modified solo/mute to use the set_mix_mute/solo function
33                 of the vtts. The previous approach messed up the sequencer
34                 and more. Removed some old unnecessary code, too.
35 */    
36
37 #include <gdk/gdk.h>
38 #include <gtk/gtk.h>
39 #include "tX_vttgui.h"
40 #include "tX_vtt.h"
41 #include "tX_widget.h"
42 #include "tX_mastergui.h"
43 #include "tX_loaddlg.h"
44 #include "tX_prelis.h"
45 #include "tX_pbutton.h"
46 #include "tX_global.h"
47 #include "tX_extdial.h"
48 #include "tX_panel.h"
49 #include "tX_ladspa.h"
50
51 #ifdef USE_DIAL
52 #include "tX_dial.h"
53 #endif
54
55 #ifdef USE_FLASH
56 #include "tX_flash.h"
57 #endif
58 #include <stdio.h>
59
60 #define WID_DYN TRUE, TRUE, 0
61 #define WID_FIX FALSE, FALSE, 0
62
63 #define FILENAME_BUTTON_MAX 20
64
65 void nicer_filename(char *dest, char *source)
66 {
67                 char *fn;
68                 char temp[PATH_MAX];
69                 
70                 fn=strrchr(source, '/');
71                 if (fn) fn++;
72                 else fn=source;
73                 
74                 strcpy (temp, fn);
75                 
76                 fn=strrchr(temp, '.');
77                 if (fn) *fn=0;
78                 
79                 if (strlen(temp) > FILENAME_BUTTON_MAX)
80                 {
81                         temp[FILENAME_BUTTON_MAX-3]='.';
82                         temp[FILENAME_BUTTON_MAX-2]='.';
83                         temp[FILENAME_BUTTON_MAX-1]='.';
84                         temp[FILENAME_BUTTON_MAX]=0;
85                 } 
86                 strcpy (dest, temp);
87 }
88
89 void name_changed(GtkWidget *wid, vtt_class *vtt)
90 {
91         vtt->set_name((char *) gtk_entry_get_text(GTK_ENTRY(wid)));
92 }
93
94 void volume_changed(GtkWidget *wid, vtt_class *vtt)
95 {
96         vtt->sp_volume.receive_gui_value(2.0-GTK_ADJUSTMENT(wid)->value);
97 }
98
99 void pan_changed(GtkWidget *wid, vtt_class *vtt)
100 {
101       vtt->sp_pan.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
102 }
103
104 void pitch_changed(GtkWidget *wid, vtt_class *vtt)
105 {
106         vtt->sp_pitch.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
107 }
108
109 GtkSignalFunc trigger_prelis(GtkWidget *w)
110 {
111         GtkFileSelection *fs;
112
113         fs=GTK_FILE_SELECTION(gtk_widget_get_toplevel(w));
114         
115         prelis_start((char *) gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
116         return(0);
117 }
118
119 void cancel_load_file(GtkWidget *wid, vtt_class *vtt)
120 {
121         prelis_stop();
122         
123         vtt->gui.file_dialog=NULL;
124         if (vtt->gui.fs) gtk_widget_destroy(GTK_WIDGET(vtt->gui.fs));
125 }
126
127 int quit_load_file(GtkWidget *wid, vtt_class *vtt)
128 {
129         return 1;
130 }
131
132 char global_filename_buffer[PATH_MAX];
133
134 void load_part(char *newfile, vtt_class *vtt)
135 {
136         tX_audio_error ret=TX_AUDIO_SUCCESS;
137
138         ld_create_loaddlg(TX_LOADDLG_MODE_SINGLE, 1);
139         ld_set_filename(newfile);
140
141         ret = vtt->load_file(newfile);
142         
143         ld_destroy();
144         if (ret)
145         {
146                 switch(ret)
147                 {
148                         case TX_AUDIO_ERR_ALLOC:
149                         tx_note("Failed to load audiofile - there's not enough memory available.", true);
150                         break;
151                         case TX_AUDIO_ERR_PIPE_READ:
152                         tx_note("An error occured on reading from the piped process - probably the file format of the audiofile is not supported by this configuration - please check terminatorX' INSTALL file on howto configure terminatorX for files of this format.", true);
153                         break;
154                         case TX_AUDIO_ERR_SOX:
155                         tx_note("Failed to run sox - to load the given audiofile please ensure that sox is installed correctly.", true);
156                         break;
157                         case TX_AUDIO_ERR_MPG123:
158                         tx_note("Failed to run mpg123 - to load the given mp3 file please ensure that mpg123 (or mpg321) is installed correctly.", true);
159                         break;
160                         case TX_AUDIO_ERR_WAV_NOTFOUND:
161                         tx_note("Couldn't acces the audiofile - file not found.", true);
162                         break;
163                         case TX_AUDIO_ERR_NOT_16BIT:
164                         tx_note("The wav file doesn't use 16 bit wide samples - please compile terminatorX with libaudiofile support to enable loading of such files.", true);
165                         break;
166                         case TX_AUDIO_ERR_NOT_MONO:
167                         tx_note("The wav file is not mono - please compile terminatorX with libaudiofile support to enable loading of such files.", true);
168                         break;
169                         case TX_AUDIO_ERR_WAV_READ:
170                         tx_note("The wav file seems to be corrupt.", true);
171                         break;
172                         case TX_AUDIO_ERR_NOT_SUPPORTED:
173                         tx_note("The file format of the audiofile is not supported - please check terminatorX' INSTALL file on howto configure terminatorX for files of this format.", true);
174                         break;
175                         case TX_AUDIO_ERR_MAD_OPEN:
176                         tx_note("Failed to open this mp3 file - please ensure that the file exists and is readable.", true);
177                         break;  
178                         case TX_AUDIO_ERR_MAD_STAT:
179                         tx_note("Failed to 'stat' this mp3 file - please ensure that the file exists and is readable.", true);
180                         break;
181                         case TX_AUDIO_ERR_MAD_DECODE:
182                         tx_note("Failed to decode the mp3 stream - file is corrupt.", true);
183                         break;
184                         case TX_AUDIO_ERR_MAD_MMAP:
185                         tx_note("Failed to map the audiofile to memory - please ensure the file is readable.", true);
186                         break;
187                         case TX_AUDIO_ERR_MAD_MUNMAP:
188                         tx_note("Failed to unmap audiofile.", true);
189                         break;
190                         case TX_AUDIO_ERR_VORBIS_OPEN:
191                         tx_note("Failed to open ogg file - please ensure the file is an ogg stream and that it is readable.", true);
192                         break;                  
193                         case TX_AUDIO_ERR_VORBIS_NODATA:
194                         tx_note("The vorbis codec failed to decode any data - possibly this ogg stream is corrupt.", true);
195                         break;
196                         case TX_AUDIO_ERR_AF_OPEN:
197                         tx_note("Failed to open this file with libaudiofile - please check terminatorX' INSTALL file on howto configure terminatorX for files of this format.",true);
198                         break;
199                         case TX_AUDIO_ERR_AF_NODATA:
200                         tx_note("libaudiofile failed to decode any data - possilby the audiofile is corrupt.", true);
201                         break;
202                         default:                                        
203                         tx_note("An unknown error occured - if this bug is reproducible please report it, thanks.", true);      
204                 }
205         }
206         else
207         {
208                 nicer_filename(global_filename_buffer, newfile);
209         gtk_button_set_label(GTK_BUTTON(vtt->gui.file), global_filename_buffer);
210         }       
211 }
212
213 void do_load_file(GtkWidget *wid, vtt_class *vtt)
214 {
215         char newfile[PATH_MAX];
216         
217         prelis_stop();
218
219         strcpy(newfile, gtk_file_selection_get_filename(GTK_FILE_SELECTION(vtt->gui.fs)));
220         gtk_widget_destroy(GTK_WIDGET(vtt->gui.fs));
221         
222         load_part(newfile, vtt);
223         
224         if (!globals.current_path)
225         {
226                 free(globals.current_path);
227                 globals.current_path = NULL;
228         }
229
230         globals.current_path = strdup(newfile);
231
232         vtt->gui.file_dialog=NULL;
233 }
234
235 void drop_file(GtkWidget *widget, GdkDragContext *context,
236                 gint x, gint y, GtkSelectionData *selection_data,
237                 guint info, guint time, vtt_class *vtt)
238 {
239         char filename[PATH_MAX];
240         char *fn;
241         
242         strncpy(filename, (char *) selection_data->data, (size_t) selection_data->length);
243         gtk_drag_finish(context, TRUE, FALSE, time);
244         filename[selection_data->length]=0;
245
246         fn = strchr (filename, '\r');
247         *fn=0;  
248         
249         char *realfn=NULL;
250         char *host=NULL;
251         
252         realfn=g_filename_from_uri(filename, &host, NULL);
253         if (realfn) {
254                 fn=realfn;
255         } else  {
256                 fn = strchr (filename, ':');
257                 if (fn) fn++; else fn=(char *) selection_data->data;
258         }
259
260         load_part(realfn, vtt);
261
262         if (realfn) g_free(realfn);
263         if (host) g_free(host);
264 }
265
266
267 GtkSignalFunc load_file(GtkWidget *wid, vtt_class *vtt)
268 {       
269         char buffer[512];
270         
271         if (vtt->gui.file_dialog)
272         {
273                 gdk_window_raise(vtt->gui.file_dialog);
274                 return(0);
275         }
276         
277         sprintf(buffer, "Select Audio File for %s", vtt->name);
278         vtt->gui.fs=gtk_file_selection_new(buffer);
279         
280         if (strlen(vtt->filename) > 0)
281         {
282                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(vtt->gui.fs), vtt->filename);        
283         }
284         
285         gtk_widget_show(GTK_WIDGET(vtt->gui.fs));
286         
287         vtt->gui.file_dialog=vtt->gui.fs->window;
288         
289         if (globals.current_path)
290                 {
291                         gtk_file_selection_set_filename(GTK_FILE_SELECTION(vtt->gui.fs),globals.current_path);
292                 }
293         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(vtt->gui.fs)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_load_file), vtt);
294         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(vtt->gui.fs)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_load_file), vtt);    
295         gtk_signal_connect (GTK_OBJECT(vtt->gui.fs), "delete-event", GTK_SIGNAL_FUNC(quit_load_file), vtt);     
296         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(vtt->gui.fs)->file_list), "cursor_changed", GTK_SIGNAL_FUNC(trigger_prelis), vtt->gui.fs);            
297         return NULL;
298 }
299
300 void delete_vtt(GtkWidget *wid, vtt_class *vtt)
301 {
302         if (audioon) tx_note("Sorry, you'll have to stop playback first.");
303         else
304         delete(vtt);
305 }
306
307 void edit_vtt_buffer(GtkWidget *wid, vtt_class *vtt)
308 {
309         char command[2*PATH_MAX];
310
311         if (vtt->samples_in_buffer == 0)
312         {
313                 tx_note("No audiofile loaded - so there's nothing to edit.", true);
314         }
315         else
316         if (strlen(globals.file_editor)>0)
317         {
318                 sprintf(command, "%s \"%s\" &", globals.file_editor, vtt->filename);
319                 system(command); /*) tx_note("Failed to run the soundfile editor."); */
320         }
321         else
322         {
323                 tx_note("No soundfile editor has been configured - to do so enter the soundfile editor of your choice in the options dialog.", true);
324         }
325 }
326
327 void reload_vtt_buffer(GtkWidget *wid, vtt_class *vtt)
328 {
329         char reload_buffer[PATH_MAX];
330         
331         while (gtk_events_pending()) gtk_main_iteration();
332         
333         if (vtt->samples_in_buffer > 0)
334         {
335                 strcpy(reload_buffer, vtt->filename);
336                 load_part(reload_buffer, vtt);
337         }
338         else tx_note("No audiofile loaded - so there's nothing to reload.", true);
339 }
340
341 void clone_vtt(GtkWidget *wid, vtt_class *vtt)
342 {
343         vtt->stop();
344 }
345
346 void trigger_vtt(GtkWidget *wid, vtt_class *vtt)
347 {
348         vtt->sp_trigger.receive_gui_value((float) 1.0);
349 }
350
351 void stop_vtt(GtkWidget *wid, vtt_class *vtt)
352 {
353         vtt->sp_trigger.receive_gui_value((float) 0.0);
354 }
355
356 void autotrigger_toggled(GtkWidget *wid, vtt_class *vtt)
357 {
358         vtt->set_autotrigger(GTK_TOGGLE_BUTTON(wid)->active);
359 }
360
361 void loop_toggled(GtkWidget *wid, vtt_class *vtt)
362 {
363         vtt->sp_loop.receive_gui_value(GTK_TOGGLE_BUTTON(wid)->active);
364 }
365
366 void lp_enabled(GtkWidget *wid, vtt_class *vtt)
367 {
368         vtt->sp_lp_enable.receive_gui_value(GTK_TOGGLE_BUTTON(wid)->active);
369 }
370
371 void lp_gain_changed(GtkWidget *wid, vtt_class *vtt)
372 {
373         vtt->sp_lp_gain.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
374 }
375
376 void lp_reso_changed(GtkWidget *wid, vtt_class *vtt)
377 {
378         vtt->sp_lp_reso.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
379 }
380
381 void lp_freq_changed(GtkWidget *wid, vtt_class *vtt)
382 {
383         vtt->sp_lp_freq.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
384 }
385
386 void ec_enabled(GtkWidget *wid, vtt_class *vtt)
387 {
388         vtt->sp_ec_enable.receive_gui_value(GTK_TOGGLE_BUTTON(wid)->active);
389 }
390
391 void ec_length_changed(GtkWidget *wid, vtt_class *vtt)
392 {
393         vtt->sp_ec_length.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
394 }
395
396 void ec_feedback_changed(GtkWidget *wid, vtt_class *vtt)
397 {
398         vtt->sp_ec_feedback.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
399 }
400
401 void ec_pan_changed(GtkWidget *wid, vtt_class *vtt)
402 {
403         vtt->sp_ec_pan.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
404 }
405
406 void ec_volume_changed(GtkWidget *wid, vtt_class *vtt)
407 {
408         vtt->sp_ec_volume.receive_gui_value(GTK_ADJUSTMENT(wid)->value);
409 }
410
411 void master_setup(GtkWidget *wid, vtt_class *vtt)
412 {
413         vtt->set_sync_master(GTK_TOGGLE_BUTTON(wid)->active);
414 }
415
416 void client_setup(GtkWidget *wid, vtt_class *vtt)
417 {
418         int client;
419         
420         client=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vtt->gui.sync_client));   
421         vtt->sp_sync_client.receive_gui_value(client);
422 }
423
424 void client_setup_number(GtkWidget *wid, vtt_class *vtt)
425 {
426         int cycles;
427         
428         cycles=(int) GTK_ADJUSTMENT(vtt->gui.cycles)->value;    
429         
430         vtt->sp_sync_cycles.receive_gui_value(cycles);
431 }
432
433 void mute_volume(GtkWidget *widget, vtt_class *vtt)
434 {
435         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
436         {
437                 vtt->set_mix_mute(1);
438         }
439         else
440         {
441                 vtt->set_mix_mute(0);
442         }
443 }
444
445 void solo_vtt(GtkWidget *widget, vtt_class *vtt)
446 {
447         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) 
448         {
449                 vtt->set_mix_solo(1);
450         }
451         else
452         {
453                 vtt->set_mix_solo(0);
454         }
455 }      
456
457 void minimize_control_panel(GtkWidget *wid, vtt_class *vtt)
458 {
459         vtt->hide_control(true);
460 }
461
462 void unminimize_control_panel(GtkWidget *wid, vtt_class *vtt)
463 {
464         vtt->hide_control(false);
465 }
466
467 void minimize_audio_panel(GtkWidget *wid, vtt_class *vtt)
468 {
469         vtt->hide_audio(true);
470 }
471
472 void unminimize_audio_panel(GtkWidget *wid, vtt_class *vtt)
473 {
474         vtt->hide_audio(false);
475 }
476
477 void vg_xcontrol_dis(GtkWidget *wid, vtt_class *vtt)
478 {
479         vtt->set_x_input_parameter(NULL);
480 }
481
482 void vg_ycontrol_dis(GtkWidget *wid, vtt_class *vtt)
483 {
484         vtt->set_y_input_parameter(NULL);
485 }
486
487 void vg_xcontrol_set(GtkWidget *wid, tX_seqpar *sp)
488 {
489         vtt_class *vtt=(vtt_class *) sp->vtt;
490         vtt->set_x_input_parameter(sp);
491 }
492
493 void vg_ycontrol_set(GtkWidget *wid, tX_seqpar *sp)
494 {
495         vtt_class *vtt=(vtt_class *) sp->vtt;
496         vtt->set_y_input_parameter(sp);
497 }
498
499 void vg_mouse_mapping_pressed(GtkWidget *wid, vtt_class *vtt) {
500         if (vtt->gui.mouse_mapping_menu) {
501                 gtk_widget_destroy(vtt->gui.mouse_mapping_menu);
502                 vtt->gui.mouse_mapping_menu=NULL;
503         }
504         /* gtk+ seems to cleanup the submenus automatically */
505         
506         vtt->gui.mouse_mapping_menu=gtk_menu_new();
507         GtkWidget *x_item;
508         GtkWidget *y_item;
509         
510         x_item=gtk_menu_item_new_with_label("X-axis (Left <-> Right)");
511         gtk_menu_append(GTK_MENU(vtt->gui.mouse_mapping_menu), x_item);
512         gtk_widget_show(x_item);
513
514         y_item=gtk_menu_item_new_with_label("Y-axis (Up <-> Down)");
515         gtk_menu_append(GTK_MENU(vtt->gui.mouse_mapping_menu), y_item);
516         gtk_widget_show(y_item);
517         
518         vtt->gui.mouse_mapping_menu_x=gtk_menu_new();
519         vtt->gui.mouse_mapping_menu_y=gtk_menu_new();
520         
521         GtkWidget *item;
522         GtkWidget *item_to_activate=NULL;
523         
524         /* Filling the X menu */
525         item = gtk_check_menu_item_new_with_label("Disable");
526         gtk_menu_append(GTK_MENU(vtt->gui.mouse_mapping_menu_x), item);
527         gtk_widget_show(item);
528         gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(vg_xcontrol_dis), vtt);
529         if (vtt->x_par==NULL) item_to_activate=item;
530
531         list <tX_seqpar *> :: iterator sp;
532
533         for (sp=tX_seqpar::all.begin(); sp!=tX_seqpar::all.end(); sp++) {
534                 if (((*sp)->is_mappable) && ((*sp)->vtt) == (void*) vtt) {
535                         item=gtk_check_menu_item_new_with_label((*sp)->get_name());
536                         gtk_menu_append(GTK_MENU(vtt->gui.mouse_mapping_menu_x), item);
537                         gtk_widget_show(item);
538                         gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(vg_xcontrol_set), (void*) (*sp));
539                         
540                         if (vtt->x_par==(*sp)) item_to_activate=item;
541                 }
542         }
543
544         if (item_to_activate) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item_to_activate), TRUE);
545         
546         /* Filling the Y menu */
547         item_to_activate=NULL;
548         
549         item = gtk_check_menu_item_new_with_label("Disable");
550         gtk_menu_append(GTK_MENU(vtt->gui.mouse_mapping_menu_y), item);
551         gtk_widget_show(item);
552         gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(vg_ycontrol_dis), vtt);
553         if (vtt->y_par==NULL) item_to_activate=item;
554
555         for (sp=tX_seqpar::all.begin(); sp!=tX_seqpar::all.end(); sp++) {
556                 if (((*sp)->is_mappable) && ((*sp)->vtt) == (void*) vtt) {
557                         item=gtk_check_menu_item_new_with_label((*sp)->get_name());
558                         gtk_menu_append(GTK_MENU(vtt->gui.mouse_mapping_menu_y), item);
559                         gtk_widget_show(item);
560                         gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(vg_ycontrol_set), (void*) (*sp));
561                         
562                         if (vtt->y_par==(*sp)) item_to_activate=item;
563                 }
564         }
565
566         if (item_to_activate) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item_to_activate), TRUE);
567         
568         gtk_menu_item_set_submenu(GTK_MENU_ITEM(x_item), vtt->gui.mouse_mapping_menu_x);
569         gtk_menu_item_set_submenu(GTK_MENU_ITEM(y_item), vtt->gui.mouse_mapping_menu_y);
570         
571         gtk_menu_popup (GTK_MENU(vtt->gui.mouse_mapping_menu), NULL, NULL, NULL, NULL, 0, 0);
572
573         gtk_signal_emit_by_name(GTK_OBJECT(wid), "released", vtt);
574 }
575
576 void vg_file_button_pressed(GtkWidget *wid, vtt_class *vtt) {
577         if (vtt->gui.file_menu==NULL) {
578                 GtkWidget *item;
579                 
580                 vtt->gui.file_menu=gtk_menu_new();
581                 item=gtk_menu_item_new_with_label("Load audio file");
582                 gtk_menu_append(GTK_MENU(vtt->gui.file_menu), item);
583                 gtk_widget_show(item);
584                 
585                 gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(load_file), vtt);
586                 
587                 item=gtk_menu_item_new_with_label("Edit audio file");
588                 gtk_menu_append(GTK_MENU(vtt->gui.file_menu), item);
589                 gtk_widget_show(item);
590
591                 gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(edit_vtt_buffer), vtt);
592
593                 item=gtk_menu_item_new_with_label("Reload current audio file");
594                 gtk_menu_append(GTK_MENU(vtt->gui.file_menu), item);
595                 gtk_widget_show(item);
596
597                 gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(reload_vtt_buffer), vtt);
598         }
599         
600         gtk_menu_popup(GTK_MENU(vtt->gui.file_menu), NULL, NULL, NULL, NULL, 0,0);
601
602         /* gtk+ is really waiting for this.. */
603         gtk_signal_emit_by_name(GTK_OBJECT(wid), "released", vtt);
604 }
605
606 void vg_adjust_zoom(GtkWidget *wid, vtt_class *vtt) {   
607         GtkAdjustment *adj=gtk_range_get_adjustment(GTK_RANGE(vtt->gui.zoom));
608         gdouble real_value=99-adj->value;
609         
610         real_value/=100;
611         gtk_tx_set_zoom(GTK_TX(vtt->gui.display),  real_value);
612 }
613
614 static gchar* vg_format_zoom(GtkScale *scale, gdouble   value) {
615   return g_strdup_printf ("%g", (gdouble) (99-value));
616 }
617
618 static vtt_class * fx_vtt;
619
620 void new_effect(GtkWidget *wid, LADSPA_Plugin *plugin)
621 {
622         fx_vtt->add_effect(plugin);
623 }
624
625 void fx_button_pressed(GtkWidget *wid, vtt_class *vtt)
626 {
627         vtt_gui *g=&vtt->gui;
628         GtkWidget *item;
629         int i;
630         LADSPA_Plugin *plugin;
631         char buffer[1024];
632         char oldfile[1024]="";
633         GtkWidget *submenu=NULL;
634
635         fx_vtt=vtt; /* AAAAARGH - Long live ugly code */
636
637         if (g->ladspa_menu) gtk_object_destroy(GTK_OBJECT(g->ladspa_menu));
638         g->ladspa_menu=gtk_menu_new();
639         
640         for (i=0; i<LADSPA_Plugin::getPluginCount(); i++)
641         {
642                 plugin=LADSPA_Plugin::getPluginByIndex(i);
643                 if (strcmp(plugin->get_file_name(), oldfile))
644                 {
645                         strcpy(oldfile, plugin->get_file_name());
646                         item = gtk_menu_item_new_with_label(oldfile);
647                         submenu=gtk_menu_new();
648                         gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
649                         gtk_menu_append(GTK_MENU(g->ladspa_menu), item);
650                         gtk_widget_show(item);
651                 }
652                 sprintf(buffer, "%s - [%li, %s]", plugin->getName(), plugin->getUniqueID(), plugin->getLabel());
653                 item=gtk_menu_item_new_with_label(buffer);
654                 gtk_menu_append(GTK_MENU(submenu), item);
655                 gtk_widget_show(item);
656                 gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(new_effect), plugin);
657         }
658         
659         gtk_menu_popup (GTK_MENU(g->ladspa_menu), NULL, NULL, NULL, NULL, 0, 0);
660
661         /* gtk+ is really waiting for this.. */
662         gtk_signal_emit_by_name(GTK_OBJECT(wid), "released", vtt);
663 }
664
665 #define connect_entry(wid, func); gtk_signal_connect(GTK_OBJECT(g->wid), "activate", (GtkSignalFunc) func, (void *) vtt);
666 #define connect_adj(wid, func); gtk_signal_connect(GTK_OBJECT(g->wid), "value_changed", (GtkSignalFunc) func, (void *) vtt);
667 #define connect_button(wid, func); gtk_signal_connect(GTK_OBJECT(g->wid), "clicked", (GtkSignalFunc) func, (void *) vtt);
668 #define connect_range(wid, func); gtk_signal_connect(GTK_OBJECT(gtk_range_get_adjustment(GTK_RANGE(g->wid))), "value_changed", (GtkSignalFunc) func, (void *) vtt);
669 #define connect_scale_format(wid, func); gtk_signal_connect(GTK_OBJECT(g->wid), "format-value", (GtkSignalFunc) func, (void *) vtt);
670 #define connect_press_button(wid, func); gtk_signal_connect(GTK_OBJECT(g->wid), "pressed", (GtkSignalFunc) func, (void *) vtt);
671 #define connect_rel_button(wid, func); gtk_signal_connect(GTK_OBJECT(g->wid), "released", (GtkSignalFunc) func, (void *) vtt);
672
673 GtkWidget *vg_create_fx_bar(vtt_class *vtt, vtt_fx *effect, int showdel);
674
675 void gui_connect_signals(vtt_class *vtt)
676 {
677         vtt_gui *g=&vtt->gui;
678
679         connect_entry(name, name_changed);
680         connect_adj(volume, volume_changed);
681         connect_adj(pitch, pitch_changed);
682         connect_adj(pan, pan_changed);
683         connect_press_button(file, vg_file_button_pressed);
684         
685         connect_button(del, delete_vtt);
686         connect_button(trigger, trigger_vtt);
687         connect_button(stop, stop_vtt);
688         connect_button(autotrigger, autotrigger_toggled);
689         connect_button(loop, loop_toggled);
690         connect_button(sync_master, master_setup);
691         connect_button(sync_client, client_setup);
692         connect_adj(cycles, client_setup_number);
693         connect_press_button(fx_button, fx_button_pressed);
694         
695         connect_button(lp_enable, lp_enabled);
696         connect_adj(lp_gain, lp_gain_changed);
697         connect_adj(lp_reso, lp_reso_changed);
698         connect_adj(lp_freq, lp_freq_changed);
699         
700         connect_button(ec_enable, ec_enabled);
701         connect_adj(ec_length, ec_length_changed);
702         connect_adj(ec_feedback, ec_feedback_changed);
703         connect_adj(ec_pan, ec_pan_changed);
704         connect_adj(ec_volume, ec_volume_changed);      
705         connect_range(zoom, vg_adjust_zoom);
706         connect_scale_format(zoom, vg_format_zoom);
707         connect_press_button(mouse_mapping, vg_mouse_mapping_pressed);
708         connect_button(control_minimize, minimize_control_panel);
709         connect_button(audio_minimize, minimize_audio_panel);
710
711         static GtkTargetEntry drop_types [] = {
712                 { "text/uri-list", 0, 0}
713         };
714         static gint n_drop_types = sizeof (drop_types) / sizeof(drop_types[0]);
715         
716         gtk_drag_dest_set (GTK_WIDGET (g->file), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
717                         drop_types, n_drop_types,
718                         GDK_ACTION_COPY);
719                                                 
720         gtk_signal_connect (GTK_OBJECT (g->file), "drag_data_received",
721                         GTK_SIGNAL_FUNC(drop_file), (void *) vtt);
722
723         gtk_drag_dest_set (GTK_WIDGET (g->display), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
724                         drop_types, n_drop_types,
725                         GDK_ACTION_COPY);
726                                                 
727         gtk_signal_connect (GTK_OBJECT (g->display), "drag_data_received",
728                         GTK_SIGNAL_FUNC(drop_file), (void *) vtt);
729         
730 }
731         
732 void build_vtt_gui(vtt_class *vtt)
733 {
734         GtkWidget *tempbox;
735         GtkWidget *tempbox2;
736         GtkWidget *tempbox3;
737         GtkWidget *dummy;
738         char nice_name[FILENAME_BUTTON_MAX];
739         
740         vtt_gui *g;
741         
742         g=&vtt->gui;
743         vtt->have_gui=1;
744         g->par_menu=NULL;
745         g->ladspa_menu=NULL;
746
747         /* Building Audio Box */
748         g->audio_box=gtk_vbox_new(FALSE,2);
749         gtk_widget_show(g->audio_box);
750         
751         tempbox2=gtk_hbox_new(FALSE,2);
752         gtk_widget_show(tempbox2);
753         gtk_box_pack_start(GTK_BOX(g->audio_box), tempbox2, WID_FIX);
754         
755         tempbox=gtk_hbox_new(TRUE,2);
756         gtk_widget_show(tempbox);
757         gtk_box_pack_start(GTK_BOX(tempbox2), tempbox, WID_DYN);
758
759         GtkWidget *pixmap;
760         g->audio_minimize=gtk_button_new();
761         pixmap=tx_pixmap_widget(TX_ICON_MINIMIZE_PANEL);
762         gtk_container_add (GTK_CONTAINER (g->audio_minimize), pixmap);  
763         gtk_box_pack_end(GTK_BOX(tempbox2), g->audio_minimize, WID_FIX);
764         gtk_widget_show(pixmap);
765         gtk_widget_show(g->audio_minimize);
766
767
768         g->audio_label=gtk_label_new(vtt->name);
769         gtk_misc_set_alignment(GTK_MISC(g->audio_label), 0.025, 0.5);
770         gtk_widget_show(g->audio_label);
771         gtk_box_pack_start(GTK_BOX(tempbox), g->audio_label, WID_DYN);
772
773         nicer_filename(nice_name, vtt->filename);
774         g->file = gtk_button_new_with_label(nice_name);
775         gtk_widget_show(g->file);
776         gui_set_tooltip(g->file, "Click to Load/Edit/Reload a sample for this turntable. To load you can also drag a file and drop it over this button or the sound data display below.");
777         gtk_box_pack_start(GTK_BOX(tempbox), g->file, WID_DYN);
778
779         g->mouse_mapping=gtk_button_new_with_label("Mouse Mapping");
780         gtk_widget_show(g->mouse_mapping);
781         gui_set_tooltip(g->mouse_mapping, "Determines what parameters should be affected on mouse moition in mouse grab mode.");
782    
783         gtk_box_pack_start(GTK_BOX(tempbox), g->mouse_mapping, WID_DYN);
784
785         tempbox=gtk_hbox_new(FALSE, 2);
786
787         g->display=gtk_tx_new(vtt->buffer, vtt->samples_in_buffer);
788         gtk_box_pack_start(GTK_BOX(tempbox), g->display, WID_DYN);
789         gtk_widget_show(g->display);    
790         
791         g->zoom=gtk_vscale_new_with_range(0,99.0,1.0);
792         gtk_scale_set_draw_value(GTK_SCALE(g->zoom), TRUE);
793         gtk_scale_set_digits(GTK_SCALE(g->zoom), 0);
794         gtk_scale_set_value_pos(GTK_SCALE(g->zoom), GTK_POS_BOTTOM);
795         gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(g->zoom)), 99);
796         gui_set_tooltip(g->zoom, "Set the zoom-level for the audio data display.");
797         gtk_box_pack_start(GTK_BOX(tempbox), g->zoom, WID_FIX);
798         gtk_widget_show(g->zoom);
799         
800         gtk_box_pack_start(GTK_BOX(g->audio_box), tempbox, WID_DYN);
801         gtk_widget_show(tempbox);
802         
803         /* Building Control Box */
804         
805         g->control_box=gtk_vbox_new(FALSE,2);
806         gtk_widget_show(g->control_box);
807
808         tempbox2=gtk_hbox_new(FALSE, 2);
809         gtk_widget_show(tempbox2);
810         gtk_box_pack_start(GTK_BOX(g->control_box), tempbox2, WID_FIX);
811
812         g->control_label=gtk_label_new(vtt->name);
813         gtk_widget_show(g->control_label);
814         gtk_box_pack_start(GTK_BOX(tempbox2), g->control_label, WID_DYN);
815
816         g->control_minimize=gtk_button_new();
817         pixmap=tx_pixmap_widget(TX_ICON_MINIMIZE_PANEL);
818         gtk_container_add (GTK_CONTAINER (g->control_minimize), pixmap);        
819         gtk_box_pack_end(GTK_BOX(tempbox2), g->control_minimize, WID_FIX);
820         gtk_widget_show(pixmap);
821         gtk_widget_show(g->control_minimize);
822
823         g->scrolled_win=gtk_scrolled_window_new (NULL, NULL);
824         gtk_container_set_border_width (GTK_CONTAINER (g->scrolled_win), 0);
825         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (g->scrolled_win),
826                                     GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
827         gtk_widget_show(g->scrolled_win);
828         gtk_box_pack_start(GTK_BOX(g->control_box), g->scrolled_win, WID_DYN);
829                                     
830         g->control_subbox=gtk_vbox_new(FALSE,0);
831         gtk_scrolled_window_add_with_viewport (
832                    GTK_SCROLLED_WINDOW (g->scrolled_win), g->control_subbox);
833         gtk_widget_show(g->control_subbox);
834                    
835
836         /* Main panel */
837         
838         tX_panel *p=new tX_panel("Main", g->control_subbox);
839         g->main_panel=p;
840                         
841         g->name = gtk_entry_new_with_max_length(256);   
842         gtk_entry_set_text(GTK_ENTRY(g->name), vtt->name);
843         p->add_client_widget(g->name);
844         gui_set_tooltip(g->name, "Enter the turntable's name here.");
845         gtk_widget_set_usize(g->name, 40, g->name->requisition.height);
846         
847         g->del=gtk_button_new_with_label("Delete");
848         gui_set_tooltip(g->del, "Click here to annihilate this turntable. All events recorded for this turntable will be erased, too.");
849         p->add_client_widget(g->del);
850         
851         gtk_box_pack_start(GTK_BOX(g->control_subbox), p->get_widget(), WID_FIX);
852                                 
853         p=new tX_panel("Trigger", g->control_subbox);
854         g->trigger_panel=p;
855         
856         g->trigger=gtk_button_new_with_label("Trigger!");
857         gui_set_tooltip(g->trigger, "Click here to trigger this turntable right now. If the audio engine is disabled this turntable will be triggerd as soon as the engine is turned on.");
858         p->add_client_widget(g->trigger);
859         
860         g->stop=gtk_button_new_with_label("Stop.");
861         gui_set_tooltip(g->stop, "Stop this turntable's playback.");
862         p->add_client_widget(g->stop);
863         
864         g->autotrigger=gtk_check_button_new_with_label("Auto");
865         p->add_client_widget(g->autotrigger);
866         gui_set_tooltip(g->autotrigger, "If turned on, this turntable will be automagically triggered whenever the audio engine is turned on.");
867         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->autotrigger), vtt->autotrigger);
868         
869         g->loop=gtk_check_button_new_with_label("Loop");
870         p->add_client_widget(g->loop);
871         gui_set_tooltip(g->loop, "Enable this option to make the turntable loop the audio data.");
872         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->loop), vtt->loop);
873         
874         g->sync_master=gtk_check_button_new_with_label("Master");
875         p->add_client_widget(g->sync_master);
876         gui_set_tooltip(g->sync_master, "Click here to make this turntable the sync-master. All turntables marked as sync-clients will be (re-)triggered in relation to the sync-master. Note that only *one* turntable can be the sync-master.");
877         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->sync_master), vtt->is_sync_master);
878         
879         g->sync_client=gtk_check_button_new_with_label("Client");
880         p->add_client_widget(g->sync_client);
881         gui_set_tooltip(g->sync_client, "If enabled this turntable will be (re-)triggerd in relation to the sync-master turntable.");
882         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->sync_client), vtt->is_sync_client);
883         
884         g->cycles=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->sync_cycles, 0, 10.0, 1,1,1));
885         dummy=gtk_spin_button_new(g->cycles, 1.0, 0);
886         p->add_client_widget(dummy);
887         gui_set_tooltip(dummy, "Determines how often a sync-client turntable gets triggered. 0 -> this turntable will be triggered with every trigger of the sync-master table, 1 -> the table will be triggered every 2nd master trigger and so on.");
888
889         gtk_box_pack_start(GTK_BOX(g->control_subbox), p->get_widget(), WID_FIX);
890
891         dummy=gtk_button_new_with_label("FX");
892         gtk_widget_show(dummy);
893         g->fx_button=dummy;
894         gui_set_tooltip(g->fx_button, "Click here to load a LADSPA plugin. You will get a menu from which you can choose which plugin to load.");
895         gtk_box_pack_start(GTK_BOX(g->control_subbox), dummy, WID_FIX);
896         
897         /* Lowpass Panel */
898
899         p=new tX_panel("Lowpass", g->control_subbox);
900         g->lp_panel=p;
901                 
902         g->lp_enable=gtk_check_button_new_with_label("Enable");
903         gui_set_tooltip(g->lp_enable, "Click here to enable the built-in lowpass effect.");
904         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->lp_enable), vtt->lp_enable);
905         p->add_client_widget(vg_create_fx_bar(vtt, vtt->lp_fx, 0));
906
907         p->add_client_widget(g->lp_enable);
908
909         g->lp_gain=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->lp_gain, 0, 2, 0.1, 0.01, 0.01));
910         g->lp_reso=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->lp_reso, 0, 0.99, 0.1, 0.01, 0.01));
911         g->lp_freq=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->lp_freq, 0, 1, 0.1, 0.01, 0.01));
912
913         g->lp_gaind=new tX_extdial("Input Gain", g->lp_gain);
914         p->add_client_widget(g->lp_gaind->get_widget());
915         gui_set_tooltip(g->lp_gaind->get_entry(), "Adjust the input gain. with this parameter you can either amplify or damp the input-signal for the lowpass effect.");
916
917         g->lp_freqd=new tX_extdial("Frequency", g->lp_freq);
918         p->add_client_widget(g->lp_freqd->get_widget());
919         gui_set_tooltip(g->lp_freqd->get_entry(), "Adjust the cutoff frequency of the lowpass filter. 0 is 0 Hz, 1 is 22.1 kHz.");
920
921         g->lp_resod=new tX_extdial("Resonance", g->lp_reso);
922         p->add_client_widget(g->lp_resod->get_widget());
923         gui_set_tooltip(g->lp_resod->get_entry(), "Adjust the resonance of the lowpass filter. This value determines how much the signal at the cutoff frequency will be amplified.");
924
925         gtk_box_pack_start(GTK_BOX(g->control_subbox), p->get_widget(), WID_FIX);
926
927         /* Echo Panel */
928
929         p=new tX_panel("Echo", g->control_subbox);
930         g->ec_panel=p;
931
932         p->add_client_widget(vg_create_fx_bar(vtt, vtt->ec_fx, 0));
933         
934         g->ec_enable=gtk_check_button_new_with_label("Enable");
935         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->ec_enable), vtt->ec_enable);
936         p->add_client_widget(g->ec_enable);
937         gui_set_tooltip(g->ec_enable, "Enable the built-in echo effect.");
938
939         g->ec_length=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->ec_length, 0, 1, 0.1, 0.01, 0.001));
940         g->ec_feedback=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->ec_feedback, 0, 1, 0.1, 0.01, 0.001));
941         g->ec_pan=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->ec_pan, -1.0, 1, 0.1, 0.01, 0.001));
942         g->ec_volume=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->ec_volume, 0.0, 3.0, 0.1, 0.01, 0.001));
943
944         g->ec_lengthd=new tX_extdial("Duration", g->ec_length);
945         p->add_client_widget(g->ec_lengthd->get_widget());
946         gui_set_tooltip(g->ec_lengthd->get_entry(), "Adjust the length of the echo buffer.");
947
948         g->ec_feedbackd=new tX_extdial("Feedback", g->ec_feedback);
949         p->add_client_widget(g->ec_feedbackd->get_widget());
950         gui_set_tooltip(g->ec_feedbackd->get_entry(), "Adjust the feedback of the echo effect. Note that a value of 1 will result in a constant signal.");
951
952         g->ec_volumed=new tX_extdial("Volume", g->ec_volume);
953         p->add_client_widget(g->ec_volumed->get_widget());
954         gui_set_tooltip(g->ec_volumed->get_entry(), "Adjust the volume of the echo effect.");
955
956         g->ec_pand=new tX_extdial("Pan", g->ec_pan);
957         p->add_client_widget(g->ec_pand->get_widget());
958         gui_set_tooltip(g->ec_pand->get_entry(), "Adjust the panning of the echo effect.");
959
960         gtk_box_pack_start(GTK_BOX(g->control_subbox), p->get_widget(), WID_FIX);
961         
962         /* Output */
963         
964         tempbox=gtk_hbox_new(FALSE,2);
965         gtk_widget_show(tempbox);
966         gtk_box_pack_end(GTK_BOX(g->control_box), tempbox, WID_FIX);
967         
968         tempbox2=gtk_vbox_new(FALSE,0);
969         gtk_widget_show(tempbox2);
970         gtk_box_pack_start(GTK_BOX(tempbox), tempbox2, WID_FIX);
971         
972         g->pitch=GTK_ADJUSTMENT(gtk_adjustment_new(vtt->rel_pitch, -3, +3, 0.1, 0.01, 0.001));
973         g->pan=GTK_ADJUSTMENT(gtk_adjustment_new(0, -1, 1, 0.1, 0.01, 0.001));
974
975         g->pitchd=new tX_extdial("Pitch", g->pitch);
976         gui_set_tooltip(g->pitchd->get_entry(), "Adjust this turntable's pitch.");
977
978         gtk_box_pack_start(GTK_BOX(tempbox2), g->pitchd->get_widget(), WID_FIX);
979
980         g->pand=new tX_extdial("Pan", g->pan);
981         gtk_box_pack_start(GTK_BOX(tempbox2), g->pand->get_widget(), WID_FIX);
982         gui_set_tooltip(g->pand->get_entry(), "Specifies the position of this turntable within the stereo spectrum: -1 -> left, 0-> center, 1->right.");
983
984         tempbox3=gtk_hbox_new(FALSE,2);
985         gtk_widget_show(tempbox3);
986
987         g->mute=gtk_check_button_new_with_label("M");
988         gtk_box_pack_start(GTK_BOX(tempbox3), g->mute, WID_FIX);
989         gtk_signal_connect(GTK_OBJECT(g->mute),"clicked", (GtkSignalFunc) mute_volume, vtt);
990         gtk_widget_show(g->mute);
991         gui_set_tooltip(g->mute, "Mute this turntable's mixer output.");
992
993         g->solo=gtk_check_button_new_with_label("S");
994         gtk_box_pack_start(GTK_BOX(tempbox3), g->solo, WID_FIX);
995         gtk_signal_connect(GTK_OBJECT(g->solo),"clicked", (GtkSignalFunc) solo_vtt, vtt);
996         gtk_widget_show(g->solo);
997         gui_set_tooltip(g->mute, "Allow only this and other solo-switched turntabels' signal to be routed to the mixer.");
998
999         gtk_box_pack_start(GTK_BOX(tempbox2), tempbox3, WID_FIX);
1000
1001         tempbox2=gtk_hbox_new(FALSE,0);
1002         gtk_widget_show(tempbox2);
1003         gtk_box_pack_start(GTK_BOX(tempbox), tempbox2, WID_FIX);
1004         
1005         g->volume=GTK_ADJUSTMENT(gtk_adjustment_new(2.0-vtt->rel_volume, 0, 2, 0.01, 0.01, 0.01));
1006         dummy=gtk_vscale_new(GTK_ADJUSTMENT(g->volume)); 
1007         gtk_scale_set_draw_value(GTK_SCALE(dummy), False);
1008         gui_set_tooltip(dummy, "Adjust this turntable's volume.");
1009
1010         gtk_box_pack_start(GTK_BOX(tempbox2), dummy, WID_FIX);
1011         gtk_widget_show(dummy);
1012
1013         g->flash=gtk_tx_flash_new();
1014         gtk_box_pack_start(GTK_BOX(tempbox2), g->flash, WID_FIX);
1015         gtk_widget_show(g->flash);              
1016
1017         g->file_dialog=NULL;
1018
1019         gui_connect_signals(vtt);
1020         
1021         g->audio_minimized_panel_bar_button=NULL;
1022         g->control_minimized_panel_bar_button=NULL;
1023         g->file_menu=NULL;
1024         g->mouse_mapping_menu=NULL;
1025         g->mouse_mapping_menu_x=NULL;
1026         g->mouse_mapping_menu_y=NULL;
1027 }
1028
1029 void fx_up(GtkWidget *wid, vtt_fx *effect)
1030 {
1031         vtt_class *vtt;
1032         
1033         vtt=(vtt_class*)effect->get_vtt();
1034         vtt->effect_up(effect);
1035 }
1036
1037 void fx_down(GtkWidget *wid, vtt_fx *effect)
1038 {
1039         vtt_class *vtt;
1040         
1041         vtt=(vtt_class*)effect->get_vtt();
1042         vtt->effect_down(effect);
1043 }
1044
1045 void fx_kill(GtkWidget *wid, vtt_fx_ladspa *effect)
1046 {
1047         vtt_class *vtt;
1048         
1049         vtt=(vtt_class*)effect->get_vtt();
1050         vtt->effect_remove(effect);
1051 }
1052
1053 GtkWidget *vg_create_fx_bar(vtt_class *vtt, vtt_fx *effect, int showdel)
1054 {
1055         GtkWidget *box;
1056         GtkWidget *pixmap;
1057         GtkWidget *button;
1058         
1059         box=gtk_hbox_new(FALSE,0);
1060
1061         if (showdel)
1062         {
1063                 button=gtk_button_new();
1064                 pixmap=tx_pixmap_widget(TX_ICON_FX_CLOSE);
1065                 gtk_container_add (GTK_CONTAINER (button), pixmap);     
1066                 gtk_box_pack_end(GTK_BOX(box), button, WID_FIX);
1067                 gtk_widget_show(pixmap);
1068                 gtk_widget_show(button);
1069                 gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) fx_kill, (void *) effect);
1070         }
1071
1072         button=gtk_button_new();
1073         pixmap=tx_pixmap_widget(TX_ICON_FX_DOWN);
1074         gtk_container_add (GTK_CONTAINER (button), pixmap);     
1075         gtk_box_pack_end(GTK_BOX(box), button, WID_FIX);
1076         gtk_widget_show(pixmap);
1077         gtk_widget_show(button);
1078         gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) fx_down, (void *) effect);
1079
1080         button=gtk_button_new();
1081         pixmap=tx_pixmap_widget(TX_ICON_FX_UP);
1082         gtk_container_add (GTK_CONTAINER (button), pixmap);     
1083         gtk_box_pack_end(GTK_BOX(box), button, WID_FIX);
1084         gtk_widget_show(pixmap);
1085         gtk_widget_show(button);
1086         gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) fx_up, (void *) effect);
1087         
1088         gtk_widget_show(box);
1089         
1090         return box;
1091 }
1092
1093
1094 int gtk_box_get_widget_pos(GtkBox *box, GtkWidget *child)
1095 {
1096         int i=0;
1097         GList *list;
1098  
1099         list = box->children;
1100         while (list)
1101         {
1102                 GtkBoxChild *child_info;
1103                 child_info = (GtkBoxChild *) list->data;
1104                 if (child_info->widget == child)
1105                 break;
1106                 list = list->next; i++;
1107         }
1108         return i;
1109 }
1110
1111 void vg_move_fx_panel_up(GtkWidget *wid, vtt_class *vtt)
1112 {
1113         int pos=gtk_box_get_widget_pos(GTK_BOX(vtt->gui.control_subbox), wid);
1114         gtk_box_reorder_child(GTK_BOX(vtt->gui.control_subbox), wid, pos-1);
1115 }
1116
1117 void vg_move_fx_panel_down(GtkWidget *wid, vtt_class *vtt)
1118 {
1119         int pos=gtk_box_get_widget_pos(GTK_BOX(vtt->gui.control_subbox), wid);
1120         gtk_box_reorder_child(GTK_BOX(vtt->gui.control_subbox), wid, pos+1);
1121 }
1122
1123 void vg_show_fx_info(GtkWidget *wid, vtt_fx *effect)
1124 {
1125         tx_l_note(effect->get_info_string());
1126 }
1127
1128 void vg_create_fx_gui(vtt_class *vtt, vtt_fx_ladspa *effect, LADSPA_Plugin *plugin)
1129 {
1130         char buffer[1024];
1131         
1132         vtt_gui *g;
1133         g=&vtt->gui;    
1134         tX_panel *p;
1135         list <tX_seqpar_vttfx *> :: iterator sp;
1136         
1137         strcpy(buffer, plugin->getLabel());
1138         if (strlen(buffer) > 6)
1139         {
1140                 buffer[5]='.';
1141                 buffer[6]='.';
1142                 buffer[7]='.';
1143                 buffer[8]=0;
1144         }
1145
1146         p=new tX_panel(buffer, g->control_subbox);
1147         
1148         p->add_client_widget(vg_create_fx_bar(vtt, effect, 1));
1149         
1150         for (sp = effect->controls.begin(); sp != effect->controls.end(); sp++)
1151         {
1152                         p->add_client_widget((*sp)->get_widget());
1153         }
1154
1155         gtk_signal_connect(GTK_OBJECT(p->get_labelbutton()), "clicked", (GtkSignalFunc) vg_show_fx_info, (void *) effect);
1156         gui_set_tooltip(p->get_labelbutton(), "Click here to learn more about this plugin.");
1157         effect->set_panel_widget(p->get_widget());
1158         effect->set_panel(p);
1159
1160         gtk_box_pack_start(GTK_BOX(g->control_subbox), p->get_widget(), WID_FIX);
1161 }
1162
1163 void gui_set_name(vtt_class *vtt, char *newname)
1164 {
1165         gtk_label_set_text(GTK_LABEL(vtt->gui.audio_label), newname);
1166         gtk_label_set_text(GTK_LABEL(vtt->gui.control_label), newname);
1167         gtk_entry_set_text(GTK_ENTRY(vtt->gui.name), newname);
1168         
1169         if (vtt->gui.audio_minimized_panel_bar_button!=NULL) {
1170                 gtk_label_set_text(GTK_LABEL(vtt->gui.audio_minimized_panel_bar_label), newname);
1171         }
1172
1173         if (vtt->gui.control_minimized_panel_bar_button!=NULL) {
1174                 gtk_label_set_text(GTK_LABEL(vtt->gui.control_minimized_panel_bar_label), newname);
1175         }
1176 }
1177
1178 void gui_set_filename (vtt_class *vtt, char *newname)
1179 {
1180         gtk_button_set_label(GTK_BUTTON(vtt->gui.file), newname);
1181 }
1182
1183 void gui_update_display(vtt_class *vtt)
1184 {
1185         nicer_filename(global_filename_buffer, vtt->filename);
1186         gtk_button_set_label(GTK_BUTTON(vtt->gui.file), global_filename_buffer);
1187         gtk_tx_set_data(GTK_TX(vtt->gui.display), vtt->buffer, vtt->samples_in_buffer);
1188 }
1189
1190 void gui_hide_control_panel(vtt_class *vtt, bool hide) {
1191         if (hide) {
1192                 gtk_widget_hide(vtt->gui.control_box);
1193                 vtt->gui.control_minimized_panel_bar_button=tx_xpm_button_new(TX_ICON_MIN_CONTROL, vtt->name, 0, &vtt->gui.control_minimized_panel_bar_label);
1194                 gtk_signal_connect(GTK_OBJECT(vtt->gui.control_minimized_panel_bar_button), "clicked", (GtkSignalFunc) unminimize_control_panel, vtt);
1195                 gtk_widget_show(vtt->gui.control_minimized_panel_bar_button);
1196                 add_to_panel_bar(vtt->gui.control_minimized_panel_bar_button);
1197         } else {
1198                 gtk_widget_show(vtt->gui.control_box);
1199                 remove_from_panel_bar(vtt->gui.control_minimized_panel_bar_button);
1200                 gtk_widget_destroy(vtt->gui.control_minimized_panel_bar_button);
1201                 vtt->gui.control_minimized_panel_bar_button=NULL;
1202         }
1203 }
1204
1205 void gui_hide_audio_panel(vtt_class *vtt, bool hide) {
1206         if (hide) {
1207                 gtk_widget_hide(vtt->gui.audio_box);
1208                 vtt->gui.audio_minimized_panel_bar_button=tx_xpm_button_new(TX_ICON_MIN_AUDIO, vtt->name, 0, &vtt->gui.audio_minimized_panel_bar_label);
1209                 gtk_signal_connect(GTK_OBJECT(vtt->gui.audio_minimized_panel_bar_button), "clicked", (GtkSignalFunc) unminimize_audio_panel, vtt);              
1210                 gtk_widget_show(vtt->gui.audio_minimized_panel_bar_button);
1211                 add_to_panel_bar(vtt->gui.audio_minimized_panel_bar_button);
1212         } else {
1213                 gtk_widget_show(vtt->gui.audio_box);
1214                 remove_from_panel_bar(vtt->gui.audio_minimized_panel_bar_button);
1215                 gtk_widget_destroy(vtt->gui.audio_minimized_panel_bar_button);
1216                 vtt->gui.audio_minimized_panel_bar_button=NULL;
1217         }
1218 }
1219
1220 void delete_gui(vtt_class *vtt)
1221 {
1222         if (vtt->gui.control_minimized_panel_bar_button!=NULL) gui_hide_control_panel(vtt, false);
1223         if (vtt->gui.audio_minimized_panel_bar_button!=NULL) gui_hide_audio_panel(vtt, false);
1224
1225         delete vtt->gui.main_panel;
1226         delete vtt->gui.trigger_panel;
1227         
1228         delete vtt->gui.pitchd;
1229         delete vtt->gui.pand;
1230         
1231         delete vtt->gui.lp_gaind;
1232         delete vtt->gui.lp_resod;
1233         delete vtt->gui.lp_freqd;
1234         delete vtt->gui.lp_panel;
1235         
1236         delete vtt->gui.ec_lengthd;
1237         delete vtt->gui.ec_feedbackd;
1238         delete vtt->gui.ec_volumed;
1239         delete vtt->gui.ec_pand;
1240         delete vtt->gui.ec_panel;
1241
1242         gtk_widget_destroy(vtt->gui.control_box);
1243         gtk_widget_destroy(vtt->gui.audio_box);
1244         if (vtt->gui.file_menu) gtk_widget_destroy(vtt->gui.file_menu);
1245         if (vtt->gui.mouse_mapping_menu) gtk_widget_destroy(vtt->gui.mouse_mapping_menu);
1246         if (vtt->gui.ladspa_menu) gtk_widget_destroy(vtt->gui.ladspa_menu);
1247 }
1248
1249 void update_all_vtts()
1250 {
1251         list <vtt_class *> :: iterator vtt;
1252         f_prec temp;
1253         
1254         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++)
1255         {
1256                 if ((*vtt)->is_playing)
1257                 {
1258                         gtk_tx_update_pos_display(GTK_TX((*vtt)->gui.display), (*vtt)->pos_i, (*vtt)->mute);
1259 #ifdef USE_FLASH
1260                         temp=(*vtt)->max_value*(*vtt)->res_volume*vtt_class::vol_channel_adjust;
1261                         (*vtt)->max_value=0;
1262                         gtk_tx_flash_set_level((*vtt)->gui.flash, temp);
1263 #endif          
1264                 }
1265         }
1266 }
1267
1268 void cleanup_vtt(vtt_class *vtt)
1269 {
1270                 gtk_tx_cleanup_pos_display(GTK_TX(vtt->gui.display));   
1271 #ifdef USE_FLASH
1272                 gtk_tx_flash_set_level(vtt->gui.flash, 0.0);
1273                 gtk_tx_flash_clear(vtt->gui.flash);
1274 #endif          
1275 }
1276
1277 void cleanup_all_vtts()
1278 {
1279         list <vtt_class *> :: iterator vtt;
1280         
1281         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++)
1282         {
1283                 if ((*vtt)->buffer) gtk_tx_cleanup_pos_display(GTK_TX((*vtt)->gui.display));
1284 #ifdef USE_FLASH
1285                 gtk_tx_flash_set_level((*vtt)->gui.flash, 0.0);
1286                 gtk_tx_flash_clear((*vtt)->gui.flash);
1287 #endif          
1288         }
1289 }
1290
1291 void gui_clear_master_button(vtt_class *vtt)
1292 {
1293         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vtt->gui.sync_master), 0);
1294 }
1295
1296 void gui_show_frame(vtt_class *vtt, int show)
1297 {
1298         gtk_tx_show_frame(GTK_TX(vtt->gui.display), show);
1299 }
1300
1301 #define vgui (*vtt)->gui
1302 #define v (*vtt)
1303
1304 void vg_enable_critical_buttons(int enable)
1305 {
1306         list <vtt_class *> :: iterator vtt;
1307         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++)
1308         {
1309                 gtk_widget_set_sensitive(vgui.del, enable);
1310                 gtk_widget_set_sensitive(vgui.sync_master, enable);
1311         }
1312 }
1313
1314
1315 void vg_init_all_non_seqpars()
1316 {
1317         list <vtt_class *> :: iterator vtt;
1318         
1319         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++)
1320         {
1321                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON((*vtt)->gui.autotrigger), (*vtt)->autotrigger);
1322                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON((*vtt)->gui.sync_master), (*vtt)->is_sync_master);
1323         }       
1324 }
1325
1326 f_prec gui_get_audio_x_zoom(vtt_class *vtt) {
1327         return gtk_tx_get_zoom(GTK_TX(vtt->gui.display));
1328 }
1329 extern void gui_set_audio_x_zoom(vtt_class *vtt, f_prec value) {
1330         gtk_tx_set_zoom(GTK_TX(vtt->gui.display), value);
1331 }