You can ignore that, because you already have a trigger signal coming from the bela pins.
See Node:map help for info on synth control bus mapping. But you don’t strictly speaking need bus mapping for your final version. This was just a convenient way to provide a trigger signal without requiring user interaction.
No. Alternately:
a = { |gate = 1, amp = 0.1|
var main_eg = EnvGen.kr(Env.asr(0.01, 1, 0.1), gate, doneAction: 2);
var trigVariableToProvideAccessToTheSynthControlInput = NamedControl.tr(\trigNameOfTheSynthControlInput, 0);
var toggle = ToggleFF.kr(trigVariableToProvideAccessToTheSynthControlInput);
var gates = [toggle, toggle <= 0];
var egs = EnvGen.kr(Env.asr(0.01, 1, 0.01), gates);
var players = PlayBuf.ar(1, b, BufRateScale.kr(b),
gates,
startPos: TRand.kr(0, BufFrames.kr(b) * 0.5, gates)
);
Out.ar(0, ((players * egs).sum * (main_eg * amp)).dup)
}.play(args: [trigNameOfTheSynthControlInput: c.asMap]);
Within a SynthDef function, we can use variables to refer to parts of the DSP graph. (Arguments are, practically speaking, variables – the only difference is that arguments receive values from outside when the function is called, while variables are completely local, 100% under control of the scope in which they are defined.)
When a Synth runs in the server, you can get control information into it using buses (In.kr
) or control inputs. It’s inconvenient to allocate buses for everything, so SynthDefs have named control inputs. We use control input a lot, and buses somewhat less. (Buses are good for control values that are shared across many nodes; control inputs are good for per-synth values.)
SynthDef function arguments are converted into control inputs, and control input channels are passed into the function at SynthDef build time (which is how UGen inputs get connected to these control inputs). So there are already two elements to gate = 1
, for instance: the control input named gate
with default = 1, and the argument/variable gate
which receives a handle to that control input.
For demo purposes, I wanted to be sure that the trigger signal is a true trigger (1 only momentarily). For control inputs, this can be done by defining it as a trigger. This can be done with argument names, but it’s a bit icky. It’s more clear to define the control explicitly as “trigger rate”: .tr
. .tr
exists basically only for the NamedControl
class, where it produces a TrigControl control input. (Note that \someName.kr(...)
is just a shortcut for NamedControl – and that the shortcut syntax also confused you earlier in this thread.)
But doing it this way exposes the two elements, which, in an argument list, are collapsed into one expression. The NamedControl needs… well… a name, which is provided as a symbol \trig
. And to access the control elsewhere, it needs a variable, which is declared: var trig
. But the name by which the control is exposed to the outside world, and the variable name used locally to access the control, are conceptually not the same thing.
(It’s also possible to dispense with the var
and just write ToggleFF.kr(\trig.tr(0))
. This is a matter of taste. Personally, I find it bothersome to have to scan through the entire function to find control input definitions, which may then be anywhere in a line, not only near the left. Others very much prefer not to be bothered with variable declarations. But, the problem in that case is that you have to be sure every time \trig.tr
is written in the same SynthDef that it has the same default value. I’ve actually argued elsewhere that neither arguments nor \name.kr(default)
syntax are good solutions to the problem, and that what’s needed is a bespoke syntax. I prototyped such a thing, but it hasn’t come into wide use. At the end of the day, it’s largely a matter of preference. For some, SynthDef function arguments are more transparent and intuitive at least for “normal” kr single-valued controls, but others feel that there is unpleasant magic lurking behind them and they prefer writing inline \symbol.kr style. I know which way I like better, but I’m not going to tell you what you should do.)
hjh