HISE Logo Forum
    • Categories
    • Register
    • Login

    Knob to change ms of a Timer

    Scheduled Pinned Locked Moved Scripting
    10 Posts 3 Posters 423 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.
    • T
      treynterrio
      last edited by

      Hello, I have this Timer that activates and deactivates a Button. Now I want a Knob to change the ms of the Timer like from 0,1sec to 10sec?

      const var Timer = Engine.createTimerObject();
      
      Timer.setTimerCallback(function()
      {
          if (Content.getComponent("Button1").getValue() == 0)
          {
              Content.getComponent("Button1").setValue(1);
          }
          else
          {
              Content.getComponent("Button1").setValue(0);
          }
      });
      
      Timer.startTimer(5000);
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @treynterrio
        last edited by

        @treynterrio said in Knob to change ms of a Timer:

        if (Content.getComponent("Button1").getValue() == 0)
        {
            Content.getComponent("Button1").setValue(1);
        }
        else
        {
            Content.getComponent("Button1").setValue(0);
        }
        

        What is this supposed to do?

        To change the duration you just call startTimer() again from your knob's callback

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

        T 1 Reply Last reply Reply Quote 0
        • T
          treynterrio @d.healey
          last edited by

          @d-healey this is for the Button this function works but I want to change the ms from the timer its set to 5000 so its fixed but I want to control it

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

            @treynterrio Ah I see. You should store the reference to the button in on init rather than creating a new reference every time you want to access it.

            You can also condense the script.

            const Button1 = Content.getComponent("Button1");
            
            Timer.setTimerCallback(function()
            {
                Button1.setValue(!Button1.getValue());
            });
            
            

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

            T 1 Reply Last reply Reply Quote 0
            • T
              treynterrio @d.healey
              last edited by

              @d-healey ok. but how can I make a knob that controls the ms between the Button is activated and deactivated?

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

                @treynterrio Like I said, use startTimer() again to change the duration from within your knob's callback.

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

                T 1 Reply Last reply Reply Quote 0
                • T
                  treynterrio @d.healey
                  last edited by

                  @d-healey I'm using this:

                  inline function ontimeControl(component, value)
                  {
                  	Timer.startTimer(value);
                  };
                  Content.getComponent("time").setControlCallback(ontimeControl);
                  

                  and it works but I got an error in the console every time I change the value with the knob.

                  Interface:! Line 30, column 18: Go easy on the timer
                  
                  d.healeyD 1 Reply Last reply Reply Quote 0
                  • d.healeyD
                    d.healey @treynterrio
                    last edited by

                    @treynterrio Don't go below 40ms

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

                    T A 2 Replies Last reply Reply Quote 1
                    • T
                      treynterrio @d.healey
                      last edited by

                      @d-healey now it works! thanks for your time and help

                      1 Reply Last reply Reply Quote 1
                      • A
                        aaronventure @d.healey
                        last edited by

                        @d-healey

                        It'll take 10ms but you can easily choke the message threat of you're repainting a big surface and using blur.

                        Also older CPUs might complain. VMs too.

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

                        25

                        Online

                        1.8k

                        Users

                        11.9k

                        Topics

                        104.0k

                        Posts