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);
}
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 ()
{
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);
states.push_back (state);
+ states.sort (state_sort_cmp);
+
return state;
}
state->output_channels = get_output_channels ();
state->midi_option = get_midi_option ();
state->midi_devices = _midi_devices;
+ state->lru = time (NULL) ;
}
void
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<MidiDeviceSettings>::const_iterator p = (*i)->midi_devices.begin(); p != (*i)->midi_devices.end(); ++p) {
}
}
+ 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
}
}
+ states.sort (state_sort_cmp);
+
for (StateList::const_iterator i = states.begin(); i != states.end(); ++i) {
if ((*i)->active) {
store_state(state);
}
+ states.sort (state_sort_cmp);
+
/* all off */
for (StateList::iterator i = states.begin(); i != states.end(); ++i) {