#include #include #include #include #include #include "utils.h" namespace Rotor { class Node; template class Node_type; 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)=0; virtual ~Variable(){}; virtual bool connect(Node* target)=0; Node* connection; bool connectable; }; template class Variable_type : public Variable { public: void init(std::string s){ std::istringstream cur(s); cur >> value; }; bool connect(Node* target){ if (connectable){ if (dynamic_cast*>(target)){ connection=target; return true; } } return false; } T* get(Frame_parameters frame); T value; }; //what happens if we want to link an unlinked attribute at runtime //should attributes and paramaters just be the same thing //it would be really nice if there could be arithmetic //type objects that could act on multiple types //either we call them attributes and inlets or just vars //for the author, is it better to have seperate static members? //for the GUI, yes. but is that another issue? //does the gui need a hint for the "basic" mode inlets so they stand out? class Node { //base type for node pointers public: virtual ~Node(){ for (auto v:vars){ //std::cerr<<"deleting "< vars; }; template class Node_type : public Node { public: virtual NT* get_output(const Frame_parameters &frame)=0; void init(std::map settings){ for (auto s:settings) { if (vars.find(s.first)!=vars.end()){ vars[s.first]->init(s.second); } }; } bool connect(std::string v,Node *t){ auto var=vars.find(v); if (var!=vars.end()){ if ((*var).second->connect(t)){ return true; } } return false; } template IT* create_inlet(std::string name){ vars[name]=new Variable_type(); return &((dynamic_cast*>(vars[name]))->value); } }; class time: public Node_type { public: double* get_output(const Frame_parameters &frame){ value=frame.time; return &value; } private: double value; }; class multiply: public Node_type { public: multiply(){ inlet=create_inlet("inlet"); value=create_inlet("value"); } double* get_output(const Frame_parameters &frame){ result=(*inlet)*(*value); return &result; } private: double *inlet; double *value; double result; }; } //next:: make a couple of nodes that do something //test them //make loading and saving functions //xml or json?