summaryrefslogtreecommitdiff
path: root/pluginchooser/src/pluginpanel.h
blob: 6e8e07dc5297e26090b29790b03bdbbeb0f2bbd9 (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
#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,vector<float_param> _params={}){
		name=_n;
		plugin=_plugin;
		params=_params;
	}
	string name;
	AChaosBase *plugin;
	vector<float_param> params;
};

class pluginPanel : public ofxPanel {
	public:
	pluginPanel(){
		ofRegisterKeyEvents(this, defaultEventsPriority);
		plugins={
			loader("baker",&baker),
			loader("clifford",&clifford,{
					{"a",0.0f,-1.0f,1.0f},
					{"b",0.0f,-1.0f,1.0f},
					{"c",0.0f,-1.0f,1.0f},
					{"d",0.0f,-1.0f,1.0f}
				}
			)
		};
		index=0;
		update();
	}
	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;
						}
						update();
						break;
					}
					case 57358:{ //right
						index+=1;
						if (index==plugins.size()){
							index=0;
						}
						update();
						break;
					}
					default:
						break		;
				}
			}
		}
	}
	bool keyReleased(ofKeyEventArgs & args){
		//required in order to call ofRegisterKeyEvents
	}
	void update(){
		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);
	   	}
	}
	ofVec2f calc(ofVec2f point){
		REAL iv[6]={point.x,point.y};
		for (int i=0;i<params.size();i++){
			iv[i+2]=params[i];
		}
		plugins[index].plugin->set(iv);
		plugins[index].plugin->calc();
	}
private:
	int index;
	bool isSelected;
	ofxLabel label;
	vector <loader> plugins;
	ofParameter<bool> active;
    ofParameter<float> amount;
    vector<ofParameter<float> > params;
    AChaosBaker baker;
    AChaosClifford clifford;
};