CC controller data delayed slightly when coming from the MIDI player
-
When a CC controller value change happens precisely at the same time as a note is played, everything works as it should when played from a DAW.
However, if the same MIDI performance is exported from DAW as a MIDI file and played in the HISE MIDI player, the CC data is delayed slightly, causing the note played simultaneously not to be affected by the CC value change.
This is problematic in instances of using CC to control hi-hat openness.
If I move the CC by 1pp earlier (so that it happens a hair before the note) and re-export the MIDI file, then import it into the HISE MIDI player, the CC plays in time to affect the note.
I am using HISE from January 10, 2024. @Christoph-Hart, is this something that may have been fixed since January 10th?
-
@gorangrooves Is there anything in the GIT comments?
-
Can you take a look at the exported midi file and see how they are sorted as a event list? There‘s nothing in HISE that favors note messages over CC messages with the same timestamp so I think it comes down to which event is written to the MIDI file first.
-
@Christoph-Hart Good point. I checked it: in the MIDI file, the notes are written before the controller. When the MIDI file plays on a MIDI track connected to the plugin in Cubase, the controller and note play at the same and thus, the controller affects the note. But, when the MIDI is loaded directly into HISE MIDI player, that is not the case.
So, I guess a solution would be to sniff out if a note is artificial and if so, delay it by a sample, right?
-
@gorangrooves another way would be to transform the MIDI sequence to ensure that it's stored in the correct order (for your project, I can't make a general assumption that a CC message always has to come before a note on).
Does this solve the problem?
const var MIDIPlayer1 = Synth.getMidiPlayer("MIDI Player1"); // This function defines the sorting algorithm: // 1. sort by timestamp // 2. if they have the same timestamp, prefer notes over CC inline function preferCC(e1, e2) { // check if one of the timestamps is bigger / smaller if(e1.getTimestamp() < e2.getTimestamp()) return -1; if(e1.getTimestamp() > e2.getTimestamp()) return 1; // check if one of the events is a note and the other a CC if(e1.isNoteOn() && e2.isController()) return -1; if(e2.isNoteOn() && e1.isController()) return 1; // "equal" events (same type & timestamp, retain order) return 0; } // We need some kind of check to prevent this system to cause an // infinite loop (because flushing the sorted list will trigger the // update callback again, which will trigger flushMessageList and so on) // The simplest solution is to just add up the timestamps of the entire sequence // and treat it as "hash" so that it will only perform the sorting & flushing // when there's actual "new" content. Of course there is the possibility of a collision // so you might want to increase the complexity of this hash function in a real world // project. reg lastHash = 0; inline function updateSequence(mp) { Console.print("update"); // grab the event list of the sequence whenever it changes local events = mp.getEventList(); local hash = 0; for(e in events) hash += e.getTimestamp(); if(hash != lastHash) { // sort it with the function defined above Engine.sortWithFunction(events, preferCC); mp.flushMessageList(events); lastHash = hash; } } // This registers the function to the MIDI player and will be // called whenever the sequence changes (either internally or when a new MIDI file is loaded) MIDIPlayer1.setSequenceCallback(updateSequence);
-
@Christoph-Hart Thank you very much! I will check this out.
@Christoph-Hart said in CC controller data delayed slightly when coming from the MIDI player:
// 2. if they have the same timestamp, prefer notes over CC
Did you mean to comment, "prefer CC over notes"?
-
I checked it: in the MIDI file, the notes are written before the controller. When the MIDI file plays on a MIDI track connected to love language test the plugin in ... It is well-known that MIDI lags if you are transmitting lots of data, regardless of the hardware you use to send it. And music is very timing- ...Latency occurs when software sound modules and/or effects that respond to MIDI data begin consuming too much processor time. As you add voices ...