From 2c74f2bf6cba53e17b5b36beacc895a121de3b4d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 1 Nov 2013 16:56:52 +0000 Subject: listnode/json --- rotord/src/graph.h | 63 +++++++++----------- rotord/src/nodes_drawing.h | 2 +- rotord/src/rotor.cpp | 144 +++++++++++++++++++++++++-------------------- rotord/src/rotor.h | 16 +++++ rotord/src/rotord.cpp | 14 ++++- 5 files changed, 137 insertions(+), 102 deletions(-) (limited to 'rotord/src') diff --git a/rotord/src/graph.h b/rotord/src/graph.h index 50f3f87..ddf2471 100644 --- a/rotord/src/graph.h +++ b/rotord/src/graph.h @@ -97,42 +97,33 @@ namespace Rotor { class Thumbnailer{ public: bool make(const string &inputfilename,int w,int h,const string &outputfilename) { - //Poco::StringTokenizer t1(inputfilename,"."); - //if (t1.count()>1) { - // if (t1[t1.count()-1]=="svg"){ - // cerr<<"found an svg"< &_settings) { return new Svg(_settings);}; void vector_output(cairo_t * cr,const Frame_spec &frame){ diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp index a4ef055..6ceab91 100644 --- a/rotord/src/rotor.cpp +++ b/rotord/src/rotor.cpp @@ -45,6 +45,7 @@ Node_factory::Node_factory(){ add_type("waves",new Waves(),category["Source"]); add_type("still_image",new Still_image(),category["Source"]); add_type("video_loader",new Video_loader(),category["Source"]); + add_type("video_bank",new Video_bank(),category["Source"]); add_type("svg",new Svg(),category["Source"]); category["Distort"]=vector(); @@ -112,7 +113,83 @@ bool Node_factory::list_node(const string &t,xmlIO XML){ } } XML.addValue("error","Node /"+t+"/ not found"); + return false; }; +bool Node_factory::list_node(const string &t,Json::Value &JSON){ + for (auto& type: type_map) { + if (type.first==t) { + JSON["node"]=list_node(type.second); + return true; + } + } + JSON["error"]="Node /"+t+"/ not found"; + return false; +}; +Json::Value Node_factory::list_node(Rotor::Node* _node){ + Json::Value node; + node["type"]=_node->type; + node["title"]=_node->title; + node["inputs"]=_node->duplicate_inputs?"expandable":"fixed"; + if (dynamic_cast (_node)!=nullptr) node["output"]="signal"; + if (dynamic_cast (_node)!=nullptr) node["output"]="image"; + node["description"]=_node->description; + node["UID"]=_node->UID; + if (_node->inputs.size()){ + node["signal_inputs"]=Json::arrayValue; + for (auto& input: _node->inputs) { + Json::Value signal_input; + signal_input["title"]=input->title; + signal_input["description"]=input->description; + node["signal_inputs"].append(signal_input); + } + } + if (dynamic_cast (_node)!=nullptr) { + if ((dynamic_cast(_node))->image_inputs.size()){ + node["image_inputs"]=Json::arrayValue; + for (auto& input: (dynamic_cast(_node))->image_inputs) { + Json::Value image_input; + image_input["title"]=input->title; + image_input["description"]=input->description; + node["image_inputs"].append(image_input); + } + } + } + if (_node->parameters.size()){ + node["parameters"]=Json::arrayValue; + for (auto& param: _node->parameters) { + Json::Value parameter; + parameter["name"]=param.first; + parameter["type"]=param.second->type; + parameter["title"]=param.second->title; + parameter["description"]=param.second->description; + parameter["value"]=param.second->value; + parameter["min"]=param.second->min; + parameter["max"]=param.second->max; + parameter["step"]=param.second->step; + node["parameters"].append(parameter); + } + } + if (_node->attributes.size()){ + node["attributes"]=Json::arrayValue; + for (auto& attr: _node->attributes) { + Json::Value attribute; + attribute["name"]=attr.first; + attribute["title"]=attr.second->title; + attribute["description"]=attr.second->description; + attribute["value"]=attr.second->value; + if (attr.second->vals.size()){ //document attribute enumeration + attribute["type"]="enum"; + attribute["options"]=Json::arrayValue; + for (auto val: attr.second->vals){ + attribute["options"].append(val); + } + } + else attribute["type"]="string"; + node["attributes"].append(attribute); + } + } + return node; +} void Node_factory::list_node(Rotor::Node* type,xmlIO XML,int i=0){ XML.addTag("node"); XML.addAttribute("node","type",type->type,i); @@ -210,70 +287,9 @@ void Node_factory::list_categories(Json::Value &JSON){ category["name"]=_category.first; category["nodes"]=Json::arrayValue; for (auto& _node: _category.second){ - cerr<<"Adding "<<_category.first<<":"<<_node->type<type; - node["title"]=_node->title; - node["inputs"]=_node->duplicate_inputs?"expandable":"fixed"; - if (dynamic_cast (_node)!=nullptr) node["output"]="signal"; - if (dynamic_cast (_node)!=nullptr) node["output"]="image"; - node["description"]=_node->description; - node["UID"]=_node->UID; - if (_node->inputs.size()){ - node["signal_inputs"]=Json::arrayValue; - for (auto& input: _node->inputs) { - Json::Value signal_input; - signal_input["title"]=input->title; - signal_input["description"]=input->description; - node["signal_inputs"].append(signal_input); - } - } - if (dynamic_cast (_node)!=nullptr) { - if ((dynamic_cast(_node))->image_inputs.size()){ - node["image_inputs"]=Json::arrayValue; - for (auto& input: (dynamic_cast(_node))->image_inputs) { - Json::Value image_input; - image_input["title"]=input->title; - image_input["description"]=input->description; - node["image_inputs"].append(image_input); - } - } - } - if (_node->parameters.size()){ - node["parameters"]=Json::arrayValue; - for (auto& param: _node->parameters) { - Json::Value parameter; - parameter["name"]=param.first; - parameter["type"]=param.second->type; - parameter["title"]=param.second->title; - parameter["description"]=param.second->description; - parameter["value"]=param.second->value; - parameter["min"]=param.second->min; - parameter["max"]=param.second->max; - parameter["step"]=param.second->step; - node["parameters"].append(parameter); - } - } - if (_node->attributes.size()){ - node["attributes"]=Json::arrayValue; - for (auto& attr: _node->attributes) { - Json::Value attribute; - attribute["name"]=attr.first; - attribute["title"]=attr.second->title; - attribute["description"]=attr.second->description; - attribute["value"]=attr.second->value; - if (attr.second->vals.size()){ //document attribute enumeration - attribute["type"]="enum"; - attribute["options"]=Json::arrayValue; - for (auto val: attr.second->vals){ - attribute["options"].append(val); - } - } - else attribute["type"]="string"; - node["attributes"].append(attribute); - } - } - category["nodes"].append(node); + //cerr<<"Adding "<<_category.first<<":"<<_node->type< _vals={}) { attributes[_attr]=new Attribute(_desc,_title,_value,_vals); }; + //void create_attribute(const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector _vals={}) { + // attributes[_attr]=new Attribute(_desc,_title,_value,_vals); + //}; void create_attribute(string *alias,const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector _vals={}) { create_attribute(_attr,_desc,_title,_value,_vals); alias=&(attributes[_attr]->value); @@ -568,6 +571,17 @@ namespace Rotor { Image in1,in2,in2t,temp; //for blend frames; string *filename; }; + class Video_bank: public Video_loader { + public: + Video_bank(){ + UID="73616e66-4306-11e3-981e-74d02b29f6a6"; + }; + Video_bank(map &settings): Video_bank() { + base_settings(settings); + }; + ~Video_bank(){}; + private: + }; class Video_output: public Image_node { //Video_output 'presents' the output movie. Aspect ratio, bars, fadein/fadeout would happen here public: @@ -696,7 +710,9 @@ namespace Rotor { return NULL; }; bool list_node(const string &t,xmlIO XML); + bool list_node(const string &t,Json::Value &JSON); void list_node(Rotor::Node* type,xmlIO XML,int i=0); + Json::Value list_node(Rotor::Node* type); void list_nodes(xmlIO XML); void list_nodes(Json::Value &JSON); void list_categories(xmlIO XML); diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp index de853e4..c4c562e 100644 --- a/rotord/src/rotord.cpp +++ b/rotord/src/rotord.cpp @@ -212,8 +212,20 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } } else if (command[0]=="listnode") { - XML.pushTag("rotor"); if (request.getMethod()=="GET") { + if (command.size()>1){ + if (command[1]=="json") { + Json::Value root; + Json::StyledWriter writer; + + Node_factory factory; + factory.list_node(body,root); + string content = writer.write(root); + status=HTTPResponse::HTTP_OK; + return new RenderContextHandler(content, status); + } + } + XML.pushTag("rotor"); Node_factory factory; if (factory.list_node(body,XML)) status=HTTPResponse::HTTP_OK; } -- cgit v1.2.3