Get values from a control Bus within a Pdef?

Hi folks!

Noob question here, just trying to experiment with patterns.
Let’s say I have a simple Synth played by a Pdef:

SynthDef(\sine, {| freq = 440, dur = 1, vol = 0.4|
		var sig, func, env, out;

		func = Env.perc(releaseTime: dur);
		env = EnvGen.kr(func, doneAction: 2);
		sig = SinOsc.ar(freq) * env * vol;
		
		out = Out.ar(0, sig!2)
	}).add;

Pdef(\test,
		Pbind(
			\instrument, \sine,
			\dur, Prand([0.5, 1], inf),
			\freq, Prand([440, 550, 660], inf))
	).play;

Exciting.
Now, I connect an external MIDI controller and create a control Bus:

MIDIClient.init;
MIDIIn.connectAll;
~volume = Bus.control(s);

MIDIFunc.cc({arg ...args;
	~volume.value = args[0] / 127;
}, ccNum: 0, chan: 0);

What I’m struggling to do is to somehow get the value from the control bus to be used within my Pdef, something similar to this pseudo-code:

Pdef(\test,
		Pbind(
			\instrument, \sine,
			\dur, Prand([0.5, 1], inf),
			\freq, Prand([440, 550, 660], inf))
            \vol, ~volume //(.get? .map? .something?)
	).play;

I looked around for answers and tried out several methods, but I guess I don’t really understand how these control buses work…

If somebody could help me in figuring this out, it would be much appreciated!
Thank you!

1 Like
\vol, ~volume.asMap

.asMap returns a bus-mapping symbol, which will be inserted into the synth argument list. From there, the synth control is mapped to the bus and will respond to value changes.

hjh

2 Likes

Hi,

you can have look at miSCellaneous_lib’s tutorial file “Event patterns and LFOs”. It contains some alternative control strategies, including the use of synchronous busses.

best

Daniel

1 Like