Ardour  9.0-pre0-582-g084a23a80d
engine_dialog.h
Go to the documentation of this file.
1 /*
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-2022 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
7  *
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.
12  *
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.
17  *
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.
21  */
22 
23 #ifndef __gtk2_ardour_engine_dialog_h__
24 #define __gtk2_ardour_engine_dialog_h__
25 
26 #include <map>
27 #include <string>
28 #include <vector>
29 
30 #include <gtkmm/box.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/buttonbox.h>
33 #include <gtkmm/checkbutton.h>
34 #include <gtkmm/comboboxtext.h>
35 #include <gtkmm/expander.h>
36 #include <gtkmm/liststore.h>
37 #include <gtkmm/notebook.h>
38 #include <gtkmm/spinbutton.h>
39 #include <gtkmm/table.h>
40 
41 #include "pbd/signals.h"
42 #include "pbd/xml++.h"
43 
44 #include "widgets/ardour_button.h"
45 
46 #include "ardour_dialog.h"
47 
49 {
50 public:
53 
54  static bool need_setup ();
55 
56  XMLNode& get_state () const;
57  bool set_state (const XMLNode&);
58 
59  void set_desired_sample_rate (uint32_t);
60 
61 private:
63 
65 
66  /* core fields used by all backends */
67 
70 
75 
90 
104 
108 
115 
117 
118  /* latency measurement */
119 
121  {
122  public:
124  {
125  add (pretty_name);
126  add (port_name);
127  }
130  };
131 
133  Glib::RefPtr<Gtk::ListStore> lm_output_channel_list;
135 
137  Glib::RefPtr<Gtk::ListStore> lm_input_channel_list;
139 
153 
154  /* MIDI Tab */
155 
159 
160  /* MIDI ... JACK */
161 
163 
164  uint32_t ignore_changes; // state save/load
165  uint32_t ignore_device_changes; // AudioEngine::DeviceListChanged
169 
170  void driver_changed ();
178 
179  void refresh_midi_display (std::string focus = "");
180 
182 
183  std::string bufsize_as_string (uint32_t);
184  std::string nperiods_as_string (uint32_t);
185 
186  std::vector<float> get_default_sample_rates ();
187  std::vector<uint32_t> get_default_buffer_sizes ();
188 
189  std::vector<float> get_sample_rates_for_all_devices ();
190  std::vector<uint32_t> get_buffer_sizes_for_all_devices ();
191 
192  float get_rate () const;
193  uint32_t get_buffer_size () const;
194  uint32_t get_nperiods () const;
195  uint32_t get_input_latency () const;
196  uint32_t get_output_latency () const;
197  std::string get_device_name () const;
198  std::string get_input_device_name () const;
199  std::string get_output_device_name () const;
200  std::string get_driver () const;
201  std::string get_backend () const;
202  std::string get_midi_option () const;
203  bool get_use_buffered_io () const;
204 
205  std::string get_default_device (const std::string&,
206  const std::vector<std::string>&);
207 
208  void device_changed ();
218  void list_devices ();
220 
222 
224  std::string name;
225  bool enabled;
226  uint32_t input_latency;
227  uint32_t output_latency;
228 
229  MidiDeviceSetting (std::string n, bool en = true, uint32_t inl = 0, uint32_t oul = 0)
230  : name (n)
231  , enabled (en)
232  , input_latency (inl)
233  , output_latency (oul)
234  {
235  }
236  };
237 
238  typedef std::shared_ptr<MidiDeviceSetting> MidiDeviceSettings;
240  std::vector<MidiDeviceSettings> _midi_devices;
241 
242  MidiDeviceSettings find_midi_device (std::string devicename) const
243  {
244  for (std::vector<MidiDeviceSettings>::const_iterator p = _midi_devices.begin (); p != _midi_devices.end (); ++p) {
245  if ((*p)->name == devicename) {
246  return *p;
247  }
248  }
249  return MidiDeviceSettings ();
250  }
251 
252  struct StateStruct {
253  std::string backend;
254  std::string driver;
255  std::string device;
256  std::string input_device;
257  std::string output_device;
258  float sample_rate;
259  uint32_t buffer_size;
260  uint32_t n_periods;
261  uint32_t input_latency;
262  uint32_t output_latency;
263  bool active;
265  std::string midi_option;
266  std::vector<MidiDeviceSettings> midi_devices;
267  std::string lm_input;
268  std::string lm_output;
269  time_t lru;
270 
272  : sample_rate (48000)
273  , buffer_size (1024)
274  , n_periods (0)
275  , input_latency (0)
276  , output_latency (0)
277  , active (false)
278  , use_buffered_io (false)
279  , lru (0)
280  {
281  }
282  };
283 
284  typedef std::shared_ptr<StateStruct> State;
285  typedef std::list<State> StateList;
286  static bool state_sort_cmp (const State& a, const State& b);
287 
289 
290  bool set_state_for_backend (const std::string& backend);
291 
292  State get_matching_state (const std::string& backend,
293  const std::string& driver,
294  const std::string& device,
295  const float sample_rate = 0);
296  State get_matching_state (const std::string& backend,
297  const std::string& driver,
298  const std::string& input_device,
299  const std::string& output_device,
300  const float sample_rate = 0);
301 
306  bool equivalent_states (const State&, const State&);
307 
308  bool set_current_state (const State& state);
310 
312 
313  void build_notebook ();
317 
321 
323  {
324  public:
325  SignalBlocker (EngineControl& engine_control, const std::string& reason);
327 
328  private:
330  std::string m_reason;
331  };
332 
333  uint32_t block_signals;
334 
335  sigc::connection backend_combo_connection;
336  sigc::connection driver_combo_connection;
339  sigc::connection nperiods_combo_connection;
340  sigc::connection device_combo_connection;
344  sigc::connection input_latency_connection;
345  sigc::connection output_latency_connection;
346  sigc::connection monitor_model_connection;
347  sigc::connection latency_timeout;
348  sigc::connection lm_back_button_signal;
349 
350  void on_show ();
351  void on_map ();
354  void config_parameter_changed (std::string const&);
363  void post_push ();
365  bool start_engine ();
366  bool stop_engine (bool for_latency = false);
367 
368  /* latency measurement */
377 
379 
382 
383  /* main dialog events */
384  void on_switch_page (GtkNotebookPage*, guint page_num);
386  void on_response (int);
387 
391 
392  void engine_running ();
393  void engine_stopped ();
395 
399 };
400 
401 #endif /* __gtk2_ardour_engine_dialog_h__ */
Gtk::TreeModelColumn< std::string > pretty_name
Gtk::TreeModelColumn< std::string > port_name
SignalBlocker(EngineControl &engine_control, const std::string &reason)
Gtk::Label lbl_input_latency
sigc::connection input_latency_connection
State get_saved_state_for_currently_displayed_backend_and_device()
void set_samplerate_popdown_strings()
sigc::connection device_combo_connection
bool set_driver_popdown_strings()
uint32_t get_output_latency() const
std::vector< MidiDeviceSettings > _midi_devices
void show_buffer_duration()
Gtk::Label lbl_device
Definition: engine_dialog.h:94
Gtk::Label lm_results
void set_nperiods_popdown_strings()
void device_changed()
void refresh_midi_display(std::string focus="")
ChannelNameCols lm_output_channel_cols
Gtk::ComboBoxText buffer_size_combo
Definition: engine_dialog.h:83
void on_response(int)
This is a default handler for the signal signal_response().
ArdourWidgets::ArdourButton start_stop_button
bool set_state(const XMLNode &)
Glib::RefPtr< Gtk::ListStore > lm_output_channel_list
Gtk::Label lbl_audio_system
Definition: engine_dialog.h:91
Gtk::VBox lm_vbox
void connect_disconnect_click()
void manage_control_app_sensitivity()
sigc::connection sample_rate_combo_connection
std::shared_ptr< StateStruct > State
std::vector< float > get_default_sample_rates()
sigc::connection backend_combo_connection
void start_latency_detection()
void control_app_button_clicked()
void disable_latency_tab()
bool on_delete_event(GdkEventAny *)
This is a default handler for the signal signal_delete_event().
std::string get_driver() const
void use_buffered_io_button_clicked()
State save_state()
PBD::ScopedConnectionList stopped_connection
bool set_device_popdown_strings()
static bool need_setup()
Gtk::Table midi_device_table
bool get_use_buffered_io() const
void monitor_model_changed()
std::vector< uint32_t > get_buffer_sizes_for_all_devices()
Gtk::Table lm_table
void output_device_changed()
std::vector< float > get_sample_rates_for_all_devices()
PBD::ScopedConnection running_connection
Gtk::Label unit_samples_txt1
MidiDeviceSettings _measure_midi
void block_changed_signals()
static bool state_sort_cmp(const State &a, const State &b)
Gtk::Button connect_disconnect_button
void latency_back_button_clicked()
void build_no_control_notebook()
void try_autostart_button_clicked()
Gtk::VBox midi_vbox
std::string get_device_name() const
bool _can_set_midi_latencies
std::string bufsize_as_string(uint32_t)
Gtk::Label lbl_output_device
Definition: engine_dialog.h:96
void start_stop_button_clicked()
void sample_rate_changed()
void midi_option_changed()
void latency_changed()
uint32_t get_nperiods() const
void enable_latency_tab()
Gtk::Expander latency_expander
Definition: engine_dialog.h:73
void connect_changed_signals()
std::string get_backend() const
Gtk::Button midi_back_button
Gtk::Label unit_samples_txt2
MidiDeviceSettings find_midi_device(std::string devicename) const
void list_devices()
std::vector< uint32_t > get_default_buffer_sizes()
bool stop_engine(bool for_latency=false)
Gtk::Table latency_table
Definition: engine_dialog.h:72
Gtk::ComboBoxText midi_option_combo
Definition: engine_dialog.h:82
sigc::connection output_device_combo_connection
std::string get_default_device(const std::string &, const std::vector< std::string > &)
Gtk::Label lm_title
Gtk::SpinButton input_latency
Definition: engine_dialog.h:86
uint32_t ignore_device_changes
void update_devices_button_clicked()
Gtk::ComboBoxText output_device_combo
Definition: engine_dialog.h:80
XMLNode & get_state() const
Gtk::Button lm_measure_button
bool set_current_state(const State &state)
void on_monitor_expand()
void store_state(State)
sigc::connection output_latency_connection
bool was_running_before_lm
Gtk::Label engine_status
Definition: engine_dialog.h:64
void maybe_display_saved_state()
Gtk::SpinButton output_latency
Definition: engine_dialog.h:88
void build_notebook()
void configure_midi_devices()
Gtk::Notebook notebook
Definition: engine_dialog.h:62
float get_rate() const
sigc::connection latency_timeout
PBD::ScopedConnection devicelist_connection
void driver_changed()
Gtk::Button lm_use_button
StateList states
std::string nperiods_as_string(uint32_t)
bool set_state_for_backend(const std::string &backend)
void input_device_changed()
Gtk::Table settings_table
Definition: engine_dialog.h:71
bool equivalent_states(const State &, const State &)
void midi_latency_adjustment_changed(Gtk::Adjustment *, MidiDeviceSettings, bool)
ArdourWidgets::ArdourButton control_app_button
Gtk::ComboBoxText sample_rate_combo
Definition: engine_dialog.h:81
ArdourWidgets::ArdourButton midi_devices_button
Gtk::Button lm_back_button
uint32_t get_input_latency() const
Gtk::Adjustment input_latency_adjustment
Definition: engine_dialog.h:85
Gtk::Label lbl_input_device
Definition: engine_dialog.h:95
Gtk::Label lbl_output_latency
Gtk::ComboBoxText nperiods_combo
Definition: engine_dialog.h:84
void set_default_state()
void engine_stopped()
std::string get_input_device_name() const
void config_parameter_changed(std::string const &)
void on_show()
This is a default handler for the signal signal_show().
void set_desired_sample_rate(uint32_t)
sigc::connection driver_combo_connection
Gtk::Adjustment output_latency_adjustment
Definition: engine_dialog.h:87
Gtk::ComboBox lm_output_channel_combo
bool started_at_least_once
void unblock_changed_signals()
Gtk::ComboBox lm_input_channel_combo
void backend_changed()
uint32_t ignore_changes
bool check_audio_latency_measurement()
void device_list_changed()
ArdourWidgets::ArdourButton try_autostart_button
Gtk::Label lbl_nperiods
Definition: engine_dialog.h:99
uint32_t get_buffer_size() const
uint32_t block_signals
Gtk::ComboBoxText device_combo
Definition: engine_dialog.h:78
Gtk::Expander monitor_expander
Definition: engine_dialog.h:74
void build_full_control_notebook()
std::list< State > StateList
bool queue_device_changed
State get_matching_state(const std::string &backend, const std::string &driver, const std::string &device, const float sample_rate=0)
void latency_button_clicked()
sigc::connection monitor_model_connection
Gtk::Label lm_preamble
void update_sensitivity()
void end_latency_detection()
ArdourWidgets::ArdourButton update_devices_button
void on_map()
This is a default handler for the signal signal_map().
State get_matching_state(const std::string &backend, const std::string &driver, const std::string &input_device, const std::string &output_device, const float sample_rate=0)
void buffer_size_changed()
void calibrate_audio_latency()
uint32_t _desired_sample_rate
void on_latency_expand()
std::string get_output_device_name() const
sigc::connection input_device_combo_connection
void engine_running()
sigc::connection lm_back_button_signal
void use_latency_button_clicked()
Gtk::Label lbl_jack_msg
Gtk::HBox main_hbox
Definition: engine_dialog.h:69
int push_state_to_backend(bool start)
void on_switch_page(GtkNotebookPage *, guint page_num)
Gtk::Label lbl_driver
Definition: engine_dialog.h:93
void set_buffersize_popdown_strings()
ArdourWidgets::ArdourButton lm_button_audio
bool check_midi_latency_measurement()
void nperiods_changed()
Gtk::Label lbl_midi_system
Definition: engine_dialog.h:92
void calibrate_midi_latency(MidiDeviceSettings)
std::shared_ptr< MidiDeviceSetting > MidiDeviceSettings
Gtk::Label buffer_size_duration_label
void populate_action_area(int)
Gtk::ComboBoxText driver_combo
Definition: engine_dialog.h:77
Gtk::ComboBoxText monitor_model_combo
Definition: engine_dialog.h:89
bool start_engine()
bool set_output_device_popdown_strings()
ArdourWidgets::ArdourButton use_buffered_io_button
Gtk::Label lbl_monitor_model
void post_push()
Gtk::Label lbl_buffer_size
Definition: engine_dialog.h:98
Gtk::ComboBoxText input_device_combo
Definition: engine_dialog.h:79
Gtk::CheckButton aj_button
sigc::connection buffer_size_combo_connection
Gtk::VBox main_vbox
Definition: engine_dialog.h:68
Gtk::Label lm_measure_label
void update_midi_options()
Gtk::Label lbl_sample_rate
Definition: engine_dialog.h:97
void midi_device_enabled_toggled(ArdourWidgets::ArdourButton *, MidiDeviceSettings)
sigc::connection nperiods_combo_connection
Gtk::ComboBoxText backend_combo
Definition: engine_dialog.h:76
sigc::connection midi_option_combo_connection
bool set_input_device_popdown_strings()
Glib::RefPtr< Gtk::ListStore > lm_input_channel_list
ChannelNameCols lm_input_channel_cols
std::string get_midi_option() const
void add(TreeModelColumnBase &column)
Definition: xml++.h:114
struct _GtkNotebookPage GtkNotebookPage
Definition: gtknotebook.h:58
PBD::PropertyDescriptor< timepos_t > start
MidiDeviceSetting(std::string n, bool en=true, uint32_t inl=0, uint32_t oul=0)
std::vector< MidiDeviceSettings > midi_devices