<commit_before>//
//  ADSR.cpp
//  Tonic
//
//  Created by <NAME> on 2/28/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#include "ADSR.h"

namespace Tonic { namespace Tonic_{
  
  ADSR_::ADSR_() : state(ATTACK){
    ramp.length(1.0);
    ramp.target(0);
    ramp.value(0);
    
    sustains = ControlValue(true);
    
  }
  
  ADSR_::~ADSR_(){
    
  }
  
  void ADSR_::switchState(State newState, const SynthesisContext_ &context){
    state = newState;
    switch(state){
      case ATTACK:
        ramp.value(0);
        ramp.target(1);
        ramp.length(attack.tick(context).value);
      break;
      case DECAY:
        ramp.target(sustain.tick(context).value);
        ramp.length(decay.tick(context).value);
      break;
      case SUSTAIN:
        ramp.value(sustain.tick(context).value);
      break;<commit_msg>ADSR no longer snaps to zero on attack. It picks up where it last was. In other words, if the envelope hasn't finished the decay portion, and the last value was 0.5, the attack now starts at 0.5 instead of 0.<commit_after>//
//  ADSR.cpp
//  Tonic
//
//  Created by <NAME> on 2/28/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#include "ADSR.h"

namespace Tonic { namespace Tonic_{
  
  ADSR_::ADSR_() : state(ATTACK){
    ramp.length(1.0);
    ramp.target(0);
    ramp.value(0);
    
    sustains = ControlValue(true);
    
  }
  
  ADSR_::~ADSR_(){
    
  }
  
  void ADSR_::switchState(State newState, const SynthesisContext_ &context){
    state = newState;
    switch(state){
      case ATTACK:
        ramp.value(synthesisBlock_[synthesisBlock_.frames() - 1]);
        ramp.target(1);
        ramp.length(attack.tick(context).value);
      break;
      case DECAY:
        ramp.target(sustain.tick(context).value);
        ramp.length(decay.tick(context).value);
      break;
      case SUSTAIN:
        ramp.value(sustain.tick(context).value);
      break;
{'fraction_non_alphanumeric': 0.13942558746736292, 'fraction_numerical': 0.018276762402088774, 'mean_word_length': 2.471014492753623, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '485790', 'n_tokens_mistral': 693, 'n_tokens_neox': 675, 'n_words': 146}