0

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:

  1. [Sequencer] MIDI Message Out: note on
  2. [Instrument] MIDI Message In: note on
  3. [Instrument] Starts interpreting note on: starts producing sound
  4. [Sequencer] Waits one second
  5. [Sequencer] MIDI Message Out: note off
  6. [Instrument] MIDI Message In: note off
  7. [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

Tomasito665
  • 1,188
  • 1
  • 12
  • 24
  • "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?? Maybe you can make the NOTES "endless" – gpasch Apr 07 '16 at 04:34
  • @gpasch: I have edited the question, clarifying what the problem is ;) – Tomasito665 Apr 07 '16 at 13:41

1 Answers1

1

The way I would do it is. Create a filter which would basically receive everything sent from the sequencer and send it to your midi out. Inside this filter create a condition where if the "pause flag" is true all note offs would be received but not sent.

Create a pause() method which when called first sets your "pause flag" to true and then does sequencer.stop().

Of course you would need some way to keep track of the note offs that have been blocked so that you can actually stop them when you eventually do want to or else they will really stay on for ever.

  • I hadn't thought about this way yet. Thanks! The idea is to pause the sequencer and later on resuming it again, so that the open notes will be closed again by the originally intended note_off messages. I will try this out tomorrow or the day after. If it works, I will mark this answer as accepted. – Tomasito665 Apr 07 '16 at 20:25