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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
#include "ofApp.h"
#include "glew.h"
const ofPoint outputWindowSize=ofPoint(1200,900);
//--------------------------------------------------------------
void ofApp::setup(){
midiIn.listInPorts();
//midiIn.openPort(1);
//midiIn.addListener(this);
//TODO make a midi chooser
/*
Detect a MIDI controller
GUI elements all have an L button to learn
Load and save settings for MIDI GUI
*/
load_settings();
madlaser.setup("madlaser",1125,510);
ofSetFrameRate(60);
}
//====================== settings
void ofApp::default_settings(){
//outputScale=1.0f;
}
void ofApp::save_settings(){
//XML.setValue("SCALE", outputScale);
XML.saveFile("settings.xml");
cout << "settings.xml saved!" <<std::endl;
}
void ofApp::load_settings(){
if( XML.loadFile("settings.xml") ){
cout << "settings.xml loaded!" <<std::endl;
}
else{
cout << "unable to load settings.xml"<<std::endl;
}
//outputScale=XML.getValue("SCALE", 1.0f);
}
void ofApp::update(){
svginput.update();
textinput.update();
}
//-------------------------------------------------------------- GUI
void ofApp::draw(){
ofBackground(0);
networkinput.draw();
svginput.draw();
textinput.draw();
switcher.draw();
//process the pipeline
vector<colourPolyline> output;
if (switcher.network){
vector<colourPolyline> networkoutput=networkinput.clipOutput();
output.insert(end(output), begin(networkoutput), end(networkoutput));
}
if (switcher.svg){
vector<colourPolyline> svgoutput=svginput.clipOutput();
output.insert(end(output), begin(svgoutput), end(svgoutput));
}
if (switcher.text){
vector<colourPolyline> textoutput=textinput.clipOutput();
output.insert(end(output), begin(textoutput), end(textoutput));
}
int points=0;
ofPushMatrix();
ofTranslate(825,5);
ofSetColor(255);
ofNoFill();
ofDrawRectangle(0,0,500,500);
ofTranslate(250,250);
ofScale(250.0f);
for (auto poly:output){
poly.draw();
points+=poly.size();
}
ofPopMatrix();
madlaser.panel.draw();
madlaser.drawNormalised(output);
ofSetWindowTitle("laser points: "+ofToString(points));
}
//--------------------------------------------------------------
void ofApp::exit() {
}
//--------------------------------------------------------------
void ofApp::keyPressed(ofKeyEventArgs &args){
if (args.key==OF_KEY_COMMAND){
//commandPressed=true;
}
switch(args.key){
case 'a':{
load_settings();
break;
}
case 'd':{
default_settings();
break;
}
case 's':{
save_settings();
break;
}
}
}
//--------------------------------------------------------------
void ofApp::keyReleased(ofKeyEventArgs &args){
if (args.key==OF_KEY_COMMAND){
//commandPressed=false;
}
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
string filename= *dragInfo.files.begin();
string extension= filename.substr(filename.find_last_of(".") + 1);
if (extension == "svg") {
if (string::npos==filename.find("fonts")){
svginput.load(filename);
}
else {
ofLog()<<"found a font";
textinput.loadFont(filename);
}
} else if (extension == "txt"){
textinput.loadText(filename);
} else if (extension == "plt"){
textinput.loadPalette(filename);
} else {
ofLog()<<"cannot load "<<filename;
}
}
void ofApp::newMidiMessage(ofxMidiMessage& msg) {
//column 0 for general controls
printf("Midi: %i %i %i\n",msg.channel,msg.control,msg.value);
int offset;
//===============================================
offset=0;
if (msg.channel==1&&msg.control==1+offset){
//pot
//xf_rotate=(((float)msg.value)/64.0f)-1.0f;
}
if (msg.channel==1&&msg.control==33+offset){
//pot button
//use_rotate=use_rotate?false:true;
}
if (msg.channel==1&&msg.control==65+offset){
//top button
//rotate_amt=ofRandom(5.0f);
}
if (msg.channel==1&&msg.control==73+offset){
//bottom button
}
if (msg.channel==1&&msg.control==81+offset){
//fader
//laser_intensity=msg.value*2;
}
//===============================================
offset=1;
}
|