| 1 | |
| 2 | <refentry id="leftbrace"> |
| 3 | <indexterm id="IndexLeftBraceStatement"><primary>{ statement</primary></indexterm> |
| 4 | <refmeta> |
| 5 | <refentrytitle>{ Statement</refentrytitle> |
| 6 | </refmeta> |
| 7 | |
| 8 | <refnamediv> |
| 9 | <refname>{</refname> |
| 10 | <refpurpose> |
| 11 | Begins a non-sectional, nestable loop. |
| 12 | </refpurpose> |
| 13 | </refnamediv> |
| 14 | |
| 15 | <refsect1> |
| 16 | <title>Description</title> |
| 17 | <para> |
| 18 | The <emphasis>{</emphasis> and <emphasis>} statements</emphasis> can be used to repeat a group of score statements. These loops do not constitute independent score sections and thus may repeat events within the same section. Multiple loops may overlap in time or be nested within each other. |
| 19 | </para> |
| 20 | </refsect1> |
| 21 | |
| 22 | <refsect1> |
| 23 | <title>Syntax</title> |
| 24 | <synopsis><command>{</command> p1 p2</synopsis> |
| 25 | </refsect1> |
| 26 | |
| 27 | <refsect1> |
| 28 | <title>Initialization</title> |
| 29 | <para> |
| 30 | <emphasis>p1</emphasis> -- Number of times to repeat the loop. |
| 31 | </para> |
| 32 | |
| 33 | <para> |
| 34 | <emphasis>p2</emphasis> -- A macro name that is automatically defined at the beginning of the loop and whose value is advanced with each repetition (optional). The initial value is zero and the final value is (p1 - 1). |
| 35 | </para> |
| 36 | </refsect1> |
| 37 | |
| 38 | <refsect1> |
| 39 | <title>Performance</title> |
| 40 | <para> |
| 41 | The <emphasis>{ statement</emphasis> is used in conjunction with the <link linkend="rightbrace"><citetitle>} statement</citetitle></link> to define repeating groups of other score events. A score loop begins with the <emphasis>{ statement</emphasis> which defines the number of repetitions and a unique macro name that will contain the current loop counter. The body of a loop can contain any number of other events (including sectional breaks) and is terminated by a <emphasis>} statement</emphasis> on its own line. The <emphasis>} statement</emphasis> takes no parameters. |
| 42 | </para> |
| 43 | |
| 44 | <para> |
| 45 | The use of the term "loop" here does not imply any sort of temporal succession to the loop iterations. In other words, the p2 values of the events inside of the loop are not automatically incremented by the length of the loop in each repetition. This is actually an advantage since it allows groups of simulataneous events to be easily defined as well. The loop macro can be used along with <link linkend="ScoreEval"><citetitle> score expressions</citetitle></link> to increase the start times of events or to vary the events in any other way desired for each iteration. The macro is incremented by one for each repetition. Note that unlike the <emphasis>r statement</emphasis>, the value of the macro the first time through the loop is zero (0), not one (1). Therefore the final value is one less than the number of repetitions. |
| 46 | </para> |
| 47 | |
| 48 | <para> |
| 49 | Score loops are a very powerful tool. While similar to the section repeat facility (the <link linkend="r"><citetitle>r statement</citetitle></link>), their chief advantage is that the score events in successive iterations of the loop are not separated by a section termination. Thus, it is possible to create multiple loops that overlap in time. Loops also can be nested within each other to a depth of 39 levels. |
| 50 | </para> |
| 51 | |
| 52 | <warning> |
| 53 | <title>Warning</title> |
| 54 | <para> |
| 55 | Because of serious problems of interaction with macro expansion, loops must start and end in the same file, and not in a macro. |
| 56 | </para> |
| 57 | </warning> |
| 58 | </refsect1> |
| 59 | |
| 60 | <refsect1> |
| 61 | <title>Examples</title> |
| 62 | <para> |
| 63 | Here are some examples of the <emphasis>{</emphasis> and <emphasis>} statements</emphasis>. |
| 64 | |
| 65 | <example> |
| 66 | <title>Sequentially repeat a three-note phrase four times.</title> |
| 67 | <programlisting> |
| 68 | <emphasis role="stamnt">{</emphasis> 4 CNT |
| 69 | |
| 70 | <emphasis role="stamnt">i</emphasis>1 [0.00 + 0.75 * $CNT.] 0.2 220 |
| 71 | <emphasis role="stamnt">i</emphasis>1 [0.25 + 0.75 * $CNT.] . 440 |
| 72 | <emphasis role="stamnt">i</emphasis>1 [0.50 + 0.75 * $CNT.] . 880 |
| 73 | |
| 74 | <emphasis role="stamnt">}</emphasis> |
| 75 | </programlisting> |
| 76 | is interpreted as |
| 77 | <programlisting> |
| 78 | <emphasis role="stamnt">i</emphasis>1 0.00 0.2 220 |
| 79 | <emphasis role="stamnt">i</emphasis>1 0.25 . 440 |
| 80 | <emphasis role="stamnt">i</emphasis>1 0.50 . 880 |
| 81 | |
| 82 | <emphasis role="stamnt">i</emphasis>1 0.75 0.2 220 |
| 83 | <emphasis role="stamnt">i</emphasis>1 1.00 . 440 |
| 84 | <emphasis role="stamnt">i</emphasis>1 1.25 . 880 |
| 85 | |
| 86 | <emphasis role="stamnt">i</emphasis>1 1.50 0.2 220 |
| 87 | <emphasis role="stamnt">i</emphasis>1 1.75 . 440 |
| 88 | <emphasis role="stamnt">i</emphasis>1 2.00 . 880 |
| 89 | |
| 90 | <emphasis role="stamnt">i</emphasis>1 2.25 0.2 220 |
| 91 | <emphasis role="stamnt">i</emphasis>1 2.50 . 440 |
| 92 | <emphasis role="stamnt">i</emphasis>1 2.75 . 880 |
| 93 | </programlisting> |
| 94 | </example> |
| 95 | </para> |
| 96 | |
| 97 | <para> |
| 98 | <example> |
| 99 | <title>Create a group of simultaneous harmonic partials.</title> |
| 100 | In this example, <emphasis>p4</emphasis> is assumed to be the frequency of the note event. |
| 101 | |
| 102 | <programlisting> |
| 103 | <emphasis role="stamnt">{</emphasis> 8 PARTIAL |
| 104 | <emphasis role="stamnt">i</emphasis>1 0 1 [100 * ($PARTIAL. + 1)] |
| 105 | <emphasis role="stamnt">}</emphasis> |
| 106 | </programlisting> |
| 107 | is interpreted as |
| 108 | <programlisting> |
| 109 | <emphasis role="stamnt">i</emphasis>1 0 1 100 |
| 110 | <emphasis role="stamnt">i</emphasis>1 0 1 200 |
| 111 | <emphasis role="stamnt">i</emphasis>1 0 1 300 |
| 112 | <emphasis role="stamnt">i</emphasis>1 0 1 400 |
| 113 | <emphasis role="stamnt">i</emphasis>1 0 1 500 |
| 114 | <emphasis role="stamnt">i</emphasis>1 0 1 600 |
| 115 | <emphasis role="stamnt">i</emphasis>1 0 1 700 |
| 116 | <emphasis role="stamnt">i</emphasis>1 0 1 800 |
| 117 | </programlisting> |
| 118 | </example> |
| 119 | </para> |
| 120 | |
| 121 | <para> |
| 122 | Here is a full example of the <emphasis>{</emphasis> and <emphasis>} statements</emphasis>. It uses the file <ulink url="examples/leftbrace.csd"><citetitle>leftbrace.csd</citetitle></ulink>. |
| 123 | |
| 124 | <example> |
| 125 | <title>An example of nested loops to create several inharmonic sine clusters.</title> |
| 126 | |
| 127 | <xi:include href="examples-xml/leftbrace.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 128 | </example> |
| 129 | </para> |
| 130 | |
| 131 | </refsect1> |
| 132 | |
| 133 | <refsect1> |
| 134 | <title>See Also</title> |
| 135 | <para> |
| 136 | <link linkend="ScoreStatements"><citetitle>Score Statements</citetitle></link> |
| 137 | </para> |
| 138 | </refsect1> |
| 139 | |
| 140 | <refsect1> |
| 141 | <title>Credits</title> |
| 142 | <para> |
| 143 | <simplelist> |
| 144 | <member>Author: &namegabriel;</member> |
| 145 | </simplelist> |
| 146 | </para> |
| 147 | |
| 148 | <para>New in Csound version 3.52 (?). (Fixed in version 5.08).</para> |
| 149 | </refsect1> |
| 150 | </refentry> |