diff options
author | rekado <rekado@elephly.net> | 2013-01-14 22:00:30 +0800 |
---|---|---|
committer | rekado <rekado@elephly.net> | 2013-01-14 22:00:30 +0800 |
commit | 6ecbe702bf74f30e4bac40c3466c957364765315 (patch) | |
tree | bea12146c9331a6dc0c5ab95bec3ea42981c426d /src/mdaPiano.cpp | |
parent | 4ef1f4938d535899fea142eaa84e4f2d36ce56dc (diff) |
find next free voice
Diffstat (limited to 'src/mdaPiano.cpp')
-rw-r--r-- | src/mdaPiano.cpp | 24 |
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) |