diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-08-22 17:41:10 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-08-22 17:41:10 +0100 |
| commit | b7992bab3a5087bdfb1d2c25b1b3e0bad339b588 (patch) | |
| tree | f0527f8b9875434527daa463a63cae3f22e92a52 | |
| parent | f567fc4db536a2c513f2b9e357c511b3ecb39114 (diff) | |
building json loader
| -rw-r--r-- | rotord/bin/examplegraph.json | 102 | ||||
| -rw-r--r-- | rotord/src/graph.cpp | 124 | ||||
| -rw-r--r-- | rotord/src/nodes_maths.h | 1 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 4 | ||||
| -rwxr-xr-x | rotord/src/rotor.h | 8 | ||||
| -rwxr-xr-x | rotord/src/rotord.cpp | 2 |
6 files changed, 124 insertions, 117 deletions
diff --git a/rotord/bin/examplegraph.json b/rotord/bin/examplegraph.json deleted file mode 100644 index 596fcdc..0000000 --- a/rotord/bin/examplegraph.json +++ /dev/null @@ -1,102 +0,0 @@ - { - title: "Lights Down @Rotor", - audio: "filename", - id:, - type: 'patchBay', - nodeDefinitions: [ - { - title: 'Video Loader', - type: 'video_loader', - inputs: 'fixed', - output: 'image', - description: 'loads a video file', - attributes: [ - { - type: 'string', - title: 'Filename' - }, - { - title: 'Mode', - name: 'mode', - type: 'enum', - value: 'still', - options: ['still', 'blend'], - description: 'video playback speed' - } - ], - parameters: [ - { - title: 'Frame Rate', - name: 'framerate', - type: 'number', - value: '0', - min: '0', - max: '10', - description: 'frame rate override' - }, - { - title: 'Speed', - name: 'speed', - type: 'number', - value: '1', - min: '0', - max: '10', - description: 'video playback speed' - } - ], - metadata: { - imageUrl: 'images/loader.svg', - }, - }, - - { - title: 'Video Cycler', - type: 'video_cycler', - description: 'Cycles through video inputs according to selector signal', - inputs: 'duplicatable', - image_input: [ - { - description: 'Input 1' - } - ], - signal_input: [ - { - description: 'selector' - } - ], - metadata: { - imageUrl: 'images/cycler.svg' - } - }, - { - title: 'Audio Analysis', - type: 'audio_analysis', - inputs: 'fixed', - description: 'analyse audio and output', - output: 'signal', - attributes: [ - { - title: 'Analyser Plugin', - name: 'analyser', - type: 'enum', - value: 'barbeattracker', - options: ['barbeattracker', 'segmenter'], - } - ], - parameters: [ - { - title: 'Output Number', - name: 'outputNo', - type: 'number', - value: '0', - min: '0', - max: '10', - description: 'plugin output to use' - } - ], - metadata: { - imageUrl: 'images/audio.svg' - } - }, - ] - }
\ No newline at end of file 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); |
