diff --git a/gtk2_ardour/engine_dialog.cc b/gtk2_ardour/engine_dialog.cc index d8f35b211a..381a15b5ac 100644 --- a/gtk2_ardour/engine_dialog.cc +++ b/gtk2_ardour/engine_dialog.cc @@ -1630,8 +1630,6 @@ EngineControl::State EngineControl::get_matching_state (const string& backend) { for (StateList::iterator i = states.begin(); i != states.end(); ++i) { - // TODO use LRU for every backend and prefer the active one - // uniqueness is only guaranteed for backend + driver + device(s) if ((*i)->backend == backend) { return (*i); } @@ -1708,6 +1706,19 @@ bool EngineControl::equivalent_states (const EngineControl::State& state1, return false; } +bool +EngineControl::state_sort_cmp (const State &a, const State &b) { + if (a->active) { + return true; + } + else if (b->active) { + return false; + } + else { + return a->lru < b->lru; + } +} + EngineControl::State EngineControl::save_state () { @@ -1716,6 +1727,7 @@ EngineControl::save_state () if (!_have_control) { state = get_matching_state (backend_combo.get_active_text(), string(), string()); if (state) { + state->lru = time (NULL) ; return state; } state.reset(new StateStruct); @@ -1735,6 +1747,8 @@ EngineControl::save_state () states.push_back (state); + states.sort (state_sort_cmp); + return state; } @@ -1754,6 +1768,7 @@ EngineControl::store_state (State state) state->output_channels = get_output_channels (); state->midi_option = get_midi_option (); state->midi_devices = _midi_devices; + state->lru = time (NULL) ; } void @@ -1817,6 +1832,7 @@ EngineControl::get_state () node->add_property ("output-channels", (*i)->output_channels); node->add_property ("active", (*i)->active ? "yes" : "no"); node->add_property ("midi-option", (*i)->midi_option); + node->add_property ("lru", (*i)->active ? time (NULL) : (*i)->lru); XMLNode* midi_devices = new XMLNode ("MIDIDevices"); for (std::vector::const_iterator p = (*i)->midi_devices.begin(); p != (*i)->midi_devices.end(); ++p) { @@ -1980,6 +1996,10 @@ EngineControl::set_state (const XMLNode& root) } } + if ((prop = grandchild->property ("lru"))) { + state->lru = atoi (prop->value ()); + } + #if 1 /* remove accumulated duplicates (due to bug in ealier version) * this can be removed again before release @@ -2016,6 +2036,8 @@ EngineControl::set_state (const XMLNode& root) } } + states.sort (state_sort_cmp); + for (StateList::const_iterator i = states.begin(); i != states.end(); ++i) { if ((*i)->active) { @@ -2414,6 +2436,8 @@ EngineControl::post_push () store_state(state); } + states.sort (state_sort_cmp); + /* all off */ for (StateList::iterator i = states.begin(); i != states.end(); ++i) { diff --git a/gtk2_ardour/engine_dialog.h b/gtk2_ardour/engine_dialog.h index ae2128b19b..bfb094deea 100644 --- a/gtk2_ardour/engine_dialog.h +++ b/gtk2_ardour/engine_dialog.h @@ -217,6 +217,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList { bool active; std::string midi_option; std::vector midi_devices; + time_t lru; StateStruct() : sample_rate (48000) @@ -225,12 +226,14 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList { , output_latency (0) , input_channels (0) , output_channels (0) - , active (false) {} + , active (false) + , lru (0) {} }; typedef boost::shared_ptr State; typedef std::list StateList; + static bool state_sort_cmp (const State &a, const State &b); StateList states;