diff options
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) |