2 Copyright (C) 2010 Paul Davis
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.
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.
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.
26 #include <boost/scoped_ptr.hpp>
28 #include <gtkmm/messagedialog.h>
30 #include "pbd/error.h"
31 #include "pbd/xml++.h"
32 #include "pbd/unwind.h"
34 #include <gtkmm/stock.h>
35 #include <gtkmm/notebook.h>
36 #include <gtkmm2ext/utils.h>
38 #include "ardour/audio_backend.h"
39 #include "ardour/audioengine.h"
40 #include "ardour/mtdm.h"
41 #include "ardour/rc_configuration.h"
42 #include "ardour/types.h"
44 #include "pbd/convert.h"
45 #include "pbd/error.h"
47 #include "engine_dialog.h"
48 #include "gui_thread.h"
53 using namespace Gtkmm2ext;
57 EngineControl::EngineControl ()
58 : ArdourDialog (_("Audio/MIDI Setup"))
59 , input_latency_adjustment (0, 0, 99999, 1)
60 , input_latency (input_latency_adjustment)
61 , output_latency_adjustment (0, 0, 99999, 1)
62 , output_latency (output_latency_adjustment)
63 , input_channels_adjustment (0, 0, 256, 1)
64 , input_channels (input_channels_adjustment)
65 , output_channels_adjustment (0, 0, 256, 1)
66 , output_channels (output_channels_adjustment)
67 , ports_adjustment (128, 8, 1024, 1, 16)
68 , ports_spinner (ports_adjustment)
69 , control_app_button (_("Launch Control App"))
70 , lm_measure_button (_("Measure latency"))
71 , lm_use_button (_("Use results"))
75 , _desired_sample_rate (0)
79 get_vbox()->set_border_width (12);
80 get_vbox()->pack_start (notebook);
82 control_app_button.signal_clicked().connect (mem_fun (*this, &EngineControl::control_app_button_clicked));
83 manage_control_app_sensitivity ();
85 add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
86 add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
87 add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_APPLY);
89 /* Pick up any existing audio setup configuration, if appropriate */
91 XMLNode* audio_setup = ARDOUR::Config->extra_xml ("AudioMIDISetup");
93 /* push a change as if we altered the backend */
97 set_state (*audio_setup);
102 EngineControl::on_response (int response_id)
104 ArdourDialog::on_response (response_id);
106 switch (response_id) {
108 push_state_to_backend (true);
111 push_state_to_backend (true);
120 EngineControl::build_notebook ()
122 using namespace Notebook_Helpers;
124 vector<string> strings;
127 vector<const ARDOUR::AudioBackendInfo*> backends = ARDOUR::AudioEngine::instance()->available_backends();
128 for (vector<const ARDOUR::AudioBackendInfo*>::const_iterator b = backends.begin(); b != backends.end(); ++b) {
129 strings.push_back ((*b)->name);
132 set_popdown_strings (backend_combo, strings);
133 backend_combo.set_active_text (strings.front());
135 basic_packer.set_spacings (6);
136 basic_packer.set_border_width (12);
137 basic_packer.set_homogeneous (true);
141 AttachOptions xopt = AttachOptions (FILL|EXPAND);
143 label = manage (left_aligned_label (_("Audio System:")));
144 basic_packer.attach (*label, 0, 1, row, row + 1, xopt, (AttachOptions) 0);
145 basic_packer.attach (backend_combo, 1, 2, row, row + 1, xopt, (AttachOptions) 0);
148 label = manage (left_aligned_label (_("Driver:")));
149 basic_packer.attach (*label, 0, 1, row, row + 1, xopt, (AttachOptions) 0);
150 basic_packer.attach (driver_combo, 1, 2, row, row + 1, xopt, (AttachOptions) 0);
153 label = manage (left_aligned_label (_("Device:")));
154 basic_packer.attach (*label, 0, 1, row, row + 1, xopt, (AttachOptions) 0);
155 basic_packer.attach (device_combo, 1, 2, row, row + 1, xopt, (AttachOptions) 0);
158 label = manage (left_aligned_label (_("Sample rate:")));
159 basic_packer.attach (*label, 0, 1, row, row + 1, xopt, (AttachOptions) 0);
160 basic_packer.attach (sample_rate_combo, 1, 2, row, row + 1, xopt, (AttachOptions) 0);
164 label = manage (left_aligned_label (_("Buffer size:")));
165 basic_packer.attach (*label, 0, 1, row, row + 1, xopt, (AttachOptions) 0);
166 basic_packer.attach (buffer_size_combo, 1, 2, row, row + 1, xopt, (AttachOptions) 0);
167 buffer_size_duration_label.set_alignment (0.0); /* left-align */
168 basic_packer.attach (buffer_size_duration_label, 2, 3, row, row+1, xopt, (AttachOptions) 0);
172 label = manage (left_aligned_label (_("Input Channels:")));
173 basic_packer.attach (*label, 0, 1, row, row+1, xopt, (AttachOptions) 0);
174 basic_packer.attach (input_channels, 1, 2, row, row+1, xopt, (AttachOptions) 0);
178 label = manage (left_aligned_label (_("Output Channels:")));
179 basic_packer.attach (*label, 0, 1, row, row+1, xopt, (AttachOptions) 0);
180 basic_packer.attach (output_channels, 1, 2, row, row+1, xopt, (AttachOptions) 0);
184 label = manage (left_aligned_label (_("Hardware input latency:")));
185 basic_packer.attach (*label, 0, 1, row, row+1, xopt, (AttachOptions) 0);
186 basic_packer.attach (input_latency, 1, 2, row, row+1, xopt, (AttachOptions) 0);
187 label = manage (left_aligned_label (_("samples")));
188 basic_packer.attach (*label, 2, 3, row, row+1, xopt, (AttachOptions) 0);
191 label = manage (left_aligned_label (_("Hardware output latency:")));
192 basic_packer.attach (*label, 0, 1, row, row+1, xopt, (AttachOptions) 0);
193 basic_packer.attach (output_latency, 1, 2, row, row+1, xopt, (AttachOptions) 0);
194 label = manage (left_aligned_label (_("samples")));
195 basic_packer.attach (*label, 2, 3, row, row+1, xopt, (AttachOptions) 0);
198 basic_hbox.pack_start (basic_packer, false, false);
199 basic_vbox.pack_start (basic_hbox, false, false);
201 Gtk::HBox* hpacker = manage (new HBox);
202 hpacker->set_border_width (12);
203 hpacker->pack_start (control_app_button, false, false);
205 control_app_button.show();
206 basic_vbox.pack_start (*hpacker);
208 midi_packer.set_border_width (12);
210 /* latency measurement tab */
212 lm_title.set_markup (string_compose ("<span size=\"large\" weight=\"bold\">%1</span>", _("Latency Measurement Tool")));
215 lm_table.set_row_spacings (12);
217 lm_table.attach (lm_title, 0, 2, row, row+1, xopt, (AttachOptions) 0);
220 lm_preamble.set_width_chars (60);
221 lm_preamble.set_line_wrap (true);
222 lm_preamble.set_markup (_("1. <span weight=\"bold\">Turn down the volume on your hardware to a very low level.</span>\n\n\
223 2. Connect the two channels that you select below using either a cable or (less ideally) a speaker \
225 3. Once the channels are connected, click the \"Measure latency\" button.\n\n\
226 4. When satisfied with the results, click the \"Use results\" button."));
228 lm_table.attach (lm_preamble, 0, 2, row, row+1, AttachOptions(FILL|EXPAND), (AttachOptions) 0);
231 label = manage (new Label (_("Output channel")));
232 lm_table.attach (*label, 0, 1, row, row+1, xopt, (AttachOptions) 0);
233 lm_table.attach (lm_output_channel_combo, 1, 2, row, row+1, xopt, (AttachOptions) 0);
236 label = manage (new Label (_("Input channel")));
237 lm_table.attach (*label, 0, 1, row, row+1, xopt, (AttachOptions) 0);
238 lm_table.attach (lm_input_channel_combo, 1, 2, row, row+1, xopt, (AttachOptions) 0);
241 xopt = AttachOptions(0);
243 lm_measure_button.signal_toggled().connect (sigc::mem_fun (*this, &EngineControl::latency_button_toggled));
244 lm_use_button.signal_clicked().connect (sigc::mem_fun (*this, &EngineControl::use_latency_button_clicked));
245 lm_use_button.set_sensitive (false);
247 lm_table.attach (lm_measure_button, 0, 2, row, row+1, xopt, (AttachOptions) 0);
249 lm_table.attach (lm_results, 0, 2, row, row+1, AttachOptions(FILL|EXPAND), (AttachOptions) 0);
251 lm_table.attach (lm_use_button, 0, 2, row, row+1, xopt, (AttachOptions) 0);
254 lm_results.set_markup ("<i>No measurement results yet</i>");
256 lm_vbox.pack_start (lm_table, false, false);
260 notebook.pages().push_back (TabElem (basic_vbox, _("Audio")));
261 notebook.pages().push_back (TabElem (midi_hbox, _("MIDI")));
262 notebook.pages().push_back (TabElem (lm_vbox, _("Latency")));
263 notebook.set_border_width (12);
265 notebook.set_tab_pos (POS_RIGHT);
266 notebook.show_all ();
268 notebook.set_name ("SettingsNotebook");
270 /* Connect to signals */
272 backend_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::backend_changed));
273 driver_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::driver_changed));
274 sample_rate_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::sample_rate_changed));
275 buffer_size_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::buffer_size_changed));
276 device_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::device_changed));
278 input_latency.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
279 output_latency.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
280 input_channels.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
281 output_channels.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
284 input_channels.signal_output().connect (sigc::bind (sigc::ptr_fun (&EngineControl::print_channel_count), &input_channels));
285 output_channels.signal_output().connect (sigc::bind (sigc::ptr_fun (&EngineControl::print_channel_count), &output_channels));
287 notebook.signal_switch_page().connect (sigc::mem_fun (*this, &EngineControl::on_switch_page));
290 EngineControl::~EngineControl ()
296 EngineControl::disable_latency_tab ()
298 vector<string> empty;
299 set_popdown_strings (lm_output_channel_combo, empty);
300 set_popdown_strings (lm_input_channel_combo, empty);
301 lm_measure_button.set_sensitive (false);
302 lm_use_button.set_sensitive (false);
306 EngineControl::enable_latency_tab ()
308 vector<string> outputs;
309 ARDOUR::AudioEngine::instance()->get_physical_outputs (ARDOUR::DataType::AUDIO, outputs);
310 set_popdown_strings (lm_output_channel_combo, outputs);
311 lm_output_channel_combo.set_active_text (outputs.front());
313 vector<string> inputs;
314 ARDOUR::AudioEngine::instance()->get_physical_inputs (ARDOUR::DataType::AUDIO, inputs);
315 set_popdown_strings (lm_input_channel_combo, inputs);
316 lm_input_channel_combo.set_active_text (inputs.front());
318 lm_measure_button.set_sensitive (true);
319 lm_use_button.set_sensitive (true);
323 EngineControl::backend_changed ()
325 if (ignore_changes) {
329 string backend_name = backend_combo.get_active_text();
330 boost::shared_ptr<ARDOUR::AudioBackend> backend;
332 if (!(backend = ARDOUR::AudioEngine::instance()->set_backend (backend_name, "ardour", ""))) {
333 /* eh? setting the backend failed... how ? */
337 if (backend->requires_driver_selection()) {
338 vector<string> drivers = backend->enumerate_drivers();
339 driver_combo.set_sensitive (true);
340 set_popdown_strings (driver_combo, drivers);
341 driver_combo.set_active_text (drivers.front());
344 driver_combo.set_sensitive (false);
348 maybe_display_saved_state ();
352 EngineControl::print_channel_count (Gtk::SpinButton* sb)
354 uint32_t cnt = (uint32_t) sb->get_value();
356 sb->set_text (_("all available channels"));
359 snprintf (buf, sizeof (buf), "%d", cnt);
366 EngineControl::list_devices ()
368 boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
371 /* now fill out devices, mark sample rates, buffer sizes insensitive */
373 vector<ARDOUR::AudioBackend::DeviceStatus> all_devices = backend->enumerate_devices ();
375 /* NOTE: Ardour currently does not display the "available" field of the
378 * Doing so would require a different GUI widget than the combo
379 * box/popdown that we currently use, since it has no way to list
380 * items that are not selectable. Something more like a popup menu,
381 * which could have unselectable items, would be appropriate.
384 vector<string> available_devices;
386 for (vector<ARDOUR::AudioBackend::DeviceStatus>::const_iterator i = all_devices.begin(); i != all_devices.end(); ++i) {
387 available_devices.push_back (i->name);
390 set_popdown_strings (device_combo, available_devices);
392 if (!available_devices.empty()) {
393 sample_rate_combo.set_sensitive (true);
394 buffer_size_combo.set_sensitive (true);
395 input_latency.set_sensitive (true);
396 output_latency.set_sensitive (true);
397 input_channels.set_sensitive (true);
398 output_channels.set_sensitive (true);
400 /* changing the text in the combo will trigger device_changed()
401 which should populate the parameter controls
404 device_combo.set_active_text (available_devices.front());
406 sample_rate_combo.set_sensitive (true);
407 buffer_size_combo.set_sensitive (true);
408 input_latency.set_sensitive (true);
409 output_latency.set_sensitive (true);
410 input_channels.set_sensitive (true);
411 output_channels.set_sensitive (true);
416 EngineControl::driver_changed ()
418 if (ignore_changes) {
422 boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
425 backend->set_driver (driver_combo.get_active_text());
428 maybe_display_saved_state ();
432 EngineControl::device_changed ()
434 if (ignore_changes) {
438 boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
440 string device_name = device_combo.get_active_text ();
443 /* don't allow programmatic change to sample_rate_combo to cause a
444 recursive call to this method.
453 vector<float> sr = backend->available_sample_rates (device_name);
454 for (vector<float>::const_iterator x = sr.begin(); x != sr.end(); ++x) {
456 if (fmod (*x, 1000.0f)) {
457 snprintf (buf, sizeof (buf), "%.1f kHz", (*x)/1000.0);
459 snprintf (buf, sizeof (buf), "%.0f kHz", (*x)/1000.0);
462 if (*x == _desired_sample_rate) {
467 set_popdown_strings (sample_rate_combo, s);
468 if (desired.empty()) {
469 sample_rate_combo.set_active_text (s.front());
471 sample_rate_combo.set_active_text (desired);
474 vector<uint32_t> bs = backend->available_buffer_sizes(device_name);
476 for (vector<uint32_t>::const_iterator x = bs.begin(); x != bs.end(); ++x) {
478 /* Translators: "samples" is always plural here, so no
479 need for plural+singular forms.
481 snprintf (buf, sizeof (buf), _("%u samples"), *x);
485 set_popdown_strings (buffer_size_combo, s);
486 buffer_size_combo.set_active_text (s.front());
487 show_buffer_duration ();
489 manage_control_app_sensitivity ();
493 /* pick up any saved state for this device */
495 maybe_display_saved_state ();
497 /* and push it to the backend */
499 push_state_to_backend (false);
503 EngineControl::sample_rate_changed ()
505 if (ignore_changes) {
509 /* reset the strings for buffer size to show the correct msec value
510 (reflecting the new sample rate).
513 show_buffer_duration ();
514 push_state_to_backend (false);
520 EngineControl::buffer_size_changed ()
522 if (ignore_changes) {
526 show_buffer_duration ();
527 push_state_to_backend (false);
532 EngineControl::show_buffer_duration ()
535 /* buffer sizes - convert from just samples to samples + msecs for
536 * the displayed string
539 string bs_text = buffer_size_combo.get_active_text ();
540 uint32_t samples = atoi (bs_text); /* will ignore trailing text */
541 uint32_t rate = get_rate();
543 /* Translators: "msecs" is ALWAYS plural here, so we do not
544 need singular form as well.
546 /* Developers: note the hard-coding of a double buffered model
547 in the (2 * samples) computation of latency. we always start
548 the audiobackend in this configuration.
551 snprintf (buf, sizeof (buf), _("(%.1f msecs)"), (2 * samples) / (rate/1000.0));
552 buffer_size_duration_label.set_text (buf);
556 EngineControl::parameter_changed ()
558 if (!ignore_changes) {
563 EngineControl::State*
564 EngineControl::get_matching_state (const string& backend,
565 const string& driver,
566 const string& device)
568 for (StateList::iterator i = states.begin(); i != states.end(); ++i) {
569 if ((*i).backend == backend &&
570 (*i).driver == driver &&
571 (*i).device == device) {
578 EngineControl::State*
579 EngineControl::get_saved_state_for_currently_displayed_backend_and_device ()
581 boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
584 return get_matching_state (backend_combo.get_active_text(),
585 (backend->requires_driver_selection() ? (std::string) driver_combo.get_active_text() : string()),
586 device_combo.get_active_text());
590 return get_matching_state (backend_combo.get_active_text(),
592 device_combo.get_active_text());
595 EngineControl::State*
596 EngineControl::save_state ()
598 bool existing = true;
599 State* state = get_saved_state_for_currently_displayed_backend_and_device ();
606 state->backend = backend_combo.get_active_text ();
607 state->driver = driver_combo.get_active_text ();
608 state->device = device_combo.get_active_text ();
609 state->buffer_size = buffer_size_combo.get_active_text ();
610 state->sample_rate = sample_rate_combo.get_active_text ();
611 state->input_latency = (uint32_t) input_latency.get_value();
612 state->output_latency = (uint32_t) output_latency.get_value();
613 state->input_channels = (uint32_t) input_channels.get_value();
614 state->output_channels = (uint32_t) output_channels.get_value();
617 states.push_back (*state);
624 EngineControl::maybe_display_saved_state ()
626 State* state = get_saved_state_for_currently_displayed_backend_and_device ();
630 if (!_desired_sample_rate) {
631 sample_rate_combo.set_active_text (state->sample_rate);
633 buffer_size_combo.set_active_text (state->buffer_size);
634 input_latency.set_value (state->input_latency);
635 output_latency.set_value (state->output_latency);
641 EngineControl::get_state ()
643 XMLNode* root = new XMLNode ("AudioMIDISetup");
646 if (!states.empty()) {
647 XMLNode* state_nodes = new XMLNode ("EngineStates");
649 for (StateList::const_iterator i = states.begin(); i != states.end(); ++i) {
651 XMLNode* node = new XMLNode ("State");
653 node->add_property ("backend", (*i).backend);
654 node->add_property ("driver", (*i).driver);
655 node->add_property ("device", (*i).device);
656 node->add_property ("sample-rate", (*i).sample_rate);
657 node->add_property ("buffer-size", (*i).buffer_size);
658 node->add_property ("input-latency", (*i).input_latency);
659 node->add_property ("output-latency", (*i).output_latency);
660 node->add_property ("input-channels", (*i).input_channels);
661 node->add_property ("output-channels", (*i).output_channels);
662 node->add_property ("active", (*i).active ? "yes" : "no");
664 state_nodes->add_child_nocopy (*node);
667 root->add_child_nocopy (*state_nodes);
674 EngineControl::set_state (const XMLNode& root)
676 XMLNodeList clist, cclist;
677 XMLNodeConstIterator citer, cciter;
680 XMLProperty* prop = NULL;
682 if (root.name() != "AudioMIDISetup") {
686 clist = root.children();
690 for (citer = clist.begin(); citer != clist.end(); ++citer) {
694 if (child->name() != "EngineStates") {
698 cclist = child->children();
700 for (cciter = cclist.begin(); cciter != cclist.end(); ++cciter) {
703 grandchild = *cciter;
705 if (grandchild->name() != "State") {
709 if ((prop = grandchild->property ("backend")) == 0) {
712 state.backend = prop->value ();
714 if ((prop = grandchild->property ("driver")) == 0) {
717 state.driver = prop->value ();
719 if ((prop = grandchild->property ("device")) == 0) {
722 state.device = prop->value ();
724 if ((prop = grandchild->property ("sample-rate")) == 0) {
727 state.sample_rate = prop->value ();
729 if ((prop = grandchild->property ("buffer-size")) == 0) {
732 state.buffer_size = prop->value ();
734 if ((prop = grandchild->property ("input-latency")) == 0) {
737 state.input_latency = atoi (prop->value ());
739 if ((prop = grandchild->property ("output-latency")) == 0) {
742 state.output_latency = atoi (prop->value ());
744 if ((prop = grandchild->property ("input-channels")) == 0) {
747 state.input_channels = atoi (prop->value ());
749 if ((prop = grandchild->property ("output-channels")) == 0) {
752 state.output_channels = atoi (prop->value ());
754 if ((prop = grandchild->property ("active")) == 0) {
757 state.active = string_is_affirmative (prop->value ());
759 states.push_back (state);
763 /* now see if there was an active state and switch the setup to it */
765 for (StateList::const_iterator i = states.begin(); i != states.end(); ++i) {
768 backend_combo.set_active_text ((*i).backend);
769 driver_combo.set_active_text ((*i).driver);
770 device_combo.set_active_text ((*i).device);
771 sample_rate_combo.set_active_text ((*i).sample_rate);
772 buffer_size_combo.set_active_text ((*i).buffer_size);
773 input_latency.set_value ((*i).input_latency);
774 output_latency.set_value ((*i).output_latency);
777 push_state_to_backend (false);
785 EngineControl::push_state_to_backend (bool start)
787 boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
793 /* grab the parameters from the GUI and apply them */
796 if (backend->requires_driver_selection()) {
797 if (backend->set_driver (get_driver())) {
802 if (backend->set_device_name (get_device_name())) {
806 if (backend->set_sample_rate (get_rate())) {
807 error << string_compose (_("Cannot set sample rate to %1"), get_rate()) << endmsg;
810 if (backend->set_buffer_size (get_buffer_size())) {
811 error << string_compose (_("Cannot set buffer size to %1"), get_buffer_size()) << endmsg;
814 if (backend->set_input_channels (get_input_channels())) {
815 error << string_compose (_("Cannot set input channels to %1"), get_input_channels()) << endmsg;
818 if (backend->set_output_channels (get_output_channels())) {
819 error << string_compose (_("Cannot set output channels to %1"), get_output_channels()) << endmsg;
822 if (backend->set_systemic_input_latency (get_input_latency())) {
823 error << string_compose (_("Cannot set input latency to %1"), get_input_latency()) << endmsg;
826 if (backend->set_systemic_output_latency (get_output_latency())) {
827 error << string_compose (_("Cannot set output latency to %1"), get_output_latency()) << endmsg;
831 /* get a pointer to the current state object, creating one if
835 State* state = get_saved_state_for_currently_displayed_backend_and_device ();
838 state = save_state ();
844 for (StateList::iterator i = states.begin(); i != states.end(); ++i) {
848 /* mark this one active (to be used next time the dialog is
852 state->active = true;
855 if (ARDOUR::AudioEngine::instance()->start()) {
860 manage_control_app_sensitivity ();
864 cerr << "exception thrown...\n";
870 EngineControl::get_rate () const
872 double r = atof (sample_rate_combo.get_active_text ());
873 /* the string may have been translated with an abbreviation for
874 * thousands, so use a crude heuristic to fix this.
883 EngineControl::get_buffer_size () const
885 string txt = buffer_size_combo.get_active_text ();
888 if (sscanf (txt.c_str(), "%d", &samples) != 1) {
896 EngineControl::get_input_channels() const
898 return (uint32_t) input_channels_adjustment.get_value();
902 EngineControl::get_output_channels() const
904 return (uint32_t) output_channels_adjustment.get_value();
908 EngineControl::get_input_latency() const
910 return (uint32_t) input_latency_adjustment.get_value();
914 EngineControl::get_output_latency() const
916 return (uint32_t) output_latency_adjustment.get_value();
920 EngineControl::get_driver () const
922 return driver_combo.get_active_text ();
926 EngineControl::get_device_name () const
928 return device_combo.get_active_text ();
932 EngineControl::control_app_button_clicked ()
934 boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
940 backend->launch_control_app ();
944 EngineControl::manage_control_app_sensitivity ()
946 boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
952 string appname = backend->control_app_name();
954 if (appname.empty()) {
955 control_app_button.set_sensitive (false);
957 control_app_button.set_sensitive (true);
962 EngineControl::set_desired_sample_rate (uint32_t sr)
964 _desired_sample_rate = sr;
969 EngineControl::on_switch_page (GtkNotebookPage*, guint page_num)
974 if (!ARDOUR::AudioEngine::instance()->running()) {
976 PBD::Unwinder<uint32_t> protect_ignore_changes (ignore_changes, ignore_changes + 1);
978 /* save any existing latency values */
980 uint32_t il = (uint32_t) input_latency.get_value ();
981 uint32_t ol = (uint32_t) input_latency.get_value ();
983 /* reset to zero so that our new test instance of JACK
984 will be clean of any existing latency measures.
987 input_latency.set_value (0);
988 output_latency.set_value (0);
990 push_state_to_backend (false);
994 input_latency.set_value (il);
995 output_latency.set_value (ol);
998 if (ARDOUR::AudioEngine::instance()->prepare_for_latency_measurement()) {
999 disable_latency_tab ();
1001 enable_latency_tab ();
1003 ARDOUR::AudioEngine::instance()->stop_latency_detection();
1007 /* latency measurement */
1010 EngineControl::check_latency_measurement ()
1012 MTDM* mtdm = ARDOUR::AudioEngine::instance()->mtdm ();
1013 static uint32_t cnt = 0;
1015 if (mtdm->resolve () < 0) {
1016 string txt = _("No signal detected ");
1017 uint32_t dots = cnt++%10;
1018 for (uint32_t i = 0; i < dots; ++i) {
1021 lm_results.set_text (txt);
1025 if (mtdm->err () > 0.3) {
1031 ARDOUR::framecnt_t const sample_rate = ARDOUR::AudioEngine::instance()->sample_rate();
1033 if (sample_rate == 0) {
1034 lm_results.set_text (_("Disconnected from audio engine"));
1035 ARDOUR::AudioEngine::instance()->stop_latency_detection ();
1039 uint32_t frames_total = mtdm->del();
1040 cerr << "total = " << frames_total << " delay = " << ARDOUR::AudioEngine::instance()->latency_signal_delay() << endl;
1041 uint32_t extra = frames_total - ARDOUR::AudioEngine::instance()->latency_signal_delay();
1043 snprintf (buf, sizeof (buf), "%u samples %10.3lf ms", extra, extra * 1000.0f/sample_rate);
1047 if (mtdm->err () > 0.2) {
1048 strcat (buf, " ??");
1053 strcat (buf, " (Inv)");
1058 lm_measure_button.set_active (false);
1059 lm_use_button.set_sensitive (true);
1060 strcat (buf, " (set)");
1063 lm_results.set_text (buf);
1069 EngineControl::latency_button_toggled ()
1071 if (lm_measure_button.get_active ()) {
1073 ARDOUR::AudioEngine::instance()->set_latency_input_port (lm_input_channel_combo.get_active_text());
1074 ARDOUR::AudioEngine::instance()->set_latency_output_port (lm_output_channel_combo.get_active_text());
1075 ARDOUR::AudioEngine::instance()->start_latency_detection ();
1076 lm_results.set_text (_("Detecting ..."));
1077 latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &EngineControl::check_latency_measurement), 250);
1080 ARDOUR::AudioEngine::instance()->stop_latency_detection ();
1081 latency_timeout.disconnect ();
1086 EngineControl::use_latency_button_clicked ()
1088 MTDM* mtdm = ARDOUR::AudioEngine::instance()->mtdm ();
1094 uint32_t frames_total = mtdm->del();
1095 uint32_t extra = frames_total - ARDOUR::AudioEngine::instance()->latency_signal_delay();
1096 uint32_t one_way = extra/2;
1098 input_latency_adjustment.set_value (one_way);
1099 output_latency_adjustment.set_value (one_way);