From fc9b92ea1ab78e8f8b441cef2416eb73472ff106 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 23 May 2014 09:45:50 +0100 Subject: variable type getter/setter --- NT/src/nodes.h | 17 ++++------------- NT/src/nodes_source.h | 31 +++++++++++++++++-------------- NT/src/rotor.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 27 deletions(-) (limited to 'NT') diff --git a/NT/src/nodes.h b/NT/src/nodes.h index f6a8a0d..eaf857b 100644 --- a/NT/src/nodes.h +++ b/NT/src/nodes.h @@ -3,21 +3,12 @@ #include "rotor.h" #include "nodes_audio_analysis.h" +#include "nodes_source.h" using namespace std; namespace Rotor{ - typedef Node_type Number_node; - typedef Node_type String_node; - typedef Node_type Image_node; - typedef Variable_type Number_inlet; - typedef Variable_type String_inlet; - typedef Variable_type Image_inlet; - - typedef Variable_array_type Number_array; - typedef Variable_array_type String_array; - typedef Variable_array_type Image_array; //colour node could be an alias of vec3f node and they could be interchangeable? @@ -46,7 +37,7 @@ namespace Rotor{ Time* clone(Json::Value &_settings) { return new Time(_settings);}; private: }; - class Multiply: public Double_node { + class Multiply: public Number_node { public: Multiply(){ factors=create_array("factors","Factors to multiply","Factors"); @@ -73,7 +64,7 @@ namespace Rotor{ } Multiply* clone(Json::Value &_settings) { return new Multiply(_settings);}; private: - Double_array *factors; + Number_array *factors; }; class Print: public String_node { public: @@ -96,7 +87,7 @@ namespace Rotor{ } Print* clone(Json::Value &_settings) { return new Print(_settings);}; private: - Double_inlet *inlet; + Number_inlet *inlet; }; } diff --git a/NT/src/nodes_source.h b/NT/src/nodes_source.h index ede0dcb..ffc826f 100644 --- a/NT/src/nodes_source.h +++ b/NT/src/nodes_source.h @@ -10,45 +10,48 @@ namespace Rotor { //1 - a data type which is a variable length array of data [as opposed to a array of inlets] //2 - a way to initialise this from json //enum - this is a hack to achieve this? designed for option selectors, can it work here? - //or just parse a string into a list of colours? + + //for now: just parse a string into a list of colours + Signal_colour(){ selector=create_inlet("selector"); - palette=create_inlet("palette","colour to choose from palette","Palette","000000") + palette=create_inlet("palette","colour to choose from palette","Palette","000000"); //create_attribute("palette","palette list of web colours","Colour palette","000000"); + type="signal_colour"; title="Signal colour"; description="Cycles through a palette of background colours according to selector signal"; - NODEID="a2183fe0-2d09-11e3-9a64-538ee2cf40bc"; + type_id="a2183fe0-2d09-11e3-9a64-538ee2cf40bc"; }; - Signal_colour(map &settings):Signal_colour() { - base_settings(settings); - for (uint32_t i=0;ivalue.size()/6;i++){ - palette.push_back(Colour(attributes["palette"]->value.substr(i*6,6))); + Signal_colour(Json::Value &settings):Signal_colour() { + init(settings); + for (uint32_t i=0;ivalue.substr(i*6,6))); } prevcol=-1; }; ~Signal_colour(){}; - Image *output(const Frame_spec &frame){ + const Image &output(const Frame_parameters &frame){ if (palette.size()) { int col=((int)inputs[0]->get((Time_spec)frame))%palette.size(); //if (col!=prevcol) cerr<<"colour now "< &_settings) { return new Signal_colour(_settings);}; private: - vector palette; + vector colours; int prevcol; Number_inlet *selector; - Enum_inlet *palette; + String_inlet *palette; }; /* class Signal_greyscale: public Image_node { diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 59533f5..6ed3b67 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -90,6 +90,33 @@ namespace Rotor { class Node; template class Node_type; + class Colour{ + public: + Colour(){ + r=g=b=0; + } + Colour(int c){ + r=c&0xFF; + g=(c&0xFF00)>>8; + b=(c&0xFF0000)>>16; + } + Colour(std::string s){ + r=(uint8_t)hexToChar(s.substr(0,2)); + g=(uint8_t)hexToChar(s.substr(2,2)); + b=(uint8_t)hexToChar(s.substr(4,2)); + } + double Rdouble(){ + return ((double)r)/255.0; + } + double Gdouble(){ + return ((double)g)/255.0; + } + double Bdouble(){ + return ((double)b)/255.0; + } + uint8_t r,g,b; + }; + class Enum{ //enumerated string type for node options that can appear in a menu public: @@ -215,6 +242,9 @@ namespace Rotor { void set(const T& val){ value=val; } + const T& get(){ + return value; + } bool create_connection(std::unordered_map &nodes){ for (auto node:nodes){ if (node.first==input){ @@ -360,6 +390,18 @@ namespace Rotor { protected: NT result; //internal value is returned as a reference }; + + typedef Node_type Number_node; + typedef Node_type String_node; + typedef Node_type Image_node; + + typedef Variable_type Number_inlet; + typedef Variable_type String_inlet; + typedef Variable_type Image_inlet; + + typedef Variable_array_type Number_array; + typedef Variable_array_type String_array; + typedef Variable_array_type Image_array; } #endif //ROTOR_H -- cgit v1.2.3