Function Syntax in Csound6

Csound 6 has introduced a new alternative syntax for orchestra code. This is initially an experimental feature, which has some limitations, as explained below. It will also allow the introduction of some non-backwards-compatible language features.


The main aspect of the new syntax is that some opcodes can be called as functions, and inlined in orchestra code. The general form of this is the expression:

   var* = op(exprlist*)

where * indicates optional, var is a single variable in one of Csound6 types, and exprlist is a comma separated list of expressions (or a single expression or variable). These expressions can be placed anywhere inside instrument or opcode blocks. I-time operations can also be placed outside instrument blocks. The functional syntax can be intermixed with standard Csound code.

Here are some examples of these expressions:

   a1 = oscil(p4,p5)
   outs(oscili(in(),p5), in())



The main limitation is that only opcodes with single outputs (or no outputs) are allowed. In addition, opcodes with multiple optional outputs will not be parsed successfully in this form. An alternative to allow for these is to wrap them in user-defined opcodes, or just to intermix standard Csound syntax with this new style.

To resolve opcode ambiguities, we have introduced type annotations, in the form of op:type(exprlist). For instance the code:

   a1 = oscili(oscili:k(p4,p5), 440)


will choose a control-rate opcode to modulate the amplitude of the audio carrier, rather than an audio rate one. There will be cases where the type annotation will be required, when the input arguments cannot be used to determine the correct type of opcode to be applied.