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