Sending a list to the Function object from Javascript

    Feb 11 2013 | 2:32 pm
    Hi All,
    I'm trying to send a list to the function object from Javascript.
    I'm getting the object like this
    a = this.patcher.getnamed("amp_env_function");
    Then sending the message like this
    a.message("sustain 3 0");
    I'm also sending a list of x+y coordinates, correctly formatted with commas, as far as I know.
    I get this message - "function: doesn't understand "sustain 3 0""
    Now if I do a bit of symbol fiddling in the Max environment I can get it to update the function object with the right values, but why can't I do this directly from JS?

    • Feb 11 2013 | 5:14 pm
      a.message("sustain", 3, 0);
      This will send the symbol sustain with 2 arguments.
    • Feb 12 2013 | 12:21 am
      Thanks EJ, does that mean all objects I'm sending lists to should be formatted in this way?
    • Feb 12 2013 | 1:49 pm
      Yes or you can pass an array which will be unrolled automatically.
      var tmp = new Array();
      tmp[0] = "sustain";
      tmp[1] = 3;
      tmp[2] = 0;
      You can also use the literal notation.
    • Feb 22 2013 | 12:40 am
      I've another question which might come under this topic.
      From Javascript I'm sending messages to Function objects inside polys~, which seems to be working fine.
      However when sending the same message to Pattrstorage using setstoredvalue, I seem to be setting things that I shouldn't be.
      The first four items in the array seem to start with the length(domain) of the Function object, two of the others might be the Lo and Hi Display Range. Also, Am I right in thinking that the array changes for a sustain point too? Does this make any sense?
      Is there any documentation on how the Pattr system stores lists related to UI objects?
    • Mar 01 2013 | 3:38 pm
      OK so it appears that,
      [0] = domain length
      [1] = lo range
      [2] = hi range
      Then what follows are the points of the function, and after each point a '0' or '2'. Zero indicates no sustain, while 2 means sustain is on.
      So an array with the following, creates an ADSR, with 270 being the length, and the range being from 0 - 1.
      270, 0, 1, 0, 0, 0 , 15.97, 1, 0, 71.42, 0.62, 0, 179.38, 0.57, 2, 269.99, 0, 0
      With annotation...
      270(length), 0(lo), 1(hi), 0, 0, 0(point1), 15.97, 1, 0(point2), 71.42, 0.62, 0(point3), 179.38, 0.57, 2(point4 w sustain), 269.99, 0, 0(point5)
      Please correct me if I'm wrong, but that's working OK for me now.