summaryrefslogtreecommitdiff
path: root/NT/src/nodes.h
blob: 21b1fc48038b00c789ba7e85a5cfbe5aa70be4ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef ROTOR_NODES_H
#define ROTOR_NODES_H

#include "rotor.h"

using namespace std;

namespace Rotor{
	class Double_node: public Node_type<double> {
		public:
			Double_node(){};
	};
	class Time: public Double_node {
		public:
			Time(){
				type="time";
				description="time in fractional seconds";
				title="Time";
				type_id="4bdaaa7a-8194-11e3-8a4f-2ff6852ae2c7";
				ui_type="none";
			};
			Time(Json::Value &settings):Time() {
				init(settings);
			};
			const double &get_output(const Frame_parameters &frame){
				value=frame.get_time();
				return value;
			}
			Time* clone(Json::Value &_settings) { return new Time(_settings);};
		private:
			double value;
	};
	class Multiply: public Double_node {
		public:
			Multiply(){
				factors=create_array<double>("factors");
				type="multiply";
				description="multiplies numbers";
				title="Multiply";
				type_id="11c67850-7ce4-11e3-abf6-930ef8613c46";
				ui_type="none";
			}
			Multiply(Json::Value &settings):Multiply() {
				init(settings);
			};
			const double &get_output(const Frame_parameters &frame){
				result=1.0f;
				//for (auto val:factors->get_values()) {
                //    result*=val.get(frame);
                //}
                //std::cerr<<"multiplying "<<factors->get_number()<<" factors"<<std::endl;
                for (uint32_t i=0;i<factors->get_number();i++){
                	//std::cerr<<"result from input "<<i<<": "<<factors->get(i,frame)<<std::endl;
                	result*=factors->get(i,frame);
                }
				return result;
			}
			Multiply* clone(Json::Value &_settings) { return new Multiply(_settings);};
		private:
			Variable_array_type<double> *factors;
			double result;
	};
	class String_node: public Node_type<string> {
		public:
			String_node(){};
	};
	class Print: public String_node {
		public:
			Print(){
				inlet=create_inlet<double>("inlet");
				type="print";
				description="number as a string";
				title="Print";
				type_id="9b9232b8-8194-11e3-a5a2-07659a1b53c3";
				ui_type="none";
			}
			Print(Json::Value &settings):Print() {
				init(settings);
			};
			const std::string &get_output(const Frame_parameters &frame){
				std::ostringstream out;
				out << inlet->get(frame);
				result=out.str();
				return result;
			}
			Print* clone(Json::Value &_settings) { return new Print(_settings);};
		private:
			Variable_type<double> *inlet;
			std::string result;
	};
}


#endif //ROTOR_NODES_H