How to control the release on an external synth?

I hope this isn’t a duplicate, I couldn’t find an answer to this. The problem is that when I send a note to my external synth there is no release. It just keeps playing that note until it’s given a new note to play. Even if I stop the run it will just keep droning the last note it was told to play until I unplug it. I would really like to be able to control the attack and release. I’m using the ‘midi’ command to play the notes, i.e.

midi :Eb3
sleep 0.5
midi :F3
sleep 0.5

EDIT:
I’ve found that it only holds the note when I’ve got it in a loop, so the example above doesn’t keep droning after I stop the run, but

loop do 
    midi :Eb3
    sleep 0.5
    midi :F3
    sleep 0.5
end

will keep droning. Is there a way to make it release once you’re done with a loop?

Hi there,

The next time you have trailing notes droning on, you can run midi_all_notes_off by itself in a separate tab to end them all. (See the note at the bottom for an explanation of what’s going on.)

I believe you’re looking for the sustain option for midi, which specifies how long a note should be held for. The default value of sustain if you omit it is 1 beat, which is equal to the time between successive calls to midi :Eb3 or midi :F3 in your code. That’s why they sound continuous. Try specifying a sustain time shorter than the time between successive calls of the note, in order to have a gap between successive triggers of the note. (E.g. midi :Eb3, sustain: 0.25.)

If you’ve reduced the sustain time to less than the sleep time, and your notes still sound continuous, consider decreasing the release of your external synth’s ADSR envelope. As I pointed out in a previous post, the ADSR envelope is not controlled by the MIDI on and off signals which are sent by midi. Rather, the attack, decay, and sustain portions of the envelope are triggered after the MIDI on signal, and the release portion of the envelope is triggered after the MIDI off signal.

Cheers!

Note: Based on my diagram, it can be seen that if no MIDI off signal is sent out, a note will simply remain on forever. I suspect that this is what is causing your issues with hanging notes when you stop your program. Given that there is no gap between notes in your original code, there will always be a note still playing when you stop the program. Thus, you hear hanging notes.

1 Like

Thanks! this fixed it!

2 Likes

You’re welcome! Happy coding and music making!

1 Like