summaryrefslogtreecommitdiff
path: root/rotord/src
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-10-15 00:49:21 -0700
committerComment <tim@gray.(none)>2013-10-15 00:49:21 -0700
commit9d6fe33bea0f070356d02a9196e9dfbfa3d0cf8d (patch)
tree82f3ebc7972a8746f7659660b741ae3d7c7628bb /rotord/src
parent514624508d16f6a3f3e6419479642acc931b0f52 (diff)
noise node
Diffstat (limited to 'rotord/src')
-rw-r--r--rotord/src/graph.cpp15
-rw-r--r--rotord/src/graph.h2
-rw-r--r--rotord/src/nodes_maths.h19
-rw-r--r--rotord/src/nodes_source.h7
-rw-r--r--rotord/src/rendercontext.cpp6
-rw-r--r--rotord/src/rotor.cpp99
-rw-r--r--rotord/src/rotor.h2
7 files changed, 85 insertions, 65 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp
index 5f63a0b..9f90486 100644
--- a/rotord/src/graph.cpp
+++ b/rotord/src/graph.cpp
@@ -24,10 +24,21 @@ Node* Graph::find_node(const string &type){
}
return nullptr; //can be tested against
};
-bool Graph::signal_render(string &signal_xml,const float framerate) {
+bool Graph::signal_render(xmlIO &XML,const float framerate) {
if (find_node("signal_output")) {
Signal_output *signal_output=dynamic_cast<Signal_output*>(find_node("signal_output"));
- return signal_output->render(duration,framerate,signal_xml);
+ //return signal_output->render(duration,framerate,signal_xml);
+ float sig=0.0f;
+ string val="";
+ for (float i=0;i<duration;i+=1.0f/framerate){
+ float s=(signal_output->get_output(Time_spec(i,framerate,duration))+1.0f)/10.0f;
+ if (!fequal(sig,s)){
+ val+=toString(i)+":"+toString(s)+" ";
+ sig=s;
+ }
+ }
+ XML.addValue("signal",val);
+ return true;
}
cerr<<"Rotor: signal output node not found"<<endl;
diff --git a/rotord/src/graph.h b/rotord/src/graph.h
index e40d753..5e3d1cd 100644
--- a/rotord/src/graph.h
+++ b/rotord/src/graph.h
@@ -44,7 +44,7 @@ namespace Rotor {
std::unordered_map<string,Node*> nodes;
vector<Node*> find_nodes(const string &type); //could be a way of finding a set based on capabilities?
Node* find_node(const string &type);
- bool signal_render(string &signal_xml,const float framerate);
+ bool signal_render(xmlIO &XML,const float framerate);
bool video_render(const string &output_filename,const float framerate,int start, int end);
bool load(string data,string media_path);
bool loadFile(string &filename,string media_path);
diff --git a/rotord/src/nodes_maths.h b/rotord/src/nodes_maths.h
index 07f111b..2696b2e 100644
--- a/rotord/src/nodes_maths.h
+++ b/rotord/src/nodes_maths.h
@@ -6,6 +6,8 @@
#include <libnoise/mathconsts.h>
#include "Poco/Logger.h"
+using namespace noise;
+
namespace Rotor {
#define COMPARISON_Equal 1
#define COMPARISON_Not_equal 2
@@ -233,22 +235,27 @@ namespace Rotor {
description="Fractal noise (seedable)";
create_signal_input("signal","Signal");
create_parameter("seed","number","Seed value","Seed",1.0f);
+ create_parameter("octaves","number","Octaves of noise","octaves",6.0f);
+ create_parameter("frequency","number","Frequency of noise","frequency",1.0f);
+ create_parameter("scale","number","scale of noise","scale",1.0f);
UID="28b3c154-2d0b-11e3-bdf2-1b9b2678a2f6";
};
Noise(map<string,string> &settings):Noise() {
base_settings(settings);
- seed=find_setting(settings,"seed",0);
};
Noise* clone(map<string,string> &_settings) { return new Noise(_settings);};
const float output(const Time_spec &time) {
- uint32_t seed=Seed+parameters["seed"]->value;
- //hash the integer part and add the fractional part back on
- float o=inputs[0]->get(time);
- uint32_t m=(int)o;
- return ((float)(fnv1a(m,seed)%((uint32_t)time.duration)))+(o-m);
+ perlin.SetOctaveCount(parameters["octaves"]->value);
+ perlin.SetFrequency(parameters["frequency"]->value);
+ perlin.SetSeed(Seed+parameters["seed"]->value);
+ if (inputs[0]->connection){
+ return perlin.GetValue(inputs[0]->get(time),0,0)*parameters["scale"]->value;
+ }
+ return perlin.GetValue(time.time,0,0)*parameters["scale"]->value;
}
uint32_t seed;
private:
+ module::RidgedMulti perlin;
};
}
diff --git a/rotord/src/nodes_source.h b/rotord/src/nodes_source.h
index 3ce9fdd..37c3b61 100644
--- a/rotord/src/nodes_source.h
+++ b/rotord/src/nodes_source.h
@@ -58,10 +58,11 @@ namespace Rotor {
Image *output(const Frame_spec &frame){
uint8_t col=((uint8_t)(inputs[0]->get((Time_spec)frame)*255.0f));
if (col!=prevcol){ //how about when starting a new render?
- for (int i=0;i<image.w*image.h*3;i++){
- image.RGBdata[i]=col;
- }
+ //for (int i=0;i<image.w*image.h*3;i++){
+ // image.RGBdata[i]=col;
+ //}
prevcol=col;
+ memset(image.RGBdata,col,image.w*image.h*3);
}
return &image;
diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp
index 86331b4..bba8d31 100644
--- a/rotord/src/rendercontext.cpp
+++ b/rotord/src/rendercontext.cpp
@@ -302,11 +302,11 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H
//if (command.size()>2) {
// framerate=toFloat(command.id);
//}
- string signal_xml;
- if (graph.signal_render(signal_xml,framerate)){
+ //string signal_xml;
+ if (graph.signal_render(XML,framerate)){
status=HTTPResponse::HTTP_OK;
logger.information("rendering signal to xml");
- XML.addValue("signal",signal_xml); //this doesn't work >> pseudo xml
+ //XML.addValue("signal",signal_xml); //this doesn't work >> pseudo xml
}
else {
status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR;
diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp
index 444d861..26fc4a4 100644
--- a/rotord/src/rotor.cpp
+++ b/rotord/src/rotor.cpp
@@ -14,62 +14,63 @@ using Poco::Logger;
Node_factory::Node_factory(){
//for now, statically load prototype map in constructor
- //how to deal with categories
- //have an associative array of arrays of pointers to nodes, "categories"
+ //how to deal with category
+ //have an associative array of arrays of pointers to nodes, "category"
//this can be hard coded also
//
- categories["signals"]=vector<Node*>();
- add_type("time",new Time(),categories["signals"]);
- add_type("track_time",new Track_time(),categories["signals"]);
- add_type("at_track_time",new At_track_time(),categories["signals"]);
+ category["signals"]=vector<Node*>();
+ add_type("time",new Time(),category["signals"]);
+ add_type("track_time",new Track_time(),category["signals"]);
+ add_type("at_track_time",new At_track_time(),category["signals"]);
//
add_type("signal_output",new Signal_output());
add_type("testcard",new Testcard());
//
- categories["channels"]=vector<Node*>();
- add_type("invert",new Invert(),categories["channels"]);
- add_type("monochrome",new Monochrome(),categories["channels"]);
- add_type("blend",new Blend(),categories["channels"]);
- add_type("image_arithmetic",new Image_arithmetic(),categories["channels"]);
- add_type("alpha_merge",new Alpha_merge(),categories["channels"]);
- add_type("difference_matte",new Difference_matte(),categories["channels"]);
- add_type("rgb_levels",new RGB_levels(),categories["channels"]);
- add_type("luma_levels",new Luma_levels(),categories["channels"]);
+ category["channels"]=vector<Node*>();
+ add_type("invert",new Invert(),category["channels"]);
+ add_type("monochrome",new Monochrome(),category["channels"]);
+ add_type("blend",new Blend(),category["channels"]);
+ add_type("image_arithmetic",new Image_arithmetic(),category["channels"]);
+ add_type("alpha_merge",new Alpha_merge(),category["channels"]);
+ add_type("difference_matte",new Difference_matte(),category["channels"]);
+ add_type("rgb_levels",new RGB_levels(),category["channels"]);
+ add_type("luma_levels",new Luma_levels(),category["channels"]);
- categories["source"]=vector<Node*>();
- add_type("signal_colour",new Signal_colour(),categories["source"]);
- add_type("signal_greyscale",new Signal_greyscale(),categories["source"]);
- add_type("shape",new Shape(),categories["source"]);
- add_type("text",new Text(),categories["source"]);
- add_type("waves",new Waves(),categories["source"]);
- add_type("still_image",new Still_image(),categories["source"]);
- add_type("video_loader",new Video_loader(),categories["source"]);
+ category["source"]=vector<Node*>();
+ add_type("signal_colour",new Signal_colour(),category["source"]);
+ add_type("signal_greyscale",new Signal_greyscale(),category["source"]);
+ add_type("shape",new Shape(),category["source"]);
+ add_type("text",new Text(),category["source"]);
+ add_type("waves",new Waves(),category["source"]);
+ add_type("still_image",new Still_image(),category["source"]);
+ add_type("video_loader",new Video_loader(),category["source"]);
- categories["distort"]=vector<Node*>();
- add_type("mirror",new Mirror(),categories["distort"]);
- add_type("transform",new Transform(),categories["distort"]);
+ category["distort"]=vector<Node*>();
+ add_type("mirror",new Mirror(),category["distort"]);
+ add_type("transform",new Transform(),category["distort"]);
- categories["editing"]=vector<Node*>();
- add_type("video_cycler",new Video_cycler(),categories["editing"]);
- add_type("video_output",new Video_output(),categories["editing"]);
- add_type("act_segmenter",new Act_segmenter(),categories["editing"]);
+ category["editing"]=vector<Node*>();
+ add_type("video_cycler",new Video_cycler(),category["editing"]);
+ add_type("video_output",new Video_output(),category["editing"]);
+ add_type("act_segmenter",new Act_segmenter(),category["editing"]);
- categories["audio"]=vector<Node*>();
- add_type("audio_analysis",new Audio_analysis(),categories["audio"]);
+ category["audio"]=vector<Node*>();
+ add_type("audio_analysis",new Audio_analysis(),category["audio"]);
- categories["maths"]=vector<Node*>();
- add_type("comparison",new Comparison(),categories["maths"]); //TODO: alias to symbols
- add_type("arithmetic",new Arithmetic(),categories["maths"]); //TODO: alias to symbols
- add_type("bang",new Is_new_integer(),categories["maths"]);
- add_type("on_off",new On_off(),categories["maths"]);
- add_type("random",new Random(),categories["maths"]);
+ category["maths"]=vector<Node*>();
+ add_type("comparison",new Comparison(),category["maths"]); //TODO: alias to symbols
+ add_type("arithmetic",new Arithmetic(),category["maths"]); //TODO: alias to symbols
+ add_type("bang",new Is_new_integer(),category["maths"]);
+ add_type("on_off",new On_off(),category["maths"]);
+ add_type("random",new Random(),category["maths"]);
+ add_type("noise",new Noise(),category["maths"]);
- categories["fx"]=vector<Node*>();
- add_type("blur",new Blur(),categories["fx"]);
- add_type("vhs",new VHS(),categories["fx"]);
- add_type("echo_trails",new Echo_trails(),categories["fx"]);
- add_type("video_feedback",new Video_feedback(),categories["fx"]);
+ category["fx"]=vector<Node*>();
+ add_type("blur",new Blur(),category["fx"]);
+ add_type("vhs",new VHS(),category["fx"]);
+ add_type("echo_trails",new Echo_trails(),category["fx"]);
+ add_type("video_feedback",new Video_feedback(),category["fx"]);
}
bool Signal_input::connect(Node* source) {
@@ -185,12 +186,12 @@ void Node_factory::list_nodes(xmlIO XML){
}
void Node_factory::list_categories(xmlIO XML){
int i=0;
- for (auto& category: categories) {
+ for (auto& _category: category) {
XML.addTag("category");
- XML.addAttribute("category","name",category.first,i);
+ XML.addAttribute("category","name",_category.first,i);
XML.pushTag("category",i);
int j=0;
- for (auto& node: category.second){
+ for (auto& node: _category.second){
list_node(node,XML,j);
j++;
}
@@ -199,8 +200,8 @@ void Node_factory::list_categories(xmlIO XML){
}
}
void Node_factory::list_categories(Json::Value &JSON){
- JSON["categories"]=Json::arrayValue;
- for (auto& _category: categories) {
+ JSON["category"]=Json::arrayValue;
+ for (auto& _category: category) {
Json::Value category;
category["name"]=_category.first;
category["nodes"]=Json::arrayValue;
@@ -268,7 +269,7 @@ void Node_factory::list_categories(Json::Value &JSON){
}
category["nodes"].append(node);
}
- JSON["categories"].append(category);
+ JSON["category"].append(category);
}
}
void Node_factory::list_nodes(Json::Value &JSON){
diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h
index 7a746cc..2d66d51 100644
--- a/rotord/src/rotor.h
+++ b/rotord/src/rotor.h
@@ -706,7 +706,7 @@ namespace Rotor {
void list_categories(Json::Value &JSON);
private:
unordered_map<string,Node*> type_map;
- unordered_map<string,vector<Rotor::Node*> > categories;
+ unordered_map<string,vector<Rotor::Node*> > category;
};
}