In the prototype Delta Thing patch below the key line (and the only one that you should need to change/add to) is this:
Oscillator[1].Tune = delta(Oscillator[1].Tune, Oscillator[1].Tune.min, Oscillator[1].Tune.max, DELTA_FROM_RANGE, 1.0, -0.5, 1.0, 12.0);
This is what it is trying to do:
Oscillator[1].Tune - the parameter being changed
Oscillator[1].Tune.min, & max - the min/max of the range of the parameter
DELTA_FROM_RANGE - the random value is taken from (a sub-range of) the min/max range (see also DELTA_FROM_VALUE), can just put a 1 or 2 here
1.0 - there is a 100% chance that this value will (try to) be changed
-0.5 - a negative bias, where one half of the allowable value increases are not possible
1.0 - scale the value change by this amount
12.0 - round the new value to this multiple, i.e. in the case of Tune, an octave.
There are many things I could say about the code in this patch -- many of the "bad" things were due to 1) Zebraspeak limitations/bugs, and 2) my sanity with respect to debugging it, and 3) my ignorance. All of which I expect to improve as time goes on. Except my ignorance, which is already a finely tuned machine.
billstei
P.S. It would obviously be
-------------
#defaults=no
#patchname=no
<?
// Delta Thing - Version 2
int DELTA_FROM_RANGE = 1;
int DELTA_FROM_VALUE = 2;
// delta() - returns the changed parameter value
// v - the parameter's current value
// vmin - the minimum of the range of v
// vmax - the maximum of the range of v
// dt - type of delta, either from a value chosen from the range,
// or a value which is a percentage of the current value
// cp - probability of there being a change, from 0.0 to 1.0
// cb - change bias is from -1.0 to 1.0
// sc - scaling applied to the random value/percentage
// cm - change multiple to round to. Use 0.0 for no rounding
float delta( float v, float vmin, float vmax, int dt, float cp, float cb, float sc, float cm) {
float lo;
float hi;
float x;
float h;
float r;
float delta_out;
// Assume no change to the current value
delta_out = v;
r = rand(0.0, 1.0);
// If random r is less than the change percentage then we do the change
if (cp > 0.0) { if (r <= cp) {
if (dt == DELTA_FROM_RANGE) {
if (cb > 0.0) {
// Positive bias
lo = (vmin - v) - ((vmin - v) * cb);
hi = vmax - v;
} else {
// Negative bias
lo = vmin - v;
hi = (vmax - v) + ((vmax - v) * cb);
}
// Else use percentages
} else {
if (cb > 0.0) {
// Positive bias
lo = -1.0 + cb;
hi = 1.0;
} else {
// Negative bias
lo = -1.0;
hi = 1.0 + cb;
}
}
if (dp_osc1_tune_delta_type == DELTA_FROM_RANGE) {
if (cm > 0.0) {
r = rand(lo, hi) * sc;
x = v + r;
if (x < 0.0) { h = -0.5; } else { h = 0.5; };
int c = ((x / cm) + h);
delta_out = c * cm;
} else {
r = rand(lo, hi) * sc;
delta_out = v + r;
}
// Else do the delta from percentage of current value
} else {
if (cm > 0.0) {
r = rand(lo, hi) * sc;
x = v + (v * r);
if (x < 0.0) { h = -0.5; } else { h = 0.5; };
int c = ((x / cm) + h);
delta_out = c * cm;
} else {
r = rand(lo, hi) * sc;
delta_out = v + (v * r);
}
}
if (delta_out < vmin) delta_out = vmin;
if (delta_out > vmax) delta_out = vmax;
}}
return delta_out;
}
Oscillator[1].Tune = delta(Oscillator[1].Tune, Oscillator[1].Tune.min, Oscillator[1].Tune.max, DELTA_FROM_RANGE, 1.0, -0.5, 1.0, 12.0);
?>
