HISE Logo Forum
    • Categories
    • Register
    • Login

    Timer Start/Stop based on external input (Gain value)

    Scheduled Pinned Locked Moved Solved General Questions
    7 Posts 2 Posters 93 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.
    • HISEnbergH
      HISEnberg
      last edited by

      I am working on an animation based on the gain value and for the sake of CPU I want the animation to stop running based on if there is any gain input or not. I am actually not sure what would be more/less CPU intensive here (leaving the timer running, or starting and stopping it based on input activity), but it does bring up an interesting challenge on how to start and stop a timer based on an external input.

      I was not able to use the startTimer/stopTimer in order to accomplish this. So I thought about using a second Timer to monitor for changes. This is counterintuitive however as it leaves a second timer running. Part of me thinks perhaps a broadcaster might work better for this purpose. Does anyone have a suggestion?

      const var TimerMainAnimation = Engine.createTimerObject();
      const var MonitorGainTimer = Engine.createTimerObject();
      const var Gain1 = Synth.getEffect("Gain1");
      const var knb_Main = Content.getComponent("knb_Main");
      
      var silenceCounter = 0;
      const var SILENCE_THRESHOLD = 17;
      const var SILENCE_LEVEL = 0.001;
      
      TimerMainAnimation.setTimerCallback(function() 
      {
          var GainL = Gain1.getCurrentLevel(0);
          var GainR = Gain1.getCurrentLevel(1);
          var GainSum = (GainL + GainR) / 2;
      
          knb_Main.setValue(GainSum);
      
          if (GainSum < SILENCE_LEVEL) 
          {
              silenceCounter++;
              if (silenceCounter >= SILENCE_THRESHOLD) 
              {
                  TimerMainAnimation.stopTimer();
                  Console.print("Timer stopped due to silence.");
              }
          } 
          else 
          {
              silenceCounter = 0;
          }
      });
      
      MonitorGainTimer.setTimerCallback(function() 
      {
          var GainL = Gain1.getCurrentLevel(0);
          var GainR = Gain1.getCurrentLevel(1);
          var GainSum = (GainL + GainR) / 2;
      
          if (GainSum >= SILENCE_LEVEL) 
          {
              TimerMainAnimation.startTimer(30);
              Console.print("Timer running" + " | Gain Value: " + GainSum);
          }
      });
      
      MonitorGainTimer.startTimer(100);
      
      
      HISEnbergH d.healeyD 2 Replies Last reply Reply Quote 0
      • HISEnbergH
        HISEnberg @HISEnberg
        last edited by

        Here is the snippet *

        HiseSnippet 1441.3oc2XE0baSDD9TRDz3BLsLko7nFO7fCkIHY6jFnTpacbR7fShmnPJvKYNKcN9nx2o4zo.YfNC+D4m.+D3e.r2IoHoDkTiGnME8ju818z29sq1cOOTv8HQQbAxn1gmERPFumo6YL4jtSvTFp+lJAR5Th33HIOD8ryBwQQDejgwhaqzvX4kP5m+7IOCGfYdjbQHzQbpGY.cJUlKcXmugFDrE1mbHbt4xa2ouGm0kGviAzrnoMJD68B7Ij8vJ0VvDsCNZBx3SMW26KVydDwds01ncqMZ2d81qul8X6ViGsw5sG05gsa42dMGuVHi2omOUxEtRrjDgLV5Yb+ybmv+IVxK3HZDcT.QsvA4Bu4DwawC7UtnRJp6DZf+vLZJBgLLGlSZKlPZ2ybWpO8b44j2czaXkaQQBzXgxvawRvyoH7rK.uJfjQAHsTBjtqoqmfFJy2Qgmaa1mIIhwXHNUDJI5hV3IllPPHRZcJVXohOhcAW4oL5TrjxYVO1pG6DJirpmf.fVqw9i9QhmrwJOpVto6xYJOSkhn0YlMTYgCnsNIb0SHxdiGqTptdi5kz8ErQGqfGndWN3VLoxft7ogbFrnQ8LETlUSYQDMf.onc4wJV.ryt3441ePu85163C24fdt6r+fMAEbdXUZLn2Q8FnLeUaaG3ruLSsZDQpk1EGDLBRjaLNl4o1owJV09kZVvSl+pNIs6ogerP.fe.4TRPCa.3E07fqTSmKnoa7TP2FIG+CRLdEqO2pIfVkdYTiBmGgChIMRsZkTEnisxDY8UkcbvATZj3Dpmxz5CdviNeG0obAR+qe7kI5zSr7opdphXg5PZwMV4QkzExAh3AjUCETUvOIuSocHw2xOlXI4YHc05Er8k5e8xDHPBhHWu6kj0jX3KUr0Ey0uoG5KFYKDLpNzVY..KRbvFsrKviUx+hXFixNoN.j5V+pFLV57suzpdJ3RR5tVBM+M5XqdkYDpEmsGWR1GXVfXWtFDJu3ViGW4dpBFBdPfJMphsSSvtZCavhmNhH9Lf0Am4bEgxukqoad00zK1xwKo9UAE4r9.KreHgcUMhPoE8T0+SQEnpTW8+CRq96FP8IBDEJxWyL6adjFyE6Si919ahk3rSBNT3EERDRpxGL1jbJzGOouxxlaRhdgZV.ktokZA2dVdu+b96b6Nmc9he6G5ftbCLn0I2ON.KK2OUkUjtADPJ0DS0ZiEQkmUbpj+0ZxNqP7tlCoRuIUiwEp.i.q+eAFSGM48MS5flCvkL256dMLGxsNedR5zv.x1Yu92UGBctlQIQnMIA3RLzyo9xI4B99NULrYe1oPF6Pd.VbQ9cwY1ActdGboYNIPWo6Fch5GZpo4a5fTG5uYCx6XND+lJXe.OVBMX2EKETn9p4dwScgaPAiqLAyXv3LfLiETcKRVaqVq.gKg4qW7WvS5lNp0Foa5jsYQZ39IzvsMeN9ThdHcMC7Q50i4hoVaSXDghettOw+8Y81hgy7sE22SBP3PAlEExiHNEOYWxT5gPmpnRRufEMqzhlkqKIiYkO5DQkzRQEaATQA8tUmLgMKJDRaJcXv5RmztzBsL+imziggjBWB3496G4ADihmKlWMLFleU+EiSQCyE2rn3cvBeHF5cc0JWZ1pU9Jty76bi6NyuELwQo1oKmgwj1o8flcAvHZmWIeLNNPlIs7mdv7z7vIvP0kBzGPfJFmbBoT9SkNzSkR3VL4RtWmCHADbTgOG+jNCfK2iE.OQlStv4e7ewQkwqO1LAt5atX816jhK9+5IEm8u9fRf2rih22DJE2zRGJsdyDKecLCvqi2wTrmferWxcYUezeKsDvuY5+C3kM2Us1x4x2fcJzx3XOuxG0kLr47ZXq40v1yqgqMuFt97Z3CmWC23Uanpi9Sik7j+BI0jMC6o+GGLLRFpQ+YB5uARXxoHA
        
        1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @HISEnberg
          last edited by

          @HISEnberg said in Timer Start/Stop based on external input (Gain value):

          I was not able to use the startTimer/stopTimer

          Working here

          HiseSnippet 1145.3oc2X0saaaCElJ1pnxcqncnXX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7rHbVr9BokI18EbQ5XAmQJV0OjpkrQinxhXetuPao0vVlyj7nMOjFSwEYve4l6ALOrDxSzkLWbyOWxbqWegaNb8Mci92dmXW4i5I1kJm2c5kDldDrIWRn3A9tlY0HzNzXboD0qXgvj+oB9oMmyz7dP2hTOPDikWNMW48Ess5ByELuR+q3qUWrhw637TKHdMibfT9sI.aoD2d.7CbGf++.g3PQlFtXReLrcwuAWYc+rjgvQZHT.pbNbwFPlyJlikjutoYc9YZ3g1E+E7Yhx.yZmIJCtP4GMwHASjh2Pxuojo8+tVIPtka+2F7b6aV6Gfr2dp3HmD3LOugPJ+nthiqsrN90KqisVVGe5x535KqiarrN19c6n4HoakoEI48hHT+AcsW2zwoKGCcU11RzeCDiDmLI
          

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

          HISEnbergH 1 Reply Last reply Reply Quote 0
          • HISEnbergH
            HISEnberg @d.healey
            last edited by

            @d-healey Ah thanks that is what I figured and had originally, I must have had a typo. Here is a solution for anyone else who lands here:

            Content.makeFrontInterface(600, 600);
            
            const var SimpleGain1 = Synth.getEffect("Simple Gain1");
            const var Knob1 = Content.getComponent("Knob1");
            
            
            const t = Engine.createTimerObject();
            
            t.setTimerCallback(function()
            {
            	var Gain = SimpleGain1.getCurrentLevel(false);
            	Console.print(Gain);
            	if (Gain <= 0)
            	{
            		Console.print("Stop");
            		this.stopTimer();
            		Knob1.setValue(Gain);
            	}
            	else
            	{
            		Console.print("Timer is running");
            		Knob1.setValue(Gain);
            	}	
            });
            
            
            
            HISEnbergH 1 Reply Last reply Reply Quote 1
            • HISEnbergH HISEnberg has marked this topic as solved on
            • HISEnbergH
              HISEnberg @HISEnberg
              last edited by

              Still bugging for me in my current project. I am using 4 channels which I think is causing issues.

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

                @HISEnberg run a loop to check all channels.

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

                HISEnbergH 1 Reply Last reply Reply Quote 0
                • HISEnbergH
                  HISEnberg @d.healey
                  last edited by

                  @d-healey It's strange it isn't the channel count either. I can't really put my finger on it since I load the snippet into the same project, change the channel amount and it works fine. It is just my current .xml that it won't work in, and it isn't like I am reusing any of the variables or anything (I commented out all my other code to test). I am just going to sit on it and address it later.

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

                  59

                  Online

                  1.7k

                  Users

                  11.7k

                  Topics

                  102.1k

                  Posts