Reimplementation of SourceInputCallbacks into Session

Session should be the object holding the list of inputs parameters (e.g. synchrony) and the list of source callbacks. This also avoids mixing input when copying sources.  Code could be improved but is operational.
This commit is contained in:
Bruno Herbelin
2022-03-07 00:23:24 +01:00
parent 83e77681d9
commit 39b61fe331
18 changed files with 689 additions and 478 deletions

View File

@@ -149,6 +149,9 @@ void SessionCreator::load(const std::string& filename)
// load playlists
loadPlayGroups( xmlDoc_.FirstChildElement("PlayGroups") );
// load input callbacks
loadInputCallbacks( xmlDoc_.FirstChildElement("InputCallbacks") );
// thumbnail
const XMLElement *thumbnailelement = sessionNode->FirstChildElement("Thumbnail");
// if there is a user-defined thumbnail, get it
@@ -193,6 +196,62 @@ void SessionCreator::loadSnapshots(XMLElement *snapshotsNode)
}
}
void SessionCreator::loadInputCallbacks(tinyxml2::XMLElement *inputsNode)
{
if (inputsNode != nullptr && session_ != nullptr) {
// read all 'Callback' nodes
xmlCurrent_ = inputsNode->FirstChildElement("Callback");
for ( ; xmlCurrent_ ; xmlCurrent_ = xmlCurrent_->NextSiblingElement()) {
// what key triggers the callback ?
uint input = 0;
xmlCurrent_->QueryUnsignedAttribute("input", &input);
if (input > 0) {
// what id is the source ?
uint64_t id = 0;
xmlCurrent_->QueryUnsigned64Attribute("id", &id);
if (id > 0) {
// what type is the callback ?
uint type = 0;
xmlCurrent_->QueryUnsignedAttribute("type", &type);
// instanciate the callback of that type
SourceCallback *loadedcallback = SourceCallback::create((SourceCallback::CallbackType)type);
// successfully created a callback of saved type
if (loadedcallback) {
// apply specific parameters
loadedcallback->accept(*this);
// find the source with the given id
SourceList::iterator sit = session_->find(id);
if (sit != session_->end()) {
// assign to source in session
session_->assignSourceCallback(input, *sit, loadedcallback);
}
}
}
}
}
// read array of synchronyzation mode for all inputs (CSV)
xmlCurrent_ = inputsNode->FirstChildElement("Synchrony");
if (xmlCurrent_) {
const char *text = xmlCurrent_->GetText();
if (text) {
std::istringstream iss(text);
std::string token;
uint i = 0;
while(std::getline(iss, token, ';')) {
if (token.compare("1") == 0)
session_->setInputSynchrony(i, Metronome::SYNC_BEAT);
else if (token.compare("2") == 0)
session_->setInputSynchrony(i, Metronome::SYNC_PHASE);
++i;
}
}
}
}
}
void SessionCreator::loadNotes(XMLElement *notesNode)
{
if (notesNode != nullptr && session_ != nullptr) {
@@ -900,30 +959,6 @@ void SessionLoader::visit (Source& s)
groups_sources_id_.push_back(idlist);
}
XMLElement* callbacksNode = sourceNode->FirstChildElement("Callbacks");
if (callbacksNode) {
// Loop over 'Callback' nodes
xmlCurrent_ = callbacksNode->FirstChildElement("Callback");
for ( ; xmlCurrent_ ; xmlCurrent_ = xmlCurrent_->NextSiblingElement()) {
// what key triggers the callback ?
uint input = 0;
xmlCurrent_->QueryUnsignedAttribute("input", &input);
// what type is the callback ?
uint type = 0;
xmlCurrent_->QueryUnsignedAttribute("type", &type);
// instanciate the callback of that type
SourceCallback *loadedcallback = SourceCallback::create((SourceCallback::CallbackType)type);
// successfully created a callback of saved type
if (loadedcallback) {
// apply specific parameters
loadedcallback->accept(*this);
// add callback to source
s.addInputCallback(input, loadedcallback);
}
}
}
// restore current
xmlCurrent_ = sourceNode;
}