tags:

views:

47

answers:

1

I am considering audio and MIDI application in Max (or Max for Live, really), but I am totally comfortable in Java, so something like this also seems attractive. Does anybody have any experience with Max? Is it really geared to people who do not code, or is the goofy/friendly looking UI much more efficient than writing straight code in, say, Java? Also, has anyone wrote a VST plugin in Java, and can share any experiences there?

+2  A: 

Max is a dataflow language. I am more familiar with PD, which is by the same author.

The advantage of dataflow as a programming style is that most data dependencies are explicit - you can literally follow the connections between subroutines visually, and they are usually displayed as a line on the screen between them. The difficulty is that order of operations is less explicit, because it is two dimensional in layout, rather than one dimensional as textual code would be.

I do most of my audio stuff in supercollider nowadays, but for a quick sketch of an audio idea, and building a working rough model, pd works great.

The main difficulty of programming in a visual dataflow language is comprehending order of operations. It is possible to create multiple connections from one outlet, but it behooves you to create an explicit [trigger] object to control which of those connections runs first (a line coming from an outlet is conceptually the same as a subroutine call). Also there is a difficulty with experienced programmers with getting used to anonymous parameters - the patching lines have no names, they just have the outlet they are coming from and the inlet they are connected to to identify them.

Another tip is to use encapsulation - in a textual language you would have a library or a class file, in Max or PD you can load an external patch file by name - so you create a small patch with some outlets and inlets, and use that from your other patch in multiple places, rather than copying and pasting (just like you would call functions rather than copying and pasting blocks of code).

[send] and [receive] are for globally setting / getting data, and have all the same problems that come with globals - a common workaround when they are needed is to prepend a unique identifier specific to the current subpatch, the $0 token evaluates to the unique ID of the current subpatch in object names / parameters, and is used for this purpose. This simulates a scoped variable.

Debugging in dataflow is excellent, because it is very easy to detach a set of items from their surrounding patch and run them independently, and turning on trace for a part of the flow is as easy as attaching a number box to an outlet.

Justin Smith
And I almost forgot to mention: a great thing about max and pd is that spaghetti code literally looks like spaghetti, and well ordered code is usually apparent by the simple fact that it does not look like a mess when you stand five feet back from your monitor.
Justin Smith
Another option would be http://www.csounds.com/manual/html/CommandCsoundVST.html csoundvst, which embeds the csound programming language into a vst plugin. The syntax of csound is very old, based on assembler macros, but it is an excellent DSL for doing non realtime audio programming. An advantage of csound is that it has implementations of pretty much every non-tradesecret audio synthesis or processing algorithm built in, so you do much less rolling-your-own than you would in any other audio DSL. It is also the best performing audio DSL in wide usage, and is sure to outperform JVAP.
Justin Smith
+1 for now, I'll need to study your answer in depth.
Yar
Okay, obviously in SO terms this answer is great, best answer and all that. But while we're here: what about processing MIDI. I have a little Bomes-killer that I wrote, and I feel like Java is pretty brilliant for processing MIDI (I've written some loopers in my framework that are pretty sharp). Just wondering if you have anything to add on the MIDI front. Deep thanks for taking your time to share our experiences on this stuff.Message-heard re: programming tips on PD or Max. Great answers like this become valuable over years. Or at least I'll use it at some point :)
Yar
For midi processing, dataflow is nice in some ways, for example you can lay out a keyboard split visually as a set of subpatches arranged left to right. The disadvantage is that each voice needs to be a subpatch, because dynamic allocation is harder. csound has the advantage that all the voice allocation is automatic. Instruments are easily mapped to midi notes, you set up an instrument to respond to a midi channel, and pitch and velocity show up as parameters to the instrument, one instrument is played for each key pressed, and the instruments are turned off when you let go of each key.
Justin Smith
I just realized you may mean midi in to midi out processing, and in my experience dataflow is excellent for filtering, because you can lay it out visually as a set of paths (for pitch / velocity). For storing and looping in pd I have used delay pipelines (I am pretty sure max has them too), and you can set it up as a feedback loop sending packed delaytime/notevalue messages (this way you can have loops of different speeds cycling through the same delay pipe).
Justin Smith
Thanks Justin, perhaps me investing additional time in my Java app might be all wrong, if PD is the way to go. I'm doing looping with Arraylists of TimerTasks :)... I think I'll ask another question and ping you back here.
Yar