HISE Logo Forum
    • Categories
    • Register
    • Login

    MIDI player laggy

    Scheduled Pinned Locked Moved General Questions
    8 Posts 3 Posters 83 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.
    • D
      daniloprates
      last edited by

      I'm trying to trigger some MIDI players on noteOn, but the behaviour is a bit strange.

      The MIDI player starts immediately, but there's a delay until I hear the sounds.
      Sometimes it also triggers the wrong player, and sometimes the stop doesn't work properly.

      Is there anything I'm doing wrong?

      Synth.deferCallbacks(false);
      
      const mp0 = Synth.getMidiPlayer("mp0");
      const mp1 = Synth.getMidiPlayer("mp1");
      
      const players = [mp0, mp1];
      const noteTriggers = [60, 62];
      const triggers = [];
      
      for (var i=0;i<players.length;i++) {
      	triggers[noteTriggers[i]] = players[i];
      }
      function onNoteOn()
      {
      	const note = Message.getNoteNumber();
      	if (!!triggers[note]) {
      		Message.ignoreEvent(true);
      		triggers[note].play(0);
      	}
      }
       function onNoteOff()
      {
      	if (!!triggers[note]) {
      		Message.ignoreEvent(true);
              triggers[note].stop(0);
      	}
      }
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @daniloprates
        last edited by

        @daniloprates said in MIDI player laggy:

        for (var i=0;i<players.length;i++) {

        No need for the var

        @daniloprates said in MIDI player laggy:

        const note = Message.getNoteNumber();

        Use a local here.

        @daniloprates said in MIDI player laggy:

        !!triggers[note]

        Doesn't the first ! cancel out the second?

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        D 1 Reply Last reply Reply Quote 1
        • D
          daniloprates @d.healey
          last edited by

          @d-healey said in MIDI player laggy:

          note = Message.getNoteNumber();

          !! returns a true instead of the value. Just a more secure way of checking if something exists.

          I've just realized that there's a latency even when pressing play on the MIDI player directly, so it's not related to the code. The player starts immediately, but the sound takes a while to start.

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @daniloprates
            last edited by

            @daniloprates said in MIDI player laggy:

            !! returns a true instead of the value. Just a more secure way of checking if something exists.

            isDefined() is probably a better way, because !! might return the wrong value for invalid values.

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            D dannytaurusD 2 Replies Last reply Reply Quote 1
            • D
              daniloprates @d.healey
              last edited by

              @d-healey thanks for the heads up!

              1 Reply Last reply Reply Quote 0
              • dannytaurusD
                dannytaurus @d.healey
                last edited by

                @d-healey I think isDefined() is for different cases. Similar in many ways but different enough to throw you off at times.

                The double quote !! turns any truthy/falsey value into a boolean. But isDefined() will consider a value of false as defined, and therefore return true.

                Meat Beats: https://meatbeats.com
                Klippr Video: https://klippr.video

                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @dannytaurus
                  last edited by

                  @dannytaurus said in MIDI player laggy:

                  But isDefined() will consider a value of false as defined,

                  Yeah that's what I meant by he might get invalid values, because he wants to check "if something exists" not if it's true or false - or at least that's what I got from the statement.

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  dannytaurusD 1 Reply Last reply Reply Quote 0
                  • dannytaurusD
                    dannytaurus @d.healey
                    last edited by

                    @d-healey said in MIDI player laggy:

                    Yeah that's what I meant by he might get invalid values, because he wants to check "if something exists" not if it's true or false - or at least that's what I got from the statement.

                    Yeah, true (no pun intended). To check if something is defined I'd always use isDefined() because it's more readable and explicit.

                    But I do use !! a lot in other places because it's so consistent in what it returns.

                    And !! does return false for undefined, for reference.

                    Console.print(isDefined(somethingUndefined)); // 0
                    Console.print(!!somethingUndefined); // 0
                    

                    Meat Beats: https://meatbeats.com
                    Klippr Video: https://klippr.video

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

                    31

                    Online

                    1.9k

                    Users

                    12.3k

                    Topics

                    106.7k

                    Posts