////////////////////////////////////////////////////////////////////////
/// VARIABLES
////////////////////////////////////////////////////////////////////////
///// GUI
var window, compView, numSlots = 6, volumeValue = 0, startValue = 0;
////// INSTR DIRECTORY
var instrRtfs, rtfArray, rtfString;
var file, instrArray, instrNameArray;
var instrDir;
var instrProb;
/////// PATCH
var patch, patchFunction;
var effectOnArray, effectSocketArray;
var prevPatchArray, prevOnArray, prevArgsArray;
////////////////////////////////////////////////////////////////////////
/// INITIALIZATION
////////////////////////////////////////////////////////////////////////
////// INSTR DIRECTORY
instrDir = "/Applications/Supercollider/Instr/";
instrRtfs = Cocoa.getPathsInDirectory(instrDir);
(instrRtfs.size - 1).do({
arg i;
file = File(instrDir ++ instrRtfs.at(i + 1), "r");
String.readNew(file).compile.value;
file.close;
});
Library.at(\Instr).at(\Effect).do({
arg file;
file.do({
arg instr;
instrArray = instrArray.add(instr.name);
});
});
instrArray.do({
arg item;
instrNameArray = instrNameArray.add(item.at(1).asString);
});
////// OTHER
effectOnArray = Array.fill(numSlots, {0});
effectSocketArray = Array.fill(numSlots, {0});
prevPatchArray = Array.fill(numSlots, {0});
prevOnArray = Array.fill(numSlots, {0});
prevArgsArray = Array.fill(numSlots, {0});
patch = AudioInPlayer.new;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
window = SCWindow("Guitar Effects", Rect(0, 0, 110, 75 + (numSlots*20)), false).front;
window.view.background_(Color(0.9, 0.6, 0.6));
window.onClose_({
patch.free;
});
/// GUI //////////////////////////////////////////////////////////////////
compView = SCCompositeView(window, Rect(5, 5, 100, 65 + (numSlots*20)))
.background_(Color(0.7, 0.4, 0.4));
SCButton(compView, Rect(10, 10, 90, 15))
.states_([
["Start", Color.black, Color(0.9, 0.6, 0.6)],
["Stop", Color.black, Color(0.9, 0.6, 0.6)]
])
.action_({
arg view;
startValue = view.value;
if (view.value == 1, {
patch.play;
}, {
patch.stop;
});
});
SCButton(compView, Rect(10, 30, 90, 15))
.states_([["GUI", Color.black, Color(0.9, 0.6, 0.6)]])
.action_({
arg view;
patch.gui;
});
numSlots.do({
arg i;
SCButton(compView, Rect(10, 50 + (i*20), 15, 15))
.states_([
[" ", Color.black, Color(0.9, 0.6, 0.6)],
["|", Color.black, Color(0.9, 0.6, 0.6)]
])
.action_({
arg view;
effectOnArray.put(i, view.value);
patchFunction.value;
prevOnArray.put(i, view.value);
});
SCPopUpMenu(compView, Rect(25, 50 + (i*20), 75, 15))
.items_(instrNameArray)
.action_({
arg view;
effectSocketArray.put(i, view.value);
if (effectOnArray.at(i) == 1, {
patchFunction.value;
});
prevPatchArray.put(i, view.value);
});
});
SCSlider(compView, Rect(10, 50 + (numSlots*20), 90, 15))
.action_({
arg view;
patch.args.at(1).activeValue_(view.value).changed;
});
patchFunction = {
var tempArray, hasPatch, index = 0;
if (patch.isPlaying, {
patch.stop;
});
tempArray = Array.new;
prevArgsArray = Array.fill(numSlots, {nil});
hasPatch = true;
if (patch.isKindOf(AudioInPlayer) == false, {
while ({patch.isKindOf(Patch)}, {
tempArray = tempArray.add(patch.args);
patch = patch.args.at(0);
});
});
prevOnArray.do({
arg item, i;
if ((item == 1) && (effectSocketArray.at(i) == prevPatchArray.at(i)), {
prevArgsArray.put(i, tempArray.pop);
});
});
patch.free;
patch = AudioInPlayer.new;
effectSocketArray.do({
arg item, i;
if (effectOnArray.at(i) == 1, {
if (prevArgsArray.at(i) == nil, {
patch = Patch(instrArray.at(item.asInteger), [patch]);
}, {
prevArgsArray.at(i).do({
arg item, j;
if (item.isKindOf(KrNumberEditor) == false, {
if (item.isKindOf(AudioInPlayer)||item.isKindOf(Patch), {
prevArgsArray.at(i).put(j, patch);
}, {
prevArgsArray.at(i).put(j, nil);
});
}, {
prevArgsArray.at(i).put(
j, KrNumberEditor(item.value, item.spec)
);
});
});
patch = Patch(instrArray.at(item.asInteger) ,prevArgsArray.at(i));
});
});
});
if (startValue == 1, {patch.play});
};
*****
/*authors so far: casey basichis */ |