diff options
author | Florian Jung <flo@thinkpad.(none)> | 2011-01-11 20:29:00 +0100 |
---|---|---|
committer | Florian Jung <flo@thinkpad.(none)> | 2011-01-11 20:29:00 +0100 |
commit | 0573c5d52174eb78c9dad41a57415ea4bcef8b25 (patch) | |
tree | 742bb31425d0aaefa97eeeaa7f77a3d407f6237c /synth | |
parent | 8201450efc105691e343c50b4eab946f7b0ee038 (diff) |
Envelope can now stay in sustain phase forever
Diffstat (limited to 'synth')
-rw-r--r-- | synth/envelope.cpp | 48 | ||||
-rw-r--r-- | synth/envelope.h | 2 |
2 files changed, 21 insertions, 29 deletions
diff --git a/synth/envelope.cpp b/synth/envelope.cpp index 3e9c6ac..5678fd3 100644 --- a/synth/envelope.cpp +++ b/synth/envelope.cpp @@ -1,22 +1,6 @@ #include "envelope.h" -Envelope::Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h, int frames) -{ - level=0; - t=0; - state=ATTACK; - max=ONE; - - nth_frame=frames; - - set_ratefactor(1.0); - - set_attack(a); - set_decay(d); - set_sustain(s); - set_release(r); - set_hold(h); -} +#include <iostream> Envelope::Envelope(env_settings_t s, int frames) { @@ -29,6 +13,8 @@ Envelope::Envelope(env_settings_t s, int frames) set_ratefactor(1.0); + has_release_phase=(s.release>=0); + set_attack(s.attack); set_decay(s.decay); set_sustain(s.sustain); @@ -100,12 +86,14 @@ void Envelope::reattack() void Envelope::release_key() { - if ((state!=RELEASE) && (state!=DONE)) - { - t=0; - state=RELEASE; - sustain=level; - } + if (has_release_phase) + if ((state!=RELEASE) && (state!=DONE)) + { + t=0; + state=RELEASE; + sustain=level; + } + //if (!has_release_phase) ignore(); } bool Envelope::still_active() @@ -134,10 +122,14 @@ fixed_t Envelope::get_level() //must be called each frame if (t>=decay) { level=max*sustain >>SCALE; - if (hold) - state=HOLD; + if (has_release_phase) + if (hold) + state=HOLD; + else + state=RELEASE; else - state=RELEASE; + state=DONE; + t=0; } else //will only happen, if t < decay. so decay will @@ -147,7 +139,7 @@ fixed_t Envelope::get_level() //must be called each frame break; case HOLD: - level=sustain*max >>SCALE; + //does nothing. level must be set properly before entering HOLD state break; case RELEASE: @@ -163,7 +155,7 @@ fixed_t Envelope::get_level() //must be called each frame break; case DONE: - level=0; + //does nothing. level must be set properly before entering DONE state break; } diff --git a/synth/envelope.h b/synth/envelope.h index 65ea723..be50fa2 100644 --- a/synth/envelope.h +++ b/synth/envelope.h @@ -14,7 +14,6 @@ class Envelope { public: - Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h, int frames=1); Envelope(env_settings_t s, int frames=1); void release_key(); void reattack(); @@ -53,6 +52,7 @@ class Envelope fixed_t sustain_orig; fixed_t level; bool hold; + bool has_release_phase; jack_nframes_t t; fixed_t ratefactor; |