Ndef to control bus?

I’m trying to send data to control bus with help of Ndef.

(
SynthDef(\fExample, {
	arg freq=440, gate=1, out=0, amp=0.1, ffreq=2000;
	var snd = Saw.ar([freq, freq*1.01]);
	var env = Linen.kr(gate, doneAction:2);
	snd = LPF.ar(snd, ffreq);
	Out.ar(out, snd*env*amp);
}).add
)

~ffreqCtlBus = Bus.control(s,1);
~ffreqCtlBus.value = 3000; // works
~ffreqCtlBus.value = 300; // works

Pdef(\fx1).play
(
Pbindef(\fx1,
	\instrument, \fExample,
	\dur, 4,
	\ffreq, ~ffreqCtlBus.asMap
)
)

// how to use Ndef/Proxy to control values on control bus with a synth?
Ndef.control(\ffreqCtl0,1)
~ctrlg = Group.new(s, \addBefore)
Ndef(\ffreqCtl0).play(out: ~ffreq, numChannels:1, group: ~ctrlg) // special group before?
Ndef(\ffreqCtl0, { SinOsc.kr(0.5).range(50,2000)}) // does not work.
Ndef(\ffreqCtl0, { SinOsc.kr(0.5).range(50,2000)}).play(out: ~ffreq, numChannels:1, group: ~ctrlg)
Ndef(\ffreqCtl0).clear

In post window I get WARNING: Can't monitor a control rate bus. and the SinOsc is not controlling the instrument run by Pbind/Pdef.

How can I use some kind of on-the-fly/JIT/proxy / crossfading structure, from within which I can send data to a control bus that is controlling some other Synth parameter?

You can assign the bus:

Ndef(\ffreqCtl0).bus = ~ffreqCtlBus

Or since Ndef create a bus itself, you can directly use it without creating your own bus:

Pbindef(\fx1,
	\instrument, \fExample,
	\dur, 4,
	\ffreq, Ndef(\ffreqCtl0),
)
1 Like

Awesome! These both solutions work greatly! I have completed example from above like this as a demonstration:

(
SynthDef(\fExample, {
	arg freq=440, gate=1, out=0, amp=0.1, ffreq=2000;
	var snd = Saw.ar([freq, freq*1.01]);
	var env = Linen.kr(gate, doneAction:2);
	snd = LPF.ar(snd, ffreq);
	Out.ar(out, snd*env*amp);
}).add
)

//////////////////////////////////////////////////////
// example 1 - using Ndef's control bus

Ndef.control(\ffreqCtl0,1)
Ndef(\ffreqCtl0, { SinOsc.kr(10).range(50,2000)}) 

Pdef(\fx1).play
(
Pbindef(\fx1,
	\instrument, \fExample,
	\dur, 4,
	\octave, 3,
	\ffreq, Ndef(\ffreqCtl0)
	
)
)

// now change Ndef:
Ndef(\ffreqCtl0, { SinOsc.kr(1).range(50,2000)}) 


//////////////////////////////////////////////////////
// example 2 - using separate control bus

~ffreqCtlBus = Bus.control(s,1);
Ndef.control(\ffreqCtl0,1)
Ndef(\ffreqCtl0).bus = ~ffreqCtlBus
Ndef(\ffreqCtl0, { SinOsc.kr(10).range(50,2000)}) 

Pdef(\fx1).play
(
Pbindef(\fx1,
	\instrument, \fExample,
	\dur, 4,
	\octave, 3,
	\ffreq, ~ffreqCtlBus.asMap	
)
)

// now change Ndef:
Ndef(\ffreqCtl0, { SinOsc.kr(1).range(250,2000)}) 

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

Thank you @hemiketal!

1 Like