fix math bug with numthreads computation
[ardour2.git] / gtk2_ardour / ardour_ui.h
blob643202a32b8f41ccea8252573c3975108dcf871f
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"
71 class About;
72 class AddRouteDialog;
73 class ArdourStartup;
74 class ArdourKeyboard;
75 class AudioClock;
76 class BundleManager;
77 class ConnectionEditor;
78 class KeyEditor;
79 class LocationUIWindow;
80 class Mixer_UI;
81 class PublicEditor;
82 class RCOptionEditor;
83 class RouteParams_UI;
84 class SessionOptionEditor;
85 class Splash;
86 class ThemeManager;
88 namespace Gtkmm2ext {
89 class TearOff;
92 namespace ARDOUR {
93 class ControlProtocolInfo;
94 class IO;
95 class Port;
96 class Route;
97 class RouteGroup;
98 class Location;
101 extern sigc::signal<void> ColorsChanged;
102 extern sigc::signal<void> DPIReset;
104 class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
106 public:
107 ARDOUR_UI (int *argcp, char **argvp[]);
108 ~ARDOUR_UI();
110 bool run_startup (bool should_be_new, std::string load_template);
112 void show ();
113 bool shown() { return shown_flag; }
115 void show_splash ();
116 void hide_splash ();
118 void launch_chat ();
119 void show_about ();
120 void hide_about ();
122 void idle_load (const Glib::ustring& path);
123 void finish();
125 int load_session (const Glib::ustring& path, const Glib::ustring& snapshot, Glib::ustring mix_template = Glib::ustring());
126 bool session_loaded;
127 int build_session (const Glib::ustring& path, const Glib::ustring& snapshot, ARDOUR::BusProfile&);
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 int get_session_parameters (bool quit_on_cancel, bool should_be_new = false, std::string load_template = "");
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);
146 /// @return true if session was successfully unloaded.
147 int unload_session (bool hide_stuff = false);
148 void close_session();
150 int save_state_canfail (std::string state_name = "", bool switch_to_it = false);
151 void save_state (const std::string & state_name = "", bool switch_to_it = false);
153 static double gain_to_slider_position (ARDOUR::gain_t g);
154 static ARDOUR::gain_t slider_position_to_gain (double pos);
156 static ARDOUR_UI *instance () { return theArdourUI; }
157 static UIConfiguration *config () { return ui_config; }
159 PublicEditor& the_editor(){return *editor;}
160 Mixer_UI* the_mixer() { return mixer; }
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_route_params_window ();
168 void toggle_editing_space();
170 Gtk::Tooltips& tooltips() { return _tooltips; }
172 static sigc::signal<void,bool> Blink;
173 static sigc::signal<void> RapidScreenUpdate;
174 static sigc::signal<void> SuperRapidScreenUpdate;
175 static sigc::signal<void,nframes_t, bool, nframes_t> Clock;
177 XMLNode* editor_settings() const;
178 XMLNode* mixer_settings () const;
179 XMLNode* keyboard_settings () const;
180 XMLNode* tearoff_settings (const char*) const;
182 void save_ardour_state ();
183 gboolean configure_handler (GdkEventConfigure* conf);
185 void do_transport_locate (nframes_t position);
186 void halt_on_xrun_message ();
187 void xrun_handler (nframes_t);
188 void create_xrun_marker (nframes_t);
190 AudioClock primary_clock;
191 AudioClock secondary_clock;
192 AudioClock preroll_clock;
193 AudioClock postroll_clock;
195 void store_clock_modes ();
196 void restore_clock_modes ();
197 void reset_main_clocks ();
199 void add_route (Gtk::Window* float_window);
201 void session_add_audio_track (int input_channels, int32_t output_channels, ARDOUR::TrackMode mode, ARDOUR::RouteGroup* route_group, uint32_t how_many) {
202 session_add_audio_route (true, false, input_channels, output_channels, mode, route_group, how_many);
205 void session_add_audio_bus (bool aux, int input_channels, int32_t output_channels, ARDOUR::RouteGroup* route_group, uint32_t how_many) {
206 session_add_audio_route (false, aux, input_channels, output_channels, ARDOUR::Normal, route_group, how_many);
209 void session_add_midi_track (ARDOUR::RouteGroup* route_group, uint32_t how_many) {
210 session_add_midi_route (true, route_group, how_many);
213 /*void session_add_midi_bus () {
214 session_add_midi_route (false);
217 int create_engine ();
218 void post_engine ();
220 gint exit_on_main_window_close (GdkEventAny *);
222 void maximise_editing_space ();
223 void restore_editing_space ();
225 void setup_profile ();
226 void setup_theme ();
227 void setup_tooltips ();
229 void set_shuttle_fract (double);
231 protected:
232 friend class PublicEditor;
234 void toggle_clocking ();
235 void toggle_auto_play ();
236 void toggle_auto_input ();
237 void toggle_punch ();
238 void unset_dual_punch ();
239 bool ignore_dual_punch;
240 void toggle_punch_in ();
241 void toggle_punch_out ();
242 void show_loop_punch_ruler_and_disallow_hide ();
243 void reenable_hide_loop_punch_ruler_if_appropriate ();
244 void toggle_auto_return ();
245 void toggle_click ();
247 void toggle_session_auto_loop ();
249 void toggle_rc_options_window ();
250 void toggle_session_options_window ();
252 private:
253 ArdourStartup* _startup;
254 ARDOUR::AudioEngine *engine;
255 Gtk::Tooltips _tooltips;
257 void goto_editor_window ();
258 void goto_mixer_window ();
259 void toggle_editor_mixer_on_top ();
260 bool _mixer_on_top;
262 Gtk::ToggleButton preroll_button;
263 Gtk::ToggleButton postroll_button;
265 int setup_windows ();
266 void setup_transport ();
267 void setup_clock ();
269 static ARDOUR_UI *theArdourUI;
271 void backend_audio_error (bool we_set_params, Gtk::Window* toplevel = 0);
272 void startup ();
273 void shutdown ();
275 int ask_about_saving_session (const std::string & why);
277 /* periodic safety backup, to be precise */
278 gint autosave_session();
279 void update_autosave();
280 sigc::connection _autosave_connection;
282 void map_transport_state ();
283 int32_t do_engine_start ();
285 void engine_halted (const char* reason, bool free_reason);
286 void engine_stopped ();
287 void engine_running ();
289 void use_config ();
291 static gint _blink (void *);
292 void blink ();
293 gint blink_timeout_tag;
294 bool blink_on;
295 void start_blinking ();
296 void stop_blinking ();
298 void about_signal_response(int response);
300 private:
301 Gtk::VBox top_packer;
303 sigc::connection clock_signal_connection;
304 void update_clocks ();
305 void start_clocking ();
306 void stop_clocking ();
308 void manage_window (Gtk::Window&);
310 AudioClock big_clock;
311 Gtk::Window* big_clock_window;
312 int original_big_clock_width;
313 int original_big_clock_height;
314 double original_big_clock_font_size;
316 void big_clock_size_allocate (Gtk::Allocation&);
317 bool idle_big_clock_text_resizer (int width, int height);
318 void big_clock_realized ();
319 bool big_clock_resize_in_progress;
320 int big_clock_height;
322 void float_big_clock (Gtk::Window* parent);
323 bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
325 void update_transport_clocks (nframes_t pos);
326 void record_state_changed ();
328 /* Transport Control */
330 void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
331 void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
333 Gtkmm2ext::TearOff* transport_tearoff;
334 Gtk::Frame transport_frame;
335 Gtk::HBox transport_tearoff_hbox;
336 Gtk::HBox play_range_hbox;
337 Gtk::VBox play_range_vbox;
338 Gtk::HBox transport_hbox;
339 Gtk::Fixed transport_base;
340 Gtk::Fixed transport_button_base;
341 Gtk::Frame transport_button_frame;
342 Gtk::HBox transport_button_hbox;
343 Gtk::VBox transport_button_vbox;
344 Gtk::HBox transport_option_button_hbox;
345 Gtk::VBox transport_option_button_vbox;
346 Gtk::HBox transport_clock_hbox;
347 Gtk::VBox transport_clock_vbox;
348 Gtk::HBox primary_clock_hbox;
349 Gtk::HBox secondary_clock_hbox;
352 struct TransportControllable : public PBD::Controllable {
353 enum ToggleType {
354 Roll = 0,
355 Stop,
356 RecordEnable,
357 GotoStart,
358 GotoEnd,
359 AutoLoop,
360 PlaySelection,
361 ShuttleControl
365 TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
366 void set_value (float);
367 float get_value (void) const;
369 void set_id (const std::string&);
371 ARDOUR_UI& ui;
372 ToggleType type;
375 boost::shared_ptr<TransportControllable> roll_controllable;
376 boost::shared_ptr<TransportControllable> stop_controllable;
377 boost::shared_ptr<TransportControllable> goto_start_controllable;
378 boost::shared_ptr<TransportControllable> goto_end_controllable;
379 boost::shared_ptr<TransportControllable> auto_loop_controllable;
380 boost::shared_ptr<TransportControllable> play_selection_controllable;
381 boost::shared_ptr<TransportControllable> rec_controllable;
382 boost::shared_ptr<TransportControllable> shuttle_controllable;
383 BindingProxy shuttle_controller_binding_proxy;
385 void set_transport_controllable_state (const XMLNode&);
386 XMLNode& get_transport_controllable_state ();
388 BindableButton roll_button;
389 BindableButton stop_button;
390 BindableButton goto_start_button;
391 BindableButton goto_end_button;
392 BindableButton auto_loop_button;
393 BindableButton play_selection_button;
394 BindableButton rec_button;
395 Gtk::ToggleButton join_play_range_button;
397 void toggle_external_sync ();
398 void toggle_time_master ();
399 void toggle_video_sync ();
401 Gtk::DrawingArea shuttle_box;
402 Gtk::EventBox speed_display_box;
403 Gtk::Label speed_display_label;
404 Gtk::Button shuttle_units_button;
405 Gtk::ComboBoxText shuttle_style_button;
406 Gtk::Menu* shuttle_unit_menu;
407 Gtk::Menu* shuttle_style_menu;
408 float shuttle_max_speed;
409 Gtk::Menu* shuttle_context_menu;
411 void build_shuttle_context_menu ();
412 void show_shuttle_context_menu ();
413 void shuttle_style_changed();
414 void shuttle_unit_clicked ();
415 void set_shuttle_max_speed (float);
416 void update_speed_display ();
417 float last_speed_displayed;
419 gint shuttle_box_button_press (GdkEventButton*);
420 gint shuttle_box_button_release (GdkEventButton*);
421 gint shuttle_box_scroll (GdkEventScroll*);
422 gint shuttle_box_motion (GdkEventMotion*);
423 gint shuttle_box_expose (GdkEventExpose*);
424 gint mouse_shuttle (double x, bool force);
425 void use_shuttle_fract (bool force);
427 bool shuttle_grabbed;
428 double shuttle_fract;
430 Gtkmm2ext::StatefulToggleButton punch_in_button;
431 Gtkmm2ext::StatefulToggleButton punch_out_button;
432 Gtkmm2ext::StatefulToggleButton auto_return_button;
433 Gtkmm2ext::StatefulToggleButton auto_play_button;
434 Gtkmm2ext::StatefulToggleButton auto_input_button;
435 Gtkmm2ext::StatefulToggleButton click_button;
436 Gtkmm2ext::StatefulToggleButton time_master_button;
437 Gtkmm2ext::StatefulToggleButton sync_button;
439 Gtk::ToggleButton auditioning_alert_button;
440 Gtk::ToggleButton solo_alert_button;
442 Gtk::VBox alert_box;
444 void solo_blink (bool);
445 void sync_blink (bool);
446 void audition_blink (bool);
448 void soloing_changed (bool);
449 void auditioning_changed (bool);
450 void _auditioning_changed (bool);
452 bool solo_alert_press (GdkEventButton* ev);
453 bool audition_alert_press (GdkEventButton* ev);
455 void big_clock_value_changed ();
456 void primary_clock_value_changed ();
457 void secondary_clock_value_changed ();
459 /* called by Blink signal */
461 void transport_rec_enable_blink (bool onoff);
463 Gtk::Menu* session_popup_menu;
465 struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
466 RecentSessionModelColumns() {
467 add (visible_name);
468 add (fullpath);
470 Gtk::TreeModelColumn<Glib::ustring> visible_name;
471 Gtk::TreeModelColumn<Glib::ustring> fullpath;
474 RecentSessionModelColumns recent_session_columns;
475 Gtk::TreeView recent_session_display;
476 Glib::RefPtr<Gtk::TreeStore> recent_session_model;
478 ArdourDialog* session_selector_window;
479 Gtk::FileChooserDialog* open_session_selector;
481 void build_session_selector();
482 void redisplay_recent_sessions();
483 void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
485 struct RecentSessionsSorter {
486 bool operator() (std::pair<std::string,std::string> a, std::pair<std::string,std::string> b) const {
487 return cmp_nocase(a.first, b.first) == -1;
491 /* menu bar and associated stuff */
493 Gtk::MenuBar* menu_bar;
494 Gtk::EventBox menu_bar_base;
495 Gtk::HBox menu_hbox;
497 void use_menubar_as_top_menubar ();
498 void build_menu_bar ();
500 Gtk::Label wall_clock_label;
501 Gtk::EventBox wall_clock_box;
502 gint update_wall_clock ();
504 Gtk::Label disk_space_label;
505 Gtk::EventBox disk_space_box;
506 void update_disk_space ();
508 Gtk::Label cpu_load_label;
509 Gtk::EventBox cpu_load_box;
510 void update_cpu_load ();
512 Gtk::Label buffer_load_label;
513 Gtk::EventBox buffer_load_box;
514 void update_buffer_load ();
516 Gtk::Label sample_rate_label;
517 Gtk::EventBox sample_rate_box;
518 void update_sample_rate (nframes_t);
520 gint every_second ();
521 gint every_point_one_seconds ();
522 gint every_point_zero_one_seconds ();
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;
529 gint session_menu (GdkEventButton *);
531 bool _will_create_new_session_automatically;
533 void open_session ();
534 void open_recent_session ();
535 void save_template ();
537 void edit_metadata ();
538 void import_metadata ();
540 void session_add_audio_route (bool disk, bool aux, int32_t input_channels, int32_t output_channels, ARDOUR::TrackMode mode, ARDOUR::RouteGroup *, uint32_t how_many);
541 void session_add_midi_route (bool disk, ARDOUR::RouteGroup *, uint32_t how_many);
543 void set_transport_sensitivity (bool);
545 void remove_last_capture ();
547 void transport_goto_zero ();
548 void transport_goto_start ();
549 void transport_goto_end ();
550 void transport_goto_wallclock ();
551 void transport_stop ();
552 void transport_stop_and_forget_capture ();
553 void transport_record (bool roll);
554 void transport_roll ();
555 void transport_play_selection();
556 void transport_forward (int option);
557 void transport_rewind (int option);
558 void transport_loop ();
559 void toggle_roll (bool with_abort, bool roll_out_of_bounded_mode);
561 bool _session_is_new;
562 void set_session (ARDOUR::Session *);
563 void connect_dependents_to_session (ARDOUR::Session *);
564 void we_have_dependents ();
566 void setup_session_options ();
568 guint32 last_key_press_time;
570 void snapshot_session (bool switch_to_it);
572 Mixer_UI *mixer;
573 int create_mixer ();
575 PublicEditor *editor;
576 int create_editor ();
578 RouteParams_UI *route_params;
579 int create_route_params ();
581 BundleManager *bundle_manager;
582 void create_bundle_manager ();
584 LocationUIWindow *location_ui;
585 int create_location_ui ();
586 void handle_locations_change (ARDOUR::Location*);
588 static UIConfiguration *ui_config;
589 ThemeManager *theme_manager;
591 /* Key bindings editor */
593 KeyEditor *key_editor;
595 /* RC Options window */
597 RCOptionEditor *rc_option_editor;
599 SessionOptionEditor *session_option_editor;
601 /* route dialog */
603 AddRouteDialog *add_route_dialog;
605 /* Keyboard Handling */
607 ArdourKeyboard* keyboard;
609 /* Keymap handling */
611 void install_actions ();
613 void toggle_record_enable (uint32_t);
615 uint32_t rec_enabled_streams;
616 void count_recenabled_streams (ARDOUR::Route&);
618 About* about;
619 Splash* splash;
620 void pop_back_splash ();
621 bool shown_flag;
623 /* cleanup */
625 Gtk::MenuItem *cleanup_item;
627 void display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title,
628 const std::string& plural_msg, const std::string& singular_msg);
629 void cleanup ();
630 void flush_trash ();
632 bool have_configure_timeout;
633 ARDOUR::microseconds_t last_configure_time;
634 gint configure_timeout ();
636 ARDOUR::microseconds_t last_peak_grab;
637 ARDOUR::microseconds_t last_shuttle_request;
639 bool have_disk_speed_dialog_displayed;
640 void disk_speed_dialog_gone (int ignored_response, Gtk::MessageDialog*);
641 void disk_overrun_handler ();
642 void disk_underrun_handler ();
644 void session_dialog (std::string);
645 int pending_state_dialog ();
646 int sr_mismatch_dialog (nframes_t, nframes_t);
648 void disconnect_from_jack ();
649 void reconnect_to_jack ();
650 void set_jack_buffer_size (nframes_t);
652 Gtk::MenuItem* jack_disconnect_item;
653 Gtk::MenuItem* jack_reconnect_item;
654 Gtk::Menu* jack_bufsize_menu;
656 Glib::RefPtr<Gtk::ActionGroup> common_actions;
658 void editor_realized ();
660 std::vector<std::string> positional_sync_strings;
662 void toggle_send_midi_feedback ();
663 void toggle_use_mmc ();
664 void toggle_send_mmc ();
665 void toggle_send_mtc ();
666 void toggle_send_midi_clock ();
668 void toggle_use_osc ();
670 void parameter_changed (std::string);
672 bool first_idle ();
674 void no_memory_warning ();
675 void check_memory_locking ();
677 bool check_audioengine();
678 void audioengine_setup ();
680 void display_message (const char *prefix, gint prefix_len,
681 Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
682 const char *msg);
683 Gtk::Label status_bar_label;
684 bool status_bar_button_press (GdkEventButton*);
685 Gtk::ToggleButton error_log_button;
687 void loading_message (const std::string& msg);
688 void end_loading_messages ();
690 void platform_specific ();
691 void platform_setup ();
692 void fontconfig_dialog ();
694 PBD::ScopedConnectionList forever_connections;
697 #endif /* __ardour_gui_h__ */