(feature request) Loadbang delay argument

Hugobox's icon

Hi!
I keep finding myself using lots of loadbangs with various delays and it would be nice if the loadbang object could take an integer as an argument that would be a delay time in miliseconds.

What do you think?

Chris Muir's icon

In a complex giant patcher, the initialization gets quite complex. The method I settled on, in the largest patch that I use, is to start a metro/counter at the top left corner of the top level patch that counts to 100 at a rate of 5ms / tick. I send this value around via a [send load_percent] and elsewhere in the patch I compare load_percent to some threshold, and initialize when load_percent has crossed that threshold. This allows me a deterministic order of initialization across a giant patch, albeit at the cost of a half second longer load time.

Roman Thilenius's icon

i use an abstraction which allows 9 arguments for 9 different delay times.

Hugobox's icon

Thanks for the ideas!

Christopher Dobrian's icon

I don't understand why having the delay built into loadbang would be any better than using a delay object. (That's what it's made to do: delay a bang.)

Max Patch
Copy patch and select New From Clipboard in Max.

A different approach would be to use a single loadbang at the top level and use send or forward to send the messages you want where you want in the order you want. What with all the objects such as b, t, delay, pipe, uzi, etc., you can construct about any sort of ordering system you want. Here's a ludicrous example.

Luke Hall's icon

I wrote a javascript implementation of an ordered [loadbang] which you can find in the linked blog post. If you skip back to the previous post there is a bit more of an explanation. Otherwise I often tend to use one master [loadbang] and use an approach similar to the method Chris suggested. I hope it helps.

lh

EMV's icon

I wrote a little abstraction to do delayed loadbangs.
The first (optional) argument specifies a delay time in ms. (Optional)arguments after the first one will be sent out as a message after the delay (so it's loadbang and loadmess with a delay function).

Max Patch
Copy patch and select New From Clipboard in Max.

Stick it in a patcher, save it as 'loadbangdelay' (that's how I named it anyway) and put it in the Max path.

jvkr's icon

Be prepared to discover that this scheme (delaying loadbangs) not always works flawlessly. What I found to work better is that a process which has finished (eg loading a file, filling a buffer) triggers the next step in the sequence. And I use deferlow abundantly. The scheduler's ways are unfathomable (sometimes).

broc's icon

For me Initialization order is the most tricky and mysterious part of Max.
In particular, I wonder how to handle self-initializing live.* objects in combination with loadbang initializations of other objects.

Any comments on this?

pid's icon

@broc, total agreement (as you know!).

i used to think i had a pretty good handle on max initialisation, but since m4l and live.* objects came along, the thing is a minefield. every time i do anything i build test patches which give me different results to the last initialisation-test-patches i made.

so, +1 to broc, any comments always good...

(p.s. - gives me great heart to read the great jvkr's comment "The scheduler's ways are unfathomable (sometimes)")...

Hans Höglund's icon

I think the delay approach is problematic. Generally you should make a clear distinction between startup time and run time which is scheduled time in Max. If you definately want to defer something to the scheduler at startup defer is a better choice.

In complex patchers it is good to only use one loadbang object, connected to a trigger and possibly send/receive so that you can initialize sub-modules of your patch in a deterministic way. This would correspond to writing multiple init functions in a programming language, and call them all from the main function.

broc's icon

@Hans - your approach makes perfect sense to me. Thanks for explaining.

So I think the confusion comes only with MaxForLive where Max behaves different in some aspects. But that's another story..

Chris Muir's icon

Hans: The order of send/receive itself is non-deterministic, isn't it?

Roman Thilenius's icon

it is getting interesting here now.

jvkr is right:
delayed loadbangs sometimes do not work as exspected, for example
when drawing to lcd or loading files from disk, and mostly when the delay is too short.
so be careful what you do, never forget that maxmp is a young girl.

answer to christopher:
for the same reason why you make abstractions in any other situation.
110.loaddels 400 500 600 700 800 900 1000 is simply less writing compared to
loadbang del 400 del 500 del 600 del 700 del 800 del 900 del 1000 and
connect them.

(the same is true for ordered loadbangs - see my abstraction attached.)

then a little idea about how to organize/find the required load order.

1.
you are the programmer, you must simply decide and take responsibilty yourself.

2.
what can really help to do so, is that you do not put any loadbangs in your
subpatches (except inside abstarctions, where it is unavoidable), but have
a "loadbang-input" to you bigger subpatches and/or bpatchers, in order to
keep overview and/or control the load order.

3.
important for beginners: do not use delays only because you are unsure how
to organize order. learn how to organize order!
 attached files:

110.loadargs
110.loadinstance
110.loadlater
110.loadprint
110.loadrebang
110.loadsolo
110.loadunisym
have fun 

-110

614.110-loadstuff-forum.zip
zip
Hans Höglund's icon

The order in which objects of the same name receive messages is (basically) not deterministic, however using a trigger to invoke separately named objects is. The name would correspond to the submodule being initialized, of course.

I use the word "basically", since the first case would actually depend on creation order which is of course subtle.

The following patcher should make this all clear.

Max Patch
Copy patch and select New From Clipboard in Max.

broc's icon

The documentation clearly states:
"The order of reception by two or more receive objects is not deterministic."

So it's quite simple: if you need deterministic behavior, avoid multiple receivers
(which is easy by giving them different names).

Hans Höglund's icon

Well it is not uncommon for a behaviour to be deterministic under the hood even if it is not documented/specified. Such behaviour may of course change without warning and should not be relied on.

As I originally stated: use one loadbang, different receivers ;)