summaryrefslogtreecommitdiff
path: root/rotord/src
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src')
-rw-r--r--rotord/src/graph.cpp124
-rw-r--r--rotord/src/nodes_maths.h1
-rw-r--r--rotord/src/rendercontext.cpp4
-rwxr-xr-xrotord/src/rotor.h8
-rwxr-xr-xrotord/src/rotord.cpp2
5 files changed, 124 insertions, 15 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp
index b799a59..139873f 100644
--- a/rotord/src/graph.cpp
+++ b/rotord/src/graph.cpp
@@ -62,23 +62,31 @@ bool Graph::load(string data,string media_path){
if (xml.loadFromBuffer(data)){
return parseXml(media_path);
}
- cerr<<"Rotor: failed to load graph from string"<<endl;
+ //cerr<<"Rotor: failed to load graph from string"<<endl;
return false;
}
bool Graph::loadFile(string &filename,string media_path){
//if (loaded)
printf("loading graph: %s\n",(filename).c_str());
- //if(xml.loadFile(filename) ){
- // return parseXml(media_path);
- //}
+
Poco::FileInputStream fis(filename);
- std::string read;
- cerr<<fis;
- cerr<<read.size()<<" json chars found"<<endl;
- return false;
+ Poco::CountingInputStream countingIstr(fis);
+ std::string str;
+ Poco::StreamCopier::copyToString(countingIstr, str);
+ //msg.Message(Poco::format(" Write/Read check : %s", std::string(0 == str.compare(ostrBackup.str()) ? "OK":"NG")));
+ //msg.Message(Poco::format(" Characters : %d", countingIstr.chars()));
+ //msg.Message(Poco::format(" Lines : %d", countingIstr.lines()));
+ //cerr<<countingIstr.chars()<<" chars, "<<countingIstr.lines()<<endl;
+ //cerr<<str.size()<<" json chars found"<<endl;
+ if (xml.loadFile(filename)){
+ return parseXml(media_path);
+ }
+ return parseJson(str,media_path);
}
bool Graph::parseJson(string &data,string &media_path){
+ //cerr<<data<<endl;
+ cerr<<"Trying to load JSON"<<endl;
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse( data, root );
@@ -89,7 +97,105 @@ bool Graph::parseJson(string &data,string &media_path){
<< reader.getFormattedErrorMessages();
return false;
}
- cerr<<root["audio"]<<endl;
+ //we know the json validates so clear the existing graph
+ if (loaded) nodes.clear();
+ string audiotrack=root["audio"].asString();
+ if (audiotrack!="") cerr<<"audio track :"<<endl; //need to deal with
+ init(root["ID"].asString(),root["description"].asString());
+ Json::Value jnodes = root["nodes"];
+ for ( int i = 0; i < jnodes.size(); ++i ) {
+ //cerr<<"json found node: "<<jnodes[i]["type"].asString()<<endl;
+ map<string,string> settings;
+ vector<string> attrs;
+ //iterate members
+ settings["type"]=jnodes[i]["type"].asString();
+ settings["title"]=jnodes[i]["title"].asString();
+ settings["description"]=jnodes[i]["description"].asString();
+ Node* node=factory.create(settings);
+ if (node) {
+ string nodeID=jnodes[i]["id"].asString();
+ if (nodes.find(nodeID)==nodes.end()){
+ cerr << "Rotor: creating node '"<<nodeID<<"': '"<< settings["type"] << "'" << endl;
+ nodes[nodeID]=node;
+ //signal inputs
+ for (int j=0;j< jnodes[i]["signal_inputs"].size();j++){
+ if ((nodes[nodeID])->inputs.size()>j) {
+ string fromID=jnodes[i]["signal_inputs"][j]["from"].asString();
+ if (fromID!=""){
+ if (nodes.find(fromID)!=nodes.end()) {
+ if (!nodes[nodeID]->inputs[j]->connect((Signal_node*)nodes[fromID])){
+ cerr << "Rotor: graph loader cannot connect input " << j << " of node '" << nodeID << "' to node '" << fromID << "'" << endl;
+ return false;
+ }
+ else cerr << "Rotor: linked input " << j << " of node '" << nodeID << "' to node '" << fromID << "'" << endl;
+ }
+ else cerr << "Rotor: linking input " << j << " of node: '" << nodeID << "', cannot find target '" << fromID << "'" << endl;
+ }
+ }
+ else cerr << "Rotor: input " << j << " of node: '" << nodeID << "' does not exist" << endl;
+ }
+ //image inputs
+ if (dynamic_cast<Image_node*>(nodes[nodeID])!=nullptr) {
+ for (int k=0;k<jnodes[i]["image_inputs"].size();k++){
+ if (((Image_node*)nodes[nodeID])->image_inputs.size()<=k) {
+ if (nodes[nodeID]->duplicate_inputs) {
+ while(((Image_node*)nodes[nodeID])->image_inputs.size()<=k){
+ ((Image_node*)nodes[nodeID])->create_image_input(settings["description"],settings["title"]);
+ }
+ }
+ }
+ if (((Image_node*)nodes[nodeID])->image_inputs.size()>k) {
+ string fromID=jnodes[i]["image_inputs"][k]["from"].asString();
+ if (fromID!=""){
+ if (nodes.find(fromID)!=nodes.end()) {
+ if (dynamic_cast<Image_node*>(nodes[fromID])!=nullptr) {
+ if (!dynamic_cast<Image_node*>(nodes[nodeID])->image_inputs[k]->connect((Image_node*)nodes[fromID])){
+ cerr << "Rotor: graph loader cannot connect image input " << k << " of node '" << nodeID << "' to node '" << fromID << "'" << endl;
+ return false;
+ }
+ else cerr << "Rotor: linked image input " << k << " of node '" << nodeID << "' to node '" << fromID << "'" << endl;
+ }
+ else cerr << "Rotor: cannot link image input "<< k << " of node '" << nodeID << "' to node '" << fromID << "' : not an image node" << endl;
+ }
+ else cerr << "Rotor: linking image input " << k << " of node: '" << nodeID << "', cannot find target '" << fromID << "'" << endl;
+ }
+ }
+ else cerr << "Rotor: image input number " << k << " of node: '" << nodeID << "' does not exist" << endl;
+ }
+ }
+ //parameters
+ for (int l=0;l<jnodes[i]["parameters"].size();l++){
+
+ string parameter=jnodes[i]["parameters"][l]["name"].asString();
+ /*
+ if (nodes[nodeID]->parameters.find(parameter)!=nodes[nodeID]->parameters.end()) {
+ string val=jnodes[i]["parameters"][l]["value"].asString();
+ if (val!="") nodes[nodeID]->parameters.find(parameter)->second->value=ofToFloat(val);
+ string fromID=jnodes[i]["parameters"][l]["from"].asString();
+ if (nodes.find(fromID)!=nodes.end()) {
+ if (!nodes[nodeID]->parameters[parameter]->connect(nodes[fromID])){
+ cerr << "Rotor: graph loader cannot connect parameter " << parameter << " of node '" << nodeID << "' to node '" << fromID << "'" << endl;
+ return false;
+ }
+ else cerr << "Rotor: linked parameter " << parameter << " of node '" << nodeID << "' to node '" << fromID << "'" << endl;
+ }
+ else if (fromID!="") cerr << "Rotor: linking parameter " << parameter << " of node: '" << nodeID << "', cannot find target '" << fromID << "'" << endl;
+ }
+ else cerr << "Rotor: cannot find parameter input '" << parameter << "' of "<<settings["type"]<<" "<< nodeID << endl;
+ */
+ }
+ //
+
+ }
+ else cerr << "Rotor: duplicate node '"<<nodeID<<"' "<< endl;
+ }
+ else {
+ cerr << "Rotor: graph loader cannot find node '" << settings["type"] << "'" << endl;
+ return false;
+ }
+
+ }
+ loaded=true;
return true;
}
bool Graph::parseXml(string media_path){
diff --git a/rotord/src/nodes_maths.h b/rotord/src/nodes_maths.h
index d083c72..eb685eb 100644
--- a/rotord/src/nodes_maths.h
+++ b/rotord/src/nodes_maths.h
@@ -19,6 +19,7 @@ namespace Rotor {
create_signal_input("signal","Signal");
create_parameter("value","number","Value or signal for operation","Value",0.0f);
create_attribute("operator","Operator for comparison","operator","==",{"==","!=",">","<",">=","<="});
+ title="Comparison";
description="Compares the signal with a value or signal according to the operator";
};
Comparison(map<string,string> &settings):Comparison() {
diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp
index 0737b2d..8c1e847 100644
--- a/rotord/src/rendercontext.cpp
+++ b/rotord/src/rendercontext.cpp
@@ -209,8 +209,8 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H
}
else {
status=HTTPResponse::HTTP_NOT_FOUND;
- logger.error("ERROR: "+command.commands[0]+" not found");
- XML.addValue("error",command.commands[0]+" not found");
+ logger.error("ERROR: "+command.body+" not found");
+ XML.addValue("error",command.body+" not found");
}
}
}
diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h
index 9db32b3..ec9f072 100755
--- a/rotord/src/rotor.h
+++ b/rotord/src/rotor.h
@@ -17,6 +17,8 @@
#include "Poco/Path.h"
#include "Poco/Base64Encoder.h"
#include "Poco/FileStream.h"
+#include "Poco/CountingStream.h"
+#include "Poco/StreamCopier.h"
#include "xmlIO.h"
#include "utils.h"
@@ -441,7 +443,7 @@ namespace Rotor {
};
~Signal_greyscale(){};
Image *output(const Frame_spec &frame){
- uint8_t col=255-((uint8_t)(inputs[0]->get((Time_spec)frame)*255.0f));
+ uint8_t col=((uint8_t)(inputs[0]->get((Time_spec)frame)*255.0f));
if (col!=prevcol){ //how about when starting a new render?
for (int i=0;i<image.w*image.h*3;i++){
image.RGBdata[i]=col;
@@ -979,7 +981,7 @@ namespace Rotor {
}
}
if (dynamic_cast<Image_node*> (type.second)!=nullptr) {
- if ((dynamic_cast<Image_node*>(type.second))->inputs.size()){
+ if ((dynamic_cast<Image_node*>(type.second))->image_inputs.size()){
node["image_inputs"]=Json::arrayValue;
for (auto& input: (dynamic_cast<Image_node*>(type.second))->image_inputs) {
Json::Value image_input;
@@ -1015,7 +1017,7 @@ namespace Rotor {
attribute["type"]="enum";
attribute["options"]=Json::arrayValue;
for (auto val: attr.second->vals){
- attribute["attribute"].append(val);
+ attribute["options"].append(val);
}
}
else attribute["type"]="string";
diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp
index 928e07e..df1ee6a 100755
--- a/rotord/src/rotord.cpp
+++ b/rotord/src/rotord.cpp
@@ -106,7 +106,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
Json::StyledWriter writer;
//root["title"]="Lights Down @Rotor";
//root["audio"]="filename";
- root["nodeslist"]=Json::arrayValue;
+
Node_factory factory;
factory.list_nodes(root);
string content = writer.write(root);