BugFix: copy-paste a selection containing a source and its clone: fixed

that the clone is created (after the source).
This commit is contained in:
brunoherbelin
2021-02-05 18:16:13 +01:00
parent 8185c93457
commit 34380e8592
3 changed files with 27 additions and 5 deletions

View File

@@ -1143,7 +1143,13 @@ void Mixer::paste(const std::string& clipboard)
XMLElement* sourceNode = root->FirstChildElement("Source"); XMLElement* sourceNode = root->FirstChildElement("Source");
for( ; sourceNode ; sourceNode = sourceNode->NextSiblingElement()) for( ; sourceNode ; sourceNode = sourceNode->NextSiblingElement())
{ {
addSource(loader.createSource(sourceNode)); Source *s = loader.createSource(sourceNode);
if (s) {
// Add source to Session
session_->addSource(s);
// Add source to Mixer
addSource(s);
}
} }
} }

View File

@@ -156,9 +156,21 @@ std::string Selection::xml()
xmlDoc.InsertEndChild(selectionNode); xmlDoc.InsertEndChild(selectionNode);
// fill doc // fill doc
SourceList selection_clones_;
SessionVisitor sv(&xmlDoc, selectionNode); SessionVisitor sv(&xmlDoc, selectionNode);
for (auto iter = selection_.begin(); iter != selection_.end(); iter++, sv.setRoot(selectionNode) ) for (auto iter = selection_.begin(); iter != selection_.end(); iter++, sv.setRoot(selectionNode) ){
// keep the clones for later
CloneSource *clone = dynamic_cast<CloneSource *>(*iter);
if (clone)
(*iter)->accept(sv);
else
selection_clones_.push_back(*iter);
}
// add the clones at the end
for (auto iter = selection_clones_.begin(); iter != selection_clones_.end(); iter++, sv.setRoot(selectionNode) ){
(*iter)->accept(sv); (*iter)->accept(sv);
}
// get compact string // get compact string
tinyxml2::XMLPrinter xmlPrint(0, true); tinyxml2::XMLPrinter xmlPrint(0, true);

View File

@@ -110,24 +110,28 @@ void Session::update(float dt)
SourceList::iterator Session::addSource(Source *s) SourceList::iterator Session::addSource(Source *s)
{ {
SourceList::iterator its = sources_.end();
// lock before change // lock before change
access_.lock(); access_.lock();
// find the source // find the source
SourceList::iterator its = find(s); its = find(s);
// ok, its NOT in the list ! // ok, its NOT in the list !
if (its == sources_.end()) { if (its == sources_.end()) {
// insert the source in the rendering // insert the source in the rendering
render_.scene.ws()->attach(s->group(View::RENDERING)); render_.scene.ws()->attach(s->group(View::RENDERING));
// insert the source to the beginning of the list // insert the source to the beginning of the list
sources_.push_front(s); sources_.push_front(s);
// return the iterator to the source created at the beginning
its = sources_.begin();
} }
// unlock access // unlock access
access_.unlock(); access_.unlock();
// return the iterator to the source created at the beginning return its;
return sources_.begin();
} }
SourceList::iterator Session::deleteSource(Source *s) SourceList::iterator Session::deleteSource(Source *s)