Callback Messages

Callback messages are a way to call a function or a process using the syntax of a message, a syntactic commodity which does not introduce a new kind of actions.

A @message_def construction is used to specify a receiver and to associate to it a process or a function:

    @message_def recv1 := @cbk

The declaration is global: it can be appear anywhere in the score. Once specified, each message with receiver recv1 will call function @cbk instead of being dispatched to the Max or PD host (the default behavior).

Message's arguments becomes parameters of the function call:

  • If there is to few arguments w.r.t. to the function parameters, the remaining parameters are set to <undef>.

  • If there is to much arguments w.r.t. to the function parameters, all arguments in excess are gathered in a tab which becomes the last parameters.

For example, with @cbk defined as

    @fun_def @cbk($x, $y, $z) { print "x=" $x "y=" $y "z=" $z }

the following messages gives:

    toto 1          x= 1 y= <undef> z= <undef>
    toto 1 2        x= 1 y= 2 z= <undef>
    toto 1 2 3      x= 1 y= 2 z= 3
    toto 1 2 3 4    x= 1 y= 2 z= TAB[3, 4]


The right hand side of a @message_def specification must be an applicable value: a process, a function, a partially applied function, a nim, a tab or a map. However, to produce a visible effect, sending a callback message must imply some side-effect, which means that only process and (partially applied) function are relevant. For instance, a function may send Max messages.

The right hand side must be a closed expression or the @-name of a function.

Possibles Use

This feature has been introduced to ease the transitionning of Max implemented functionnalities to Antescofo implementations. Using this features, messages sent to Max can be rerouted to an Antescofo process achieving the same behavior, without altering the main Antescofo program.