Synthdef to use with Pmono

I’m trying to control a synth from Pmono, but I don’t understand how the enveloppe retrig works. What’s wrong the following code? The sound starts but does not retrig with each event…

(
SynthDef(\bb, {
	var freq = \freq.kr(110);
	var decay = \decay.kr(1);
	var sweep = LinExp.kr(\sweep.kr(0.6), 0, 1, 1, 100);
	var gate = \gate.tr(1);

	var env = Env.new(
		levels: [0,1,0],
		times: [0.01, decay]);

	Out.ar(\out.ir(0),
		Pan2.ar(
			Pulse.ar(freq) * EnvGen.kr(env, gate)
		)
	);
}).add;

p = Pmono(
        // the name of the SynthDef to use for each note
    \bb,
        // MIDI note numbers -- converted automatically to Hz
    \midinote, Pseq([60, 72, 71, 67, 69, 71, 72, 60, 69, 67]-12, 1),
        // rhythmic values
    \dur, Pseq([2, 2, 1, 0.5, 0.5, 1, 1, 2, 2, 3]*0.5, 1)
).play;
)

Events and Patterns employ certain conventions with the \gate control that work well with synths that aren’t mono synths. The conventions don’t work quite as well with monosynths. In other words, the \gate control can’t really be used as a trigger in the way you have written. The code below does what you’re expecting. But to do so it doesn’t use the \gate control but rather uses a trigger to retrigger the envelope.

(
SynthDef(\bb, {
	var freq = \freq.kr(110);
	var decay = \decay.kr(1);
	var sweep = LinExp.kr(\sweep.kr(0.6), 0, 1, 1, 100);
	var gate = \trig.tr(1);

	var env = Env.new(
		levels: [0,1,0],
		times: [0.01, decay]);

	Out.ar(\out.ir(0),
		Pan2.ar(
			Pulse.ar(freq) * EnvGen.kr(env, gate)
		)
	);
}).add;

p = Pmono(
        // the name of the SynthDef to use for each note
    \bb,
        // MIDI note numbers -- converted automatically to Hz
    \midinote, Pseq([60, 72, 71, 67, 69, 71, 72, 60, 69, 67]-12, 1),
        // rhythmic values
    \dur, Pseq([2, 2, 1, 0.5, 0.5, 1, 1, 2, 2, 3]*0.5, 1),
	
	\trig, 1
).play;
)

3 Likes