summaryrefslogtreecommitdiff
path: root/rotord/src/nodes_source.h
blob: 0e37fc74177701788c477a3958546b51b328cc8d (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
#ifndef ROTOR_NODES_SOURCE
#define ROTOR_NODES_SOURCE

#include "rotor.h"

namespace Rotor {
	class Signal_colour: public Image_node {
		public:
			Signal_colour(){
				create_signal_input("Selector","Selector input");
				create_attribute("palette","palette list of web colours","Colour palette","000000");
				title="Signal colour";
				description="Cycles through a palette of background colours according to selector signal";
				NODEID="a2183fe0-2d09-11e3-9a64-538ee2cf40bc";
			};
			Signal_colour(map<string,string> &settings):Signal_colour() {
				base_settings(settings);
				for (uint32_t i=0;i<attributes["palette"]->value.size()/6;i++){
					palette.push_back(Colour(attributes["palette"]->value.substr(i*6,6)));
				}
				prevcol=-1;
			};
			~Signal_colour(){};
			Image *output(const Frame_spec &frame){
				if (palette.size()) {
					int col=((int)inputs[0]->get((Time_spec)frame))%palette.size();
					//if (col!=prevcol) cerr<<"colour now "<<palette[col].r<<","<<palette[col].g<<","<<palette[col].b<<endl;
					//if (col!=prevcol){ //how about when starting a new render?
						for (int i=0;i<image.w*image.h;i++){
							image.RGBdata[i*3]=palette[col].r;
							image.RGBdata[i*3+1]=palette[col].g;
							image.RGBdata[i*3+2]=palette[col].b;
						}
						prevcol=col;
					//}
					return &image;
				}
				return nullptr;
			}
			Signal_colour* clone(map<string,string> &_settings) { return new Signal_colour(_settings);};
		private:
			vector<Colour> palette;
			int prevcol;
	};
	class Signal_greyscale: public Image_node {
		//Draws signal bars in greyscale
		public:
			Signal_greyscale(){
				create_signal_input("Signal","Signal input");
				title="Signal greyscale";
				description="Renders signal level as greyscale background";
				NODEID="ae91b8a0-2d09-11e3-aa7d-8b7f1ef1a439";
			};
			Signal_greyscale(map<string,string> &settings):Signal_greyscale() {
				base_settings(settings);
				prevcol=-1;
			};
			~Signal_greyscale(){};
			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;
					//}
					prevcol=col;
					memset(image.RGBdata,col,image.w*image.h*3);
				}
				return &image;

			}
			Signal_greyscale* clone(map<string,string> &_settings) { return new Signal_greyscale(_settings);};
		private:
			uint8_t prevcol;
	};
}
#endif