enable ArdourButton focus in EngineDialog
[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 #include "ardour_button.h"
40
41 class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
42   public:
43     EngineControl ();
44     ~EngineControl ();
45     
46     static bool need_setup ();
47     
48     XMLNode& get_state ();
49     void set_state (const XMLNode&);
50     
51     void set_desired_sample_rate (uint32_t);
52     
53   private:
54     Gtk::Notebook notebook;
55
56     /* core fields used by all backends */
57
58     Gtk::Table basic_packer;
59     Gtk::HBox basic_hbox;
60     Gtk::VBox basic_vbox;
61
62     Gtk::ComboBoxText backend_combo;
63     Gtk::ComboBoxText driver_combo;
64     Gtk::ComboBoxText device_combo;
65     Gtk::ComboBoxText sample_rate_combo;
66     Gtk::ComboBoxText midi_option_combo;
67     Gtk::ComboBoxText buffer_size_combo;
68     Gtk::Label        buffer_size_duration_label;
69     Gtk::Adjustment input_latency_adjustment;
70     Gtk::SpinButton input_latency;
71     Gtk::Adjustment output_latency_adjustment;
72     Gtk::SpinButton output_latency;
73     Gtk::Adjustment input_channels_adjustment;
74     Gtk::SpinButton input_channels;
75     Gtk::Adjustment output_channels_adjustment;
76     Gtk::SpinButton output_channels;
77     Gtk::Adjustment ports_adjustment;
78     Gtk::SpinButton ports_spinner;
79
80     Gtk::Label      have_control_text;
81     Gtk::Button     control_app_button;
82     ArdourButton    midi_devices_button;
83
84     Gtk::Button     connect_disconnect_button;
85
86     /* latency measurement */
87
88     Gtk::ComboBoxText lm_output_channel_combo;
89     Gtk::ComboBoxText lm_input_channel_combo;
90     Gtk::Label        lm_measure_label;
91     Gtk::Button       lm_measure_button;
92     Gtk::Button       lm_use_button;
93     Gtk::Button       lm_back_button;
94     ArdourButton      lm_button_audio;
95     Gtk::Label        lm_title;
96     Gtk::Label        lm_results;
97     Gtk::Table        lm_table;
98     Gtk::VBox         lm_vbox;
99     bool              have_lm_results;
100     bool              lm_running;
101
102     Gtk::Button* cancel_button;
103     Gtk::Button* ok_button;
104     Gtk::Button* apply_button;
105
106     /* MIDI Tab */
107
108     Gtk::VBox midi_vbox;
109     Gtk::Button midi_back_button;
110     Gtk::Table midi_device_table;
111
112     /* MIDI ... JACK */
113     
114     Gtk::CheckButton aj_button;
115     
116     uint32_t ignore_changes;
117     uint32_t _desired_sample_rate;
118     bool     started_at_least_once;
119
120     void driver_changed ();
121     void backend_changed ();
122     void sample_rate_changed ();
123     void buffer_size_changed ();
124     void parameter_changed ();
125     void midi_option_changed ();
126
127     void setup_midi_tab_for_backend ();
128     void setup_midi_tab_for_jack ();
129     void refresh_midi_display (std::string focus = "");
130     
131     std::string bufsize_as_string (uint32_t);
132
133     float get_rate() const;
134     uint32_t get_buffer_size() const;
135     uint32_t get_input_channels() const;
136     uint32_t get_output_channels() const;
137     uint32_t get_input_latency() const;
138     uint32_t get_output_latency() const;
139     std::string get_device_name() const;
140     std::string get_driver() const;
141     std::string get_backend() const;
142     std::string get_midi_option () const;
143
144     void device_changed ();
145     void list_devices ();
146     void show_buffer_duration ();
147
148     void configure_midi_devices ();
149
150     struct MidiDeviceSetting {
151         std::string name;
152         bool enabled;
153         uint32_t input_latency;
154         uint32_t output_latency;
155
156         MidiDeviceSetting (std::string n, bool en = true, uint32_t inl = 0, uint32_t oul = 0)
157             : name (n)
158             , enabled (en)
159             , input_latency (inl)
160             , output_latency (oul)
161         {}
162     };
163
164     typedef boost::shared_ptr<MidiDeviceSetting> MidiDeviceSettings;
165     bool _can_set_midi_latencies;
166     std::vector<MidiDeviceSettings> _midi_devices;
167
168     MidiDeviceSettings find_midi_device(std::string devicename) const {
169         for (std::vector<MidiDeviceSettings>::const_iterator p = _midi_devices.begin(); p != _midi_devices.end(); ++p) {
170             if ((*p)->name == devicename) {
171                 return *p;
172             }
173         }
174         return MidiDeviceSettings();
175     }
176
177     struct State {
178         std::string backend;
179         std::string driver;
180         std::string device;
181         float sample_rate;
182         uint32_t buffer_size;
183         uint32_t input_latency;
184         uint32_t output_latency;
185         uint32_t input_channels;
186         uint32_t output_channels;
187         bool active;
188         std::string midi_option;
189         std::vector<MidiDeviceSettings> midi_devices;
190
191         State() 
192                 : input_latency (0)
193                 , output_latency (0)
194                 , input_channels (0)
195                 , output_channels (0)
196                 , active (false) {}
197
198     };
199     
200     typedef std::list<State> StateList;
201
202     StateList states;
203
204     State* get_matching_state (const std::string& backend,
205                                const std::string& driver,
206                                const std::string& device);
207     State* get_saved_state_for_currently_displayed_backend_and_device ();
208     void maybe_display_saved_state ();
209     State* save_state ();
210     void store_state (State&);
211
212     bool  _have_control;
213
214     static bool print_channel_count (Gtk::SpinButton*);
215
216     void build_notebook ();
217     void build_full_control_notebook ();
218     void build_no_control_notebook ();
219
220     void on_response (int);
221     void control_app_button_clicked ();
222     void use_latency_button_clicked ();
223     void manage_control_app_sensitivity ();
224     int push_state_to_backend (bool start);
225     void post_push ();
226     void update_sensitivity ();
227
228     /* latency measurement */
229     void latency_button_clicked ();
230     bool check_audio_latency_measurement ();
231     bool check_midi_latency_measurement ();
232     sigc::connection latency_timeout;
233     void enable_latency_tab ();
234     void disable_latency_tab ();
235     void start_latency_detection ();
236     void end_latency_detection ();
237     
238     void on_switch_page (GtkNotebookPage*, guint page_num);
239     bool on_delete_event (GdkEventAny*);
240
241     void engine_running ();
242     void engine_stopped ();
243     PBD::ScopedConnection running_connection;
244     PBD::ScopedConnection stopped_connection;
245
246     void connect_disconnect_click ();
247     void calibrate_audio_latency ();
248     void calibrate_midi_latency (MidiDeviceSettings);
249
250     MidiDeviceSettings _measure_midi;
251     void midi_latency_adjustment_changed(Gtk::Adjustment *, MidiDeviceSettings, bool);
252     void midi_device_enabled_toggled(ArdourButton *, MidiDeviceSettings);
253     sigc::connection lm_back_button_signal;
254 };
255
256 #endif /* __gtk2_ardour_engine_dialog_h__ */