| 1 | <section id="functional"> |
| 2 | <title>Function Syntax</title> |
| 3 | <para> |
| 4 | Since 6.0, Csound has introduced a new alternative syntax for orchestra code. This is initially an experimental feature, which has some limitations, |
| 5 | as explained below. It will also allow the introduction of some non-backwards-compatible language features. |
| 6 | </para> |
| 7 | <bridgehead>Overview</bridgehead> |
| 8 | <para> |
| 9 | The main aspect of the new syntax is that some opcodes can be called as functions, and inlined in orchestra code. The |
| 10 | general form of this is the expression: |
| 11 | </para> |
| 12 | <literallayout> |
| 13 | var* = op(exprlist*) |
| 14 | </literallayout> |
| 15 | <para> |
| 16 | where * indicates optional, var is a single variable in one of Csound6 types, and exprlist is a comma separated list |
| 17 | of expressions (or a single expression or variable). These expressions can be placed anywhere inside instrument or |
| 18 | opcode blocks. I-time operations can also be placed outside instrument blocks. The functional syntax can be intermixed with |
| 19 | standard Csound code. |
| 20 | </para> |
| 21 | <para> |
| 22 | Here are some examples of these expressions: |
| 23 | </para> |
| 24 | <literallayout> |
| 25 | |
| 26 | a1 = oscil(p4,p5) |
| 27 | out(vco2(p4*linen(1,0.1,p3,0.1),p5) |
| 28 | outs(oscili(in(),p5), in()) |
| 29 | |
| 30 | </literallayout> |
| 31 | <bridgehead>Limitations</bridgehead> |
| 32 | <para> |
| 33 | The main limitation is that only opcodes with single outputs (or no outputs) are allowed. In addition, opcodes with |
| 34 | multiple optional outputs will not be parsed successfully in this form. An alternative to allow for these |
| 35 | is to wrap them in user-defined opcodes, or just to intermix standard Csound syntax with this new style. |
| 36 | </para> |
| 37 | <para> |
| 38 | To resolve opcode ambiguities, we have introduced type annotations, in the form of op:type(exprlist). For instance |
| 39 | the code: |
| 40 | </para> |
| 41 | <para> |
| 42 | <literallayout> |
| 43 | |
| 44 | a1 = oscili(oscili:k(p4,p5), 440) |
| 45 | |
| 46 | </literallayout> |
| 47 | </para> |
| 48 | <para> |
| 49 | will choose a control-rate opcode to modulate the amplitude of the audio carrier, rather than an audio rate one. There will |
| 50 | be cases where the type annotation will be required, when the input arguments cannot be used to determine the correct type |
| 51 | of opcode to be applied. |
| 52 | </para> |
| 53 | </section> |