diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-26 21:50:35 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-26 21:50:35 +0000 |
| commit | fba8f7cbf38bfa6ecd7bab7cdd5e6d08d53840c6 (patch) | |
| tree | 934b18298cf61842bdd4ee943c5b9e851daf94cb /NT/src | |
| parent | 0632c3bf7808608d9e1b165c30f6791662ce009c (diff) | |
making test
Diffstat (limited to 'NT/src')
| -rw-r--r-- | NT/src/rotor.cpp | 6 | ||||
| -rw-r--r-- | NT/src/rotor.h | 80 |
2 files changed, 61 insertions, 25 deletions
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<string,string> settings={{"p1","1"}, {"p2","2"}, {"p3","3"}}; - a.init(settings); + //a_node a; + //map<string,string> 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 <string> #include <sstream> +#include <iostream> #include <map> #include <unordered_map> @@ -7,14 +8,36 @@ namespace Rotor { - template <class T> 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 T> 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 "<<v.first<<" ("<<(*v.second)<<")"<<std::endl; delete v.second; } } @@ -54,33 +79,44 @@ namespace Rotor { }; template <class NT> 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<std::string,std::string> settings){ for (auto s:settings) { - if (vars.find(s.first)){ + if (vars.find(s.first)!=vars.end()){ vars[s.first]->init(s.second); } - } + }; } template <class IT> IT* create_inlet(std::string name){ vars[name]=new Variable_type<IT>(); return &((dynamic_cast<Variable_type<IT>*>(vars[name]))->value); } }; - - class a_node: public Node_type<double> { + class time: public Node_type<double> { public: - a_node(){ - p1=create_inlet<int>("p1"); - p2=create_inlet<float>("p2"); - p3=create_inlet<double>("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<double> { + public: + signal_double(){ + value=create_inlet<double>("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 |
