Skip to content

Remove unused phase in ADSR #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions ADSR.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,25 @@ class ADSR
*/
void update(){ // control rate

switch(current_phase->phase_type) {
switch(current_phase->phase_type) {

case ATTACK:
checkForAndSetNextPhase(&decay);
break;
if (decay.lerp_steps > 0) {
checkForAndSetNextPhase(&decay);
break;
}

case DECAY:
checkForAndSetNextPhase(&sustain);
break;
if (sustain.lerp_steps > 0) {
checkForAndSetNextPhase(&sustain);
break;
}

case SUSTAIN:
checkForAndSetNextPhase(&release);
break;
if (release.lerp_steps > 0) {
checkForAndSetNextPhase(&release);
break;
}

case RELEASE:
checkForAndSetNextPhase(&idle);
Expand All @@ -152,7 +158,7 @@ class ADSR
case IDLE:
adsr_playing = false;
break;
}
}
}


Expand Down Expand Up @@ -180,6 +186,16 @@ class ADSR
void noteOn(bool reset=false){
if (reset) transition.set(0);
setPhase(&attack);
if (attack.lerp_steps == 0) {
if (decay.lerp_steps > 0)
setPhase(&decay);
else if (sustain.lerp_steps > 0)
setPhase(&sustain);
else if (release.lerp_steps > 0)
setPhase(&release);
else
setPhase(&idle);
}
adsr_playing = true;
}

Expand Down