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. In my continued exploration of javascript in MaxMSP I realised I could probably do this all in one [js] object and jotted down some code on a scrap of paper at work. I typed it up when I got home and all systems go first time, which is a good feeling. The code makes use of the global object to iterate through instances of the [js] and the task object to keep polling until everything is done. At the moment it requires the arguments to be an ascending sequence of numbers starting at 1 with no gaps but I’m looking into changing this, and adding a [loadmess] equivalent as well. Here we go:

// lh.loadbang.js

var loader = new Global("loader");
loader.num = 1;

var count = jsarguments[1];

var t = new Task(poll);
t.interval = 10;

function poll() {
	if (loader.num == count) {

function loadbang() {
	if (!max.loadbangdisabled) {

autowatch = 1;

// EOF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s