Debian Codegraph @

opcodes/if.xml

raw symbols SCIP
1
2 <refentry id="if">
3 <indexterm id="IndexIf"><primary>if</primary></indexterm>
4 <refentryinfo><title>Instrument Control:Program Flow Control</title></refentryinfo>
5 <refmeta>
6 <refentrytitle>if</refentrytitle>
7 </refmeta>
8
9 <refnamediv>
10 <refname>if</refname>
11
12 <refpurpose>
13 Branches conditionally at initialization or during performance time.
14 </refpurpose>
15 </refnamediv>
16
17 <refsect1>
18 <title>Description</title>
19 <para>
20 <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.
21 </para>
22
23 <para>
24 <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.
25 </para>
26
27 <para>
28 <emphasis>if...goto</emphasis> -- combination of the above. Condition tested on every pass.
29 </para>
30
31 <para>
32 <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.
33 </para>
34
35 <note>
36 <title>Note</title>
37 <para>
38 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.
39 </para>
40 </note>
41 </refsect1>
42
43 <refsect1>
44 <title>Syntax</title>
45 <synopsis><command>if</command> ia R ib <command>igoto</command> label</synopsis>
46
47 <synopsis><command>if</command> ka R kb <command>kgoto</command> label</synopsis>
48
49 <synopsis><command>if</command> xa R xb <command>goto</command> label</synopsis>
50
51 <synopsis><command>if</command> xa R xb <command>then</command></synopsis>
52
53 <para>
54 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>).
55 </para>
56 <para>
57 If <emphasis>goto</emphasis> or <emphasis>then</emphasis> is used instead of <emphasis>kgoto</emphasis> or <emphasis>igoto</emphasis>, the behavior is determined by the type being compared. If the comparison used k-type variables, kgoto is used and viceversa.
58 </para>
59 <note>
60 <para>
61 <emphasis>If/then/goto</emphasis> statements cannot do audio-type comparisons. You cannot put a-type variables in the comparison expressions for these opcodes. The reason for this is that audio variables are actually vectors, which cannot be compared in the same way as scalars. If you need to compare individua audio samples, use <link linkend="kr"><citetitle>kr = 1</citetitle></link> or <link linkend="SigmodCompaccum"><citetitle>Comparators</citetitle></link>
62 </para>
63 </note>
64 </refsect1>
65
66 <refsect1>
67 <title>Examples</title>
68 <para>
69 Here is an example of the if...igoto combination. It uses the file <ulink url="examples/igoto.csd"><citetitle>igoto.csd</citetitle></ulink>.
70
71 <example>
72 <title>Example of the if...igoto combination.</title>
73
74 <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>
75 <xi:include href="examples-xml/igoto.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
76 </example>
77
78 Its output should include lines like this:
79 <screen>
80 instr 1: iparam = 0.000
81 instr 1: ifreq = 440.000
82 instr 1: iparam = 1.000
83 instr 1: ifreq = 880.000</screen>
84 </para>
85
86 <para>
87 Here is an example of the if...kgoto combination. It uses the file <ulink url="examples/kgoto.csd"><citetitle>kgoto.csd</citetitle></ulink>.
88
89 <example>
90 <title>Example of the if...kgoto combination.</title>
91 <xi:include href="examples-xml/kgoto.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
92 </example>
93
94 Its output should include lines like this:
95 <screen>
96 kval = 0.000000, kfreq = 440.000000
97 kval = 0.999732, kfreq = 440.000000
98 kval = 1.999639, kfreq = 880.000000</screen>
99 </para>
100 </refsect1>
101
102 <refsect1>
103 <title>Examples</title>
104 <para>
105 Here is an example of the if...then combo. It uses the file <ulink url="examples/ifthen.csd"><citetitle>ifthen.csd</citetitle></ulink>.
106
107 <example>
108 <title>Example of the if...then combo.</title>
109 <xi:include href="examples-xml/ifthen.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
110 </example>
111 </para>
112 </refsect1>
113
114 <refsect1>
115 <title>See also</title>
116 <para><link linkend="ControlPgmctl"><citetitle>Program Flow Control</citetitle></link></para>
117 </refsect1>
118
119 <refsect1>
120 <title>Credits</title>
121 <para>Examples written by &namekevin;.</para>
122 <para>Added a note by Jim Aikin.</para>
123 <para>February 2004. Added a note by &namematt;.</para>
124 </refsect1>
125 </refentry>