//////////////////////////////////////////////////////////////////////////
var window, fileString;
var tableFill, rhythmArray, pitchArray, ampArray, probArray, randPitch = 2;
var bus, group, synth, synthDefArray, taskArray, taskPlaying;
var buffer = 0, channels = 1, sampleStart = 0, sampleEnd = 1;
var offset = 0, start = 0, length = 32;
var entropyConstValue = 0, entropyValue = 0, entropyFillValue = 0;
var rateValue = 1, absValue = 0, volumeValue = 1;
var bufferArray, channelArray, bufferPopUp;
//////////////////////////////////////////////////////////////////////////
bus = Bus.new;
group = Group.new;
probArray = [0.0, 0.1, 0.2, 0.4, 0.5, 0.4];
bufferArray = Array.new;
channelArray = Array.new;
rhythmArray = Array.new;
pitchArray = Array.new;
ampArray = Array.new;
//////////////////////////////////////////////////////////////////////////
SynthDef("GenBeatMono", {
arg bus, buffer, amp, pan, start, end, rate;
var env, sound, length;
length = BufFrames.kr(buffer);
env = EnvGen.kr(Env([0,1,1,0], [0.01, 0.98, 0.01]),
timeScale: (end - start) * BufDur.kr(buffer), doneAction:2);
sound = Pan2.ar(PlayBuf.ar(1, buffer, rate, 1, start * length), pan,
env * amp);
Out.ar(bus, sound);
}).load(s);
SynthDef("GenBeatStereo", {
arg bus, buffer, amp, pan, start, end, rate;
var env, sound, length;
length = BufFrames.kr(buffer);
env = EnvGen.kr(Env([0,1,1,0], [0.01, 0.98, 0.01]),
timeScale: (end - start) * BufDur.kr(buffer), doneAction:2);
sound = Pan1.ar(PlayBuf.ar(2, buffer, rate, 1, start * length), pan,
env * amp);
Out.ar(bus, sound);
}).load(s);
synthDefArray = ["GenBeatMono", "GenBeatStereo"];
//////////////////////////////////////////////////////////////////////////
window = SCWindow("GenBeat", Rect(0,0,100,355), false).front;
window.view.background_(Color(0.4, 0.4, 0.4));
window.onClose_({
bufferArray.do({
arg item;
item.free;
});
});
SCButton(window, Rect(10, 10, 80, 15))
.states_([
["Start", Color.black, Color.new(0.8, 0.7, 0.9)],
["Stop", Color.black, Color.new(0.8, 0.7, 0.9)]
])
.action_({
arg view;
if (view.value == 1, {
taskArray.reset;
taskArray.start;
}, {
taskArray.stop;
});
});
SCButton(window, Rect(10, 30, 80, 15))
.states_([
["Fill", Color.black, Color.new(0.8, 0.7, 0.9)] ])
.action_({
tableFill.value;
});
SCMultiSliderView(window, Rect(10, 50, 80, 40))
.action_({
arg view;
probArray.put(view.index, view.currentvalue);
})
.value_([0.0, 0.1, 0.2, 0.4, 0.5, 0.4]);
SCSlider(window, Rect(10, 95, 80, 15))
.action_({
arg view;
randPitch=view.value * 4;
})
.value_(0.5);
SCSlider(window, Rect(10, 115, 80, 15))
.action_({
arg view;
entropyValue = view.value;
});
SCButton(window, Rect(10, 135, 40, 15))
.states_([
["Const", Color.black, Color.new(0.8, 0.7, 0.9)],
["Fill", Color.black, Color.new(0.8, 0.7, 0.9)]
])
.action_({
arg view;
entropyConstValue = view.value;
});
SCButton(window, Rect(50, 135, 40, 15))
.states_([
["W_On", Color.black, Color.new(0.8, 0.7, 0.9)],
["W_Off", Color.black, Color.new(0.8, 0.7, 0.9)]
])
.action_({
arg view;
entropyFillValue = view.value;
});
SCRangeSlider(window, Rect(10, 155, 80, 15))
.step_(0.25)
.action_({
arg view;
start = (view.lo * 64).asInteger;
length = ((view.hi - view.lo) * 64).asInteger.max(16);
})
.lo_(0)
.hi_(0.5);
SCNumberBox(window, Rect(10, 175, 80, 15))
.value_(0)
.action_({
arg view;
offset = view.value.asInteger;
});
SCStaticText(window, Rect(5, 5, 90, 190))
.string_(" ")
.background_(Color.new255(247, 128, 29));
////////////////////////////////////////////////////////////////////
// Sample Gui
SCButton(window, Rect(10, 205, 80, 15)).states_(
[["Load", Color.black, Color.new(0.8, 0.7, 0.9)]]
).action_({
CocoaDialog.getPaths({
arg path;
path.do({
arg item, i;
var sf;
sf = SoundFile.new;
sf.openRead(item);
channelArray = channelArray.add(sf.numChannels);
sf.close;
bufferArray = bufferArray.add(Buffer.read(s, item));
bufferPopUp.items_(bufferPopUp.items.add(PathName(item).fileName));
});
}, {"Canceled".postln}, 20);
});
SCButton(window, Rect(10, 225, 15, 15))
.states_([["-"]])
.action_({
bufferArray.at(bufferPopUp.value).free;
bufferArray.removeAt(bufferPopUp.value);
channelArray.removeAt(bufferPopUp.value);
bufferPopUp.items.removeAt(bufferPopUp.value);
bufferPopUp.items_(bufferPopUp.items);
});
bufferPopUp = SCPopUpMenu(window, Rect(25, 225, 65, 15))
.items_(Array.new);
//fileString = SCStaticText(window,Rect(10, 225 ,80,15)).string_("Path")
// .align_(\center)
// .background_(Color.new(0.7, 0.6, 0.8));
SCNumberBox(window, Rect(10, 245, 40, 15))
.value_(1.0)
.background_(Color.new(0.7, 0.6, 0.8))
.action_({
arg view;
rateValue = view.value;
});
SCButton(window, Rect(50, 245, 40, 15))
.canFocus_(false)
.states_([["AbsOn"], ["AbsOff"]])
.action_({
arg view;
absValue = view.value;
});
SCRangeSlider(window, Rect(10, 265, 80, 15))
.lo_(0.0).hi_(1.0)
.background_(Color.new(0.8, 0.7, 0.9))
.action_({
arg view;
sampleStart = view.lo;
sampleEnd = view.hi;
synth.set("start", sampleStart, "end", sampleEnd);
});
SC2DSlider(window, Rect(10, 285, 80, 40))
.x_(0.5).y_(1.0)
.background_(Color.new(0.7, 0.6, 0.8))
.action_({
arg view;
volumeValue = \amp.asSpec.map(view.y);
synth.set("pan", view.x * 2 - 1);
});
SCButton(window, Rect(10, 330, 80, 15))
.states_([
["Mute", Color.black, Color.new(0.8, 0.7, 0.9)],
["UnMute", Color.black, Color.new(0.7, 0.6, 0.8)]
])
.action_({
arg view;
//synth.set("mute", 1 - view.value);
});
SCStaticText(window, Rect(5, 200, 90, 150))
.string_(" ")
.background_(Color.new255(247, 128, 29));
taskArray = Task({
var pitch, dbeat, bufferSelect;
dbeat = OSCSched.deltaTillNext(4);
Tempo.beats2secs(dbeat).wait;
loop({
length.do({
arg j;
j = j + start + offset;
bufferSelect = bufferArray.size.rand;
if ((rhythmArray.at(j) != 0), {
pitch = if (entropyConstValue == 0, {
[
pitchArray,
if (absValue == 1, {
rrand(randPitch*(-1),randPitch).abs
}, {
rrand(randPitch*(-1),randPitch)
});
].at(windex([1 - entropyValue, entropyValue]));
}, {
pitchArray.at(j);
});
Synth(synthDefArray.at((channelArray.at(bufferSelect) - 1).min(1)), [
"bus", bus.index,
"buffer", bufferArray.at(bufferSelect).bufnum,
"amp", ampArray.at(j) * volumeValue,
"start", sampleStart,
"end", sampleEnd,
"rate", rateValue + pitchArray.at(j),
], group, \addToHead);
if (entropyFillValue == 1, {
pitchArray.put(j, pitch);
if (entropyValue.coin, {
rhythmArray.wrapPut(j+[32,16,8,4,2,1]
.windex([probArray]), 1);
});
});
});
Tempo.beats2secs(0.25).wait;
});
});
});
//////////////////////////////////////////////////////////////
tableFill = {
var wholePlus, low, high, tally = 0, randVol;
rhythmArray=Array.new;
while ({rhythmArray.size <= 64}, {
wholePlus = [20, 24, 28, 32].choose;
rhythmArray=rhythmArray ++ [
([wholePlus] ++ Array.fill(wholePlus - 1, 0)),
[16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[8, 0, 0, 0, 0, 0, 0, 0],
[4, 0, 0, 0],
[2, 0],
[1],
].at(windex(
if (probArray.normalizeSum == [0, 0, 0, 0, 0, 1], {
probArray.normalizeSum;
}, {
(probArray.normalizeSum + [
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
].at(rhythmArray.size % 2)).normalizeSum;
});
));
});
(rhythmArray.size - 64).do({
rhythmArray.pop;
});
pitchArray=Array.fill(rhythmArray.size, {0});
rhythmArray.size.do({
arg j;
pitchArray.put(j,
if (absValue == 1, {
(rrand(-1*randPitch,randPitch)).abs;
}, {
(rrand(-1randPitch,randPitch));
});
);
});
randVol = {
arg j;
[0.9, 0.6, 0.7, 0.6, 0.8, 0.6, 0.7, 0.6].at(j % 8) + rrand(-0.2, 0.2);
};
ampArray=Array.fill(rhythmArray.size, {0});
rhythmArray.size.do({
arg i;
ampArray.put(i, randVol.value(i));
});
};
/*authors so far: casey basichis */ |