progress indicator...


    Jun 01 2007 | 12:26 am
    I have a function that iterates in JS, and i would like to show its progress visually. However, I seem to be encountering one of these priority walls...
    Here is a js and patch that run a simple iteration, but the multislider doesn't keep up. Is there a way I can show progress?
    //******* begin "junk.js"
    /*
    moves the dozer.mov file to a specified folder 10 times.
    */
    mov = new JitterObject("jit.qt.movie");
    mov.autostart = 0;
    function mover(topath){
    for (var i=0; i tomove = mov.read("dozer.mov");
    saveto = topath+i+mov.moviename;
    post("nsavingto",saveto);
    mov.savemoviecopy(saveto);
    mov.flatten(saveto);
    myout = i;
    outlet(0,myout);
    }
    }
    //-----end junk.js
    //begin max patch
    //end max patch

    • Jun 01 2007 | 1:15 am
      On May 31, 2007, at 5:26 PM, pnyboer wrote:
      >
      > I have a function that iterates in JS, and i would like to show its
      > progress visually. However, I seem to be encountering one of these
      > priority walls...
      > Here is a js and patch that run a simple iteration, but the
      > multislider doesn't keep up. Is there a way I can show progress?
      You need to use a Task to introduce asynchrony--i.e. the multislider
      won't update until the event is done being sent, so break the
      operation into chunks that are processed as separate low priority
      events. This is similar to "cooperative multithreading".
      This will also enable you to have things like a "cancel" button.
      -Joshua
    • Jun 04 2007 | 6:06 pm
      Josh, thanks for the hints.
      I gave this a shot, and didn't get the results I hoped for!
      Here's a js that uses a task instead of a for loop to copy the file. It just sort of stops after one iteration, even though I specify the task to run 11 times.
      Clearly it has to do with my interval of "1", so how do I get it to execute the task asynchronously without guessing at the interval?
      I'm also confused about something in the JavascriptInMax documentation (pg 34):
      "Although the overall timing accuracy of a Task function is high, the latency between the
      scheduled time and the actual execution time of a Task function is variable because the
      function runs in a low-priority thread."
      BUT LATER on pg 45...
      "In summary, a function will execute at in the high-priority thread...
      ? if the function?s immediate property is set
      and
      ? the js receives a message to invoke the function at high-priority
      or
      ? the function is executing via a js Task object "
      Aren't these 2 things contradictory?
      //-----begin junk.js
      /*
      moves the dozer.mov file to a specified folder 11 times.
      */
      mov = new JitterObject("jit.qt.movie");
      mov.autostart = 0;
      var movepath;
      var movecounter = 0;
      var TASK_INTERVAL = 1;
      var MOVEIT = new Task(movetask,this);
      function mover(topath){
      for (var i=0; i var tomove = mov.read("dozer.mov");
      var saveto = topath+i+mov.moviename;
      post("nsavingto",saveto);
      mov.savemoviecopy(saveto);
      mov.flatten(saveto);
      myout = i;
      outlet(0,myout);
      }
      }
      function moverastask(topath){
      movepath = topath;
      var limit = 11;
      if (!MOVEIT.running){
      MOVEIT.interval = TASK_INTERVAL;
      MOVEIT.repeat(limit);
      post("nrunning task ",limit," times");
      }
      }
      function movetask(){
      var tomove = mov.read("dozer.mov");
      var saveto = movepath+movecounter+mov.moviename;
      post("nsavingto",saveto);
      mov.savemoviecopy(saveto);
      mov.flatten(saveto);
      post("ncounting",movecounter);
      outlet(0,movecounter);
      movecounter++;
      }
      movetask.immediate = 0;
      //----------end junk.js
      /*
      --begin max patch
      //end maxpatch
      */
    • Jul 10 2007 | 2:55 am
      for the sake of the archive, here is a working version that uses the jitter listener to break up and schedule the task, keeping you informed of the progress along the way.
      //-----begin movem.js
      /*
      moves the dozer.mov file to a specified folder 11 times, and provides progress while doing it.
      */
      autowatch = 1;
      mov = new JitterObject("jit.qt.movie");
      mov.autostart = 0;
      var movlisten = new JitterListener(mov.getregisteredname(), thecallback);
      var movepath;
      var movecounter = 0;
      var TASK_INTERVAL = 1;
      var MOVEIT = new Task(movetask,this);
      function mover(topath){
      for (var i=0; i var tomove = mov.read("dozer.mov");
      var saveto = topath+i+mov.moviename;
      post("nsavingto",saveto);
      mov.savemoviecopy(saveto);
      mov.flatten(saveto);
      myout = i;
      outlet(0,myout);
      }
      }
      function moverastask(topath){
      movepath = topath;
      var limit = 11;
      if (!MOVEIT.running){
      MOVEIT.execute();
      }
      }
      function movetask(){
      var tomove = mov.read("dozer.mov");
      var saveto = movepath+movecounter+mov.moviename;
      post("nsavingto",saveto);
      mov.savemoviecopy(saveto);
      mov.flatten(saveto);
      post("ncounting",movecounter);
      outlet(0,movecounter);
      movecounter++;
      }
      movetask.immediate = 0;
      function thecallback(event)
      {
      if (event) post("nlisten",event.eventname);
      if (event.eventname=="flatten"){
      if (movecounter }
      }
      //end movem.js