mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
New Session class to contain the list of sources. Loading and Saving of
session files in XML. Verified deletion of Nodes, Groups and Sources.
This commit is contained in:
173
SessionCreator.cpp
Normal file
173
SessionCreator.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
#include "SessionCreator.h"
|
||||
|
||||
#include "Log.h"
|
||||
#include "Scene.h"
|
||||
#include "Primitives.h"
|
||||
#include "Mesh.h"
|
||||
#include "Source.h"
|
||||
#include "Session.h"
|
||||
#include "ImageShader.h"
|
||||
#include "ImageProcessingShader.h"
|
||||
#include "MediaPlayer.h"
|
||||
|
||||
#include <tinyxml2.h>
|
||||
using namespace tinyxml2;
|
||||
|
||||
|
||||
SessionCreator::SessionCreator(tinyxml2::XMLElement *sessionNode): Visitor()
|
||||
{
|
||||
session_ = nullptr;
|
||||
|
||||
if (sessionNode != nullptr) {
|
||||
session_ = new Session;
|
||||
|
||||
int counter = 0;
|
||||
XMLElement* sourceNode = sessionNode->FirstChildElement("Source");
|
||||
for( ; sourceNode ; sourceNode = sourceNode->NextSiblingElement())
|
||||
{
|
||||
xmlCurrent_ = sourceNode;
|
||||
counter++;
|
||||
|
||||
const char *pType = xmlCurrent_->Attribute("type");
|
||||
if ( std::string(pType) == "MediaSource") {
|
||||
MediaSource *new_media_source = new MediaSource();
|
||||
new_media_source->accept(*this);
|
||||
session_->addSource(new_media_source);
|
||||
}
|
||||
// TODO : else other types of source
|
||||
|
||||
}
|
||||
Log::Info("Created %d Sources", counter);
|
||||
|
||||
}
|
||||
else
|
||||
Log::Warning("Session seems empty.");
|
||||
}
|
||||
|
||||
|
||||
void SessionCreator::XMLToNode(tinyxml2::XMLElement *xml, Node &n)
|
||||
{
|
||||
XMLElement *node = xml->FirstChildElement("Node");
|
||||
if (node) {
|
||||
XMLElement *scaleNode = node->FirstChildElement("scale");
|
||||
tinyxml2::XMLElementToGLM( scaleNode->FirstChildElement("vec3"), n.scale_);
|
||||
XMLElement *translationNode = node->FirstChildElement("translation");
|
||||
tinyxml2::XMLElementToGLM( translationNode->FirstChildElement("vec3"), n.translation_);
|
||||
XMLElement *rotationNode = node->FirstChildElement("rotation");
|
||||
tinyxml2::XMLElementToGLM( rotationNode->FirstChildElement("vec3"), n.rotation_);
|
||||
}
|
||||
}
|
||||
|
||||
void SessionCreator::visit(Node &n)
|
||||
{
|
||||
XMLToNode(xmlCurrent_, n);
|
||||
}
|
||||
|
||||
void SessionCreator::visit(MediaPlayer &n)
|
||||
{
|
||||
XMLElement* mediaplayerNode = xmlCurrent_->FirstChildElement("MediaPlayer");
|
||||
if (mediaplayerNode) {
|
||||
double speed = 1.0;
|
||||
mediaplayerNode->QueryDoubleAttribute("speed", &speed);
|
||||
n.setPlaySpeed(speed);
|
||||
int loop = 1;
|
||||
mediaplayerNode->QueryIntAttribute("loop", &loop);
|
||||
n.setLoop( (MediaPlayer::LoopMode) loop);
|
||||
bool play = true;
|
||||
mediaplayerNode->QueryBoolAttribute("play", &play);
|
||||
n.play(play);
|
||||
}
|
||||
}
|
||||
|
||||
void SessionCreator::visit(Shader &n)
|
||||
{
|
||||
XMLElement* color = xmlCurrent_->FirstChildElement("color");
|
||||
tinyxml2::XMLElementToGLM( color->FirstChildElement("vec4"), n.color);
|
||||
|
||||
XMLElement* blending = xmlCurrent_->FirstChildElement("blending");
|
||||
if (blending) {
|
||||
int blend = 0;
|
||||
blending->QueryIntAttribute("loop", &blend);
|
||||
n.blending = (Shader::BlendMode) blend;
|
||||
}
|
||||
}
|
||||
|
||||
void SessionCreator::visit(ImageShader &n)
|
||||
{
|
||||
const char *pType = xmlCurrent_->Attribute("type");
|
||||
if ( std::string(pType) != "ImageShader" )
|
||||
return;
|
||||
|
||||
XMLElement* uniforms = xmlCurrent_->FirstChildElement("uniforms");
|
||||
if (uniforms) {
|
||||
uniforms->QueryFloatAttribute("stipple", &n.stipple);
|
||||
uniforms->QueryUnsignedAttribute("mask", &n.mask);
|
||||
}
|
||||
}
|
||||
|
||||
void SessionCreator::visit(ImageProcessingShader &n)
|
||||
{
|
||||
const char *pType = xmlCurrent_->Attribute("type");
|
||||
if ( std::string(pType) != "ImageProcessingShader" )
|
||||
return;
|
||||
|
||||
XMLElement* uniforms = xmlCurrent_->FirstChildElement("uniforms");
|
||||
if (uniforms) {
|
||||
uniforms->QueryFloatAttribute("brightness", &n.brightness);
|
||||
uniforms->QueryFloatAttribute("contrast", &n.contrast);
|
||||
uniforms->QueryFloatAttribute("saturation", &n.saturation);
|
||||
uniforms->QueryFloatAttribute("hueshift", &n.hueshift);
|
||||
uniforms->QueryFloatAttribute("threshold", &n.threshold);
|
||||
uniforms->QueryFloatAttribute("lumakey", &n.lumakey);
|
||||
uniforms->QueryIntAttribute("nbColors", &n.nbColors);
|
||||
uniforms->QueryIntAttribute("invert", &n.invert);
|
||||
uniforms->QueryFloatAttribute("chromadelta", &n.chromadelta);
|
||||
uniforms->QueryIntAttribute("filter", &n.filterid);
|
||||
}
|
||||
|
||||
XMLElement* gamma = xmlCurrent_->FirstChildElement("gamma");
|
||||
tinyxml2::XMLElementToGLM( gamma->FirstChildElement("vec4"), n.gamma);
|
||||
XMLElement* levels = xmlCurrent_->FirstChildElement("levels");
|
||||
tinyxml2::XMLElementToGLM( levels->FirstChildElement("vec4"), n.levels);
|
||||
XMLElement* chromakey = xmlCurrent_->FirstChildElement("chromakey");
|
||||
tinyxml2::XMLElementToGLM( chromakey->FirstChildElement("vec4"), n.chromakey);
|
||||
}
|
||||
|
||||
void SessionCreator::visit (Source& s)
|
||||
{
|
||||
XMLElement* sourceNode = xmlCurrent_;
|
||||
const char *pName = sourceNode->Attribute("name");
|
||||
s.setName(pName);
|
||||
|
||||
xmlCurrent_ = sourceNode->FirstChildElement("Mixing");
|
||||
s.node(View::MIXING)->accept(*this);
|
||||
|
||||
xmlCurrent_ = sourceNode->FirstChildElement("Geometry");
|
||||
s.node(View::GEOMETRY)->accept(*this);
|
||||
|
||||
xmlCurrent_ = sourceNode->FirstChildElement("Blending");
|
||||
s.blendingShader()->accept(*this);
|
||||
|
||||
xmlCurrent_ = sourceNode->FirstChildElement("ImageProcessing");
|
||||
s.processingShader()->accept(*this);
|
||||
|
||||
// restore current
|
||||
xmlCurrent_ = sourceNode;
|
||||
}
|
||||
|
||||
void SessionCreator::visit (MediaSource& s)
|
||||
{
|
||||
// set uri
|
||||
XMLElement* uriNode = xmlCurrent_->FirstChildElement("uri");
|
||||
if (uriNode) {
|
||||
std::string uri = std::string ( uriNode->GetText() );
|
||||
s.setURI(uri);
|
||||
}
|
||||
|
||||
// set config media player
|
||||
s.mediaplayer()->accept(*this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user