Remove unused method.
[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/session.h"
63 #include "ardour/types.h"
64
65 #include "audio_clock.h"
66 #include "ardour_dialog.h"
67 #include "editing.h"
68 #include "ui_config.h"
69
70 class AudioClock;
71 class PublicEditor;
72 class Keyboard;
73 class RCOptionEditor;
74 class SessionOptionEditor;
75 class KeyEditor;
76 class Mixer_UI;
77 class ConnectionEditor;
78 class RouteParams_UI;
79 class About;
80 class Splash;
81 class AddRouteDialog;
82 class LocationUI;
83 class ThemeManager;
84 class BundleManager;
85 class ArdourStartup;
86
87 namespace Gtkmm2ext {
88         class TearOff;
89 }
90
91 namespace ARDOUR {
92         class Route;
93         class Port;
94         class IO;
95         class ControlProtocolInfo;
96 }
97
98 namespace ALSA {
99         class MultiChannelDevice;
100 }
101
102 #define FRAME_NAME "BaseFrame"
103
104 extern sigc::signal<void>  ColorsChanged;
105 extern sigc::signal<void>  DPIReset;
106
107 class ARDOUR_UI : public Gtkmm2ext::UI
108 {
109   public:
110         ARDOUR_UI (int *argcp, char **argvp[]);
111         ~ARDOUR_UI();
112
113         void run_startup (bool should_be_new);
114
115         void show ();
116         bool shown() { return shown_flag; }
117
118         void show_splash ();
119         void hide_splash ();
120
121         void show_about ();
122         void hide_about ();
123
124         void finish();
125
126         int load_session (const Glib::ustring& path, const Glib::ustring& snapshot, Glib::ustring mix_template = Glib::ustring());
127         bool session_loaded;
128         int build_session (const Glib::ustring& path, const Glib::ustring& snapshot,
129                            uint32_t ctl_chns,
130                            uint32_t master_chns,
131                            ARDOUR::AutoConnectOption input_connect,
132                            ARDOUR::AutoConnectOption output_connect,
133                            uint32_t nphysin,
134                            uint32_t nphysout,
135                            nframes_t initial_length);
136         bool session_is_new() const { return _session_is_new; }
137
138         ARDOUR::Session* the_session() { return session; }
139
140         bool will_create_new_session_automatically() const {
141                 return _will_create_new_session_automatically;
142         }
143
144         void set_will_create_new_session_automatically (bool yn) {
145                 _will_create_new_session_automatically = yn;
146         }
147         
148         int get_session_parameters (bool should_be_new = false);
149         void parse_cmdline_path (const Glib::ustring& cmdline_path, Glib::ustring& session_name, Glib::ustring& session_path, bool& existing_session);
150         int  load_cmdline_session (const Glib::ustring& session_name, const Glib::ustring& session_path, bool& existing_session);
151         int  build_session_from_nsd (const Glib::ustring& session_name, const Glib::ustring& session_path);
152         bool ask_about_loading_existing_session (const Glib::ustring& session_path);
153
154         /// @return true if session was successfully unloaded.
155         int unload_session (bool hide_stuff = false);
156         void close_session();
157
158         int  save_state_canfail (std::string state_name = "");
159         void save_state (const std::string & state_name = "");
160
161         static double gain_to_slider_position (ARDOUR::gain_t g);
162         static ARDOUR::gain_t slider_position_to_gain (double pos);
163
164         static ARDOUR_UI *instance () { return theArdourUI; }
165         static UIConfiguration *config () { return ui_config; }
166
167         PublicEditor&     the_editor(){return *editor;}
168         Mixer_UI* the_mixer() { return mixer; }
169
170         void toggle_key_editor ();
171         void toggle_location_window ();
172         void toggle_theme_manager ();
173         void toggle_bundle_manager ();
174         void toggle_big_clock_window ();
175         void toggle_route_params_window ();
176         void toggle_editing_space();
177
178         Gtk::Tooltips& tooltips() { return _tooltips; }
179
180         static sigc::signal<void,bool> Blink;
181         static sigc::signal<void>      RapidScreenUpdate;
182         static sigc::signal<void>      SuperRapidScreenUpdate;
183         static sigc::signal<void,nframes_t, bool, nframes_t> Clock;
184
185         void name_io_setup (ARDOUR::AudioEngine&, std::string&, ARDOUR::IO& io, bool in);
186
187         XMLNode* editor_settings() const;
188         XMLNode* mixer_settings () const;
189         XMLNode* keyboard_settings () const;
190
191         void save_ardour_state ();
192         gboolean configure_handler (GdkEventConfigure* conf);
193
194         void do_transport_locate (nframes_t position);
195         void halt_on_xrun_message ();
196         void xrun_handler (nframes_t);
197         void create_xrun_marker (nframes_t);
198
199         AudioClock primary_clock;
200         AudioClock secondary_clock;
201         AudioClock preroll_clock;
202         AudioClock postroll_clock;
203
204         void store_clock_modes ();
205         void restore_clock_modes ();
206
207         void add_route (Gtk::Window* float_window);
208
209         void session_add_audio_track (int input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many) {
210                 session_add_audio_route (true, input_channels, output_channels, mode, how_many);
211         }
212
213         void session_add_audio_bus (int input_channels, int32_t output_channels, uint32_t how_many) {
214                 session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, how_many);
215         }
216
217         void session_add_midi_track (uint32_t how_many) {
218                 session_add_midi_route (true, how_many);
219         }
220
221         /*void session_add_midi_bus () {
222                 session_add_midi_route (false);
223         }*/
224
225         int  create_engine ();
226         void post_engine ();
227
228         gint exit_on_main_window_close (GdkEventAny *);
229
230         void maximise_editing_space ();
231         void restore_editing_space ();
232
233         void setup_profile ();
234         void setup_theme ();
235
236         void set_shuttle_fract (double);
237
238   protected:
239         friend class PublicEditor;
240
241         void toggle_clocking ();
242         void toggle_auto_play ();
243         void toggle_auto_input ();
244         void toggle_punch ();
245         void unset_dual_punch ();
246         bool ignore_dual_punch;
247         void toggle_punch_in ();
248         void toggle_punch_out ();
249         void toggle_auto_return ();
250         void toggle_click ();
251
252         void toggle_session_auto_loop ();
253
254         void toggle_rc_options_window ();
255         void toggle_session_options_window ();
256
257   private:
258         ArdourStartup*      _startup;
259         ARDOUR::AudioEngine *engine;
260         ARDOUR::Session      *session;
261         Gtk::Tooltips        _tooltips;
262
263         void                goto_editor_window ();
264         void                goto_mixer_window ();
265         void                toggle_editor_mixer_on_top ();
266         bool                _mixer_on_top;
267
268         Gtk::ToggleButton   preroll_button;
269         Gtk::ToggleButton   postroll_button;
270
271         int  setup_windows ();
272         void setup_transport ();
273         void setup_clock ();
274
275         static ARDOUR_UI *theArdourUI;
276
277         void backend_audio_error (bool we_set_params, Gtk::Window* toplevel = 0);
278         void startup ();
279         void shutdown ();
280
281         int  ask_about_saving_session (const std::string & why);
282
283         /* periodic safety backup, to be precise */
284         gint autosave_session();
285         void update_autosave();
286         sigc::connection _autosave_connection;
287
288         void queue_transport_change ();
289         void map_transport_state ();
290         int32_t do_engine_start ();
291
292         void engine_halted ();
293         void engine_stopped ();
294         void engine_running ();
295
296         void use_config ();
297
298         static gint _blink  (void *);
299         void blink ();
300         gint blink_timeout_tag;
301         bool blink_on;
302         void start_blinking ();
303         void stop_blinking ();
304
305         void about_signal_response(int response);
306
307   private:
308         Gtk::VBox     top_packer;
309
310         sigc::connection clock_signal_connection;
311         void         update_clocks ();
312         void         start_clocking ();
313         void         stop_clocking ();
314
315         void manage_window (Gtk::Window&);
316
317         AudioClock   big_clock;
318         Gtk::Window* big_clock_window;
319
320         void float_big_clock (Gtk::Window* parent);
321         bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
322
323         void update_transport_clocks (nframes_t pos);
324         void record_state_changed ();
325
326         /* Transport Control */
327
328         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
329         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
330
331         Gtkmm2ext::TearOff*      transport_tearoff;
332         Gtk::Frame               transport_frame;
333         Gtk::HBox                transport_tearoff_hbox;
334         Gtk::HBox                transport_hbox;
335         Gtk::Fixed               transport_base;
336         Gtk::Fixed               transport_button_base;
337         Gtk::Frame               transport_button_frame;
338         Gtk::HBox                transport_button_hbox;
339         Gtk::VBox                transport_button_vbox;
340         Gtk::HBox                transport_option_button_hbox;
341         Gtk::VBox                transport_option_button_vbox;
342         Gtk::HBox                transport_clock_hbox;
343         Gtk::VBox                transport_clock_vbox;
344         Gtk::HBox                primary_clock_hbox;
345         Gtk::HBox                secondary_clock_hbox;
346
347
348         struct TransportControllable : public PBD::Controllable {
349             enum ToggleType {
350                     Roll = 0,
351                     Stop,
352                     RecordEnable,
353                     GotoStart,
354                     GotoEnd,
355                     AutoLoop,
356                     PlaySelection,
357                     ShuttleControl
358
359             };
360
361             TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
362             void set_value (float);
363             float get_value (void) const;
364
365             void set_id (const std::string&);
366
367             ARDOUR_UI& ui;
368             ToggleType type;
369         };
370
371         boost::shared_ptr<TransportControllable> roll_controllable;
372         boost::shared_ptr<TransportControllable> stop_controllable;
373         boost::shared_ptr<TransportControllable> goto_start_controllable;
374         boost::shared_ptr<TransportControllable> goto_end_controllable;
375         boost::shared_ptr<TransportControllable> auto_loop_controllable;
376         boost::shared_ptr<TransportControllable> play_selection_controllable;
377         boost::shared_ptr<TransportControllable> rec_controllable;
378         boost::shared_ptr<TransportControllable> shuttle_controllable;
379         BindingProxy shuttle_controller_binding_proxy;
380
381         void set_transport_controllable_state (const XMLNode&);
382         XMLNode& get_transport_controllable_state ();
383
384         BindableButton roll_button;
385         BindableButton stop_button;
386         BindableButton goto_start_button;
387         BindableButton goto_end_button;
388         BindableButton auto_loop_button;
389         BindableButton play_selection_button;
390         BindableButton rec_button;
391
392         Gtk::ComboBoxText sync_option_combo;
393
394         void sync_option_changed ();
395         void toggle_time_master ();
396         void toggle_video_sync ();
397
398         Gtk::DrawingArea  shuttle_box;
399         Gtk::EventBox     speed_display_box;
400         Gtk::Label        speed_display_label;
401         Gtk::Button       shuttle_units_button;
402         Gtk::ComboBoxText shuttle_style_button;
403         Gtk::Menu*        shuttle_unit_menu;
404         Gtk::Menu*        shuttle_style_menu;
405         float             shuttle_max_speed;
406         Gtk::Menu*        shuttle_context_menu;
407
408         void build_shuttle_context_menu ();
409         void show_shuttle_context_menu ();
410         void shuttle_style_changed();
411         void shuttle_unit_clicked ();
412         void set_shuttle_max_speed (float);
413         void update_speed_display ();
414         float last_speed_displayed;
415
416         gint shuttle_box_button_press (GdkEventButton*);
417         gint shuttle_box_button_release (GdkEventButton*);
418         gint shuttle_box_scroll (GdkEventScroll*);
419         gint shuttle_box_motion (GdkEventMotion*);
420         gint shuttle_box_expose (GdkEventExpose*);
421         gint mouse_shuttle (double x, bool force);
422         void use_shuttle_fract (bool force);
423
424         bool   shuttle_grabbed;
425         double shuttle_fract;
426
427         Gtkmm2ext::StatefulToggleButton punch_in_button;
428         Gtkmm2ext::StatefulToggleButton punch_out_button;
429         Gtkmm2ext::StatefulToggleButton auto_return_button;
430         Gtkmm2ext::StatefulToggleButton auto_play_button;
431         Gtkmm2ext::StatefulToggleButton auto_input_button;
432         Gtkmm2ext::StatefulToggleButton click_button;
433         Gtkmm2ext::StatefulToggleButton time_master_button;
434
435         Gtk::ToggleButton auditioning_alert_button;
436         Gtk::ToggleButton solo_alert_button;
437
438         Gtk::VBox alert_box;
439
440         void solo_blink (bool);
441         void audition_blink (bool);
442
443         void soloing_changed (bool);
444         void auditioning_changed (bool);
445         void _auditioning_changed (bool);
446
447         void solo_alert_toggle ();
448         void audition_alert_toggle ();
449
450         void big_clock_value_changed ();
451         void primary_clock_value_changed ();
452         void secondary_clock_value_changed ();
453
454         /* called by Blink signal */
455
456         void transport_rec_enable_blink (bool onoff);
457
458         Gtk::Menu*        session_popup_menu;
459
460         struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
461             RecentSessionModelColumns() {
462                     add (visible_name);
463                     add (fullpath);
464             }
465             Gtk::TreeModelColumn<Glib::ustring> visible_name;
466             Gtk::TreeModelColumn<Glib::ustring> fullpath;
467         };
468
469         RecentSessionModelColumns    recent_session_columns;
470         Gtk::TreeView                recent_session_display;
471         Glib::RefPtr<Gtk::TreeStore> recent_session_model;
472
473         ArdourDialog*     session_selector_window;
474         Gtk::FileChooserDialog* open_session_selector;
475
476         void build_session_selector();
477         void redisplay_recent_sessions();
478         void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
479
480         struct RecentSessionsSorter {
481                 bool operator() (std::pair<std::string,std::string> a, std::pair<std::string,std::string> b) const {
482                     return cmp_nocase(a.first, b.first) == -1;
483             }
484         };
485
486         /* menu bar and associated stuff */
487
488         Gtk::MenuBar* menu_bar;
489         Gtk::EventBox menu_bar_base;
490         Gtk::HBox     menu_hbox;
491
492         void use_menubar_as_top_menubar ();
493         void build_menu_bar ();
494
495         Gtk::Label   wall_clock_label;
496         Gtk::EventBox wall_clock_box;
497         gint update_wall_clock ();
498
499         Gtk::Label   disk_space_label;
500         Gtk::EventBox disk_space_box;
501         void update_disk_space ();
502
503         Gtk::Label   cpu_load_label;
504         Gtk::EventBox cpu_load_box;
505         void update_cpu_load ();
506
507         Gtk::Label   buffer_load_label;
508         Gtk::EventBox buffer_load_box;
509         void update_buffer_load ();
510
511         Gtk::Label   sample_rate_label;
512         Gtk::EventBox sample_rate_box;
513         void update_sample_rate (nframes_t);
514
515         gint every_second ();
516         gint every_point_one_seconds ();
517         gint every_point_zero_one_seconds ();
518
519         sigc::connection second_connection;
520         sigc::connection point_one_second_connection;
521         sigc::connection point_oh_five_second_connection;
522         sigc::connection point_zero_one_second_connection;
523
524         gint session_menu (GdkEventButton *);
525
526         bool _will_create_new_session_automatically;
527
528         void open_session ();
529         void open_recent_session ();
530         void save_template ();
531         
532         void edit_metadata ();
533         void import_metadata ();
534
535         void session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many);
536         void session_add_midi_route (bool disk, uint32_t how_many);
537
538         void set_transport_sensitivity (bool);
539
540         void remove_last_capture ();
541
542         void transport_goto_zero ();
543         void transport_goto_start ();
544         void transport_goto_end ();
545         void transport_goto_wallclock ();
546         void transport_stop ();
547         void transport_stop_and_forget_capture ();
548         void transport_record (bool roll);
549         void transport_roll ();
550         void transport_play_selection();
551         void transport_forward (int option);
552         void transport_rewind (int option);
553         void transport_loop ();
554
555         void transport_rolling ();
556         void transport_rewinding ();
557         void transport_forwarding ();
558         void transport_stopped ();
559
560         bool _session_is_new;
561         void connect_to_session (ARDOUR::Session *);
562         void connect_dependents_to_session (ARDOUR::Session *);
563         void we_have_dependents ();
564
565         void setup_session_options ();
566
567         guint32  last_key_press_time;
568
569         void snapshot_session ();
570
571         Mixer_UI   *mixer;
572         int         create_mixer ();
573
574         PublicEditor     *editor;
575         int         create_editor ();
576
577         RouteParams_UI *route_params;
578         int             create_route_params ();
579
580         BundleManager *bundle_manager;
581         void create_bundle_manager ();
582
583         LocationUI *location_ui;
584         int         create_location_ui ();
585         void        handle_locations_change (ARDOUR::Location*);
586
587         static UIConfiguration *ui_config;
588         ThemeManager *theme_manager;
589
590         /* Key bindings editor */
591
592         KeyEditor *key_editor;
593
594         /* RC Options window */
595
596         RCOptionEditor *rc_option_editor;
597
598         SessionOptionEditor *session_option_editor;
599
600         /* route dialog */
601
602         AddRouteDialog *add_route_dialog;
603
604         /* Keyboard Handling */
605
606         Keyboard* keyboard;
607
608         /* Keymap handling */
609
610         void install_actions ();
611
612         void toggle_record_enable (uint32_t);
613
614         uint32_t rec_enabled_streams;
615         void count_recenabled_streams (ARDOUR::Route&);
616
617         About* about;
618         Splash* splash;
619         void pop_back_splash ();
620         bool shown_flag;
621
622         /* cleanup */
623
624         Gtk::MenuItem *cleanup_item;
625
626         void display_cleanup_results (ARDOUR::Session::cleanup_report& rep, const gchar* list_title, const std::string & msg);
627         void cleanup ();
628         void flush_trash ();
629
630         bool have_configure_timeout;
631         ARDOUR::microseconds_t last_configure_time;
632         gint configure_timeout ();
633
634         ARDOUR::microseconds_t last_peak_grab;
635         ARDOUR::microseconds_t last_shuttle_request;
636
637         struct DiskBufferStat {
638             time_t when;
639             uint32_t capture;
640             uint32_t playback;
641
642             DiskBufferStat (time_t w, uint32_t c, uint32_t p) 
643             : when (w), capture (c), playback (p) {}
644         };
645         
646         std::list<DiskBufferStat> disk_buffer_stats;
647         void push_buffer_stats (uint32_t, uint32_t);
648         void write_buffer_stats ();
649
650         bool have_disk_speed_dialog_displayed;
651         void disk_speed_dialog_gone (int ignored_response, Gtk::MessageDialog*);
652         void disk_overrun_handler ();
653         void disk_underrun_handler ();
654
655         void session_dialog (std::string);
656         int pending_state_dialog ();
657         int sr_mismatch_dialog (nframes_t, nframes_t);
658
659         void disconnect_from_jack ();
660         void reconnect_to_jack ();
661         void set_jack_buffer_size (nframes_t);
662
663         Gtk::MenuItem* jack_disconnect_item;
664         Gtk::MenuItem* jack_reconnect_item;
665         Gtk::Menu*     jack_bufsize_menu;
666
667         Glib::RefPtr<Gtk::ActionGroup> common_actions;
668
669         void editor_realized ();
670
671         std::vector<std::string> positional_sync_strings;
672
673         void toggle_send_midi_feedback ();
674         void toggle_use_mmc ();
675         void toggle_send_mmc ();
676         void toggle_send_mtc ();
677         void toggle_send_midi_clock ();
678
679         void toggle_use_osc ();
680
681         void mtc_port_changed ();
682         void parameter_changed (std::string);
683
684         bool first_idle ();
685
686         void no_memory_warning ();
687         void check_memory_locking ();
688
689         bool check_audioengine();
690         void audioengine_setup ();
691
692         void display_message (const char *prefix, gint prefix_len,
693                               Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag, const char *msg);
694         Gtk::Label status_bar_label;
695         Gtk::ToggleButton error_log_button;
696
697         void loading_message (const std::string& msg);
698         void end_loading_messages ();
699
700         void platform_specific ();
701         void platform_setup ();
702         void fontconfig_dialog ();
703 };
704
705 #endif /* __ardour_gui_h__ */
706