diff options
Diffstat (limited to 'maximilian.cpp')
| -rw-r--r-- | maximilian.cpp | 199 |
1 files changed, 195 insertions, 4 deletions
diff --git a/maximilian.cpp b/maximilian.cpp index 3391da1..0d9bcfd 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -364,6 +364,8 @@ double maxiOsc::triangle(double frequency) { } +// don't use this nonsense. Use ramps instead. +// ..er... I mean "This method is deprecated" double maxiEnvelope::line(int numberofsegments,double segments[1000]) { //This is a basic multi-segment ramp generator that you can use for more or less anything. //However, it's not that intuitive. @@ -372,14 +374,14 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) { nextval=segments[valindex+2]; currentval=segments[valindex]; if (currentval-amplitude > 0.0000001 && valindex < numberofsegments) { - amplitude += ((currentval-startval)/(maxiSettings::sampleRate/period)); + amplitude += ((currentval-startVal)/(maxiSettings::sampleRate/period)); } else if (currentval-amplitude < -0.0000001 && valindex < numberofsegments) { - amplitude -= (((currentval-startval)*(-1))/(maxiSettings::sampleRate/period)); + amplitude -= (((currentval-startVal)*(-1))/(maxiSettings::sampleRate/period)); } else if (valindex >numberofsegments-1) { valindex=numberofsegments-2; } else { valindex=valindex+2; - startval=currentval; + startVal=currentval; } output=amplitude; @@ -391,7 +393,7 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) { return(output); } -//and this +//and this is also deprecated void maxiEnvelope::trigger(int index, double amp) { isPlaying=1;//ok the envelope is being used now. valindex=index; @@ -399,6 +401,195 @@ void maxiEnvelope::trigger(int index, double amp) { } +void maxiEnvelope::trigger(bool noteOn) { + + if (noteOn) trig=1; + if (noteOn==false) trig=0; + +} + +double maxiEnvelope::ramp(double startVal, double endVal, double duration){ + + if (trig!=0) { + phase=startVal; + isPlaying=true; + trig=0; + } + + if (isPlaying) { + + if (startVal<endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./duration))); + if ( phase >= endVal ) phase = endVal; + } + + if (startVal > endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./duration))); + if ( phase <= endVal ) phase = endVal; + } + return(phase); + } else { + + return(0); + + } + + +} + + +double maxiEnvelope::ramps(std::vector<double> rampsArray){ + + if (trig!=0) { + valindex=0; + endVal=rampsArray[valindex+1]; + isPlaying=true; + trig=0; + + } + + if (isPlaying) { + + if (valindex>0 && rampsArray[valindex-1]==rampsArray[valindex+1]) { + period += (1/(maxiSettings::sampleRate/(1./rampsArray[valindex]))); + if (period>=1) { + phase=endVal; + startVal=phase; + if (valindex+2<rampsArray.size()){ + valindex+=2; + endVal=rampsArray[valindex+1]; + period=0; + } + } output=phase; + } + + if (valindex==0 && output==endVal) { + period += (1/(maxiSettings::sampleRate/(1./rampsArray[valindex]))); + if (period>=1) { + phase=endVal; + startVal=phase; + if (valindex+2<rampsArray.size()){ + valindex+=2; + endVal=rampsArray[valindex+1]; + period=0; + } + } output=phase; + } + + if (phase<endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex]))); + if ( phase >= endVal ) { + phase=endVal; + startVal=phase; + if (valindex+2<rampsArray.size()){ + valindex+=2; + endVal=rampsArray[valindex+1]; + + } + } + output=phase; + } + + if (phase > endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex]))); + if ( phase <= endVal ) { + phase=endVal; + startVal=phase; + if (valindex+2<rampsArray.size()){ + valindex+=2; + endVal=rampsArray[valindex+1]; + + } + } output=phase; + } + + return(output); + + } else { + + return(0); + } +} + +double maxiEnvelope::ar(double attack, double release) { + + if (trig!=0) { + //phase=0; + releaseMode=false; + trig=0; + } + + if (phase<1 && releaseMode==false) { + phase += ((1)/(maxiSettings::sampleRate/(1./attack))); + if ( phase >= 1 ) { + phase=1; + releaseMode=true; + }; + } + + if (releaseMode==true) { + phase += ((-1)/(maxiSettings::sampleRate/(1./release))); + if ( phase <= 0 ) phase = 0; + } + + return phase; +} + + +double maxiEnvelope::adsr(double attack, double decay, double sustain, double release) { + + if (trig!=0 && !attackMode) { +// phase=0.; + releaseMode=false; + decayMode=false; + sustainMode=false; + attackMode=true; + trig=0; + } + + if (attackMode) { + phase += ((1)/(maxiSettings::sampleRate/(1./attack))); + + if ( phase >= 1 ) { + phase=1; + attackMode=false; + decayMode=true; + }; + } + + if (decayMode) { + phase += ((-1)/(maxiSettings::sampleRate/(1./decay))); + if ( phase <= sustain ) { + phase=sustain; + decayMode=false; + sustainMode=true; + }; + } + + if (sustainMode) { + + if (noteOn) { + phase=sustain; + } + + if (!noteOn) { + sustainMode=false; + releaseMode=true; + } + } + + if (releaseMode) { + phase += ((-sustain)/(maxiSettings::sampleRate/(1./release))); + if ( phase <= 0 ) { + phase = 0; + releaseMode=false; + } + } + + return phase; +} + + //Delay with feedback maxiDelayline::maxiDelayline() { memset( memory, 0, 88200*sizeof (double) ); |
