summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2013-01-14 22:17:21 +0800
committerrekado <rekado@elephly.net>2013-01-14 22:17:21 +0800
commit9b02feb9d5dc0ed830f437afa493631747b72ed7 (patch)
tree2ffee0eb80d379d1360f3cb2eed3f8e3066d9640 /src
parentfba9fc35f94198e8f2cf29d6fdc6937029f38e01 (diff)
implement key release handler
Diffstat (limited to 'src')
-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; }