summaryrefslogtreecommitdiff
path: root/src/mdaPiano.cpp
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2013-01-14 22:00:30 +0800
committerrekado <rekado@elephly.net>2013-01-14 22:00:30 +0800
commit6ecbe702bf74f30e4bac40c3466c957364765315 (patch)
treebea12146c9331a6dc0c5ab95bec3ea42981c426d /src/mdaPiano.cpp
parent4ef1f4938d535899fea142eaa84e4f2d36ce56dc (diff)
find next free voice
Diffstat (limited to 'src/mdaPiano.cpp')
-rw-r--r--src/mdaPiano.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mdaPiano.cpp b/src/mdaPiano.cpp
index a3c0311..bc9a5f8 100644
--- a/src/mdaPiano.cpp
+++ b/src/mdaPiano.cpp
@@ -51,6 +51,30 @@ void mdaPiano::update() {
}
+unsigned mdaPiano::find_free_voice(unsigned char key, unsigned char velocity) {
+ //is this a retriggered note during sustain?
+ if (sustain) {
+ for (unsigned i = 0; i < NVOICES; ++i) {
+ if ((voices[i]->get_key() == key) && (voices[i]->is_sustained()))
+ return i;
+ }
+ }
+
+ //take the next free voice if
+ // ... notes are sustained but not this new one
+ // ... notes are not sustained
+ for (unsigned i = 0; i < NVOICES; ++i) {
+ if (voices[i]->get_key() == LV2::INVALID_KEY)
+ {
+ return i;
+ }
+ }
+
+ //TODO: steal quietest note if all voices are used up
+ return 0;
+}
+
+
void mdaPiano::setVolume(float value)
{
for (uint32_t v=0; v<NVOICES; ++v)