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