[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] timeScale and one other problem



Could someone here give me a hand with this... Its
pretty simple but i cant get it to work.  I suspect
theres a problem in the timeScale in the envelope,
because if i take that out i can get it to make sound,
but for some reason i still cant get the volume slider
and mute button to work.  Any thoughts?




var numLoops;
var window;
var mainGroup, mainBus;

numLoops = 4;
mainGroup = Group.new;
mainBus = Bus.new;

// SynthDef and Routine
===================================================

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

//
===============================================================

window = SCWindow("Looper", Rect(0,0,numLoops * 85 -
5,120));
window.view.background = Color.rand;
window.front;
window.onClose = {
	mainGroup.free;
};

numLoops.do({
	arg i;
	var buffer, group, soundDuration;
	var loadButton, fileString, loopRange, volPanSlider,
muteButton;
	var loopOffset, loopLength;
	var loopRoutine;
	
	group = Group.new(mainGroup);
	
	loopRoutine = Routine({
		var offset, length;
		loop({
			offset = soundDuration * loopOffset;
			length = soundDuration * loopLength;
			"bus, buffer, rate, offset, length".postln;
			Synth("Looper", [
				"bus", mainBus.index.postln,
				"buffer", buffer.bufnum.postln,
				"rate", 1.0.postln,
				"offset", offset.postln,
				"length", length.postln
			], group);
			length.wait;
			"end".postln;
			"".postln;
		});
	});

	loadButton = SCButton(window, Rect((85 * i), 0, 80,
20)).states_(
		[["Load", Color.black, Color.rand]]
	).action = {
		CocoaDialog.getPaths({
			arg path;
			var soundfile;
			loopRoutine.stop;
			buffer.free;
			loopRoutine.reset;
			loopRange.lo_(0.0).hi_(1.0);
			
			soundfile = SoundFile.new;
			soundfile.openRead(path.at(0));
			soundDuration = soundfile.duration;
			buffer = Buffer.read(s, path.at(0));
			fileString.string_(" " ++ BaseName(path.at(0)));
			
			SystemClock.play(loopRoutine);
		}, {"Canceled".postln}, 1);
	};

	fileString = SCStaticText(window,
Rect((85*i),20,80,20)).string_(" empty")
		.background_(Color.rand);
	
	loopRange = SCRangeSlider(window, Rect((85 * i), 40,
80, 20))
		.lo_(0.0).hi_(1.0)
		.background_(Color.rand)
		.action = {
			loopOffset = loopRange.lo;
			loopLength = loopRange.hi - loopRange.lo;
		};
	
	volPanSlider = SC2DSlider(window, Rect((85 * i), 60,
80, 40))
		.x_(0.5).y_(0.0)
		.background_(Color.rand)
		.action = {
			group.set("amp", 1 - volPanSlider.y);
		};
	
	muteButton = SCButton(window, Rect((85 * i), 100, 80,
20))
		.states_(
			[["Mute", Color.black, Color.rand],
			["UnMute", Color.black, Color.rand]]
		)
		.action = {
			group.set("mute", 1 - muteButton.value);
		};

});

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com