Coding in max- js vs java vs ...


    Sep 13 2019 | 3:30 pm
    Hi, I use max/msp to make interactive sound art. I've found javascript really useful for the interaction logic and math within these max patches, but have been running up against problems with the low timing priority of the js object. All of the things I do in js I could and have done in max, but I find the process a lot slower, and a lot harder to modify later.
    With the goals of high speed and efficiency, and keeping in mind that it's not for directly processing audio, what are my alternatives? I haven't worked in java in years, but I'd relearn if mxj was the way to go. I'm learning c++ to create externals, but that seems better for small, reusable bits rather than these larger, more specific programs. An example of the kind of stuff I need to do and where I'm doing it now: max: -get data from sensors, for example: pitch/roll/yaw info from 10 sensors via serial or OSC -generate, process, route all audio js: -process datasets from sensors -based on sensor values, output control messages that: assign note values, modulate effects and envelope, route to different sub-patchers, trigger messages when multiple datasets do something specific- they're all at same angle or they're all balanced, etc. -time out messages after inactivity -load presets based on time of day -create messages for reading/writing to databases -custom ui elements
    Thanks

    • Sep 13 2019 | 3:45 pm
      I found a similar question from 2006 , but was curious about a) the performance penalties with inlet/outlet operations for java- I'm processing serial data, so many hits to inlet every second b) anything that's changed since 2006!
    • Sep 14 2019 | 12:25 pm
      I personnally still use mxj in 2019 for sensor, numbers processing. it's 20 to 100x faster than js. and it can process in the main thread. One interesting function in mxj, is that you can read and write from matrices with vectors. it's way faster than reading and writing each cell /plane values. By vector, It means that you can read as an java array directly a cell with all the planes. for sensor, particules, i store all datas in a matrix, each particule is a cell, with each plane for x,y,z,mass, velocity-x, etc... I can then process in mxj each cell by retrieving all the planes at once.
    • Sep 15 2019 | 11:47 am
      Java/mxj still has its strong point in my point of view. In my current project I went back to do stuff in a custom mxj object, because i need a lot of smaller operations on a set of matrices, that need to run in parallel. I constantly hit limits doing this in JavaScript and NodeForMax (which has asynchronous features) does not give me the access to (almost) all parts of Max as Java does.
      Java was for me the best and simplest way to take advantage of the Java multi threading capacities for that. I didn't even had to manage the the non-blocking thread myself as the Max-Java API offers this already (in a basic fashion) with the MaxClock Object. Another very strong plus (for me) for using Java is that I can use xdebug and a proper IDE for developing, meaning i can step step through my code while it executes. Debugging in Javascript in Max can be an exercise in frustration..... Unfortunately mxj is in "maintenance mode" by Cycling'74, meaning they ensure it keeps on working but there is no new development done :( Newer features (e.g. dicts) are not accessible in Java directly and to my knowledge the newest officially supported Java version is Java 8. The mxj/Java part in Max is well documented, but the documentation is VERY VERY VERY VERY hidden inside the application. On macOs got to your Max.app, select with right click "Show Package Contents" and navigate to the folder Contents/Resources/C74/packages/max-mxj and you'll find all yo need.
    • Sep 15 2019 | 1:27 pm
      @Dailytlj: I guess when you say "the process a lot slower", you mean the programming part. I find programming in simple Max to be quite efficient at execution. Maybe you already do that, but, for the record: to get a rough idea of the efficiency of different implementations in Max, you can use this very old idea with the [timer] object. That would be something to try with your own code, for instance in "Max" version vs js or mxj version.
      Max Patcher
      In Max, select New From Clipboard.
      You could modify to have the count inside your js or mxj world, depending on use case, how you want to use the inlets/outlets, etc.
    • Sep 27 2019 | 8:04 pm
      Thanks for all the feedback eveybody. I'm going to work on learning my way around the mxj object!
      @Jean-Francois Charles, sorry I was unclear, and you understood correctly. I find the programming part much slower in max, and also find it slower to interpret old max code vs old non-visual (js, java, c++ etc) code I've written, but both of these things may just be a result of my own inefficient/bad habits in programming and documenting my max patches.