Issue with sending message to [line] object using JAVA


    Dec 27 2013 | 5:26 pm
    I need to send a message to line e.g 20 200
    I.e I want line to increase to 20 and use 200 ms on the operation.
    However the send method is per API defined like this:
    send(int i) Send this box the "int" message.
    send(java.lang.String message, Atom[] args) Send this box an arbitrary message.
    The only option I can think of is to send to the second inlet of line but do anyone know if this is possible in java to route to a specific inlet?
    MaxPatcher p = this.getParentPatcher();
    MaxBox mb = p.getNamedBox("sn_line1");
    mb.send(20); //This work but the change is immediate

    • Dec 27 2013 | 8:23 pm
      its not possible to send array to the outlet ? or literal with commas like in JS ? mb.send(20,200) ?
    • Dec 28 2013 | 9:01 am
      you could reformulate your message as "list 20 200" (which is essentially the same as "20 200") and use the "send(java.lang.String message, Atom[] args)" method.
      vb
    • Dec 28 2013 | 12:05 pm
      Thanks for the suggestions. However I did not get it quite to work. In the example below the value changes but the change is immediate so I assume the second value(the ramp time) is ignored..
      MaxPatcher p = this.getParentPatcher();
      MaxBox mb = p.getNamedBox("sn_line1");
      Atom[] outputAtom = new Atom[] {Atom.newAtom ("300 "),Atom.newAtom ("5000")};
      //mb.send(10); //OK
      mb.send("list",outputAtom);
    • Dec 28 2013 | 1:09 pm
      Hi Kmill !
      i never coded in java and max api but ...
      i would try to ommit "list" message as it may be that send() function sends array as list by itself (but im just guessing) ... because line object expects 2 values inside list message so it get two aready -> "list 300" and 5000 is ignored . but yeah , im jsut guessing .
      or try to format your atom array with 3 cells
      Atom[] outputAtom = new Atom[] {Atom.newAtom ("list "),Atom.newAtom ("300 "),Atom.newAtom ("5000")};
    • Dec 28 2013 | 4:51 pm
      First of all, a Java String is not a Max list. All Volker's suggestion will do is generate a symbol 'list 20 200' which is not, and never will be, a list (although inserting a [fromsymbol] object might give you some joy, but then you've got to go through Max patch cords--which, in and of itself, would probably be a Good Idea).
      I've had Java objects create Max lists, so it can be done. It's been a while, but as I recall, the Java/Max interface simply converts Atom arrays in Java to lists in Max. So, change your last line to
      mb.send(new Atom[] {Atom.newAtom(300), Atom.newAtom(5000)});
      And leave out the quotation marks, otherwise you're going to generate symbol atoms when you want int atoms.
    • Dec 28 2013 | 4:57 pm
      Actually, you could probably make life even easier for yourself by using an int[] instead of an Atom[].
      This is, btw, all covered in the "Writing Max Externals In Java" document, pp.29-31.
    • Dec 28 2013 | 11:13 pm
      The challenge is that I am bound by the API as described in my initial post. For that reason
      mb.send(new Atom[] {Atom.newAtom(300), Atom.newAtom(5000)}); will not be a valid call. However I think I will use outlets instead of direct messaging to the [line] object as described in the “Writing Max Externals In Java” document.
      MAX objects seem to be inconsistent with regards to the message format they receive and as far as I can see this is not reflected in the API. E.g the [play] object takes the style "start 300 500 200" (which is possible using the API) whilst the [line] object takes "200 5000" which is not possible using the API.
    • Dec 29 2013 | 9:47 am
      All Volker’s suggestion will do is generate a symbol ‘list 20 200′ which is not, and never will be, a list
      maybe the quotes were misleading, but i really meant message when i wrote message, and not symbol. thought it would be clear from the context.
      int args[] = {20, 200};
      MaxPatcher p = this.getParentPatcher();
      MaxBox mb = p.getNamedBox("sn_line1");
      mb.send("list", Atom.newAtom(args));