HISE Logo Forum
    • Categories
    • Register
    • Login

    CC controller data delayed slightly when coming from the MIDI player

    Scheduled Pinned Locked Moved Bug Reports
    7 Posts 4 Posters 443 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gorangroovesG
      gorangrooves
      last edited by gorangrooves

      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?

      Goran Rista
      https://gorangrooves.com

      Handy Drums and Handy Grooves
      https://library.gorangrooves.com

      clevername27C 1 Reply Last reply Reply Quote 1
      • clevername27C
        clevername27 @gorangrooves
        last edited by

        @gorangrooves Is there anything in the GIT comments?

        Christoph HartC 1 Reply Last reply Reply Quote 0
        • Christoph HartC
          Christoph Hart @clevername27
          last edited by

          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.

          gorangroovesG 1 Reply Last reply Reply Quote 0
          • gorangroovesG
            gorangrooves @Christoph Hart
            last edited by

            @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?

            Goran Rista
            https://gorangrooves.com

            Handy Drums and Handy Grooves
            https://library.gorangrooves.com

            Christoph HartC 1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart @gorangrooves
              last edited by

              @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);
              
              gorangroovesG 1 Reply Last reply Reply Quote 0
              • gorangroovesG
                gorangrooves @Christoph Hart
                last edited by

                @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"?

                Goran Rista
                https://gorangrooves.com

                Handy Drums and Handy Grooves
                https://library.gorangrooves.com

                1 Reply Last reply Reply Quote 0
                • L
                  Larisabrownb
                  last edited by

                  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 ...

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  20

                  Online

                  1.7k

                  Users

                  11.8k

                  Topics

                  102.4k

                  Posts