//In this example code, a sound file can be made to loop at any selection in the
graphical display
//load soundfile onto Server
b = [Link](s,[Link] +/+ "sounds/[Link]");
//SynthDef (making Synth straight away) which has arguments for the loop points
c= SynthDef(\loopbuffer, {arg start=0, end=10000; [Link](0,[Link]([Link](1, 0,
[Link](0, [Link]([Link]), start, end),0.0)))}).play(s);
//*[Link]([Link]) //this isn't needed since the GUI gives us positions
directly in samples
( // make a simple SCSoundFileView
w = Window("soundfiles looper", Rect(10, 700, 750, 100));
[Link];
a = SoundFileView(w, Rect(20,20, 700, 60));
f = [Link];
[Link]([Link] +/+ "sounds/[Link]");
[Link] = f; // set soundfile
[Link](0, [Link]); // read in the entire file.
[Link]; // refresh to display the file.
//set a function which is called when the mouse is let go, i.e. just after dragging
out a selection in the window
a.mouseUpAction_({arg view;
var where;
where= ([Link][0]); //get the latest selection (assuming no other
selections going on)
[Link]; //post where - start sample and length in samples of selection
[Link](\start, where[0], \end, where[0]+where[1]); //convert to start and end
samples for loop area
});
)