2 Copyright (C) 1999-2002 Paul Davis
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.
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.
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.
20 #ifndef __ardour_gui_h__
21 #define __ardour_gui_h__
25 /* need _BSD_SOURCE to get timersub macros */
39 #include "pbd/xml++.h"
40 #include "pbd/controllable.h"
41 #include "pbd/system_exec.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>
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"
68 #include "video_timeline.h"
71 #include "ardour_button.h"
72 #include "ardour_dialog.h"
73 #include "ardour_window.h"
75 #include "engine_dialog.h"
76 #include "meterbridge.h"
77 #include "ui_config.h"
79 #include "visibility_group.h"
80 #include "window_manager.h"
82 #include "add_route_dialog.h"
83 #include "add_video_dialog.h"
84 #include "big_clock_window.h"
85 #include "bundle_manager.h"
86 #include "global_port_matrix.h"
87 #include "keyeditor.h"
88 #include "location_ui.h"
89 #include "rc_option_editor.h"
90 #include "route_params_ui.h"
91 #include "session_option_editor.h"
92 #include "speaker_dialog.h"
93 #include "theme_manager.h"
99 class ConnectionEditor;
103 class RCOptionEditor;
104 class RouteParams_UI;
106 class SessionOptionEditor;
107 class ShuttleControl;
112 class LevelMeterHBox;
113 class GUIObjectState;
115 namespace Gtkmm2ext {
120 class ControlProtocolInfo;
129 class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
132 ARDOUR_UI (int *argcp, char **argvp[], const char* localedir);
135 bool run_startup (bool should_be_new, std::string load_template);
141 void launch_manual ();
142 void launch_reference ();
146 void idle_load (const std::string& path);
149 int load_session (const std::string& path, const std::string& snapshot, std::string mix_template = std::string());
151 int build_session (const std::string& path, const std::string& snapshot, ARDOUR::BusProfile&);
152 bool session_is_new() const { return _session_is_new; }
154 ARDOUR::Session* the_session() { return _session; }
156 bool get_smart_mode () const;
158 int get_session_parameters (bool quit_on_cancel, bool should_be_new = false, std::string load_template = "");
159 int build_session_from_dialog (SessionDialog&, const std::string& session_name, const std::string& session_path);
160 bool ask_about_loading_existing_session (const std::string& session_path);
162 /// @return true if session was successfully unloaded.
163 int unload_session (bool hide_stuff = false);
164 void close_session();
166 int save_state_canfail (std::string state_name = "", bool switch_to_it = false);
167 void save_state (const std::string & state_name = "", bool switch_to_it = false);
169 static ARDOUR_UI *instance () { return theArdourUI; }
170 static UIConfiguration *config () { return ui_config; }
172 PublicEditor& the_editor(){return *editor;}
173 Mixer_UI* the_mixer() { return mixer; }
175 void new_midi_tracer_window ();
176 void toggle_editing_space();
177 void toggle_keep_tearoffs();
179 Gtk::Tooltips& tooltips() { return _tooltips; }
181 Gtk::HBox& editor_transport_box() { return _editor_transport_box; }
183 static PublicEditor* _instance;
184 static sigc::signal<void,bool> Blink;
186 /** point_zero_one_seconds -- 10Hz ^= 100ms */
187 static sigc::signal<void> RapidScreenUpdate;
189 /** point_zero_something_seconds -- currently 25Hz ^= 40ms */
190 static sigc::signal<void> SuperRapidScreenUpdate;
192 /** Emitted frequently with the audible frame, false, and the edit point as
193 * parameters respectively.
195 * (either RapidScreenUpdate || SuperRapidScreenUpdate - user-config)
197 static sigc::signal<void, framepos_t, bool, framepos_t> Clock;
199 static void close_all_dialogs () { CloseAllDialogs(); }
200 static sigc::signal<void> CloseAllDialogs;
202 XMLNode* editor_settings() const;
203 XMLNode* mixer_settings () const;
204 XMLNode* keyboard_settings () const;
205 XMLNode* tearoff_settings (const char*) const;
207 void save_ardour_state ();
208 gboolean configure_handler (GdkEventConfigure* conf);
210 void halt_on_xrun_message ();
211 void xrun_handler (framepos_t);
212 void create_xrun_marker (framepos_t);
214 GUIObjectState* gui_object_state;
216 MainClock* primary_clock;
217 MainClock* secondary_clock;
218 void focus_on_clock ();
219 AudioClock* big_clock;
221 TimeInfoBox* time_info_box;
223 VideoTimeLine *video_timeline;
225 void store_clock_modes ();
226 void restore_clock_modes ();
227 void reset_main_clocks ();
229 void synchronize_sync_source_and_video_pullup ();
231 void add_route (Gtk::Window* float_window);
232 void add_routes_part_two ();
233 void add_routes_thread ();
235 void add_video (Gtk::Window* float_window);
236 void remove_video ();
237 void start_video_server_menu (Gtk::Window* float_window);
238 bool start_video_server (Gtk::Window* float_window, bool popup_msg);
239 void stop_video_server (bool ask_confirm=false);
240 void flush_videotimeline_cache (bool localcacheonly=false);
242 void session_add_audio_track (
244 int32_t output_channels,
245 ARDOUR::TrackMode mode,
246 ARDOUR::RouteGroup* route_group,
248 std::string const & name_template
251 session_add_audio_route (true, input_channels, output_channels, mode, route_group, how_many, name_template);
254 void session_add_audio_bus (int input_channels, int32_t output_channels, ARDOUR::RouteGroup* route_group,
255 uint32_t how_many, std::string const & name_template) {
256 session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, route_group, how_many, name_template);
259 void session_add_midi_track (ARDOUR::RouteGroup* route_group, uint32_t how_many, std::string const & name_template,
260 ARDOUR::PluginInfoPtr instrument) {
261 session_add_midi_route (true, route_group, how_many, name_template, instrument);
264 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,
265 ARDOUR::PluginInfoPtr instrument);
267 /*void session_add_midi_bus () {
268 session_add_midi_route (false);
271 void attach_to_engine ();
274 gint exit_on_main_window_close (GdkEventAny *);
276 void maximise_editing_space ();
277 void restore_editing_space ();
279 void update_tearoff_visibility ();
281 void setup_profile ();
282 void setup_tooltips ();
284 void set_shuttle_fract (double);
286 void get_process_buffers ();
287 void drop_process_buffers ();
289 void reset_peak_display ();
290 void reset_route_peak_display (ARDOUR::Route*);
291 void reset_group_peak_display (ARDOUR::RouteGroup*);
293 const std::string& announce_string() const { return _announce_string; }
295 int disconnect_from_engine ();
296 int reconnect_to_engine ();
299 friend class PublicEditor;
301 void toggle_auto_play ();
302 void toggle_auto_input ();
303 void toggle_punch ();
304 void unset_dual_punch ();
305 bool ignore_dual_punch;
306 void toggle_punch_in ();
307 void toggle_punch_out ();
308 void show_loop_punch_ruler_and_disallow_hide ();
309 void reenable_hide_loop_punch_ruler_if_appropriate ();
310 void toggle_auto_return ();
311 void toggle_click ();
312 void toggle_audio_midi_setup ();
313 void toggle_session_auto_loop ();
314 void toggle_rc_options_window ();
315 void toggle_session_options_window ();
318 Gtk::Tooltips _tooltips;
322 bool first_time_engine_run;
324 void goto_editor_window ();
325 void goto_mixer_window ();
326 void toggle_mixer_window ();
327 void toggle_meterbridge ();
328 void toggle_editor_mixer ();
330 int setup_windows ();
331 void setup_transport ();
334 static ARDOUR_UI *theArdourUI;
338 int ask_about_saving_session (const std::vector<std::string>& actions);
340 /* periodic safety backup, to be precise */
341 gint autosave_session();
342 void update_autosave();
343 sigc::connection _autosave_connection;
345 void map_transport_state ();
346 int32_t do_engine_start ();
348 void engine_halted (const char* reason, bool free_reason);
349 void engine_stopped ();
350 void engine_running ();
354 static gint _blink (void *);
356 gint blink_timeout_tag;
358 void start_blinking ();
359 void stop_blinking ();
361 void about_signal_response(int response);
363 Gtk::VBox top_packer;
365 sigc::connection clock_signal_connection;
366 void update_clocks ();
367 void start_clocking ();
368 void stop_clocking ();
370 bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
372 void update_transport_clocks (framepos_t pos);
373 void record_state_changed ();
375 std::list<MidiTracer*> _midi_tracer_windows;
377 /* Transport Control */
379 void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
380 void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
382 Gtkmm2ext::TearOff* transport_tearoff;
383 Gtk::Frame transport_frame;
384 Gtk::HBox transport_tearoff_hbox;
385 Gtk::HBox _editor_transport_box;
386 Gtk::HBox transport_hbox;
387 Gtk::Fixed transport_base;
388 Gtk::Fixed transport_button_base;
389 Gtk::Frame transport_button_frame;
390 Gtk::HBox transport_button_hbox;
391 Gtk::VBox transport_button_vbox;
392 Gtk::HBox transport_option_button_hbox;
393 Gtk::VBox transport_option_button_vbox;
394 Gtk::HBox transport_clock_hbox;
395 Gtk::VBox transport_clock_vbox;
396 Gtk::HBox primary_clock_hbox;
397 Gtk::HBox secondary_clock_hbox;
399 struct TransportControllable : public PBD::Controllable {
410 TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
411 void set_value (double);
412 double get_value (void) const;
418 boost::shared_ptr<TransportControllable> roll_controllable;
419 boost::shared_ptr<TransportControllable> stop_controllable;
420 boost::shared_ptr<TransportControllable> goto_start_controllable;
421 boost::shared_ptr<TransportControllable> goto_end_controllable;
422 boost::shared_ptr<TransportControllable> auto_loop_controllable;
423 boost::shared_ptr<TransportControllable> play_selection_controllable;
424 boost::shared_ptr<TransportControllable> rec_controllable;
426 void toggle_always_play_range ();
428 void set_transport_controllable_state (const XMLNode&);
429 XMLNode& get_transport_controllable_state ();
431 ArdourButton roll_button;
432 ArdourButton stop_button;
433 ArdourButton goto_start_button;
434 ArdourButton goto_end_button;
435 ArdourButton auto_loop_button;
436 ArdourButton play_selection_button;
437 ArdourButton rec_button;
439 void toggle_external_sync ();
440 void toggle_time_master ();
441 void toggle_video_sync ();
443 ShuttleControl* shuttle_box;
445 ArdourButton auto_return_button;
446 ArdourButton follow_edits_button;
447 ArdourButton auto_input_button;
448 ArdourButton click_button;
449 ArdourButton sync_button;
451 ArdourButton auditioning_alert_button;
452 ArdourButton solo_alert_button;
453 ArdourButton feedback_alert_button;
457 LevelMeterHBox * editor_meter;
458 float editor_meter_max_peak;
459 ArdourButton editor_meter_peak_display;
460 bool editor_meter_peak_button_release (GdkEventButton*);
462 void solo_blink (bool);
463 void sync_blink (bool);
464 void audition_blink (bool);
465 void feedback_blink (bool);
467 void soloing_changed (bool);
468 void auditioning_changed (bool);
469 void _auditioning_changed (bool);
471 bool solo_alert_press (GdkEventButton* ev);
472 bool audition_alert_press (GdkEventButton* ev);
473 bool feedback_alert_press (GdkEventButton *);
475 void big_clock_value_changed ();
476 void primary_clock_value_changed ();
477 void secondary_clock_value_changed ();
479 /* called by Blink signal */
481 void transport_rec_enable_blink (bool onoff);
483 Gtk::Menu* session_popup_menu;
485 struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
486 RecentSessionModelColumns() {
491 Gtk::TreeModelColumn<std::string> visible_name;
492 Gtk::TreeModelColumn<std::string> tip;
493 Gtk::TreeModelColumn<std::string> fullpath;
496 RecentSessionModelColumns recent_session_columns;
497 Gtk::TreeView recent_session_display;
498 Glib::RefPtr<Gtk::TreeStore> recent_session_model;
500 ArdourDialog* session_selector_window;
501 Gtk::FileChooserDialog* open_session_selector;
503 void build_session_selector();
504 void redisplay_recent_sessions();
505 void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
507 struct RecentSessionsSorter {
508 bool operator() (std::pair<std::string,std::string> a, std::pair<std::string,std::string> b) const {
509 return cmp_nocase(a.first, b.first) == -1;
513 /* menu bar and associated stuff */
515 Gtk::MenuBar* menu_bar;
516 Gtk::EventBox menu_bar_base;
519 void use_menubar_as_top_menubar ();
520 void build_menu_bar ();
522 Gtk::Label wall_clock_label;
523 gint update_wall_clock ();
525 Gtk::Label disk_space_label;
526 void update_disk_space ();
528 Gtk::Label timecode_format_label;
529 void update_timecode_format ();
531 Gtk::Label cpu_load_label;
532 void update_cpu_load ();
534 Gtk::Label buffer_load_label;
535 void update_buffer_load ();
537 Gtk::Label sample_rate_label;
538 void update_sample_rate (ARDOUR::framecnt_t);
540 Gtk::Label format_label;
541 void update_format ();
543 gint every_second ();
544 gint every_point_one_seconds ();
545 gint every_point_zero_something_seconds ();
547 sigc::connection second_connection;
548 sigc::connection point_one_second_connection;
549 sigc::connection point_zero_something_second_connection;
551 void open_session ();
552 void open_recent_session ();
553 void save_template ();
555 void edit_metadata ();
556 void import_metadata ();
558 void session_add_audio_route (bool, int32_t, int32_t, ARDOUR::TrackMode, ARDOUR::RouteGroup *, uint32_t, std::string const &);
559 void session_add_midi_route (bool, ARDOUR::RouteGroup *, uint32_t, std::string const &, ARDOUR::PluginInfoPtr);
561 void set_transport_sensitivity (bool);
563 void transport_goto_zero ();
564 void transport_goto_start ();
565 void transport_goto_end ();
566 void transport_goto_wallclock ();
567 void transport_stop ();
568 void transport_record (bool roll);
569 void transport_roll ();
570 void transport_play_selection();
571 void transport_play_preroll();
572 void transport_forward (int option);
573 void transport_rewind (int option);
574 void transport_loop ();
575 void toggle_roll (bool with_abort, bool roll_out_of_bounded_mode);
577 bool _session_is_new;
578 void set_session (ARDOUR::Session *);
579 void connect_dependents_to_session (ARDOUR::Session *);
580 void we_have_dependents ();
582 void setup_session_options ();
584 guint32 last_key_press_time;
586 void snapshot_session (bool switch_to_it);
587 void rename_session ();
588 void setup_order_hint ();
593 PublicEditor *editor;
594 int create_editor ();
596 Meterbridge *meterbridge;
597 int create_meterbridge ();
598 /* Dialogs that can be created via new<T> */
600 WM::Proxy<SpeakerDialog> speaker_config_window;
601 WM::Proxy<ThemeManager> theme_manager;
602 WM::Proxy<KeyEditor> key_editor;
603 WM::Proxy<RCOptionEditor> rc_option_editor;
604 WM::Proxy<AddRouteDialog> add_route_dialog;
605 WM::Proxy<About> about;
606 WM::Proxy<LocationUIWindow> location_ui;
607 WM::Proxy<RouteParams_UI> route_params;
608 WM::Proxy<EngineControl> audio_midi_setup;
610 /* Windows/Dialogs that require a creator method */
612 WM::ProxyWithConstructor<SessionOptionEditor> session_option_editor;
613 WM::ProxyWithConstructor<AddVideoDialog> add_video_dialog;
614 WM::ProxyWithConstructor<BundleManager> bundle_manager;
615 WM::ProxyWithConstructor<BigClockWindow> big_clock_window;
616 WM::ProxyWithConstructor<GlobalPortMatrixWindow> audio_port_matrix;
617 WM::ProxyWithConstructor<GlobalPortMatrixWindow> midi_port_matrix;
619 /* creator methods */
621 SessionOptionEditor* create_session_option_editor ();
622 BundleManager* create_bundle_manager ();
623 AddVideoDialog* create_add_video_dialog ();
624 BigClockWindow* create_big_clock_window();
625 GlobalPortMatrixWindow* create_global_port_matrix (ARDOUR::DataType);
627 static UIConfiguration *ui_config;
629 PBD::SystemExec *video_server_process;
631 void handle_locations_change (ARDOUR::Location*);
633 /* Keyboard Handling */
635 ArdourKeyboard* keyboard;
637 /* Keymap handling */
639 void install_actions ();
641 void toggle_record_enable (uint32_t);
643 uint32_t rec_enabled_streams;
644 void count_recenabled_streams (ARDOUR::Route&);
648 void pop_back_splash (Gtk::Window&);
652 Gtk::MenuItem *cleanup_item;
654 void display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title, const bool msg_delete);
658 bool have_configure_timeout;
659 ARDOUR::microseconds_t last_configure_time;
660 gint configure_timeout ();
662 ARDOUR::microseconds_t last_peak_grab;
663 ARDOUR::microseconds_t last_shuttle_request;
665 bool have_disk_speed_dialog_displayed;
666 void disk_speed_dialog_gone (int ignored_response, Gtk::MessageDialog*);
667 void disk_overrun_handler ();
668 void disk_underrun_handler ();
669 void gui_idle_handler ();
671 void cancel_plugin_scan ();
672 void plugin_scan_dialog (std::string type, std::string plugin, bool);
674 void session_format_mismatch (std::string, std::string);
676 void session_dialog (std::string);
677 int pending_state_dialog ();
678 int sr_mismatch_dialog (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
680 Gtk::MenuItem* jack_disconnect_item;
681 Gtk::MenuItem* jack_reconnect_item;
682 Gtk::Menu* jack_bufsize_menu;
684 Glib::RefPtr<Gtk::ActionGroup> common_actions;
686 void editor_realized ();
688 std::vector<std::string> positional_sync_strings;
690 void toggle_send_midi_feedback ();
691 void toggle_use_mmc ();
692 void toggle_send_mmc ();
693 void toggle_send_mtc ();
694 void toggle_send_midi_clock ();
696 void toggle_use_osc ();
698 void parameter_changed (std::string);
699 void session_parameter_changed (std::string);
703 void check_memory_locking ();
705 bool check_audioengine();
706 void audioengine_setup ();
708 void display_message (const char *prefix, gint prefix_len,
709 Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
711 Gtk::Label status_bar_label;
712 bool status_bar_button_press (GdkEventButton*);
713 Gtk::ToggleButton error_log_button;
715 void loading_message (const std::string& msg);
717 PBD::ScopedConnectionList forever_connections;
718 PBD::ScopedConnection halt_connection;
720 void step_edit_status_change (bool);
722 void platform_specific ();
723 void platform_setup ();
725 /* these are used only in response to a platform-specific "ShouldQuit" signal
728 void queue_finish ();
729 void fontconfig_dialog ();
731 int missing_file (ARDOUR::Session*s, std::string str, ARDOUR::DataType type);
732 int ambiguous_file (std::string file, std::vector<std::string> hits);
734 bool click_button_clicked (GdkEventButton *);
736 VisibilityGroup _status_bar_visibility;
738 /** A ProcessThread so that we have some thread-local buffers for use by
739 * PluginEqGui::impulse_analysis ().
741 ARDOUR::ProcessThread* _process_thread;
743 void feedback_detected ();
745 ArdourButton midi_panic_button;
748 void successful_graph_sort ();
749 bool _feedback_exists;
751 void resize_text_widgets ();
753 std::string _announce_string;
754 void check_announcements ();
756 int do_audio_midi_setup (uint32_t);
759 #endif /* __ardour_gui_h__ */