more fixes on the long road to compiling
[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 allow_focus (bool yn);
149
150         static gint generic_focus_in_event (GdkEventFocus *);
151         static gint generic_focus_out_event (GdkEventFocus *);
152
153         void toggle_location_window ();
154         void toggle_big_clock_window ();
155         void toggle_connection_editor ();
156         void toggle_route_params_window ();
157         void toggle_tempo_window ();
158
159         gint32 select_diskstream (GdkEventButton *ev);
160
161         Gtk::Tooltips& tooltips() { return _tooltips; }
162
163         static sigc::signal<void,bool> Blink;
164         static sigc::signal<void>      RapidScreenUpdate;
165         static sigc::signal<void>      SuperRapidScreenUpdate;
166         static sigc::signal<void,jack_nframes_t> Clock;
167
168         /* this is a helper function to centralize the (complex) logic for
169            blinking rec-enable buttons.
170         */
171
172         void rec_enable_button_blink (bool onoff, ARDOUR::DiskStream *, Gtk::Widget *w);
173
174         void name_io_setup (ARDOUR::AudioEngine&, string&, ARDOUR::IO& io, bool in);
175         void choose_io (ARDOUR::IO&, bool input);
176
177         static gint hide_and_quit (GdkEventAny *ev, ArdourDialog *);
178
179         XMLNode* editor_settings() const;
180         XMLNode* mixer_settings () const;
181         XMLNode* keyboard_settings () const;
182
183         void save_ardour_state ();
184         gboolean configure_handler (GdkEventConfigure* conf);
185
186         void do_transport_locate (jack_nframes_t position);
187         void halt_on_xrun_message ();
188
189         AudioClock primary_clock;
190         AudioClock secondary_clock;
191         AudioClock preroll_clock;
192         AudioClock postroll_clock;
193
194         void add_route ();
195         
196         void session_add_audio_track (int input_channels, int32_t output_channels) {
197                 session_add_audio_route (true, input_channels, output_channels);
198         }
199
200         void session_add_audio_bus (int input_channels, int32_t output_channels) {
201                 session_add_audio_route (false, input_channels, output_channels);
202         }
203
204         void session_add_midi_track ();
205
206         void set_engine (ARDOUR::AudioEngine&);
207
208         gint exit_on_main_window_close (GdkEventAny *);
209
210   protected:
211         friend class PublicEditor;
212
213         void toggle_metering ();
214         void toggle_clocking ();
215         void toggle_auto_play ();
216         void toggle_auto_input ();
217         void toggle_punch_in ();
218         void toggle_punch_out ();
219         void toggle_auto_return ();
220         void toggle_click ();
221         void toggle_follow ();
222
223         void toggle_session_auto_loop ();
224         void toggle_session_punch_in ();
225         
226         void toggle_options_window ();
227
228   private:
229         struct GlobalClickBox : public Gtk::VBox {
230             Gtkmm2ext::ClickBox  *box;
231             Gtk::Frame      frame;
232             Gtk::Label      label;
233             vector<string> &strings;
234             Gtk::Adjustment adjustment;
235
236             static void printer (char buf[32], Gtk::Adjustment &adj, void *arg);
237
238             GlobalClickBox (const string &str, vector<string> &vs)
239                     : strings (vs),
240                       adjustment (0, 0, vs.size() - 1, 1, 1, 0) {
241                     box = new Gtkmm2ext::ClickBox (&adjustment, "ClickButton");
242                     label.set_text (str);
243                     label.set_name ("GlobalButtonLabel");
244                     frame.add (*box);
245                     frame.set_shadow_type (Gtk::SHADOW_IN);
246                     pack_start (label);
247                     pack_start (frame);
248                     box->set_print_func (printer, this);
249                     box->set_wrap (true);
250             };
251         };
252
253         ARDOUR::AudioEngine                 *engine;
254         ARDOUR::Session                     *session;
255
256         Gtk::Tooltips          _tooltips;
257
258         void                     goto_editor_window ();
259         void                     goto_mixer_window ();
260         
261         Gtk::Table               adjuster_table;
262         Gtk::Frame               adjuster_frame;
263         Gtk::Fixed               adjuster_base;
264
265         GlobalClickBox     *online_control_button;
266         vector<string>      online_control_strings;
267
268         GlobalClickBox    *crossfade_time_button;
269         vector<string>     crossfade_time_strings;
270
271         GlobalClickBox    *mmc_id_button;
272         vector<string>     mmc_id_strings;
273
274         Gtk::ToggleButton   preroll_button;
275         Gtk::ToggleButton   postroll_button;
276
277         Gtk::Table          transport_table;
278         Gtk::Table          option_table;
279
280         int  setup_windows ();
281         void setup_session_menu ();
282         void setup_transport ();
283         void setup_clock ();
284         void setup_session_info ();
285         void setup_adjustables ();
286
287         Gtk::MenuBar* make_menubar ();
288         
289         static ARDOUR_UI *theArdourUI;
290
291         void startup ();
292         void shutdown ();
293
294         void finish();
295         int  ask_about_saving_session (string why);
296         gint ask_about_save_deleted (GdkEventAny*);
297         void save_session_choice_made (int);
298         int  save_the_session;
299
300         void queue_transport_change ();
301         void map_transport_state ();
302         int32_t do_engine_start ();
303         gint start_engine ();
304         
305         void engine_halted ();
306         void engine_stopped ();
307         void engine_running ();
308
309         void map_some_session_state (Gtk::ToggleButton& button,
310                                      bool (ARDOUR::Session::*get)() const);
311
312         void toggle_some_session_state (Gtk::ToggleButton& button,
313                                      bool (ARDOUR::Session::*get)() const,
314                                      void (ARDOUR::Session::*set)(bool));
315         void map_button_state ();
316
317         void clear_meters ();
318
319         static gint _blink  (void *);
320         void blink ();
321         gint blink_timeout_tag;
322         bool blink_on;
323         void start_blinking ();
324         void stop_blinking ();
325
326         void control_methods_adjusted ();
327         void mmc_device_id_adjusted ();
328
329   private:
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         AudioClock               big_clock;
338         Gtk::Frame               big_clock_frame;
339         ArdourDialog*          big_clock_window;
340
341         /* Transport Control */
342
343         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
344         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
345
346         Gtkmm2ext::TearOff*       transport_tearoff;
347         Gtk::Frame               transport_frame;
348         Gtk::HBox                transport_tearoff_hbox;
349         Gtk::HBox                transport_hbox;
350         Gtk::Fixed               transport_base;
351         Gtk::Fixed               transport_button_base;
352         Gtk::Frame               transport_button_frame;
353         Gtk::HBox                transport_button_hbox;
354         Gtk::VBox                transport_button_vbox;
355         Gtk::HBox                transport_option_button_hbox;
356         Gtk::VBox                transport_option_button_vbox;
357         Gtk::HBox                transport_clock_hbox;
358         Gtk::VBox                transport_clock_vbox;
359         Gtk::HBox                primary_clock_hbox;
360         Gtk::HBox                secondary_clock_hbox;
361
362         Gtk::Button goto_start_button;
363         Gtk::Button goto_end_button;
364         Gtk::Button rewind_button;
365         Gtk::Button forward_button;
366         Gtk::Button stop_button;
367
368         enum ShuttleBehaviour {
369                 Sprung,
370                 Wheel
371         };
372
373         enum ShuttleUnits {
374                 Percentage,
375                 Semitones
376         };
377
378         Gtk::DrawingArea shuttle_box;
379         Gtk::EventBox    speed_display_box;
380         Gtk::Label       speed_display_label;
381         Gtk::Button      shuttle_units_button;
382         Gtk::Button      shuttle_style_button;
383         Gtk::Menu*       shuttle_unit_menu;
384         Gtk::Menu*       shuttle_style_menu;
385         ShuttleBehaviour shuttle_behaviour;
386         ShuttleUnits     shuttle_units;
387
388         void shuttle_style_clicked ();
389         void shuttle_unit_clicked ();
390         void set_shuttle_behaviour (ShuttleBehaviour);
391         void set_shuttle_units (ShuttleUnits);
392         void update_speed_display ();
393
394         gint shuttle_box_button_press (GdkEventButton*);
395         gint shuttle_box_button_release (GdkEventButton*);
396         gint shuttle_box_motion (GdkEventMotion*);
397         gint shuttle_box_expose (GdkEventExpose*);
398         gint mouse_shuttle (double x, bool force);
399         void use_shuttle_fract (bool force);
400
401         bool   shuttle_grabbed;
402         double shuttle_fract;
403
404         Gtk::ToggleButton auto_loop_button;
405         Gtk::ToggleButton play_selection_button;
406         Gtk::ToggleButton roll_button;
407
408         Gtk::ToggleButton rec_button;
409         Gtk::ToggleButton punch_in_button;
410         Gtk::ToggleButton punch_out_button;
411         Gtk::ToggleButton auto_return_button;
412         Gtk::ToggleButton auto_play_button;
413         Gtk::ToggleButton auto_input_button;
414         Gtk::ToggleButton click_button;
415         Gtk::ToggleButton follow_button;
416         Gtk::ToggleButton auditioning_alert_button;
417         Gtk::ToggleButton solo_alert_button;
418
419         Gtk::VBox alert_box;
420         
421         void follow_changed ();
422
423         void solo_blink (bool);
424         void audition_blink (bool);
425
426         void soloing_changed (bool);
427         void auditioning_changed (bool);
428         void _auditioning_changed (bool);
429
430         void solo_alert_toggle ();
431         void audition_alert_toggle ();
432
433         void primary_clock_value_changed ();
434         void secondary_clock_value_changed ();
435
436         /* called by Blink signal */
437
438         void transport_rec_enable_blink (bool onoff);
439
440         /* These change where we accept control from:
441            MMC, X (local) or both.
442         */
443
444         void allow_mmc_only ();
445         void allow_mmc_and_local ();
446         void allow_local_only ();
447
448         static void rate_printer (char buf[32], Gtk::Adjustment &, void *);
449
450         Gtk::Menu*        session_popup_menu;
451
452         struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
453             RecentSessionModelColumns() { 
454                     add (visible_name);
455                     add (fullpath);
456             }
457             Gtk::TreeModelColumn<Glib::ustring> visible_name;
458             Gtk::TreeModelColumn<Glib::ustring> fullpath;
459         };
460
461         RecentSessionModelColumns    recent_session_columns;
462         Gtk::TreeView                recent_session_display;
463         Glib::RefPtr<Gtk::TreeStore> recent_session_model;
464
465         ArdourDialog*     session_selector_window;
466         Gtk::FileChooserDialog* open_session_selector;
467         
468         void build_session_selector();
469         void recent_session_selection_changed ();
470         void redisplay_recent_sessions();
471
472         struct RecentSessionsSorter {
473             bool operator() (std::pair<string,string> a, std::pair<string,string> b) const {
474                     return cmp_nocase(a.first, b.first) == -1;
475             }
476         };
477
478         /* menu bar and associated stuff */
479
480         Gtk::MenuBar* menu_bar;
481         Gtk::Fixed    menu_bar_base;
482         Gtk::HBox     menu_hbox;
483
484         void build_menu_bar ();
485         void pack_toplevel_controls();
486
487         /* handles on the menu bar items that need to 
488            be sensitive to whether or not we have
489            a session loaded.
490         */
491
492         Gtk::MenuItem *add_track_item;
493         Gtk::MenuItem *save_item;
494         Gtk::MenuItem *snapshot_item;
495         Gtk::MenuItem *save_as_item;
496         Gtk::MenuItem *save_template_item;
497         Gtk::MenuItem *export_item;
498         Gtk::MenuItem *close_item;
499
500         Gtk::CheckMenuItem *meter_bridge_dialog_check;
501         Gtk::CheckMenuItem *connection_editor_check;
502         Gtk::CheckMenuItem *route_params_check;
503         Gtk::CheckMenuItem *locations_dialog_check;
504         Gtk::CheckMenuItem *big_clock_check;
505         Gtk::CheckMenuItem *tempo_editor_check;
506         Gtk::CheckMenuItem *sfdb_check;
507         Gtk::CheckMenuItem *options_window_check;
508         
509         /* <CMT Additions> */
510         Gtk::MenuItem *image_compositor_item ;
511         /* </CMT Additions> */
512
513
514         Gtk::Label   wall_clock_label;
515         Gtk::EventBox wall_clock_box;
516         gint update_wall_clock ();
517
518         Gtk::Label   disk_space_label;
519         Gtk::EventBox disk_space_box;
520         void update_disk_space ();
521
522         Gtk::Label   cpu_load_label;
523         Gtk::EventBox cpu_load_box;
524         void update_cpu_load ();
525
526         Gtk::Label   disk_rate_label;
527         Gtk::EventBox disk_rate_box;
528         void update_disk_rate();
529
530         Gtk::Label   buffer_load_label;
531         Gtk::EventBox buffer_load_box;
532         void update_buffer_load ();
533
534         Gtk::Label   sample_rate_label;
535         Gtk::EventBox sample_rate_box;
536         void update_sample_rate (jack_nframes_t);
537
538         gint every_second ();
539         gint every_point_one_seconds ();
540         gint every_point_zero_one_seconds ();
541
542         sigc::connection second_connection;
543         sigc::connection point_one_second_connection;
544         sigc::connection point_zero_one_second_connection;
545
546         void diskstream_added (ARDOUR::DiskStream*);
547
548         gint session_menu (GdkEventButton *);
549
550         bool _will_create_new_session_automatically;
551
552         GladeRef m_new_session_dialog_ref;
553         NewSessionDialog* m_new_session_dialog;
554         
555         void open_session ();
556         void open_recent_session ();
557         void open_ok_clicked ();
558
559         void save_template ();
560
561
562         void session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels);
563
564         void add_diskstream_to_menu (ARDOUR::DiskStream&);
565         void diskstream_selected (gint32);
566         Gtk::Menu *diskstream_menu;
567         gint32 selected_dstream;
568         
569         gint mouse_transport_goto_start (GdkEventButton *) {
570                 transport_goto_start (); return TRUE;
571         }
572         gint mouse_transport_goto_end (GdkEventButton *) {
573                 transport_goto_end (); return TRUE;
574         }
575         gint mouse_transport_record (GdkEventButton *) {
576                 transport_record (); return TRUE;
577         }
578         gint mouse_transport_forward (GdkEventButton *) {
579                 transport_forward (0); return TRUE;
580         }
581         gint mouse_transport_rewind (GdkEventButton *) {
582                 transport_rewind (0); return TRUE;
583         }
584         gint mouse_transport_loop (GdkEventButton *) {
585                 transport_loop (); return TRUE;
586         }
587         gint mouse_transport_play_selection (GdkEventButton *) {
588                 transport_play_selection (); return TRUE;
589         }
590
591         gint mouse_transport_roll (GdkEventButton *);
592         gint mouse_transport_stop (GdkEventButton *);
593
594         void set_transport_sensitivity (bool);
595
596         void remove_last_capture ();
597
598         void transport_goto_start ();
599         void transport_goto_end ();
600         void transport_stop ();
601         void transport_stop_and_forget_capture ();
602         void transport_record ();
603         void transport_roll ();
604         void transport_play_selection(); 
605         void transport_forward (int option);
606         void transport_rewind (int option);
607         void transport_loop ();
608
609         void transport_locating ();
610         void transport_rolling ();
611         void transport_rewinding ();
612         void transport_forwarding ();
613         void transport_stopped ();
614
615         void send_all_midi_feedback ();
616         
617         bool _session_is_new;
618         void connect_to_session (ARDOUR::Session *);
619         void connect_dependents_to_session (ARDOUR::Session *);
620         void we_have_dependents ();
621         void setup_keybindings ();
622
623         guint32  last_key_press_time;
624
625         void snapshot_session ();
626
627         void map_control_change (ARDOUR::Session::ControlType);
628         void queue_map_control_change (ARDOUR::Session::ControlType);
629         void map_record_state ();
630         void queue_map_record_state ();
631
632         Mixer_UI   *mixer;
633         int         create_mixer ();
634         
635         PublicEditor     *editor;
636         int         create_editor ();
637
638         MeterBridge  *meter_bridge;
639         int          create_meter_bridge ();
640
641         RouteParams_UI *route_params;
642         int             create_route_params ();
643
644         ConnectionEditor *connection_editor;
645         int               create_connection_editor ();
646
647         LocationUI *location_ui;
648         int         create_location_ui ();
649
650         void meter_bridge_hiding ();
651         void location_ui_hiding ();
652         void big_clock_hiding ();
653         void route_params_hiding ();
654         void connection_editor_hiding ();
655         void option_hiding ();
656
657         /* Various options */
658
659         void toggle_recording_plugins ();
660
661         /* Options window */
662         
663         OptionEditor *option_editor;
664         
665         /* route dialog */
666
667         AddRouteDialog *add_route_dialog;
668         void add_route_dialog_done (int status);
669
670         /* SoundFile Browser */
671         void toggle_sound_file_browser ();
672         
673         /* Keyboard Handling */
674         
675         Keyboard* keyboard;
676
677         /* Keymap handling */
678
679         void install_keybindings ();
680         Glib::RefPtr<Gtk::ActionGroup> get_common_actions();
681         void install_actions ();
682         void test_binding_action (const char *);
683         void start_keyboard_prefix();
684
685         void toggle_record_enable (guint32);
686         void toggle_monitor_enable (guint32);
687
688         uint32_t rec_enabled_diskstreams;
689         void count_recenabled_diskstreams (ARDOUR::DiskStream&);
690
691         About* about;
692         bool shown_flag;
693         /* cleanup */
694
695         Gtk::MenuItem *cleanup_item;
696
697         void display_cleanup_results (ARDOUR::Session::cleanup_report& rep, const gchar* list_title, string msg);
698         void cleanup ();
699         void flush_trash ();
700
701         bool have_configure_timeout;
702         struct timeval last_configure_time;
703         gint configure_timeout ();
704
705         struct timeval last_peak_grab;
706         struct timeval last_shuttle_request;
707
708         void cannot_record_no_input (ARDOUR::DiskStream*);
709
710         void delete_sources_in_the_right_thread (list<ARDOUR::Source*>*);
711
712         void editor_display_control_changed (Editing::DisplayControl c);
713
714         bool have_disk_overrun_displayed;
715         bool have_disk_underrun_displayed;
716
717         void disk_overrun_message_gone ();
718         void disk_underrun_message_gone ();
719         void disk_overrun_handler ();
720         void disk_underrun_handler ();
721
722         int pending_state_dialog ();
723         
724         void disconnect_from_jack ();
725         void reconnect_to_jack ();
726         void set_jack_buffer_size (jack_nframes_t);
727
728         Gtk::MenuItem* jack_disconnect_item;
729         Gtk::MenuItem* jack_reconnect_item;
730         Gtk::Menu*     jack_bufsize_menu;
731
732         int make_session_clean ();
733         bool filter_ardour_session_dirs (const Gtk::FileFilter::Info&);
734
735         Glib::RefPtr<Gtk::UIManager> ui_manager;
736         Glib::RefPtr<Gtk::ActionGroup> common_actions;
737 };
738
739 #endif /* __ardour_gui_h__ */