I am using this basic structure below to play a pre-recorded soundFile. The section of the display selected will loop the audio and setting the curser to a specific point or a selecting a very short duration will stop the playback.
Now I would like to record into a buffer (or write a soundFile) of same length as the mastertrack using a modified version of your code. My problem is that the resolution of the selection and cursor position in your code is different from that of the mastertrack in my code - in your code the selection is relative to the screenbounds and in my example (modded from the helpfile), the selection is relative to the number of frames in the mastertrack.
Is there a way to link the update of the live-recording buffer/soundFile to the phasor in my Synth(\playBack) which would allow me to start loop recording anywhere in the mastertrack in way where the track can be ‘record enabled’ (overwriting existing audio in the buffer/soundFile and updating the view) or not (showing what has already been recorded without overwriting with new content)?
(
v = SoundFileView();
w =View(nil, Rect(200, 300, 1040, 100)).layout_(HLayout(v)).front;
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
v.soundfile = b;
v.read(0, b.numFrames);
v.timeCursorOn = true;
v.timeCursorColor = Color.white;
v.gridOn = false;
s.waitForBoot{
SynthDef(\playBack, {|buf, start = 0, end = 48000, loop = 1, gate = 1, t_trig = 1|
var phasor = Phasor.ar(t_trig, 1, start, end, start);
var play = BufRd.ar(1, buf, phasor, loop);
var env = Env.asr(0.01, 1, 0.01).kr(2, gate);
SendReply.ar(Impulse.ar(20), '/reply', phasor);
Out.ar(\out.kr(0), play!2 * env);
}).add;
s.sync;
v.mouseUpAction = {
if (v.selection(0)[1] > 6000)
{
if ( ~play.isPlaying )
{ ~play.set(\gate, 0) };
~play = Synth(\playBack, [buf: b, start: v.selection(0)[0], end: v.selection(0)[0] + v.selection(0)[1]]).register;
}
{ if ( ~play.isPlaying ) { ~play.set(\gate, 0) } }
};
o = OSCFunc({|val|
{ v.timeCursorPosition = val[3] }.defer;
}, '/reply');
}
)