Fixed replacement of failed RenderView after sessionSource import (if a

sessionSource contains a RenderView, the later should be re-created).
This commit is contained in:
brunoherbelin
2021-02-05 18:11:16 +01:00
parent 93b6bc9ca4
commit 8185c93457
5 changed files with 74 additions and 35 deletions

View File

@@ -220,10 +220,8 @@ void Mixer::update()
// failed Render loopback: replace it with one matching the current session // failed Render loopback: replace it with one matching the current session
RenderSource *failedRender = dynamic_cast<RenderSource *>(failure); RenderSource *failedRender = dynamic_cast<RenderSource *>(failure);
if (failedRender != nullptr) { if (failedRender != nullptr) {
RenderSource *fixedRender = new RenderSource; if ( recreateSource(failedRender) )
replaceSource(failedRender, fixedRender); failure = nullptr; // prevent delete (already done in recreateSource)
fixedRender->setSession(session_);
failure = nullptr; // prevent delete (already done in replace)
} }
// delete the source // delete the source
deleteSource(failure, false); deleteSource(failure, false);
@@ -423,36 +421,75 @@ void Mixer::insertSource(Source *s, View::Mode m)
} }
void Mixer::replaceSource(Source *from, Source *to) bool Mixer::replaceSource(Source *from, Source *to)
{ {
if ( from != nullptr && to != nullptr) if ( from == nullptr || to == nullptr)
{ return false;
// rename
renameSource(to, from->name());
// remove source Nodes from all views // rename
detach(from); renameSource(to, from->name());
// copy all transforms // remove source Nodes from all views
to->group(View::MIXING)->copyTransform( from->group(View::MIXING) ); detach(from);
to->group(View::GEOMETRY)->copyTransform( from->group(View::GEOMETRY) );
to->group(View::LAYER)->copyTransform( from->group(View::LAYER) );
to->group(View::MIXING)->copyTransform( from->group(View::MIXING) );
// TODO copy all filters // copy all transforms
to->group(View::MIXING)->copyTransform( from->group(View::MIXING) );
to->group(View::GEOMETRY)->copyTransform( from->group(View::GEOMETRY) );
to->group(View::LAYER)->copyTransform( from->group(View::LAYER) );
to->group(View::MIXING)->copyTransform( from->group(View::MIXING) );
// TODO copy all filters
// add sources Nodes to all views // add source Nodes to all views
attach(to); attach(to);
// add source // add source
session_->addSource(to); session_->addSource(to);
// delete source // delete source
session_->deleteSource(from); session_->deleteSource(from);
} return true;
}
bool Mixer::recreateSource(Source *s)
{
if ( s == nullptr )
return false;
// get the xml description from this source, and exit if not wellformed
tinyxml2::XMLDocument xmlDoc;
tinyxml2::XMLError eResult = xmlDoc.Parse(Source::xml(s).c_str());
if ( XMLResultError(eResult))
return false;
tinyxml2::XMLElement *root = xmlDoc.FirstChildElement(APP_NAME);
if ( root == nullptr )
return false;
XMLElement* sourceNode = root->FirstChildElement("Source");
if ( sourceNode == nullptr )
return false;
// actually create the source with SessionLoader using xml description
SessionLoader loader( session_ );
Source *replacement = loader.createSource(sourceNode, false); // not clone
if (replacement == nullptr)
return false;
// remove source Nodes from all views
detach(s);
// delete source
session_->deleteSource(s);
// add sources Nodes to all views
attach(replacement);
// add source
session_->addSource(replacement);
return true;
} }
void Mixer::deleteSource(Source *s, bool withundo) void Mixer::deleteSource(Source *s, bool withundo)
@@ -1106,7 +1143,7 @@ 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.cloneOrCreateSource(sourceNode)); addSource(loader.createSource(sourceNode));
} }
} }

View File

@@ -109,7 +109,8 @@ protected:
SourceList candidate_sources_; SourceList candidate_sources_;
SourceList stash_; SourceList stash_;
void insertSource(Source *s, View::Mode m = View::INVALID); void insertSource(Source *s, View::Mode m = View::INVALID);
void replaceSource(Source *from, Source *to); bool replaceSource(Source *from, Source *to);
bool recreateSource(Source *s);
void setCurrentSource(SourceList::iterator it); void setCurrentSource(SourceList::iterator it);
SourceList::iterator current_source_; SourceList::iterator current_source_;

View File

@@ -220,7 +220,7 @@ void SessionLoader::load(XMLElement *sessionNode)
} }
Source *SessionLoader::cloneOrCreateSource(tinyxml2::XMLElement *sourceNode) Source *SessionLoader::createSource(tinyxml2::XMLElement *sourceNode, bool clone_duplicates)
{ {
xmlCurrent_ = sourceNode; xmlCurrent_ = sourceNode;
@@ -228,10 +228,13 @@ Source *SessionLoader::cloneOrCreateSource(tinyxml2::XMLElement *sourceNode)
Source *load_source = nullptr; Source *load_source = nullptr;
bool is_clone = false; bool is_clone = false;
SourceList::iterator sit = session_->end();
// check if a source with the given id exists in the session // check if a source with the given id exists in the session
uint64_t id__ = 0; if (clone_duplicates) {
xmlCurrent_->QueryUnsigned64Attribute("id", &id__); uint64_t id__ = 0;
SourceList::iterator sit = session_->find(id__); xmlCurrent_->QueryUnsigned64Attribute("id", &id__);
sit = session_->find(id__);
}
// no source with this id exists // no source with this id exists
if ( sit == session_->end() ) { if ( sit == session_->end() ) {
@@ -278,8 +281,6 @@ Source *SessionLoader::cloneOrCreateSource(tinyxml2::XMLElement *sourceNode)
// apply config to source // apply config to source
if (load_source) { if (load_source) {
load_source->accept(*this); load_source->accept(*this);
// reset mixing (force to place in mixing scene)
load_source->group(View::MIXING)->translation_ = glm::vec3(DEFAULT_MIXING_TRANSLATION, 0.f);
// increment depth for clones (avoid supperposition) // increment depth for clones (avoid supperposition)
if (is_clone) if (is_clone)
load_source->group(View::LAYER)->translation_.z += 0.2f; load_source->group(View::LAYER)->translation_.z += 0.2f;

View File

@@ -19,7 +19,7 @@ public:
void load(tinyxml2::XMLElement *sessionNode); void load(tinyxml2::XMLElement *sessionNode);
inline std::list<uint64_t> getIdList() const { return sources_id_; } inline std::list<uint64_t> getIdList() const { return sources_id_; }
Source *cloneOrCreateSource(tinyxml2::XMLElement *sourceNode); Source *createSource(tinyxml2::XMLElement *sourceNode, bool clone_duplicates = true);
// Elements of Scene // Elements of Scene
void visit (Node& n) override; void visit (Node& n) override;

View File

@@ -226,7 +226,7 @@ void SessionSource::update(float dt)
void SessionSource::accept(Visitor& v) void SessionSource::accept(Visitor& v)
{ {
Source::accept(v); Source::accept(v);
if (!failed()) // if (!failed())
v.visit(*this); v.visit(*this);
} }
@@ -281,6 +281,6 @@ void RenderSource::init()
void RenderSource::accept(Visitor& v) void RenderSource::accept(Visitor& v)
{ {
Source::accept(v); Source::accept(v);
if (!failed()) // if (!failed())
v.visit(*this); v.visit(*this);
} }