[javascript-dev] another example of weird javascript crosstalk
Ivica Ico Bukvic
ico at vt.edu
Mon Jul 9 09:57:10 MDT 2007
- Previous message: [javascript-dev] Re: JitterListener and jit.qt.movie read...bug?
- Next message: [javascript-dev] another example of weird javascript crosstalk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi all,
Here is an addendum to a problem I posted earlier on the maxmsp list.
Symptom 1: multiple instances of the same abstraction (which contains a js
object for the purpose of creation dynamic number of audio outputs) create
objects ok when included in the same file (see poly_test.pat below), their
#0 argument is for some reason cross-polluted. So if we have a "boo" and
"bao" instance, both of them will be for some reason instantiated as "boo"
in this case.
Symptom 2: matters are worse when using this in conjunction with poly~ (see
main.pat below) where sometimes instance 1 fails to create objects. I tried
rigging the code with Tasks to delay their execution within javascript which
for the most part minimizes failure to create objects, but (depending on the
time it takes to instantiate poly object, especially in the case of more
complex objects) its success rate is impossible to assess consistently. I
also tried using setname message which would be responsible for
instantiating object's name via external message and that does not work
consistently either.
Expected behavior: multiple instances should instantiate as per their #0
vars and create/delete objects as expected.
FWIW, I tried changing js filenames as well as making two different
(identical) abstractions with different filenames in hope to make them more
different, neither of which had any bearing in this case.
Any insight in this matter is most appreciated.
NB: in order for this example to work, please use exact .pat and .js names
//dac2~.pat abstraction
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 70 161 109 9109513 send~ $2;
#P newex 48 46 49 9109513 zl nth $1;
#N comlet signal~;
#P inlet 27 26 15 0;
#P newex 27 132 30 9109513 *~ 0.;
#N comlet amplitude;
#P inlet 48 26 15 0;
#P newex 48 109 44 9109513 line~ 0.;
#P newex 27 161 41 9109513 dac~ $1;
#P flonum 48 68 59 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 48 87 59 9109513 append 10;
#P connect 5 0 2 0;
#P fasten 5 0 8 0 32 155 75 155;
#P connect 0 0 3 0;
#P connect 1 0 0 0;
#P connect 7 0 1 0;
#P connect 4 0 7 0;
#P connect 3 0 5 1;
#P connect 6 0 5 0;
#P window clipboard copycount 9;
//modular_dac~.pat abstraction
#P button 508 25 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 525 25 13 9109513 1;
#N comlet instance number;
#P inlet 540 25 15 0;
#N comlet speaker amplitude list;
#P inlet 287 25 15 0;
#P objectname amp_list;
#P number 626 44 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 583 44 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#N comlet rows;
#P inlet 626 25 15 0;
#N comlet cols;
#P inlet 583 25 15 0;
#P newex 540 64 97 9109513 js dac2.js $1;
#N comlet signal~;
#P inlet 9 25 15 0;
#P objectname sig_in;
#P connect 5 0 1 2;
#P connect 3 0 5 0;
#P connect 4 0 1 1;
#P connect 2 0 4 0;
#P connect 7 0 1 0;
#P connect 9 0 1 0;
#P connect 8 0 1 0;
#P window clipboard copycount 10;
//poly_test.pat (single instance)
#P window setfont "Sans Serif" 10.;
#P window linecount 1;
#N in 2;
#P newobj 143 43 26 9109514 in 2;
#P message 243 95 14 9109514 1;
#P message 299 96 14 9109514 2;
#P newex 285 66 53 9109514 loadbang;
#P newex 254 146 97 9109514 modular_dac~ bao;
#P newex 139 146 97 9109514 modular_dac~ boo;
#P connect 3 0 1 2;
#P connect 3 0 1 3;
#P connect 3 0 1 4;
#P connect 2 0 4 0;
#P connect 2 0 3 0;
#P connect 5 0 0 2;
#P connect 5 0 1 2;
#P connect 4 0 0 4;
#P connect 4 0 0 3;
#P connect 4 0 0 2;
#P window clipboard copycount 6;
//main.pat (poly~ example)
#P window setfont "Sans Serif" 10.;
#P window linecount 1;
#N thispatcher;
#Q end;
#P newobj 313 126 59 9109514 thispatcher;
#P number 101 138 35 10 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 112 162 47 9109514 open \$1;
#P message 95 110 44 9109514 target 0;
#P button 252 126 15 0;
#P number 171 75 35 10 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 171 100 52 9109514 voices \$1;
#P newex 178 153 88 9109514 poly~ poly_test 1;
#P connect 3 0 0 1;
#P connect 4 0 0 0;
#P connect 1 0 0 0;
#P connect 5 0 0 0;
#P connect 2 0 1 0;
#P connect 6 0 5 0;
#P window clipboard copycount 8;
//dac2.js
inlets=3; //instance/reset (bang), cols, rows
outlets=1;
var cols=0;
var rows=0;
var instance=0;
var output;
var initialized=false;
function msg_int(val)
{
if (inlet==0 && val>0)
{
instance=val;
init();
}
else if (inlet==1 && val>0 && val<17)
{
cols=val;
init();
}
else if (inlet==2 && val>0 && val<17)
{
rows=val;
init();
}
//else post ("dac2.js reports invalid data " + val + "\n");
}
function init()
{
name=jsarguments[1];
if (cols && rows && instance && name)
{
if (initialized) destructor();
initialized=true;
tsk=new Task(this.createoutputs);
tsk.repeat(0,1000);
}
}
function createoutputs()
{
output=new Array(rows*cols);
//make new ones and connect them
for (i=0; i<rows*cols; i++)
{
output[i]=this.patcher.newdefault(100*(i%cols)+20,30*Math.floor(i/cols)+120,
"dac2~", (i+1), name + "_" + instance + "_" + (i+1));
output[i].varname=(i+1);
}
tsk=new Task(this.connectall);
tsk.repeat(0,500);
}
function connectall()
{
sig=this.patcher.getnamed("sig_in");
amp=this.patcher.getnamed("amp_list");
for (i=0; i<rows*cols; i++)
{
this.patcher.connect(sig,0,output[i],0);
this.patcher.connect(amp,0,output[i],1);
}
}
function bang()
{
if (inlet==0) destructor();
}
function destructor()
{
//a kind of destructor: remove old outputs
i=1;
while(tmp=this.patcher.getnamed(i))
{
this.patcher.remove(tmp);
//post(i + "\n");
i++;
}
initialized=false;
}
//end dac2.js
Ivica Ico Bukvic, D.M.A.
Composition, Music Technology, CCTAD, CHCI
Virginia Tech
Dept. of Music - 0240
Blacksburg, VA 24061
(540) 231-1137
(540) 231-5034 (fax)
ico at vt.edu
http://www.music.vt.edu/people/faculty/bukvic/
http://ico.bukvic.net
- Previous message: [javascript-dev] Re: JitterListener and jit.qt.movie read...bug?
- Next message: [javascript-dev] another example of weird javascript crosstalk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
