diff options
| -rw-r--r-- | NT/src/rotor.cpp | 10 | ||||
| -rw-r--r-- | NT/src/rotor.h | 33 |
2 files changed, 34 insertions, 9 deletions
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp index 0c09b39..9a0bc5d 100644 --- a/NT/src/rotor.cpp +++ b/NT/src/rotor.cpp @@ -6,8 +6,10 @@ using namespace std; using namespace Rotor; int main(){ - //a_node a; - //map<string,string> settings={{"p1","1"}, {"p2","2"}, {"p3","3"}}; - //a.init(settings); - printf("hello, world\n"); + Rotor::time t; + multiply m; + map<string,string> settings={{"value","2"}}; + m.init(settings); + if (m.connect("inlet",&t)) printf("connected!\n"); + else printf("not connected...\n"); }
\ No newline at end of file diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 49d50a1..93b6865 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -9,6 +9,7 @@ namespace Rotor { class Node; + template <class NT> class Node_type; class Audio_frame{ public: @@ -40,8 +41,9 @@ namespace Rotor { }; class Variable { //base type for variable pointers public: - virtual void init(std::string s){}; + virtual void init(std::string s)=0; virtual ~Variable(){}; + virtual bool connect(Node* target)=0; Node* connection; bool connectable; }; @@ -51,6 +53,15 @@ namespace Rotor { std::istringstream cur(s); cur >> value; }; + bool connect(Node* target){ + if (connectable){ + if (dynamic_cast<Node_type<T>*>(target)){ + connection=target; + return true; + } + } + return false; + } T* get(Frame_parameters frame); T value; }; @@ -87,6 +98,15 @@ namespace Rotor { } }; } + 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 <class IT> IT* create_inlet(std::string name){ vars[name]=new Variable_type<IT>(); return &((dynamic_cast<Variable_type<IT>*>(vars[name]))->value); @@ -101,17 +121,20 @@ namespace Rotor { private: double value; }; - class signal_double: public Node_type<double> { + class multiply: public Node_type<double> { public: - signal_double(){ + multiply(){ + inlet=create_inlet<double>("inlet"); value=create_inlet<double>("value"); } double* get_output(const Frame_parameters &frame){ - (*value)*=2.0; - return value; + result=(*inlet)*(*value); + return &result; } private: + double *inlet; double *value; + double result; }; } |
