HISE Logo Forum
    • Categories
    • Register
    • Login

    noteOff() / noteOffByEventId()

    Scheduled Pinned Locked Moved Scripting
    9 Posts 3 Posters 478 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.
    • pasmaeP
      pasmae
      last edited by

      Hello,

      I am working on a script that retriggers all currently pressed keys when another key is pressed. I created an object which stores if a certain keynumber is pressed or not. When I print to the console I get the keynumbers just as I want. Retriggering works fine, but when I let go a key, it doesn't stop the note with the Synth.noteOff() function, it says in the console that I should use Synth.noteOffByEventId() instead. But when I get the EventId in onNoteOff and insert it in the function, it also doesn't work right. It seems to look for the same ID in the onNoteOn. How do I have to treat the Synth.noteOffByEventId() in this case?

      //On Init
      
      //Storing the current key status for the key range
      const var a = {}
      
      for (i = 53; i < 97; i++)
      {
          a[i] = 0;
      }
      
      function onNoteOn()
      {
      	const var n = Message.getNoteNumber();
      		
      	a[n] = Synth.isKeyDown(n);
      	
      for (k in a)
          {
              if (a[k] == 1)
              {
      	        Synth.playNote(k, 1);
              }
          }
      }	
      
      function onNoteOff()
      {
          const var n = Message.getNoteNumber();
          
          const var e = Message.getEventId();
          
          a[n] = Synth.isKeyDown(n);
          
      for (k in a)
          {
              if (a[k] == 0)
              {
      	        Synth.noteOffByEventId(e);
              }
          }
      	
      }
      
      1 Reply Last reply Reply Quote 1
      • Casey KolbC
        Casey Kolb
        last edited by

        First, you need to make the NoteOn events artificial by callingMessage.makeArtificial(); You can't operate on real events. There's more on this real vs. artificial concept in the documentation.

        Then, you need to save all of these artificial eventIds in an array so you can turn them off later by calling Synth.noteOffByEventId()

        A really simple way to achieve this is to either use a MIDIList or use an array with 128 slots reserved so you can put the eventIds in the respective note number slot in the array. When you clear the eventID with Synth.noteOffByEventId() you should set that number in the array back to -1 or some reasonable value to indicate it's inactive.

        Casey Kolb
        Founder & CEO of Lunacy Audio
        Composer | Producer | Software Developer

        pasmaeP 1 Reply Last reply Reply Quote 0
        • pasmaeP
          pasmae @Casey Kolb
          last edited by

          @Lunacy-Audio I tried something out but I guess I didn't get it right. I referred to the saved EventID in the Synth.noteOffByEventId() but it says it couldn't find a NoteOn with that ID...

          const var a = {}
          
          for (i = 53; i < 97; i++)
          {
              a[i] = [0, e];
          }
          
          function onNoteOn()
          {
              Message.makeArtificial();
              
          	const var n = Message.getNoteNumber();
          	
          	const var e = Message.getEventId();
          		
          	a[n] = [Synth.isKeyDown(n), e];
          	
          for (k in a)
              {
                  if (a[k] == [1, e > -1])
                  {
          	        Synth.playNote(k, 1);	        
                  }
              }
          }
          
          function onNoteOff()
          {
              Message.makeArtificial();
              
              const var n = Message.getNoteNumber();
              
              const var e = Message.getEventId();
              
              const var v = a[n][1];
              
              a[n] = [Synth.isKeyDown(n), e];
              
          for (k in a)
              {
                  if (a[k] == [0, e > 0])
                  {
          	        Synth.noteOffByEventId(v);
                  }
              }
          	
              v = -1;
          }
          
          Casey KolbC 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey
            last edited by

            Doesn't solve your problem but just a FYI you should use a MIDI list rather than an array for storing your note IDs in this instance.

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

            1 Reply Last reply Reply Quote 0
            • Casey KolbC
              Casey Kolb @pasmae
              last edited by

              @pasmae said in noteOff() / noteOffByEventId():

              @Lunacy-Audio I tried something out but I guess I didn't get it right. I referred to the saved EventID in the Synth.noteOffByEventId() but it says it couldn't find a NoteOn with that ID...

              I'm realizing you don't even need the make artificial call for this. You can just ignore the note on event, and then retrigger all pressed notes. Try this:

              // store all eventIds in a MIDI List for faster processing
              const var eventIds = Engine.createMidiList(); 
              eventIds.clear(); // set all values to -1
              
              function onNoteOn() {
                  local n = Message.getNoteNumber();
                  local v = Message.getVelocity();
              
                  Message.ignoreEvent(true);
              
                  // play all currently held notes
                  for (i = 0; i < 127; i++) {
              
                      // turn off previous event if applicable
                      local e = eventIds.getValue(i);
                      if (e != -1)
                          Synth.noteOffByEventId(e);
              
                      // play new note if key is down
                      if (Synth.isKeyDown(i)) {
                          local newNote = Synth.addNoteOn(1, i, v, 0);
                          eventIds.setValue(i, newNote);
                      }
                  }
              }
              
              function onNoteOff() {
                  local n = Message.getNoteNumber();
                  Synth.noteOffByEventId(eventIds.getValue(n));
                  eventIds.setValue(n, -1);
              }
              

              Works for me here:

              HiseSnippet 902.3oc4W0sjaSCEVZSDvBsaoCLbcdAnSBrP4tlrNNsgtYSF6Pob0NB4ytQsNRFY4.Y5zWKttORc3E.jrbVaO0DVLCL6Njqx4Smi724We7BkjAooREBe3xsI.BeGR3Vgdk2JJWflNFgOhLilpAUOGzIaSnooPDBi67XK.9vtn7eu8QmPioBFTBgPOSxYvo70bcI5hgOkGGOgFAK4qqn8wCmxjBOYrLyvmNj9nDJ6kzKgynV0NffvumeDWKUgZpFRQ3tmHi1FtR9yBm9Oimx+wXvJL.EZtHG7DYbjkw1+i7VwiiVryuSQHLYQYTniKJ7ojY7H9U3kQiON+fdkVTMdfOXezaP6nGpB655XmgDxnrXptNyroihC3x5YpoBMHR45sUSW+Mna+Fo6f+Az89jEbMaUy78fF3qIQ8uMeKR92k3ewE.SWR1tjIOusY51QkibT4iHgbAj2QlSjOKWt22S2.8dLH.kMnN3Oqob3u8ze851TlbsaJmyzlG+REUjlHSqcwgvZ9RovFQJA+tTXhB9o.aVtJtmjpZ7n29nIFmrQaBo5LUd4xn0xLgtV4QmV08Uuqoh9MLon6M5IEX7616ceRHSwSzkmX41mTfVxt50PtSQ3iIux+4K8CNazomG5ELcwxW+pEAy+VeukmOY9oi8Cd8roimVdMO3EVmotu8gWOeyTkY540UTTJlJ354IvUxmI0vbwNj96Pt3hpPdlKRIiiAUUTaUspA0JgZngzywIaQ7zwTM0FiKvL5k.JM25g3wvFSGkKheHYLj9RsL4lwj6VV9bOGeeexnmLNLnXhc9+64K1.wFmudIyLoPlrRJ3rp8jAfVwu7RPUk8M5RizZyK68xTapMQYLvnaeGTmxUGR4PNELTqphOw3wWIO7ECyutq.diZXXVpt1VL+vaBfXflVaDnOSZROv9RActdof+h0O1WYxcINmrW9.5a1uc+ncb0kQtYS16PxKKtMDWuGonf8VQf8HRQuzsgP6dWHsy+OWHMPlo4hKmQMSw+EyjpyxVGZ1CjAFlHDPr4AQvGXeQoStuU1sHnHJW32M+JNbfUFWb3fcG9exyXMkojmybuw2Ny8CxQL9sH+SKOz7MtF4dCPanwYF.Bo+C5iVaVf6bFyFt+bS7oYa9hVXyW1BaNtE17UsvlutE17vVXy2rWar6NOJSKW6ZEM.K7y2.Ci8ETSkbdUO5OD+newL
              

              Casey Kolb
              Founder & CEO of Lunacy Audio
              Composer | Producer | Software Developer

              pasmaeP 1 Reply Last reply Reply Quote 0
              • pasmaeP
                pasmae @Casey Kolb
                last edited by

                @Lunacy-Audio Somehow it doesn't work here. If I press a key it disables all the notes that are higher on the keyboard. On noteOn() it doesn't find the NoteOn with IDxxxx and onNoteOff it says NoteOn with ID-1 wasn't found?

                1 Reply Last reply Reply Quote 0
                • Casey KolbC
                  Casey Kolb
                  last edited by

                  Are you using the most recent scriptnode branch?

                  Casey Kolb
                  Founder & CEO of Lunacy Audio
                  Composer | Producer | Software Developer

                  pasmaeP 1 Reply Last reply Reply Quote 0
                  • pasmaeP
                    pasmae @Casey Kolb
                    last edited by

                    @Lunacy-Audio I just rebuilt HISE and now it works! Thanks so much for your help and effort!

                    1 Reply Last reply Reply Quote 1
                    • Casey KolbC
                      Casey Kolb
                      last edited by

                      For sure!

                      Casey Kolb
                      Founder & CEO of Lunacy Audio
                      Composer | Producer | Software Developer

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

                      36

                      Online

                      1.7k

                      Users

                      11.7k

                      Topics

                      102.1k

                      Posts