fix initial display of solo-model in monitor section
[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 */
19
20 #ifndef __ardour_gui_h__
21 #define __ardour_gui_h__
22
23 #include <time.h>
24
25 /* need _BSD_SOURCE to get timersub macros */
26
27 #ifdef _BSD_SOURCE
28 #include <sys/time.h>
29 #else
30 #define _BSD_SOURCE
31 #include <sys/time.h>
32 #undef _BSD_SOURCE
33 #endif
34
35 #include <list>
36 #include <cmath>
37
38 #include <libgnomecanvasmm/canvas.h>
39
40 #include "pbd/xml++.h"
41 #include "pbd/controllable.h"
42 #include <gtkmm/box.h>
43 #include <gtkmm/frame.h>
44 #include <gtkmm/label.h>
45 #include <gtkmm/table.h>
46 #include <gtkmm/fixed.h>
47 #include <gtkmm/drawingarea.h>
48 #include <gtkmm/eventbox.h>
49 #include <gtkmm/menu.h>
50 #include <gtkmm/menuitem.h>
51 #include <gtkmm/button.h>
52 #include <gtkmm/togglebutton.h>
53 #include <gtkmm/treeview.h>
54 #include <gtkmm/menubar.h>
55 #include <gtkmm/textbuffer.h>
56 #include <gtkmm/adjustment.h>
57 #include <gtkmm2ext/gtk_ui.h>
58 #include <gtkmm2ext/click_box.h>
59 #include <gtkmm2ext/stateful_button.h>
60 #include <gtkmm2ext/bindable_button.h>
61 #include "ardour/ardour.h"
62 #include "ardour/types.h"
63 #include "ardour/utils.h"
64 #include "ardour/session_handle.h"
65
66 #include "ardour_dialog.h"
67 #include "editing.h"
68 #include "ui_config.h"
69 #include "window_proxy.h"
70 #include "enums.h"
71 #include "visibility_group.h"
72
73 class About;
74 class AddRouteDialog;
75 class ArdourStartup;
76 class ArdourKeyboard;
77 class AudioClock;
78 class BundleManager;
79 class ConnectionEditor;
80 class KeyEditor;
81 class LocationUIWindow;
82 class Mixer_UI;
83 class PublicEditor;
84 class RCOptionEditor;
85 class RouteParams_UI;
86 class SessionOptionEditor;
87 class ShuttleControl;
88 class Splash;
89 class SpeakerDialog;
90 class ThemeManager;
91 class TimeInfoBox;
92 class MidiTracer;
93 class WindowProxyBase;
94 class GlobalPortMatrixWindow;
95 class GUIObjectState;
96
97 namespace Gtkmm2ext {
98         class TearOff;
99 }
100
101 namespace ARDOUR {
102         class ControlProtocolInfo;
103         class IO;
104         class Port;
105         class Route;
106         class RouteGroup;
107         class Location;
108         class ProcessThread;
109 }
110
111 class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
112 {
113   public:
114         ARDOUR_UI (int *argcp, char **argvp[]);
115         ~ARDOUR_UI();
116
117         bool run_startup (bool should_be_new, std::string load_template);
118
119         void show_splash ();
120         void hide_splash ();
121
122         void launch_chat ();
123         void launch_manual ();
124         void launch_reference ();
125         void show_about ();
126         void hide_about ();
127
128         void idle_load (const std::string& path);
129         void finish();
130
131         int load_session (const std::string& path, const std::string& snapshot, std::string mix_template = std::string());
132         bool session_loaded;
133         int build_session (const std::string& path, const std::string& snapshot, ARDOUR::BusProfile&);
134         bool session_is_new() const { return _session_is_new; }
135
136         ARDOUR::Session* the_session() { return _session; }
137
138         bool will_create_new_session_automatically() const {
139                 return _will_create_new_session_automatically;
140         }
141
142         void set_will_create_new_session_automatically (bool yn) {
143                 _will_create_new_session_automatically = yn;
144         }
145
146         int get_session_parameters (bool quit_on_cancel, bool should_be_new = false, std::string load_template = "");
147         int  build_session_from_nsd (const std::string& session_name, const std::string& session_path);
148         bool ask_about_loading_existing_session (const std::string& session_path);
149
150         /// @return true if session was successfully unloaded.
151         int unload_session (bool hide_stuff = false);
152         void close_session();
153
154         int  save_state_canfail (std::string state_name = "", bool switch_to_it = false);
155         void save_state (const std::string & state_name = "", bool switch_to_it = false);
156
157         static ARDOUR_UI *instance () { return theArdourUI; }
158         static UIConfiguration *config () { return ui_config; }
159
160         PublicEditor&     the_editor(){return *editor;}
161         Mixer_UI* the_mixer() { return mixer; }
162
163         void toggle_key_editor ();
164         void toggle_location_window ();
165         void toggle_theme_manager ();
166         void toggle_bundle_manager ();
167         void toggle_big_clock_window ();
168         void toggle_speaker_config_window ();
169         void new_midi_tracer_window ();
170         void toggle_route_params_window ();
171         void toggle_editing_space();
172         void toggle_keep_tearoffs();
173
174         Gtk::Tooltips& tooltips() { return _tooltips; }
175
176         Gtk::HBox& editor_transport_box() { return _editor_transport_box; }
177
178         static PublicEditor* _instance;
179         static sigc::signal<void,bool> Blink;
180         static sigc::signal<void>      RapidScreenUpdate;
181         static sigc::signal<void>      SuperRapidScreenUpdate;
182         /** Emitted frequently with the audible frame, false, and the edit point as
183          *  parameters respectively.
184          */
185         static sigc::signal<void, framepos_t, bool, framepos_t> Clock;
186
187         XMLNode* editor_settings() const;
188         XMLNode* mixer_settings () const;
189         XMLNode* keyboard_settings () const;
190         XMLNode* tearoff_settings (const char*) const;
191
192         void save_ardour_state ();
193         gboolean configure_handler (GdkEventConfigure* conf);
194
195         void do_transport_locate (framepos_t, bool);
196         void halt_on_xrun_message ();
197         void xrun_handler (framepos_t);
198         void create_xrun_marker (framepos_t);
199
200         GUIObjectState* gui_object_state;
201
202         AudioClock* primary_clock;
203         AudioClock* secondary_clock;
204         AudioClock* preroll_clock;
205         AudioClock* postroll_clock;
206
207         TimeInfoBox* time_info_box;
208
209         void store_clock_modes ();
210         void restore_clock_modes ();
211         void reset_main_clocks ();
212
213         void synchronize_sync_source_and_video_pullup ();
214
215         void add_route (Gtk::Window* float_window);
216
217         void session_add_audio_track (
218                 int input_channels,
219                 int32_t output_channels,
220                 ARDOUR::TrackMode mode,
221                 ARDOUR::RouteGroup* route_group,
222                 uint32_t how_many,
223                 std::string const & name_template
224                 ) {
225
226                 session_add_audio_route (true, input_channels, output_channels, mode, route_group, how_many, name_template);
227         }
228
229         void session_add_audio_bus (
230                 int input_channels,
231                 int32_t output_channels,
232                 ARDOUR::RouteGroup* route_group,
233                 uint32_t how_many,
234                 std::string const & name_template
235                 ) {
236
237                 session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, route_group, how_many, name_template);
238         }
239
240         void session_add_midi_track (
241                 ARDOUR::RouteGroup* route_group,
242                 uint32_t how_many,
243                 std::string const & name_template
244                 ) {
245
246                 session_add_midi_route (true, route_group, how_many, name_template);
247         }
248
249         /*void session_add_midi_bus () {
250                 session_add_midi_route (false);
251         }*/
252
253         int  create_engine ();
254         void post_engine ();
255
256         gint exit_on_main_window_close (GdkEventAny *);
257
258         void maximise_editing_space ();
259         void restore_editing_space ();
260
261         void setup_profile ();
262         void setup_theme ();
263         void setup_tooltips ();
264
265         void set_shuttle_fract (double);
266
267         void add_window_proxy (WindowProxyBase *);
268         void remove_window_proxy (WindowProxyBase *);
269
270         void get_process_buffers ();
271         void drop_process_buffers ();
272
273   protected:
274         friend class PublicEditor;
275
276         void toggle_clocking ();
277         void toggle_auto_play ();
278         void toggle_auto_input ();
279         void toggle_punch ();
280         void unset_dual_punch ();
281         bool ignore_dual_punch;
282         void toggle_punch_in ();
283         void toggle_punch_out ();
284         void show_loop_punch_ruler_and_disallow_hide ();
285         void reenable_hide_loop_punch_ruler_if_appropriate ();
286         void toggle_auto_return ();
287         void toggle_click ();
288
289         void toggle_session_auto_loop ();
290
291         void toggle_rc_options_window ();
292         void toggle_session_options_window ();
293
294   private:
295         ArdourStartup*      _startup;
296         ARDOUR::AudioEngine *engine;
297         Gtk::Tooltips        _tooltips;
298
299         void                goto_editor_window ();
300         void                goto_mixer_window ();
301         void                toggle_mixer_window ();
302         void                toggle_mixer_on_top ();
303
304         Gtk::ToggleButton   preroll_button;
305         Gtk::ToggleButton   postroll_button;
306
307         int  setup_windows ();
308         void setup_transport ();
309         void setup_clock ();
310
311         static ARDOUR_UI *theArdourUI;
312
313         void backend_audio_error (bool we_set_params, Gtk::Window* toplevel = 0);
314         void startup ();
315         void shutdown ();
316
317         int  ask_about_saving_session (const std::vector<std::string>& actions);
318
319         /* periodic safety backup, to be precise */
320         gint autosave_session();
321         void update_autosave();
322         sigc::connection _autosave_connection;
323
324         void map_transport_state ();
325         int32_t do_engine_start ();
326
327         void engine_halted (const char* reason, bool free_reason);
328         void engine_stopped ();
329         void engine_running ();
330
331         void use_config ();
332
333         static gint _blink  (void *);
334         void blink ();
335         gint blink_timeout_tag;
336         bool blink_on;
337         void start_blinking ();
338         void stop_blinking ();
339
340         void about_signal_response(int response);
341
342         Gtk::VBox     top_packer;
343
344         sigc::connection clock_signal_connection;
345         void         update_clocks ();
346         void         start_clocking ();
347         void         stop_clocking ();
348
349         void manage_window (Gtk::Window&);
350
351         AudioClock*   big_clock;
352         ActionWindowProxy<Gtk::Window>* big_clock_window;
353         int original_big_clock_width;
354         int original_big_clock_height;
355         double original_big_clock_font_size;
356
357         void big_clock_size_allocate (Gtk::Allocation&);
358         bool idle_big_clock_text_resizer (int width, int height);
359         void big_clock_realized ();
360         bool big_clock_resize_in_progress;
361         int  big_clock_height;
362
363         void float_big_clock (Gtk::Window* parent);
364         bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
365
366         ActionWindowProxy<SpeakerDialog>* speaker_config_window;
367
368         void update_transport_clocks (framepos_t pos);
369         void record_state_changed ();
370
371         std::list<MidiTracer*> _midi_tracer_windows;
372
373         /* Transport Control */
374
375         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
376         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
377
378         Gtkmm2ext::TearOff*      transport_tearoff;
379         Gtk::Frame               transport_frame;
380         Gtk::HBox                transport_tearoff_hbox;
381         Gtk::HBox               _editor_transport_box;
382         Gtk::HBox                transport_hbox;
383         Gtk::Fixed               transport_base;
384         Gtk::Fixed               transport_button_base;
385         Gtk::Frame               transport_button_frame;
386         Gtk::HBox                transport_button_hbox;
387         Gtk::VBox                transport_button_vbox;
388         Gtk::HBox                transport_option_button_hbox;
389         Gtk::VBox                transport_option_button_vbox;
390         Gtk::HBox                transport_clock_hbox;
391         Gtk::VBox                transport_clock_vbox;
392         Gtk::HBox                primary_clock_hbox;
393         Gtk::HBox                secondary_clock_hbox;
394
395         struct TransportControllable : public PBD::Controllable {
396             enum ToggleType {
397                     Roll = 0,
398                     Stop,
399                     RecordEnable,
400                     GotoStart,
401                     GotoEnd,
402                     AutoLoop,
403                     PlaySelection,
404             };
405
406             TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
407             void set_value (double);
408             double get_value (void) const;
409
410             ARDOUR_UI& ui;
411             ToggleType type;
412         };
413
414         boost::shared_ptr<TransportControllable> roll_controllable;
415         boost::shared_ptr<TransportControllable> stop_controllable;
416         boost::shared_ptr<TransportControllable> goto_start_controllable;
417         boost::shared_ptr<TransportControllable> goto_end_controllable;
418         boost::shared_ptr<TransportControllable> auto_loop_controllable;
419         boost::shared_ptr<TransportControllable> play_selection_controllable;
420         boost::shared_ptr<TransportControllable> rec_controllable;
421         boost::shared_ptr<TransportControllable> shuttle_controllable;
422         boost::shared_ptr<TransportControllable> join_play_range_controllable;
423
424         void set_transport_controllable_state (const XMLNode&);
425         XMLNode& get_transport_controllable_state ();
426
427         BindableButton roll_button;
428         BindableButton stop_button;
429         BindableButton goto_start_button;
430         BindableButton goto_end_button;
431         BindableButton auto_loop_button;
432         BindableButton play_selection_button;
433         BindableButton rec_button;
434         BindableToggleButton join_play_range_button;
435
436         void toggle_external_sync ();
437         void toggle_time_master ();
438         void toggle_video_sync ();
439
440         ShuttleControl* shuttle_box;
441
442         Gtkmm2ext::StatefulToggleButton auto_return_button;
443         Gtkmm2ext::StatefulToggleButton auto_play_button;
444         Gtkmm2ext::StatefulToggleButton auto_input_button;
445         Gtkmm2ext::StatefulToggleButton click_button;
446         Gtkmm2ext::StatefulToggleButton time_master_button;
447         Gtkmm2ext::StatefulToggleButton sync_button;
448
449         Gtk::ToggleButton auditioning_alert_button;
450         Gtk::ToggleButton solo_alert_button;
451
452         Gtk::VBox alert_box;
453
454         void solo_blink (bool);
455         void sync_blink (bool);
456         void audition_blink (bool);
457
458         void soloing_changed (bool);
459         void auditioning_changed (bool);
460         void _auditioning_changed (bool);
461
462         bool solo_alert_press (GdkEventButton* ev);
463         bool audition_alert_press (GdkEventButton* ev);
464
465         void big_clock_value_changed ();
466         void primary_clock_value_changed ();
467         void secondary_clock_value_changed ();
468
469         /* called by Blink signal */
470
471         void transport_rec_enable_blink (bool onoff);
472
473         Gtk::Menu*        session_popup_menu;
474
475         struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
476             RecentSessionModelColumns() {
477                     add (visible_name);
478                     add (fullpath);
479             }
480             Gtk::TreeModelColumn<std::string> visible_name;
481             Gtk::TreeModelColumn<std::string> fullpath;
482         };
483
484         RecentSessionModelColumns    recent_session_columns;
485         Gtk::TreeView                recent_session_display;
486         Glib::RefPtr<Gtk::TreeStore> recent_session_model;
487
488         ArdourDialog*     session_selector_window;
489         Gtk::FileChooserDialog* open_session_selector;
490
491         void build_session_selector();
492         void redisplay_recent_sessions();
493         void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
494
495         struct RecentSessionsSorter {
496                 bool operator() (std::pair<std::string,std::string> a, std::pair<std::string,std::string> b) const {
497                     return cmp_nocase(a.first, b.first) == -1;
498             }
499         };
500
501         /* menu bar and associated stuff */
502
503         Gtk::MenuBar* menu_bar;
504         Gtk::EventBox menu_bar_base;
505         Gtk::HBox     menu_hbox;
506
507         void use_menubar_as_top_menubar ();
508         void build_menu_bar ();
509
510         Gtk::Label   wall_clock_label;
511         Gtk::EventBox wall_clock_box;
512         gint update_wall_clock ();
513
514         Gtk::Label   disk_space_label;
515         Gtk::EventBox disk_space_box;
516         void update_disk_space ();
517
518         Gtk::Label   cpu_load_label;
519         Gtk::EventBox cpu_load_box;
520         void update_cpu_load ();
521
522         Gtk::Label   buffer_load_label;
523         Gtk::EventBox buffer_load_box;
524         void update_buffer_load ();
525
526         Gtk::Label   sample_rate_label;
527         Gtk::EventBox sample_rate_box;
528         void update_sample_rate (ARDOUR::framecnt_t);
529
530         Gtk::Label    format_label;
531         Gtk::EventBox format_box;
532         void update_format ();
533         
534         gint every_second ();
535         gint every_point_one_seconds ();
536         gint every_point_zero_one_seconds ();
537
538         sigc::connection second_connection;
539         sigc::connection point_one_second_connection;
540         sigc::connection point_oh_five_second_connection;
541         sigc::connection point_zero_one_second_connection;
542
543         gint session_menu (GdkEventButton *);
544
545         bool _will_create_new_session_automatically;
546
547         void open_session ();
548         void open_recent_session ();
549         void save_template ();
550
551         void edit_metadata ();
552         void import_metadata ();
553
554         void session_add_audio_route (bool, int32_t, int32_t, ARDOUR::TrackMode, ARDOUR::RouteGroup *, uint32_t, std::string const &);
555         void session_add_midi_route (bool, ARDOUR::RouteGroup *, uint32_t, std::string const &);
556
557         void set_transport_sensitivity (bool);
558
559         void remove_last_capture ();
560
561         void transport_goto_zero ();
562         void transport_goto_start ();
563         void transport_goto_end ();
564         void transport_goto_wallclock ();
565         void transport_stop ();
566         void transport_stop_and_forget_capture ();
567         void transport_record (bool roll);
568         void transport_roll ();
569         void transport_play_selection();
570         void transport_forward (int option);
571         void transport_rewind (int option);
572         void transport_loop ();
573         void toggle_roll (bool with_abort, bool roll_out_of_bounded_mode);
574
575         bool _session_is_new;
576         void set_session (ARDOUR::Session *);
577         void connect_dependents_to_session (ARDOUR::Session *);
578         void we_have_dependents ();
579
580         void setup_session_options ();
581
582         guint32  last_key_press_time;
583
584         void snapshot_session (bool switch_to_it);
585         void rename_session ();
586
587         Mixer_UI   *mixer;
588         int         create_mixer ();
589
590         PublicEditor     *editor;
591         int         create_editor ();
592
593         RouteParams_UI *route_params;
594         int             create_route_params ();
595
596         BundleManager *bundle_manager;
597         void create_bundle_manager ();
598
599         ActionWindowProxy<LocationUIWindow>* location_ui;
600         int               create_location_ui ();
601         void              handle_locations_change (ARDOUR::Location*);
602
603         ActionWindowProxy<GlobalPortMatrixWindow>* _global_port_matrix[ARDOUR::DataType::num_types];
604         void toggle_global_port_matrix (ARDOUR::DataType);
605
606         static UIConfiguration *ui_config;
607         ThemeManager *theme_manager;
608
609         /* Key bindings editor */
610
611         KeyEditor *key_editor;
612
613         /* RC Options window */
614
615         RCOptionEditor *rc_option_editor;
616
617         SessionOptionEditor *session_option_editor;
618
619         /* route dialog */
620
621         AddRouteDialog *add_route_dialog;
622
623         /* Keyboard Handling */
624
625         ArdourKeyboard* keyboard;
626
627         /* Keymap handling */
628
629         void install_actions ();
630
631         void toggle_record_enable (uint32_t);
632
633         uint32_t rec_enabled_streams;
634         void count_recenabled_streams (ARDOUR::Route&);
635
636         About* about;
637         Splash* splash;
638         void pop_back_splash ();
639
640         /* cleanup */
641
642         Gtk::MenuItem *cleanup_item;
643
644         void display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title,
645                                       const std::string& plural_msg, const std::string& singular_msg);
646         void cleanup ();
647         void flush_trash ();
648
649         bool have_configure_timeout;
650         ARDOUR::microseconds_t last_configure_time;
651         gint configure_timeout ();
652
653         ARDOUR::microseconds_t last_peak_grab;
654         ARDOUR::microseconds_t last_shuttle_request;
655
656         bool have_disk_speed_dialog_displayed;
657         void disk_speed_dialog_gone (int ignored_response, Gtk::MessageDialog*);
658         void disk_overrun_handler ();
659         void disk_underrun_handler ();
660
661         void session_dialog (std::string);
662         int pending_state_dialog ();
663         int sr_mismatch_dialog (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
664
665         void disconnect_from_jack ();
666         void reconnect_to_jack ();
667         void set_jack_buffer_size (ARDOUR::pframes_t);
668
669         Gtk::MenuItem* jack_disconnect_item;
670         Gtk::MenuItem* jack_reconnect_item;
671         Gtk::Menu*     jack_bufsize_menu;
672
673         Glib::RefPtr<Gtk::ActionGroup> common_actions;
674
675         void editor_realized ();
676
677         std::vector<std::string> positional_sync_strings;
678
679         void toggle_send_midi_feedback ();
680         void toggle_use_mmc ();
681         void toggle_send_mmc ();
682         void toggle_send_mtc ();
683         void toggle_send_midi_clock ();
684
685         void toggle_use_osc ();
686
687         void parameter_changed (std::string);
688         void session_parameter_changed (std::string);
689
690         bool first_idle ();
691
692         void no_memory_warning ();
693         void check_memory_locking ();
694
695         bool check_audioengine();
696         void audioengine_setup ();
697
698         void display_message (const char *prefix, gint prefix_len,
699                         Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
700                         const char *msg);
701         Gtk::Label status_bar_label;
702         bool status_bar_button_press (GdkEventButton*);
703         Gtk::ToggleButton error_log_button;
704
705         void loading_message (const std::string& msg);
706         void end_loading_messages ();
707
708         void toggle_translations ();
709
710         PBD::ScopedConnectionList forever_connections;
711
712         void step_edit_status_change (bool);
713
714         void platform_specific ();
715         void platform_setup ();
716
717         /* these are used only in response to a platform-specific "ShouldQuit" signal
718          */
719         bool idle_finish ();
720         void queue_finish ();
721         void fontconfig_dialog ();
722
723         std::list<WindowProxyBase*> _window_proxies;
724
725         int missing_file (ARDOUR::Session*s, std::string str, ARDOUR::DataType type);
726         int ambiguous_file (std::string file, std::string path, std::vector<std::string> hits);
727
728         bool click_button_clicked (GdkEventButton *);
729
730         VisibilityGroup _status_bar_visibility;
731
732         /** A ProcessThread so that we have some thread-local buffers for use by
733          *  PluginEqGui::impulse_analysis ().
734          */
735         ARDOUR::ProcessThread* _process_thread;
736 };
737
738 #endif /* __ardour_gui_h__ */
739