From fba8f7cbf38bfa6ecd7bab7cdd5e6d08d53840c6 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 26 Dec 2013 21:50:35 +0000 Subject: making test --- NT/src/rotor.cpp | 6 ++--- NT/src/rotor.h | 80 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 25 deletions(-) (limited to 'NT') diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp index f13f700..0c09b39 100644 --- a/NT/src/rotor.cpp +++ b/NT/src/rotor.cpp @@ -6,8 +6,8 @@ using namespace std; using namespace Rotor; int main(){ - a_node a; - map settings={{"p1","1"}, {"p2","2"}, {"p3","3"}}; - a.init(settings); + //a_node a; + //map settings={{"p1","1"}, {"p2","2"}, {"p3","3"}}; + //a.init(settings); printf("hello, world\n"); } \ No newline at end of file diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 19e5d18..49d50a1 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -7,14 +8,36 @@ namespace Rotor { - template void from_string(T t,std::string s) { - std::istringstream cur(s); - cur >> t; - }; - class Node; - class Frame_parameters; + class Audio_frame{ + public: + Audio_frame(uint16_t *_samples,int _channels,int _numsamples){ + samples=_samples; + channels=_channels; + numsamples=_numsamples; + } + uint16_t *samples; + int channels,numsamples; + }; + class Frame_parameters{ + public: + Frame_parameters(double _time,double _framerate,double _duration,int _w,int _h,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) + { time=((double)_frame)/_framerate; framerate=_framerate; duration=_duration; w=_w; h=_h;audio=_audio;}; + int h,w; + Frame_parameters lastframe() const{ + return Frame_parameters(time-(1.0/framerate),framerate,duration,w,h); + } + Frame_parameters nextframe() const{ + return Frame_parameters(time+(1.0/framerate),framerate,duration,w,h); + } + double time; //num/denom ? + double framerate; + double duration; + Audio_frame *audio; + }; class Variable { //base type for variable pointers public: virtual void init(std::string s){}; @@ -25,7 +48,8 @@ namespace Rotor { template class Variable_type : public Variable { public: void init(std::string s){ - from_string(value,s); + std::istringstream cur(s); + cur >> value; }; T* get(Frame_parameters frame); T value; @@ -46,6 +70,7 @@ namespace Rotor { public: virtual ~Node(){ for (auto v:vars){ + //std::cerr<<"deleting "< class Node_type : public Node { public: - NT* get_output(Frame_parameters frame); + virtual NT* get_output(const Frame_parameters &frame)=0; void init(std::map settings){ for (auto s:settings) { - if (vars.find(s.first)){ + if (vars.find(s.first)!=vars.end()){ vars[s.first]->init(s.second); } - } + }; } template IT* create_inlet(std::string name){ vars[name]=new Variable_type(); return &((dynamic_cast*>(vars[name]))->value); } }; - - class a_node: public Node_type { + class time: public Node_type { public: - a_node(){ - p1=create_inlet("p1"); - p2=create_inlet("p2"); - p3=create_inlet("p3"); - //initialise the pointer to point at the instance variable - //how to delete the vars ??? - }; + double* get_output(const Frame_parameters &frame){ + value=frame.time; + return &value; + } private: - int *p1; - float *p2; - double *p3; + double value; + }; + class signal_double: public Node_type { + public: + signal_double(){ + value=create_inlet("value"); + } + double* get_output(const Frame_parameters &frame){ + (*value)*=2.0; + return value; + } + private: + double *value; }; } + +//next:: make a couple of nodes that do something +//test them +//make loading and saving functions +//xml or json? \ No newline at end of file -- cgit v1.2.3