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