<?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>active</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="abs.html" title="abs" /> <link rel="next" href="adsr.html" title="adsr" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">active</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="abs.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="adsr.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="active"> <a id="active"></a> <div class="titlepage"></div> <a id="IndexActive" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">active</span> </h2> <p>active — Returns the number of active instances of an instrument. </p> </div> <div class="refsect1" title="Description"> <a id="idp13226632"></a> <h2>Description</h2> <p> Returns the number of active instances of an instrument. </p> </div> <div class="refsect1" title="Syntax"> <a id="idp13251824"></a> <h2>Syntax</h2> <pre class="synopsis">ir <span class="command"><strong>active</strong></span> insnum [,iopt]</pre> <pre class="synopsis">ir <span class="command"><strong>active</strong></span> Sinsname [,iopt]</pre> <pre class="synopsis">kres <span class="command"><strong>active</strong></span> kinsnum [,iopt]</pre> </div> <div class="refsect1" title="Initialization"> <a id="idp13254352"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>insnum</em></span> -- number or string name of the instrument to be reported </p> <p> <span class="emphasis"><em>Sinsname</em></span> -- instrument name </p> <p> <span class="emphasis"><em>iopt</em></span> -- select currently active (zero, default), or all every active (non zero) </p> </div> <div class="refsect1" title="Performance"> <a id="idp13256336"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>kinsnum</em></span> -- number or string name of the instrument to be reported </p> <p> <span class="emphasis"><em>active</em></span> returns the number of active instances of instrument number <span class="emphasis"><em>insnum/kinsnum</em></span> (or named instrument <span class="emphasis"><em>Sinsname</em></span>). As of Csound 4.17 the output is updated at k-rate (if input arg is k-rate), to allow running count of instr instances. </p> <p> As of Csound 5.17 if the instrument number is given as zero then all instruments are counted. </p> </div> <div class="refsect1" title="Examples"> <a id="idp13258960"></a> <h2>Examples</h2> <p> Here is a simple example of the active opcode. It uses the file <a class="ulink" href="examples/active.csd" target="_top"><em class="citetitle">active.csd</em></a>. </p> <div class="example"> <a id="idp13260048"></a> <p class="title"> <strong>Example 36. Simple example of the active 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</span> -odac -iadc <span class="comment">;;;RT audio I/O</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o active.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">; Initialize the global variables.</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">kr</span> <span class="op">=</span> 4410 <span class="ohdr">ksmps</span> <span class="op">=</span> 10 <span class="ohdr">nchnls</span> <span class="op">=</span> 1 <span class="comment">; Instrument #1 - a noisy waveform.</span> <span class="oblock">instr</span> 1 <span class="comment">; Generate a really noisy waveform.</span> anoisy <span class="opc">rand</span> 44100 <span class="comment">; Turn down its amplitude.</span> aoutput <span class="opc">gain</span> anoisy, 2500 <span class="comment">; Send it to the output.</span> <span class="opc">out</span> aoutput <span class="oblock">endin</span> <span class="comment">; Instrument #2 - counts active instruments.</span> <span class="oblock">instr</span> 2 <span class="comment">; Count the active instances of Instrument #1.</span> icount <span class="opc">active</span> 1 <span class="comment">; Print the number of active instances.</span> <span class="opc">print</span> icount <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; Start the first instance of Instrument #1 at 0:00 seconds.</span> <span class="stamnt">i</span> 1 0.0 3.0 <span class="comment">; Start the second instance of Instrument #1 at 0:015 seconds.</span> <span class="stamnt">i</span> 1 1.5 1.5 <span class="comment">; Play Instrument #2 at 0:01 seconds, when we have only </span> <span class="comment">; one active instance of Instrument #1.</span> <span class="stamnt">i</span> 2 1.0 0.1 <span class="comment">; Play Instrument #2 at 0:02 seconds, when we have </span> <span class="comment">; two active instances of Instrument #1.</span> <span class="stamnt">i</span> 2 2.0 0.1 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> Its output should include lines like this: </p> <pre class="screen"> instr 2: icount = 1.000 instr 2: icount = 2.000 </pre> <p> </p> <p> Here is a more advanced example of the active opcode. It displays the results of the active opcode at k-rate instead of i-rate. It uses the file <a class="ulink" href="examples/active_k.csd" target="_top"><em class="citetitle">active_k.csd</em></a>. </p> <div class="example"> <a id="idp13263712"></a> <p class="title"> <strong>Example 37. Example of the active opcode at k-rate.</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> <span class="comment">; Audio out Audio in</span> -odac -iadc <span class="comment">;;;RT audio I/O</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o active_k.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">; Initialize the global variables.</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">kr</span> <span class="op">=</span> 4410 <span class="ohdr">ksmps</span> <span class="op">=</span> 10 <span class="ohdr">nchnls</span> <span class="op">=</span> 1 <span class="comment">; Instrument #1 - a noisy waveform.</span> <span class="oblock">instr</span> 1 <span class="comment">; Generate a really noisy waveform.</span> anoisy <span class="opc">rand</span> 44100 <span class="comment">; Turn down its amplitude.</span> aoutput <span class="opc">gain</span> anoisy, 2500 <span class="comment">; Send it to the output.</span> <span class="opc">out</span> aoutput <span class="oblock">endin</span> <span class="comment">; Instrument #2 - counts active instruments at k-rate.</span> <span class="oblock">instr</span> 2 <span class="comment">; Count the active instances of Instrument #1.</span> kcount <span class="opc">active</span> 1 <span class="comment">; Print the number of active instances.</span> <span class="opc">printk2</span> kcount <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; Start the first instance of Instrument #1 at 0:00 seconds.</span> <span class="stamnt">i</span> 1 0.0 3.0 <span class="comment">; Start the second instance of Instrument #1 at 0:015 seconds.</span> <span class="stamnt">i</span> 1 1.5 1.5 <span class="comment">; Play Instrument #2 at 0:01 seconds, when we have only </span> <span class="comment">; one active instance of Instrument #1.</span> <span class="stamnt">i</span> 2 1.0 0.1 <span class="comment">; Play Instrument #2 at 0:02 seconds, when we have </span> <span class="comment">; two active instances of Instrument #1.</span> <span class="stamnt">i</span> 2 2.0 0.1 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> Its output should include lines like: </p> <pre class="screen"> i2 1.00000 i2 2.00000 </pre> <p> </p> <p> Here is another example of the active opcode, using the number of instances to calculate gain. It uses the file <a class="ulink" href="examples/active_scale.csd" target="_top"><em class="citetitle">active_scale.csd</em></a>. </p> <div class="example"> <a id="idp13265856"></a> <p class="title"> <strong>Example 38. Example of the active opcode at k-rate.</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> <span class="comment">; Audio out Audio in No messages</span> -odac -d <span class="comment">;;;RT audio I/O</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o atone.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> 64 <span class="ohdr">nchnls</span> <span class="op">=</span> 1 <span class="ohdr">0dbfs</span> <span class="op">=</span> 1 <span class="comment">;by Victor Lazzarini 2008</span> <span class="oblock">instr</span> 1 kscal <span class="opc">active</span> 1 kamp <span class="opc">port</span> 1<span class="op">/</span>kscal, 0.01 asig <span class="opc">oscili</span> kamp, p4, 1 kenv <span class="opc">linseg</span> 0, 0.1,1,p3<span class="op">-</span>0.2,1,0.1, 0 <span class="opc">out</span> asig<span class="op">*</span>kenv <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">f</span>1 0 16384 10 1 <span class="stamnt">i</span>1 0 10 440 <span class="stamnt">i</span>1 1 3 220 <span class="stamnt">i</span>1 2 5 350 <span class="stamnt">i</span>1 4 3 700 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1" title="Credits"> <a id="idp13266816"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: John ffitch</td> </tr> <tr> <td>University of Bath/Codemist Ltd.</td> </tr> <tr> <td>Bath, UK</td> </tr> <tr> <td>July, 1999</td> </tr> </table> <p> </p> <p>Examples written by Kevin Conder.</p> <p>New in Csound version 3.57; named instruments added version 5.13</p> <p>Option for all ever active new in 5.13</p> <p>Count of all instruments new in 5.17</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="abs.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="adsr.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">abs </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> adsr</td> </tr> </table> </div> </body> </html>