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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
#include "testApp.h"
previewWindow::~previewWindow(){
cout << "preview window destroyed" << endl;
}
void previewWindow::setup(){}
void previewWindow::setBuffer(ofFbo *buffer){
rb=buffer;
}
void previewWindow::draw(){
rb->draw(0,0,ofGetWidth(),ofGetHeight());
}
//--------------------------------------------------------------
guiWindow::~guiWindow(){
cout << "gui window destroyed" << endl;
}
void guiWindow::setup(){}
void guiWindow::setParent(testApp *p){
parent=p;
}
void guiWindow::draw(){
parent->gui.draw();
}
void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){
printf("gui received file:%s\n",dragInfo.files[0].c_str());
}
//--------------------------------------------------------------
void testApp::setup(){
int midiPort=0;
midiChannel=0;
if( !XML.loadFile("settings.xml") ){
printf("unable to load settings.xml check data/ folder\n");
}else{
printf("settings loaded!\n");
midiPort=ofToInt(XML.getAttribute("liveEngine", "port", "0")); //default to 0/all
midiChannel=ofToInt(XML.getAttribute("liveEngine", "channel", "0"));
if (midiChannel) printf("listening on port %d, midi channel %d\n",midiPort,midiChannel);
else printf("listening on port %d, all midi channels\n",midiPort);
}
midiIn.listPorts();
midiIn.openPort(midiPort);
midiIn.addListener(this);
// to register only to one controller pass the id as first argument
// midiIn.addListener(84,this);
// to debug
// midiIn.setVerbose(true);
controllers=new unsigned char[NUM_CONTROLLERS];
memset(controllers,NUM_CONTROLLERS,0);
note=0;
makeColours();
colShift=0;
controlColours=false;
debug=false;
noteRandomiseColours=false;
transparentBlack=false;
reversemain=false;
vp1.setup(768,1024,1024,0,-90,-256,-384);
vp2.setup(1024,768,0,0,0,-512,-384);
showFPS=false;
ofBackground(0,0,0);
ofSetBackgroundAuto(false);
xshift=-1;
yshift=-1;
fadetime=0;
mode=BLOCKS;
lastnoteTime=ofGetElapsedTimef();
decayTime=1.0f;
//ofSetVerticalSync(true); deosn't seem effective
//glXSwapIntervalSGI(1);
/*
printf("hue of red is %f\n",ofColor(255,0,0).getHue());
printf("hue of green is %f\n",ofColor(0,255,0).getHue());
printf("hue of blue is %f\n",ofColor(0,0,255).getHue());
hue is float from 0.0-255.0
*/
ofSetFrameRate(60);
rotate=-90;
scale=1.0f;
fscale=1.0f;
//preview window stuff
prevWin=new previewWindow();
win=ofxFensterManager::get()->createFenster(0, 0, 600, 800, OF_WINDOW);
ofAddListener(win->events.mouseDragged, this, &testApp::mousePressedEvent);
ofAddListener(win->events.mousePressed, this, &testApp::mousePressedEvent);
ofAddListener(win->events.keyPressed, this, &testApp::keyPressedEvent);
ofAddListener(win->events.fileDragEvent, this, &testApp::refDragEvent);
win->setWindowTitle("preview");
win->addListener(prevWin);
prevWin->setup();
prevWin->setBuffer(&vp1.rb2);
fullscreenoutput=false;
guiWin=new guiWindow();
gui.setup("","panel.xml",0,0);
gui.add(reversemain.setup("reverse main", false));
gui.add(controlColours.setup("control colours", false));
gui.add(noteRandomiseColours.setup("randomise note colours", false));
gui.add(transparentBlack.setup("transparent black", false));
gui.add(resetDrawscale.setup("reset draw scale"));
gui.add(resetFBscale.setup("reset FB scale"));
resetDrawscale.addListener(this,&testApp::resetDrawscalePressed);
resetFBscale.addListener(this,&testApp::resetFBscalePressed);
//gui window stuff
ofxFenster* win2=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW);
ofAddListener(win2->events.fileDragEvent, this, &testApp::refDragEvent);
//ofAddListener(win2->events.mousePressed, 0, &testApp::mousePressedEvent);
//ofAddListener(win2->events.keyPressed, this, &testApp::keyPressedEvent);
win2->setWindowTitle("config");
win2->addListener(guiWin);
guiWin->setup();
guiWin->setParent(this);
}
void testApp::resetDrawscalePressed(bool & pressed){
scale=1.0f;
}
void testApp::resetFBscalePressed(bool & pressed){
fscale=1.0f;
}
void testApp::makeColours() {
controller_colours=new ofColor[NUM_CONTROLLERS];
for (int i=0;i<NUM_CONTROLLERS;i++) controller_colours[i]=ofColor::fromHsb(ofRandom(255), 255, 255);
colShift=ofRandom(255.0f);
}
//--------------------------------------------------------------
void testApp::update(){
//for (int i=0;i<numLayers;i++) layers[i]->update();
}
//--------------------------------------------------------------
void testApp::draw(){
float lambda=max(0.0f,1.0f-((ofGetElapsedTimef()-lastnoteTime)/decayTime));
ofSetColor(255-fadetime,255-fadetime,255-fadetime); //for feedback
vp1.draw(lambda,controllers,xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,scale,fscale,noteRandomiseColours?colShift:0.0f);
vp2.draw(lambda,controllers,reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,reversemain?1.0f/scale:scale,reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f);
ofSetColor(255,255,255);
if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
/*
rb1.begin();
// can this work?
//grab.setAnchorPoint(xshift,yshift);
//grab.setTextureWrap( GL_WRAP_BORDER, GL_WRAP_BORDER);
//grab.draw(0,0); // xshift,yshift);
ofSetColor(255-fadetime,255-fadetime,255-fadetime);
for (int i=(xshift>0?xshift-rb1.getWidth():xshift);i<rb1.getWidth()*2;i+=ofGetWidth()) {
for (int j=(yshift>0?yshift-rb1.getHeight():yshift);j<rb1.getHeight()*2;j+=rb1.getHeight()) {
rb2.draw(i,j);
}
}
float notewidth=rb1.getWidth()/NUM_NOTES;
float noteheight=rb1.getHeight()/NUM_CONTROLLERS;
if (note>0) {
switch(mode) {
case BLOCKS:
for (int i=0;i<NUM_CONTROLLERS;i++){
ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7));
ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight);
}
break;
case LIST:
if (list.lock()) { //if playlist is loaded
ofPushMatrix();
ofTranslate(rb1.getWidth()/2,rb1.getHeight()/2);
ofScale(scale,scale,scale);
ofRotate(rotate);
ofTranslate(-rb1.getWidth()/2,-rb1.getHeight()/2);
if (list.layers.find(note)!=list.layers.end()) {
if (controlColours) list.layers[note]->draw(lamda,controllers,512,384,transparentBlack);
else list.layers[note]->draw(lamda,512,384);
}
ofPopMatrix();
list.unlock();
}
break;
}
}
//for (int i=0;i<numLayers;i++) layers[i]->draw();
ofSetColor(255,255,255);
if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
rb1.end();
rb2.begin();
ofSetColor(255,255,255);
rb1.draw(0,0);
rb2.end();
rb2.draw(1024,0);
rb3.begin(); //landscape
ofSetColor(255-fadetime,255-fadetime,255-fadetime);
for (int i=(xshift>0?xshift-rb3.getWidth():xshift);i<rb3.getWidth()*2;i+=ofGetWidth()) {
for (int j=(yshift>0?yshift-rb3.getHeight():yshift);j<rb3.getHeight()*2;j+=rb3.getHeight()) {
rb4.draw(i,j);
}
}
notewidth=rb3.getHeight()/NUM_NOTES;
noteheight=rb3.getWidth()/NUM_CONTROLLERS;
ofPushMatrix();
ofTranslate(rb3.getWidth(),rb3.getHeight()/2);
ofRotate(90);
ofTranslate(-rb3.getWidth()/2,-rb3.getHeight()/2);
if (note>0) {
switch(mode) {
case BLOCKS:
for (int i=0;i<NUM_CONTROLLERS;i++){
ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7));
ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight);
}
break;
case LIST:
if (list.lock()) { //if playlist is loaded
ofPushMatrix();
ofTranslate(rb3.getWidth()/2,rb3.getHeight()/2);
ofScale(scale,scale,scale);
ofRotate(rotate);
ofTranslate(-rb3.getWidth()/2,-rb3.getHeight()/2);
if (list.layers.find(note)!=list.layers.end()) {
if (controlColours) list.layers[note]->draw(lamda,controllers,512,384,transparentBlack);
else list.layers[note]->draw(lamda,512,384);
}
ofPopMatrix();
list.unlock();
}
break;
}
}
ofPopMatrix();
//for (int i=0;i<numLayers;i++) layers[i]->draw();
ofSetColor(255,255,255);
if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
rb3.end();
rb4.begin();
ofSetColor(255,255,255);
rb3.draw(0,0);
rb4.end();
rb4.draw(0,0);
*/
/* test screen shape
ofSetColor(255,0,0);
ofRect(0,0,1024,768);
ofSetColor(0,255,0);
ofRect(1024,0,1024,768);
*/
}
//--------------------------------------------------------------
void testApp::keyPressed(int key, ofxFenster* win){
if(key == ' '){
fullscreenoutput=!fullscreenoutput;
win->setFullscreen(fullscreenoutput);
printf("resolution: %ix%i %s\n",win->getWidth(),win->getHeight(),fullscreenoutput?"fullscreen":"windowed");
}
else keyPressed(key);
}
void testApp::keyPressed(int key){
if(key == 'q'){
list.load("insects.xml");
}
if(key == 'Q'){
list.load("birds.xml");
}
if(key == 'w'){
list.load("teamsports.xml");
}
if(key == 'W'){
list.load("american_football.xml");
}
if(key == 'e'){
list.load("organs.xml");
}
if(key == 'E'){
list.load("crests.xml");
}
if(key == 'r'){
list.load("tai_chi.xml");
}
if(key == 'R'){
list.load("cricket.xml");
}
if(key == 't'){
list.load("reptiles.xml");
}
if(key == 'T'){
list.load("tools.xml");
}
if(key == 'y'){
list.load("miltary_ladies.xml");
}
if(key == 'Y'){
list.load("women_ethnic.xml");
}
if(key == 'u'){
list.load("knights.xml");
}
if(key == 'U'){
list.load("food.xml");
}
if(key == 'i'){
list.load("mil_historic.xml");
}
if(key == 'I'){
list.load("mil_ethnic.xml");
}
if(key == 'o'){
list.load("yoga.xml");
}
if(key == 'O'){
list.load("computers.xml");
}
if(key == 'p'){
list.load("dancing.xml");
}
if(key == 'P'){
list.load("trainers.xml");
}
if(key == 's'){
XML.saveFile("settings.xml");
printf("settings saved!\n");
}
if(key == 'f'){
toggleFPS();
}
if(key >='0' && key <= '9'){
mode=key-'0';
}
if(key == 267){
xshift--;
}
if(key == 268){
xshift++;
}
if(key == 269){
yshift--;
}
if(key == 270){
yshift++;
}
if(key == '='){
makeColours();
}
if(key == '+'){
fadetime=min(128,fadetime+1);
}
if(key == '_'){
fadetime=max(0,fadetime-1);
}
if(key == ']'){
scale*=1.01;
}
if(key == '['){
scale/=1.01;
}
if(key == '}'){
rotate+=90;
}
if(key == '{'){
rotate-=90;
}
if(key == 'd'){
debug=!debug;
}
if (key=='j') {
fscale=1.0f;
}
if (key=='h') {
scale=1.0f;
}
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
void testApp::mousePressed(int x, int y, int button) {
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::refDragEvent(ofDragInfo &dragInfo){
dragEvent(dragInfo);
}
void testApp::dragEvent(ofDragInfo dragInfo, ofxFenster* win){
dragEvent(dragInfo);
}
void testApp::dragEvent(ofDragInfo dragInfo){
printf("received file:%s\n",dragInfo.files[0].c_str());
}
void testApp::mousePressedEvent(ofMouseEventArgs &args) {
//printf("mouse: %i,%i %i of %ix%i\n",args.x,args.y,args.button,win->getWidth(),win->getHeight());
//0-2
switch (args.button) {
case 0:
xshift=args.x-(win->getWidth()/2);
yshift=args.y-(win->getHeight()/2);
break;
case 1:
scale=pow(pow(args.x-(win->getWidth()/2),2)+pow(args.y-(win->getHeight()/2),2),0.5)/(win->getWidth()*.1);
break;
case 2:
fscale=(pow(pow(args.x-(win->getWidth()/2),2)+pow(args.y-(win->getHeight()/2),2),0.5)/(win->getWidth()))+0.5;
break;
}
}
void testApp::keyPressedEvent(ofKeyEventArgs &args) {
//printf("window key pressed: %i (%c)\n",args.key,args.key);
keyPressed(args.key);
}
void testApp::toggleFPS(){
showFPS=!showFPS;
}
void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){
//newMessage(eventArgs.port, eventArgs.channel, eventArgs.byteTwo, eventArgs.timestamp);
//byteOne : message type
/*
int port;
int channel;
int status;
int byteOne;
int byteTwo;
double timestamp;
*/
//printf("%d %d %d %d %d\n",eventArgs.port,eventArgs.channel,eventArgs.status,eventArgs.byteOne,eventArgs.byteTwo);
bool noteOn; //this old thing!
if ((midiChannel==0)||(eventArgs.channel==midiChannel)) {
switch(eventArgs.status) {
case 144: //noteon-off channel 0
noteOn=(eventArgs.byteTwo==0?false:true);
//for (int i=0;i<numLayers;i++){
// if (layers[i]->note==eventArgs.byteOne) layers[i]->setActive(noteOn);
//}
if (debug) printf("note: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo);
note=eventArgs.byteOne;
lastnoteTime=ofGetElapsedTimef();
if (noteRandomiseColours) {
makeColours(); //
}
break;
case 176: //control change channel 0
//for (int i=0;i<numLayers;i++){
// if (layers[i]->mix==eventArgs.byteOne) layers[i]->setMixAmt(((float)eventArgs.byteTwo)/127.0f);
//}
if (debug) printf("cc: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo);
controllers[eventArgs.byteOne-START_CONTROLLER]=eventArgs.byteTwo;
}
}
}
|