From b1af4c233f43d450bf1a2d3a47f13305fa001d1b Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sat, 30 Sep 2017 23:01:35 +0200 Subject: [PATCH] Introduce an enum to describe the VCA mode Replace the integer encoding of the VCA mode with an enumeration. --- plugins/lb302/lb302.cpp | 20 ++++++++++---------- plugins/lb302/lb302.h | 9 ++++++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index a5be95ad6..1a32f7f92 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -289,7 +289,7 @@ lb302Synth::lb302Synth( InstrumentTrack * _instrumentTrack ) : vca_decay(0.99897516), vca_a0(0.5), vca_a(0.), - vca_mode(3) + vca_mode(never_played) { connect( Engine::mixer(), SIGNAL( sampleRateChanged( ) ), @@ -472,7 +472,7 @@ int lb302Synth::process(sampleFrame *outbuf, const int size) if( release_frame == 0 || ! m_playingNote ) { - vca_mode = 1; + vca_mode = decay; } if( new_freq ) @@ -496,7 +496,7 @@ int lb302Synth::process(sampleFrame *outbuf, const int size) // start decay if we're past release if( i >= release_frame ) { - vca_mode = 1; + vca_mode = decay; } // update vcf @@ -636,18 +636,18 @@ int lb302Synth::process(sampleFrame *outbuf, const int size) } // Handle Envelope - if(vca_mode==0) { + if(vca_mode==attack) { vca_a+=(vca_a0-vca_a)*vca_attack; if(sample_cnt>=0.5*Engine::mixer()->processingSampleRate()) - vca_mode = 2; + vca_mode = idle; } - else if(vca_mode == 1) { + else if(vca_mode == decay) { vca_a *= vca_decay; // the following line actually speeds up processing if(vca_a < (1/65536.0)) { vca_a = 0; - vca_mode = 3; + vca_mode = never_played; } } @@ -669,15 +669,15 @@ void lb302Synth::initNote( lb302Note *n) // Always reset vca on non-dead notes, and // Only reset vca on decaying(decayed) and never-played - if(n->dead == 0 || (vca_mode==1 || vca_mode==3)) { + if(n->dead == 0 || (vca_mode == decay || vca_mode == never_played)) { //printf(" good\n"); sample_cnt = 0; - vca_mode = 0; + vca_mode = attack; // LB303: //vca_a = 0; } else { - vca_mode = 2; + vca_mode = idle; } initSlide(); diff --git a/plugins/lb302/lb302.h b/plugins/lb302/lb302.h index 4b58a314f..3ca22c78b 100644 --- a/plugins/lb302/lb302.h +++ b/plugins/lb302/lb302.h @@ -224,7 +224,14 @@ private: vca_a; // Amplifier coefficient. // Envelope State - int vca_mode; // 0: attack, 1: decay, 2: idle, 3: never played + enum VCA_Mode + { + attack = 0, + decay = 1, + idle = 2, + never_played = 3 + }; + VCA_Mode vca_mode; // My hacks int sample_cnt;