Accessing Values in Multi-Channel Buses

Hi All,

silly question, but I can’t seem to work out how to access values from multi-channel buses in a SynthDef.

s.boot;

(
// Create k-rate bus for parameter control
~midiBus = Bus.control(s, 10);

SynthDef.new(\busTest, {
	arg cBus;

	Out.ar([0, 1], SinOsc.ar(In.kr(cBus, 1).midicps, 0, mul: 0.5));

});

~p0 = Synth(\busTest, [\cBus: ~midiBus]);



// Connect all available MIDI interfaces
MIDIIn.connectAll;

// Mappings for X-Station (synth mode)
~paramCCs = (
	72:  (\desc: "Body SINE Level", \busIndex: 0),
	73:  (\desc: "Body TRIANGLE Level", \busIndex: 1),
	74:  (\desc: "Body SAWTOOTH Level", \busIndex: 2),
	75:  (\desc: "Body SQUARE Level", \busIndex: 3),
	108: (\desc: "Body AMP Decay", \busIndex: 4),
	109: (\desc: "Body AMP Curve", \busIndex: 5),
	41:  (\desc: "Body PITCH", \busIndex: 6),
	110: (\desc: "Body PITCH Env Decay", \busIndex: 7),
	111: (\desc: "Body PITCH Env Curve", \busIndex: 8),
	44:  (\desc: "Body PITCH Env Depth", \busIndex: 9),
);

// Match cc 127, all channels
MIDIdef.cc(\test3, {
	arg val, cc, ch;

	// Post current CC (debug)
	//postln(cc);

	if(~paramCCs[cc] !== nil, {
		// Set value in 0 - 1 range to bus corresponding to CC number
		~midiBus.setAt(~paramCCs[cc][\busIndex], val);
		// Post value + description string
		//postln(~paramCCs[cc][\desc] + ": " + val);
		postln(~midiBus.getn);
	});

}, (1..127), 0);

)

Seems to be working great, but I can’t seem to access the values in the other bus channels.

I tried

In.kr(cBus + 1, 1)

…assuming that cBus is just the lowest index of the bus channels, but this doesn’t seem to work.

How do I get to these other values?

As a supplementary question; I can obviously feed bus values directly into k-rate UGens as args, but is it possible to force local variables inside a SynthDef to be updated whenever the value of a particular bus changes?

I’d like to do some pre-processing of values from a bus, before feeding them into oscillator etc. UGens, and would prefer not to do it “inline”, for readability.

You are correct about how to access the bus channels (see the code below), so your error is somewhere else.

Also, control bus channels are by nature k-rate, so as long as the UGen you are using is control or audio rate, it will be being updated at that rate.

s.boot;

(

// Create k-rate bus for parameter control

~midiBus = Bus.control(s, 10);

~midiBus.setn([60, 62, 64, 65, 67, 69, 71, 72, 74, 76]);

a = SynthDef.new(\busTest, {

arg cBus, add;

var freq;

freq = In.kr(cBus+add, 1).midicps;

Out.ar([0, 1], SinOsc.ar(freq, 0, mul: 0.1));

}).play(s, [\cBus, ~midiBus, \add, rrand(0, 9)])

)

Hi @Sam_Pluta, thanks very much for getting back to me.

It’s now working!