|
| 1 | +#ifndef __MaximilianPatch_hpp__ |
| 2 | +#define __MaximilianPatch_hpp__ |
| 3 | + |
| 4 | +#include "Patch.h" |
| 5 | +#include "maximilian.h" |
| 6 | + |
| 7 | +static maxiParam* maxiParameters[8]; |
| 8 | +static unsigned int maxiParameterCount = 0; |
| 9 | +maxiParam::maxiParam() : value(0.0), minValue(0.0), maxValue(1.0), |
| 10 | + name(NULL), pid(maxiParameterCount++){ |
| 11 | + if(pid < 8) |
| 12 | + maxiParameters[pid] = this; |
| 13 | +} |
| 14 | + |
| 15 | +void maxiParam::update(double v){ |
| 16 | + const static double lambda = 0.9; // factor for exponential smoothing |
| 17 | + value = value*lambda + scale(v)*(1-lambda); |
| 18 | +} |
| 19 | + |
| 20 | +class MaximilianPatch : public Patch { |
| 21 | +private: |
| 22 | +#include "maximilian-patch.h" |
| 23 | + float output[2]; |
| 24 | +public: |
| 25 | + MaximilianPatch(){ |
| 26 | + maxiSettings::sampleRate = getSampleRate(); |
| 27 | + maxiSettings::channels = 2; |
| 28 | + maxiSettings::bufferSize = getBlockSize(); |
| 29 | + setup(); |
| 30 | + char name[] = "A"; |
| 31 | + maxiParameterCount = std::min(7u, maxiParameterCount); |
| 32 | + for(int i=0; i<maxiParameterCount; ++i){ |
| 33 | + if(maxiParameters[i]->name == NULL){ |
| 34 | + name[0] = 'A'+maxiParameters[i]->pid; |
| 35 | + registerParameter((PatchParameterId)(maxiParameters[i]->pid), name); |
| 36 | + }else{ |
| 37 | + registerParameter((PatchParameterId)(maxiParameters[i]->pid), maxiParameters[i]->name); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + void processAudio(AudioBuffer &buffer) { |
| 42 | + float* left = buffer.getSamples(LEFT_CHANNEL); |
| 43 | + float* right = buffer.getSamples(RIGHT_CHANNEL); |
| 44 | + for(int i=0; i<maxiParameterCount; ++i) |
| 45 | + maxiParameters[i]->update(getParameterValue((PatchParameterId)(maxiParameters[i]->pid))); |
| 46 | + for(int i=0; i<buffer.getSize(); ++i){ |
| 47 | + play(output); |
| 48 | + left[i] = output[0]; |
| 49 | + right[i] = output[1]; |
| 50 | + } |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +#endif // __MaximilianPatch_hpp__ |
0 commit comments