My js is slowing down
Posted: Fri Apr 13, 2012 12:53 pm
Hi, I have created a java script that changes clip color of all clips in my set based on the key of to the currently playing clip. It's based on the last characters in the clip name that contains the key code (A01 to B12). I bang the track that has the currently playing track to the inlet of the java script.
The script works really well and fast enough. Only after a while the script is stalling and it gets really slow. Especially when there a lot of clips and scenes in the session.
Anyone knows what I can do. Maybe some sort of reset.
This is the script:
//function bang()
inlets=1
function msg_int(TRACKPLAY)
{
var NoTRACKS = 3;
//var NoCLIPSLOTS = 6;
api = new LiveAPI(this.patcher, "live_set");
var SCENES=api.getcount("scenes");
//post (SCENES,"\n");
NoCLIPSLOTS=SCENES-1
//test="08A";
// post ("test is ");
// post (test,"\n");
// post ( parseInt(test,10), "\n");
//Resolve key of playing clip, last 3 characters of clipname, A01 to B12
var i=0;
for (i=0;i<=NoCLIPSLOTS;i++)
{
api = new LiveAPI(this.patcher, "live_set tracks " + TRACKPLAY + " clip_slots " + i);
if (api.get("has_clip") == 1)
{
api = new LiveAPI(this.patcher, "live_set tracks " + TRACKPLAY + " clip_slots " + i + " clip");
var CLIPISPLAYING=api.get("is_playing");
//post (CLIPISPLAYING,"\n");
if (CLIPISPLAYING==1)
{
var CLIPNAME=api.get("name");
KEYCLIPPLAY = (CLIPNAME.join().slice(-3));
api.set("color", "16712965");
//post (KEYCLIPPLAY,"\n");
i=NoCLIPSLOTS;
}
}
}
//Set color according to key
//tracks
//bugs:
//1A 1B
//1A 12A
for (k=4;k<=NoTRACKS+4;k++)
{
//clip_slots
var j=0;
for (j=0;j<=NoCLIPSLOTS;j++)
{
api = new LiveAPI(this.patcher, "live_set tracks " + k + " clip_slots " + j);
if (api.get("has_clip") == 1)
{
api = new LiveAPI(this.patcher, "live_set tracks " + k + " clip_slots " + j + " clip");
var CLIPNAME=api.get("name");
KEYCLIP = (CLIPNAME.join().slice(-3));
post ("keyclip is ", KEYCLIP,"\n");
if ( api.get("color") == 16712965)
{
}
else if(KEYCLIP==KEYCLIPPLAY)
{
//really green, same key
api.set("color", "1769263");
}
else if (KEYCLIP.slice(0,2)==KEYCLIPPLAY.slice(0,2)&&KEYCLIP.slice(-1)=="A")
{
//dark green, minor
api.set("color", "5480241");
}
else if (KEYCLIP.slice(0,2)==KEYCLIPPLAY.slice(0,2)&&KEYCLIP.slice(-1)=="B")
{
//light green, major
api.set("color", "5480241");
}
else if (parseInt(KEYCLIP,10)==parseInt(KEYCLIPPLAY,10)+1&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//light purple, +1
api.set("color", "12094975");
}
// else if (7==parseInt(KEYCLIPPLAY.slice(0,2))&&KEYCLIP.slice(0,2)==8&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
// {
// //light purple, +1
// api.set("color", "12094975");
// }
else if (parseInt(KEYCLIP,10)==1&&parseInt(KEYCLIPPLAY,10)==12&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//light purple, +1
api.set("color", "12094975");
}
else if (parseInt(KEYCLIP,10)==parseInt(KEYCLIPPLAY,10)-1&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//dark purple, -1
api.set("color", "8940772");
}
else if (parseInt(KEYCLIP,10)==12&&parseInt(KEYCLIPPLAY,10)==1&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//dark purple, -1
api.set("color", "8940772");
}
else
{
//gray
api.set("color", "8092539");
}
}
}
}
// post (KEYCLIP,"\n");
// post ( parseInt(KEYCLIPPLAY.slice(0,2)), "\n");
// post ( parseInt(KEYCLIP.slice(0,2)), "\n");
//post ("keyclip is ", parseInt(KEYCLIP.slice(0,2))+1,"\n");
//post (CLIPCOLOR,"\n");
}
//print: 1769263 light green
//print: 8092539 gray
//print: 16712965 red
//js: 8940772 dark purple
//js: 10927616 light green
//js: 5480241 dark green
//js: 12094975 light purple
The script works really well and fast enough. Only after a while the script is stalling and it gets really slow. Especially when there a lot of clips and scenes in the session.
Anyone knows what I can do. Maybe some sort of reset.
This is the script:
//function bang()
inlets=1
function msg_int(TRACKPLAY)
{
var NoTRACKS = 3;
//var NoCLIPSLOTS = 6;
api = new LiveAPI(this.patcher, "live_set");
var SCENES=api.getcount("scenes");
//post (SCENES,"\n");
NoCLIPSLOTS=SCENES-1
//test="08A";
// post ("test is ");
// post (test,"\n");
// post ( parseInt(test,10), "\n");
//Resolve key of playing clip, last 3 characters of clipname, A01 to B12
var i=0;
for (i=0;i<=NoCLIPSLOTS;i++)
{
api = new LiveAPI(this.patcher, "live_set tracks " + TRACKPLAY + " clip_slots " + i);
if (api.get("has_clip") == 1)
{
api = new LiveAPI(this.patcher, "live_set tracks " + TRACKPLAY + " clip_slots " + i + " clip");
var CLIPISPLAYING=api.get("is_playing");
//post (CLIPISPLAYING,"\n");
if (CLIPISPLAYING==1)
{
var CLIPNAME=api.get("name");
KEYCLIPPLAY = (CLIPNAME.join().slice(-3));
api.set("color", "16712965");
//post (KEYCLIPPLAY,"\n");
i=NoCLIPSLOTS;
}
}
}
//Set color according to key
//tracks
//bugs:
//1A 1B
//1A 12A
for (k=4;k<=NoTRACKS+4;k++)
{
//clip_slots
var j=0;
for (j=0;j<=NoCLIPSLOTS;j++)
{
api = new LiveAPI(this.patcher, "live_set tracks " + k + " clip_slots " + j);
if (api.get("has_clip") == 1)
{
api = new LiveAPI(this.patcher, "live_set tracks " + k + " clip_slots " + j + " clip");
var CLIPNAME=api.get("name");
KEYCLIP = (CLIPNAME.join().slice(-3));
post ("keyclip is ", KEYCLIP,"\n");
if ( api.get("color") == 16712965)
{
}
else if(KEYCLIP==KEYCLIPPLAY)
{
//really green, same key
api.set("color", "1769263");
}
else if (KEYCLIP.slice(0,2)==KEYCLIPPLAY.slice(0,2)&&KEYCLIP.slice(-1)=="A")
{
//dark green, minor
api.set("color", "5480241");
}
else if (KEYCLIP.slice(0,2)==KEYCLIPPLAY.slice(0,2)&&KEYCLIP.slice(-1)=="B")
{
//light green, major
api.set("color", "5480241");
}
else if (parseInt(KEYCLIP,10)==parseInt(KEYCLIPPLAY,10)+1&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//light purple, +1
api.set("color", "12094975");
}
// else if (7==parseInt(KEYCLIPPLAY.slice(0,2))&&KEYCLIP.slice(0,2)==8&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
// {
// //light purple, +1
// api.set("color", "12094975");
// }
else if (parseInt(KEYCLIP,10)==1&&parseInt(KEYCLIPPLAY,10)==12&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//light purple, +1
api.set("color", "12094975");
}
else if (parseInt(KEYCLIP,10)==parseInt(KEYCLIPPLAY,10)-1&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//dark purple, -1
api.set("color", "8940772");
}
else if (parseInt(KEYCLIP,10)==12&&parseInt(KEYCLIPPLAY,10)==1&&KEYCLIP.slice(-1)==KEYCLIPPLAY.slice(-1))
{
//dark purple, -1
api.set("color", "8940772");
}
else
{
//gray
api.set("color", "8092539");
}
}
}
}
// post (KEYCLIP,"\n");
// post ( parseInt(KEYCLIPPLAY.slice(0,2)), "\n");
// post ( parseInt(KEYCLIP.slice(0,2)), "\n");
//post ("keyclip is ", parseInt(KEYCLIP.slice(0,2))+1,"\n");
//post (CLIPCOLOR,"\n");
}
//print: 1769263 light green
//print: 8092539 gray
//print: 16712965 red
//js: 8940772 dark purple
//js: 10927616 light green
//js: 5480241 dark green
//js: 12094975 light purple