<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>pindex</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" /> <link rel="prev" href="phasorbnk.html" title="phasorbnk" /> <link rel="next" href="pinkish.html" title="pinkish" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">pindex</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="phasorbnk.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="pinkish.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="pindex"> <a id="pindex"></a> <div class="titlepage"></div> <a id="IndexPindex" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">pindex</span> </h2> <p>pindex — Returns the value of a specified pfield. </p> </div> <div class="refsect1" title="Description"> <a id="idp36260632"></a> <h2>Description</h2> <p> <span class="emphasis"><em>pindex</em></span> returns the value of a specified pfield. </p> </div> <div class="refsect1" title="Syntax"> <a id="idp36261552"></a> <h2>Syntax</h2> <pre class="synopsis">ivalue <span class="command"><strong>pindex</strong></span> ipfieldIndex</pre> </div> <div class="refsect1" title="Initialization"> <a id="idp36271992"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>ipfieldIndex</em></span> - pfield number to query. </p> <p> <span class="emphasis"><em>ivalue</em></span> - value of the pfield. </p> </div> <div class="refsect1" title="Examples"> <a id="idp36273608"></a> <h2>Examples</h2> <p> Here is an example of the pindex opcode. It uses the file <a class="ulink" href="examples/pindex.csd" target="_top"><em class="citetitle">pindex.csd</em></a>. </p> <div class="example"> <a id="idp36274528"></a> <p class="title"> <strong>Example 590. Example of the pindex opcode.</strong> </p> <div class="example-contents"> <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></span> <span class="comment">; Select audio/midi flags here according to platform</span> <span class="comment">; Audio out Audio in No messages MIDI in</span> -odac -iadc <span class="comment">; -d -M0 ;;;RT audio I/O with MIDI in</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">;-o pindex.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">;Example by Anthony Kozar Dec 2006</span> <span class="oblock">instr</span> 1 inum <span class="opc">pcount</span> index <span class="opc">init</span> 1 loop1<span class="op">:</span> ivalue <span class="opc">pindex</span> index <span class="opc">printf_i</span> "p<span class="op">%</span>d <span class="op">=</span> <span class="op">%</span>f\n", 1, index, ivalue index <span class="op">=</span> index <span class="op">+</span> 1 <span class="octrl">if</span> (index <span class="op"><=</span> inum) <span class="octrl">igoto</span> loop1 <span class="opc">print</span> inum <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">i</span>1 0 3 40 50 <span class="comment">; has 5 pfields</span> <span class="stamnt">i</span>1 1 2 80 <span class="comment">; has 5 due to carry</span> <span class="stamnt">i</span>1 2 1 40 50 60 70 <span class="comment">; has 7</span> <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> <p> The example will produce the following output: </p> <pre class="screen"> new alloc for instr 1: WARNING: instr 1 uses 3 p-fields but is given 5 p1 = 1.000000 p2 = 0.000000 p3 = 3.000000 p4 = 40.000000 p5 = 50.000000 instr 1: inum = 5.000 B 0.000 .. 1.000 T 1.000 TT 1.000 M: 0.0 new alloc for instr 1: WARNING: instr 1 uses 3 p-fields but is given 5 p1 = 1.000000 p2 = 1.000000 p3 = 2.000000 p4 = 80.000000 p5 = 50.000000 instr 1: inum = 5.000 B 1.000 .. 2.000 T 2.000 TT 2.000 M: 0.0 new alloc for instr 1: WARNING: instr 1 uses 3 p-fields but is given 7 p1 = 1.000000 p2 = 2.000000 p3 = 1.000000 p4 = 40.000000 p5 = 50.000000 p6 = 60.000000 p7 = 70.000000 instr 1: inum = 7.000 </pre> <p> The warnings can be ignored, because the pfields are used indirectly through pindex instead of explicitly through p4, p5, etc. </p> <p> Here is another example of the pindex opcode. It uses the file <a class="ulink" href="examples/pindex-2.csd" target="_top"><em class="citetitle">pindex-2.csd</em></a>. </p> <div class="example"> <a id="idp36310240"></a> <p class="title"> <strong>Example 591. Second example of the pindex opcode.</strong> </p> <div class="example-contents"> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></span> <span class="comment">; Select audio/midi flags here according to platform</span> -odac <span class="comment">;;;realtime audio</span> <span class="comment">;-iadc ;;;uncomment -iadc if realtime audio input is needed too</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o pindex-2.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">ksmps</span> <span class="op">=</span> 32 <span class="ohdr">nchnls</span> <span class="op">=</span> 2 <span class="ohdr">0dbfs</span> <span class="op">=</span> 1 <span class="comment">; This UDO returns a pfield value but returns 0 if it does not exist.</span> <span class="oblock">opcode</span> mypvalue, i, <span class="opc">i</span> index <span class="opc">xin</span> inum <span class="opc">pcount</span> <span class="octrl">if</span> (index <span class="op">></span> inum) then iout <span class="op">=</span> 0.0 <span class="octrl">else</span> iout <span class="opc">pindex</span> index <span class="octrl">endif</span> <span class="opc">xout</span> iout <span class="oblock">endop</span> <span class="comment">; Envelope UDO that reads parameters from a flexible number of pfields</span> <span class="comment">; Syntax: kenv flexlinseg ipstart</span> <span class="comment">; ipstart is the first pfield of the envelope</span> <span class="comment">; parameters. Reads remaining pfields (up to 21 of them).</span> <span class="comment">; kenv is the output envelope.</span> <span class="oblock">opcode</span> flexlinseg, k, <span class="opc">i</span> ipstart <span class="opc">xin</span> iep1 mypvalue ipstart iep2 mypvalue ipstart <span class="op">+</span> 1 iep3 mypvalue ipstart <span class="op">+</span> 2 iep4 mypvalue ipstart <span class="op">+</span> 3 iep5 mypvalue ipstart <span class="op">+</span> 4 iep6 mypvalue ipstart <span class="op">+</span> 5 iep7 mypvalue ipstart <span class="op">+</span> 6 iep8 mypvalue ipstart <span class="op">+</span> 7 iep9 mypvalue ipstart <span class="op">+</span> 8 iepa mypvalue ipstart <span class="op">+</span> 9 iepb mypvalue ipstart <span class="op">+</span> 10 iepc mypvalue ipstart <span class="op">+</span> 11 iepd mypvalue ipstart <span class="op">+</span> 12 iepe mypvalue ipstart <span class="op">+</span> 13 iepf mypvalue ipstart <span class="op">+</span> 14 iepg mypvalue ipstart <span class="op">+</span> 15 ieph mypvalue ipstart <span class="op">+</span> 16 iepi mypvalue ipstart <span class="op">+</span> 17 iepj mypvalue ipstart <span class="op">+</span> 18 iepk mypvalue ipstart <span class="op">+</span> 19 iepl mypvalue ipstart <span class="op">+</span> 20 kenv <span class="opc">linseg</span> iep1, iep2, iep3, iep4, iep5, iep6, iep7, iep8, \ iep9, iepa, iepb, iepc, iepd, iepe, iepf, iepg, \ ieph, iepi, iepj, iepk, iepl <span class="opc">xout</span> kenv <span class="oblock">endop</span> <span class="oblock">instr</span> 1 <span class="comment">; This instrument only requires 3 pfields but can accept up to 24.</span> <span class="comment">; (You will still get warnings about more than 3). </span> kenv flexlinseg 4 <span class="comment">; envelope params start at p4</span> aout <span class="opc">oscili</span> kenv<span class="op">*</span>.5, 256, 1 <span class="opc">outs</span> aout, aout <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">f</span>1 0 8192 10 1 <span class="stamnt">i</span>1 0 2 0.0 1.0 1.0 1.0 0.0 <span class="stamnt">i</span>1 2 2 0.0 0.1 1.0 1.0 1.0 0.1 0.0 <span class="stamnt">i</span>1 4 2 0.0 0.5 0.0 <span class="comment">; one problem is that "missing" pfields carry</span> <span class="stamnt">i</span>1 6 2 0.0 0.5 0.0 ! <span class="comment">; now we can fix this problem with !</span> <span class="stamnt">i</span>1 8 10 0.0 3.0 1.0 0.3 0.1 0.3 1.0 0.3 0.1 0.3 1.0 0.3 0.1 0.8 0.9 5.0 0.0 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> <p> The example will produce the following output: </p> <pre class="screen"> WARNING: instr 1 uses 3 p-fields but is given 8 B 0.000 .. 2.000 T 2.000 TT 2.000 M: 0.49966 0.49966 WARNING: instr 1 uses 3 p-fields but is given 10 B 2.000 .. 4.000 T 4.000 TT 4.000 M: 0.50000 0.50000 WARNING: instr 1 uses 3 p-fields but is given 10 B 4.000 .. 6.000 T 6.000 TT 6.000 M: 0.49943 0.49943 WARNING: instr 1 uses 3 p-fields but is given 6 B 6.000 .. 8.000 T 8.000 TT 8.000 M: 0.00000 0.00000 WARNING: instr 1 uses 3 p-fields but is given 20 B 8.000 .. 18.000 T 18.000 TT 18.000 M: 0.49994 0.49994 </pre> <p> </p> </div> <div class="refsect1" title="See Also"> <a id="idp36313104"></a> <h2>See Also</h2> <p> <a class="link" href="pcount.html" title="pcount"><em class="citetitle">pcount</em></a> </p> </div> <div class="refsect1" title="Credits"> <a id="idp36314232"></a> <h2>Credits</h2> <p>Example by: Anthony Kozar</p> <p>Dec. 2006</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="phasorbnk.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="OpcodesTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="pinkish.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">phasorbnk </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> pinkish</td> </tr> </table> </div> </body> </html>