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