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