Forums > MaxMSP

memory in jsui,pictcontrol etc

February 10, 2006 | 4:56 pm

i just made a jsui that lets you load images for knob controls. It reads png transparency and lets you change the background colour. This means that max users can use the vast collection of knobs designed for synthedit.

here are some nice ones:

http://www.artvera-music.com/

The problem is that when you have an image with a large number of frames, every time you insert a new instance of the knob it uses up noticably more memory. So a patch with many knobs could use a very large amount of memory. I tried to work around this by using a global for the img object but it’s kind of complicated. I am wondering if there is any other way to make max store only one copy of the image file in memory and reference the same image in multiple JSUIs. Does pictcontrol do this?

thanks,

oli

http://www.oli.adbe.org

// graphicknob.js —————————-
//——————————————-

inlets = 1;
outlets = 1;

autowatch = 1;

sketch.default2d();
sketch.fsaa = 0;

var img = new Image("knob.png"); // create a new Image
var numframes = jsarguments[1];
var fheight = img.size[1]/numframes;
var y_offset = 0;
var vbrgb = [1.,1.,1.,1.];
var val = 0;
var last_x = 0;
var last_y = 0;

box.size(img.size[0],fheight);

draw();

function draw()
{
sketch.glclearcolor(vbrgb);
sketch.glclear();
sketch.copypixels(img,0,0,0,y_offset,img.size[0],fheight);
refresh();
}

// the loadimage function demonstrates creating a new image from a file
function loadimage(s)
{
img.freepeer();
img = new Image(s);
fheight = img.size[1]/numframes;
if(img.size[1]/fheight != numframes) post("check argument 1 (number of frames");
else
{
box.size(img.size[0],fheight);
msg_float(val);
}
}

function msg_float(v)
{
val = Math.min(Math.max(0,v),1);

var frame = Math.floor(val*(numframes-1));

y_offset = Math.floor(fheight*frame);
//if(frame>numframes/2) y_offset = y_offset -1; //if image has an odd number of frames we need this line, i think

notifyclients();
bang();
}

function bang()
{
draw();
if(jsarguments.length == 2) outlet(0,val);
else messnamed(jsarguments[2], val);
}

function notifydeleted()
{
img.freepeer();
}

function ondrag(x,y,but,cmd,shift,capslock,option,ctrl)
{
var f,dy;

dy = y – last_y;
if (shift) {
f = val – dy*0.001;
} else {
f = val – dy*0.01;
}
msg_float(f);
last_x = x;
last_y = y;
}
ondrag.local = 1;

function onclick(x,y,but,cmd,shift,capslock,option,ctrl)
{
last_x = x;
last_y = y;
}
onclick.local = 1;

function ondblclick(x,y,but,cmd,shift,capslock,option,ctrl)
{
last_x = x;
last_y = y;
msg_float(0); // reset dial?
}
ondblclick.local = 1;

function onresize()
{
box.size(img.size[0],fheight);
draw();
}
onresize.local = 1; //private

function brgb(r,g,b)
{
vbrgb[0] = r/255.;
vbrgb[1] = g/255.;
vbrgb[2] = b/255.;
draw();
refresh();
}


October 4, 2007 | 12:21 pm

Hi,

I also face this memory issue, and thus have the exact same question :

/*
I am wondering if there is any other way to make max store only one copy of the image file in memory and reference the same image in multiple JSUIs. Does pictcontrol do this?
*/

Thanks,

Salvator


Viewing 2 posts - 1 through 2 (of 2 total)