HISE Logo Forum
    • Categories
    • Register
    • Login

    Synth.startTimer not calling onTimer callback

    Scheduled Pinned Locked Moved Scripting
    6 Posts 2 Posters 285 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.
    • Casey KolbC
      Casey Kolb
      last edited by Casey Kolb

      Hello! I'm trying to setup a really basic tempo synced note repeater for each sampler, but for some reason nothing will start the onTimer callback. I'm probably missing something really obvious. Here's a WIP:

      /* Basic tempo synced note repeater */ 
      const var loopButton = Content.addButton("Loop", 0, 10);
      loopButton.set("text", "Loop");
      
      var notes = [];
      notes.reserve(127);
      
      var heldNotes = [];
      
      inline function playAllHeldNotes() {
          for (var i = 0; i < heldNotes.length; i++) {
              Synth.playNote(heldNotes[i], 127);
          }
      }
      
      function onNoteOn() {
          local note = Message.getNoteNumber();
          local eventId = Message.makeArtificial();
      
          notes[note] = eventId;
          heldNotes.push(note);
          
          if (loopButton.getValue() == 1) {
              local interval = Engine.getMilliSecondsForQuarterBeats(1);
      
              // if first note on, start timer
              if (!Synth.isLegatoInterval()) {
                  Synth.startTimer(interval);
              }
          }
      }
      
      function onNoteOff() {
          local note = Message.getNoteNumber();
          Synth.noteOffByEventId(notes[note]);
      
          notes[note] = -1;
          heldNotes.remove(note);
      
          // if no notes are held, stop timer
          if (!Synth.isLegatoInterval()) {
              Synth.stopTimer();
          }
      }
      
      function onTimer() {
          Console.print("TIMER!!!");
          playAllHeldNotes();
      }
      
      function onControl(number, value) {
      
      }
      
      function onController() {
      
      }
      
      

      Would appreciate any suggestions! Thanks.

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

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

        Post a snippet

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

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

          Actually I see the problem. Synth.startTimer() doesn't take a value in milliseconds.

          1f653b62-c919-4b1d-9913-09c57710260f-image.png

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

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

            WOW! I knew it was something simple. Yes, that should do the trick. Thank you!

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

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

              Also if you use an Engine.createTimer() type timer then the value IS in milliseconds :p

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

              Casey KolbC 1 Reply Last reply Reply Quote 0
              • Casey KolbC
                Casey Kolb @d.healey
                last edited by

                @d-healey said in Synth.startTimer not calling onTimer callback:

                Also if you use an Engine.createTimer() type timer then the value IS in milliseconds

                So I'm realizing haha 😵

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

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

                26

                Online

                1.8k

                Users

                11.9k

                Topics

                104.0k

                Posts