summaryrefslogtreecommitdiff
path: root/rotord/src/rotor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src/rotor.cpp')
-rwxr-xr-xrotord/src/rotor.cpp121
1 files changed, 45 insertions, 76 deletions
diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp
index c7e7bc7..99fe396 100755
--- a/rotord/src/rotor.cpp
+++ b/rotord/src/rotor.cpp
@@ -1,87 +1,74 @@
#include "rotor.h"
#include "nodes_audio_analysis.h"
-#include "nodes_drawing.h"
#include "nodes_maths.h"
+#include "nodes_drawing.h"
#include "nodes_filters.h"
using namespace Rotor;
+using Poco::Logger;
Node_factory::Node_factory(){
//for now, statically load prototype map in constructor
- add_type("audio_analysis",new Audio_analysis());
- add_type("divide",new Signal_divide());
- add_type("bang",new Is_new_integer());
+ add_type("time",new Time());
+ add_type("track_time",new Track_time());
add_type("signal_output",new Signal_output());
add_type("testcard",new Testcard());
- add_type("video_output",new Video_output());
- add_type("video_loader",new Video_loader());
- add_type("on_off",new On_off());
add_type("invert",new Invert());
add_type("video_cycler",new Video_cycler());
- add_type("luma_levels",new Luma_levels());
- add_type("echo_trails",new Echo_trails());
- add_type("time",new Time());
- add_type("track_time",new Track_time());
- add_type("comparison",new Comparison()); //TODO: alias to symbols
- add_type("arithmetic",new Arithmetic()); //TODO: alias to symbols
add_type("signal_colour",new Signal_colour());
add_type("signal_greyscale",new Signal_greyscale());
add_type("image_arithmetic",new Image_arithmetic());
- add_type("random",new Random());
+ add_type("luma_levels",new Luma_levels());
+ add_type("echo_trails",new Echo_trails());
add_type("blend",new Blend());
add_type("mirror",new Mirror());
add_type("monochrome",new Monochrome());
add_type("transform",new Transform());
add_type("alpha_merge",new Alpha_merge());
+ //nodes_audio_analysis.h
+ add_type("audio_analysis",new Audio_analysis());
+ //nodes_maths.h
+ add_type("comparison",new Comparison()); //TODO: alias to symbols
+ add_type("arithmetic",new Arithmetic()); //TODO: alias to symbols
+ add_type("bang",new Is_new_integer());
+ add_type("on_off",new On_off());
+ add_type("random",new Random());
+ //nodes_drawing.h
add_type("shape",new Shape());
+ add_type("hello",new Hello_draw());
+ //nodes_filters.h
add_type("blur",new Blur());
+ //video nodes
+ add_type("video_loader",new Video_loader());
+ add_type("video_output",new Video_output());
}
-
-bool Signal_input::connect(Signal_node* source) {
- if (source->output_type=="signal") {
- connection=(Node*)source;
- return true;
- }
+bool Signal_input::connect(Node* source) {
+ connection=dynamic_cast<Signal_node*>(source);
+ if (connection) return true;
else return false;
}
-void Parameter_input::update(const Time_spec& time){ //gets input and updates variable
- if (receiver){
- *receiver=((Signal_node*)connection)->get_output(time);
+float Signal_input::get(const Time_spec& time){ //gets input and updates variable
+ if (connection){
+ return (((Signal_node*)connection)->get_output(time));
}
+ else return 0.0f;
}
-bool Image_input::connect(Image_node* source) {
- if (source->output_type=="image") {
- connection=(Node*)source;
- return true;
- }
+bool Image_input::connect(Node* source) {
+ connection=dynamic_cast<Image_node*>(source);
+ if (connection) return true;
else return false;
}
-void Node::update_params(const Time_spec& time){ //compute connected parameters
- for (auto p:parameter_inputs){
- p->update(time);
+Image* Image_input::get(const Frame_spec& time){ //gets input and updates variable
+ if (connection){
+ return (((Image_node*)connection)->get_output(time));
}
+ else return nullptr;
}
-bool Signal_output::render(const float duration, const float framerate,string &xml_out){
- //testing signal routes
- Logger& logger = Logger::get("Rotor");
- logger.information("SIgnal_output rendering "+ofToString(duration)+" seconds at "+ofToString(framerate)+" fps");
-
- float step=1.0f/framerate;
- float v=0.0f;
- float min=10000000.0f;
- float max=-10000000.0f;
- for (float f=0.0f;f<duration;f+=step) {
- float u=get_output(Time_spec(f,framerate,duration));
- if (!fequal(u,v)) {
- xml_out+=("<signal time='"+ofToString(f)+"'>"+ofToString(u)+"</signal>\n");
- v=u;
- if (v>max) max=v;
- if (v<min) min=v;
- }
+float Parameter::get(const Time_spec& time){ //gets input and updates variable
+ if (connection){
+ value = ((Signal_node*)connection)->get_output(time);
}
- xml_out+=("<signal_finished min='"+ofToString(min)+"' max='"+ofToString(max)+"'/>\n");
- return true;
+ return value;
}
-
bool Audio_thumbnailer::init(int _channels,int _bits,int _samples,int _rate) {
//base_audio_processor::init(_channels,_bits,_samples);
channels=_channels;
@@ -162,6 +149,7 @@ string Audio_thumbnailer::print(){
delete enc;
return output.str();
}
+
bool Audio_analysis::init(int _channels,int _bits,int _samples, int _rate) {
//need these to make sense of data
channels=_channels;
@@ -190,7 +178,6 @@ void Audio_analysis::print_features(){
}
cerr<<endl;
}
-
bool Video_output::render(const float duration, const float framerate,const string &output_filename,const string &audio_filename,float& progress,int outW,int outH){
//
@@ -282,11 +269,11 @@ bool Video_loader::load(const string &_filename){
string uri="file://"+_filename;
isLoaded=player.open(uri);
if (isLoaded){
- logger.information("Video_loader loaded "+filename+": "+ofToString(player.getNumberOfFrames())+" frames, "+ofToString(player.getFrameRate())+" fps, "+ofToString(player.getWidth())+"x"+ofToString(player.getHeight()));
+ logger.information("Video_loader loaded "+_filename+": "+ofToString(player.getNumberOfFrames())+" frames, "+ofToString(player.getFrameRate())+" fps, "+ofToString(player.getWidth())+"x"+ofToString(player.getHeight()));
return true;
}
- logger.error("Video_loader failed to load "+filename);
+ logger.error("Video_loader failed to load "+_filename);
return false;
}
@@ -297,15 +284,15 @@ Image* Video_loader::output(const Frame_spec &frame){
//need to cache frames so as to avoid asking for a frame other than the next one.
//need an algorithm to find the previous keyframe and seek forward
- float clipframerate=(framerate==0.0f?player.getFrameRate():framerate);
+ float clipframerate=(parameters["framerate"]->value==0.0f?player.getFrameRate():parameters["framerate"]->value);
- float clipspeed=(clipframerate/frame.framerate)*speed;
+ float clipspeed=(clipframerate/frame.framerate)*parameters["speed"]->value;
int wanted=(((int) ((frame.time*frame.framerate*clipspeed)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1?
if (wanted!=lastframe){
if (!player.fetchFrame(frame.w,frame.h,wanted)) { //seek fail
Logger& logger = Logger::get("Rotor");
- logger.error("Video_loader failed to seek frame "+ofToString(wanted)+" of "+filename);
+ logger.error("Video_loader failed to seek frame "+ofToString(wanted)+" of "+attributes["filename"]->value);
if (image.w>0) return &image; //just return the previous frame if possible
else return nullptr;
@@ -316,22 +303,4 @@ Image* Video_loader::output(const Frame_spec &frame){
return &image;
}
return nullptr;
-};
-/*
-bool CVideo_loader::load(const string &filename){
-
- Poco::Path path;
- string uri="file://"+filename;
- isLoaded=player.open(filename);
- if (isLoaded){
- cerr<<"Rotor::Video_loader: "<<filename<<", "<<player.get(CV_CAP_PROP_FRAME_COUNT)<<" frames "<<", "<<player.get(CV_CAP_PROP_FRAME_WIDTH)<<"x"<<player.get(CV_CAP_PROP_FRAME_HEIGHT)<<endl;
- return true;
- }
- cerr<<"Rotor::Video_loader: failed to load "<<filename<<endl;
- return false;
-}
-Image* CVideo_loader::output(const Frame_spec &frame){
-
- return nullptr;
-};
-*/ \ No newline at end of file
+}; \ No newline at end of file