// this patch is a rough implementation of a utility to handle buffers.
// jan t. has made it into a class artwork in his distribution and added many cool features // checkout http://wiki.sampleandhold.org
// ____inspired by lloop environment for max. http://lloopp.klingt.org/start.html____
Routine({
var patchArray, orig, dir;
var window, fileNames, pathNames, a, c, d, f, t, n, m, b, p, u, l, o, q, r, v;
if(~newDir.isNil, {dir = "/Users/df/Desktop/DoWN/_LooPS/"}, {dir = ~newDir; ~newDir=nil;}); // a default sample directory
fileNames = Cocoa.getPathsInDirectory(dir).select({| file | file.contains(".aif") });
patchArray = Array.fill(
fileNames.size
, { arg i; [
fileNames.at(i).asString
, dir++ Cocoa.getPathsInDirectory(dir).select({| file | file.contains(".aif") }).at(i)
]
}
);
window = SCWindow("BuFFeR-HoST"
, Rect(10, 770, 265, 70)
, false
// , false
).front;
window.view.background = Color.rand;
t = 0;
u = 0;
c = 0;
SynthDef("x", {arg buf=0, gate=1; Out.ar(0, Pan2.ar(PlayBuf.ar(1, buf, loop:1))*EnvGen.ar(Env.adsr(0.01, 0, 1, 0.01), gate, doneAction:2))}).load(s);
SynthDef("y", {arg buf=0, gate=1; RecordBuf.ar(AudioIn.ar, buf, loop:1)*EnvGen.ar(Env.adsr(0.01, 0, 1, 0.01), gate, doneAction:2)}).load(s);
d = SCStaticText(window, Rect(2, 25, 50, 15));
d.string = "allocate";
d.font = Font("LucidaGrande-Bold", 8);
d = SCStaticText(window, Rect(87, 25, 50, 15));
d.string = "buffer";
d.font = Font("LucidaGrande-Bold", 8);
d = SCStaticText(window, Rect(132, 25, 50, 15));
d.string = "channels";
d.font = Font("LucidaGrande-Bold", 8);
d = SCStaticText(window, Rect(184, 25, 50, 15));
d.string = "buf";
d.font = Font("LucidaGrande-Bold", 8);
d = SCStaticText(window, Rect(2, 0, 50, 15));
d.string = "sample dir";
d.font = Font("LucidaGrande-Bold", 8);
d = SCStaticText(window, Rect(87, 0, 50, 15));
d.string = "add sample";
d.font = Font("LucidaGrande-Bold", 8);
d = SCStaticText(window, Rect(184, 0, 50, 15));
d.string = "buf";
d.font = Font("LucidaGrande-Bold", 8);
b = SCPopUpMenu(window
, Rect(5, 13, 80, 15)
).focus.background_(Color.yellow)
.font = (Font("Helvetica", 9));
b.items = fileNames;
b.action = {arg b;
s.sendMsg("/b_allocRead", u, dir++ fileNames.at(b.value));
};
SCButton(window, Rect(87, 13, 40, 15))
.states_([["samp", Color.black,Color.white]])
.action_({
CocoaDialog.getPaths({ arg paths;
paths.do({ arg p;
s.sendMsg("/b_allocRead", u, p) })
},{
"cancelled".postln;
});
})
.font = (Font("Helvetica", 9));
m = SCNumberBox(window, Rect(184, 12, 40, 15))
.font = (Font("Helvetica", 9));
m.setProperty(\align,\center);
m.value = 0;
m.action = { arg numb;
p.set(\buf, numb.value;);
c = numb.value;
};
SCButton(window, Rect(227, 12, 15, 15))
.states_([[">", Color.black,Color.green]])
.action_({ if(p.isNil.not, {p.free}); p=Synth("x", [\buf, c])})
.font = (Font("Helvetica", 9));
SCButton(window, Rect(243, 12, 15, 15))
.states_([["||", Color.black,Color.green]])
.action_({p.set(\gate, 0); p = 0})
.font = (Font("Helvetica", 9));
orig = thisFunction;
l = SCNumberBox(window, Rect(2, 37, 80, 15))
.font = (Font("Helvetica", 9));
l.setProperty(\align,\center);
l.value = 0;
l.action = {arg num;
s.sendMsg("/b_alloc", u, num.value, c);
};
o = SCNumberBox(window, Rect(87, 37, 40, 15))
.font = (Font("Helvetica", 9));
o.setProperty(\align,\center);
o.value = 0;
o.action = { arg num; u = num.value };
q = SCNumberBox(window, Rect(132, 37, 40, 15))
.font = (Font("Helvetica", 9));
q.setProperty(\align,\center);
q.value = 1;
q.action = { arg num; c = num.value };
v = SCNumberBox(window, Rect(184, 37, 40, 15))
.font = (Font("Helvetica", 9));
v.setProperty(\align,\center);
v.value = 0;
v.action = { arg numb;
r.set(\buf, numb.value;);
t = numb.value;
};
SCButton(window, Rect(227, 35, 15, 15))
.states_([["*", Color.black,Color.green]])
.action_({if(r.isNil.not, {r.free}); r=Synth("y", [\buf, t])})
.font = (Font("Helvetica", 9));
SCButton(window, Rect(243, 35, 15, 15))
.states_([["||", Color.black,Color.green]])
.action_({r.set(\gate, 0); r = 0})
.font = (Font("Helvetica", 9));
SCButton(window, Rect(2, 55, 15, 15))
.states_([["X", Color.black,Color.white]])
.action_({window.close; p.set(\gate, 0); r.set(\gate, 0)})
.font = (Font("Helvetica", 9));
SCButton(window, Rect(15, 55, 80, 15))
.states_([["DiR=>DeFaulT", Color.black,Color.white]])
.action_({window.close; ~newDir = nil; orig.value; }) // this patch
.font = (Font("Helvetica", 9));
SCButton(window, Rect(95, 55, 80, 15))
.states_([["GeT=>NeWDiR", Color.black,Color.white]])
.action_({ CocoaDialog.getPaths({ arg paths;
paths.do({ arg p;
~newDir = p.dirname++ "/";
~newDir.postln;
})
},{
"cancelled".postln;
});
})
.font = (Font("Helvetica", 9));
SCButton(window, Rect(175, 55, 85, 15))
.states_([["LoaD=>NeWDiR", Color.black,Color.white]])
.action_({window.close; orig.value}) // this patch
.font = (Font("Helvetica", 9));
}).run
editors so far
tom tlalim