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