the usual blob of fixes. note the requirement for ComboBoxText::set_active_text()
[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     $Id$
19 */
20
21 #ifndef __ardour_gui_h__
22 #define __ardour_gui_h__
23
24 /* need _BSD_SOURCE to get timersub macros */
25
26 #ifdef _BSD_SOURCE
27 #include <sys/time.h>
28 #else
29 #define _BSD_SOURCE
30 #include <sys/time.h>
31 #undef _BSD_SOURCE
32 #endif
33
34 #include <list>
35
36 #include <cmath>
37
38 #include <libgnomecanvasmm/canvas.h>
39
40 #include <pbd/xml++.h>
41 #include <gtkmm/box.h>
42 #include <gtkmm/frame.h>
43 #include <gtkmm/label.h>
44 #include <gtkmm/table.h>
45 #include <gtkmm/fixed.h>
46 #include <gtkmm/drawingarea.h>
47 #include <gtkmm/eventbox.h>
48 #include <gtkmm/menu.h>
49 #include <gtkmm/menuitem.h>
50 #include <gtkmm/button.h>
51 #include <gtkmm/togglebutton.h>
52 #include <gtkmm/treeview.h>
53 #include <gtkmm/menubar.h>
54 #include <gtkmm/adjustment.h>
55 #include <gtkmm2ext/gtk_ui.h>
56 #include <gtkmm2ext/pix.h>
57 #include <gtkmm2ext/click_box.h>
58 #include <ardour/ardour.h>
59 #include <ardour/session.h>
60
61 #include "audio_clock.h"
62 #include "ardour_dialog.h"
63 #include "editing.h"
64 #include "glade_factory.h"
65
66 class AudioClock;
67 class PublicEditor;
68 class Keyboard;
69 class MeterBridge;
70 class OptionEditor;
71 class Mixer_UI;
72 class ConnectionEditor;
73 class RouteParams_UI;
74 class SoundFileChooser;
75 class About;
76 class AddRouteDialog;
77 class NewSessionDialog;
78 class LocationUI;
79
80 namespace Gtkmm2ext {
81         class TearOff;
82 };
83
84 namespace ARDOUR {
85         class AudioEngine;
86         class Route;
87         class Port;
88         class IO;
89 };
90
91 namespace ALSA {
92         class MultiChannelDevice;
93 };
94
95 #define FRAME_NAME "BaseFrame"
96
97 class ARDOUR_UI : public Gtkmm2ext::UI
98 {
99   public:
100         ARDOUR_UI (int *argcp, char **argvp[], string rcfile);
101         ~ARDOUR_UI();
102
103         void show ();
104         bool shown() { return shown_flag; }
105         
106         void show_splash ();
107         void hide_splash ();
108         
109         int load_session (string path, string snapshot, string* mix_template = 0);
110         bool session_loaded;
111         int build_session (string path, string snapshot, 
112                            uint32_t ctl_chns, 
113                            uint32_t master_chns,
114                            ARDOUR::Session::AutoConnectOption input_connect,
115                            ARDOUR::Session::AutoConnectOption output_connect,
116                            uint32_t nphysin,
117                            uint32_t nphysout,
118                            jack_nframes_t initial_length);
119         bool session_is_new() const { return _session_is_new; }
120
121         ARDOUR::Session* the_session() { return session; }
122
123         bool will_create_new_session_automatically() const {
124                 return _will_create_new_session_automatically;
125         }
126
127         void set_will_create_new_session_automatically (bool yn) {
128                 _will_create_new_session_automatically = yn;
129         }
130
131         void new_session(bool startup = false, std::string path = string());
132         gint cmdline_new_session (std::string path);
133         int  unload_session ();
134         void close_session() { unload_session(); }
135
136         int  save_state_canfail (string state_name = "");
137         void save_state (string state_name = "");
138         void restore_state (string state_name = "");
139
140         static double gain_to_slider_position (ARDOUR::gain_t g);
141         static ARDOUR::gain_t slider_position_to_gain (double pos);
142
143         static ARDOUR_UI *instance () { return theArdourUI; }
144
145         PublicEditor&     the_editor(){return *editor;}
146         Mixer_UI* the_mixer() { return mixer; }
147         
148         void toggle_location_window ();
149         void toggle_big_clock_window ();
150         void toggle_connection_editor ();
151         void toggle_route_params_window ();
152         void toggle_tempo_window ();
153
154         gint32 select_diskstream (GdkEventButton *ev);
155
156         Gtk::Tooltips& tooltips() { return _tooltips; }
157
158         static sigc::signal<void,bool> Blink;
159         static sigc::signal<void>      RapidScreenUpdate;
160         static sigc::signal<void>      SuperRapidScreenUpdate;
161         static sigc::signal<void,jack_nframes_t> Clock;
162
163         /* this is a helper function to centralize the (complex) logic for
164            blinking rec-enable buttons.
165         */
166
167         void rec_enable_button_blink (bool onoff, ARDOUR::DiskStream *, Gtk::Widget *w);
168
169         void name_io_setup (ARDOUR::AudioEngine&, string&, ARDOUR::IO& io, bool in);
170         void choose_io (ARDOUR::IO&, bool input);
171
172         static gint hide_and_quit (GdkEventAny *ev, ArdourDialog *);
173
174         XMLNode* editor_settings() const;
175         XMLNode* mixer_settings () const;
176         XMLNode* keyboard_settings () const;
177
178         void save_ardour_state ();
179         gboolean configure_handler (GdkEventConfigure* conf);
180
181         void do_transport_locate (jack_nframes_t position);
182         void halt_on_xrun_message ();
183
184         AudioClock primary_clock;
185         AudioClock secondary_clock;
186         AudioClock preroll_clock;
187         AudioClock postroll_clock;
188
189         void add_route ();
190         
191         void session_add_audio_track (int input_channels, int32_t output_channels) {
192                 session_add_audio_route (true, input_channels, output_channels);
193         }
194
195         void session_add_audio_bus (int input_channels, int32_t output_channels) {
196                 session_add_audio_route (false, input_channels, output_channels);
197         }
198
199         void session_add_midi_track ();
200
201         void set_engine (ARDOUR::AudioEngine&);
202
203         gint exit_on_main_window_close (GdkEventAny *);
204
205   protected:
206         friend class PublicEditor;
207
208         void toggle_clocking ();
209         void toggle_auto_play ();
210         void toggle_auto_input ();
211         void toggle_punch_in ();
212         void toggle_punch_out ();
213         void toggle_auto_return ();
214         void toggle_click ();
215         void toggle_follow ();
216
217         void toggle_session_auto_loop ();
218         void toggle_session_punch_in ();
219         
220         void toggle_options_window ();
221
222   private:
223         struct GlobalClickBox : public Gtk::VBox {
224             Gtkmm2ext::ClickBox  *box;
225             Gtk::Frame      frame;
226             Gtk::Label      label;
227             vector<string> &strings;
228             Gtk::Adjustment adjustment;
229
230             static void printer (char buf[32], Gtk::Adjustment &adj, void *arg);
231
232             GlobalClickBox (const string &str, vector<string> &vs)
233                     : strings (vs),
234                       adjustment (0, 0, vs.size() - 1, 1, 1, 0) {
235                     box = new Gtkmm2ext::ClickBox (&adjustment, "ClickButton");
236                     label.set_text (str);
237                     label.set_name ("GlobalButtonLabel");
238                     frame.add (*box);
239                     frame.set_shadow_type (Gtk::SHADOW_IN);
240                     pack_start (label);
241                     pack_start (frame);
242                     box->set_print_func (printer, this);
243                     box->set_wrap (true);
244             };
245         };
246
247         ARDOUR::AudioEngine                 *engine;
248         ARDOUR::Session                     *session;
249
250         Gtk::Tooltips          _tooltips;
251
252         void                     goto_editor_window ();
253         void                     goto_mixer_window ();
254         
255         Gtk::Table               adjuster_table;
256         Gtk::Frame               adjuster_frame;
257         Gtk::Fixed               adjuster_base;
258
259         GlobalClickBox     *online_control_button;
260         vector<string>      online_control_strings;
261
262         GlobalClickBox    *crossfade_time_button;
263         vector<string>     crossfade_time_strings;
264
265         GlobalClickBox    *mmc_id_button;
266         vector<string>     mmc_id_strings;
267
268         Gtk::ToggleButton   preroll_button;
269         Gtk::ToggleButton   postroll_button;
270
271         Gtk::Table          transport_table;
272         Gtk::Table          option_table;
273
274         int  setup_windows ();
275         void setup_session_menu ();
276         void setup_transport ();
277         void setup_clock ();
278         void setup_session_info ();
279         void setup_adjustables ();
280
281         Gtk::MenuBar* make_menubar ();
282         
283         static ARDOUR_UI *theArdourUI;
284
285         void startup ();
286         void shutdown ();
287
288         void finish();
289         int  ask_about_saving_session (string why);
290         gint ask_about_save_deleted (GdkEventAny*);
291         void save_session_choice_made (int);
292         int  save_the_session;
293
294         void queue_transport_change ();
295         void map_transport_state ();
296         int32_t do_engine_start ();
297         gint start_engine ();
298         
299         void engine_halted ();
300         void engine_stopped ();
301         void engine_running ();
302
303         void map_some_session_state (Gtk::ToggleButton& button,
304                                      bool (ARDOUR::Session::*get)() const);
305
306         void toggle_some_session_state (Gtk::ToggleButton& button,
307                                      bool (ARDOUR::Session::*get)() const,
308                                      void (ARDOUR::Session::*set)(bool));
309         void map_button_state ();
310
311         void clear_meters ();
312
313         static gint _blink  (void *);
314         void blink ();
315         gint blink_timeout_tag;
316         bool blink_on;
317         void start_blinking ();
318         void stop_blinking ();
319
320         void control_methods_adjusted ();
321         void mmc_device_id_adjusted ();
322
323   private:
324         Gtk::VBox     top_packer;
325
326         sigc::connection clock_signal_connection;
327         void         update_clocks ();
328         void         start_clocking ();
329         void         stop_clocking ();
330
331         void manage_window (Gtk::Window&);
332         
333         AudioClock   big_clock;
334         Gtk::Frame   big_clock_frame;
335         Gtk::Window* big_clock_window;
336
337         /* Transport Control */
338
339         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
340         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
341
342         Gtkmm2ext::TearOff*       transport_tearoff;
343         Gtk::Frame               transport_frame;
344         Gtk::HBox                transport_tearoff_hbox;
345         Gtk::HBox                transport_hbox;
346         Gtk::Fixed               transport_base;
347         Gtk::Fixed               transport_button_base;
348         Gtk::Frame               transport_button_frame;
349         Gtk::HBox                transport_button_hbox;
350         Gtk::VBox                transport_button_vbox;
351         Gtk::HBox                transport_option_button_hbox;
352         Gtk::VBox                transport_option_button_vbox;
353         Gtk::HBox                transport_clock_hbox;
354         Gtk::VBox                transport_clock_vbox;
355         Gtk::HBox                primary_clock_hbox;
356         Gtk::HBox                secondary_clock_hbox;
357
358         Gtk::Button goto_start_button;
359         Gtk::Button goto_end_button;
360         Gtk::Button rewind_button;
361         Gtk::Button forward_button;
362         Gtk::Button stop_button;
363
364         enum ShuttleBehaviour {
365                 Sprung,
366                 Wheel
367         };
368
369         enum ShuttleUnits {
370                 Percentage,
371                 Semitones
372         };
373
374         Gtk::DrawingArea shuttle_box;
375         Gtk::EventBox    speed_display_box;
376         Gtk::Label       speed_display_label;
377         Gtk::Button      shuttle_units_button;
378         Gtk::Button      shuttle_style_button;
379         Gtk::Menu*       shuttle_unit_menu;
380         Gtk::Menu*       shuttle_style_menu;
381         ShuttleBehaviour shuttle_behaviour;
382         ShuttleUnits     shuttle_units;
383
384         void shuttle_style_clicked ();
385         void shuttle_unit_clicked ();
386         void set_shuttle_behaviour (ShuttleBehaviour);
387         void set_shuttle_units (ShuttleUnits);
388         void update_speed_display ();
389
390         gint shuttle_box_button_press (GdkEventButton*);
391         gint shuttle_box_button_release (GdkEventButton*);
392         gint shuttle_box_motion (GdkEventMotion*);
393         gint shuttle_box_expose (GdkEventExpose*);
394         gint mouse_shuttle (double x, bool force);
395         void use_shuttle_fract (bool force);
396
397         bool   shuttle_grabbed;
398         double shuttle_fract;
399
400         Gtk::ToggleButton auto_loop_button;
401         Gtk::ToggleButton play_selection_button;
402         Gtk::ToggleButton roll_button;
403
404         Gtk::ToggleButton rec_button;
405         Gtk::ToggleButton punch_in_button;
406         Gtk::ToggleButton punch_out_button;
407         Gtk::ToggleButton auto_return_button;
408         Gtk::ToggleButton auto_play_button;
409         Gtk::ToggleButton auto_input_button;
410         Gtk::ToggleButton click_button;
411         Gtk::ToggleButton follow_button;
412         Gtk::ToggleButton auditioning_alert_button;
413         Gtk::ToggleButton solo_alert_button;
414
415         Gtk::VBox alert_box;
416         
417         void follow_changed ();
418
419         void solo_blink (bool);
420         void audition_blink (bool);
421
422         void soloing_changed (bool);
423         void auditioning_changed (bool);
424         void _auditioning_changed (bool);
425
426         void solo_alert_toggle ();
427         void audition_alert_toggle ();
428
429         void primary_clock_value_changed ();
430         void secondary_clock_value_changed ();
431
432         /* called by Blink signal */
433
434         void transport_rec_enable_blink (bool onoff);
435
436         /* These change where we accept control from:
437            MMC, X (local) or both.
438         */
439
440         void allow_mmc_only ();
441         void allow_mmc_and_local ();
442         void allow_local_only ();
443
444         static void rate_printer (char buf[32], Gtk::Adjustment &, void *);
445
446         Gtk::Menu*        session_popup_menu;
447
448         struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
449             RecentSessionModelColumns() { 
450                     add (visible_name);
451                     add (fullpath);
452             }
453             Gtk::TreeModelColumn<Glib::ustring> visible_name;
454             Gtk::TreeModelColumn<Glib::ustring> fullpath;
455         };
456
457         RecentSessionModelColumns    recent_session_columns;
458         Gtk::TreeView                recent_session_display;
459         Glib::RefPtr<Gtk::TreeStore> recent_session_model;
460
461         ArdourDialog*     session_selector_window;
462         Gtk::FileChooserDialog* open_session_selector;
463         
464         void build_session_selector();
465         void recent_session_selection_changed ();
466         void redisplay_recent_sessions();
467
468         struct RecentSessionsSorter {
469             bool operator() (std::pair<string,string> a, std::pair<string,string> b) const {
470                     return cmp_nocase(a.first, b.first) == -1;
471             }
472         };
473
474         /* menu bar and associated stuff */
475
476         Gtk::MenuBar* menu_bar;
477         Gtk::Fixed    menu_bar_base;
478         Gtk::HBox     menu_hbox;
479
480         void build_menu_bar ();
481         void pack_toplevel_controls();
482
483         Gtk::Label   wall_clock_label;
484         Gtk::EventBox wall_clock_box;
485         gint update_wall_clock ();
486
487         Gtk::Label   disk_space_label;
488         Gtk::EventBox disk_space_box;
489         void update_disk_space ();
490
491         Gtk::Label   cpu_load_label;
492         Gtk::EventBox cpu_load_box;
493         void update_cpu_load ();
494
495         Gtk::Label   disk_rate_label;
496         Gtk::EventBox disk_rate_box;
497         void update_disk_rate();
498
499         Gtk::Label   buffer_load_label;
500         Gtk::EventBox buffer_load_box;
501         void update_buffer_load ();
502
503         Gtk::Label   sample_rate_label;
504         Gtk::EventBox sample_rate_box;
505         void update_sample_rate (jack_nframes_t);
506
507         gint every_second ();
508         gint every_point_one_seconds ();
509         gint every_point_zero_one_seconds ();
510
511         sigc::connection second_connection;
512         sigc::connection point_one_second_connection;
513         sigc::connection point_zero_one_second_connection;
514
515         void diskstream_added (ARDOUR::DiskStream*);
516
517         gint session_menu (GdkEventButton *);
518
519         bool _will_create_new_session_automatically;
520
521         GladeRef m_new_session_dialog_ref;
522         NewSessionDialog* m_new_session_dialog;
523         
524         void open_session ();
525         void open_recent_session ();
526         void open_ok_clicked ();
527
528         void save_template ();
529
530
531         void session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels);
532
533         void add_diskstream_to_menu (ARDOUR::DiskStream&);
534         void diskstream_selected (gint32);
535         Gtk::Menu *diskstream_menu;
536         gint32 selected_dstream;
537         
538         gint mouse_transport_goto_start (GdkEventButton *) {
539                 transport_goto_start (); return TRUE;
540         }
541         gint mouse_transport_goto_end (GdkEventButton *) {
542                 transport_goto_end (); return TRUE;
543         }
544         gint mouse_transport_record (GdkEventButton *) {
545                 transport_record (); return TRUE;
546         }
547         gint mouse_transport_forward (GdkEventButton *) {
548                 transport_forward (0); return TRUE;
549         }
550         gint mouse_transport_rewind (GdkEventButton *) {
551                 transport_rewind (0); return TRUE;
552         }
553         gint mouse_transport_loop (GdkEventButton *) {
554                 transport_loop (); return TRUE;
555         }
556         gint mouse_transport_play_selection (GdkEventButton *) {
557                 transport_play_selection (); return TRUE;
558         }
559
560         gint mouse_transport_roll (GdkEventButton *);
561         gint mouse_transport_stop (GdkEventButton *);
562
563         void set_transport_sensitivity (bool);
564
565         void remove_last_capture ();
566
567         void transport_goto_start ();
568         void transport_goto_end ();
569         void transport_stop ();
570         void transport_stop_and_forget_capture ();
571         void transport_record ();
572         void transport_roll ();
573         void transport_play_selection(); 
574         void transport_forward (int option);
575         void transport_rewind (int option);
576         void transport_loop ();
577
578         void transport_locating ();
579         void transport_rolling ();
580         void transport_rewinding ();
581         void transport_forwarding ();
582         void transport_stopped ();
583
584         void send_all_midi_feedback ();
585         
586         bool _session_is_new;
587         void connect_to_session (ARDOUR::Session *);
588         void connect_dependents_to_session (ARDOUR::Session *);
589         void we_have_dependents ();
590         void setup_keybindings ();
591
592         guint32  last_key_press_time;
593
594         void snapshot_session ();
595
596         void map_control_change (ARDOUR::Session::ControlType);
597         void queue_map_control_change (ARDOUR::Session::ControlType);
598         void map_record_state ();
599         void queue_map_record_state ();
600
601         Mixer_UI   *mixer;
602         int         create_mixer ();
603         
604         PublicEditor     *editor;
605         int         create_editor ();
606
607         RouteParams_UI *route_params;
608         int             create_route_params ();
609
610         ConnectionEditor *connection_editor;
611         int               create_connection_editor ();
612
613         LocationUI *location_ui;
614         int         create_location_ui ();
615
616         void location_ui_hiding ();
617         void big_clock_hiding ();
618         void route_params_hiding ();
619         void connection_editor_hiding ();
620         void option_hiding ();
621
622         /* Various options */
623
624         void toggle_recording_plugins ();
625
626         /* Options window */
627         
628         OptionEditor *option_editor;
629         
630         /* route dialog */
631
632         AddRouteDialog *add_route_dialog;
633         void add_route_dialog_done (int status);
634
635         /* SoundFile Browser */
636         void toggle_sound_file_browser ();
637         
638         /* Keyboard Handling */
639         
640         Keyboard* keyboard;
641
642         /* Keymap handling */
643
644         void install_keybindings ();
645         Glib::RefPtr<Gtk::ActionGroup> get_common_actions();
646         void install_actions ();
647         void test_binding_action (const char *);
648         void start_keyboard_prefix();
649
650         void toggle_record_enable (guint32);
651         void toggle_monitor_enable (guint32);
652
653         uint32_t rec_enabled_diskstreams;
654         void count_recenabled_diskstreams (ARDOUR::DiskStream&);
655
656         About* about;
657         bool shown_flag;
658         /* cleanup */
659
660         Gtk::MenuItem *cleanup_item;
661
662         void display_cleanup_results (ARDOUR::Session::cleanup_report& rep, const gchar* list_title, string msg);
663         void cleanup ();
664         void flush_trash ();
665
666         bool have_configure_timeout;
667         struct timeval last_configure_time;
668         gint configure_timeout ();
669
670         struct timeval last_peak_grab;
671         struct timeval last_shuttle_request;
672
673         void cannot_record_no_input (ARDOUR::DiskStream*);
674
675         void delete_sources_in_the_right_thread (list<ARDOUR::Source*>*);
676
677         void editor_display_control_changed (Editing::DisplayControl c);
678
679         bool have_disk_overrun_displayed;
680         bool have_disk_underrun_displayed;
681
682         void disk_overrun_message_gone ();
683         void disk_underrun_message_gone ();
684         void disk_overrun_handler ();
685         void disk_underrun_handler ();
686
687         int pending_state_dialog ();
688         
689         void disconnect_from_jack ();
690         void reconnect_to_jack ();
691         void set_jack_buffer_size (jack_nframes_t);
692
693         Gtk::MenuItem* jack_disconnect_item;
694         Gtk::MenuItem* jack_reconnect_item;
695         Gtk::Menu*     jack_bufsize_menu;
696
697         int make_session_clean ();
698         bool filter_ardour_session_dirs (const Gtk::FileFilter::Info&);
699
700         Glib::RefPtr<Gtk::ActionGroup> common_actions;
701 };
702
703
704 #endif /* __ardour_gui_h__ */