Sending a trigger into a SynthDef from a pattern

How can I play this SynthDef by sending a trigger with a pattern? I have a Dust Ugen doing what I want to hear. A clean ringing. Ive tried various things, but they didn’t work. Looked online for examples of sending a trigger into a SynthDef with a pattern, and found nothing. Thank you

(
SynthDef(\smrDynKlank, {
    arg out=0, gate=1, t_trig=1, trigRate=10,
    freq=440, rotate=0, spread=0.5, resonance=0.5,
    morph=0, slew=0.1, masterLevel=0.5;
    var input, sig, numBands=6;
    var freqs, amps, decayTimes;

    // Generate input based on trigger or continuous rate
	input = Dust.ar(4);

    // Reduce input amplitude
    input = input * 0.1;

    freqs = Array.fill(numBands, { |i|
        var baseFreq = freq * (2 ** (i / 12));
        var rotatedFreq = baseFreq * (2 ** (rotate / 12));
        var spreadFreq = rotatedFreq * (1 + (i - (numBands/2)) * spread);
        LFDNoise3.kr(morph).range(spreadFreq * 0.9, spreadFreq * 1.1).clip(20, 20000);
    });
    freqs = freqs.collect({ |freq| VarLag.kr(freq, slew) });

    // Reduce amplitude range
    amps = Array.fill(numBands, { LFNoise2.kr(0.1).range(0.1, 0.3) });

    // Increase decay times for a smoother sound
    decayTimes = Array.fill(numBands, { resonance.linexp(0, 1, 0.2, 3) });

    sig = DynKlank.ar(`[freqs, amps, decayTimes], input);

    // Apply master level and envelope
    sig = sig * masterLevel * EnvGen.kr(Env.asr(0.01, 1, 0.1), gate, doneAction: 2);

    // Apply limiter to prevent clipping
    sig = Limiter.ar(sig, 0.9);

    Out.ar(out, sig!2);
}).play;
)

There is a \set event type but I had trouble getting it to behave in this case. This was easier (using \rest event type so it doesn’t play anything, and then using the finish key to explicitly set the appropriate parameters):

(
SynthDef(\smrDynKlank, {
  arg out=0, gate=1, t_trig=1, trigRate=10,
  freq=440, rotate=0, spread=0.5, resonance=0.5,
  morph=0, slew=0.1, masterLevel=0.5;
  var input, sig, numBands=6;
  var freqs, amps, decayTimes;
  
  // Generate input based on trigger or continuous rate
  input = Trig.ar(t_trig, SampleDur.ir); //Dust.ar(4);
  
  // Reduce input amplitude
  input = input * 0.1;
  
  freqs = Array.fill(numBands, { |i|
    var baseFreq = freq * (2 ** (i / 12));
    var rotatedFreq = baseFreq * (2 ** (rotate / 12));
    var spreadFreq = rotatedFreq * (1 + (i - (numBands/2)) * spread);
    LFDNoise3.kr(morph).range(spreadFreq * 0.9, spreadFreq * 1.1).clip(20, 20000);
  });
  freqs = freqs.collect({ |freq| VarLag.kr(freq, slew) });
  
  // Reduce amplitude range
  amps = Array.fill(numBands, { LFNoise2.kr(0.1).range(0.1, 0.3) });
  
  // Increase decay times for a smoother sound
  decayTimes = Array.fill(numBands, { resonance.linexp(0, 1, 0.2, 3) });
  
  sig = DynKlank.ar(`[freqs, amps, decayTimes], input);
  
  // Apply master level and envelope
  sig = sig * masterLevel * EnvGen.kr(Env.asr(0.01, 1, 0.1), gate, doneAction: 2);
  
  // Apply limiter to prevent clipping
  sig = Limiter.ar(sig, 0.9);
  
  Out.ar(out, sig!2);
}).add;
)

(
x = Synth(\smrDynKlank);
Pbind(
  \type, \rest,
  \dur, Pwhite().linexp(0, 1, 0.01, 0.5),
  \amp, Pwhite().linexp(0, 1, 0.01, 0.5),
  \freq, Pbrown().linexp(0, 1, 100, 500),
  \finish, { x.set(\t_trig, ~amp, \freq, ~freq) }
).play
)

The \finish approach is losing timing accuracy, by not timestamping the outgoing messages.

Suggest one of these:

(
x = Synth(\smrDynKlank);
Pbind(
	\type, \set,
	\id, x.nodeID,
	\args, [\freq, \t_trig],
	\dur, Pwhite().linexp(0, 1, 0.01, 0.5),
	\t_trig, Pwhite().linexp(0, 1, 0.01, 0.5),
	\freq, Pbrown().linexp(0, 1, 100, 500),
).play
)

// note that this will send values for any event default values as well
// which may not be what you want. So the first option is probably better.
(
x = Synth(\smrDynKlank);
Pbind(
	\type, \set,
	\id, x.nodeID,
	\args, [],
	\instrument, \smrDynKlank,
	\dur, Pwhite().linexp(0, 1, 0.01, 0.5),
	// note: NOT t_trig -- debatable decision by JMc back in the day
	\trig, Pwhite().linexp(0, 1, 0.01, 0.5),
	\freq, Pbrown().linexp(0, 1, 100, 500),
).play
)

The set event type is documented here – Pattern Guide 08: Event Types and Parameters | SuperCollider 3.12.2 Help – however many people use patterns without reading the pattern guide and then find some details to be mysterious.

hjh

UGH - yes I read through your pattern guide at least once a year and still I forget to check there first. That page should probably be linked from the Event Types helpfile…

and yes right, to use \finish properly the x.set should be wrapped in s.bind. Using \set type is better.

Thank you, I’m up to data sharing :thank you