Facility Control

 View Only
  • 1.  Sleep function within a task?

    Posted 07-05-2016 18:44
    Hi, I'm trying to build a Dashboard where I'm triggering an external mixer using OSC commands via TCP/IP. I'm able to send commands without issue, but I was just wondering if there was a way I could insert in a sleep function between commands I sent to the server to be able to do fade transitions up/down for a variable number of milliseconds to mimic a soft fade on a channel/DCA group. I know there's a task you can create that can pause for x number of milliseconds, but I can't seem to figure out if there's a way for me to insert the task inside another task or if there's another function that can give the same effect.

    Thanks!


  • 2.  RE: Sleep function within a task?

    Posted 07-05-2016 19:26

    ogScript does not allow pauses to be performed in the main DashBoard UI thread but they can be done in the "asyncExec" thread.
    The trick is to put your code into a function and then call that function with ogscript.asyncExec.

    function doFade()
    {
       var counter = 0;
       while (counter < 10)   
       {
          ogscript.debug(counter);
          counter++;      
          ogscript.pause(500);
       }
    }
    
    ogscript.asyncExec(doFade, 0);

    #DashBoard


  • 3.  RE: Sleep function within a task?

    Posted 07-05-2016 19:40
    Amazing! Thanks! I'll give it a try.
    #DashBoard


  • 4.  RE: Sleep function within a task?

    Posted 07-05-2016 22:33

    So, I've got it working minus trying to pass parameters to the function.

    This code works fine, not passing any parameters, but defeats the purpose of making it a function.

    function doFade()
    {
       //var channel = 1;
       var iterations = 25;
       var time = 5;
       var currLevel = params.getValue("testFader", 0);
       ogscript.debug("time: " + time + " | currLevel: " + currLevel);
       var pauseTime = ((time * 1000)/ iterations);
       ogscript.debug("Pause Time: " + pauseTime);
       var levelPer = ((currLevel) / 25);
       while (iterations >= 0)  
       {
          currLevel = currLevel - levelPer;
          ogscript.debug(currLevel);
          params.setValue("testFader", 0, currLevel);
          iterations--;      
          ogscript.pause(pauseTime);
       }
    }
    
    ogscript.asyncExec(doFade, 0 );

    This one doesn't seem to work. Is there a specific way multiple parameters need to be passed using the asyncExec function? I was assuming it would be an array, but I guess that's not the case?

    function doFade(currVol, fadeTime)
    {
       //var channel = 1;
       var iterations = 25;
       var time = fadeTime;
       var currLevel = currVol;
       ogscript.debug("time: " + time + " | currLevel: " + currLevel);
       var pauseTime = ((time * 1000)/ iterations);
       ogscript.debug("Pause Time: " + pauseTime);
       var levelPer = ((currLevel) / 25);
       while (iterations >= 0)  
       {
          currLevel = currLevel - levelPer;
          ogscript.debug(currLevel);
          params.setValue("testFader", 0, currLevel);
          iterations--;      
          ogscript.pause(pauseTime);
       }
    }
    
    ogscript.asyncExec(doFade, [ params.getValue("testFader", 0), 5 ] );

    After messing around with it more for some reason when I try this it executes but ignores the pause function:

    ogscript.asyncExec(doFade(100, 50));

    #DashBoard


  • 5.  RE: Sleep function within a task?

    Posted 07-06-2016 14:15

    Making it a function is so you can pass it to asyncExec to run later.

    There are a few workarounds for needing to pass parameters. The easiest one is to have a function that creates and returns a new function to pass into asyncExec"

    function createFade(steps, delay)
    {
       return function()
       {
          var counter = 0;
          while (counter < steps)   
          {
             ogscript.debug(counter);
             counter++;      
             ogscript.pause(delay);
          }
       }   
    }
    
    
    ogscript.asyncExec(createFade(10, 100), 0); //First fade
    ogscript.asyncExec(createFade(20, 500), 0); //Second fade

    The one downside to this, as you'll see, is that you cannot run multiple fades simultaneously.

    If this is a requirement, there is a slightly more complex way of getting this done using timers. If necessary, I can create that example as well.


    #DashBoard


  • 6.  RE: Sleep function within a task?

    Posted 01-17-2023 16:48
    James,

    Is this something that would help my problem with a pause in Visual Logic?

    https://livinglive.community/discussion/dashboard-visual-logic-ands-ors#bm8120e80f-ac9d-495b-be0e-0185bc68db14

    I want to stick with visual logic as I can see better what I'm doing and have some hope of explaining it to coworkers.

    Could I create a timer in Xpression or use some duration from my Carbonite Black to accomplish this all within visual logic blocks?

    Thanks,
    James.

    ------------------------------
    James Hessler
    WAAY (HEARTLAND MEDIA)
    ------------------------------