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