2 * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2007-2016 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2008-2009 David Robillard <d@drobilla.net>
5 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __gtk2_ardour_engine_dialog_h__
24 #define __gtk2_ardour_engine_dialog_h__
30 #include <gtkmm/box.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/buttonbox.h>
33 #include <gtkmm/comboboxtext.h>
34 #include <gtkmm/checkbutton.h>
35 #include <gtkmm/expander.h>
36 #include <gtkmm/notebook.h>
37 #include <gtkmm/spinbutton.h>
38 #include <gtkmm/table.h>
40 #include "pbd/signals.h"
42 #include "widgets/ardour_button.h"
44 #include "ardour_dialog.h"
46 class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList
52 static bool need_setup ();
54 XMLNode& get_state ();
55 bool set_state (const XMLNode&);
57 void set_desired_sample_rate (uint32_t);
60 Gtk::Notebook notebook;
62 Gtk::Label engine_status;
64 /* core fields used by all backends */
66 Gtk::Table basic_packer;
70 Gtk::ComboBoxText backend_combo;
71 Gtk::ComboBoxText driver_combo;
72 Gtk::ComboBoxText device_combo;
73 Gtk::ComboBoxText input_device_combo;
74 Gtk::ComboBoxText output_device_combo;
75 Gtk::ComboBoxText sample_rate_combo;
76 Gtk::ComboBoxText midi_option_combo;
77 Gtk::ComboBoxText buffer_size_combo;
78 Gtk::Label buffer_size_duration_label;
79 Gtk::ComboBoxText nperiods_combo;
80 Gtk::Adjustment input_latency_adjustment;
81 Gtk::SpinButton input_latency;
82 Gtk::Adjustment output_latency_adjustment;
83 Gtk::SpinButton output_latency;
84 Gtk::Adjustment input_channels_adjustment;
85 Gtk::SpinButton input_channels;
86 Gtk::Adjustment output_channels_adjustment;
87 Gtk::SpinButton output_channels;
88 Gtk::Adjustment ports_adjustment;
89 Gtk::SpinButton ports_spinner;
91 Gtk::Label have_control_text;
92 ArdourWidgets::ArdourButton control_app_button;
93 ArdourWidgets::ArdourButton midi_devices_button;
94 ArdourWidgets::ArdourButton start_stop_button;
95 ArdourWidgets::ArdourButton update_devices_button;
96 ArdourWidgets::ArdourButton use_buffered_io_button;
97 ArdourWidgets::ArdourButton try_autostart_button;
99 Gtk::Button connect_disconnect_button;
101 /* latency measurement */
103 class ChannelNameCols : public Gtk::TreeModelColumnRecord
110 Gtk::TreeModelColumn<std::string> pretty_name;
111 Gtk::TreeModelColumn<std::string> port_name;
114 ChannelNameCols lm_output_channel_cols;
115 Glib::RefPtr<Gtk::ListStore> lm_output_channel_list;
116 Gtk::ComboBox lm_output_channel_combo;
118 ChannelNameCols lm_input_channel_cols;
119 Glib::RefPtr<Gtk::ListStore> lm_input_channel_list;
120 Gtk::ComboBox lm_input_channel_combo;
122 Gtk::Label lm_measure_label;
123 Gtk::Button lm_measure_button;
124 Gtk::Button lm_use_button;
125 Gtk::Button lm_back_button;
126 ArdourWidgets::ArdourButton lm_button_audio;
128 Gtk::Label lm_preamble;
129 Gtk::Label lm_results;
132 bool have_lm_results;
138 Gtk::Button midi_back_button;
139 Gtk::Table midi_device_table;
143 Gtk::CheckButton aj_button;
145 uint32_t ignore_changes; // state save/load
146 uint32_t ignore_device_changes; // AudioEngine::DeviceListChanged
147 uint32_t _desired_sample_rate;
148 bool started_at_least_once;
149 bool queue_device_changed;
151 void driver_changed ();
152 void backend_changed ();
153 void sample_rate_changed ();
154 void buffer_size_changed ();
155 void nperiods_changed ();
156 void parameter_changed ();
157 void midi_option_changed ();
159 void setup_midi_tab_for_backend ();
160 void setup_midi_tab_for_jack ();
161 void refresh_midi_display (std::string focus = "");
163 void update_midi_options ();
165 std::string bufsize_as_string (uint32_t);
166 std::string nperiods_as_string (uint32_t);
168 std::vector<float> get_default_sample_rates ();
169 std::vector<uint32_t> get_default_buffer_sizes ();
171 std::vector<float> get_sample_rates_for_all_devices ();
172 std::vector<uint32_t> get_buffer_sizes_for_all_devices ();
174 float get_rate() const;
175 uint32_t get_buffer_size() const;
176 uint32_t get_nperiods() const;
177 uint32_t get_input_channels() const;
178 uint32_t get_output_channels() const;
179 uint32_t get_input_latency() const;
180 uint32_t get_output_latency() const;
181 std::string get_device_name() const;
182 std::string get_input_device_name() const;
183 std::string get_output_device_name() const;
184 std::string get_driver() const;
185 std::string get_backend() const;
186 std::string get_midi_option () const;
187 bool get_use_buffered_io () const;
189 std::string get_default_device (const std::string&,
190 const std::vector<std::string>&);
192 void device_changed ();
193 void input_device_changed ();
194 void output_device_changed ();
195 bool set_driver_popdown_strings ();
196 bool set_device_popdown_strings ();
197 bool set_input_device_popdown_strings ();
198 bool set_output_device_popdown_strings ();
199 void set_samplerate_popdown_strings ();
200 void set_buffersize_popdown_strings ();
201 void set_nperiods_popdown_strings ();
202 void list_devices ();
203 void show_buffer_duration ();
205 void configure_midi_devices ();
207 struct MidiDeviceSetting {
210 uint32_t input_latency;
211 uint32_t output_latency;
213 MidiDeviceSetting (std::string n, bool en = true, uint32_t inl = 0, uint32_t oul = 0)
216 , input_latency (inl)
217 , output_latency (oul)
221 typedef boost::shared_ptr<MidiDeviceSetting> MidiDeviceSettings;
222 bool _can_set_midi_latencies;
223 std::vector<MidiDeviceSettings> _midi_devices;
225 MidiDeviceSettings find_midi_device(std::string devicename) const {
226 for (std::vector<MidiDeviceSettings>::const_iterator p = _midi_devices.begin(); p != _midi_devices.end(); ++p) {
227 if ((*p)->name == devicename) {
231 return MidiDeviceSettings();
238 std::string input_device;
239 std::string output_device;
241 uint32_t buffer_size;
243 uint32_t input_latency;
244 uint32_t output_latency;
245 uint32_t input_channels;
246 uint32_t output_channels;
248 bool use_buffered_io;
249 std::string midi_option;
250 std::vector<MidiDeviceSettings> midi_devices;
254 : sample_rate (48000)
259 , output_channels (0)
261 , use_buffered_io (false)
266 typedef boost::shared_ptr<StateStruct> State;
267 typedef std::list<State> StateList;
268 static bool state_sort_cmp (const State &a, const State &b);
272 State get_matching_state (const std::string& backend);
273 State get_matching_state (const std::string& backend,
274 const std::string& driver,
275 const std::string& device);
276 State get_matching_state (const std::string& backend,
277 const std::string& driver,
278 const std::string& input_device,
279 const std::string& output_device);
280 State get_saved_state_for_currently_displayed_backend_and_device ();
281 void maybe_display_saved_state ();
283 void store_state (State);
284 bool equivalent_states (const State&, const State&);
286 bool set_current_state (const State& state);
287 void set_default_state ();
291 static bool print_channel_count (Gtk::SpinButton*);
293 void build_notebook ();
294 void build_full_control_notebook ();
295 void build_no_control_notebook ();
297 void connect_changed_signals ();
298 void block_changed_signals ();
299 void unblock_changed_signals ();
304 SignalBlocker (EngineControl& engine_control, const std::string& reason);
310 std::string m_reason;
313 uint32_t block_signals;
315 sigc::connection backend_combo_connection;
316 sigc::connection driver_combo_connection;
317 sigc::connection sample_rate_combo_connection;
318 sigc::connection buffer_size_combo_connection;
319 sigc::connection nperiods_combo_connection;
320 sigc::connection device_combo_connection;
321 sigc::connection input_device_combo_connection;
322 sigc::connection output_device_combo_connection;
323 sigc::connection midi_option_combo_connection;
324 sigc::connection input_latency_connection;
325 sigc::connection output_latency_connection;
326 sigc::connection input_channels_connection;
327 sigc::connection output_channels_connection;
331 void config_parameter_changed (std::string const&);
332 void control_app_button_clicked ();
333 void start_stop_button_clicked ();
334 void update_devices_button_clicked ();
335 void use_buffered_io_button_clicked ();
336 void try_autostart_button_clicked ();
337 void use_latency_button_clicked ();
338 void manage_control_app_sensitivity ();
339 int push_state_to_backend (bool start);
341 void update_sensitivity ();
342 bool start_engine ();
343 bool stop_engine (bool for_latency = false);
345 /* latency measurement */
346 void latency_button_clicked ();
347 void latency_back_button_clicked ();
348 bool check_audio_latency_measurement ();
349 bool check_midi_latency_measurement ();
350 sigc::connection latency_timeout;
351 void enable_latency_tab ();
352 void disable_latency_tab ();
353 void start_latency_detection ();
354 void end_latency_detection ();
356 void on_switch_page (GtkNotebookPage*, guint page_num);
357 bool on_delete_event (GdkEventAny*);
358 void on_response (int);
360 void engine_running ();
361 void engine_stopped ();
362 void device_list_changed ();
364 PBD::ScopedConnection running_connection;
365 PBD::ScopedConnectionList stopped_connection;
366 PBD::ScopedConnection devicelist_connection;
368 void connect_disconnect_click ();
369 void calibrate_audio_latency ();
370 void calibrate_midi_latency (MidiDeviceSettings);
372 MidiDeviceSettings _measure_midi;
373 void midi_latency_adjustment_changed(Gtk::Adjustment *, MidiDeviceSettings, bool);
374 void midi_device_enabled_toggled(ArdourWidgets::ArdourButton *, MidiDeviceSettings);
375 sigc::connection lm_back_button_signal;
378 #endif /* __gtk2_ardour_engine_dialog_h__ */