View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide

Runtime Patch Workaround

Ok, here is a sorta hack to get patchable effects working.

Note:

this works only with Instr directory given. For more help on this, see crucial library help in the help folder.

How to install:

In this example its reading in my Instr directory "/Applications/Supercollider/Instr/" from a file Effect.rtf,
so all the instrs have to be named something along the lines of Instr([\Effect, \myEffect] ... where my effect is the effect.

If you want to use this for putting effects on something other than an AudioInputPlayer, you have to create a patch like this in place of the AudioInPlayer: patch = Patch({arg inbus; In.ar(inbus, 2)});

BTW the bulk of the code is getting it to remeber the setting of all the other effects if you change one, because it reassembles all of the effects into a single Patch every time you change anything.

The only things i havent been able to figure out yet are:
1) How to get individual gui's for each effect, i tried seperating the patches after they were built and setting the inputs to nil and calling a gui but that gives errors.
2) Getting it to use XOut
////////////////////////////////////////////////////////////////////////
/// 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
*/


Link to this Page