I have had a nosey around the forum and also through the Max examples, trying to find some pointers on envelope following. If there's one lurking in the Max folder and I missed it - sorry!
I recall PM answering a similar or related topic here, but cannot find it either, despite searching, so again, apologies for not finding a pre-existent solution, as I know this type of question has appeared numerous times before.
I am trying to generate a simple attack-sustain-release envelope from signal input, that is, a monophonic guitar line, such that I can impose a variable envelope on each new note. You may have seen this on the MFOS youtube channel. I've had a stab at it myself, based on the Max simple-compressor example and it's almost working, but it occasionally misses the onset of new notes very close to the end of a previous one; perhaps you can have a look and suggest a better way: