notein and kslider, stop sound when release on keyboard

thori's icon

Ive tried searching but cant find out how to do this.

Im trying to make a synth patch, how can i make it so sound plays when a key is pressed and stops when released? Ive got notein-kslider-mtof, what do i add?

Can anyone help please?

brendan mccloskey's icon

Have a nosey round the examples folder inside your Max/Cycling74 folder; there's many midi-synth examples.

A quick fix for this is to use the note-off velocity from your keyboard (I assume you mean an external midi keyboard); when the key is released it sends a velocity of zero. Use [sel 0]-> message[0 50]->[line]->[*~] and multiply the output of your oscillator or sound source by this ramp.

Also look at the helpfile for [makenote] and the handy little "See Also" box in the helpfiles.

Luke Hall's icon

Definitely have a look to see how the examples achieve this. You might also want to look at other midi processing objects like [stripnote] (in conjunction with [sel 0] for note-offs) and envelope generators like [function] and [adsr~].