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