I have some code that injects a noteOn message into a track using injectLiveMidiMessage()
. I noticed that a noteOff message gets automatically generated a short time after as well. Is it possible to not generate the noteOff message so that it can be generated manually, by my code, so that the “guid note” functionality can play notes with sustain rather than just a short bleep? The noteOff will be generated when the user releases the key and will be injected the same way as the noteOn. I also tried doing this using the virtualMidiInputDevice. I’d like to do it both ways actually, one to just trigger notes when they are pressed in the sequencer and one to trigger notes to actually record onto the track. Is that possible?
auto noteOn = juce::MidiMessage::noteOn(1, 64, (float)1.0);
track->getOutput().injectLiveMidiMessage(noteOn);
// or
virtualMidiInputDevice->handleIncomingMidiMessage(noteOn);
I’ve also looked into playGuideNote()
with autorelease
both true and false though it didn’t work with either option and the noteOff message still gets generated in both cases. That function uses injectLiveMidiMessage
under the hood, though maybe it could potentially be customized to support this behavior? The option to generate the noteOff seems to be rather deep in the engine and I would only want to do it for injected messages.
What you are trying to do should work. I’m not sure why the note off is getting generated without seeing more code. You can see this works in waveform, you click on a note, you hear the preview until you release the mouse. Are you doing something else that is restarting playback?
I’m not intentionally sending any noteOff messages anywhere yet. I traced the noteOff event to MidiList::createDefaultPlaybackMidiSequence()
which ends up making the call: addToSequence (destSequence, clip, note, channelNumber, useNoteUp, grooveTemplate);
and the useNoteUp
parameter is true. That seems to be where the noteOff event comes from. It seems this is replaceable by subclassing the EngineBehaviour
class but it would change the logic for the entire app in that case.
The ‘all notes off’ from the last few messages on my other thread could also be an issue, potentially but I’ll settle for getting rid of the explicit note off first. ( See: Adding / removing MidiNotes from a playing MidiSequence in a MidiClip without restarting playback - #29 by dave96 )
This is what the midi messages look like:
|10:10:47.035|To IAC Driver Bus 1|Note On|1|E3|64|
|---|---|---|---|---|---|
|10:10:47.043|To IAC Driver Bus 1|Note Off|1|E3|0| <- seems to be from MidiList::addToSequence()
|10:10:47.043|To IAC Driver Bus 1|Control|1|All Notes Off|0| <- these last two are a known issue from the other ticket, I just haven't gotten around to working on the fix suggested by dave96 in that ticket yet
|10:10:47.043|To IAC Driver Bus 1|Control|1|Reset All Controllers|0|
Are you updating the notes in the midi clip at the same time? I think it stops all the notes that aren’t in the clip anymore, so you don’t get stuck notes.
Yes, when they press the note, I add it to the MidiClip
. The ‘all notes off’ issue is indeed an issue remaining to be rectified, but the explicit noteOff message being sent is what I’m trying to figure out how to prevent.
I was able to get this to work if I don’t modify the midi sequence. If I do modify it, even if the edit is not playing, I’m getting the notes off messages when I modify the sequence. I’m trying to figure out how to implement this feature so to allow the user to enter notes into the sequencer and hear them when he presses the note buttons when the sequence is not playing. I tried using a second track but the issue remains as all the MIDI is going out to the same instrument.