EDITED: if this is against community guidelines, please let me know what the problem is.y post was flagged as inappropriate and I’m a bit confused.
I made a function that evaluates the Collatz conjecture (3n+1) for an integer, loads the result as the amplitude array argument of Signal.sineFill
, which is then converted to a wavetable, loaded to a buffer, and so on.
I wanted to make a GUI with a slider and number box to choose the initial value of n (which is assigned to x in the code), but I can’t find a way to
-
plot the buffer on the parent window of my GUI (I did see this post, but it didn’t really seem to work when I tried to use this idea in the code.
-
redraw the plotter with the new buffer whenever the value of x changes.
-
I posted about this earlier, but it’s the same issue and I don’t understand it: I get an error message when the buffer tmp file is erased and I then try to load a new collection to the allocated buffer. It does replace the collection with whatever new wavetable data I have, but the post window throws an error every time. Can I just block the error message somehow? Or just deal with it? It doesn’t disrupt anything, it just is annoying. (EDIT: apologies if this sounded like I was annoyed that no one had responded. I was annoyed by the post window error.)
(
var list = List.new;
var sig, wt, size = 2.pow(11);
var val;
x=1;
s = Server.local;
s.freeAllBuffers;
s.waitForBoot({
b = Buffer.alloc(s, size*2, 1);
w = Window("3x+1", Rect(300,300,800,600)).front;
h = Slider(w, Rect(70, 570, 720, 20))
.value_(x.linlin(1,99999,0.0,1.0))
.step_(1.linlin(1,99999,0.0,1.0))
.action_({
//collatz
n.value_(h.value.linlin(0.0,1.0,1,99999));
while({x>1},
{list.add(x);
if (x.mod(2)==0, {val = x/2}, {val = (3*x)+1});
x = val;
});
//collect in list
list.add(1);
list = list.asArray;
sig = Signal.sineFill(size, list);
wt = sig.asWavetable;
b.loadCollection(wt);
});
n = NumberBox(w, Rect(10, 570, 50, 20))
.value_(x)
.maxDecimals_(0)
.action_({
h.valueAction_(n.value.linlin(1,99999,0.0,1.0));
});
v = CompositeView(w, Rect(10,10,780,550)).background_(Color.white);
s.sync;
SynthDef(\wt, {
arg amp = 0.5;
var sig, freq;
freq = MouseX.kr(10,1000,1);
sig = Osc.ar(b, freq, 0.0, amp)!2;
Out.ar(0, sig);
}).add;
});
)