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/rotor.cpp | 144 ++++++++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 64 deletions(-) (limited to 'rotord/src/rotor.cpp') 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<