Adding Dry/Wet controls - Alex
[terminatorX.git] / src / tX_mastergui.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_mastergui.cc
20  
21     Description: This implements the main (aka master) gtk+ GUI of terminatorX
22                  It serves as a container for the vtt-guis.
23 */    
24
25 #include <gtk/gtk.h>
26 #include <gdk/gdkx.h>
27 #include <X11/Xlib.h>
28 #include <math.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <gdk/gdkkeysyms.h>
32 #include "version.h"
33 #include "tX_global.h"
34 #include "tX_engine.h"
35 #include "tX_vttgui.h"
36 #include "tX_vtt.h"
37 #include "tX_flash.h"
38 #include "tX_dialog.h"
39 #include "tX_loaddlg.h"
40 #include "tX_seqpar.h"
41 #include "tX_pbutton.h"
42 #include "tX_sequencer.h"
43 #include "tX_mastergui.h"
44 #include "tX_knobloader.h"
45 #include "tX_glade_interface.h"
46 #include "tX_glade_support.h"
47 #include <sys/time.h>
48 #include <sys/wait.h>
49 #include "tX_midiin.h"
50
51 #ifdef USE_SCHEDULER
52 #include <sys/resource.h>
53 #endif
54
55 #define TX_SET_ID_10 "terminatorX turntable set file - version 1.0 - data:"
56 #define TX_SET_ID_11 "terminatorX turntable set file - version 1.1 - data:"
57 #define TX_SET_ID_12 "terminatorX turntable set file - version 1.2 - data:"
58 #define TX_SET_ID_13 "terminatorX turntable set file - version 1.3 - data:"
59 #define TX_SET_ID_14 "terminatorX turntable set file - version 1.4 - data:"
60
61 int audioon=0;
62 int sequencer_ready=1;
63
64 bool tX_shutdown=false;
65
66 GtkWidget *tt_parent;
67 GtkWidget *control_parent;
68 GtkWidget *audio_parent;
69 GtkWidget *main_window;
70 GtkWidget *grab_button;
71 GtkWidget *main_flash_l;
72 GtkWidget *main_flash_r;
73
74 GtkWidget *seq_rec_btn;
75 GtkWidget *seq_play_btn;
76 GtkWidget *seq_stop_btn;
77 GtkAdjustment *seq_adj;
78 GtkWidget *seq_slider;
79 GtkWidget *seq_entry;
80 GtkWidget *panel_bar;
81
82 int buttons_on_panel_bar=0;
83
84 int seq_adj_care=1;
85 int seq_stop_override=0;
86
87 GtkAdjustment *volume_adj;
88 GtkAdjustment *pitch_adj;
89
90 /* seq-pars */
91 tX_seqpar_master_volume sp_master_volume;
92 tX_seqpar_master_pitch sp_master_pitch;
93
94 GtkWidget *engine_btn;
95
96 GtkWidget *main_menubar;
97 GtkWidget *rec_menu_item;
98 GtkWidget *fullscreen_item;
99
100 int rec_dont_care=0;
101 gint update_tag;
102
103 #define connect_entry(wid, func, ptr); g_signal_connect(G_OBJECT(wid), "activate", (GtkSignalFunc) func, (void *) ptr);
104 #define connect_adj(wid, func, ptr); g_signal_connect(G_OBJECT(wid), "value_changed", (GtkSignalFunc) func, (void *) ptr);
105 #define connect_button(wid, func, ptr); g_signal_connect(G_OBJECT(wid), "clicked", (GtkSignalFunc) func, (void *) ptr);
106
107 Window xwindow;
108 #define WID_DYN TRUE, TRUE, 0
109 #define WID_FIX FALSE, FALSE, 0
110 extern void add_vtt(GtkWidget *ctrl, GtkWidget *audio, char *fn);
111 extern void destroy_gui(vtt_class *vtt);
112 extern void gui_show_frame(vtt_class *vtt, int show);
113
114 GdkWindow *save_dialog_win=NULL;
115 GdkWindow *load_dialog_win=NULL;
116 GtkWidget *save_dialog=NULL;
117 GtkWidget *load_dialog=NULL;
118
119 GdkWindow *rec_dialog_win=NULL;
120 GtkWidget *rec_dialog=NULL;
121
122 GtkWidget *no_of_vtts=NULL;
123 GtkWidget *used_mem=NULL;
124
125 int stop_update=0;
126 int update_delay;
127
128 vtt_class *old_focus=NULL;
129
130 int grab_status=0;
131 int last_grab_status=0;
132
133 GtkWidget *delete_all_item=NULL;
134 GtkWidget *delete_all_vtt_item=NULL;
135
136 GtkTooltips *gui_tooltips=NULL;
137
138 void gui_set_tooltip(GtkWidget *wid, char *tip)
139 {
140         gtk_tooltips_set_tip(gui_tooltips, wid, tip, NULL);
141 }
142
143 void turn_audio_off(void)
144 {
145         if (audioon) {
146                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0);
147                 while (gtk_events_pending()) gtk_main_iteration();              
148         }
149 }
150
151
152 gint pos_update(gpointer data)
153 {
154         f_prec temp;
155
156         if (stop_update) {              
157                 cleanup_all_vtts();
158                 tX_seqpar :: update_all_graphics();
159                 if (old_focus) gui_show_frame(old_focus, 0);
160                 old_focus=NULL;
161                 gtk_tx_flash_clear(main_flash_l);
162                 gtk_tx_flash_clear(main_flash_r);
163                 gdk_flush();    
164                 update_tag=0;
165                 return(FALSE);
166         } else {
167                 update_all_vtts();
168                 
169                 /*left vu meter */
170                 temp=vtt_class::mix_max_l;
171                 vtt_class::mix_max_l=0;
172                 gtk_tx_flash_set_level(main_flash_l, temp);
173
174                 /*right vu meter */
175                 temp=vtt_class::mix_max_r;
176                 vtt_class::mix_max_r=0;
177                 gtk_tx_flash_set_level(main_flash_r, temp);
178                 
179                 if (vtt_class::focused_vtt!=old_focus) {
180                         if (old_focus) gui_show_frame(old_focus, 0);
181                         old_focus=vtt_class::focused_vtt;
182                         if (old_focus) gui_show_frame(old_focus, 1);                    
183                 }
184                 if (grab_status!=last_grab_status) {
185                         last_grab_status=grab_status;
186                         if (!grab_status) {
187                                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(grab_button), 0);
188                         }
189                 }
190                 gdk_flush();    
191                 update_delay--;
192                 
193                 if (update_delay < 0) {
194                         seq_update();
195                         tX_seqpar :: update_all_graphics();
196                         update_delay=globals.update_delay;
197                 }
198                 return(TRUE);
199         }
200 }
201
202 void mg_update_status()
203 {
204         FILE *procfs;
205         pid_t mypid;
206         char filename[PATH_MAX];
207         char buffer[256];
208         int found=0;    
209         int mem;
210         
211         mypid=getpid();
212         sprintf(filename, "/proc/%i/status", mypid);
213         procfs=fopen(filename, "r");
214         if (procfs) {
215                 while((!feof(procfs)) && !found) {
216                         fgets(buffer, 256, procfs);
217                         
218                         if (strncmp("VmSize:", buffer, 7)==0) {
219                                 found=1;
220                                 sscanf(buffer, "VmSize: %i kB", &mem);
221                                 sprintf(buffer, "%i", mem);
222                                 gtk_label_set_text(GTK_LABEL(used_mem), buffer);
223                         }
224                 }
225                 fclose(procfs); 
226         } else {
227                 gtk_label_set_text(GTK_LABEL(used_mem), "");
228         }
229         
230         sprintf(buffer, "%i", vtt_class::vtt_amount);
231         gtk_label_set_text(GTK_LABEL(no_of_vtts), buffer);
232 }
233
234 GtkSignalFunc new_table(GtkWidget *, char *fn)
235 {
236         turn_audio_off();
237                 
238         if (fn) {
239                 ld_create_loaddlg(TX_LOADDLG_MODE_SINGLE, 1);
240                 ld_set_filename(fn);
241         }
242         
243         add_vtt(control_parent, audio_parent, fn);                              
244         
245         if (fn) ld_destroy();           
246         mg_update_status();
247         
248 #ifdef USE_ALSA_MIDI_IN
249         if (globals.auto_assign_midi) tX_midiin::auto_assign_midi_mappings(NULL, NULL);
250 #endif
251         
252         return NULL;
253 }
254
255 bool tx_mg_have_setname=false;
256 char tx_mg_current_setname[PATH_MAX]="";
257
258 GtkSignalFunc new_tables() {
259         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), 
260                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
261                 "Are you sure you want to loose all turntables and events?");
262         
263         int res=gtk_dialog_run(GTK_DIALOG(dialog));
264         gtk_widget_destroy(dialog);
265                 
266         if (res!=GTK_RESPONSE_YES) {
267                 return NULL;
268         }
269
270         vtt_class::delete_all();
271         new_table(NULL, NULL);
272
273 #ifdef USE_ALSA_MIDI_IN
274         if (globals.auto_assign_midi) tX_midiin::auto_assign_midi_mappings(NULL, NULL);
275 #endif
276         
277         gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
278
279         return NULL;
280 }
281
282 /* Loading saved setups */
283
284 GtkSignalFunc cancel_load_tables(GtkWidget *wid)
285 {
286         gtk_widget_destroy(load_dialog);
287         load_dialog=NULL;
288         load_dialog_win=NULL;
289         return(0);
290 }
291
292 void load_tt_part(char * buffer)
293 {
294         char idbuff[256];
295         char wbuf[PATH_MAX];
296         xmlDocPtr doc;
297 #ifdef ENABLE_TX_LEGACY
298         FILE *in;
299 #endif  
300         turn_audio_off();
301         
302         strcpy(globals.tables_filename, buffer);
303         
304         doc = xmlParseFile(buffer);
305         if (doc) {
306                 vtt_class::load_all(doc, buffer);
307                 xmlFreeDoc(doc);
308         } 
309         
310 #ifdef ENABLE_TX_LEGACY
311         else {  
312                 in=fopen(buffer, "r");  
313         
314                 if (in) {
315                         fread(idbuff, strlen(TX_SET_ID_10), 1, in);
316                         if (strncmp(idbuff, TX_SET_ID_10, strlen(TX_SET_ID_10))==0) {
317                                 if (vtt_class::load_all_10(in, buffer)) tx_note("Error while reading set.", true);
318                         } else if (strncmp(idbuff, TX_SET_ID_11, strlen(TX_SET_ID_11))==0)      {
319                                 if (vtt_class::load_all_11(in, buffer)) tx_note("Error while reading set.", true);                      
320                         } else if (strncmp(idbuff, TX_SET_ID_12, strlen(TX_SET_ID_12))==0) {
321                                 if (vtt_class::load_all_12(in, buffer)) tx_note("Error while reading set.", true);                      
322                         } else if (strncmp(idbuff, TX_SET_ID_13, strlen(TX_SET_ID_13))==0) {
323                                 if (vtt_class::load_all_13(in, buffer)) tx_note("Error while reading set.", true);                      
324                         } else if (strncmp(idbuff, TX_SET_ID_14, strlen(TX_SET_ID_14))==0) {
325                                 if (vtt_class::load_all_14(in, buffer)) tx_note("Error while reading set.", true);                      
326                         }       else {
327                                 tx_note("This file is not a terminatorX set-file.", true);
328                                 fclose(in);
329                                 return;
330                         }
331                         fclose(in);     
332                 } else {
333                         strcpy(idbuff, "Failed to access file: \"");    // I'm stealing the unrelated sting for a temp :)
334                         strcat(idbuff, globals.tables_filename);
335                         strcat(idbuff, "\"");
336                         tx_note(idbuff, true);
337                         
338                         return;
339                 }
340         }
341 #else
342         else {
343                 strcpy(idbuff, "Failed to access file: \"");    // I'm stealing the unrelated sting for a temp :)
344                 strcat(idbuff, globals.tables_filename);
345                 strcat(idbuff, "\"");
346                 tx_note(idbuff, true);
347                 
348                 return;
349         }
350 #endif  
351         
352         tx_mg_have_setname=true;
353         strcpy(tx_mg_current_setname, buffer);
354         
355         tX_seqpar :: init_all_graphics();
356         vg_init_all_non_seqpars();
357                 
358         gtk_adjustment_set_value(volume_adj, globals.volume);
359         gtk_adjustment_set_value(pitch_adj, globals.pitch);
360         sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
361 #ifdef USE_ALSA_MIDI_IN
362         if (globals.auto_assign_midi) tX_midiin::auto_assign_midi_mappings(NULL, NULL);
363 #endif  
364         gtk_window_set_title(GTK_WINDOW(main_window), wbuf);            
365 }
366
367 void do_load_tables(GtkWidget *wid)
368 {
369         char buffer[PATH_MAX];
370         
371         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(load_dialog)));
372         
373         gtk_widget_destroy(load_dialog);
374         
375         load_dialog=NULL;
376         load_dialog_win=NULL;
377
378         tX_cursor::set_cursor(tX_cursor::WAIT_CURSOR);
379         load_tt_part(buffer);
380         tX_cursor::reset_cursor();
381 }
382
383 GtkSignalFunc load_tables()
384 {
385         if (load_dialog_win) {
386                 gdk_window_raise(load_dialog_win);
387                 return 0;
388         }
389         
390         load_dialog=gtk_file_selection_new("Load Set"); 
391         
392         gtk_file_selection_show_fileop_buttons(GTK_FILE_SELECTION(load_dialog));
393         gtk_file_selection_complete(GTK_FILE_SELECTION(load_dialog), "*.tX");
394         
395         if (strlen(globals.tables_filename)) {
396                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(load_dialog), globals.tables_filename);
397         }
398         
399         gtk_widget_show(load_dialog);
400         
401         load_dialog_win=load_dialog->window;
402         
403         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(load_dialog)->ok_button), "clicked", G_CALLBACK(do_load_tables), NULL);
404         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(load_dialog)->cancel_button), "clicked", G_CALLBACK (cancel_load_tables), NULL);  
405         g_signal_connect (G_OBJECT(load_dialog), "delete-event", G_CALLBACK(cancel_load_tables), NULL); 
406         
407         return NULL;
408 }
409
410 GtkSignalFunc drop_set(GtkWidget *widget, GdkDragContext *context,
411                 gint x, gint y, GtkSelectionData *selection_data,
412                 guint info, guint time, vtt_class *vtt)
413 {
414         char filename[PATH_MAX];
415         char *fn;
416         
417         strncpy(filename, (char *) selection_data->data, (size_t) selection_data->length);
418         filename[selection_data->length]=0;
419
420         fn = strchr (filename, '\r');
421         *fn=0;  
422         
423         fn = strchr (filename, ':');
424         if (fn) fn++; else fn=(char *) selection_data->data;
425         
426         load_tt_part(fn);
427
428         strcpy (filename, "dont segfault workaround ;)");
429         return NULL;
430 }
431
432
433 /* save tables */
434
435 GtkSignalFunc cancel_save_tables(GtkWidget *wid)
436 {
437         gtk_widget_destroy(save_dialog);
438         save_dialog=NULL;
439         save_dialog_win=NULL;
440         return(0);
441 }
442
443 gboolean do_save_tables(GtkWidget *wid)
444 {
445         FILE *out;
446         gzFile zout;
447         char buffer[PATH_MAX];
448         char wbuf[PATH_MAX];
449         char *ext;
450         
451         if (wid) {
452                 strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(save_dialog)));
453                 int len=strlen(buffer);
454                 if (!len || (buffer[len-1]=='/')) {                     
455                         tx_note("Invalid filename for set file.", true);                        
456                         return FALSE;
457                 }
458                 strcpy(globals.tables_filename, buffer);
459                 gtk_widget_destroy(save_dialog);
460                 save_dialog=NULL;
461                 save_dialog_win=NULL;
462         } else {
463                 strcpy(buffer, tx_mg_current_setname);
464         }
465         
466         ext=strrchr(buffer, '.');
467         
468         if (ext) {
469                 if (strcmp(ext, ".tX")) strcat(buffer, ".tX");
470         } else {
471                 strcat(buffer, ".tX");
472         }
473
474         tx_mg_have_setname=true;
475         strcpy(tx_mg_current_setname, buffer);
476         
477         if (globals.compress_set_files) {
478                 _store_compress_xml=1;
479                 out=NULL;
480                 zout=gzopen(buffer, "w");
481         } else {
482                 _store_compress_xml=0;
483                 out=fopen(buffer, "w");
484                 zout=NULL;
485         }
486         
487         if (out || zout) {
488                 if (vtt_class::save_all(out, zout)) tx_note("Error while saving set.", true);
489                 if (out) fclose(out); 
490                 else if (zout) gzclose(zout);
491                 sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
492                 gtk_window_set_title(GTK_WINDOW(main_window), wbuf);                            
493         } else {
494                 tx_note("Failed to open file for write access.", true);
495         }
496         
497         return FALSE;
498 }
499
500 GtkSignalFunc save_tables_as()
501 {
502         if (save_dialog_win) {
503                 gtk_widget_destroy(save_dialog);
504                 save_dialog=NULL;
505                 save_dialog_win=NULL;
506         }
507         
508         save_dialog=gtk_file_selection_new("Save Set"); 
509
510         if (tx_mg_have_setname) {
511                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(save_dialog), tx_mg_current_setname);
512         }
513         
514         gtk_widget_show(save_dialog);
515         
516         save_dialog_win=save_dialog->window;
517         
518         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(save_dialog)->ok_button), "clicked", G_CALLBACK(do_save_tables), NULL);
519         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(save_dialog)->cancel_button), "clicked", G_CALLBACK (cancel_save_tables), NULL);  
520         g_signal_connect (G_OBJECT(save_dialog), "delete-event", G_CALLBACK(cancel_save_tables), NULL); 
521
522         return NULL;
523 }
524
525 GtkSignalFunc save_tables()
526 {
527         if (!tx_mg_have_setname) {
528                 save_tables_as();
529         } else {
530                 do_save_tables(NULL);
531         }
532         
533         return NULL;
534 }
535
536 GtkSignalFunc master_volume_changed (GtkWidget *wid, void *d)
537 {
538         sp_master_volume.receive_gui_value((float) GTK_ADJUSTMENT(wid)->value);
539         return NULL;    
540 }
541
542 GtkSignalFunc master_pitch_changed(GtkWidget *wid, void *d)
543 {
544         sp_master_pitch.receive_gui_value((float) GTK_ADJUSTMENT(wid)->value);  
545         return NULL;    
546 }
547
548 void mg_enable_critical_buttons(int enable)
549 {
550         gtk_widget_set_sensitive(seq_rec_btn, enable);
551         gtk_widget_set_sensitive(seq_play_btn, enable);
552         gtk_widget_set_sensitive(seq_slider, enable);
553
554         gtk_widget_set_sensitive(rec_menu_item, enable);
555         gtk_widget_set_sensitive(delete_all_item, enable);
556         gtk_widget_set_sensitive(delete_all_vtt_item, enable);
557         
558         vg_enable_critical_buttons(enable);
559 }
560
561
562 GtkSignalFunc seq_stop(GtkWidget *w, void *);
563
564 static bool stop_override=false;
565
566 GtkSignalFunc audio_on(GtkWidget *w, void *d)
567 {
568         tX_engine_error res;
569         
570         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {               
571                 sequencer_ready=0;
572                 mg_enable_critical_buttons(0);
573                 res=tX_engine::get_instance()->run();
574
575                 if (res!=NO_ERROR) {
576                         mg_enable_critical_buttons(1);
577                         stop_override=true;
578                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
579                         stop_override=false;                    
580
581                         switch(res) {
582                                 case ERROR_BUSY:
583                                 tx_note("Error starting engine: engine is already running.", true);
584                                 break;
585                                 case ERROR_AUDIO:
586                                 tx_note("Error starting engine: failed to access audiodevice.\nPlease check the audio device settings in the \"Preferences\" dialog.", true);
587                                 break;
588                                 case ERROR_TAPE:
589                                 tx_note("Error starting engine: failed to open the recording file.", true);
590                                 break;
591                                 default:tx_note("Error starting engine: Unknown error.", true);
592                         }
593                         
594                         return 0;
595                 }
596                 
597                 sequencer_ready=1;
598                 stop_update=0;
599                 audioon=1;
600                 update_delay=globals.update_delay;
601                 update_tag=gtk_timeout_add(globals.update_idle, (GtkFunction) pos_update, NULL);
602                 gtk_widget_set_sensitive(grab_button, 1);
603         } else {        
604                 if (stop_override) return NULL;
605                 if (!sequencer_ready) return NULL;
606                 gtk_widget_set_sensitive(grab_button, 0);
607                 tX_engine::get_instance()->stop();
608                 stop_update=1;
609                 audioon=0;
610                 if (tX_engine::get_instance()->get_recording_request()) {
611                         tX_engine::get_instance()->set_recording_request(false);
612                         rec_dont_care=1;
613                         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(rec_menu_item), 0);
614                         rec_dont_care=0;
615                 }
616                 
617                 seq_stop(NULL, NULL);
618                 mg_enable_critical_buttons(1);
619         }
620         
621         return NULL;
622 }
623
624 GtkSignalFunc cancel_rec(GtkWidget *wid)
625 {
626         gtk_widget_destroy(rec_dialog);
627         rec_dialog=NULL;
628         rec_dialog_win=NULL;
629         rec_dont_care=0;
630         return(0);
631 }
632
633 void do_rec(GtkWidget *wid)
634 {
635         char buffer[PATH_MAX];
636         
637         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(rec_dialog)));
638
639         if (strlen(buffer)) {
640                 strcpy(globals.record_filename, buffer);                
641                 tX_engine::get_instance()->set_recording_request(true);
642                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(rec_menu_item), 1);
643         }
644         
645         rec_dont_care=0;
646         
647         gtk_widget_destroy(rec_dialog);
648         
649         rec_dialog=NULL;
650         rec_dialog_win=NULL;
651 }
652
653 GtkSignalFunc select_rec_file()
654 {
655         if (rec_dialog_win) {
656                 gdk_window_raise(rec_dialog_win);
657                 return 0;
658         }
659         
660         rec_dialog=gtk_file_selection_new("Record To Disk");    
661         
662         if (strlen(globals.record_filename)) {
663                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(rec_dialog), globals.record_filename);
664         }
665         
666         gtk_widget_show(rec_dialog);
667         
668         rec_dialog_win=rec_dialog->window;
669         
670         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(rec_dialog)->ok_button), "clicked", G_CALLBACK(do_rec), NULL);
671         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(rec_dialog)->cancel_button), "clicked", G_CALLBACK (cancel_rec), NULL);   
672         g_signal_connect (G_OBJECT(rec_dialog), "delete-event", G_CALLBACK(cancel_rec), NULL);  
673         
674         return NULL;
675 }
676
677 GtkSignalFunc tape_on(GtkWidget *w, void *d)
678 {
679         if (rec_dont_care) return 0;
680
681         if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))) {   
682                 rec_dont_care=1;
683                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 0);
684                 select_rec_file();
685         } else {
686                         tX_engine::get_instance()->set_recording_request(false);
687         }
688         
689         return NULL;
690 }
691
692 void grab_on(GtkWidget *w, void *d)
693 {
694         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
695                 tX_engine::get_instance()->set_grab_request();
696         }
697         grab_status=1;
698 }
699
700 void grab_off()
701 {
702         grab_status=0;
703 }
704
705 gboolean quit()
706 {       
707         if (globals.quit_confirm) {
708                 GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), 
709                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
710                 "Exit terminatorX and loose all unsaved data?");
711                 
712                 int res=gtk_dialog_run(GTK_DIALOG(dialog));
713                 gtk_widget_destroy(dialog);
714                         
715                 if (res!=GTK_RESPONSE_YES) {
716                         return TRUE;
717                 }
718         }
719         
720         tX_shutdown=true;
721         
722         turn_audio_off();
723         vtt_class::delete_all();
724
725         if (update_tag)
726         gtk_timeout_remove(update_tag);
727         globals.width=main_window->allocation.width;
728         globals.height=main_window->allocation.height;
729
730         gtk_main_quit();
731         
732         return true;
733 }
734
735 void mplcfitx()
736 /* Most Probably Least Called Function In terminatorX :) */
737 {
738         show_about(0);
739 }
740
741 GtkSignalFunc seq_play(GtkWidget *w, void *)
742 {
743         if ((sequencer.is_empty()) &&   (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(seq_rec_btn)))) {
744                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
745                  {
746                         tx_note("Sequencer playback triggered - but no events recorded yet - nothing to playback!\n\nTo perform live with terminatorX just activate the audio engine with the \"Power\" button.");
747                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
748                  }
749         } else {
750                 if (seq_stop_override) return NULL;
751                         
752                 seq_adj_care=0;
753                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
754                 sequencer.trig_play();
755         
756                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 1);
757         }
758         
759         return NULL;
760 }
761
762 GtkSignalFunc seq_stop(GtkWidget *w, void *)
763 {
764         if (!sequencer_ready) return NULL;
765         sequencer.trig_stop();
766         seq_adj_care=1;
767         seq_stop_override=1;
768         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_play_btn), 0);
769         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_rec_btn), 0);
770         while (gtk_events_pending()) gtk_main_iteration();              
771         seq_stop_override=0;
772         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0); 
773         gtk_widget_set_sensitive(seq_slider, 1);        
774         gtk_widget_set_sensitive(engine_btn, 1);
775         gtk_widget_set_sensitive(seq_rec_btn, 1);
776
777         return NULL;
778 }
779
780 GtkSignalFunc seq_rec(GtkWidget *w, void *)
781 {
782         seq_adj_care=0;
783         gtk_widget_set_sensitive(seq_slider, 0);
784
785         if (seq_stop_override) return NULL;
786         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
787         gtk_widget_set_sensitive(engine_btn, 0);
788         gtk_widget_set_sensitive(seq_rec_btn, 0);
789         sequencer.trig_rec();
790         
791         return NULL;
792 }
793
794 void seq_update_entry(const guint32 timestamp)
795 {
796         char buffer[20];
797         guint32 samples;
798         guint32 minu,sec,hun;   
799         guint32 sr;
800         
801         samples=timestamp*vtt_class::get_mix_buffer_size();
802         sr=vtt_class::get_last_sample_rate();
803         
804         if (samples>0) {
805                 minu=samples/(sr*60);
806                 samples-=(sr*60)*minu;
807         
808                 sec=samples/sr;
809                 samples-=sr*sec;
810         
811                 hun=samples/(sr/100);
812         } else {
813                 minu=sec=hun=0;
814         }
815         
816         sprintf(buffer, "%02i:%02i.%02i", minu, sec, hun);
817         gtk_entry_set_text(GTK_ENTRY(seq_entry), buffer);
818 }
819
820 void seq_update()
821 {
822         seq_update_entry(sequencer.get_timestamp());
823         gtk_adjustment_set_value(seq_adj, sequencer.get_timestamp_as_float());
824         
825 }
826 gboolean seq_slider_released(GtkWidget *wid, void *d)
827 {
828         seq_adj_care=0;
829         gtk_widget_set_sensitive(seq_slider, 0);        
830         sequencer.forward_to_start_timestamp(0);
831         gtk_widget_set_sensitive(seq_slider, 1);        
832         seq_adj_care=1;
833         
834         return FALSE;
835 }
836 void sequencer_move(GtkWidget *wid, void *d)
837 {
838         guint32 pos;
839         
840         if (seq_adj_care) {
841                 pos=sequencer.set_start_timestamp((float) GTK_ADJUSTMENT(wid)->value);
842                 seq_update_entry(pos);  
843         }
844 }
845
846 #define add_sep();      dummy=gtk_hseparator_new ();\
847         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);\
848         gtk_widget_show(dummy);\
849
850 #define add_sep2();     dummy=gtk_hseparator_new ();\
851         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);\
852         gtk_widget_show(dummy);\
853
854 void fullscreen_toggle(GtkCheckMenuItem *item, gpointer data);
855 void display_help();
856 void display_browser();
857
858 tX_seqpar *del_sp=NULL;
859 vtt_class *del_vtt=NULL;
860 tx_menu_del_mode menu_del_mode=ALL_EVENTS_ALL_TURNTABLES;
861
862 GtkWidget *del_dialog=NULL;
863
864 GCallback menu_delete_all_events(GtkWidget *, void *param)
865 {       
866         del_dialog=create_tx_del_mode();
867         tX_set_icon(del_dialog);
868         
869         GtkWidget *label=lookup_widget(del_dialog, "delmode_label");
870         
871         menu_del_mode=ALL_EVENTS_ALL_TURNTABLES;
872         
873         gtk_label_set_markup(GTK_LABEL(label), "Delete <b>all</b> events for <b>all</b> turntables.");
874         gtk_widget_show(del_dialog);
875         
876         return NULL;
877 }
878
879 GCallback menu_delete_all_events_for_vtt(GtkWidget *, vtt_class *vtt)
880 {       
881         if (!vtt) {
882                 tX_error("No vtt passed to menu_delete_all_events_for_vtt().");
883                 return FALSE;
884         }
885         
886         char label_str[512];
887         
888         del_dialog=create_tx_del_mode();
889         tX_set_icon(del_dialog);
890
891         del_vtt=vtt;
892         GtkWidget *label=lookup_widget(del_dialog, "delmode_label");
893         
894         menu_del_mode=ALL_EVENTS_FOR_TURNTABLE;
895         
896         sprintf(label_str, "Delete <b>all</b> events for turntable <b>%s</b>.", vtt->name);
897         gtk_label_set_markup(GTK_LABEL(label), label_str);
898         gtk_widget_show(del_dialog);
899         
900         return NULL;
901 }
902
903 GCallback menu_delete_all_events_for_sp(GtkWidget *, tX_seqpar *sp)
904 {       
905         if (!sp) {
906                 tX_error("No sp passed to menu_delete_all_events_for_sp().");
907                 return FALSE;
908         }
909         
910         char label_str[512];
911         
912         del_dialog=create_tx_del_mode();
913         tX_set_icon(del_dialog);
914         
915         GtkWidget *label=lookup_widget(del_dialog, "delmode_label");
916         
917         menu_del_mode=ALL_EVENTS_FOR_SP;
918         del_sp=sp;
919         sprintf(label_str, "Delete all <b>%s</b> events for turntable <b>%s</b>.", sp->get_name(), ((vtt_class *) sp->vtt)->name);
920         gtk_label_set_markup(GTK_LABEL(label), label_str);
921         gtk_widget_show(del_dialog);
922
923         return NULL;
924 }
925
926 static GtkWidget *table_menu=NULL;
927 static GtkWidget *table_menu_item=NULL;
928
929 GCallback create_table_sequencer_menu(GtkWidget *widget, void *param) 
930 {
931         char label[328];
932         table_menu=gtk_menu_new();
933         
934         list <vtt_class *> :: iterator vtt;
935
936         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
937                 GtkWidget *menu_item=gtk_menu_item_new_with_label((*vtt)->name);
938                 gtk_container_add (GTK_CONTAINER (table_menu), menu_item);
939                 gtk_widget_show(menu_item);
940                 
941                 GtkWidget *seqpar_menu=gtk_menu_new();
942                 list <tX_seqpar *> :: iterator sp;
943                 
944                 GtkWidget *all=gtk_menu_item_new_with_label("Delete All Events");
945                 gtk_container_add (GTK_CONTAINER (seqpar_menu), all);
946                 g_signal_connect(all, "activate", (GCallback) menu_delete_all_events_for_vtt, (*vtt));
947                 gtk_widget_show(all);
948
949                 GtkWidget *sep = gtk_menu_item_new ();
950                 gtk_widget_show(sep);
951                 gtk_container_add(GTK_CONTAINER (seqpar_menu), sep);
952                 gtk_widget_set_sensitive (sep, FALSE);
953                 
954                 for (sp=tX_seqpar::all.begin(); sp!=tX_seqpar::all.end(); sp++) {
955                         if ((*sp)->vtt==(*vtt)) {
956                                 sprintf(label, "Delete '%s' Events", (*sp)->get_name());
957                                 GtkWidget *menu_item=gtk_menu_item_new_with_label(label);
958                                 g_signal_connect(menu_item, "activate", (GCallback) menu_delete_all_events_for_sp, (*sp));
959                                 gtk_container_add(GTK_CONTAINER(seqpar_menu), menu_item);
960                                 gtk_widget_show(menu_item);
961                         }
962                 }
963                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), seqpar_menu);
964         }
965         
966         gtk_menu_item_set_submenu(GTK_MENU_ITEM(table_menu_item), table_menu);
967         
968         return NULL;
969 }
970
971 GCallback toggle_confirm_events(GtkWidget *widget, void *dummy)
972 {       
973         globals.confirm_events=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));     
974         return NULL;    
975 }
976
977 GCallback toggle_auto_assign(GtkWidget *widget, void *dummy)
978 {       
979         globals.auto_assign_midi=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
980 #ifdef USE_ALSA_MIDI_IN
981         tX_midiin::auto_assign_midi_mappings(NULL, NULL);
982 #endif
983 /*      if (globals.auto_assign_midi) {
984                 GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), 
985                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO,
986                 "Note: Enabling \"Auto Assign Default MIDI Settings\" will constantly overwrite the\
987 MIDI mappings for the standard parameters. \
988 Are you sure you really want this?");
989                 
990                 int res=gtk_dialog_run(GTK_DIALOG(dialog));
991                 gtk_widget_destroy(dialog);
992                         
993                 if (res!=GTK_RESPONSE_YES) {
994                         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), 0);
995                 }                       
996         } */
997         return NULL;    
998 }
999
1000 void create_master_menu() 
1001 {
1002         GtkWidget *menu_item;
1003         GtkWidget *sub_menu;
1004         GtkAccelGroup* accel_group=gtk_accel_group_new();
1005         gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group);
1006
1007         /* FILE */
1008         menu_item = gtk_menu_item_new_with_mnemonic ("_File");
1009         gtk_widget_show (menu_item);
1010         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1011
1012         sub_menu = gtk_menu_new ();
1013         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1014
1015         menu_item = gtk_image_menu_item_new_from_stock ("gtk-new", accel_group);
1016         gtk_widget_show (menu_item);
1017         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1018         g_signal_connect(menu_item, "activate", (GCallback) new_tables, NULL);
1019
1020         menu_item = gtk_image_menu_item_new_from_stock ("gtk-open", accel_group);
1021         gtk_widget_show (menu_item);
1022         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1023         g_signal_connect(menu_item, "activate", (GCallback) load_tables, NULL);
1024
1025         menu_item = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
1026         gtk_widget_show (menu_item);
1027         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1028         g_signal_connect(menu_item, "activate", (GCallback) save_tables, NULL);
1029
1030         menu_item = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
1031         gtk_widget_show (menu_item);
1032         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1033         g_signal_connect(menu_item, "activate", (GCallback) save_tables_as, NULL);
1034
1035         menu_item = gtk_menu_item_new ();
1036         gtk_widget_show (menu_item);
1037         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1038         gtk_widget_set_sensitive (menu_item, FALSE);
1039
1040         menu_item = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
1041         gtk_widget_show (menu_item);
1042         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1043         g_signal_connect(menu_item, "activate", (GCallback) quit, NULL);
1044
1045         /* Turntables */
1046         menu_item = gtk_menu_item_new_with_mnemonic ("_Turntables");
1047         gtk_widget_show (menu_item);
1048         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1049         
1050         sub_menu = gtk_menu_new ();
1051         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1052
1053         menu_item = gtk_menu_item_new_with_mnemonic("_Add Turntable");
1054         gtk_widget_show (menu_item);
1055         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1056         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_A, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);    
1057         g_signal_connect(menu_item, "activate", (GCallback) new_table, NULL);
1058
1059         menu_item = gtk_menu_item_new ();
1060         gtk_widget_show (menu_item);
1061         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1062         gtk_widget_set_sensitive (menu_item, FALSE);
1063
1064         menu_item = gtk_menu_item_new_with_mnemonic("Assign _Default MIDI Mappings");
1065         gtk_widget_show (menu_item);
1066         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1067         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_M, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
1068
1069 #ifdef USE_ALSA_MIDI_IN
1070         g_signal_connect(menu_item, "activate", G_CALLBACK(tX_midiin::auto_assign_midi_mappings), (void *) true);
1071 #else
1072         gtk_widget_set_sensitive(menu_item, FALSE);
1073 #endif
1074
1075         menu_item = gtk_check_menu_item_new_with_mnemonic("A_uto Assign Default MIDI Mappings");
1076         gtk_widget_show (menu_item);
1077         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1078         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), globals.auto_assign_midi);
1079 #ifdef USE_ALSA_MIDI_IN 
1080         g_signal_connect(menu_item, "activate", (GCallback) toggle_auto_assign, NULL);
1081 #else
1082         gtk_widget_set_sensitive(menu_item, FALSE);
1083 #endif
1084
1085         menu_item = gtk_menu_item_new_with_mnemonic("_Clear MIDI Mappings");
1086         gtk_widget_show (menu_item);
1087         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1088         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_C, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
1089
1090 #ifdef USE_ALSA_MIDI_IN
1091         g_signal_connect(menu_item, "activate", G_CALLBACK(tX_midiin::clear_midi_mappings), (void *) true);
1092 #else
1093         gtk_widget_set_sensitive(menu_item, FALSE);
1094 #endif
1095
1096         menu_item = gtk_menu_item_new ();
1097         gtk_widget_show (menu_item);
1098         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1099         gtk_widget_set_sensitive (menu_item, FALSE);
1100
1101         menu_item = gtk_check_menu_item_new_with_mnemonic("_Record Audio To Disk");
1102         rec_menu_item = menu_item;
1103         gtk_widget_show (menu_item);
1104         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1105         g_signal_connect(menu_item, "activate", (GCallback) tape_on, NULL);
1106
1107         /* Sequencer */
1108         
1109         menu_item = gtk_menu_item_new_with_mnemonic("_Sequencer");
1110         gtk_widget_show (menu_item);
1111         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1112
1113         sub_menu = gtk_menu_new ();
1114         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1115                 
1116         table_menu = gtk_menu_new();
1117         menu_item = gtk_menu_item_new_with_mnemonic("Delete _Events");
1118         delete_all_vtt_item = menu_item;
1119         table_menu_item = menu_item;
1120         gtk_menu_item_set_submenu(GTK_MENU_ITEM(table_menu_item), table_menu);
1121         
1122         gtk_widget_show (menu_item);
1123         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1124         g_signal_connect_swapped (G_OBJECT (menu_item), "select", G_CALLBACK (create_table_sequencer_menu), NULL);
1125         
1126         menu_item = gtk_menu_item_new_with_mnemonic("Delete _All Events");
1127         delete_all_item = menu_item;
1128         gtk_widget_show (menu_item);
1129         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1130         g_signal_connect(menu_item, "activate", (GCallback) menu_delete_all_events, NULL);
1131
1132         menu_item = gtk_menu_item_new ();
1133         gtk_widget_show (menu_item);
1134         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1135         gtk_widget_set_sensitive (menu_item, FALSE);
1136
1137         menu_item = gtk_check_menu_item_new_with_mnemonic("_Confirm Recorded Events");
1138         //rec_menu_item = menu_item;
1139         gtk_widget_show (menu_item);
1140         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1141         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), globals.confirm_events);
1142         g_signal_connect(menu_item, "activate", (GCallback) toggle_confirm_events, NULL);
1143
1144         /* Options */
1145         menu_item = gtk_menu_item_new_with_mnemonic ("_Options");
1146         gtk_widget_show (menu_item);
1147         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1148
1149         sub_menu = gtk_menu_new ();
1150         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1151                 
1152         menu_item = gtk_check_menu_item_new_with_mnemonic("_Fullscreen");
1153         fullscreen_item = menu_item;
1154         gtk_widget_show (menu_item);
1155         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1156
1157         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), globals.fullscreen_enabled);
1158         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_F11, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
1159         g_signal_connect(menu_item, "activate", (GCallback) fullscreen_toggle, NULL);
1160         
1161         menu_item = gtk_menu_item_new ();
1162         gtk_widget_show (menu_item);
1163         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1164         gtk_widget_set_sensitive (menu_item, FALSE);
1165
1166         menu_item = gtk_image_menu_item_new_from_stock ("gtk-preferences", accel_group);
1167         gtk_widget_show (menu_item);
1168         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1169         g_signal_connect(menu_item, "activate", (GCallback) display_options, NULL);
1170
1171         /* HELP */ 
1172         menu_item = gtk_menu_item_new_with_mnemonic ("_Help");
1173         gtk_widget_show (menu_item);
1174         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1175         gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_item), TRUE);
1176         
1177         sub_menu = gtk_menu_new ();
1178         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1179
1180         menu_item = gtk_menu_item_new_with_mnemonic ("_Contents");
1181         gtk_widget_show (menu_item);
1182         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1183         g_signal_connect(menu_item, "activate", (GCallback) display_help, NULL);
1184         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_F1, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
1185
1186         menu_item = gtk_menu_item_new_with_mnemonic ("_About");
1187         gtk_widget_show (menu_item);
1188         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1189         g_signal_connect(menu_item, "activate", (GCallback) mplcfitx, NULL);
1190         
1191         menu_item = gtk_menu_item_new ();
1192         gtk_widget_show (menu_item);
1193         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1194         gtk_widget_set_sensitive (menu_item, FALSE);
1195
1196         menu_item = gtk_menu_item_new_with_mnemonic ("_Visit terminatorX.cx");
1197         gtk_widget_show (menu_item);
1198         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1199         g_signal_connect(menu_item, "activate", (GCallback) display_browser, NULL);
1200 }
1201
1202 void create_mastergui(int x, int y)
1203 {
1204         GtkWidget *mother_of_all_boxen;
1205         GtkWidget *main_vbox;
1206         GtkWidget *right_hbox;
1207         GtkWidget *left_hbox;
1208         GtkWidget *control_box;
1209         //GtkWidget *sequencer_box;
1210         GtkAdjustment *dumadj;
1211         GtkWidget *dummy;
1212         GtkWidget *master_vol_box;
1213         GtkWidget *status_box;
1214         
1215         gui_tooltips=gtk_tooltips_new();
1216
1217         main_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
1218
1219         gtk_window_set_wmclass(GTK_WINDOW(main_window), "terminatorX", "tX_mastergui");
1220
1221         gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
1222         
1223         gtk_container_set_border_width(GTK_CONTAINER(main_window), 5);
1224
1225         gtk_widget_realize(main_window);
1226         
1227         mother_of_all_boxen=gtk_vbox_new(FALSE, 5);
1228         gtk_container_add(GTK_CONTAINER(main_window), mother_of_all_boxen);
1229         gtk_widget_show(mother_of_all_boxen);   
1230         
1231         main_menubar=gtk_menu_bar_new();
1232         gtk_box_pack_start(GTK_BOX(mother_of_all_boxen), main_menubar, WID_FIX);
1233         gtk_widget_show(main_menubar);  
1234         
1235         create_master_menu();
1236         
1237         main_vbox=gtk_hbox_new(FALSE, 5);
1238         gtk_box_pack_start(GTK_BOX(mother_of_all_boxen), main_vbox, WID_DYN);
1239         gtk_widget_show(main_vbox);
1240         
1241         left_hbox=gtk_vbox_new(FALSE, 5);
1242         gtk_box_pack_start(GTK_BOX(main_vbox), left_hbox, WID_DYN);
1243         gtk_widget_show(left_hbox);
1244         
1245         control_box=gtk_hbox_new(FALSE, 5);
1246         gtk_box_pack_start(GTK_BOX(left_hbox), control_box, WID_FIX);
1247         gtk_widget_show(control_box);
1248         
1249         dummy=gtk_hseparator_new();
1250         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
1251         gtk_widget_show(dummy);
1252
1253     /* control_box contents */
1254
1255         dummy=tx_xpm_label_box(TX_ICON_AUDIOENGINE, "Audio");
1256         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1257         gtk_widget_show(dummy);
1258         
1259         dummy=tx_xpm_button_new(TX_ICON_POWER,"Power ", 1);
1260         connect_button(dummy,audio_on, NULL);
1261         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1262         gui_set_tooltip(dummy, "Turn the audio engine on/off.");
1263         gtk_widget_show(dummy);
1264         engine_btn=dummy;
1265         
1266         grab_button=tx_xpm_button_new(TX_ICON_GRAB, "Mouse Grab ", 1);
1267         gtk_box_pack_start(GTK_BOX(control_box), grab_button, WID_FIX);
1268         connect_button(grab_button, grab_on, NULL);
1269         gui_set_tooltip(grab_button, "Enter the mouse grab mode operation. Press <ESCAPE> to exit grab mode.");
1270         gtk_widget_show(grab_button);
1271
1272         dummy=gtk_vseparator_new();
1273         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1274         gtk_widget_show(dummy);
1275     
1276         dummy=tx_xpm_label_box(TX_ICON_SEQUENCER, "Seq.");
1277         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1278         gtk_widget_show(dummy);
1279
1280         dummy=tx_xpm_button_new(TX_ICON_PLAY,"Play ", 1);
1281         connect_button(dummy, seq_play, NULL);
1282         seq_play_btn=dummy;
1283         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1284         gui_set_tooltip(dummy, "Playback previously recorded events from the sequencer. This will turn on the audio engine automagically.");
1285         gtk_widget_show(dummy);
1286
1287         dummy=tx_xpm_button_new(TX_ICON_STOP,"Stop ", 0);
1288         seq_stop_btn=dummy;
1289         connect_button(dummy, seq_stop, NULL);  
1290         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1291         gui_set_tooltip(dummy, "Stop the playback of sequencer events.");
1292         gtk_widget_show(dummy);
1293
1294         dummy=tx_xpm_button_new(TX_ICON_RECORD,"Record ", 1);
1295         connect_button(dummy, seq_rec, NULL);
1296         seq_rec_btn=dummy;
1297         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1298         gui_set_tooltip(dummy, "Enable recording of *events* into the sequencer. All touched controls will be recorded. Existing events for the song-time recording will be overwritten for touched controls.");
1299         gtk_widget_show(dummy);
1300
1301         dummy=gtk_label_new("Pos:");
1302         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1303         gtk_widget_show(dummy);
1304         
1305         dummy=gtk_entry_new();
1306         gtk_entry_set_max_length(GTK_ENTRY(dummy), 12);
1307         seq_entry=dummy;
1308         //gtk_widget_set_usize(dummy, 65, 20);
1309         gtk_entry_set_text(GTK_ENTRY(dummy), "00:00.00");
1310         gtk_entry_set_width_chars(GTK_ENTRY(dummy), 9);
1311         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1312         gtk_widget_show(dummy);
1313
1314         dumadj=(GtkAdjustment*) gtk_adjustment_new(0, 0, 100, 0.1, 1, 1);
1315         seq_adj=dumadj;
1316         connect_adj(dumadj, sequencer_move, NULL);      
1317         dummy=gtk_hscale_new(dumadj);
1318         gtk_widget_set_size_request(dummy, 65, 20);
1319         seq_slider=dummy;
1320         g_signal_connect(G_OBJECT(seq_slider), "button-release-event", (GtkSignalFunc) seq_slider_released, NULL);
1321         gtk_scale_set_draw_value(GTK_SCALE(dummy), FALSE);
1322         
1323         gui_set_tooltip(dummy, "Select the start position for the sequencer in song-time.");
1324         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_DYN);
1325         gtk_widget_show(dummy);
1326         
1327         dummy=gtk_hbox_new(FALSE,2); //gtk_hpaned_new ();
1328         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_DYN);
1329         gtk_widget_show(dummy);
1330         
1331         tt_parent=dummy;
1332
1333     panel_bar=gtk_hbox_new(TRUE,2);
1334         gtk_box_pack_start(GTK_BOX(left_hbox), panel_bar, WID_FIX);
1335
1336         control_parent=gtk_hbox_new(FALSE,0);
1337         gtk_box_pack_start(GTK_BOX(tt_parent), control_parent, WID_FIX);
1338         gtk_widget_show(control_parent);
1339
1340         dummy=gtk_vseparator_new();
1341         gtk_box_pack_start(GTK_BOX(tt_parent), dummy, WID_FIX);
1342         gtk_widget_show(dummy);
1343
1344         audio_parent=gtk_vbox_new(FALSE,0);
1345         gtk_box_pack_start(GTK_BOX(tt_parent), audio_parent, WID_DYN);
1346         gtk_widget_show(audio_parent);
1347         
1348         dummy=gtk_vseparator_new();
1349         gtk_box_pack_start(GTK_BOX(main_vbox), dummy, WID_FIX);
1350         gtk_widget_show(dummy);
1351                 
1352         right_hbox=gtk_vbox_new(FALSE, 5);
1353         gtk_box_pack_start(GTK_BOX(main_vbox), right_hbox, WID_FIX);
1354         gtk_widget_show(right_hbox);
1355
1356         /* Master */
1357         
1358         dummy=gtk_label_new(NULL);
1359         gtk_label_set_markup(GTK_LABEL(dummy),"<b>Master</b>");
1360         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1361         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1362         gtk_widget_show(dummy); 
1363
1364         dummy=gtk_hseparator_new();
1365         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1366         gtk_widget_show(dummy);
1367
1368          /* Pitch */
1369          
1370         /*dummy=gtk_label_new("Pitch:");
1371         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1372         gtk_widget_show(dummy);*/
1373
1374         dumadj=(GtkAdjustment*) gtk_adjustment_new(globals.pitch, -3, 3, 0.001, 0.001, 0.01);
1375         pitch_adj=dumadj;
1376         connect_adj(dumadj, master_pitch_changed, NULL);
1377         
1378         tX_extdial *pdial=new tX_extdial("Pitch", pitch_adj, &sp_master_pitch, true);
1379         gtk_box_pack_start(GTK_BOX(right_hbox), pdial->get_widget(), WID_FIX);
1380         gui_set_tooltip(pdial->get_entry(), "Use this dial to adjust the master pitch (affecting *all* turntables).");
1381         
1382         dummy=gtk_hseparator_new();
1383         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1384         gtk_widget_show(dummy);
1385         
1386         /* Volume */
1387         master_vol_box=gtk_hbox_new(FALSE, 2);
1388         gtk_box_pack_start(GTK_BOX(right_hbox), master_vol_box, WID_DYN);
1389         gtk_widget_show(master_vol_box);        
1390         
1391         dumadj=(GtkAdjustment*) gtk_adjustment_new(globals.volume, 0, 2, 0.01, 0.05, 0.005);
1392         volume_adj=dumadj;
1393
1394         connect_adj(dumadj, master_volume_changed, NULL);       
1395         dummy=gtk_vscale_new(dumadj);
1396         gtk_range_set_inverted(GTK_RANGE(dummy), TRUE);
1397         gtk_scale_set_draw_value(GTK_SCALE(dummy), False);
1398         g_signal_connect(G_OBJECT(dummy), "button_press_event", (GtkSignalFunc) tX_seqpar::tX_seqpar_press, &sp_master_volume); 
1399         
1400         gtk_box_pack_end(GTK_BOX(master_vol_box), dummy, WID_FIX);
1401         gtk_widget_show(dummy); 
1402         gui_set_tooltip(dummy, "Adjust the master volume. This parameter will effect *all* turntables in the set.");
1403         
1404         main_flash_r=gtk_tx_flash_new();
1405         gtk_box_pack_end(GTK_BOX(master_vol_box), main_flash_r, WID_DYN);
1406         gtk_widget_show(main_flash_r);
1407
1408         main_flash_l=gtk_tx_flash_new();
1409         gtk_box_pack_end(GTK_BOX(master_vol_box), main_flash_l, WID_DYN);
1410         gtk_widget_show(main_flash_l);
1411
1412         dummy=gtk_label_new("Volume");
1413         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1414         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1415         gtk_widget_show(dummy);
1416
1417         /* STATUS BOX */ 
1418         dummy=gtk_hseparator_new();
1419         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1420         gtk_widget_show(dummy);
1421         
1422         status_box=gtk_vbox_new(FALSE, 0);
1423         gtk_box_pack_start(GTK_BOX(right_hbox), status_box, WID_FIX);
1424         gtk_widget_show(status_box);
1425         
1426         dummy=gtk_label_new("0");
1427         used_mem=dummy;
1428         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1429         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1430         gtk_widget_show(dummy);
1431
1432         dummy=gtk_label_new("Mem/kB:");
1433         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1434         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1435         gtk_widget_show(dummy);
1436         
1437         add_sep2();
1438
1439         dummy=gtk_label_new("1");
1440         no_of_vtts=dummy;
1441         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1442         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1443         gtk_widget_show(dummy);
1444
1445         dummy=gtk_label_new("Vtts:");
1446         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1447         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1448         gtk_widget_show(dummy);
1449
1450         add_sep2();
1451
1452         dummy=gtk_label_new(VERSION);
1453         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1454         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1455         gtk_widget_show(dummy);
1456
1457         dummy=gtk_label_new("Release:");
1458         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1459         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1460         gtk_widget_show(dummy);
1461         
1462         add_sep2();
1463
1464         dummy=gtk_label_new(NULL);
1465         gtk_label_set_markup(GTK_LABEL(dummy), "<b>Status</b>");
1466         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1467         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1468         gtk_widget_show(dummy);
1469         
1470         /* END GUI */
1471         
1472         gtk_window_set_default_size(GTK_WINDOW(main_window), x, y);     
1473         gtk_widget_set_sensitive(grab_button, 0);
1474
1475         new_table(NULL, NULL); // to give the user something to start with ;)
1476
1477         g_signal_connect (G_OBJECT(main_window), "delete-event", (GtkSignalFunc) quit, NULL);   
1478         
1479         if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
1480         else gtk_tooltips_disable(gui_tooltips);
1481 }
1482
1483 gfloat old_percent=-1;
1484
1485 void note_destroy(GtkWidget *widget, GtkWidget *mbox)
1486 {
1487         gtk_widget_destroy(GTK_WIDGET(mbox));
1488 }
1489
1490 void tx_note(const char *message, bool isError)
1491 {
1492         char buffer[4096]="terminatorX ";
1493         if (isError) {
1494                 strcat(buffer, "note:\n\n");
1495         } else {
1496                 strcat(buffer, "error:\n\n");
1497         }
1498         
1499         strcat(buffer, message);
1500         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window),
1501                 GTK_DIALOG_DESTROY_WITH_PARENT,
1502                 isError ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
1503         gtk_dialog_run(GTK_DIALOG(dialog));
1504         gtk_widget_destroy(dialog);     
1505 }
1506
1507
1508 void tx_l_note(const char *message)
1509 {
1510         char buffer[4096]="Plugin info:\n\n";
1511         strcat(buffer, message);
1512         
1513         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window),
1514                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
1515         gtk_dialog_run(GTK_DIALOG(dialog));
1516         gtk_widget_destroy(dialog);     
1517 }
1518
1519
1520 void add_to_panel_bar(GtkWidget *button) 
1521 {
1522         buttons_on_panel_bar++;
1523         gtk_box_pack_start(GTK_BOX(panel_bar), button, WID_DYN);
1524         gtk_widget_show(panel_bar);
1525 }
1526
1527 void remove_from_panel_bar(GtkWidget *button) 
1528 {
1529         buttons_on_panel_bar--;
1530         gtk_container_remove(GTK_CONTAINER(panel_bar), button);
1531         if (buttons_on_panel_bar==0) gtk_widget_hide(panel_bar);
1532 }
1533
1534 /* Fullscreen code... */
1535 #define _WIN_LAYER_TOP          -1
1536 #define _WIN_LAYER_NORMAL       4
1537 #define _NET_WM_STATE_REMOVE    0
1538 #define _NET_WM_STATE_ADD       1
1539 #define _NET_WM_STATE_TOGGLE    2
1540
1541 void fullscreen_toggle(GtkCheckMenuItem *item, gpointer data) {
1542         XEvent xev;
1543         Window win=GDK_WINDOW_XID(main_window->window);
1544         Display *disp=GDK_WINDOW_XDISPLAY(main_window->window);
1545         
1546         globals.fullscreen_enabled=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(fullscreen_item));
1547         
1548         /* Top layer.. */
1549         xev.xclient.type = ClientMessage;
1550         xev.xclient.serial = 0;
1551         xev.xclient.send_event = True;
1552         xev.xclient.display = disp;
1553         xev.xclient.window = win;
1554         xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_WIN_LAYER");
1555         xev.xclient.format = 32;
1556         xev.xclient.data.l[0] = globals.fullscreen_enabled ? _WIN_LAYER_TOP : _WIN_LAYER_NORMAL ;
1557         XSendEvent(disp, GDK_WINDOW_XID (gdk_get_default_root_window ()),
1558                 False, SubstructureRedirectMask | SubstructureNotifyMask,
1559                 &xev);
1560         
1561         /* Fullscreen */
1562         xev.xclient.type = ClientMessage;
1563         xev.xclient.serial = 0;
1564         xev.xclient.send_event = True;
1565         xev.xclient.display = disp;
1566         xev.xclient.window = win;
1567         xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1568         xev.xclient.format = 32;
1569         xev.xclient.data.l[0] = globals.fullscreen_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1570         xev.xclient.data.l[1] = gdk_x11_atom_to_xatom (gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", TRUE));
1571         xev.xclient.data.l[2] = gdk_x11_atom_to_xatom (GDK_NONE);
1572         XSendEvent(gdk_display, GDK_WINDOW_XID (gdk_get_default_root_window ()),
1573                 False, SubstructureRedirectMask | SubstructureNotifyMask,
1574                 &xev);  
1575 }
1576
1577 void fullscreen_setup() {
1578         if (globals.fullscreen_enabled) {
1579                 fullscreen_toggle(NULL, NULL);
1580         }
1581 }
1582
1583 void display_mastergui()
1584 {
1585         GtkWidget *top;
1586         gtk_widget_realize(main_window);
1587         tX_set_icon(main_window);
1588         load_knob_pixs();
1589         gtk_widget_show(main_window);
1590         fullscreen_setup();     
1591         top=gtk_widget_get_toplevel(main_window);
1592         xwindow=GDK_WINDOW_XWINDOW(top->window);
1593 }
1594
1595 pid_t help_child=0;
1596 GTimer *help_timer=NULL;
1597 int help_tag=-1;
1598
1599 int help_checker()
1600 {
1601         gdouble time;
1602         gulong ms;
1603         int status;
1604         int result=waitpid(help_child, &status, WNOHANG);
1605         
1606         if (result==0) {
1607                 time=g_timer_elapsed(help_timer, &ms);
1608                 if (time > 5) {
1609                         /* 5 seconds and it's still running - so we assume everything's OK. */
1610                         tX_debug("No longer waiting for gnome-help..");
1611                         gtk_idle_remove(help_tag);
1612                         help_tag=-1;
1613                 }
1614         } else {
1615                 /* We are still here and the child exited - that could mean trouble. */
1616                 tx_note("Couldn't run the gnome-help command (alias \"yelp\") to display the terminatorX manual. Please ensure that \"yelp\" is installed.", true);             
1617                 
1618                 gtk_idle_remove(help_tag);
1619                 help_tag=-1;
1620         }
1621         return TRUE;    
1622 }
1623
1624 #ifndef INSTALL_PREFIX
1625 #define INSTALL_PREFIX "/usr/local/share"
1626 #endif
1627
1628 void display_help()
1629 {       
1630         help_child=fork();
1631
1632         if (help_tag!=-1) {
1633                 gtk_idle_remove(help_tag);
1634                 if (help_timer) g_timer_destroy(help_timer);
1635                 help_child=0;
1636                 help_tag=-1;
1637                 help_timer=NULL;
1638         }
1639         
1640         if (help_child==0) {
1641                 // child
1642                 // execlp("gnome-help","gnome-help","ghelp:/" INSTALL_PREFIX "/terminatorX/doc/terminatorX-manual/C/terminatorX-manual.xml", NULL);
1643                 execlp("gnome-help","gnome-help","ghelp:/" XML_MANUAL, NULL);           
1644                 _exit(-1);
1645         } else if (help_child==-1) {
1646                 tx_note("System error: couldn't fork() to run the help process.", true);
1647         } else {
1648                 help_timer=g_timer_new();
1649                 g_timer_start(help_timer);
1650         
1651                 help_tag=gtk_idle_add((GtkFunction) help_checker, NULL);
1652         }
1653 }
1654
1655 pid_t browser_child=0;
1656 GTimer *browser_timer=NULL;
1657 int browser_tag=-1;
1658
1659 int browser_checker()
1660 {
1661         gdouble time;
1662         gulong ms;
1663         int status;
1664         int result=waitpid(browser_child, &status, WNOHANG);
1665         
1666         if (result==0) {
1667                 time=g_timer_elapsed(browser_timer, &ms);
1668                 if (time > 5) {
1669                         /* 5 seconds and it's still running - so we assume everything's OK. */
1670                         tX_debug("No longer waiting for a browser..");
1671                         gtk_idle_remove(browser_tag);
1672                         browser_tag=-1;
1673                 }
1674         } else {
1675                 /* We are still here and the child exited - that could mean trouble. */
1676                 tx_note("Failed to run a suitable web browser - if there's one installed on this system, please run it and forward yourself to:\nhttp://terminatorX.cx", true);         
1677                 
1678                 gtk_idle_remove(browser_tag);
1679                 browser_tag=-1;
1680         }
1681         return TRUE;    
1682 }
1683
1684 void display_browser()
1685 {       
1686         browser_child=fork();
1687
1688         if (browser_tag!=-1) {
1689                 gtk_idle_remove(browser_tag);
1690                 if (browser_timer) g_timer_destroy(browser_timer);
1691                 browser_child=0;
1692                 browser_tag=-1;
1693                 browser_timer=NULL;
1694         }
1695         
1696         if (browser_child==0) {
1697                 // child
1698                 execlp("mozilla","mozilla","http://terminatorX.cx", NULL);
1699                 execlp("netscape","netscape","http://terminatorX.cx", NULL);
1700                 execlp("galeon","galeon","http://terminatorX.cx", NULL);
1701                 execlp("konqueror","konqueror","http://terminatorX.cx", NULL);          
1702                 _exit(-1);
1703         } else if (browser_child==-1) {
1704                 tx_note("System error: couldn't fork() to run the browser process.", true);
1705         } else {
1706                 browser_timer=g_timer_new();
1707                 g_timer_start(browser_timer);
1708         
1709                 browser_tag=gtk_idle_add((GtkFunction) browser_checker, NULL);
1710         }
1711 }
1712
1713
1714
1715 GdkCursor *tX_cursor::cursors[MAX_CURSOR]={NULL, NULL, NULL};
1716 tX_cursor::cursor_shape tX_cursor::current_shape=tX_cursor::DEFAULT_CURSOR;
1717
1718 void tX_cursor::set_cursor(cursor_shape shape)
1719 {
1720         switch (shape) {
1721                 case DEFAULT_CURSOR:
1722                         cursors[shape]=NULL;
1723                         break;
1724                 
1725                 case WAIT_CURSOR:
1726                         if (!cursors[shape]) cursors[shape]=gdk_cursor_new(GDK_WATCH);
1727                         break;
1728                 
1729                 case WAIT_A_SECOND_CURSOR:
1730                         /* FIXME: What's that short-time wait cursor's id? */
1731                         if (!cursors[shape]) cursors[shape]=gdk_cursor_new(GDK_WATCH);
1732                         break;
1733                 
1734                 default:
1735                         tX_debug("No such cursor shape.");
1736                         return;
1737         }
1738         
1739         /* Still here? Ok... */
1740         current_shape=shape;
1741         
1742         gdk_window_set_cursor(main_window->window, cursors[shape]);
1743 }
1744
1745 GdkCursor *tX_cursor::get_cursor()
1746 {
1747         return cursors[current_shape];
1748 }
1749
1750 void tX_cursor::reset_cursor()
1751 {
1752         current_shape=DEFAULT_CURSOR;
1753         gdk_window_set_cursor(main_window->window, cursors[current_shape]);
1754 }