HISE Logo Forum
    • Categories
    • Register
    • Login

    Getting the play positions of held notes

    Scheduled Pinned Locked Moved Scripting
    3 Posts 1 Posters 292 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.
    • B
      benosterhouse
      last edited by benosterhouse

      Hi,

      I saw David Healey's video on using timers to get note held, and was intrigued: https://www.youtube.com/watch?v=hVF2vkmrpME

      I've hit a dead end while using timers to get the play positions of held notes though.

      Here's the code I ended up with:

      // onInit
      const var timer = [];
      const var eventPlayPos = [];
      
      function onNoteOn()
      {   
          Message.ignoreEvent(true);
          
          var eventId = Synth.playNote(Message.getNoteNumber(), 64);
          timer[eventId] = Engine.createTimerObject();
          eventPlayPos[eventId] = 0;
          timer[eventId].setTimerCallback(function(){
              //Console.print("note held");
              
              // this of course only gets the play position at the most recent eventId. It would be nice if eventId could be local to this function. 
              // You can only define local variables in an inline function or a callback though, and if you define a local variable outside of this function, it can't see it here.
              Console.print(eventPlayPos[eventId]);
              eventPlayPos[eventId]++;
          });
          timer[eventId].startTimer(((60/hostBpm) * 1000) / 12);
      }
      
      function onNoteOff()
      {
          var artificialEventId = Message.getEventId()+1; // this doesn't seem like a good idea...
          timer[artificialEventId].stopTimer();
      }
      
      1 Reply Last reply Reply Quote 0
      • B
        benosterhouse
        last edited by benosterhouse

        I should give more context as well:

        One of the reasons I'm trying to do this is for legato.
        I'd like to make it so when you play a legato note, it plays the sample from wherever you were in the previous one.

        Kontakt's Unisono - Portamento script has an option to do this if you set the Mono Mode to Legato. It's quite handy!
        fb0135cf-2740-4c3e-802a-b261637bd048-image.png

        1 Reply Last reply Reply Quote 0
        • B
          benosterhouse
          last edited by benosterhouse

          Ok, to answer my own question :winking_face_with_tongue:

          // onInit
          const timerInterval = 0.05;
          Synth.startTimer(timerInterval);
          const sampleLength = (60 / 110) * 16;
          var keyDown = Engine.createMidiList();
          var legatoPlayPos = 0;
          
          function onNoteOn()
          { 
              keyDown.setValue(Message.getNoteNumber(), 1);
              if (keyDown.getValueAmount(1) == 1) {
                  Console.print("first note played");
                  legatoPlayPos = 0;
              };
          };
          
          function onNoteOff()
          {
              keyDown.setValue(Message.getNoteNumber(), 0);
          };
          
          function onTimer()
          {
              if (keyDown.getValueAmount(1) >= 1) {
                  normalizedIntensity = (legatoPlayPos * timerInterval) / sampleLength;
                  // set the intensity of sample start constants here
                  legatoPlayPos++;
              };
          };   
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          38

          Online

          1.7k

          Users

          11.7k

          Topics

          102.1k

          Posts