From cfb9046eec768c76baa4c0711870bb255c86ef4a Mon Sep 17 00:00:00 2001 From: mick grierson Date: Mon, 19 Dec 2016 22:35:23 +0000 Subject: Fixing errors in new envelope functions. maxiEnvelope now has a ramp function, a ramps function that takes time / value pairs from a std::vector, an adsr and ar that all sync directly to the samplerate. They all take params in seconds. This makes it easier for javascript users when I transpile with emscripten. Wait what? --- maximilian.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 26 deletions(-) (limited to 'maximilian.cpp') diff --git a/maximilian.cpp b/maximilian.cpp index ca3517d..5609aad 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. @@ -399,13 +401,23 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) { // //} -double maxiEnvelope::ramp(double startVal, double endVal, double duration, int trigger1){ - +void maxiEnvelope::note(bool noteOn) { + + if (noteOn) trigger=1; + if (noteOn==false) trigger=0; + +} + +double maxiEnvelope::ramp(double startVal, double endVal, double duration){ + if (trigger!=0) { phase=startVal; + isPlaying=true; trigger=0; } + if (isPlaying) { + if (startVal= endVal ) phase = endVal; @@ -416,41 +428,90 @@ double maxiEnvelope::ramp(double startVal, double endVal, double duration, int t if ( phase <= endVal ) phase = endVal; } return(phase); + } else { + + return(0); + + } + } -double maxiEnvelope::ramps(double rampsArray[1000], int trigger1){ +double maxiEnvelope::ramps(std::vector rampsArray){ if (trigger!=0) { valindex=0; - endVal=rampsArray[valindex]; + endVal=rampsArray[valindex+1]; + isPlaying=true; trigger=0; - + } - if (phase= endVal ) { - startVal=phase; - valindex+=2; - endVal=rampsArray[valindex]; + 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 endVal) { - phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex+1]))); - if ( phase <= endVal ) { - startVal=phase; - valindex+=2; - endVal=rampsArray[valindex]; + + if (valindex==0 && output==endVal) { + period += (1/(maxiSettings::sampleRate/(1./rampsArray[valindex]))); + if (period>=1) { + phase=endVal; + startVal=phase; + if (valindex+2= endVal ) { + phase=endVal; + startVal=phase; + if (valindex+2 endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex]))); + if ( phase <= endVal ) { + phase=endVal; + startVal=phase; + if (valindex+2= 1 ) { phase=1; attackMode=false; -- cgit v1.3