//connecting a GUI to buffer manipulations- live wavetable redraw/ changing 
//wavetable for an Osc UGen
(
var s, b, x, bufsize, secperbuf;
var w, ms, slid, cspec;
var changed;

bufsize=128; 
secperbuf= bufsize/44100;

s = Server.local;

b=Buffer.alloc(s, bufsize, 1);

x = { arg rate=440; 
	BufRd.ar(1, b.bufnum, Phasor.ar(0, BufRateScale.kr(b.bufnum) *
	 rate *secperbuf, 0, BufFrames.kr(b.bufnum)),1, 3)	//cubic interp 
}.play;

w = SCWindow("uibufread", Rect(200, 450, bufsize+50, 150));
ms = SCMultiSliderView(w, Rect(0, 0, bufsize, 100));

ms.value_(Array.fill(bufsize,0.5));
ms.valueThumbSize_(1.0);
ms.indexThumbSize_(1.0);
ms.gap_(0);

slid=SCSlider(w,Rect(bufsize+10, 0, 20, 100));
cspec= ControlSpec(70,1000, 'exponential', 10, 440);
slid.action_({x.set(\rate, cspec.map(slid.value)); });

slid.value_(0.3); slid.action.value;

w.front;

changed=false;

ms.action_({changed=true;});

t=Task({	
	
	inf.do({	
		
		if(changed,{
		changed=false;
		{b.setn(0,2*((ms.value)-0.5));}.defer
		});
		
		0.1.wait;	//10 Hz- change this to whatever suits you
	})
	
}).start;

)