From d66b70f3a2edc7f294fb0b1c0adb4a6318ef658a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 2 Jun 2023 21:44:36 +0200 Subject: [PATCH] Distinct engine-states per sample-rate Previously only the one engine-state per device was saved. However systemic latency depends on the sample-rate (and buffersize) --- gtk2_ardour/engine_dialog.cc | 48 +++++++++++++++++++++++++----------- gtk2_ardour/engine_dialog.h | 11 ++++++--- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/gtk2_ardour/engine_dialog.cc b/gtk2_ardour/engine_dialog.cc index 45af3c5d4f..6871e1e3f2 100644 --- a/gtk2_ardour/engine_dialog.cc +++ b/gtk2_ardour/engine_dialog.cc @@ -1778,12 +1778,20 @@ EngineControl::State EngineControl::get_matching_state ( const string& backend, const string& driver, - const string& device) + const string& device, + const float sample_rate) { - for (StateList::iterator i = states.begin (); i != states.end (); ++i) { - if ((*i)->backend == backend && - (!_have_control || ((*i)->driver == driver && (*i)->device == device))) { - return (*i); + for (auto const& i : states) { + if (i->backend != backend) { + continue; + } + if (!_have_control) { + return i; + } + if (i->driver == driver && i->device == device) { + if (sample_rate == 0 || i->sample_rate == sample_rate) { + return i; + } } } return State (); @@ -1794,12 +1802,20 @@ EngineControl::get_matching_state ( const string& backend, const string& driver, const string& input_device, - const string& output_device) + const string& output_device, + const float sample_rate) { - for (StateList::iterator i = states.begin (); i != states.end (); ++i) { - if ((*i)->backend == backend && - (!_have_control || ((*i)->driver == driver && ((*i)->input_device == input_device) && (*i)->output_device == output_device))) { - return (*i); + for (auto const& i : states) { + if (i->backend != backend) { + continue; + } + if (!_have_control) { + return i; + } + if (i->driver == driver && i->input_device == input_device && i->output_device == output_device) { + if (sample_rate == 0 || i->sample_rate == sample_rate) { + return i; + } } } return State (); @@ -1815,17 +1831,20 @@ EngineControl::get_saved_state_for_currently_displayed_backend_and_device () return get_matching_state (backend_combo.get_active_text (), (backend->requires_driver_selection () ? (std::string)driver_combo.get_active_text () : string ()), input_device_combo.get_active_text (), - output_device_combo.get_active_text ()); + output_device_combo.get_active_text (), + get_rate ()); } else { return get_matching_state (backend_combo.get_active_text (), (backend->requires_driver_selection () ? (std::string)driver_combo.get_active_text () : string ()), - device_combo.get_active_text ()); + device_combo.get_active_text (), + get_rate ()); } } return get_matching_state (backend_combo.get_active_text (), string (), - device_combo.get_active_text ()); + device_combo.get_active_text (), + get_rate ()); } bool @@ -1836,7 +1855,8 @@ EngineControl::equivalent_states (const EngineControl::State& state1, state1->driver == state2->driver && state1->device == state2->device && state1->input_device == state2->input_device && - state1->output_device == state2->output_device) { + state1->output_device == state2->output_device && + state1->sample_rate == state2->sample_rate) { return true; } return false; diff --git a/gtk2_ardour/engine_dialog.h b/gtk2_ardour/engine_dialog.h index 86c7e55474..b8ba0a2c4a 100644 --- a/gtk2_ardour/engine_dialog.h +++ b/gtk2_ardour/engine_dialog.h @@ -271,6 +271,7 @@ private: StateStruct () : sample_rate (48000) , buffer_size (1024) + , n_periods (0) , input_latency (0) , output_latency (0) , active (false) @@ -281,8 +282,8 @@ private: }; typedef std::shared_ptr State; - typedef std::list StateList; - static bool state_sort_cmp (const State& a, const State& b); + typedef std::list StateList; + static bool state_sort_cmp (const State& a, const State& b); StateList states; @@ -290,11 +291,13 @@ private: State get_matching_state (const std::string& backend, const std::string& driver, - const std::string& device); + const std::string& device, + const float sample_rate = 0); State get_matching_state (const std::string& backend, const std::string& driver, const std::string& input_device, - const std::string& output_device); + const std::string& output_device, + const float sample_rate = 0); State get_saved_state_for_currently_displayed_backend_and_device (); void maybe_display_saved_state ();