cookiecutter-supercollider-plugin
cookiecutter-supercollider-plugin copied to clipboard
Maybe add audio/control rate boiler code?
Hi again.
Just a heads up / FYI. I am using this to write my first ugens (hurraaay!!) and it's going fairly well, but as a newbie to this I just wanted to let you know that I found the lack of audio/control rate distinction a bit confusing.
If you build and run the example plugin that this template generates, it emits horrible noise if you just set the gain to a fixed value like 0.5
but fine if modulating by audiorate SinOsc.ar(0.1)
for example. This to me (as a newbie) was a bit confusing.
I know this would be at the cost of making the default example here more complicated but I would personally have preferred if the audio/control rate stuff was a bit more verbose in the built example :)
// 1. set the calculation function.
if (isAudioRateIn(1)) {
// if the gain argument is audio rate
set_calc_function<SimpleGain, &SimpleGain::next_a>();
} else {
// if thene gain argument is control rate (or a scalar).
set_calc_function<SimpleGain, &SimpleGain::next_k>();
};
// Check if "gain" is control rate or audio rate
if (isAudioRateIn(1)) {
next_a(1);
} else {
next_k(1);
}
etc
And thanks again for this awesome tool !
best!
ah no sorry, maybe it's better to just update the next function to use in0 instead for the gain arg?
void SimpleGain::next(int nSamples) {
const float *input = in(0);
const float gain = in0(1);
float *outbuf = out(0);
// simple gain function
for (int i = 0; i < nSamples; ++i) {
outbuf[i] = input[i] * gain;
}
}
i'd be happy to accept a pull request, but i currently have no time to spend on this repo, sorry. i agree this would be a good addition
Cool I can cook up a PR. Thanks!