-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofApp.cpp
More file actions
151 lines (124 loc) · 4.05 KB
/
ofApp.cpp
File metadata and controls
151 lines (124 loc) · 4.05 KB
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
#include "ofApp.h"
#include "ofxPresetsParametersBase.h"
#include "ofxPresets.h"
#include "ofxGui.h"
// use ofxPresetsParametersBase for a more flexible way of setting up a group of parameters
//
//struct Params : public ofxPresetsParametersBase {
//public:
// ofParameter<int> x;
// ofParameter<int> y;
// ofParameter<int> radius;
// ofParameter<ofColor> color;
//
// Params() {
// groupName = "params";
//
// parameterMap["x"] = &x.set("x pos", ofGetWidth() / 2);
// parameterMap["y"] = &y;
// parameterMap["color"] = &color;
// // radius is not added to the map, so it won't be saved
// }
//};
//Params p;
//std::vector<ofxPresetsParametersBase*> allParameters; // when using more than one group, wrap them on a vector
ofParameter<int> x;
ofParameter<int> y;
ofParameter<int> radius;
ofParameter<ofColor> color;
ofParameterGroup params;
ofxPresets manager;
ofxPanel gui;
ofxPanel guiParams;
ofxLabel currentPreset;
ofxLabel instructions;
ofxLabel internalSequence;
ofxLabel playing;
ofParameter<std::string> sequenceInput;
//--------------------------------------------------------------
void ofApp::setup(){
//ofSetLogLevel(OF_LOG_VERBOSE);
// Different ways of setting up the presets
// 1. using ofParameterGroup
params.setName("params");
params.add(x.set("x", ofGetWidth() / 2, 0, ofGetWidth()));
params.add(y.set("y", ofGetHeight() / 2, 0, ofGetHeight()));
params.add(radius.set("radius", 5, 5, 80));
params.add(color.set("color", ofColor::white));
manager.setup(params);
// 2. Use the ofxPresetsParametersBase struct as defined above
//manager.setup(p);
//
// or various in a vector
//allParameters = { &p, &q };
//manager.setup( allParameters );
ofAddListener(manager.transitionFinished, this, &ofApp::onPresetChanged);
gui.setup("sequencer", ofxPanelDefaultFilename, 10, 10);
gui.setPosition(10, 0);
gui.setWidthElements(230);
gui.add(manager.interpolationDuration.set("Transition duration", 2.5f, 0.0f, 20.0f));
gui.add(manager.sequencePresetDuration.set("Preset duration", 0.5f, 0.0f, 20.0f));
gui.add(sequenceInput.set("Sequence", "1, 2*, ?-2"));
gui.add(internalSequence.setup("Internal seq", ""));
gui.add(currentPreset.setup("Current preset", ""));
gui.add(playing.setup("Sequencer playing", ""));
guiParams.setup("params");
guiParams.setPosition(10, ofGetHeight()-260);
guiParams.setWidthElements(100);
guiParams.add(x);
guiParams.add(y);
guiParams.add(radius);
guiParams.add(color);
}
//--------------------------------------------------------------
void ofApp::update(){
manager.update();
currentPreset = ofToString(manager.getCurrentPreset());
internalSequence = ofToString(manager.sequence.get());
playing = ofToString(manager.isPlayingSequence() ? "true" : "false");
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(ofColor::gray);
ofSetColor(color);
ofDrawCircle(x, y, radius);
ofDrawBitmapStringHighlight("Press 1-9 to apply a preset\n<Shift> 1-9 to save into a preset\nS to start a sequence\nC to stop the sequence\nM to mutate", ofGetWidth() - 280, 38);
gui.draw();
guiParams.draw();
}
//--------------------------------------------------------------
void ofApp::keyReleased(ofKeyEventArgs& e) {
if (e.keycode >= '1' && e.keycode <= '9') {
int index = e.keycode - '1' + 1; // convert to int by removing the ascii offset
if (e.hasModifier(OF_KEY_SHIFT)) {
manager.savePreset(index);
}
else {
manager.applyPreset(index);
}
}
if (e.keycode == 'S') {
manager.loadSequence(ofToString(sequenceInput.get()));
manager.playSequence();
}
if (e.keycode == 'C') {
manager.stop();
}
if (e.keycode == 'M') {
manager.mutate();
}
}
//--------------------------------------------------------------
void ofApp::onPresetChanged() {
ofLog() << "Recieving preset changed event";
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int _x, int _y, int button){
x = _x;
y = _y;
}
//--------------------------------------------------------------
void ofApp::mousePressed(int _x, int _y, int button){
x = _x;
y = _y;
}