For a project I am working on I need to pause the midi sequencer and I want all the sounding notes to sustain and thus make those notes endless. The problem I am facing is that sequencer.stop()
apparently not only stops the playback, but also sends MIDI note off messages to all sounding notes, terminating all sounding notes (in some literature refered to as flushing).
I have tried to use sequencer.setTempoInBPM(0)
and that gets the job done, but has other unwanted side-effects specific to my project.
The most obvious solution then seems overriding Sequencer.stop()
, but how do I do that? And how exactly will that overridden method look like?
Edit: I would like to edit the question in response to the comment of gpasch.
not only stops the playback, but also sends MIDI note off messages to all sounding notes: what are you talking about?? isnt this the same thing??
That is true for audio, but that is not true for MIDI. The MIDI protocol doesnt specify any audio data by itself. It only gives instructions to a musical instruments on what to play. The instrument interprets the MIDI messages and makes the final sound.
In order to let an instrument play a sound of one second, this are the actions:
- [Sequencer] MIDI Message Out: note on
- [Instrument] MIDI Message In: note on
- [Instrument] Starts interpreting note on: starts producing sound
- [Sequencer] Waits one second
- [Sequencer] MIDI Message Out: note off
- [Instrument] MIDI Message In: note off
- [Instrument] Starts interpreting note off: stops producing sound
So, if this process gets interrupted on step 4, it would create an "endless note". Because the MIDI instrument got instructions to begin playing a certain note, but never got an instruction to stop playing that note. [*]
Looking back to my question. When I call sequencer.stop()
in the middle of a note (step 4), instead of having an "endless note", all notes that are being played on that moment that did not yet have got an note off message, stop sounding. The logical explenation for that, is that sequencer.stop()
sends a MIDI All Note Off message under the hood. We can be really thankfull for that, because otherwhise sequencer.stop()
would be a real mess. In my particular case though I really need the sequencer to not send the note off message. So the question is: can I make a workaround for that?
* If it is a piano sound with a natural decay of the sound, the sound will eventually die. But with a synth sound the sound will persist till there has been