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