summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mdaPianoVoice.cpp26
-rw-r--r--src/mdaPianoVoice.h1
2 files changed, 21 insertions, 6 deletions
diff --git a/src/mdaPianoVoice.cpp b/src/mdaPianoVoice.cpp
index 1417056..b229062 100644
--- a/src/mdaPianoVoice.cpp
+++ b/src/mdaPianoVoice.cpp
@@ -116,17 +116,31 @@ void mdaPianoVoice::on(unsigned char note, unsigned char velocity)
// TODO: move the loop to mdaPiano.cpp
for(v=0; v<NVOICES; v++) if(voice[v].note==note) //any voices playing that note?
{
- if(sustain==0)
- {
- if(note < 94 || note == SUSTAIN) //no release on highest notes
- voice[v].dec = (float)exp(-iFs * exp(2.0 + 0.017 * (double)note - 2.0 * param[1]));
- }
- else voice[v].note = SUSTAIN;
+ release(0);
}
}
}
+void mdaPianoVoice::release(unsigned char velocity)
+{
+ if(sustain==0) {
+ //no release on highest notes
+ if(note < 94 || note == SUSTAIN) {
+ dec = (float)exp(-iFs * exp(2.0 + 0.017 * (double)note - 2.0 * *p(p_envelope_release)));
+ }
+ } else {
+ note = SUSTAIN;
+ }
+
+ //Mark the voice to be turned off later. It may not be set to
+ //INVALID_KEY yet, because the release sound still needs to be
+ //rendered. m_key is finally set to INVALID_KEY by 'render' when
+ //env < SILENCE
+ m_key = SUSTAIN;
+}
+
+
void mdaPianoVoice::process(float **inputs, float **outputs, uint32_t sampleFrames)
{
float* out0 = outputs[0];
diff --git a/src/mdaPianoVoice.h b/src/mdaPianoVoice.h
index 1cd393f..22f8218 100644
--- a/src/mdaPianoVoice.h
+++ b/src/mdaPianoVoice.h
@@ -56,6 +56,7 @@ class mdaPianoVoice : public LV2::Voice {
float p_helper(unsigned short, Param);
void update(Param); // recalculates internal variables
void on(unsigned char key, unsigned char velocity);
+ void release(unsigned char velocity);
void reset(void);
bool is_sustained(void) { return (note == SUSTAIN); }
unsigned char get_key(void) const { return m_key; }