progress indicator…

Jun 1, 2007 at 12:26am

progress indicator…

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<11;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

#P window setfont “Sans Serif” 9.;
#P window linecount 4;
#P comment 238 128 100 196617 the js makes 10 copies of the file “dozer.mov” into the folder.;
#P button 214 122 15 0;
#P number 53 181 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 188 123 21 196617 t 0;
#P newex 92 127 77 196617 prepend mover;
#P user multiSlider 92 227 113 60 0. 10. 1 2920 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P newex 92 153 53 196617 js junk.js;
#P user dropfile 92 44 259 98 1;
#P comment 103 56 127 196617 drag an empty folder here;
#P window linecount 6;
#P comment 222 229 100 196617 is it possible to show the progress of the movie copying? Nothing comes out of the js outlet until everything is done.;
#P connect 3 0 7 0;
#P connect 2 0 5 0;
#P connect 5 0 3 0;
#P connect 3 0 4 0;
#P connect 6 0 4 0;
#P connect 2 0 6 0;
#P connect 8 0 6 0;
#P window clipboard copycount 10;

//end max patch

#32220
Jun 1, 2007 at 1:15am

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

#105608
Jun 4, 2007 at 6:06pm

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<11;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

#P window setfont “Sans Serif” 9.;
#P window linecount 4;
#P comment 251 131 100 196617 the js makes 10 copies of the file “dozer.mov” into the folder.;
#P button 227 125 15 0;
#P number 53 181 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 201 126 21 196617 t 0;
#P newex 92 127 106 196617 prepend moverastask;
#P user multiSlider 92 227 113 60 0. 10. 1 2920 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P newex 92 153 53 196617 js junk.js;
#P user dropfile 92 44 259 98 1;
#P comment 103 56 127 196617 drag an empty folder here;
#P window linecount 6;
#P comment 222 229 100 196617 is it possible to show the progress of the movie copying? Nothing comes out of the js outlet until everything is done.;
#P connect 2 0 5 0;
#P connect 2 0 6 0;
#P connect 8 0 6 0;
#P connect 3 0 7 0;
#P connect 3 0 4 0;
#P connect 6 0 4 0;
#P connect 5 0 3 0;
#P window clipboard copycount 10;

//end maxpatch
*/

#105609
Jul 10, 2007 at 2:55am

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.

#P window setfont “Sans Serif” 9.;
#P window linecount 4;
#P comment 310 190 100 196617 the js makes 12 copies of the file “dozer.mov” into the folder.;
#P button 287 185 15 0;
#P number 113 241 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 261 186 21 196617 t 0;
#P newex 152 187 106 196617 prepend moverastask;
#P user multiSlider 152 287 113 60 0. 10. 1 2920 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P newex 152 213 66 196617 js movem.js;
#P user dropfile 152 104 319 158 1;
#P comment 163 116 127 196617 drag an empty folder here;
#P window linecount 6;
#P comment 282 289 100 196617 is it possible to show the progress of the movie copying? Nothing comes out of the js outlet until everything is done.;
#P connect 2 0 5 0;
#P connect 2 0 6 0;
#P connect 8 0 6 0;
#P connect 6 0 4 0;
#P connect 3 0 7 0;
#P connect 3 0 4 0;
#P connect 5 0 3 0;
#P window clipboard copycount 10;

//—–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<11;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<12) MOVEIT.execute();
}
}

//end movem.js

#105610

You must be logged in to reply to this topic.