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
|
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
int midiPort=0;
midiChannel=0;
int numLayers=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);
if(XML.pushTag("liveEngine")) {
numLayers=XML.getNumTags("svglayer");
if(numLayers) {
for (int i=0;i<numLayers;i++) {
string s=XML.getAttribute("svglayer", "file", "",i);
printf("loading %s: ",s.c_str());
layers[XML.getAttribute("svglayer", "note", 0,i)]=new svglayer(XML.getAttribute("svglayer", "file", "",i));
}
}
else printf("no layers loaded!\n");
}
}
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;
controller_colours=new ofColor[NUM_CONTROLLERS];
for (int i=0;i<NUM_CONTROLLERS;i++) controller_colours[i]=ofColor::fromHsb(ofRandom(255), 255, 255);
//grab.allocate(ofGetWidth(), ofGetHeight(),OF_IMAGE_COLOR_ALPHA);
grab.setUseTexture(true);
showFPS=false;
ofBackground(0,0,0);
//ofSetVerticalSync(true); deosn't seem effective
//glXSwapIntervalSGI(1);
}
//--------------------------------------------------------------
void testApp::update(){
//for (int i=0;i<numLayers;i++) layers[i]->update();
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetColor(255,255,255);
grab.grabScreen( 0, 0, ofGetWidth(), ofGetHeight() );
grab.update();
grab.reloadTexture();
ofBackground(0,0,0);
//grab.draw( 1,1);
float notewidth=ofGetWidth()/NUM_NOTES;
float noteheight=ofGetHeight()/NUM_CONTROLLERS;
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*notewidth,i*noteheight,notewidth,noteheight);
}
ofSetColor((sin(ofGetElapsedTimef())+1)*128,255,255);
ofPushMatrix();
//ofScale(sin(ofGetElapsedTimef())+1.1,sin(ofGetElapsedTimef())+1.1);
if (layers.find(note)!=layers.end()) layers[note]->draw();
ofPopMatrix();
//for (int i=0;i<numLayers;i++) layers[i]->draw();
ofSetColor(255,255,255);
if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
if(key == 's'){
XML.saveFile("settings.xml");
printf("settings saved!\n");
}
if(key == 'f'){
toggleFPS();
}
}
//--------------------------------------------------------------
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::dragEvent(ofDragInfo dragInfo){
}
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);
//}
printf("note: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo);
note=eventArgs.byteOne-START_NOTE;
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);
//}
printf("cc: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo);
controllers[eventArgs.byteOne-START_CONTROLLER]=eventArgs.byteTwo;
}
}
}
|