Automatically Resize [bpatcher]

I’ve recently been piecing together a performance patch and using the [bpatcher] object to hold multiple instances of the same subpatch. As I think of new things to add into the subpatch I find it a bit annoying having to shuffle the [bpatcher] view around so the new user interface objects fit in. Presentation mode helps but to make things really simple I wrote this javascript which I can drop into the subpatch to do all the hard work for me. It automatically resizes and repositions the [bpatcher] view when everything loads. This way I don’t have to make any changes by hand, it saves me some time and lets me concentrate on the project work. If you’re using presentation mode you should give it a positive number argument so it knows to look out for only the objects you need, otherwise it uses every object on the canvas to calculate the dimensions. Continue reading…

Including Extra Javascript Files

Sometimes when writing javascript for use with Max/MSP I find I need to reuse bits of code that I’ve already created for a different project. Most of the time a simple search, copy and paste suffices but in some situations it would be better to have the ability to import other javascript files to get access to all of the functions they contain. This would also be useful when trying to organise where you files are stored. I don’t always want my javascripts in the Max search path (too many files here will cause the program to take ages to load), and I don’t always want them in the same directory as my main patch (which is the default place Max will look for a javascript/abstraction/image). The following code will import a specified javascript file into the current one. Continue reading…

JSON File Parser

When using javascript in MaxMSP you can query most of the attributes of the available objects. Things like the screen co-ordinates, the scripting name and whether the object is included in presentation mode. There are a few things that it cannot tell you with one example being the number of inlets or outlets an object has. One way to do this is to parse the file in the uncompressed text format. MaxMSP files are stored as JSON so reading them inside javascript isn’t too difficult. We can then query any of the values that you can see if you open a file as text. I’ve written a script to load in the parent patch and report object attributes in a few different ways. Continue reading…

Ordered [loadbang]

I have looked into setting the firing order of the [loadbang] object before for use in some of my own patches. I found one [mxj] class that does the job: mat.OrderedLoadBangMobj and one subpatch that makes use of javascript and the [loadmess] and [patcherargs] objects to guarantee order: TS.loadBang. Personally I tend to use one [loadbang] per patch and liberal use of [trigger] to specify the load order to keep things under control. However this can get a bit difficult when patches get larger and I dislike having to use lots of messy patch cables or confusing [send] and [receive] pairs. Continue reading…

Attribute Parsing

I’ve been working with javascript in MaxMSP quite a lot recently. I find it easier to work with when dealing with lists, logic and patch scripting. Personally, I think it makes a lot more sense to use a few lines of code than loads of standard objects. I will share some of these javascript tools in the future, hopefully someone will find them useful. In the meantime I’ve been tidying them up, documenting them and making helpfiles. While doing this I realised that it would be nice to be able to use @style attributes in the [js] object like you can in standard objects rather than just creating an array from the “jsarguments” property. So I decided to write a script to parse both attributes and arguments automatically so you don’t have to search for them yourself. Continue reading…