diff options
| author | Tim Redfern <tim@eclectronics.org> | 2014-01-31 16:29:05 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2014-01-31 16:29:05 +0000 |
| commit | 8d2a96416c0c02ec14f14c363052468115e61ec2 (patch) | |
| tree | 4e633c38fde635bf87e3f798ab3d856d01a33f50 /NT/src/rotor.h | |
| parent | 36826b5680db3265e3432455c9e91a9b4ee474e4 (diff) | |
switch render 2
Diffstat (limited to 'NT/src/rotor.h')
| -rw-r--r-- | NT/src/rotor.h | 25 |
1 files changed, 16 insertions, 9 deletions
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<std::string> init={},int def=0) : labels(init), value(def){}; int get_value(){return value;}; + operator int () const { + return value; + } private: std::vector<std::string> 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 T> 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<std::string,Node*> &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<Variable> values; }; template <class T> 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<NT>::Get();}; template <class IT> Variable_type<IT>* create_inlet(std::string name="",std::string description="",std::string title="",IT _default=IT()){ vars[name]=new Variable_type<IT>(name,description,title,true); + dynamic_cast<Variable_type<IT>*>(vars[name])->set(_default); return (dynamic_cast<Variable_type<IT>*>(vars[name])); } template <class IT> Variable_type<IT>* create_attribute(std::string name="",std::string description="",std::string title="",IT _default=IT()){ vars[name]=new Variable_type<IT>(name,description,title,false); + dynamic_cast<Variable_type<IT>*>(vars[name])->set(_default); return (dynamic_cast<Variable_type<IT>*>(vars[name])); } template <class IT> Variable_array_type<IT>* create_array(std::string name="",std::string description="",std::string title="",IT _default=IT()){ vars[name]=new Variable_array_type<IT>(name,description,title); return (dynamic_cast<Variable_array_type<IT>*>(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 }; } |
