use entered track for fit-tracks if in internal edit mode and no tracks or regions...
[ardour2.git] / gtk2_ardour / ardour_ui.h
blobd38dabc0858d528439080b7520f8933c1adc6472
1 /*
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 #include <time.h>
25 /* need _BSD_SOURCE to get timersub macros */
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
35 #include <list>
36 #include <cmath>
38 #include <libgnomecanvasmm/canvas.h>
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"
66 #include "audio_clock.h"
67 #include "ardour_dialog.h"
68 #include "editing.h"
69 #include "ui_config.h"
70 #include "window_proxy.h"
72 class About;
73 class AddRouteDialog;
74 class ArdourStartup;
75 class ArdourKeyboard;
76 class AudioClock;
77 class BundleManager;
78 class ConnectionEditor;
79 class KeyEditor;
80 class LocationUIWindow;
81 class Mixer_UI;
82 class PublicEditor;
83 class RCOptionEditor;
84 class RouteParams_UI;
85 class SessionOptionEditor;
86 class Splash;
87 class SpeakerDialog;
88 class ThemeManager;
89 class MidiTracer;
90 class WindowProxyBase;
91 class GlobalPortMatrixWindow;
93 namespace Gtkmm2ext {
94 class TearOff;
97 namespace ARDOUR {
98 class ControlProtocolInfo;
99 class IO;
100 class Port;
101 class Route;
102 class RouteGroup;
103 class Location;
106 class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
108 public:
109 ARDOUR_UI (int *argcp, char **argvp[]);
110 ~ARDOUR_UI();
112 bool run_startup (bool should_be_new, std::string load_template);
114 void show_splash ();
115 void hide_splash ();
117 void launch_chat ();
118 void launch_manual ();
119 void launch_reference ();
120 void show_about ();
121 void hide_about ();
123 void idle_load (const std::string& path);
124 void finish();
126 int load_session (const std::string& path, const std::string& snapshot, std::string mix_template = std::string());
127 bool session_loaded;
128 int build_session (const std::string& path, const std::string& snapshot, ARDOUR::BusProfile&);
129 bool session_is_new() const { return _session_is_new; }
131 ARDOUR::Session* the_session() { return _session; }
133 bool will_create_new_session_automatically() const {
134 return _will_create_new_session_automatically;
137 void set_will_create_new_session_automatically (bool yn) {
138 _will_create_new_session_automatically = yn;
141 int get_session_parameters (bool quit_on_cancel, bool should_be_new = false, std::string load_template = "");
142 void parse_cmdline_path (const std::string& cmdline_path, std::string& session_name, std::string& session_path, bool& existing_session);
143 int load_cmdline_session (const std::string& session_name, const std::string& session_path, bool& existing_session);
144 int build_session_from_nsd (const std::string& session_name, const std::string& session_path);
145 bool ask_about_loading_existing_session (const std::string& session_path);
147 /// @return true if session was successfully unloaded.
148 int unload_session (bool hide_stuff = false);
149 void close_session();
151 int save_state_canfail (std::string state_name = "", bool switch_to_it = false);
152 void save_state (const std::string & state_name = "", bool switch_to_it = false);
154 static ARDOUR_UI *instance () { return theArdourUI; }
155 static UIConfiguration *config () { return ui_config; }
157 PublicEditor& the_editor(){return *editor;}
158 Mixer_UI* the_mixer() { return mixer; }
160 void toggle_key_editor ();
161 void toggle_location_window ();
162 void toggle_theme_manager ();
163 void toggle_bundle_manager ();
164 void toggle_big_clock_window ();
165 void toggle_speaker_config_window ();
166 void new_midi_tracer_window ();
167 void toggle_route_params_window ();
168 void toggle_editing_space();
169 void toggle_keep_tearoffs();
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 /** Emitted frequently with the audible frame, false, and the edit point as
177 * parameters respectively.
179 static sigc::signal<void, framepos_t, bool, framepos_t> Clock;
181 XMLNode* editor_settings() const;
182 XMLNode* mixer_settings () const;
183 XMLNode* keyboard_settings () const;
184 XMLNode* tearoff_settings (const char*) const;
186 void save_ardour_state ();
187 gboolean configure_handler (GdkEventConfigure* conf);
189 void do_transport_locate (framepos_t, bool);
190 void halt_on_xrun_message ();
191 void xrun_handler (framepos_t);
192 void create_xrun_marker (framepos_t);
194 AudioClock primary_clock;
195 AudioClock secondary_clock;
196 AudioClock preroll_clock;
197 AudioClock postroll_clock;
199 void store_clock_modes ();
200 void restore_clock_modes ();
201 void reset_main_clocks ();
203 void synchronize_sync_source_and_video_pullup ();
205 void add_route (Gtk::Window* float_window);
207 void session_add_audio_track (
208 int input_channels,
209 int32_t output_channels,
210 ARDOUR::TrackMode mode,
211 ARDOUR::RouteGroup* route_group,
212 uint32_t how_many,
213 std::string const & name_template
216 session_add_audio_route (true, input_channels, output_channels, mode, route_group, how_many, name_template);
219 void session_add_audio_bus (
220 int input_channels,
221 int32_t output_channels,
222 ARDOUR::RouteGroup* route_group,
223 uint32_t how_many,
224 std::string const & name_template
227 session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, route_group, how_many, name_template);
230 void session_add_midi_track (
231 ARDOUR::RouteGroup* route_group,
232 uint32_t how_many,
233 std::string const & name_template
236 session_add_midi_route (true, route_group, how_many, name_template);
239 /*void session_add_midi_bus () {
240 session_add_midi_route (false);
243 int create_engine ();
244 void post_engine ();
246 gint exit_on_main_window_close (GdkEventAny *);
248 void maximise_editing_space ();
249 void restore_editing_space ();
251 void setup_profile ();
252 void setup_theme ();
253 void setup_tooltips ();
255 void set_shuttle_fract (double);
257 void add_window_proxy (WindowProxyBase *);
258 void remove_window_proxy (WindowProxyBase *);
260 protected:
261 friend class PublicEditor;
263 void toggle_clocking ();
264 void toggle_auto_play ();
265 void toggle_auto_input ();
266 void toggle_punch ();
267 void unset_dual_punch ();
268 bool ignore_dual_punch;
269 void toggle_punch_in ();
270 void toggle_punch_out ();
271 void show_loop_punch_ruler_and_disallow_hide ();
272 void reenable_hide_loop_punch_ruler_if_appropriate ();
273 void toggle_auto_return ();
274 void toggle_click ();
276 void toggle_session_auto_loop ();
278 void toggle_rc_options_window ();
279 void toggle_session_options_window ();
281 private:
282 ArdourStartup* _startup;
283 ARDOUR::AudioEngine *engine;
284 Gtk::Tooltips _tooltips;
286 void goto_editor_window ();
287 void goto_mixer_window ();
288 void toggle_mixer_window ();
289 void toggle_mixer_on_top ();
291 Gtk::ToggleButton preroll_button;
292 Gtk::ToggleButton postroll_button;
294 int setup_windows ();
295 void setup_transport ();
296 void setup_clock ();
298 static ARDOUR_UI *theArdourUI;
300 void backend_audio_error (bool we_set_params, Gtk::Window* toplevel = 0);
301 void startup ();
302 void shutdown ();
304 int ask_about_saving_session (const std::string & why);
306 /* periodic safety backup, to be precise */
307 gint autosave_session();
308 void update_autosave();
309 sigc::connection _autosave_connection;
311 void map_transport_state ();
312 int32_t do_engine_start ();
314 void engine_halted (const char* reason, bool free_reason);
315 void engine_stopped ();
316 void engine_running ();
318 void use_config ();
320 static gint _blink (void *);
321 void blink ();
322 gint blink_timeout_tag;
323 bool blink_on;
324 void start_blinking ();
325 void stop_blinking ();
327 void about_signal_response(int response);
329 Gtk::VBox top_packer;
331 sigc::connection clock_signal_connection;
332 void update_clocks ();
333 void start_clocking ();
334 void stop_clocking ();
336 void manage_window (Gtk::Window&);
338 AudioClock big_clock;
339 ActionWindowProxy<Gtk::Window>* big_clock_window;
340 int original_big_clock_width;
341 int original_big_clock_height;
342 double original_big_clock_font_size;
344 void big_clock_size_allocate (Gtk::Allocation&);
345 bool idle_big_clock_text_resizer (int width, int height);
346 void big_clock_realized ();
347 bool big_clock_resize_in_progress;
348 int big_clock_height;
350 void float_big_clock (Gtk::Window* parent);
351 bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
353 ActionWindowProxy<SpeakerDialog>* speaker_config_window;
355 void update_transport_clocks (framepos_t pos);
356 void record_state_changed ();
358 std::list<MidiTracer*> _midi_tracer_windows;
360 /* Transport Control */
362 void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
363 void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
365 Gtkmm2ext::TearOff* transport_tearoff;
366 Gtk::Frame transport_frame;
367 Gtk::HBox transport_tearoff_hbox;
368 Gtk::HBox play_range_hbox;
369 Gtk::VBox play_range_vbox;
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;
384 struct TransportControllable : public PBD::Controllable {
385 enum ToggleType {
386 Roll = 0,
387 Stop,
388 RecordEnable,
389 GotoStart,
390 GotoEnd,
391 AutoLoop,
392 PlaySelection,
393 ShuttleControl
397 TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
398 void set_value (double);
399 double get_value (void) const;
401 void set_id (const std::string&);
403 ARDOUR_UI& ui;
404 ToggleType type;
407 boost::shared_ptr<TransportControllable> roll_controllable;
408 boost::shared_ptr<TransportControllable> stop_controllable;
409 boost::shared_ptr<TransportControllable> goto_start_controllable;
410 boost::shared_ptr<TransportControllable> goto_end_controllable;
411 boost::shared_ptr<TransportControllable> auto_loop_controllable;
412 boost::shared_ptr<TransportControllable> play_selection_controllable;
413 boost::shared_ptr<TransportControllable> rec_controllable;
414 boost::shared_ptr<TransportControllable> shuttle_controllable;
415 BindingProxy shuttle_controller_binding_proxy;
417 void set_transport_controllable_state (const XMLNode&);
418 XMLNode& get_transport_controllable_state ();
420 BindableButton roll_button;
421 BindableButton stop_button;
422 BindableButton goto_start_button;
423 BindableButton goto_end_button;
424 BindableButton auto_loop_button;
425 BindableButton play_selection_button;
426 BindableButton rec_button;
427 Gtk::ToggleButton join_play_range_button;
429 void toggle_external_sync ();
430 void toggle_time_master ();
431 void toggle_video_sync ();
433 Gtk::DrawingArea shuttle_box;
434 Gtk::EventBox speed_display_box;
435 Gtk::Label speed_display_label;
436 Gtk::Button shuttle_units_button;
437 Gtk::ComboBoxText shuttle_style_button;
438 Gtk::Menu* shuttle_unit_menu;
439 Gtk::Menu* shuttle_style_menu;
440 float shuttle_max_speed;
441 Gtk::Menu* shuttle_context_menu;
443 void build_shuttle_context_menu ();
444 void show_shuttle_context_menu ();
445 void shuttle_style_changed();
446 void shuttle_unit_clicked ();
447 void set_shuttle_max_speed (float);
448 void update_speed_display ();
449 float last_speed_displayed;
451 gint shuttle_box_button_press (GdkEventButton*);
452 gint shuttle_box_button_release (GdkEventButton*);
453 gint shuttle_box_scroll (GdkEventScroll*);
454 gint shuttle_box_motion (GdkEventMotion*);
455 gint shuttle_box_expose (GdkEventExpose*);
456 gint mouse_shuttle (double x, bool force);
457 void use_shuttle_fract (bool force);
459 bool shuttle_grabbed;
460 double shuttle_fract;
462 Gtkmm2ext::StatefulToggleButton punch_in_button;
463 Gtkmm2ext::StatefulToggleButton punch_out_button;
464 Gtkmm2ext::StatefulToggleButton auto_return_button;
465 Gtkmm2ext::StatefulToggleButton auto_play_button;
466 Gtkmm2ext::StatefulToggleButton auto_input_button;
467 Gtkmm2ext::StatefulToggleButton click_button;
468 Gtkmm2ext::StatefulToggleButton time_master_button;
469 Gtkmm2ext::StatefulToggleButton sync_button;
471 Gtk::ToggleButton auditioning_alert_button;
472 Gtk::ToggleButton solo_alert_button;
474 Gtk::VBox alert_box;
476 void solo_blink (bool);
477 void sync_blink (bool);
478 void audition_blink (bool);
480 void soloing_changed (bool);
481 void auditioning_changed (bool);
482 void _auditioning_changed (bool);
484 bool solo_alert_press (GdkEventButton* ev);
485 bool audition_alert_press (GdkEventButton* ev);
487 void big_clock_value_changed ();
488 void primary_clock_value_changed ();
489 void secondary_clock_value_changed ();
491 /* called by Blink signal */
493 void transport_rec_enable_blink (bool onoff);
495 Gtk::Menu* session_popup_menu;
497 struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
498 RecentSessionModelColumns() {
499 add (visible_name);
500 add (fullpath);
502 Gtk::TreeModelColumn<std::string> visible_name;
503 Gtk::TreeModelColumn<std::string> fullpath;
506 RecentSessionModelColumns recent_session_columns;
507 Gtk::TreeView recent_session_display;
508 Glib::RefPtr<Gtk::TreeStore> recent_session_model;
510 ArdourDialog* session_selector_window;
511 Gtk::FileChooserDialog* open_session_selector;
513 void build_session_selector();
514 void redisplay_recent_sessions();
515 void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
517 struct RecentSessionsSorter {
518 bool operator() (std::pair<std::string,std::string> a, std::pair<std::string,std::string> b) const {
519 return cmp_nocase(a.first, b.first) == -1;
523 /* menu bar and associated stuff */
525 Gtk::MenuBar* menu_bar;
526 Gtk::EventBox menu_bar_base;
527 Gtk::HBox menu_hbox;
529 void use_menubar_as_top_menubar ();
530 void build_menu_bar ();
532 Gtk::Label wall_clock_label;
533 Gtk::EventBox wall_clock_box;
534 gint update_wall_clock ();
536 Gtk::Label disk_space_label;
537 Gtk::EventBox disk_space_box;
538 void update_disk_space ();
540 Gtk::Label cpu_load_label;
541 Gtk::EventBox cpu_load_box;
542 void update_cpu_load ();
544 Gtk::Label buffer_load_label;
545 Gtk::EventBox buffer_load_box;
546 void update_buffer_load ();
548 Gtk::Label sample_rate_label;
549 Gtk::EventBox sample_rate_box;
550 void update_sample_rate (ARDOUR::framecnt_t);
552 gint every_second ();
553 gint every_point_one_seconds ();
554 gint every_point_zero_one_seconds ();
556 sigc::connection second_connection;
557 sigc::connection point_one_second_connection;
558 sigc::connection point_oh_five_second_connection;
559 sigc::connection point_zero_one_second_connection;
561 gint session_menu (GdkEventButton *);
563 bool _will_create_new_session_automatically;
565 void open_session ();
566 void open_recent_session ();
567 void save_template ();
569 void edit_metadata ();
570 void import_metadata ();
572 void session_add_audio_route (bool, int32_t, int32_t, ARDOUR::TrackMode, ARDOUR::RouteGroup *, uint32_t, std::string const &);
573 void session_add_midi_route (bool, ARDOUR::RouteGroup *, uint32_t, std::string const &);
575 void set_transport_sensitivity (bool);
577 void remove_last_capture ();
579 void transport_goto_zero ();
580 void transport_goto_start ();
581 void transport_goto_end ();
582 void transport_goto_wallclock ();
583 void transport_stop ();
584 void transport_stop_and_forget_capture ();
585 void transport_record (bool roll);
586 void transport_roll ();
587 void transport_play_selection();
588 void transport_forward (int option);
589 void transport_rewind (int option);
590 void transport_loop ();
591 void toggle_roll (bool with_abort, bool roll_out_of_bounded_mode);
593 bool _session_is_new;
594 void set_session (ARDOUR::Session *);
595 void connect_dependents_to_session (ARDOUR::Session *);
596 void we_have_dependents ();
598 void setup_session_options ();
600 guint32 last_key_press_time;
602 void snapshot_session (bool switch_to_it);
604 Mixer_UI *mixer;
605 int create_mixer ();
607 PublicEditor *editor;
608 int create_editor ();
610 RouteParams_UI *route_params;
611 int create_route_params ();
613 BundleManager *bundle_manager;
614 void create_bundle_manager ();
616 ActionWindowProxy<LocationUIWindow>* location_ui;
617 int create_location_ui ();
618 void handle_locations_change (ARDOUR::Location*);
620 ActionWindowProxy<GlobalPortMatrixWindow>* _global_port_matrix[ARDOUR::DataType::num_types];
621 void toggle_global_port_matrix (ARDOUR::DataType);
623 static UIConfiguration *ui_config;
624 ThemeManager *theme_manager;
626 /* Key bindings editor */
628 KeyEditor *key_editor;
630 /* RC Options window */
632 RCOptionEditor *rc_option_editor;
634 SessionOptionEditor *session_option_editor;
636 /* route dialog */
638 AddRouteDialog *add_route_dialog;
640 /* Keyboard Handling */
642 ArdourKeyboard* keyboard;
644 /* Keymap handling */
646 void install_actions ();
648 void toggle_record_enable (uint32_t);
650 uint32_t rec_enabled_streams;
651 void count_recenabled_streams (ARDOUR::Route&);
653 About* about;
654 Splash* splash;
655 void pop_back_splash ();
657 /* cleanup */
659 Gtk::MenuItem *cleanup_item;
661 void display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title,
662 const std::string& plural_msg, const std::string& singular_msg);
663 void cleanup ();
664 void flush_trash ();
666 bool have_configure_timeout;
667 ARDOUR::microseconds_t last_configure_time;
668 gint configure_timeout ();
670 ARDOUR::microseconds_t last_peak_grab;
671 ARDOUR::microseconds_t last_shuttle_request;
673 bool have_disk_speed_dialog_displayed;
674 void disk_speed_dialog_gone (int ignored_response, Gtk::MessageDialog*);
675 void disk_overrun_handler ();
676 void disk_underrun_handler ();
678 void session_dialog (std::string);
679 int pending_state_dialog ();
680 int sr_mismatch_dialog (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
682 void disconnect_from_jack ();
683 void reconnect_to_jack ();
684 void set_jack_buffer_size (ARDOUR::pframes_t);
686 Gtk::MenuItem* jack_disconnect_item;
687 Gtk::MenuItem* jack_reconnect_item;
688 Gtk::Menu* jack_bufsize_menu;
690 Glib::RefPtr<Gtk::ActionGroup> common_actions;
692 void editor_realized ();
694 std::vector<std::string> positional_sync_strings;
696 void toggle_send_midi_feedback ();
697 void toggle_use_mmc ();
698 void toggle_send_mmc ();
699 void toggle_send_mtc ();
700 void toggle_send_midi_clock ();
702 void toggle_use_osc ();
704 void parameter_changed (std::string);
706 bool first_idle ();
708 void no_memory_warning ();
709 void check_memory_locking ();
711 bool check_audioengine();
712 void audioengine_setup ();
714 void display_message (const char *prefix, gint prefix_len,
715 Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
716 const char *msg);
717 Gtk::Label status_bar_label;
718 bool status_bar_button_press (GdkEventButton*);
719 Gtk::ToggleButton error_log_button;
721 void loading_message (const std::string& msg);
722 void end_loading_messages ();
724 void platform_specific ();
725 void platform_setup ();
726 void fontconfig_dialog ();
727 void toggle_translations ();
729 PBD::ScopedConnectionList forever_connections;
731 void step_edit_status_change (bool);
733 /* these are used only in response to a platform-specific "ShouldQuit" signal
735 bool idle_finish ();
736 void queue_finish ();
738 std::list<WindowProxyBase*> _window_proxies;
740 int missing_file (ARDOUR::Session*s, std::string str, ARDOUR::DataType type);
741 int ambiguous_file (std::string file, std::string path, std::vector<std::string> hits);
743 bool click_button_clicked (GdkEventButton *);
746 #endif /* __ardour_gui_h__ */