Forums > Max For Live

Methods for storing and accessing key->value pairs

Feb 24 2010 | 10:28 pm

I’m working on a system to control Hi-Def flash animations from within Ableton Live, using Max4Live as glue. It’s working, but needs some better design for how it stores data.

I need to:
1. Store strings with integers as their indexes/keys
2. Retrieve strings based on their index
3. Save the data into pattr so Live can access it.

I’ve been working with a named coll (and a referred jit.cellblock for UI), which works great for storing/retrieving the pairs in the short term, but has been a bit of a nightmare as far as saving to a pattr. I’ve been trying Chris Muir’s collPattr method, but my keys come out as symbols.

The other possiblity I see is to simply have about 10 pairs of text fields and matching if/thens. The text fields will easily save with some autopattr, but the whole solution seems clunky.

I can attach the existing patch if it will help. For more clarification, I am doing MIDI to osc-type string conversion for transmission via the flashserver object. So I can choose incoming MIDI note 60 to trigger the message ‘/drumzilla/bass/1’.

I’d love to hear if you have an idea for an alternate method, or if you think I just need to work out the bugs in the coll-to-pattr system.

Feb 24 2010 | 10:54 pm

js Arrays seem like a good thought, but you should post the patch, if possible, or a patch demonstrating what you have.

why is a plain coll object not a good solution? parse the midi, get the number, send that to to coll. coll sends the value out to a sprintf and BAM you got your string. (that was meant to be a question.)

Feb 24 2010 | 11:25 pm

The upload system seems to have a problem with my .maxpat file.So instead I’ve uploaded both the .maxpat and .amxd files in a zip here:

The problem with the coll is saving it. This patch is designed as a Max4Live MIDI Effect – so there will be multiple instances of it running in Live, and colls within .amxd files do not remember their changes without a pattr system.

Feb 25 2010 | 7:02 am

If you go the js route, don’t use Array. You want to use a plain Object. Array will mostly work because it is an Object, but there are some weird issues that may or may not crop up.

Short version of the "right way" to make a map/dictionary/associative array/whatever you want to call it in js:

var myMap = {}; // an empty map
myMap["foo"] = "bar"; // associates "foo" with "bar"
myMap[1] = "baz"; // associates 1 with "baz"; // synonym for myMap["foo"]; only works for
           // keys which are strings which are valid
           // identifiers. myMap.1 won't work.

// iterate through all of the keys, values:
for(var x in myMap) {
    post(x, ":", myMap[x], ",");
// prints "foo : bar , 1 : baz ,"
Feb 25 2010 | 2:18 pm

> I’ve been trying Chris Muir’s collPattr method, but my keys come out as symbols.

You could convert them back with the "fromsymbol" object…

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

Forums > Max For Live