Call a max object/function from JS possible?

    Mar 24 2011 | 6:05 pm
    Hey all, Is it possible to call a max function like ftom from Javascript?

    • Mar 25 2011 | 5:06 pm
      I guess maybe no one's gonna reply to this. Here's a javascript function that does the same job as ftom
      //Frequency to Midi conversion in JS:
      function ftom(freq) {
      I'm still interested if the max objects can be accessed from JS so if anyone knows. SHOUT!
    • Apr 27 2011 | 3:27 am
      The least roundabout way I can think of to access max values is to use
      var valueAfterMaxObjects = this.patcher.getnamed("bar").getvalueof();
      where sending foo a message triggers an update to bar's value.
    • Jan 14 2013 | 3:14 pm
      Lately I've returned to JS in max, and am doing some work in Jitter with JS, and I love how I can instantiate jitter objects and process matrices with them in the same way I would in the max patcher straight from JavaScript. In the same patch I would like to generate MIDI from the jitter matrices, so I've been desparately trying to find out how to call max objects (say makenote for instance) straight from JavaScript, using max as sort a library of MIDI functions and processors. Do I really need to actually create the objects in the patcher from JS, connect them all, and *then* be able to actually use them in my code?
      It is slightly frustrating to become comfortable with coding in JavaScript for max in one way as I do in jitter, but can't extend these techniques to max objects!
    • Jan 15 2013 | 4:09 pm
      It ain't that easy.
      When Jitter was introduced it came with its own Software Developer Kit (SDK) for developing externals. One of its peculiarities (compared to the SDK for plain-vanilla Max objects, and the SDK for MSP objects), was that Jitter externals are supposed to be coded in two parts: a "core" Jitter object and a "Max wrapper" object. The logic behind the division was that it was supposed to allow Jitter externals to be used from "other languages". At the time there weren't any other languages that used Jitter objects, and there weren't any on the horizon, either (at least not from where those outside C74 could see). Since the introduction of Javascript for Max, of course, the division suddenly makes sense. Which doesn't change the fact that it's something of a PITA for 3rd party developers. And, apparently, occasionally so even for developers at Cycling… there are a small number of Jitter objects that aren't supported in the Javascript environment. Don't ask me why, but it is so.
      As for Max and MSP objects, most of which were developed before the Jitter "division of labor" was introduced, it would require a pretty major effort to retrofit existing objects with the "core object"/"Max wrapper" split of functionality.
      Which isn't to discourage you from trying to lobby for that functionality. But understand that it's not just a matter of flipping a switch and all existing Max/MSP objects exist in Javascript.
      Instantiating objects inside JS code is cool, I do it myself. As for the 100-some-odd Max/MSP objects that I've already developed, the prospect of having to go back and code every one almost-but-not-quite from scratch in order to support instantiation from inside Javascript (or anything else) doesn't exactly fill this developer with delight. And until the Max SDK actually supports this sort of thing… well, I don't see that much can happen.
      This is just the view from outside the ranch, I don't know if any of the devs inside Cycling wants to say more about this.
    • Jan 16 2013 | 9:49 am
      @peter you can actually make NOBOX objects that will be available in JavaScript (there's an example in the SDK called simplejs which demonstrates that). Still you'll have to make a BOX object to instantiate your NOBOX object if you want to use it in Max and in JavaScript. I'm not saying it's easy, just that it's possible ;-) This is basically how polybuffer / dict works in the both Max and JS world.
    • Jan 16 2013 | 12:45 pm
      OK, good to know.
      Still, I'll retrofit all of Litter Power to support this when Cycling '74 does it for all the standard Max/MSP objects.
      Or do you want to have a race to see who gets done first?-)
    • Jan 16 2013 | 2:31 pm
      One could argue that it would make more sense to have the Litter Power objects in JS than the standard Max objects: they do very specific stuff whereas Max's plus object is very similar to js's plus ;-)
    • Jan 17 2013 | 2:29 pm
      [Plus] isn't exactly the most sophisticated factory Max object.
      Still a good point, indeed a very good one. Seriously need to claw out a good quantity of quality time to get this going.