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