Javascript and pattrstorage

edsonedge's icon

Hi,

I am wondering how I can pull data from pattrstorage - both name and data

I want to compare pattr data to lists I would send from the patcher to the js object, through the inlet. -- And these are multiple lists from pattrstorage, so I would need to iterate through them with a for loop

As far as I understand the setvalueof and getvalueof are used so that pattrstorage can see variables within the javascript code - but I want to do the opposite: use data gotten from synths and such within max, and manipulate it with Javascript code.

Admin Support HEMU-CL's icon

BUMP!
i am also a beginner in javascript an i am very interested how to deal with connections fromto value and pattr object and JS....

do.while's icon

Hi !

@RATOX
you have got three functions to perform storage inside pattr . one way to expose values from JS to pattr is to connect pattr with middle outlet to your JS object in max

setvalueof / getvalueof / notifyclients

.
you can store one value , or array of values .
here is example of how to use array


var foo = [] ;

function setvalueof(){
    foo = arrayfromargs(arguments);
}

function getvalueof(){
    return foo ;
}

function bang(){
    post(foo[0] + " " + foo[1] + "\n");
}

function msg_int(i){
    foo[0] = i ;
    notifyclients();
}

function msg_float(f){
    foo[1] = f ;
    notifyclients();
}

@EDSONEDGE
i dont think u are able to see other values in pattrstorage than those owned by you inside JS .

you can affect ui controls and other by accessing them via its "varname" , there is no way to manipulate their state through pattrstorage in JS direct way .
You can try to access pattrstorage as an instance and send messages to it . but ive never checked it . at least you will not be able to retrieve any information from it

Admin Support HEMU-CL's icon

Dear Do...While,
you seem to have the right nickname to be helpful on these subject. Many thanks for the help, but because of my novice attitude there's still a point missing to me.

Your example works only if you bind the pattr to the [js] object name, is it? In this case i am able to write and read only one object per script.....

What i have in mind is to have a series of module that output a value that should be stored in a different [value] or [pattr] object to connect wirelessly to a central script that operate on these values.

The idea is to have an user interface made by some max abstraction that will store many parameters (numbers and filepaths) and make them accessible to central script that will operate on these values. Is there a way to achieve that, am I on the right path?

Thank you very much for your help...
Alessandro

do.while's icon

Hello Alessandro !

yes . JS object pattr'ized can hold only its own parameters , nor can access content of a pattrstorage in a direct way (or any way that i know , it may be that ive not been researching too far) .

What you are looking for is quite common scenario for data maintaining ,at least ive been researching of how to achieve it with JS in max .
So definitely there are few ways . Ive found one very useful ,but not without caveats .

In short ...
With help of "pattr" binded to "Dict" ,you would be able to store states of your data/elements once sent to "Dict" (or sent to JS and introduced to Dict from inside). It means that you can keep events in a database scenario .
Inside JS you are able to access that particular data internally and manipulate it in a various ways . and send it back to your "data owners" , ui's etc ...
As said , values are stored and pattr'ized via "Dict" . In order to recall all necessary data states after launching your patch again you need to automate it from inside JS by yourself,
by retrieving data from Dict and sending it to dedicated object instantiated in max directly .
Its not that straight forward as you are responsive to maintain updates to ui/objects and "Dict" state in order to keep values in sync until next recall , boot or save .

maybe there is another way (like editing JSON file in JS stored by pattrstorage - but never bothered to experiment),
actually i could not think of other solutions as im personally feeling comfortable with solution above .

If you will think of it ,and would like to explore the idea as you would feel that it could suit your need , im able to provide some help but for small systems this may be an overkill . And maybe there is a better solution than mine as its actually mirroring what pattrstorage is doing . I wouldnt be surprised .