How can I create an ADSR envelope to control the output volume of a track in Ableton, which is triggered by the audio of another track passing a certain loudness threshold?

r d's icon

I want to create a M4L audio-device which acts like this: It detects when audio on a certain track has crossed a "user specified" loudness-threshold, and then starts increasing the loudness of a second track, the target-track, from zero (silence) to a specified maximum volume, over a specified length of time. The action would be similar to that of a gate, except that it would be detecting audio on one track to affect the loudness of another -- and it would open s-l-o-w-l-y, like an "attack" portion of an envelope set to upwards of a full minute.

The use-case is this: I'm trying to create an ambient drone which, as a key is depressed and held, gradually evolves and adds new layers and textures, automatically. The first layer would gradually get louder and expand in stereo-width. As it does, once it crosses a certain loudness threshold, the next layer will slowly fade-in. And then, gradually, another layer, and another. Each of these layers is actually a different instrument in a different track or chain. Once the key is released, each layer should fade-out according to other programmatic settings. And I want this all to work live, so to speak. Using manually-created volume-envelopes is the antithesis of what I'm trying to do. I want this ever-expanding drone-note to essentially, in the end, function like a single instrument.

Anyway, it seems like M4L should be the right way to approach this problem. I feel like what I'm asking for is essentially an ADSR envelope which can control the output-volume for a track or a chain in a rack, and which will hold on silence until it is triggered by the volume from another track rising above a certain threshold.

Does anyone have any idea how such a device could be created? Or do you know of a device which already does this? I have to confess, I'm a complete noob at M4L, and this is the first time I've had a specific idea for a device I wanted to create. I've only really started to dig-into whatever documentation I can find, but honestly much of it is written in a kind of shorthand that I can't make heads or tails of.

I was trying to use the adsr~ device in various ways last night to accomplish this, but I never could get any audio to pass through it, and eventually I decided that I really don't understand how that device's connections are supposed to work.

dfwaudio's icon

Interesting idea. Should be no problem to accomplish this. There are a lot of examples in M4L. (Right click>Paste from>Max for Live>LiveApiAbstractions/Track.ChangeTrackvolume) and reference is always worth a look.
All other things are more or less simple MaxMsp processes. You can find a lot of information about all over.
snapshot~ is a good object to get signal values.

adsr~ is not the right objects for your needs... it does way more than is necessary for this. Its not really an adsr envelope.... Its more like an ahr (Attack Hold Release) env. And you dont need to work signal~ based... float or int does the job to control Live Interface parts . Line object is a good tool for such things.