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