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