summaryrefslogtreecommitdiff
path: root/pluginchooser/src/pluginpanel.h
blob: 82c7e46bc458d521e933a94753014b2427d9fdb9 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma once

#include "ofMain.h"
#include "ofxGui.h"
#include "ofxAChaoslib.h"

struct float_param {
	public:
		string name;
		float val;
		float min;
		float max;
};

class loader {
public:
	loader(string _n,AChaosBase *_plugin,int _dimension,int _input_index,vector<float_param> _params={}){
		name=_n;
		plugin=_plugin;
		dimension=_dimension;
		input_index=_input_index;
		params=_params;
		iv.resize(_params.size()+_dimension);
	}
	string name;
	AChaosBase *plugin;
	vector<float_param> params;
	vector<REAL> iv;
	int dimension;
	int input_index;
	void update(vector<ofParameter<float> > _params){
		int in=input_index==0?dimension:0;
		for (int i=0;i<min(_params.size(),params.size());i++,in++){
			iv[in]=_params[i];
			params[i].val=_params[i];
		}
	}
	ofVec2f calc(ofVec2f point){
		iv[input_index]=point.x;
		iv[input_index+1]=point.y;
		plugin->set(iv);
		plugin->calc();
		vector<REAL> ov=plugin->getVec();
		return ofVec2f(ov[0],ov[1]);
	}
};

/*
some plugins have more or less dimensions of input/output
params are ordered differently
some allow t/dt control

-> tag the first input dimension index
-> tag the first param index
-> tag the number of params

*/

class pluginPanel : public ofxPanel {
	public:
	pluginPanel(){
		ofRegisterKeyEvents(this, defaultEventsPriority);
		plugins={
			//loader("baker",&baker),  //2,1
			loader("clifford",&clifford,
				2,4, //number of dimensions and index
				{ //4,2 a b c d nx ny
					{"a",-1.4f,-2.0f,2.0f},
					{"b",1.6f,-2.0f,2.0f},
					{"c",1.0f,-2.0f,2.0f},
					{"d",0.7f,-2.0f,2.0f}
				}
			),
			//loader("collatz",&collatz),  //3,1
			//loader("duffing",&duffing,{ //7,2 a b w nx ny dt t time, could be real time or magnified
			//	} //seems perfect
			//),
			//loader("ginger",&ginger),  //3,2 seed nx ny maybe
			loader("henon",&henon,  //4,2 a b nx ny perfect	
				2,2,
				{
					{"a",1.4f,-0.0f,2.0f},
					{"b",0.3f,-1.0f,1.0f}
				}
			)
		};
		index=0;
		select();
	}
	bool mouseMoved(ofMouseEventArgs & args){
		if (args.x>getPosition().x&&
			args.x-getPosition().x<getWidth()&&
			args.y>getPosition().y&&
			args.y-getPosition().y<getHeight()){
			if (!isSelected){
				isSelected=true;	
				//setBorderColor(
				setHeaderBackgroundColor(ofColor(255,128,0));
				//ofLog()<<"IN> "<<args.x<<","<<args.y;
			}
		}
		else {
			if (isSelected){
				isSelected=false;
				setHeaderBackgroundColor(ofColor(80,80,80));
				//ofLog()<<"OUT> "<<args.x<<","<<args.y;
			}
		}
	}
	bool keyPressed(ofKeyEventArgs & args){
		if (isSelected){
			//ofLog()<<"plugin KEY> "<<args.key;
			switch(args.key){
				if (plugins.size()){
					case 57356:{ //left
						index-=1;
						if (index<0){
							index=plugins.size()-1;
						}
						select();
						break;
					}
					case 57358:{ //right
						index+=1;
						if (index==plugins.size()){
							index=0;
						}
						select();
						break;
					}
					default:
						break		;
				}
			}
		}
	}
	bool keyReleased(ofKeyEventArgs & args){
		//required in order to call ofRegisterKeyEvents
	}
	void select(){
		ofLog()<<"selected "<<plugins[index].name;
		clear();
		add(label.setup(plugins[index].name));
    	add(active.set("use",false));
    	add(amount.set("amount", 0.0f, -0.1f, 0.1f));
    	params.clear();
    	for (int i=0;i<plugins[index].params.size();i++){
    		ofParameter<float> param;
    		ofLog()<<"creating parameter: "<<plugins[index].params[i].name;
	    	add(param.set(
	    		plugins[index].params[i].name,
	    		plugins[index].params[i].val,
	    		plugins[index].params[i].min,
	    		plugins[index].params[i].max
	    		));
	    	params.push_back(param);
	   	}
	}
	void update(){
		//push params to plugin
		plugins[index].update(params);
	}
	ofVec2f calc(ofVec2f point){
		return plugins[index].calc(point);
	}
private:
	int index;
	bool isSelected;
	ofxLabel label;
	vector <loader> plugins;
	ofParameter<bool> active;
    ofParameter<float> amount;
    vector<ofParameter<float> > params;
    AChaosClifford clifford;
    AChaosHenon henon;
};