From ea8d3b6fa7ac59d064e86755fae8f25f7ed8a0d2 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 27 Dec 2013 12:45:46 +0000 Subject: making template connection logic --- NT/src/rotor.cpp | 10 ++++++---- NT/src/rotor.h | 33 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) (limited to 'NT') 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 settings={{"p1","1"}, {"p2","2"}, {"p3","3"}}; - //a.init(settings); - printf("hello, world\n"); + Rotor::time t; + multiply m; + map 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 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*>(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 IT* create_inlet(std::string name){ vars[name]=new Variable_type(); return &((dynamic_cast*>(vars[name]))->value); @@ -101,17 +121,20 @@ namespace Rotor { private: double value; }; - class signal_double: public Node_type { + class multiply: public Node_type { public: - signal_double(){ + multiply(){ + inlet=create_inlet("inlet"); value=create_inlet("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; }; } -- cgit v1.2.3