13
0

lots of changes to auto-start (and stop) the backend for latency measurements, and continuing work on the session construction/engine configuration flow

This commit is contained in:
Paul Davis 2013-09-12 16:28:51 -04:00
parent 9af75b2ac9
commit 7c88670680
6 changed files with 164 additions and 53 deletions

View File

@ -384,25 +384,8 @@ ARDOUR_UI::create_global_port_matrix (ARDOUR::DataType type)
void void
ARDOUR_UI::attach_to_engine () ARDOUR_UI::attach_to_engine ()
{ {
AudioEngine::instance()->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
AudioEngine::instance()->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this), gui_context()); AudioEngine::instance()->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this), gui_context());
AudioEngine::instance()->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
AudioEngine::instance()->Halted.connect_same_thread (halt_connection, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports); ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports);
/* if there is only one audio/midi backend, and it does not require setup, get our use of it underway
* right here (we need to know the client name and potential session ID
* to do this, which is why this is here, rather than in, say,
* ARDOUR::init().
*/
if (!AudioEngine::instance()->setup_required()) {
const AudioBackendInfo* backend = AudioEngine::instance()->available_backends().front();
AudioEngine::instance()->set_backend (backend->name, ARDOUR_COMMAND_LINE::backend_client_name, ARDOUR_COMMAND_LINE::backend_session_uuid);
AudioEngine::instance()->start ();
}
} }
void void
@ -524,6 +507,12 @@ ARDOUR_UI::post_engine ()
*/ */
ARDOUR::init_post_engine (); ARDOUR::init_post_engine ();
/* connect to important signals */
AudioEngine::instance()->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
AudioEngine::instance()->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
AudioEngine::instance()->Halted.connect_same_thread (halt_connection, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
_tooltips.enable(); _tooltips.enable();
@ -4161,6 +4150,8 @@ ARDOUR_UI::launch_audio_midi_setup ()
int int
ARDOUR_UI::do_audio_midi_setup (uint32_t desired_sample_rate) ARDOUR_UI::do_audio_midi_setup (uint32_t desired_sample_rate)
{ {
cerr << "DO-AMS\n";
launch_audio_midi_setup (); launch_audio_midi_setup ();
_audio_midi_setup->set_desired_sample_rate (desired_sample_rate); _audio_midi_setup->set_desired_sample_rate (desired_sample_rate);

View File

@ -29,6 +29,7 @@
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/xml++.h" #include "pbd/xml++.h"
#include "pbd/unwind.h"
#include <gtkmm/stock.h> #include <gtkmm/stock.h>
#include <gtkmm/notebook.h> #include <gtkmm/notebook.h>
@ -95,15 +96,6 @@ EngineControl::EngineControl ()
if (audio_setup) { if (audio_setup) {
set_state (*audio_setup); set_state (*audio_setup);
} }
ARDOUR::AudioEngine::instance()->Stopped.connect (*this, MISSING_INVALIDATOR, boost::bind (&EngineControl::disable_latency_tab, this), gui_context());
if (!ARDOUR::AudioEngine::instance()->connected()) {
ARDOUR::AudioEngine::instance()->Running.connect (*this, MISSING_INVALIDATOR, boost::bind (&EngineControl::enable_latency_tab, this), gui_context());
disable_latency_tab ();
} else {
enable_latency_tab ();
}
} }
void void
@ -281,9 +273,18 @@ and microphone.\n\n\
driver_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::driver_changed)); driver_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::driver_changed));
sample_rate_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::sample_rate_changed)); sample_rate_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::sample_rate_changed));
buffer_size_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::buffer_size_changed)); buffer_size_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::buffer_size_changed));
device_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::device_changed));
input_latency.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
output_latency.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
input_channels.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
output_channels.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::parameter_changed));
input_channels.signal_output().connect (sigc::bind (sigc::ptr_fun (&EngineControl::print_channel_count), &input_channels)); input_channels.signal_output().connect (sigc::bind (sigc::ptr_fun (&EngineControl::print_channel_count), &input_channels));
output_channels.signal_output().connect (sigc::bind (sigc::ptr_fun (&EngineControl::print_channel_count), &output_channels)); output_channels.signal_output().connect (sigc::bind (sigc::ptr_fun (&EngineControl::print_channel_count), &output_channels));
device_combo.signal_changed().connect (sigc::mem_fun (*this, &EngineControl::device_changed));
notebook.signal_switch_page().connect (sigc::mem_fun (*this, &EngineControl::on_switch_page));
} }
EngineControl::~EngineControl () EngineControl::~EngineControl ()
@ -297,6 +298,8 @@ EngineControl::disable_latency_tab ()
vector<string> empty; vector<string> empty;
set_popdown_strings (lm_output_channel_combo, empty); set_popdown_strings (lm_output_channel_combo, empty);
set_popdown_strings (lm_input_channel_combo, empty); set_popdown_strings (lm_input_channel_combo, empty);
lm_measure_button.set_sensitive (false);
lm_use_button.set_sensitive (false);
} }
void void
@ -311,6 +314,9 @@ EngineControl::enable_latency_tab ()
ARDOUR::AudioEngine::instance()->get_physical_inputs (ARDOUR::DataType::AUDIO, inputs); ARDOUR::AudioEngine::instance()->get_physical_inputs (ARDOUR::DataType::AUDIO, inputs);
set_popdown_strings (lm_input_channel_combo, inputs); set_popdown_strings (lm_input_channel_combo, inputs);
lm_input_channel_combo.set_active_text (inputs.front()); lm_input_channel_combo.set_active_text (inputs.front());
lm_measure_button.set_sensitive (true);
lm_use_button.set_sensitive (true);
} }
void void
@ -384,10 +390,26 @@ EngineControl::list_devices ()
set_popdown_strings (device_combo, available_devices); set_popdown_strings (device_combo, available_devices);
if (!available_devices.empty()) { if (!available_devices.empty()) {
sample_rate_combo.set_sensitive (true);
buffer_size_combo.set_sensitive (true);
input_latency.set_sensitive (true);
output_latency.set_sensitive (true);
input_channels.set_sensitive (true);
output_channels.set_sensitive (true);
/* changing the text in the combo will trigger device_changed()
which should populate the parameter controls
*/
device_combo.set_active_text (available_devices.front()); device_combo.set_active_text (available_devices.front());
} else {
sample_rate_combo.set_sensitive (true);
buffer_size_combo.set_sensitive (true);
input_latency.set_sensitive (true);
output_latency.set_sensitive (true);
input_channels.set_sensitive (true);
output_channels.set_sensitive (true);
} }
device_changed ();
} }
void void
@ -468,7 +490,13 @@ EngineControl::device_changed ()
ignore_changes--; ignore_changes--;
/* pick up any saved state for this device */
maybe_display_saved_state (); maybe_display_saved_state ();
/* and push it to the backend */
push_state_to_backend (false);
} }
void void
@ -483,6 +511,7 @@ EngineControl::sample_rate_changed ()
*/ */
show_buffer_duration (); show_buffer_duration ();
push_state_to_backend (false);
save_state (); save_state ();
} }
@ -495,6 +524,7 @@ EngineControl::buffer_size_changed ()
} }
show_buffer_duration (); show_buffer_duration ();
push_state_to_backend (false);
save_state (); save_state ();
} }
@ -522,6 +552,14 @@ EngineControl::show_buffer_duration ()
buffer_size_duration_label.set_text (buf); buffer_size_duration_label.set_text (buf);
} }
void
EngineControl::parameter_changed ()
{
if (!ignore_changes) {
save_state ();
}
}
EngineControl::State* EngineControl::State*
EngineControl::get_matching_state (const string& backend, EngineControl::get_matching_state (const string& backend,
const string& driver, const string& driver,
@ -927,23 +965,47 @@ EngineControl::set_desired_sample_rate (uint32_t sr)
device_changed (); device_changed ();
} }
/* latency measurement */
void void
EngineControl::update_latency_display () EngineControl::on_switch_page (GtkNotebookPage*, guint page_num)
{ {
ARDOUR::framecnt_t const sample_rate = ARDOUR::AudioEngine::instance()->sample_rate(); if (page_num == 2) {
if (sample_rate == 0) { /* latency tab */
lm_results.set_text (_("Disconnected from audio engine"));
} else { if (!ARDOUR::AudioEngine::instance()->running()) {
char buf[64];
//snprintf (buf, sizeof (buf), "%10.3lf frames %10.3lf ms", PBD::Unwinder<uint32_t> protect_ignore_changes (ignore_changes, ignore_changes + 1);
//(float)_pi->latency(), (float)_pi->latency() * 1000.0f/sample_rate);
strcpy (buf, "got something"); /* save any existing latency values */
lm_results.set_text(buf);
} uint32_t il = (uint32_t) input_latency.get_value ();
uint32_t ol = (uint32_t) input_latency.get_value ();
/* reset to zero so that our new test instance of JACK
will be clean of any existing latency measures.
*/
input_latency.set_value (0);
output_latency.set_value (0);
push_state_to_backend (false);
/* reset control */
input_latency.set_value (il);
output_latency.set_value (ol);
}
if (ARDOUR::AudioEngine::instance()->prepare_for_latency_measurement()) {
disable_latency_tab ();
}
enable_latency_tab ();
} else {
ARDOUR::AudioEngine::instance()->stop_latency_detection();
}
} }
/* latency measurement */
bool bool
EngineControl::check_latency_measurement () EngineControl::check_latency_measurement ()
{ {
@ -975,6 +1037,7 @@ EngineControl::check_latency_measurement ()
} }
uint32_t frames_total = mtdm->del(); uint32_t frames_total = mtdm->del();
cerr << "total = " << frames_total << " delay = " << ARDOUR::AudioEngine::instance()->latency_signal_delay() << endl;
uint32_t extra = frames_total - ARDOUR::AudioEngine::instance()->latency_signal_delay(); uint32_t extra = frames_total - ARDOUR::AudioEngine::instance()->latency_signal_delay();
snprintf (buf, sizeof (buf), "%u samples %10.3lf ms", extra, extra * 1000.0f/sample_rate); snprintf (buf, sizeof (buf), "%u samples %10.3lf ms", extra, extra * 1000.0f/sample_rate);
@ -992,7 +1055,6 @@ EngineControl::check_latency_measurement ()
} }
if (solid) { if (solid) {
// _pi->set_measured_latency (rint (mtdm->del()));
lm_measure_button.set_active (false); lm_measure_button.set_active (false);
lm_use_button.set_sensitive (true); lm_use_button.set_sensitive (true);
strcat (buf, " (set)"); strcat (buf, " (set)");
@ -1010,7 +1072,6 @@ EngineControl::latency_button_toggled ()
ARDOUR::AudioEngine::instance()->set_latency_input_port (lm_input_channel_combo.get_active_text()); ARDOUR::AudioEngine::instance()->set_latency_input_port (lm_input_channel_combo.get_active_text());
ARDOUR::AudioEngine::instance()->set_latency_output_port (lm_output_channel_combo.get_active_text()); ARDOUR::AudioEngine::instance()->set_latency_output_port (lm_output_channel_combo.get_active_text());
cerr << "latency detection on " << lm_input_channel_combo.get_active_text() << " => " << lm_output_channel_combo.get_active_text() << endl;
ARDOUR::AudioEngine::instance()->start_latency_detection (); ARDOUR::AudioEngine::instance()->start_latency_detection ();
lm_results.set_text (_("Detecting ...")); lm_results.set_text (_("Detecting ..."));
latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &EngineControl::check_latency_measurement), 250); latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &EngineControl::check_latency_measurement), 250);
@ -1018,7 +1079,6 @@ EngineControl::latency_button_toggled ()
} else { } else {
ARDOUR::AudioEngine::instance()->stop_latency_detection (); ARDOUR::AudioEngine::instance()->stop_latency_detection ();
latency_timeout.disconnect (); latency_timeout.disconnect ();
update_latency_display ();
} }
} }

View File

@ -118,6 +118,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
void backend_changed (); void backend_changed ();
void sample_rate_changed (); void sample_rate_changed ();
void buffer_size_changed (); void buffer_size_changed ();
void parameter_changed ();
uint32_t get_rate() const; uint32_t get_rate() const;
uint32_t get_buffer_size() const; uint32_t get_buffer_size() const;
@ -172,10 +173,11 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
/* latency measurement */ /* latency measurement */
void latency_button_toggled (); void latency_button_toggled ();
bool check_latency_measurement (); bool check_latency_measurement ();
void update_latency_display ();
sigc::connection latency_timeout; sigc::connection latency_timeout;
void enable_latency_tab (); void enable_latency_tab ();
void disable_latency_tab (); void disable_latency_tab ();
void on_switch_page (GtkNotebookPage*, guint page_num);
}; };
#endif /* __gtk2_ardour_engine_dialog_h__ */ #endif /* __gtk2_ardour_engine_dialog_h__ */

View File

@ -188,6 +188,7 @@ public:
/* latency measurement */ /* latency measurement */
MTDM* mtdm(); MTDM* mtdm();
int prepare_for_latency_measurement ();
void start_latency_detection (); void start_latency_detection ();
void stop_latency_detection (); void stop_latency_detection ();
void set_latency_input_port (const std::string&); void set_latency_input_port (const std::string&);
@ -225,6 +226,7 @@ public:
std::string _latency_input_name; std::string _latency_input_name;
std::string _latency_output_name; std::string _latency_output_name;
framecnt_t _latency_signal_latency; framecnt_t _latency_signal_latency;
bool _started_for_latency;
void meter_thread (); void meter_thread ();
void start_metering_thread (); void start_metering_thread ();

View File

@ -80,6 +80,7 @@ AudioEngine::AudioEngine ()
, _latency_output_port (0) , _latency_output_port (0)
, _latency_flush_frames (0) , _latency_flush_frames (0)
, _latency_signal_latency (0) , _latency_signal_latency (0)
, _started_for_latency (false)
{ {
g_atomic_int_set (&m_meter_exit, 0); g_atomic_int_set (&m_meter_exit, 0);
discover_backends (); discover_backends ();
@ -202,6 +203,13 @@ AudioEngine::process_callback (pframes_t nframes)
bool return_after_remove_check = false; bool return_after_remove_check = false;
if (_measuring_latency && _mtdm) { if (_measuring_latency && _mtdm) {
/* run a normal cycle from the perspective of the PortManager
so that we get silence on all registered ports.
we overwrite the silence on the two ports used for latency
measurement.
*/
PortManager::cycle_start (nframes); PortManager::cycle_start (nframes);
PortManager::silence (nframes); PortManager::silence (nframes);
@ -609,7 +617,9 @@ AudioEngine::start ()
start_metering_thread (); start_metering_thread ();
Running(); /* EMIT SIGNAL */ if (!_started_for_latency) {
Running(); /* EMIT SIGNAL */
}
return 0; return 0;
} }
@ -632,6 +642,7 @@ AudioEngine::stop ()
_measuring_latency = false; _measuring_latency = false;
_latency_output_port = 0; _latency_output_port = 0;
_latency_input_port = 0; _latency_input_port = 0;
_started_for_latency = false;
stop_metering_thread (); stop_metering_thread ();
Port::PortDrop (); Port::PortDrop ();
@ -982,6 +993,13 @@ AudioEngine::halted_callback (const char* why)
bool bool
AudioEngine::setup_required () const AudioEngine::setup_required () const
{ {
/* If there is only a single backend and it claims to be configured
* already there is no setup to be done.
*
* Primarily for a case where there is only a JACK backend and
* JACK is already running.
*/
if (_backends.size() == 1 && _backends.begin()->second->already_configured()) { if (_backends.size() == 1 && _backends.begin()->second->already_configured()) {
return false; return false;
} }
@ -995,9 +1013,28 @@ AudioEngine::mtdm()
return _mtdm; return _mtdm;
} }
int
AudioEngine::prepare_for_latency_measurement ()
{
if (!running()) {
_started_for_latency = true;
if (start()) {
_started_for_latency = false;
return -1;
}
}
return 0;
}
void void
AudioEngine::start_latency_detection () AudioEngine::start_latency_detection ()
{ {
if (prepare_for_latency_measurement ()) {
return;
}
PortEngine& pe (port_engine()); PortEngine& pe (port_engine());
delete _mtdm; delete _mtdm;
@ -1026,26 +1063,32 @@ AudioEngine::start_latency_detection ()
_latency_signal_latency = 0; _latency_signal_latency = 0;
lr = pe.get_latency_range (_latency_input_port, false); lr = pe.get_latency_range (_latency_input_port, false);
_latency_signal_latency = lr.max; _latency_signal_latency = lr.max;
cerr << "Input port lm = " << lr.max;
lr = pe.get_latency_range (_latency_output_port, true); lr = pe.get_latency_range (_latency_output_port, true);
_latency_signal_latency += lr.max; _latency_signal_latency += lr.max;
cerr << " output port lm = " << lr.max << endl;
cerr << "latency signal pathway = " << _latency_signal_latency << endl;
/* all created and connected, lets go */ /* all created and connected, lets go */
_mtdm = new MTDM (sample_rate()); _mtdm = new MTDM (sample_rate());
_measuring_latency = true; _measuring_latency = true;
_latency_flush_frames = samples_per_cycle(); _latency_flush_frames = samples_per_cycle();
} }
void void
AudioEngine::stop_latency_detection () AudioEngine::stop_latency_detection ()
{ {
cerr << "Stop LD\n";
_measuring_latency = false;
port_engine().unregister_port (_latency_output_port); port_engine().unregister_port (_latency_output_port);
port_engine().unregister_port (_latency_input_port); port_engine().unregister_port (_latency_input_port);
_measuring_latency = false;
if (_started_for_latency) {
stop ();
}
} }
void void

View File

@ -289,13 +289,26 @@ Session::Session (AudioEngine &eng,
/* we need the audioengine to be up and usable to make much more /* we need the audioengine to be up and usable to make much more
* progress with construction, so lets get that started if it isn't already. * progress with construction, so lets get that started if it isn't already.
*/ */
if (_engine.current_backend() == 0 || _engine.setup_required()) { if (_engine.current_backend() == 0) {
/* backend is unknown ... */
boost::optional<int> r = AudioEngineSetupRequired (sr); boost::optional<int> r = AudioEngineSetupRequired (sr);
if (r.get_value_or (-1) != 0) { if (r.get_value_or (-1) != 0) {
destroy (); destroy ();
throw failed_constructor(); throw failed_constructor();
} }
} else if (_engine.setup_required()) {
/* backend is known, but setup is needed */
boost::optional<int> r = AudioEngineSetupRequired (sr);
if (r.get_value_or (-1) != 0) {
destroy ();
throw failed_constructor();
}
} else if (!_engine.running()) {
if (_engine.start()) {
destroy ();
throw failed_constructor ();
}
} }
/* at this point the engine should be connected (i.e. interacting /* at this point the engine should be connected (i.e. interacting