changes from colin for route_params, nick for location_ui and route_ui, and me for...
[ardour.git] / gtk2_ardour / ardour_ui.h
1 /*
2     Copyright (C) 1999-2002 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __ardour_gui_h__
22 #define __ardour_gui_h__
23
24 /* need _BSD_SOURCE to get timersub macros */
25
26 #ifdef _BSD_SOURCE
27 #include <sys/time.h>
28 #else
29 #define _BSD_SOURCE
30 #include <sys/time.h>
31 #undef _BSD_SOURCE
32 #endif
33
34 #include <list>
35
36 #include <cmath>
37
38 #include <libgnomecanvasmm/canvas.h>
39
40 #include <pbd/xml++.h>
41 #include <gtkmm2ext/gtk_ui.h>
42 #include <gtkmm2ext/pix.h>
43 #include <gtkmm2ext/click_box.h>
44 #include <ardour/ardour.h>
45 #include <ardour/session.h>
46
47 #include "audio_clock.h"
48 #include "ardour_dialog.h"
49 #include "editing.h"
50
51 class AudioClock;
52 class PublicEditor;
53 class Keyboard;
54 class MeterBridge;
55 class OptionEditor;
56 class Mixer_UI;
57 class ConnectionEditor;
58 class RouteParams_UI;
59 class SoundFileSelector;
60 class About;
61 class AddRouteDialog;
62 class NewSessionDialog;
63 class LocationUI;
64
65 namespace Gtkmm2ext {
66         class TearOff;
67 };
68
69 namespace ARDOUR {
70         class AudioEngine;
71         class Route;
72         class Port;
73         class IO;
74 };
75
76 namespace ALSA {
77         class MultiChannelDevice;
78 };
79
80 #define FRAME_NAME "BaseFrame"
81
82 class ARDOUR_UI : public Gtkmm2ext::UI
83 {
84   public:
85         ARDOUR_UI (int *argcp, char **argvp[], string rcfile);
86         ~ARDOUR_UI();
87         
88         void show ();
89         bool shown() { return shown_flag; }
90         
91         void show_splash ();
92         void hide_splash ();
93         
94         int load_session (string path, string snapshot, string* mix_template = 0);
95         bool session_loaded;
96         int build_session (string path, string snapshot, 
97                            uint32_t ctl_chns, 
98                            uint32_t master_chns,
99                            ARDOUR::Session::AutoConnectOption input_connect,
100                            ARDOUR::Session::AutoConnectOption output_connect,
101                            uint32_t nphysin,
102                            uint32_t nphysout,
103                            jack_nframes_t initial_length);
104         bool session_is_new() const { return _session_is_new; }
105
106         ARDOUR::Session* the_session() { return session; }
107
108         bool will_create_new_session_automatically() const {
109                 return _will_create_new_session_automatically;
110         }
111
112         void set_will_create_new_session_automatically (bool yn) {
113                 _will_create_new_session_automatically = yn;
114         }
115
116         void new_session (bool startup = false, std::string path = string());
117         gint cmdline_new_session (std::string path);
118         int  unload_session ();
119         void close_session() { unload_session(); }
120
121         int  save_state_canfail (string state_name = "");
122         void save_state (string state_name = "");
123         void restore_state (string state_name = "");
124
125         static double gain_to_slider_position (ARDOUR::gain_t g);
126         static ARDOUR::gain_t slider_position_to_gain (double pos);
127
128         static ARDOUR_UI *instance () { return theArdourUI; }
129
130         PublicEditor&     the_editor(){return *editor;}
131         Mixer_UI* the_mixer() { return mixer; }
132         
133         void allow_focus (bool yn);
134
135         static gint generic_focus_in_event (GdkEventFocus *);
136         static gint generic_focus_out_event (GdkEventFocus *);
137
138         void toggle_location_window ();
139         void toggle_big_clock_window ();
140         void toggle_connection_editor ();
141         void toggle_route_params_window ();
142         void toggle_tempo_window ();
143         void toggle_sfdb_window ();
144
145         SoundFileSelector& get_sfdb_window();
146
147         gint32 select_diskstream (GdkEventButton *ev);
148
149         Gtk::Tooltips& tooltips() { return _tooltips; }
150
151         static sigc::signal<void,bool> Blink;
152         static sigc::signal<void>      RapidScreenUpdate;
153         static sigc::signal<void>      SuperRapidScreenUpdate;
154         static sigc::signal<void,jack_nframes_t> Clock;
155
156         /* this is a helper function to centralize the (complex) logic for
157            blinking rec-enable buttons.
158         */
159
160         void rec_enable_button_blink (bool onoff, ARDOUR::DiskStream *, Gtk::Widget *w);
161
162         void name_io_setup (ARDOUR::AudioEngine&, string&, ARDOUR::IO& io, bool in);
163         void choose_io (ARDOUR::IO&, bool input);
164
165         static gint hide_and_quit (GdkEventAny *ev, ArdourDialog *);
166
167         XMLNode* editor_settings() const;
168         XMLNode* mixer_settings () const;
169         XMLNode* keyboard_settings () const;
170
171         void save_ardour_state ();
172         gboolean configure_handler (GdkEventConfigure* conf);
173
174         void do_transport_locate (jack_nframes_t position);
175         void halt_on_xrun_message ();
176
177         AudioClock primary_clock;
178         AudioClock secondary_clock;
179         AudioClock preroll_clock;
180         AudioClock postroll_clock;
181
182         void add_route ();
183         
184         void session_add_audio_track (int input_channels, int32_t output_channels) {
185                 session_add_audio_route (true, input_channels, output_channels);
186         }
187
188         void session_add_audio_bus (int input_channels, int32_t output_channels) {
189                 session_add_audio_route (false, input_channels, output_channels);
190         }
191
192         void session_add_midi_track ();
193
194         void set_engine (ARDOUR::AudioEngine&);
195
196         gint exit_on_main_window_close (GdkEventAny *);
197
198   protected:
199         friend class PublicEditor;
200
201         void toggle_metering ();
202         void toggle_clocking ();
203         void toggle_auto_play ();
204         void toggle_auto_input ();
205         void toggle_punch_in ();
206         void toggle_punch_out ();
207         void toggle_auto_return ();
208         void toggle_click ();
209         void toggle_follow ();
210
211         void toggle_session_auto_loop ();
212         void toggle_session_punch_in ();
213         
214         void toggle_options_window ();
215
216   private:
217         struct GlobalClickBox : public Gtk::VBox {
218             Gtkmm2ext::ClickBox  *box;
219             Gtk::Frame      frame;
220             Gtk::Label      label;
221             vector<string> &strings;
222             Gtk::Adjustment adjustment;
223
224             static void printer (char buf[32], Gtk::Adjustment &adj, void *arg);
225
226             GlobalClickBox (const string &str, vector<string> &vs)
227                     : strings (vs),
228                       adjustment (0, 0, vs.size() - 1, 1, 1, 0) {
229                     box = new Gtkmm2ext::ClickBox (&adjustment, "ClickButton");
230                     label.set_text (str);
231                     label.set_name ("GlobalButtonLabel");
232                     frame.add (*box);
233                     frame.set_shadow_type (Gtk::SHADOW_IN);
234                     pack_start (label);
235                     pack_start (frame);
236                     box->set_print_func (printer, this);
237                     box->set_wrap (true);
238             };
239         };
240
241         ARDOUR::AudioEngine                 *engine;
242         ARDOUR::Session                     *session;
243
244         Gtk::Tooltips          _tooltips;
245
246         void                     goto_editor_window ();
247         void                     goto_mixer_window ();
248         
249         Gtk::Table               adjuster_table;
250         Gtk::Frame               adjuster_frame;
251         Gtk::Fixed               adjuster_base;
252
253         GlobalClickBox     *online_control_button;
254         vector<string>      online_control_strings;
255
256         GlobalClickBox    *crossfade_time_button;
257         vector<string>     crossfade_time_strings;
258
259         GlobalClickBox    *mmc_id_button;
260         vector<string>     mmc_id_strings;
261
262         Gtk::ToggleButton   preroll_button;
263         Gtk::ToggleButton   postroll_button;
264
265         Gtk::Table          transport_table;
266         Gtk::Table          option_table;
267
268         static SoundFileSelector* sfdb_window;
269
270         int  setup_windows ();
271         void setup_session_menu ();
272         void setup_transport ();
273         void setup_clock ();
274         void setup_session_info ();
275         void setup_adjustables ();
276
277         Gtk::MenuBar* make_menubar ();
278         
279         static ARDOUR_UI *theArdourUI;
280
281         void startup ();
282         void shutdown ();
283
284         void finish();
285         int  ask_about_saving_session (string why);
286         gint ask_about_save_deleted (GdkEventAny*);
287         void save_session_choice_made (int);
288         int  save_the_session;
289
290         void queue_transport_change ();
291         void map_transport_state ();
292         int32_t do_engine_start ();
293         gint start_engine ();
294         
295         void engine_halted ();
296         void engine_stopped ();
297         void engine_running ();
298
299         void map_some_session_state (Gtk::ToggleButton& button,
300                                      bool (ARDOUR::Session::*get)() const);
301
302         void toggle_some_session_state (Gtk::ToggleButton& button,
303                                      bool (ARDOUR::Session::*get)() const,
304                                      void (ARDOUR::Session::*set)(bool));
305         void map_button_state ();
306
307         void clear_meters ();
308
309         static gint _blink  (void *);
310         void blink ();
311         gint blink_timeout_tag;
312         bool blink_on;
313         void start_blinking ();
314         void stop_blinking ();
315
316         void control_methods_adjusted ();
317         void mmc_device_id_adjusted ();
318
319   private:
320         Gtk::VBox     top_packer;
321
322         sigc::connection clock_signal_connection;
323         void         update_clocks ();
324         void         start_clocking ();
325         void         stop_clocking ();
326
327         class BigClockWindow : public ArdourDialog
328         {
329           public:
330                 BigClockWindow () : ArdourDialog ("big clock window") {};
331         };
332
333         AudioClock               big_clock;
334         Gtk::Frame               big_clock_frame;
335         BigClockWindow*          big_clock_window;
336
337         void big_clock_size_event (GtkAllocation *alloc);
338         void big_clock_realize ();
339
340         /* Transport Control */
341
342         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
343         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
344
345         Gtkmm2ext::TearOff*       transport_tearoff;
346         Gtk::Frame               transport_frame;
347         Gtk::HBox                transport_tearoff_hbox;
348         Gtk::HBox                transport_hbox;
349         Gtk::Fixed               transport_base;
350         Gtk::Fixed               transport_button_base;
351         Gtk::Frame               transport_button_frame;
352         Gtk::HBox                transport_button_hbox;
353         Gtk::VBox                transport_button_vbox;
354         Gtk::HBox                transport_option_button_hbox;
355         Gtk::VBox                transport_option_button_vbox;
356         Gtk::HBox                transport_clock_hbox;
357         Gtk::VBox                transport_clock_vbox;
358         Gtk::HBox                primary_clock_hbox;
359         Gtk::HBox                secondary_clock_hbox;
360
361         Gtk::Button goto_start_button;
362         Gtk::Button goto_end_button;
363         Gtk::Button rewind_button;
364         Gtk::Button forward_button;
365         Gtk::Button stop_button;
366
367         enum ShuttleBehaviour {
368                 Sprung,
369                 Wheel
370         };
371
372         enum ShuttleUnits {
373                 Percentage,
374                 Semitones
375         };
376
377         Gtk::DrawingArea shuttle_box;
378         Gtk::EventBox    speed_display_box;
379         Gtk::Label       speed_display_label;
380         Gtk::Button      shuttle_units_button;
381         Gtk::Button      shuttle_style_button;
382         Gtk::Menu*       shuttle_unit_menu;
383         Gtk::Menu*       shuttle_style_menu;
384         ShuttleBehaviour shuttle_behaviour;
385         ShuttleUnits     shuttle_units;
386
387         void shuttle_style_clicked ();
388         void shuttle_unit_clicked ();
389         void set_shuttle_behaviour (ShuttleBehaviour);
390         void set_shuttle_units (ShuttleUnits);
391         void update_speed_display ();
392
393         gint shuttle_box_button_press (GdkEventButton*);
394         gint shuttle_box_button_release (GdkEventButton*);
395         gint shuttle_box_motion (GdkEventMotion*);
396         gint shuttle_box_expose (GdkEventExpose*);
397         gint mouse_shuttle (double x, bool force);
398         void use_shuttle_fract (bool force);
399
400         bool   shuttle_grabbed;
401         double shuttle_fract;
402
403         Gtk::ToggleButton auto_loop_button;
404         Gtk::ToggleButton play_selection_button;
405         Gtk::ToggleButton roll_button;
406
407         Gtk::ToggleButton rec_button;
408         Gtk::ToggleButton punch_in_button;
409         Gtk::ToggleButton punch_out_button;
410         Gtk::ToggleButton auto_return_button;
411         Gtk::ToggleButton auto_play_button;
412         Gtk::ToggleButton auto_input_button;
413         Gtk::ToggleButton click_button;
414         Gtk::ToggleButton follow_button;
415         Gtk::ToggleButton auditioning_alert_button;
416         Gtk::ToggleButton solo_alert_button;
417
418         Gtk::VBox alert_box;
419         
420         void follow_changed ();
421
422         void solo_blink (bool);
423         void audition_blink (bool);
424
425         void soloing_changed (bool);
426         void auditioning_changed (bool);
427         void _auditioning_changed (bool);
428
429         void solo_alert_toggle ();
430         void audition_alert_toggle ();
431
432         void primary_clock_value_changed ();
433         void secondary_clock_value_changed ();
434
435         /* called by Blink signal */
436
437         void transport_rec_enable_blink (bool onoff);
438
439         /* These change where we accept control from:
440            MMC, X (local) or both.
441         */
442
443         void allow_mmc_only ();
444         void allow_mmc_and_local ();
445         void allow_local_only ();
446
447         static void rate_printer (char buf[32], Gtk::Adjustment &, void *);
448
449         Gtk::Menu*        session_popup_menu;
450
451         struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
452             RecentSessionModelColumns() { 
453                     add (visible_name);
454                     add (fullpath);
455             }
456             Gtk::TreeModelColumn<Glib::ustring> visible_name;
457             Gtk::TreeModelColumn<Glib::ustring> fullpath;
458         };
459
460         RecentSessionModelColumns    recent_session_columns;
461         Gtk::TreeView                recent_session_display;
462         Glib::RefPtr<Gtk::TreeStore> recent_session_model;
463
464         ArdourDialog*     session_selector_window;
465         Gtk::FileChooserDialog* open_session_selector;
466         
467         void build_session_selector();
468         void recent_session_selection_changed ();
469         void redisplay_recent_sessions();
470
471         struct RecentSessionsSorter {
472             bool operator() (std::pair<string,string> a, std::pair<string,string> b) const {
473                     return cmp_nocase(a.first, b.first) == -1;
474             }
475         };
476
477         /* menu bar and associated stuff */
478
479         Gtk::MenuBar* menu_bar;
480         Gtk::Fixed    menu_bar_base;
481         Gtk::HBox     menu_hbox;
482
483         void build_menu_bar ();
484         void pack_toplevel_controls();
485
486         /* handles on the menu bar items that need to 
487            be sensitive to whether or not we have
488            a session loaded.
489         */
490
491         Gtk::MenuItem *add_track_item;
492         Gtk::MenuItem *save_item;
493         Gtk::MenuItem *snapshot_item;
494         Gtk::MenuItem *save_as_item;
495         Gtk::MenuItem *save_template_item;
496         Gtk::MenuItem *export_item;
497         Gtk::MenuItem *close_item;
498
499         Gtk::CheckMenuItem *meter_bridge_dialog_check;
500         Gtk::CheckMenuItem *connection_editor_check;
501         Gtk::CheckMenuItem *route_params_check;
502         Gtk::CheckMenuItem *locations_dialog_check;
503         Gtk::CheckMenuItem *big_clock_check;
504         Gtk::CheckMenuItem *tempo_editor_check;
505         Gtk::CheckMenuItem *sfdb_check;
506         Gtk::CheckMenuItem *options_window_check;
507         
508         /* <CMT Additions> */
509         Gtk::MenuItem *image_compositor_item ;
510         /* </CMT Additions> */
511
512
513         Gtk::Label   wall_clock_label;
514         Gtk::EventBox wall_clock_box;
515         gint update_wall_clock ();
516
517         Gtk::Label   disk_space_label;
518         Gtk::EventBox disk_space_box;
519         void update_disk_space ();
520
521         Gtk::Label   cpu_load_label;
522         Gtk::EventBox cpu_load_box;
523         void update_cpu_load ();
524
525         Gtk::Label   disk_rate_label;
526         Gtk::EventBox disk_rate_box;
527         void update_disk_rate();
528
529         Gtk::Label   buffer_load_label;
530         Gtk::EventBox buffer_load_box;
531         void update_buffer_load ();
532
533         Gtk::Label   sample_rate_label;
534         Gtk::EventBox sample_rate_box;
535         void update_sample_rate (jack_nframes_t);
536
537         gint every_second ();
538         gint every_point_one_seconds ();
539         gint every_point_zero_one_seconds ();
540
541         sigc::connection second_connection;
542         sigc::connection point_one_second_connection;
543         sigc::connection point_zero_one_second_connection;
544
545         void diskstream_added (ARDOUR::DiskStream*);
546
547         gint session_menu (GdkEventButton *);
548
549         bool _will_create_new_session_automatically;
550
551         NewSessionDialog* new_session_window;
552         string template_name;
553
554         void new_session_ok_clicked ();
555         void new_session_template_choice (Gtk::TreeView&, Glib::RefPtr<Gtk::TreeSelection>);
556         void hide_dialog (ArdourDialog *dialog);
557
558         void fs_cancel_clicked (Gtk::FileSelection*);
559         gint fs_delete_event (GdkEventAny*, Gtk::FileSelection*);
560
561         void open_session ();
562         void open_recent_session ();
563         void open_ok_clicked ();
564
565         void save_template ();
566
567
568         void session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels);
569
570         void add_diskstream_to_menu (ARDOUR::DiskStream&);
571         void diskstream_selected (gint32);
572         Gtk::Menu *diskstream_menu;
573         gint32 selected_dstream;
574         
575         gint mouse_transport_goto_start (GdkEventButton *) {
576                 transport_goto_start (); return TRUE;
577         }
578         gint mouse_transport_goto_end (GdkEventButton *) {
579                 transport_goto_end (); return TRUE;
580         }
581         gint mouse_transport_record (GdkEventButton *) {
582                 transport_record (); return TRUE;
583         }
584         gint mouse_transport_forward (GdkEventButton *) {
585                 transport_forward (0); return TRUE;
586         }
587         gint mouse_transport_rewind (GdkEventButton *) {
588                 transport_rewind (0); return TRUE;
589         }
590         gint mouse_transport_loop (GdkEventButton *) {
591                 transport_loop (); return TRUE;
592         }
593         gint mouse_transport_play_selection (GdkEventButton *) {
594                 transport_play_selection (); return TRUE;
595         }
596
597         gint mouse_transport_roll (GdkEventButton *);
598         gint mouse_transport_stop (GdkEventButton *);
599
600         void set_transport_sensitivity (bool);
601
602         void remove_last_capture ();
603
604         void transport_goto_start ();
605         void transport_goto_end ();
606         void transport_stop ();
607         void transport_stop_and_forget_capture ();
608         void transport_record ();
609         void transport_roll ();
610         void transport_play_selection(); 
611         void transport_forward (int option);
612         void transport_rewind (int option);
613         void transport_loop ();
614
615         void transport_locating ();
616         void transport_rolling ();
617         void transport_rewinding ();
618         void transport_forwarding ();
619         void transport_stopped ();
620
621         void send_all_midi_feedback ();
622         
623         bool _session_is_new;
624         void connect_to_session (ARDOUR::Session *);
625         void connect_dependents_to_session (ARDOUR::Session *);
626         void we_have_dependents ();
627         void setup_keybindings ();
628
629         guint32  last_key_press_time;
630
631         void snapshot_session ();
632
633         void map_control_change (ARDOUR::Session::ControlType);
634         void queue_map_control_change (ARDOUR::Session::ControlType);
635         void map_record_state ();
636         void queue_map_record_state ();
637
638         Mixer_UI   *mixer;
639         int         create_mixer ();
640         
641         PublicEditor     *editor;
642         int         create_editor ();
643
644         MeterBridge  *meter_bridge;
645         int          create_meter_bridge ();
646
647         RouteParams_UI *route_params;
648         int             create_route_params ();
649
650         ConnectionEditor *connection_editor;
651         int               create_connection_editor ();
652
653         LocationUI *location_ui;
654         int         create_location_ui ();
655
656         void meter_bridge_hiding ();
657         void location_ui_hiding ();
658         void big_clock_hiding ();
659         void route_params_hiding ();
660         void connection_editor_hiding ();
661         void sfdb_hiding ();
662         void option_hiding ();
663
664         /* Various options */
665
666         void toggle_recording_plugins ();
667
668         /* Options window */
669         
670         OptionEditor *option_editor;
671         
672         /* route dialog */
673
674         AddRouteDialog *add_route_dialog;
675         void add_route_dialog_done (int status);
676         
677         /* Keyboard Handling */
678         
679         Keyboard* keyboard;
680
681         /* Keymap handling */
682
683         void install_keybindings ();
684         void test_binding_action (const char *);
685         void start_keyboard_prefix();
686
687         void toggle_record_enable (guint32);
688         void toggle_monitor_enable (guint32);
689
690         uint32_t rec_enabled_diskstreams;
691         void count_recenabled_diskstreams (ARDOUR::DiskStream&);
692
693         About* about;
694         bool shown_flag;
695         /* cleanup */
696
697         Gtk::MenuItem *cleanup_item;
698
699         void display_cleanup_results (ARDOUR::Session::cleanup_report& rep, const gchar* list_title, string msg);
700         void cleanup ();
701         void flush_trash ();
702
703         bool have_configure_timeout;
704         struct timeval last_configure_time;
705         gint configure_timeout ();
706
707         struct timeval last_peak_grab;
708         struct timeval last_shuttle_request;
709
710         void cannot_record_no_input (ARDOUR::DiskStream*);
711
712         void delete_sources_in_the_right_thread (list<ARDOUR::Source*>*);
713
714         void editor_display_control_changed (Editing::DisplayControl c);
715
716         bool have_disk_overrun_displayed;
717         bool have_disk_underrun_displayed;
718
719         void disk_overrun_message_gone ();
720         void disk_underrun_message_gone ();
721         void disk_overrun_handler ();
722         void disk_underrun_handler ();
723
724         int pending_state_dialog ();
725         
726         void disconnect_from_jack ();
727         void reconnect_to_jack ();
728         void set_jack_buffer_size (jack_nframes_t);
729
730         Gtk::MenuItem* jack_disconnect_item;
731         Gtk::MenuItem* jack_reconnect_item;
732         Gtk::Menu*     jack_bufsize_menu;
733
734         int make_session_clean ();
735         bool filter_ardour_session_dirs (const Gtk::FileFilter::Info&);
736
737         Glib::RefPtr<Gtk::UIManager> ui_manager;
738 };
739
740 #endif /* __ardour_gui_h__ */