From 36826b5680db3265e3432455c9e91a9b4ee474e4 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 30 Jan 2014 19:25:56 +0000 Subject: NT var type inferred from default value --- NT/src/rotor.h | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index d2d7d00..8fbba7d 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -88,7 +88,8 @@ namespace Rotor { class Enum{ //enumerated string type for menus public: - Enum(std::initializer_list init) : labels(init){}; + Enum(std::initializer_list init={},int def=0) : labels(init), value(def){}; + int get_value(){return value;}; private: std::vector labels; int value; @@ -105,10 +106,11 @@ namespace Rotor { int channels,numsamples; }; class Frame_parameters{ + //chosen to be used as a struct: less overhead etc public: - Frame_parameters(double _time,double _framerate,double _duration,int _w,int _h,Audio_frame *_audio=nullptr) + Frame_parameters(double _time=0.0,double _framerate=25.0,double _duration=20.0,int _w=640,int _h=360,Audio_frame *_audio=nullptr) { time=_time; framerate=_framerate; duration=_duration; w=_w; h=_h;audio=_audio;}; - Frame_parameters(int _frame,double _framerate,double _duration,int _w,int _h,Audio_frame *_audio=nullptr) + Frame_parameters(int _frame,double _framerate=25.0,double _duration=20.0,int _w=640,int _h=360,Audio_frame *_audio=nullptr) { time=((double)_frame)/_framerate; framerate=_framerate; duration=_duration; w=_w; h=_h;audio=_audio;}; int h,w; Frame_parameters lastframe() const{ @@ -117,13 +119,10 @@ namespace Rotor { Frame_parameters nextframe() const{ return Frame_parameters(time+(1.0/framerate),framerate,duration,w,h); } - double get_time() const{ - return time; - } - private: double time; //num/denom ? double framerate; double duration; + private: Audio_frame *audio; }; class Variable { //pure virtual base type for variable pointers @@ -149,9 +148,8 @@ namespace Rotor { }; template class Variable_type : public Variable { public: - Variable_type(std::string _name="",std::string _input="",bool _connectable=true){ - name=_name; - input=_input; + 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){ @@ -182,12 +180,12 @@ namespace Rotor { } return false; } - const T& get(const Frame_parameters &frame){ + const T& get(const Frame_parameters &frame=Frame_parameters()){ //if (connection) std::cerr<<"still connected to '"<<(dynamic_cast*>(connection))->get_type()<<"'"<*>(connection))->get_type()<<"' node ("<*>(connection))->get_output(frame)<*>(connection))->get_output(frame); + value=(dynamic_cast*>(connection))->get_output(frame); } //else std::cerr<<"variable: returning default"<::Get();}; - template Variable_type* create_inlet(std::string name){ - vars[name]=new Variable_type(name,"",true); + 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); 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,"",false); + vars[name]=new Variable_type(name,description,title,false); return (dynamic_cast*>(vars[name])); } - template Variable_array_type* create_array(std::string name){ - vars[name]=new Variable_array_type(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 -- cgit v1.2.3