HISE Logo Forum
    • Categories
    • Register
    • Login

    onTimer: play a note, reset timer, repeat

    Scheduled Pinned Locked Moved General Questions
    3 Posts 2 Posters 150 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

      It seemed a trivial thing to accomplish, but I am a bit stuck.

      Objective: In a NoiseGenerator start a timer. When the timer reaches a particular value (eg. 3sec), play a note (noise), then reset the timer, so that the process can repeat indefinitely.

      I've tried various strategies, but I am still not getting a note to play on timer. Here is the latest I've got that doesn't work.

      **onInit**
      
      var t = Engine.createTimerObject();
      
      t.startTimer(100);
      
      
      var qt = Synth.isTimerRunning();
      
      
      
      **onNoteOn**
      
      function onNoteOn()
      {
      	Message.ignoreEvent(true); // Isolate the synth by ignoring any MIDI notes coming in
      }
       
      
      
      **onTimer**
      
      function onTimer()
      {
          Console.print("Is timer running? " + qt);
          
      	if (t > 3000)
          {
          Synth.playNote(38,127);
          Synth.addNoteOff(1,38,100000);
          t.resetCounter;
          }
          Console.print("Current timer: " + t);
      }
       
      

      Any help is much appreciated!

      Goran Rista
      https://gorangrooves.com

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

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

        @gorangrooves

        There are a few issues.

        Firstly never use var unless your life depends on it :p (almost).

        Your timer should be a const

        isTimerRunning() lives in the moment. If you call that function within on init then it is only going to check if the timer is running during on init and at no other time.

        Engine.createTimerObject() Creates a new timer, completely separate from the in-built synth timer. So starting that timer will not trigger the synth timer callback.

        I think this playlist is for you:
        https://www.youtube.com/playlist?list=PLynv7CujPCfZBVsmtWsSZ68nPMXuIHwNL

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

        gorangroovesG 1 Reply Last reply Reply Quote 0
        • gorangroovesG
          gorangrooves @d.healey
          last edited by

          @d-healey Thanks, @d-healey . Your video was very helpful in understanding a few things. I created a looping timer that plays a note at random intervals. I specify a range for the random interval.

          Here is my script, which I put on the main Container holding a child synth noise generator.

          **onInit**
          
          Synth.startTimer(3);
          
          
          **onNoteOn**
          
          function onNoteOn()
          {
          	Message.ignoreEvent(true); // Isolate the synth by ignoring any MIDI notes coming in
          	
          }
           
          
          
          **onTimer**
          
          function onTimer()
          {
              var RT = Math.randInt(10,20);
              Synth.stopTimer();
              Synth.startTimer(RT);
              
              local ti = Synth.getTimerInterval();
          
              Synth.playNote(38,127);
              Synth.addNoteOff(1,38,100000);
              
              Console.print("Current timer: " + ti);
          }
           
          

          So, all of that works wonderfully for a single generator.

          Here is the next challenge: I'd like to create several child synths in that main Container, each playing a different note and routed to a different matrix output. All notes should start and finish at the same time, thus getting the cue from the main Container timer.

          How do I go about this, please?

          Goran Rista
          https://gorangrooves.com

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

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

          47

          Online

          1.7k

          Users

          11.7k

          Topics

          101.8k

          Posts