summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2013-01-14 20:56:29 +0800
committerrekado <rekado@elephly.net>2013-01-14 21:00:02 +0800
commitde9ff425adc8df348f88505a5a045006f44c6e55 (patch)
treea9e113eed6209d36f39c155816833d7c0e092818 /src
parentf0641c754f3a44d6cdf1d05d1d6bea8b98f43333 (diff)
rewrite `processEvents` as `handle_midi`
Diffstat (limited to 'src')
-rw-r--r--src/mdaPiano.cpp119
-rw-r--r--src/mdaPiano.h3
2 files changed, 56 insertions, 66 deletions
diff --git a/src/mdaPiano.cpp b/src/mdaPiano.cpp
index 7f6833e..d3286c3 100644
--- a/src/mdaPiano.cpp
+++ b/src/mdaPiano.cpp
@@ -73,73 +73,64 @@ void mdaPiano::setParameter(uint32_t index, float value)
}
-uint32_t mdaPiano::processEvents(VstEvents* ev)
-{
- uint32_t npos=0;
+void mdaPiano::handle_midi(uint32_t size, unsigned char* data) {
+#ifdef DEBUG
+ printf("%d\n", data[1]);
+#endif
+
+ //discard invalid midi messages
+ if (size != 3)
+ return;
- for (uint32_t i=0; i<ev->numEvents; i++)
+ //receive on all channels
+ switch(data[0] & 0xf0)
{
- if((ev->events[i])->type != kVstMidiType) continue;
- VstMidiEvent* event = (VstMidiEvent*)ev->events[i];
- char* midiData = event->midiData;
-
- switch(midiData[0] & 0xf0) //status byte (all channels)
- {
- case 0x80: //note off
- notes[npos++] = event->deltaFrames; //delta
- notes[npos++] = midiData[1] & 0x7F; //note
- notes[npos++] = 0; //vel
- break;
-
- case 0x90: //note on
- notes[npos++] = event->deltaFrames; //delta
- notes[npos++] = midiData[1] & 0x7F; //note
- notes[npos++] = midiData[2] & 0x7F; //vel
- break;
-
- case 0xB0: //controller
- switch(midiData[1])
- {
- case 0x01: //mod wheel
- case 0x43: //soft pedal
- muff = 0.01f * (float)((127 - midiData[2]) * (127 - midiData[2]));
- break;
-
- case 0x07: //volume
- volume = 0.00002f * (float)(midiData[2] * midiData[2]);
- break;
-
- case 0x40: //sustain pedal
- case 0x42: //sustenuto pedal
- sustain = midiData[2] & 0x40;
- if(sustain==0)
- {
- notes[npos++] = event->deltaFrames;
- notes[npos++] = SUSTAIN; //end all sustained notes
- notes[npos++] = 0;
- }
- break;
-
- //all sound off
- case 0x78:
- //all notes off
- case 0x7b:
- default:
- for(short v=0; v<NVOICES; v++) {
- voices[v]->reset();
- }
- break;
- }
- break;
-
- default: break;
- }
-
- if(npos>EVENTBUFFER) npos -= 3; //discard events if buffer full!!
- event++; //?
+ case 0x80: //note off
+ notes[npos++] = data[1] & 0x7F; //note
+ notes[npos++] = 0; //vel
+ break;
+
+ case 0x90: //note on
+ notes[npos++] = data[1] & 0x7F; //note
+ notes[npos++] = data[2] & 0x7F; //vel
+ break;
+
+ case 0xB0: //controller
+ switch(data[1])
+ {
+ case 0x01: //mod wheel
+ case 0x43: //soft pedal
+ muff = 0.01f * (float)((127 - data[2]) * (127 - data[2]));
+ break;
+
+ case 0x07: //volume
+ volume = 0.00002f * (float)(data[2] * data[2]);
+ break;
+
+ case 0x40: //sustain pedal
+ case 0x42: //sustenuto pedal
+ sustain = data[2] & 0x40;
+ if(sustain==0)
+ {
+ notes[npos++] = SUSTAIN; //end all sustained notes
+ notes[npos++] = 0;
+ }
+ break;
+
+ //all sound off
+ case 0x78:
+ //all notes off
+ case 0x7b:
+ default:
+ for(short v=0; v<NVOICES; v++) {
+ voices[v]->reset();
+ }
+ break;
+ }
+ break;
+
+ default: break;
}
- notes[npos] = EVENTS_DONE;
- return 1;
}
diff --git a/src/mdaPiano.h b/src/mdaPiano.h
index e4cc261..ecfeba6 100644
--- a/src/mdaPiano.h
+++ b/src/mdaPiano.h
@@ -19,8 +19,7 @@ public:
void load_kgrp(KGRP*);
void load_samples(short**);
- virtual uint32_t processEvents(VstEvents* events);
-
+ void handle_midi(uint32_t size, unsigned char* data);
virtual void setParameter(uint32_t index, float value);