<?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>midichn</title> <link rel="stylesheet" href="csound.css" type="text/css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /> <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="midichannelaftertouch.html" title="midichannelaftertouch" /> <link rel="next" href="midicontrolchange.html" title="midicontrolchange" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">midichn</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="midichannelaftertouch.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="midicontrolchange.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="midichn"> <a id="midichn"></a> <div class="titlepage"></div> <a id="IndexMidichn" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">midichn</span> </h2> <p>midichn — Returns the MIDI channel number from which the note was activated. </p> </div> <div class="refsect1" title="Description"> <a id="id3018412"></a> <h2>Description</h2> <p> <span class="emphasis"><em>midichn</em></span> returns the MIDI channel number (1 - 16) from which the note was activated. In the case of score notes, it returns 0. </p> </div> <div class="refsect1" title="Syntax"> <a id="id3019321"></a> <h2>Syntax</h2> <pre class="synopsis">ichn <span class="command"><strong>midichn</strong></span></pre> </div> <div class="refsect1" title="Initialization"> <a id="id3019337"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>ichn</em></span> -- channel number. If the current note was activated from score, it is set to zero. </p> </div> <div class="refsect1" title="Examples"> <a id="id3019354"></a> <h2>Examples</h2> <p> Here is a simple example of the midichn opcode. It uses the file <a class="ulink" href="examples/midichn.csd" target="_top"><em class="citetitle">midichn.csd</em></a>. </p> <div class="example"> <a id="id3019370"></a> <p class="title"> <b>Example 362. Example of the midichn opcode.</b> </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 -d -M0 <span class="comment">;;;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 midichn.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.</span> <span class="oblock">instr</span> 1 i1 <span class="opc">midichn</span> <span class="opc">print</span> i1 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; Play Instrument #1 for 12 seconds.</span> <span class="stamnt">i</span> 1 0 12 <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> Here is an advanced example of the midichn opcode. It uses the file <a class="ulink" href="examples/midichn_advanced.csd" target="_top"><em class="citetitle">midichn_advanced.csd</em></a>. </p> <p> Don't forget that you must include the <a class="link" href="CommandFlags.html#FlagsMinusUpperF"><em class="citetitle">-F flag</em></a> when using an external MIDI file like <span class="quote">“<span class="quote">midichn_advanced.mid</span>”</span>. </p> <p> </p> <div class="example"> <a id="id3019440"></a> <p class="title"> <b>Example 363. An advanced example of the midichn opcode.</b> </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 MIDI in</span> -odac -iadc -d -M0 <span class="comment">;;;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 midichn_advanced.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> 10 <span class="ohdr">nchnls</span> <span class="op">=</span> 1 <span class="ohdr">massign</span> 1, 1 <span class="comment">; all channels use instr 1</span> <span class="ohdr">massign</span> 2, 1 <span class="ohdr">massign</span> 3, 1 <span class="ohdr">massign</span> 4, 1 <span class="ohdr">massign</span> 5, 1 <span class="ohdr">massign</span> 6, 1 <span class="ohdr">massign</span> 7, 1 <span class="ohdr">massign</span> 8, 1 <span class="ohdr">massign</span> 9, 1 <span class="ohdr">massign</span> 10, 1 <span class="ohdr">massign</span> 11, 1 <span class="ohdr">massign</span> 12, 1 <span class="ohdr">massign</span> 13, 1 <span class="ohdr">massign</span> 14, 1 <span class="ohdr">massign</span> 15, 1 <span class="ohdr">massign</span> 16, 1 gicnt <span class="op">=</span> 0 <span class="comment">; note counter</span> <span class="oblock">instr</span> 1 gicnt <span class="op">=</span> gicnt <span class="op">+</span> 1 <span class="comment">; update note counter</span> kcnt <span class="opc">init</span> gicnt <span class="comment">; copy to local variable</span> ichn <span class="opc">midichn</span> <span class="comment">; get channel number</span> istime <span class="opc">times</span> <span class="comment">; note-on time</span> <span class="octrl">if</span> (ichn <span class="op">></span> 0.5) <span class="octrl">goto</span> <span class="olabel">l2</span> <span class="comment">; MIDI note</span> <span class="opc">printks</span> "note <span class="op">%</span>.0f (time <span class="op">=</span> <span class="op">%</span>.2f) was activated from the score\\n", \ 3600, kcnt, istime <span class="octrl">goto</span> <span class="olabel">l1</span> <span class="olabel">l2</span><span class="op">:</span> <span class="opc">printks</span> "note <span class="op">%</span>.0f (time <span class="op">=</span> <span class="op">%</span>.2f) was activated from channel <span class="op">%</span>.0f\\n", \ 3600, kcnt, istime, ichn <span class="olabel">l1</span><span class="op">:</span> <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">t</span> 0 60 <span class="stamnt">f</span> 0 6 2 -2 0 <span class="stamnt">i</span> 1 1 0.5 <span class="stamnt">i</span> 1 4 0.5 <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"> note 7 (time = 0.00) was activated from channel 4 note 8 (time = 0.00) was activated from channel 2 </pre> <p> </p> </div> <div class="refsect1" title="See Also"> <a id="id3019466"></a> <h2>See Also</h2> <p> <a class="link" href="pgmassign.html" title="pgmassign"><em class="citetitle">pgmassign</em></a> </p> </div> <div class="refsect1" title="Credits"> <a id="id3019484"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Istvan Varga</td> </tr> <tr> <td>May 2002</td> </tr> </table> <p> </p> <p>The simple example was written by Kevin Conder.</p> <p>New in version 4.20</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="midichannelaftertouch.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="midicontrolchange.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">midichannelaftertouch </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> midicontrolchange</td> </tr> </table> </div> </body> </html>