From 8d2a96416c0c02ec14f14c363052468115e61ec2 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 31 Jan 2014 16:29:05 +0000 Subject: switch render 2 --- NT/src/rotor.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 8fbba7d..f2e19b5 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -90,11 +90,14 @@ namespace Rotor { public: Enum(std::initializer_list init={},int def=0) : labels(init), value(def){}; int get_value(){return value;}; + operator int () const { + return value; + } private: std::vector labels; int value; }; - + class Audio_frame{ public: Audio_frame(uint16_t *_samples,int _channels,int _numsamples){ @@ -127,7 +130,7 @@ namespace Rotor { }; class Variable { //pure virtual base type for variable pointers public: - Variable():name(""),description(""),title(""),connection(nullptr){}; + Variable(std::string _name="",std::string _description="",std::string _title=""):name(_name),description(_description),title(_title),connection(nullptr){}; virtual ~Variable(){}; virtual Json::Value to_json()=0; virtual void init(Json::Value s)=0; @@ -148,8 +151,7 @@ namespace Rotor { }; template class Variable_type : public Variable { public: - Variable_type(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true){ - Variable(_name,_description,_title); + Variable_type(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true): Variable(_name,_description,_title){ connectable=_connectable; }; void init(Json::Value s){ @@ -158,6 +160,9 @@ namespace Rotor { name=s["name"].asString(); input=s["input"].asString(); } + void set(const T& val){ + value=val; + } bool create_connection(std::unordered_map &nodes){ for (auto node:nodes){ if (node.first==input){ @@ -195,13 +200,15 @@ namespace Rotor { }; class Variable_array: public Variable { public: - Variable_array(){}; + Variable_array(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true): Variable(_name,_description,_title){ + connectable=_connectable; + }; protected: std::vector values; }; template class Variable_array_type: public Variable_array { public: - Variable_array_type(std::string n){name=n;connectable=true;}; + Variable_array_type(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true): Variable_array(_name,_description,_title,connectable){}; void init(Json::Value s){ name=s["name"].asString(); if (!s["input"].empty()){ @@ -321,20 +328,20 @@ namespace Rotor { std::string get_output_type(){return TypeName::Get();}; template Variable_type* create_inlet(std::string name="",std::string description="",std::string title="",IT _default=IT()){ vars[name]=new Variable_type(name,description,title,true); + dynamic_cast*>(vars[name])->set(_default); return (dynamic_cast*>(vars[name])); } template Variable_type* create_attribute(std::string name="",std::string description="",std::string title="",IT _default=IT()){ vars[name]=new Variable_type(name,description,title,false); + dynamic_cast*>(vars[name])->set(_default); return (dynamic_cast*>(vars[name])); } template Variable_array_type* create_array(std::string name="",std::string description="",std::string title="",IT _default=IT()){ vars[name]=new Variable_array_type(name,description,title); return (dynamic_cast*>(vars[name])); } - //enum will require specialisation - //1st, define the enum data type protected: - NT value; //every node has a value so it can return a reference + NT value; //every node has an internal value so it can return a reference }; } -- cgit v1.2.3