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

puff bunny beat cutter 1.0

puff bunny beat cutter 1.0:

UPDATE 5/27/03 NEW OLD CODE... MORE STABLE... stay tuned for a new puff bunny that combines the others and is totally bad ass, its almost done...

Requirements:

Instructions:
////////////////////////////////////////////////////////////////////////////////////////////////////////

var rhythmArray, ampArray, positionArray, probArray, rhythmArrayCopy, sampleArray;
var randVol;
var barLength = 32, barOffset = 0, barHigh = 32, tempo = 120 , mainRoutine, tableFill;

var bus, bufferArray, bufferSizeArray, bufferBarsArray = 32, channelsArray = 1, group, synthDefArray;

var pathPopUp;
var volSlider, volMidi;
var lengthValue = 1, entropyValue = 0, sampleEntropy = 0, pathPopUpValue = 0, rollProb = 0;
var entropyConstValue = 0, entropyFillValue = 0;
var volumeValue = 1;

var tally = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////

bufferArray = Array.new;
bufferSizeArray = Array.new;
bufferBarsArray = Array.new;
channelsArray = Array.new;

bus = Bus.new;
group = Group.head(RootNode.new);
probArray = [0.1, 0.2, 0.4, 0.5, 0.4];
//	Tempo.bpm_(160);

////////////////////////////////////////////////////////////////////////////////////////////////////////

SynthDef("DrumCutterMono", {
	arg bus, buffer, amp, rate, length, offset;
	var env, sound;
	env = EnvGen.kr(Env.new([0,1,1,0], [0.01, 0.98, 0.01]),
		timeScale:length, levelScale:amp, doneAction:2);
	sound = PlayBuf.ar(1, buffer, rate, 1.0, offset * 44100, 1) * env;
	Out.ar(bus, [sound, sound]);
}).load(s);

SynthDef("DrumCutterStereo", {
	arg bus, buffer, amp, rate, length, offset;
	var env, sound;
	env = EnvGen.kr(Env.new([0,1,1,0], [0.01, 0.98, 0.01]),
		timeScale:length, doneAction:2) * amp;
	sound = PlayBuf.ar(2, buffer, rate, 1.0, offset * 44100, 1) * env;
	Out.ar(bus, sound);
}).load(s);

SynthDef("DrumCutterMonoLoop", {
	arg bus, buffer, amp, rate, length, offset, speed;
	var env, sound, offSmp;
	offSmp = offset * 44100;
	env = EnvGen.kr(Env.new([0,1,1,0], [0.01, 0.98, 0.01]),
		timeScale:length, levelScale:amp, doneAction:2);
	sound = LoopBuf.ar(1, buffer, rate, 1.0, offSmp, offSmp + (speed * 44100)) * env;
	Out.ar(bus, [sound, sound]);
}).load(s);

SynthDef("DrumCutterStereoLoop", {
	arg bus, buffer, amp, rate, length, offset, speed;
	var env, sound, offSmp;
	offSmp = offset * 44100;
	env = EnvGen.kr(Env.new([0,1,1,0], [0.01, 0.98, 0.01]),
		timeScale:length, doneAction:2) * amp;
	sound = LoopBuf.ar(2, buffer, rate, 1.0, offSmp, offSmp + (speed * 44100)) * env;
	Out.ar(bus, sound);
}).load(s);

synthDefArray = ["DrumCutterMono", "DrumCutterStereo", "DrumCutterMonoLoop", "DrumCutterStereoLoop"];

////////////////////////////////////////////////////////////////////////////////////////////////////////

w = SCWindow(" ", Rect(0, 0, 110, 340), false);
w.view.background_(Color.new(0.8, 0.8, 1.0));
w.front;
w.onClose = {
	mainRoutine.stop;
	bufferArray.do({
		arg item;
		item.free;
	});
	group.free;
	bus.free;
	volMidi.free;
};

SCButton(w, Rect( 10, 10, 90, 15))
	.states_([["load", Color.black, Color.new(0.7, 0.7, 0.9)]])
	.action = {
		CocoaDialog.getPaths({
			arg paths;
			var sf, low, high, bbars;
			paths.do({
				arg item, i;
			
				sf = SoundFile.new;
				sf.openRead(item);
				channelsArray = channelsArray.add(sf.numChannels);
				bufferSizeArray = bufferSizeArray.add(sf.duration);
				sf.close;
				
				bbars = (bufferSizeArray.last / (Tempo.beats2secs(4))).asInteger.max(1);
				low = bbars.log2.asInteger;
				high = 2.pow(low + 1);
				low = 2.pow(low);
				bufferBarsArray = bufferBarsArray.add([low,high].at((((bbars - low) / (high - low)) + 0.4)
					.round(1).asInteger.min(1).max(0)));
				bufferBarsArray.last;
				bufferArray = bufferArray.add(Buffer.read(s, item));
				pathPopUp.items_(pathPopUp.items.add(BaseName(item)));
			});
		}, {"Canceled".postln}, 20);
	};

SCButton(w, Rect(10, 30, 15, 15))
	.states_([["-"]])
	.action_({
		var items;
		channelsArray.removeAt(pathPopUp.value);
		bufferSizeArray.removeAt(pathPopUp.value);
		bufferBarsArray.removeAt(pathPopUp.value);
		bufferArray.at(pathPopUp.value).free;
		bufferArray.removeAt(pathPopUp.value);
		items = pathPopUp.items;
		items.removeAt(pathPopUp.value);
		pathPopUp.items_(items);
	});
	
pathPopUp = SCPopUpMenu(w, Rect(25, 30, 75,15))
	.action_({
		arg view;
		pathPopUpValue = view.value;
	});


SCButton(w, Rect( 10, 50, 90, 15))
	.states_([
		["Start", Color.black, Color.new(0.7, 0.7, 0.9)], 
		["Stop", Color.black, Color.new(0.6, 0.6, 0.8)]
	])
	.action_({
		arg view;
		if (view.value == 1, {
			mainRoutine.reset;
			SystemClock.play(mainRoutine);
		}, {
			mainRoutine.stop;
		});
	});
	
SCButton(w, Rect( 10, 70, 90, 15))
	.states_([["Fill", Color.black, Color.new(0.7, 0.7, 0.9)]])
	.action_({
		var tally = 0;
		tableFill.value;
		(barLength).do({
			arg i;
			if (rhythmArray.at(barHigh - 1 - i) == 0, {
				tally = tally + 1
			}, {
				rhythmArrayCopy.put((barHigh -1- i), tally + 1);
				tally = 0;
			});
		});			
	});
	
SCRangeSlider(w, Rect( 10, 90, 90, 15))
	.step_(0.25)
	.hi_(0.5)
	.lo_(0)
	.action_({
		arg view;
		var tally = 0, high;
		barLength = ((view.hi - view.lo) * 64).max(16).asInteger;
		barOffset = (view.lo * 64).asInteger;
		barHigh = (view.hi * 64).asInteger.max(16);
		
		(barLength).do({
			arg i;
			if (rhythmArray.at(barHigh - 1 - i) == 0, {
				tally = tally + 1
			}, {
				rhythmArrayCopy.put((barHigh -1- i), tally + 1);
				tally = 0;
			});
		});
	});

SCStaticText(w, Rect( 10, 110, 90, 15))
	.string_("Probability")
	.align_(\center)
	.background_(Color.new(0.7, 0.7, 0.9));
	
SCMultiSliderView(w, Rect(10, 130, 90, 60))
	.gap_(0)	
	.thumbSize_(90 / 5)
	.action_({
		arg view;
		probArray.put(view.index, view.currentvalue);
	})
	.value_(probArray);
	
SCSlider(w, Rect( 10, 195, 90, 15))
	.value_(0.5)
	.action_({
		arg view;
		lengthValue = view.value;
	})
	.value_(1);

SCSlider(w, Rect( 10, 215, 90, 15))
	.value_(0.5)
	.action_({
		arg view;
		entropyValue = view.value;
	})
	.value_(0);
	
SCSlider(w, Rect( 10, 235, 90, 15))
	.value_(0.5)
	.action_({
		arg view;
		sampleEntropy = view.value;
	})
	.value_(0);
	
SCSlider(w, Rect( 10, 255, 90, 15))
	.value_(0.5)
	.action_({
		arg view;
		rollProb = view.value;
	})
	.value_(0);
	
SCButton(w, Rect( 10, 275, 90, 15))
	.states_([
		["Constant Entropy", Color.black, Color.new(0.7, 0.7, 0.9)], 
		["Random Fill", Color.black, Color.new(0.6, 0.6, 0.8)]
	])
	.action_({
		arg view;
		entropyConstValue = view.value;
	});

SCButton(w, Rect( 10, 295, 90, 15))
	.states_([
		["Entropy Write Off", Color.black, Color.new(0.7, 0.7, 0.9)], 
		["Entropy Write On", Color.black, Color.new(0.6, 0.6, 0.8)]
	])
	.action_({
		arg view;
		entropyFillValue = view.value;
	});
	
volSlider = SCSlider(w, Rect(10, 315, 90, 15))
	.value_(1)
	.action_({
		arg view;
		volumeValue = \amp.asSpec.map(view.value);
	});
	
volMidi = MidiSlider.slider(volSlider);
w.name_("     " ++ (volMidi.cc + 1).asString);
	
SCStaticText(w, Rect(5, 5, 100, 330))
	.string_(" ")
	.background_(Color.new(0.6, 0.6, 0.8));

////////////////////////////////////////////////////////////////////////////////////////////////////////

mainRoutine = Routine({
	var offset, dbeat, sample, length, loop;
	dbeat = OSCSched.deltaTillNext(4);
	Tempo.beats2secs(dbeat).wait;
	loop({
		barLength.do({
			arg i;
			i = i + barOffset;
			if (rhythmArrayCopy.at(i) != 0, {				
				sample = [pathPopUpValue, sampleArray.at(i)].at(
						windex([1 - sampleEntropy, sampleEntropy]));
				offset = if (entropyConstValue == 0, {
					[positionArray.at((i % (bufferBarsArray.wrapAt(sample) * 16)).asInteger), 
						(bufferBarsArray.wrapAt(sample) * 16.rand)
					].at(windex([1 - entropyValue, entropyValue]));
				}, {
					positionArray.at((i % (bufferBarsArray.wrapAt(sample) * 16)).asInteger);
				});
				loop = windex([1 - rollProb, rollProb]);
				length = Tempo.beats2secs(0.25)*(rhythmArrayCopy.at(i)*lengthValue).max(0.2);
				if (((loop == 1) &amp; (rhythmArrayCopy.at(i) < 4)), {
					Synth(synthDefArray.at(channelsArray.wrapAt(sample) + 1), [
						"bus", bus.index,
						"buffer", bufferArray.wrapAt(sample).bufnum,
						"amp", ampArray.at(i) * volumeValue,
						"rate", bufferSizeArray.wrapAt(sample) / 
							Tempo.beats2secs(4*bufferBarsArray.wrapAt(sample)),
						"length", length,
						"speed", Tempo.beats2secs([0.0625, 0.125, 0.25, 0.33].choose),
						"offset",(bufferSizeArray.wrapAt(sample)/
							(bufferBarsArray.wrapAt(sample)*16))*offset
					], group, \addToHead);
				}, {
					Synth(synthDefArray.at((channelsArray.wrapAt(sample) - 1).min(1)), [
						"bus", bus.index,
						"buffer", bufferArray.wrapAt(sample).bufnum,
						"amp", ampArray.at(i) * volumeValue,
						"rate", bufferSizeArray.wrapAt(sample) / 
							Tempo.beats2secs(4*bufferBarsArray.wrapAt(sample)),
						"length", length,
						"offset",(bufferSizeArray.wrapAt(sample)/
							(bufferBarsArray.wrapAt(sample)*16))*offset
					], group, \addToHead);
				});
				if (entropyFillValue == 1, {
					positionArray.put(i, offset);
				});
			});
			Tempo.beats2secs(0.25).wait;
		});
	});
});

////////////////////////////////////////////////////////////////////////////////////////////////////////

tableFill = {
	var wholePlus, low, high, tally = 0;
	/*
	bufferSizeArray.do({
		arg item, i;
		var bufferBars;
		bufferBars = (item / (Tempo.beats2secs(4))).asInteger.max(1);
		low = bufferBars.log2.asInteger;
		high = 2.pow(low + 1);
		low = 2.pow(low);
		bufferBars = [low,high].at((((bufferBars - low) / (high - low)) - 0.25)			.round(1).asInteger);
		bufferBarsArray.put(i, bufferBars);
	});
	*/	
	
	rhythmArray = Array.new;
				
	while ({rhythmArray.size <= 64}, {
		wholePlus = [16, 20, 24, 28, 32].choose;
		rhythmArray = rhythmArray ++ [
			([wholePlus] ++ Array.fill(wholePlus - 1, 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, 1], {
				probArray.normalizeSum;
			}, {
				probArray.normalizeSum + [
					[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
			});
		));
	});
	
	rhythmArrayCopy = rhythmArray;
			
	positionArray = Array.fill(rhythmArray.size, {0});
		
	rhythmArray.do({
		arg item, i;
		positionArray.put(i, [i , rhythmArray.size.rand]
			.at(windex([1 - entropyValue, entropyValue])));
	});
			
	randVol = {
		arg i;
		[0.9, 0.6, 0.7, 0.6, 0.8, 0.6, 0.7, 0.6].at(i % 8) + rrand(-0.2, 0.2);
	};
	
	ampArray = Array.fill(rhythmArray.size, {0});
	
	
	rhythmArray.do({
		arg item, i;
		ampArray.put(i, randVol.value(i));
	});
	
	sampleArray = Array.fill(rhythmArray.size, {20.rand});
};

tableFill.value;
(barLength).do({
	arg i;
	if (rhythmArray.at(barHigh - 1 - i) == 0, {
		tally = tally + 1
	}, {
		rhythmArrayCopy.put((barHigh -1- i), tally + 1);
		tally = 0;
	});
});	
     
************
/*
authors so far:
casey basichis
*/


Links to this Page