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__
23 /* need _BSD_SOURCE to get timersub macros */
37 #include <libgnomecanvasmm/canvas.h>
39 #include <pbd/xml++.h>
40 #include <gtkmm/box.h>
41 #include <gtkmm/frame.h>
42 #include <gtkmm/label.h>
43 #include <gtkmm/table.h>
44 #include <gtkmm/fixed.h>
45 #include <gtkmm/drawingarea.h>
46 #include <gtkmm/eventbox.h>
47 #include <gtkmm/menu.h>
48 #include <gtkmm/menuitem.h>
49 #include <gtkmm/button.h>
50 #include <gtkmm/togglebutton.h>
51 #include <gtkmm/treeview.h>
52 #include <gtkmm/menubar.h>
53 #include <gtkmm/textbuffer.h>
54 #include <gtkmm/adjustment.h>
55 #include <gtkmm2ext/gtk_ui.h>
56 #include <gtkmm2ext/click_box.h>
57 #include <gtkmm2ext/stateful_button.h>
58 #include <gtkmm2ext/bindable_button.h>
59 #include <ardour/ardour.h>
60 #include <ardour/session.h>
62 #include "audio_clock.h"
63 #include "ardour_dialog.h"
65 #include "ui_config.h"
73 class ConnectionEditor;
80 class NewSessionDialog;
91 class ControlProtocolInfo;
95 class MultiChannelDevice;
98 #define FRAME_NAME "BaseFrame"
100 extern sigc::signal<void> ColorsChanged;
101 extern sigc::signal<void> DPIReset;
103 class ARDOUR_UI : public Gtkmm2ext::UI
106 ARDOUR_UI (int *argcp, char **argvp[]);
110 bool shown() { return shown_flag; }
118 int load_session (const Glib::ustring & path, const Glib::ustring& snapshot, Glib::ustring mix_template = Glib::ustring());
120 int build_session (const Glib::ustring& path, const Glib::ustring& snapshot,
122 uint32_t master_chns,
123 ARDOUR::AutoConnectOption input_connect,
124 ARDOUR::AutoConnectOption output_connect,
127 nframes_t initial_length);
128 bool session_is_new() const { return _session_is_new; }
130 ARDOUR::Session* the_session() { return session; }
132 bool will_create_new_session_automatically() const {
133 return _will_create_new_session_automatically;
136 void set_will_create_new_session_automatically (bool yn) {
137 _will_create_new_session_automatically = yn;
140 bool get_session_parameters (bool have_engine = false, bool should_be_new = false);
141 void parse_cmdline_path (const Glib::ustring& cmdline_path, Glib::ustring& session_name, Glib::ustring& session_path, bool& existing_session);
142 int load_cmdline_session (const Glib::ustring& session_name, const Glib::ustring& session_path, bool& existing_session);
143 int build_session_from_nsd (const Glib::ustring& session_name, const Glib::ustring& session_path);
144 bool ask_about_loading_existing_session (const Glib::ustring& session_path);
145 int unload_session (bool hide_stuff = false);
146 void close_session();
148 int save_state_canfail (string state_name = "");
149 void save_state (const string & state_name = "");
150 void restore_state (string state_name = "");
152 static double gain_to_slider_position (ARDOUR::gain_t g);
153 static ARDOUR::gain_t slider_position_to_gain (double pos);
155 static ARDOUR_UI *instance () { return theArdourUI; }
156 static UIConfiguration *config () { return ui_config; }
158 PublicEditor& the_editor(){return *editor;}
159 Mixer_UI* the_mixer() { return mixer; }
161 ARDOUR::AudioEngine& the_engine() const { return *engine; }
163 void toggle_key_editor ();
164 void toggle_location_window ();
165 void toggle_theme_manager ();
166 void toggle_big_clock_window ();
167 void toggle_connection_editor ();
168 void toggle_route_params_window ();
169 void toggle_editing_space();
171 Gtk::Tooltips& tooltips() { return _tooltips; }
173 static sigc::signal<void,bool> Blink;
174 static sigc::signal<void> RapidScreenUpdate;
175 static sigc::signal<void> SuperRapidScreenUpdate;
176 static sigc::signal<void,nframes_t, bool, nframes_t> Clock;
178 /* this is a helper function to centralize the (complex) logic for
179 blinking rec-enable buttons.
182 void rec_enable_button_blink (bool onoff, ARDOUR::AudioDiskstream *, Gtk::Widget *w);
184 void name_io_setup (ARDOUR::AudioEngine&, string&, ARDOUR::IO& io, bool in);
186 static gint hide_and_quit (GdkEventAny *ev, ArdourDialog *);
188 XMLNode* editor_settings() const;
189 XMLNode* mixer_settings () const;
190 XMLNode* keyboard_settings () const;
192 void save_ardour_state ();
193 gboolean configure_handler (GdkEventConfigure* conf);
195 void do_transport_locate (nframes_t position);
196 void halt_on_xrun_message ();
197 void xrun_handler (nframes_t);
198 void create_xrun_marker (nframes_t);
200 AudioClock primary_clock;
201 AudioClock secondary_clock;
202 AudioClock preroll_clock;
203 AudioClock postroll_clock;
205 void store_clock_modes ();
206 void restore_clock_modes ();
208 void add_route (Gtk::Window* float_window);
210 void session_add_audio_track (int input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many) {
211 session_add_audio_route (true, input_channels, output_channels, mode, how_many);
214 void session_add_audio_bus (int input_channels, int32_t output_channels, uint32_t how_many) {
215 session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, how_many);
218 void session_add_midi_track ();
220 int create_engine ();
223 gint exit_on_main_window_close (GdkEventAny *);
225 void maximise_editing_space ();
226 void restore_editing_space ();
228 void set_native_file_header_format (ARDOUR::HeaderFormat sf);
229 void set_native_file_data_format (ARDOUR::SampleFormat sf);
231 void setup_profile ();
234 void set_shuttle_fract (double);
237 friend class PublicEditor;
239 void toggle_clocking ();
240 void toggle_auto_play ();
241 void toggle_auto_input ();
242 void toggle_punch ();
243 void toggle_punch_in ();
244 void toggle_punch_out ();
245 void toggle_auto_return ();
246 void toggle_click ();
248 void toggle_session_auto_loop ();
250 void toggle_options_window ();
253 struct GlobalClickBox : public Gtk::VBox {
254 Gtkmm2ext::ClickBox *box;
257 vector<string> &strings;
258 Gtk::Adjustment adjustment;
260 static void printer (char buf[32], Gtk::Adjustment &adj, void *arg);
262 GlobalClickBox (const string &str, vector<string> &vs)
264 adjustment (0, 0, vs.size() - 1, 1, 1, 0) {
265 box = new Gtkmm2ext::ClickBox (&adjustment, "ClickButton");
266 label.set_text (str);
267 label.set_name ("GlobalButtonLabel");
269 frame.set_shadow_type (Gtk::SHADOW_IN);
272 box->set_print_func (printer, this);
273 box->set_wrap (true);
277 ARDOUR::AudioEngine *engine;
278 ARDOUR::Session *session;
280 Gtk::Tooltips _tooltips;
282 void goto_editor_window ();
283 void goto_mixer_window ();
285 Gtk::Table adjuster_table;
286 Gtk::Frame adjuster_frame;
287 Gtk::Fixed adjuster_base;
289 GlobalClickBox *online_control_button;
290 vector<string> online_control_strings;
292 GlobalClickBox *crossfade_time_button;
293 vector<string> crossfade_time_strings;
295 Gtk::ToggleButton preroll_button;
296 Gtk::ToggleButton postroll_button;
298 Gtk::Table transport_table;
299 Gtk::Table option_table;
301 int setup_windows ();
302 void setup_transport ();
305 static ARDOUR_UI *theArdourUI;
307 void backend_audio_error (bool we_set_params, Gtk::Window* toplevel = 0);
312 int ask_about_saving_session (const string & why);
313 int save_the_session;
315 /* periodic safety backup, to be precise */
316 gint autosave_session();
317 void update_autosave();
318 sigc::connection _autosave_connection;
320 void queue_transport_change ();
321 void map_transport_state ();
322 int32_t do_engine_start ();
324 void engine_halted ();
325 void engine_stopped ();
326 void engine_running ();
330 static gint _blink (void *);
332 gint blink_timeout_tag;
334 void start_blinking ();
335 void stop_blinking ();
337 void about_signal_response(int response);
341 Gtk::VBox top_packer;
343 sigc::connection clock_signal_connection;
344 void update_clocks ();
345 void start_clocking ();
346 void stop_clocking ();
348 void manage_window (Gtk::Window&);
350 AudioClock big_clock;
351 Gtk::Frame big_clock_frame;
352 Gtk::Window* big_clock_window;
354 void update_transport_clocks (nframes_t pos);
355 void record_state_changed ();
357 /* Transport Control */
359 void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
360 void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
362 Gtkmm2ext::TearOff* transport_tearoff;
363 Gtk::Frame transport_frame;
364 Gtk::HBox transport_tearoff_hbox;
365 Gtk::HBox transport_hbox;
366 Gtk::Fixed transport_base;
367 Gtk::Fixed transport_button_base;
368 Gtk::Frame transport_button_frame;
369 Gtk::HBox transport_button_hbox;
370 Gtk::VBox transport_button_vbox;
371 Gtk::HBox transport_option_button_hbox;
372 Gtk::VBox transport_option_button_vbox;
373 Gtk::HBox transport_clock_hbox;
374 Gtk::VBox transport_clock_vbox;
375 Gtk::HBox primary_clock_hbox;
376 Gtk::HBox secondary_clock_hbox;
379 struct TransportControllable : public PBD::Controllable {
392 TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
393 void set_value (float);
394 float get_value (void) const;
396 void set_id (const std::string&);
402 TransportControllable roll_controllable;
403 TransportControllable stop_controllable;
404 TransportControllable goto_start_controllable;
405 TransportControllable goto_end_controllable;
406 TransportControllable auto_loop_controllable;
407 TransportControllable play_selection_controllable;
408 TransportControllable rec_controllable;
409 TransportControllable shuttle_controllable;
410 BindingProxy shuttle_controller_binding_proxy;
412 void set_transport_controllable_state (const XMLNode&);
413 XMLNode& get_transport_controllable_state ();
415 BindableButton roll_button;
416 BindableButton stop_button;
417 BindableButton goto_start_button;
418 BindableButton goto_end_button;
419 BindableButton auto_loop_button;
420 BindableButton play_selection_button;
421 BindableButton rec_button;
423 Gtk::ComboBoxText sync_option_combo;
425 void sync_option_changed ();
426 void toggle_time_master ();
427 void toggle_video_sync ();
429 Gtk::DrawingArea shuttle_box;
430 Gtk::EventBox speed_display_box;
431 Gtk::Label speed_display_label;
432 Gtk::Button shuttle_units_button;
433 Gtk::ComboBoxText shuttle_style_button;
434 Gtk::Menu* shuttle_unit_menu;
435 Gtk::Menu* shuttle_style_menu;
436 float shuttle_max_speed;
437 Gtk::Menu* shuttle_context_menu;
439 void build_shuttle_context_menu ();
440 void show_shuttle_context_menu ();
441 void shuttle_style_changed();
442 void shuttle_unit_clicked ();
443 void set_shuttle_max_speed (float);
444 void update_speed_display ();
445 float last_speed_displayed;
447 gint shuttle_box_button_press (GdkEventButton*);
448 gint shuttle_box_button_release (GdkEventButton*);
449 gint shuttle_box_scroll (GdkEventScroll*);
450 gint shuttle_box_motion (GdkEventMotion*);
451 gint shuttle_box_expose (GdkEventExpose*);
452 gint mouse_shuttle (double x, bool force);
453 void use_shuttle_fract (bool force);
455 bool shuttle_grabbed;
456 double shuttle_fract;
458 Gtkmm2ext::StatefulToggleButton punch_in_button;
459 Gtkmm2ext::StatefulToggleButton punch_out_button;
460 Gtkmm2ext::StatefulToggleButton auto_return_button;
461 Gtkmm2ext::StatefulToggleButton auto_play_button;
462 Gtkmm2ext::StatefulToggleButton auto_input_button;
463 Gtkmm2ext::StatefulToggleButton click_button;
464 Gtkmm2ext::StatefulToggleButton time_master_button;
466 Gtk::ToggleButton auditioning_alert_button;
467 Gtk::ToggleButton solo_alert_button;
471 void solo_blink (bool);
472 void audition_blink (bool);
474 void soloing_changed (bool);
475 void auditioning_changed (bool);
476 void _auditioning_changed (bool);
478 void solo_alert_toggle ();
479 void audition_alert_toggle ();
481 void big_clock_value_changed ();
482 void primary_clock_value_changed ();
483 void secondary_clock_value_changed ();
485 /* called by Blink signal */
487 void transport_rec_enable_blink (bool onoff);
489 Gtk::Menu* session_popup_menu;
491 struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
492 RecentSessionModelColumns() {
496 Gtk::TreeModelColumn<Glib::ustring> visible_name;
497 Gtk::TreeModelColumn<Glib::ustring> fullpath;
500 RecentSessionModelColumns recent_session_columns;
501 Gtk::TreeView recent_session_display;
502 Glib::RefPtr<Gtk::TreeStore> recent_session_model;
504 ArdourDialog* session_selector_window;
505 Gtk::FileChooserDialog* open_session_selector;
507 void build_session_selector();
508 void redisplay_recent_sessions();
509 void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
511 struct RecentSessionsSorter {
512 bool operator() (std::pair<string,string> a, std::pair<string,string> b) const {
513 return cmp_nocase(a.first, b.first) == -1;
517 /* menu bar and associated stuff */
519 Gtk::MenuBar* menu_bar;
520 Gtk::EventBox menu_bar_base;
523 void use_menubar_as_top_menubar ();
525 void build_menu_bar ();
526 void build_control_surface_menu ();
528 Gtk::Label wall_clock_label;
529 Gtk::EventBox wall_clock_box;
530 gint update_wall_clock ();
532 Gtk::Label disk_space_label;
533 Gtk::EventBox disk_space_box;
534 void update_disk_space ();
536 Gtk::Label cpu_load_label;
537 Gtk::EventBox cpu_load_box;
538 void update_cpu_load ();
540 Gtk::Label buffer_load_label;
541 Gtk::EventBox buffer_load_box;
542 void update_buffer_load ();
544 Gtk::Label sample_rate_label;
545 Gtk::EventBox sample_rate_box;
546 void update_sample_rate (nframes_t);
548 gint every_second ();
549 gint every_point_one_seconds ();
550 gint every_point_zero_one_seconds ();
552 sigc::connection second_connection;
553 sigc::connection point_one_second_connection;
554 sigc::connection point_oh_five_second_connection;
555 sigc::connection point_zero_one_second_connection;
557 gint session_menu (GdkEventButton *);
559 bool _will_create_new_session_automatically;
561 NewSessionDialog* new_session_dialog;
563 void open_session ();
564 void open_recent_session ();
565 void save_template ();
567 void session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many);
569 void set_transport_sensitivity (bool);
571 void remove_last_capture ();
573 void transport_goto_zero ();
574 void transport_goto_start ();
575 void transport_goto_end ();
576 void transport_stop ();
577 void transport_stop_and_forget_capture ();
578 void transport_record (bool roll);
579 void transport_roll ();
580 void transport_play_selection();
581 void transport_forward (int option);
582 void transport_rewind (int option);
583 void transport_loop ();
585 void transport_rolling ();
586 void transport_rewinding ();
587 void transport_forwarding ();
588 void transport_stopped ();
590 bool _session_is_new;
591 void connect_to_session (ARDOUR::Session *);
592 void connect_dependents_to_session (ARDOUR::Session *);
593 void we_have_dependents ();
595 void setup_session_options ();
597 guint32 last_key_press_time;
599 void snapshot_session ();
604 PublicEditor *editor;
605 int create_editor ();
607 RouteParams_UI *route_params;
608 int create_route_params ();
610 ConnectionEditor *connection_editor;
611 int create_connection_editor ();
613 LocationUI *location_ui;
614 int create_location_ui ();
615 void handle_locations_change (ARDOUR::Location*);
617 static UIConfiguration *ui_config;
618 ThemeManager *theme_manager;
620 /* Key bindings editor */
622 KeyEditor *key_editor;
626 OptionEditor *option_editor;
630 AddRouteDialog *add_route_dialog;
632 /* Keyboard Handling */
636 /* Keymap handling */
638 void install_actions ();
640 void toggle_record_enable (uint32_t);
642 uint32_t rec_enabled_streams;
643 void count_recenabled_streams (ARDOUR::Route&);
647 void pop_back_splash ();
652 Gtk::MenuItem *cleanup_item;
654 void display_cleanup_results (ARDOUR::Session::cleanup_report& rep, const gchar* list_title, const string & msg);
658 bool have_configure_timeout;
659 struct timeval last_configure_time;
660 gint configure_timeout ();
662 struct timeval last_peak_grab;
663 struct timeval 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 ();
670 int pending_state_dialog ();
671 int sr_mismatch_dialog (nframes_t, nframes_t);
673 void disconnect_from_jack ();
674 void reconnect_to_jack ();
675 void set_jack_buffer_size (nframes_t);
677 Gtk::MenuItem* jack_disconnect_item;
678 Gtk::MenuItem* jack_reconnect_item;
679 Gtk::Menu* jack_bufsize_menu;
681 int make_session_clean ();
682 bool filter_ardour_session_dirs (const Gtk::FileFilter::Info&);
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 ();
695 void toggle_use_osc ();
697 void toggle_denormal_protection ();
699 void set_input_auto_connect (ARDOUR::AutoConnectOption);
700 void set_output_auto_connect (ARDOUR::AutoConnectOption);
701 void set_solo_model (ARDOUR::SoloModel);
702 void set_monitor_model (ARDOUR::MonitorModel);
703 void set_remote_model (ARDOUR::RemoteModel);
704 void set_denormal_model (ARDOUR::DenormalModel);
706 void toggle_sync_order_keys ();
707 void toggle_StopPluginsWithTransport();
708 void toggle_DoNotRunPluginsWhileRecording();
709 void toggle_VerifyRemoveLastCapture();
710 void toggle_PeriodicSafetyBackups();
711 void toggle_StopRecordingOnXrun();
712 void toggle_CreateXrunMarker();
713 void toggle_StopTransportAtEndOfSession();
714 void toggle_GainReduceFastTransport();
715 void toggle_LatchedSolo();
716 void toggle_ShowSoloMutes();
717 void toggle_LatchedRecordEnable ();
718 void toggle_RegionEquivalentsOverlap ();
719 void toggle_PrimaryClockDeltaEditCursor ();
720 void toggle_SecondaryClockDeltaEditCursor ();
721 void toggle_only_copy_imported_files ();
722 void toggle_ShowTrackMeters ();
723 void toggle_use_narrow_ms();
724 void toggle_rubberbanding_snaps_to_grid ();
725 void toggle_TapeMachineMode();
727 void mtc_port_changed ();
728 void map_solo_model ();
729 void map_monitor_model ();
730 void map_denormal_model ();
731 void map_denormal_protection ();
732 void map_remote_model ();
733 void map_file_header_format ();
734 void map_file_data_format ();
735 void map_input_auto_connect ();
736 void map_output_auto_connect ();
737 void map_only_copy_imported_files ();
738 void parameter_changed (const char*);
740 void set_meter_hold (ARDOUR::MeterHold);
741 void set_meter_falloff (ARDOUR::MeterFalloff);
742 void map_meter_hold ();
743 void map_meter_falloff ();
745 void toggle_control_protocol (ARDOUR::ControlProtocolInfo*);
746 void toggle_control_protocol_feedback (ARDOUR::ControlProtocolInfo*, const char* group_name, std::string action_name);
750 void no_memory_warning ();
751 void check_memory_locking ();
753 bool check_audioengine();
754 void audioengine_setup ();
756 void display_message (const char *prefix, gint prefix_len,
757 Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag, const char *msg);
758 Gtk::Label status_bar_label;
759 Gtk::ToggleButton error_log_button;
761 void loading_message (const std::string& msg);
762 void end_loading_messages ();
764 void platform_specific ();
765 void platform_setup ();
766 void fontconfig_dialog ();
769 #endif /* __ardour_gui_h__ */