Debian Codegraph @

opcodes/OSClisten.xml

raw symbols SCIP
1
2 <refentry id="OSClisten">
3 <indexterm id="IndexOSClisten"><primary>OSClisten</primary></indexterm>
4 <refentryinfo><title>OSC</title></refentryinfo>
5 <refmeta>
6 <refentrytitle>OSClisten</refentrytitle>
7 </refmeta>
8
9 <refnamediv>
10 <refname>OSClisten</refname>
11 <refpurpose>
12 Listen for OSC messages to a particular path, either from a custom-defined
13 OSC server or from the Csound UDP server.
14 </refpurpose>
15 </refnamediv>
16
17 <refsect1>
18 <title>Description</title>
19 <para>Plugin opcode in osc; internal opcode (for UDP server)</para>
20 <para>
21 On each k-cycle looks to see if an OSC message has been sent to
22 a given path of a given type.
23 </para>
24 </refsect1>
25
26 <refsect1>
27 <title>Syntax</title>
28 <synopsis>kans <command>OSClisten</command> ihandle, idest, itype [, xdata1, xdata2, ...]</synopsis>
29 <synopsis>kans, kdata[] <command>OSClisten</command> ihandle,
30 idest, itype</synopsis>
31
32 <synopsis>kans, ... <command>OSClisten</command> idest, itype</synopsis>
33
34 </refsect1>
35
36 <refsect1>
37 <title>Initialization</title>
38 <para>
39 <emphasis>ihandle</emphasis>
40 -- In the first two versions (overloads) of the opcode, a handle
41 returned by an earlier call to OSCinit,
42 to associate
43 OSClisten with a particular port number. The third overload does
44 not take a handle as it will listen for messages
45 sent to the Csound <link linkend="udpserver"><citetitle>UDP server</citetitle></link>.
46 </para>
47 <para>
48 <emphasis>idest</emphasis>
49 -- a string that is the destination address. This takes the
50 form of a path prefixed with a forward slash, with optional subdirectories
51 separated by forward slashes. Csound processes incoming messages that
52 match this address.
53 </para>
54
55 <para>
56 <emphasis>itype</emphasis> -- a string that indicates the types
57 of the optional arguments that are to be read. The string can
58 contain the characters "acdfhisAG" which stand for audio,
59 character, double, float, 64-bit integer, 32-bit integer,
60 string, scalar array and f-table. All types other than 'asA'
61 require a k-rate variable; 's' requires a string variable, 'a' an audio
62 variable and 'A' an i- or k- rate array. For type 'G', a variable
63 or constant can be used.
64 </para>
65
66 <para> A handler is inserted into the listener (see OSCinit) to
67 intercept messages that match this pattern.
68 </para>
69
70 </refsect1>
71
72 <refsect1>
73 <title>Performance</title>
74 <para>
75 <emphasis>kans</emphasis> -- set to 1 if a new message was
76 received, or 0 if not. If multiple messages are received in
77 a single control period, the messages are buffered, and OSClisten
78 can be called again until zero is returned.
79 </para>
80
81 <para>
82 If there was a message the <emphasis>xdata</emphasis> variables
83 are set to the incoming values, as interpretted by the
84 <emphasis>itype</emphasis> parameter.
85 Note that although the <emphasis>xdata</emphasis> variables are on
86 the right of an operation, they are actually outputs, and so must be
87 variables of type a, ga, k, gk, S, gS, k[] and gk[] and may need
88 to be declared with init, or = in the case of string variables,
89 before calling OSClisten.
90 </para>
91
92 <para>
93 Alternatively, if the message to be received is a series of values all of
94 the same scalar numeric type (e.g., one of "dfhi"), then the
95 return parameter <emphasis>kdata</emphasis> may be used in place of
96 <emphasis>xdata</emphasis> variables. <emphasis>kdata</emphasis> must be an
97 array, it must be declared with init before calling OSClisten,
98 or used with the [] syntax. It will be created to sufficient
99 size if it is other that a one dimensional array of size greater
100 or equal to length as the format string. If a message is received, this
101 array will be filled with the incoming values. See below for an example of
102 this usage.
103 </para>
104
105 <para>
106 The third overload uses a different number of outputs of
107 different types (k or S) to store messages matching address and
108 type, which are coming into the UDP server. It only accepts
109 scalar values ("dfhi") or strings ("s").
110 </para>
111
112 </refsect1>
113
114 <refsect1>
115 <title>Example</title>
116 <para>
117 This example shows a pair of floating point numbers being received
118 on port 7770.
119 </para>
120
121 <informalexample>
122 <programlisting>
123 <emphasis role="ohdr">sr</emphasis> <emphasis role="op">=</emphasis> 44100
124 <emphasis role="ohdr">ksmps</emphasis> <emphasis role="op">=</emphasis> 100
125 <emphasis role="ohdr">nchnls</emphasis> <emphasis role="op">=</emphasis> 2
126
127 gihandle <emphasis role="opc">OSCinit</emphasis> 7770
128
129 <emphasis role="oblock">instr</emphasis> 1
130 kf1 <emphasis role="opc">init</emphasis> 0
131 kf2 <emphasis role="opc">init</emphasis> 0
132 nxtmsg:
133 kk <emphasis role="opc">OSClisten</emphasis> gihandle, &quot;/foo/bar&quot;, &quot;ff&quot;, kf1, kf2
134 if (kk <emphasis role="opc">==</emphasis> 0) goto ex
135 <emphasis role="opc">printk</emphasis> 0,kf1
136 <emphasis role="opc">printk</emphasis> 0,kf2
137 <emphasis role="opc">kgoto</emphasis> nxtmsg
138 ex:
139 <emphasis role="oblock">endin</emphasis>
140 </programlisting>
141 </informalexample>
142
143 <para>
144 This example shows use of the alternate form of the opcode, where an
145 array is used to receive a list of scalar values. In this case, the
146 OSC sender is simulating a set of radio buttons (as is done, for
147 example by a Lemur "Switches" object set in this mode), where the
148 button that is set will have value 1.0 and all other buttons will have
149 value 0.0.
150 </para>
151 <informalexample>
152 <programlisting>
153 gihandle <emphasis role="opc">OSCinit</emphasis> 7770
154 <emphasis role="oblock">instr</emphasis> 1
155 ; the UI object behind the OSC sender has 5 buttons arranged as radio buttons
156 kdata[] <emphasis role="opc">init</emphasis> 5
157 nxtmsg:
158 kk, kdata <emphasis role="opc">OSClisten</emphasis> gihandle, &quot;/foo/bar&quot;, &quot;fffff&quot;
159 if (kk <emphasis role="opc">==</emphasis> 0) goto ex
160 ; the only button with a non-zero value will be the one that is set,
161 ; so maxarray is used to get the index of that element
162 kmax, kidx <emphasis role="opc">maxarray</emphasis> kdata
163 <emphasis role="opc">printks</emphasis> &quot;button %d (zero-based) is set\n&quot;, 0, kidx
164 <emphasis role="opc">kgoto</emphasis> nxtmsg
165 ex:
166 <emphasis role="oblock">endin</emphasis>
167 </programlisting>
168 </informalexample>
169 <para>
170 Below are two .csd files which demonstrate the usage of the OSC opcodes. They use the files <ulink url="examples/OSCmidisend.csd"><citetitle>OSCmidisend.csd</citetitle></ulink> and <ulink url="examples/OSCmidircv.csd"><citetitle>OSCmidircv.csd</citetitle></ulink>.
171
172 <example>
173 <title>Example of the OSC opcodes.</title>
174 <para>The following two .csd files demonstrate the usage of the OSC opcodes in csound. The first file, <ulink url="examples/OSCmidisend.csd"><citetitle>OSCmidisend.csd</citetitle></ulink>, transforms received real-time MIDI messages into OSC data. The second file, <ulink url="examples/OSCmidircv.csd"><citetitle>OSCmidircv.csd</citetitle></ulink>, can take these OSC messages, and intrepret them to generate sound from note messages, and store controller values. It will use controller number 7 to control volume. Note that these files are designed to be on the same machine, but if a different host address (in the IPADDRESS macro) is used, they can be separate machines on a network, or connected through the internet.</para>
175 <para>CSD file to send OSC messages:</para>
176 <xi:include href="examples-xml/OSCmidisend.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
177 <para>CSD file to receive OSC messages:</para>
178 <xi:include href="examples-xml/OSCmidircv.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
179 </example>
180 </para>
181
182 <para>
183 The next example demonstrates the usage of the third overload of
184 the OSClisten opcode. It uses the fils <ulink url="examples/OSClistenex2.csd"><citetitle>OSClistenex2.csd</citetitle></ulink>.
185 </para>
186
187 <xi:include href="examples-xml/OSClistenex2.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
188
189 </refsect1>
190
191 <refsect1>
192 <title>See also</title>
193 <para><link linkend="OSC"><citetitle>OSC (Open Sound Control)</citetitle></link></para>
194 <para> More information on this opcode: <ulink url="http://www.youtube.com/watch?v=JX1C3TqP_9Y"><citetitle>http://www.youtube.com/watch?v=JX1C3TqP_9Y</citetitle></ulink> , made by Andrés Cabrera </para>
195 </refsect1>
196
197 <refsect1>
198 <title>Credits</title>
199 <para>
200 <simplelist>
201 <member>Author: &namejohn; Victor Lazzarini</member>
202 <member>2005, 2024</member>
203 <member>Examples by: David Akbari, &nameandres; and Jonathan
204 Murphy 2007; Victor Lazzarini 2024</member>
205 </simplelist>
206 </para>
207 <para>
208 <simplelist>
209 <member>types aAG are new in Csound 6.07</member>
210 <member>the use an an array for outputs is new in Csound
211 6.12</member>
212 <member>UDP server support new in Csound 7.0</member>
213 </simplelist>
214 </para>
215 </refsect1>
216 </refentry>