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