summaryrefslogtreecommitdiff
path: root/NT/src
diff options
context:
space:
mode:
Diffstat (limited to 'NT/src')
-rw-r--r--NT/src/rotor.cpp36
-rw-r--r--NT/src/rotor.h76
2 files changed, 71 insertions, 41 deletions
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp
index 056736d..ca15423 100644
--- a/NT/src/rotor.cpp
+++ b/NT/src/rotor.cpp
@@ -5,15 +5,43 @@
using namespace std;
using namespace Rotor;
+template <class T>
+void Rotor::Variable_type<T>::init(std::string s){
+ std::istringstream cur(s);
+cur >> value;
+ //std::cout<<s<<" "<<value<<std::endl;
+ }
+
+template <class T>
+bool Rotor::Variable_type<T>::connect(Node* target){
+ if (connectable){
+ if (dynamic_cast<Node_type<T>*>(target)){
+ connection=target;
+ return true;
+ }
+ }
+ return false;
+ }
+
+template <class T>
+const T& Rotor::Variable_type<T>::get(const Frame_parameters &frame){
+ if (connection){
+ return (dynamic_cast<Node_type<T>*>(connection))->get_output(frame);
+ }
+ return value;
+ }
+
int main(){
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");
+ if (!m.connect("inlet",&t)) printf("not connected...\n");
+Rotor::print p;
+if (!p.connect("inlet",&m)) printf("not connected...\n");
for (double t=0;t<10.0;t+=0.765){
Frame_parameters f=Frame_parameters(t,25.0,10.0,640,360);
- printf()
+ printf("%04f %s\n",t,p.get_output(f).c_str());
+
}
-} \ No newline at end of file
+}
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 1451a1b..2d8c7d7 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -4,7 +4,6 @@
#include <map>
#include <unordered_map>
-#include "utils.h"
namespace Rotor {
@@ -41,6 +40,7 @@ namespace Rotor {
};
class Variable { //pure virtual base type for variable pointers
public:
+ Variable(){connection=nullptr;};
virtual void init(std::string s)=0;
virtual ~Variable(){};
virtual bool connect(Node* target)=0;
@@ -50,33 +50,19 @@ namespace Rotor {
template <class T> class Variable_type : public Variable {
public:
Variable_type(bool _c){connectable=_c;};
- void init(std::string s){
- 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);
+ void init(std::string s);
+ bool connect(Node* target);
+ const T& get(const Frame_parameters &frame);
T value;
};
+ class enum{
+ public:
+ vector<std::string> options;
+
+ };
- //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?
+//rotor variable types
class Node { //base type for node pointers
public:
@@ -91,11 +77,12 @@ namespace Rotor {
};
template <class NT> class Node_type : public Node {
public:
- virtual NT* get_output(const Frame_parameters &frame)=0;
+ virtual const 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)!=vars.end()){
vars[s.first]->init(s.second);
+ //printf("set %s to %s\n",s.first.c_str(),s.second.c_str());
}
};
}
@@ -108,20 +95,20 @@ namespace Rotor {
}
return false;
}
- template <class IT> IT* create_inlet(std::string name){
+ template <class IT> Variable_type<IT>* create_inlet(std::string name){
vars[name]=new Variable_type<IT>(true);
- return &((dynamic_cast<Variable_type<IT>*>(vars[name]))->value);
+ return (dynamic_cast<Variable_type<IT>*>(vars[name]));
}
- template <class IT> IT* create_attribute(std::string name){
+ template <class IT> Variable_type<IT>* create_attribute(std::string name){
vars[name]=new Variable_type<IT>(false);
- return &((dynamic_cast<Variable_type<IT>*>(vars[name]))->value);
+ return (dynamic_cast<Variable_type<IT>*>(vars[name]));
}
};
class time: public Node_type<double> {
public:
- double* get_output(const Frame_parameters &frame){
+ const double &get_output(const Frame_parameters &frame){
value=frame.time;
- return &value;
+ return value;
}
private:
double value;
@@ -132,19 +119,34 @@ namespace Rotor {
inlet=create_inlet<double>("inlet");
value=create_inlet<double>("value");
}
- double* get_output(const Frame_parameters &frame){
- result=(*inlet)*(*value);
- return &result;
+ const double &get_output(const Frame_parameters &frame){
+ result=inlet->get(frame)*value->get(frame);
+ return result;
}
private:
- double *inlet;
- double *value;
+ Variable_type<double> *inlet;
+ Variable_type<double> *value;
double result;
};
+class print: public Node_type<std::string> {
+ public:
+ print(){
+ inlet=create_inlet<double>("inlet");
+ }
+ const std::string &get_output(const Frame_parameters &frame){
+std::ostringstream out;
+ out << inlet->get(frame);
+ result=out.str();
+ return result;
+ }
+ private:
+ Variable_type<double> *inlet;
+ std::string result;
+ };
}
//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
+//xml or json?