summaryrefslogtreecommitdiff
path: root/opcodes/if.xml
blob: 80acb48d9e63dd711511815b4a4f253810d16739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<refentry id="if">
<indexterm id="IndexIf"><primary>if</primary></indexterm>
  <refentryinfo><title>Instrument Control:Program Flow Control</title></refentryinfo>
  <refmeta>
    <refentrytitle>if</refentrytitle>
  </refmeta>


 
  <refnamediv>
    <refname>if</refname>

    <refpurpose>
      Branches conditionally at initialization or during performance time.
          </refpurpose>
  </refnamediv>
 
  <refsect1>
    <title>Description</title>
    <para>
      <emphasis>if...igoto</emphasis> -- conditional branch at initialization time, depending on the truth value of the logical expression <emphasis>ia</emphasis> <emphasis>R</emphasis> <emphasis>ib</emphasis>. The branch is taken only if the result is true.
    </para>

    <para>
      <emphasis>if...kgoto</emphasis> -- conditional branch during performance time, depending on the truth value of the logical expression <emphasis>ka</emphasis> <emphasis>R</emphasis> <emphasis>kb</emphasis>. The branch is taken only if the result is true.
    </para>

    <para>
      <emphasis>if...goto</emphasis> -- combination of the above. Condition tested on every pass.
    </para>

    <para>
      <emphasis>if...then</emphasis> -- allows the ability to specify conditional <emphasis>if</emphasis>/<emphasis>else</emphasis>/<emphasis>endif</emphasis> blocks.  All <emphasis>if...then</emphasis> blocks must end with an <emphasis>endif</emphasis> statement. <emphasis>elseif</emphasis> and <emphasis>else</emphasis> statements are optional. Any number of <emphasis>elseif</emphasis> statements are allowed. Only one <emphasis>else</emphasis> statement may occur and it must be the last conditional statement before the <emphasis>endif</emphasis> statement. Nested <emphasis>if...then</emphasis> blocks are allowed.
    </para>

    <note>
      <title>Note</title>
      <para>
        Note that if the condition uses a k-rate variable (for instance, <quote>if kval &gt; 0</quote>), the <emphasis>if...goto</emphasis> or <emphasis>if...then</emphasis> statement will be ignored during the i-time pass. This allows for opcode initialization, even if the k-rate variable has already been assigned an appropriate value by an earlier init statement.
      </para>
    </note>
  </refsect1>

  <refsect1>
    <title>Syntax</title>
    <synopsis><command>if</command> ia R ib <command>igoto</command> label</synopsis>

    <synopsis><command>if</command> ka R kb <command>kgoto</command> label</synopsis>

    <synopsis><command>if</command> ia R ib <command>goto</command> label</synopsis>

    <synopsis><command>if</command> xa R xb <command>then</command></synopsis>

    <para>
      where <emphasis>label</emphasis> is in the same instrument block and is not an expression, and where <emphasis>R</emphasis> is one of the Relational operators (<emphasis>&lt;</emphasis>, <emphasis>=</emphasis>, <emphasis>&lt;=</emphasis>, <emphasis>==</emphasis>, <emphasis>!=</emphasis>) (and <emphasis>=</emphasis> for convenience, see also under <link linkend="ControlConditional"><citetitle>Conditional Values</citetitle></link>).
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      Here is an example of the if...igoto combination. It uses the file <ulink url="examples/igoto.csd"><citetitle>igoto.csd</citetitle></ulink>.

      <example>
        <title>Example of the if...igoto combination.</title>

        <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para>
          <xi:include href="examples-xml/igoto.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      </example>

      Its output should include lines like this:
      <screen>
instr 1:  iparam = 0.000
instr 1:  ifreq = 440.000
instr 1:  iparam = 1.000
instr 1:  ifreq = 880.000
      </screen>
    </para>

    <para>
      Here is an example of the if...kgoto combination. It uses the file <ulink url="examples/kgoto.csd"><citetitle>kgoto.csd</citetitle></ulink>.

      <example>
        <title>Example of the if...kgoto combination.</title>
          <xi:include href="examples-xml/kgoto.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      </example>

      Its output should include lines like this:
      <screen>
kval = 0.000000, kfreq = 440.000000
kval = 0.999732, kfreq = 440.000000
kval = 1.999639, kfreq = 880.000000
      </screen>
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      Here is an example of the if...then combo. It uses the file <ulink url="examples/ifthen.csd"><citetitle>if.csd</citetitle></ulink>.

      <example>
        <title>Example of the if...then combo.</title>
          <programlisting>
<!--<xi:include href="examples/ifthen.csd" parse="text" xmlns:xi="http://www.w3.org/2001/XInclude"/>-->
          </programlisting>
      </example>
    </para>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <para>
      <link linkend="elseif"><citetitle>elseif</citetitle></link>,
      <link linkend="else"><citetitle>else</citetitle></link>,
      <link linkend="endif"><citetitle>endif</citetitle></link>,
      <link linkend="goto"><citetitle>goto</citetitle></link>,
      <link linkend="igoto"><citetitle>igoto</citetitle></link>,
      <link linkend="kgoto"><citetitle>kgoto</citetitle></link>,
      <link linkend="tigoto"><citetitle>tigoto</citetitle></link>,
      <link linkend="timout"><citetitle>timout</citetitle></link>
    </para>
  </refsect1>

  <refsect1>
    <title>Credits</title>
    <para>Examples written by &namekevin;.</para>
    <para>Added a note by Jim Aikin.</para>
    <para>February 2004. Added a note by &namematt;.</para>
  </refsect1>
</refentry>