more fixes and rationalizations for MIDI option handling in the audio MIDI setup
[ardour.git] / gtk2_ardour / engine_dialog.h
1 /*
2     Copyright (C) 2010 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 __gtk2_ardour_engine_dialog_h__
21 #define __gtk2_ardour_engine_dialog_h__
22
23 #include <map>
24 #include <vector>
25 #include <string>
26
27 #include <gtkmm/checkbutton.h>
28 #include <gtkmm/spinbutton.h>
29 #include <gtkmm/comboboxtext.h>
30 #include <gtkmm/table.h>
31 #include <gtkmm/expander.h>
32 #include <gtkmm/box.h>
33 #include <gtkmm/buttonbox.h>
34 #include <gtkmm/button.h>
35
36 #include "pbd/signals.h"
37
38 #include "ardour_dialog.h"
39
40 class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
41   public:
42     EngineControl ();
43     ~EngineControl ();
44     
45     static bool need_setup ();
46     
47     XMLNode& get_state ();
48     void set_state (const XMLNode&);
49     
50     void set_desired_sample_rate (uint32_t);
51     
52   private:
53     Gtk::Notebook notebook;
54
55     /* core fields used by all backends */
56
57     Gtk::Table basic_packer;
58     Gtk::HBox basic_hbox;
59     Gtk::VBox basic_vbox;
60
61     Gtk::ComboBoxText backend_combo;
62     Gtk::ComboBoxText driver_combo;
63     Gtk::ComboBoxText device_combo;
64     Gtk::ComboBoxText sample_rate_combo;
65     Gtk::ComboBoxText midi_option_combo;
66     Gtk::ComboBoxText buffer_size_combo;
67     Gtk::Label        buffer_size_duration_label;
68     Gtk::Adjustment input_latency_adjustment;
69     Gtk::SpinButton input_latency;
70     Gtk::Adjustment output_latency_adjustment;
71     Gtk::SpinButton output_latency;
72     Gtk::Adjustment input_channels_adjustment;
73     Gtk::SpinButton input_channels;
74     Gtk::Adjustment output_channels_adjustment;
75     Gtk::SpinButton output_channels;
76     Gtk::Adjustment ports_adjustment;
77     Gtk::SpinButton ports_spinner;
78
79     Gtk::Label      have_control_text;
80     Gtk::Button     control_app_button;
81
82     Gtk::Button     connect_disconnect_button;
83
84     /* latency measurement */
85
86     Gtk::ComboBoxText lm_output_channel_combo;
87     Gtk::ComboBoxText lm_input_channel_combo;
88     Gtk::Label        lm_start_stop_label;
89     Gtk::ToggleButton lm_measure_button;
90     Gtk::Button       lm_use_button;
91     Gtk::Label        lm_title;
92     Gtk::Label        lm_results;
93     Gtk::Table        lm_table;
94     Gtk::VBox         lm_vbox;
95     bool              have_lm_results;
96
97     Gtk::Button* cancel_button;
98     Gtk::Button* ok_button;
99     Gtk::Button* apply_button;
100
101     /* MIDI Tab */
102
103     Gtk::VBox midi_vbox;
104     Gtk::Button midi_refresh_button;
105     Gtk::Table midi_device_table;
106
107     /* MIDI ... JACK */
108     
109     Gtk::CheckButton aj_button;
110     
111     uint32_t ignore_changes;
112     uint32_t _desired_sample_rate;
113     bool     no_push;
114     bool     started_at_least_once;
115
116     void driver_changed ();
117     void backend_changed ();
118     void sample_rate_changed ();
119     void buffer_size_changed ();
120     void parameter_changed ();
121     void midi_option_changed ();
122
123     void setup_midi_tab_for_backend ();
124     void setup_midi_tab_for_jack ();
125     void refresh_midi_display ();
126     
127     std::string bufsize_as_string (uint32_t);
128
129     float get_rate() const;
130     uint32_t get_buffer_size() const;
131     uint32_t get_input_channels() const;
132     uint32_t get_output_channels() const;
133     uint32_t get_input_latency() const;
134     uint32_t get_output_latency() const;
135     std::string get_device_name() const;
136     std::string get_driver() const;
137     std::string get_backend() const;
138     std::string get_midi_option () const;
139
140     void device_changed ();
141     void list_devices ();
142     void show_buffer_duration ();
143
144     struct State {
145         std::string backend;
146         std::string driver;
147         std::string device;
148         float sample_rate;
149         uint32_t buffer_size;
150         uint32_t input_latency;
151         uint32_t output_latency;
152         uint32_t input_channels;
153         uint32_t output_channels;
154         bool active;
155         std::string midi_option;
156
157         State() 
158                 : input_latency (0)
159                 , output_latency (0)
160                 , input_channels (0)
161                 , output_channels (0)
162                 , active (false) {}
163
164     };
165     
166     typedef std::list<State> StateList;
167
168     StateList states;
169
170     State* get_matching_state (const std::string& backend,
171                                const std::string& driver,
172                                const std::string& device);
173     State* get_saved_state_for_currently_displayed_backend_and_device ();
174     void maybe_display_saved_state ();
175     State* save_state ();
176     void store_state (State&);
177
178     bool  _have_control;
179
180     static bool print_channel_count (Gtk::SpinButton*);
181
182     void build_notebook ();
183     void build_full_control_notebook ();
184     void build_no_control_notebook ();
185
186     void on_response (int);
187     void control_app_button_clicked ();
188     void use_latency_button_clicked ();
189     void manage_control_app_sensitivity ();
190     int push_state_to_backend (bool start);
191     void post_push ();
192     void update_sensitivity ();
193
194     /* latency measurement */
195     void latency_button_toggled ();
196     bool check_latency_measurement ();
197     sigc::connection latency_timeout;
198     void enable_latency_tab ();
199     void disable_latency_tab ();
200     void start_latency_detection ();
201     void end_latency_detection ();
202     
203     void on_switch_page (GtkNotebookPage*, guint page_num);
204     bool on_delete_event (GdkEventAny*);
205
206     void engine_running ();
207     void engine_stopped ();
208     PBD::ScopedConnection running_connection;
209     PBD::ScopedConnection stopped_connection;
210
211     void connect_disconnect_click ();
212 };
213
214 #endif /* __gtk2_ardour_engine_dialog_h__ */