From 92b9ab519a4e7eb0a0d365229835b044d431566c Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 14 May 2013 18:15:35 +0100 Subject: started parameter inputs --- rotord/graph.cpp | 13 +++++++++++++ rotord/rotor.cpp | 5 +++++ rotord/rotor.h | 35 +++++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/rotord/graph.cpp b/rotord/graph.cpp index 2139f6c..57cae92 100644 --- a/rotord/graph.cpp +++ b/rotord/graph.cpp @@ -84,6 +84,19 @@ bool Graph::load(string &filename){ } else cerr << "Rotor: linking image input " << i3 << " of node: '" << nodeID << "', cannot find target '" << fromID << "'" << endl; } + int n4=xml.getNumTags("parameter_input"); + for (int i4=0;i4create_parameter_input(xml.getAttribute("parameter_input","parameter","",i4),xml.getValue("parameter_input","",i4)); + string fromID=xml.getAttribute("parameter_input","from","",i4); + if (nodes.find(fromID)!=nodes.end()) { + if (!nodes[nodeID]->parameter_inputs[i4]->connect(nodes[fromID])){ + cerr << "Rotor: graph loader cannot connect parameter input " << i4 << " of node '" << nodeID << "' to node '" << fromID << "'" << endl; + return false; + } + else cerr << "Rotor: linked parameter input " << i4 << " of node '" << nodeID << "' to node '" << fromID << "'" << endl; + } + else cerr << "Rotor: linking parameter input " << i4 << " of node: '" << nodeID << "', cannot find target '" << fromID << "'" << endl; + } xml.popTag(); } } diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 0f78100..59a1697 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -37,6 +37,11 @@ bool Image_input::connect(Image_node* source) { } else return false; } +void Node::update_params(const Time_spec& time){ //compute connected parameters + for (auto p:parameter_inputs){ + p->update(time); + } +} bool Signal_output::render(const float duration, const float framerate,string &xml_out){ //testing signal routes cerr << "Rotor: Signal_output rendering " << duration << " seconds at " << framerate << " frames per second" << endl; diff --git a/rotord/rotor.h b/rotord/rotor.h index fa166a2..d5dc60e 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -83,6 +83,7 @@ namespace Rotor { class Node; class Signal_node; class Image_node; + class Parameter_input; //http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/ struct Packet { @@ -258,7 +259,17 @@ namespace Rotor { public: bool connect(Signal_node *source); Signal_input(const string &_desc): Input(_desc){}; - + }; + class Parameter_input: public Signal_input{ + public: + Parameter_input(const string &_param,const string &_desc): Signal_input(_desc),receiver(nullptr),parameter(_param){}; + float *receiver; + void update(const Time_spec& time){ //gets input and updates variable + if (receiver){ + *receiver=((Signal_node*)connection)->get_output(time); + } + } + string parameter; }; class Node{ public: @@ -266,7 +277,9 @@ namespace Rotor { UUID uid; //every usable node has a UUID int id; vector inputs; //simple node can have signal inputs, output depends on node type + vector parameter_inputs; //linked parameters can convert from settings to inputs void create_signal_input(const string &description) {inputs.push_back(new Signal_input(description));}; + void create_parameter_input(const string ¶meter,const string &description) {parameter_inputs.push_back(new Parameter_input(parameter,description));}; string description; string type; string output_type; @@ -280,10 +293,12 @@ namespace Rotor { output_type=find_setting(settings,"output"); ID=find_setting(settings,"ID"); } + void update_params(const Time_spec& time); }; class Signal_node: public Node{ public: - virtual const float get_output(const Time_spec &time) { return 0.0f; }; + const float get_output(const Time_spec &time) { update_params(time); return output(time); }; + virtual const float output(const Time_spec &time) { return 0.0f; }; }; class Image_node: public Node{ public: @@ -316,7 +331,7 @@ namespace Rotor { bool init(int _channels,int _bits,int _samples,int _rate); void cleanup(); int process_frame(uint8_t *data,int samples_in_frame); - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { if (analyser.features.size()) { auto i=analyser.features.lower_bound(time.time); if (i!=analyser.features.end()){ @@ -344,7 +359,7 @@ namespace Rotor { base_settings(settings); }; Track_time* clone(map &_settings) { return new Track_time(_settings);}; - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { return time.time/time.duration; } }; @@ -369,7 +384,7 @@ namespace Rotor { if (_op=="<=") op=COMPARISON_Less_or_equal; }; Comparison* clone(map &_settings) { return new Comparison(_settings);}; - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { if (inputs.size()) { //there should there be a way to specify number of inputs in the code rather than in xml if (inputs[0]->connection) { float in= (((Signal_node*)inputs[0]->connection)->get_output(time)); @@ -419,7 +434,7 @@ namespace Rotor { if (_op=="%") op=ARITHMETIC_modulo; }; Arithmetic* clone(map &_settings) { return new Arithmetic(_settings);}; - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { if (inputs.size()) { //there should there be a way to specify number of inputs in the code rather than in xml if (inputs[0]->connection) { float in= (((Signal_node*)inputs[0]->connection)->get_output(time)); @@ -455,7 +470,7 @@ namespace Rotor { divide_amount=ofToFloat(find_setting(settings,"amount")); }; Signal_divide* clone(map &_settings) { return new Signal_divide(_settings);}; - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { if (inputs.size()) { //there should there be a way to specify number of inputs in the code rather than in xml if (inputs[0]->connection) { return (((Signal_node*)inputs[0]->connection)->get_output(time))/divide_amount; @@ -472,7 +487,7 @@ namespace Rotor { base_settings(settings); }; Is_new_integer* clone(map &_settings) { return new Is_new_integer(_settings);}; - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { if (inputs[0]->connection) { float s1=(((Signal_node*)(inputs[0]->connection))->get_output(time)); float s2=(((Signal_node*)(inputs[0]->connection))->get_output(time.lastframe())); @@ -490,7 +505,7 @@ namespace Rotor { base_settings(settings); }; On_off* clone(map &_settings) { return new On_off(_settings);}; - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { if (inputs[0]->connection) { float s1=(((Signal_node*)(inputs[0]->connection))->get_output(time)); if ((int)s1%2) return 1.0f; @@ -506,7 +521,7 @@ namespace Rotor { }; Signal_output* clone(map &_settings) { return new Signal_output(_settings);}; bool render(const float duration, const float framerate,string &xml_out); - const float get_output(const Time_spec &time) { + const float output(const Time_spec &time) { if (inputs[0]->connection) { return ((Signal_node*)(inputs[0]->connection))->get_output(time); } -- cgit v1.2.3