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

Re: [sc-users] SuperCollider Volume Control?



Sure...

Josh

On Dec 11, 2007, at 5:47 PM, Scott Wilson wrote:

I mean as a default.

On 12 Dec 2007, at 01:44, Scott Wilson wrote:

Why not just read numChannels from the server's options?

S.

On 12 Dec 2007, at 01:37, Josh Parmenter wrote:



How about this (server works... added a few other things - min and max, numChannels, and startbus):

/*
// Utility class for a simple general volume
// andrea after Josh

// Volume.new(server, startBus, numChans, min, max); // min and max in db

a = Volume.new; // use all defaults

z = {SinOsc.ar(440 * [1, 2], 0, 0.2)}.play(s)

a.close; // frees the Volume control. So does closing the window

// only control the left channel
a = Volume.new(startBus: 1, numChans: 1, min: -60, max: 12);

a.close;

z.free;

*/

Volume {

	var server, <amp, <>window,  <volume, spec ;
	var slider, box, <lag ;

	
*new { arg server, startBus = 0, numChans = 2, min = -90, max = 6 ;
		^super.new.initVolume(server, startBus, numChans, min, max) ;
	}

	initVolume { arg aServer, aStartBus, aNumChans, aMin, aMax ;
		var cond;
		cond = Condition.new;
		server = aServer ?? {Server.default};
		if ( server.serverRunning.not, { server.boot }) ;
		volume = 0;
		spec = [aMin, aMax, \db].asSpec;
		//server = Server.default.boot ;
		server.doWhenBooted({
			Routine.run({
				this.sendDef(aStartBus, aNumChans);
				server.sync(cond);
				{
					this.gui;
					this.volume_(0);
					this.play;
					}.defer;
				});
			})
	}

	// avoid confilcts with someone elses SynthDef called \amp
	// by giving it a name that hopefully won't be used!
	sendDef {arg startBus, numChans;
		SynthDef(\volume_amp_sd_32768, { arg amp = 1, lag = 0.1;
ReplaceOut.ar( startBus, In.ar(startBus, numChans) * Lag.kr(amp, lag) );
		}).send(server);
	}

	play {
		amp = Synth(\volume_amp_sd_32768, [\amp, volume.dbamp, \lag, lag],
			target: 0, addAction: \addToTail);	
		}	
		
	// cleaner with MVC - in db
	volume_ { arg aVolume ;
		volume = aVolume ;
		amp.set([\amp, volume.dbamp]) ;
		box.value_(volume.round(0.01)) ;
		slider.value_(spec.unmap(volume)) ;
	}
	
	lag_ {arg aLagTime;
		lag = aLagTime;
		amp.set([\lag, lag]);
		}
		
	
	gui {
		window = GUI.window.new("Volume", Rect(100, 100, 80, 330)).front;
		box = GUI.numberBox.new(window, Rect(10, 10, 60, 30))
			.value_(volume) ;
		slider = GUI.slider.new(window, Rect(10, 40, 60, 280))
			.value_(volume) ;
		slider.action_({ arg item ;
			this.volume_(spec.map(item.value));
		}) ;
		box.action_({ arg item ;
			this.volume_(item.value) ;
		}) ;
		window.onClose_({
			amp.free;
			});
	
	}
	
	close {
		window.close;
		}

}
On Dec 11, 2007, at 3:34 PM, Andrea Valle wrote:

Josh,

I was going to write exactly a little utility class with the proposed mechanism, so I used yours (thanks!). Now, I have to pass the constructor a server, I was thinking I could refer to Server.default inside the class (i.e. without passing a server), but doesn't work in this way.
What am I missing?

Best

-a-



// Utility class for a simple general volume
// andrea after Josh

/*
// a sound
{SinOsc.ar(mul:0.1)}.play

v = Volume.new(s) ;
v.gui ;
v.volume_(0.5) ;
v.volume ;

*/

Volume {

	var server, amp, <>window,  <volume ;
	var slider, box ;

	
	*new {  arg server ;
		^super.new.initVolume(server) ;
	}

	initVolume { arg aServer ;
		server = aServer ;
		if ( server.serverRunning.not, { server.boot }) ;
		//server = Server.default.boot ;
		server.doWhenBooted({
			this.sendDef ;
			}) ;
		volume = 1 ;
	}

	sendDef {
		SynthDef(\amp, { arg inbus, amp = 1;
			ReplaceOut.ar( inbus, In.ar(inbus, 2) * amp );
		}).send(server);
		amp = Synth(\amp, target: 0, addAction: \addToTail) ;
	}
	
	// cleaner with MVC
	volume_ { arg aVolume ;
		volume = aVolume ;
		amp.set([\amp, volume]) ;
		box.value_(aVolume) ;
		slider.value_(aVolume) ;
	}
		
	gui {
		window = GUI.window.new("Volume", Rect(100, 100, 60, 320)).front;
		box = GUI.numberBox.new(window, Rect(10, 10, 60, 30))
			.value_(volume) ;
		slider = GUI.slider.new(window, Rect(10, 40, 60, 280))
			.value_(volume) ;
		slider.action_({ arg item ;
			volume =  item.value ;
			amp.set([\amp, volume]) ;
			box.value_(volume) ;
		 }) ;
		box.action_({ arg item ;
			volume = item.value ;
			amp.set([\amp, volume]) ;
			slider.value_(volume)
		 }) ;
	
	}

}





--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - DAMS
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> andrea.valle@xxxxxxxx
--------------------------------------------------


I did this interview where I just mentioned that I read Foucault. Who doesn't in university, right? I was in this strip club giving this guy a lap dance and all he wanted to do was to discuss Foucault with me. Well, I can stand naked and do my little dance, or I can discuss Foucault, but not at the same time; too much information.
(Annabel Chong)




_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users

******************************************
/* Joshua D. Parmenter
http://www.realizedsound.net/josh/

“Every composer – at all times and in all cases – gives his own interpretation of how modern society is structured: whether actively or passively, consciously or unconsciously, he makes choices in this regard. He may be conservative or he may subject himself to continual renewal; or he may strive for a revolutionary, historical or social palingenesis." - Luigi Nono
*/


******************************************
/* Joshua D. Parmenter
http://www.realizedsound.net/josh/

“Every composer – at all times and in all cases – gives his own interpretation of how modern society is structured: whether actively or passively, consciously or unconsciously, he makes choices in this regard. He may be conservative or he may subject himself to continual renewal; or he may strive for a revolutionary, historical or social palingenesis." - Luigi Nono
*/


_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users



_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users



_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users

******************************************
/* Joshua D. Parmenter
http://www.realizedsound.net/josh/

“Every composer – at all times and in all cases – gives his own interpretation of how modern society is structured: whether actively or passively, consciously or unconsciously, he makes choices in this regard. He may be conservative or he may subject himself to continual renewal; or he may strive for a revolutionary, historical or social palingenesis." - Luigi Nono
*/