Retriggering Ndef envelope/line inside of a pattern

Hi everyone!

Take a look at the following example:

(
Pdef(\example,
    Pbind(
        \instrument, \default,
        \freq, Ndef(\d, {
          XLine.ar(4000, 0.1, 0.8) + 200;
        }), // triggered once
        \dur, 0.5, \amp, 0.1,
    )
).play;
);

This pattern is using an Ndef which is a neat feature for LFOs and slow constant modulations that doesn’t need to account for any event trigger. It doesn’t work quite as well for envelopes, lines, and trigger based modulations.

Obviously, this is SC and there is a lot of options to solve this issue. However, this one is quite pleasing because of its simplicity. There isn’t much to type and it would be almost perfect if it retriggered and mapped over the parameter at audio/control rate like it does now.

The use case I have in mind is extending my modulation vocabulary when playing with a large set of SynthDefs that live in some other file that is being loaded at boot time for live coding. I prefer not to use a solution like \set / \xset even though I am using ProxySpace. My main constraint is keeping the code minimal so that the solution for re-triggering modulations is fast to type when improvising.

I have searched everywhere on the internet and started a discussion with @hemiketal on the Discord server about possible solutions. I still lack to experience to figure out clever hacks for this. I want to open this topic to gather some knowledge about it and compare different techniques some of you might know.

I found this solution that works quite well:

(
Pdef(\example,
    Pbind(
        \instrument, \default,
        \freq, Pfunc({Ndef(\d, { XLine.ar(2000, 20, 0.25) + 200; }).asMap}),
        \dur, 0.5, \amp, 0.1,
    )
).play;
);