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