<!-- Converted to DocBook/SGML by Kevin Conder -->
<refentry id="midicontrolchange">
  <refmeta>
    <refentrytitle>midicontrolchange</refentrytitle>
  </refmeta>

  <refnamediv>
    <refname>midicontrolchange</refname>
    <refpurpose>
      Gets a MIDI control change value.
      <indexterm id="IndexMidicontrolchange"><primary>midicontrolchange</primary></indexterm>
    </refpurpose>
  </refnamediv>
  
  <refsect1>
    <title>Description</title>
    <para>
      <emphasis>midicontrolchange</emphasis> is designed to simplify writing instruments that can be used interchangeably for either score or MIDI input, and to make it easier to adapt instruments originally written for score input to work with MIDI input.
    </para>

    <para>
      In general, it should be possible to write instrument definitions that work identically with both scores
and MIDI, including both MIDI files and real-time MIDI input, without using any conditional statements, and that take full advantage of MIDI voice messages.
    </para>

    <para>
      Note that correlating Csound instruments with MIDI channel numbers is done using the <link linkend="massign"><citetitle>massign</citetitle></link> opcode for real-time performance,.  For file-driven performance, instrument numbers default to MIDI channel number + 1, but the defaults are overridden by any MIDI program change messages in the file.
    </para>
  </refsect1>

  <refsect1>
    <title>Syntax</title>
    <synopsis><command>midicontrolchange</command> xcontroller, xcontrollervalue [, ilow] [, ihigh]</synopsis>
  </refsect1>

  <refsect1>
    <title>Initialization</title>
    <para>
      <emphasis>ilow</emphasis> (optional) -- optional low value after rescaling, defaults to 0.
    </para>

    <para>
      <emphasis>ihigh</emphasis> (optional) -- optional high value after rescaling, defaults to 127.
    </para>
  </refsect1>

  <refsect1>
    <title>Performance</title>
    <para>
      <emphasis>xcontroller</emphasis> -- specifies a MIDI controller number (0-127).
    </para>

    <para>
      <emphasis>xcontrollervalue</emphasis> -- returns the value of the MIDI controller during MIDI activation, remains unchanged otherwise.
    </para>

    <para>
      If the instrument was activated by MIDI input, the opcode overwrites the values of the <emphasis>xcontroller</emphasis> and <emphasis>xcontrollervalue</emphasis> with the corresponding values from MIDI input. If the instrument was <emphasis>NOT</emphasis> activated by MIDI input, the values of <emphasis>xcontroller</emphasis> and <emphasis>xcontrollervalue</emphasis> remain unchanged.
    </para>

    <para>
      This enables score p-fields to receive MIDI input data during MIDI activation, and score values otherwise.
    </para>

    <note>
      <title>Adapting a score-activated Csound instrument.</title>
      <para>
        To adapt an ordinary Csound instrument designed for score activation for score/MIDI interoperability:

        <itemizedlist>
           <listitem><para>Change all <link linkend="linen"><citetitle>linen</citetitle></link>, <link linkend="linseg"><citetitle>linseg</citetitle></link>, and <link linkend="expseg"><citetitle>expseg</citetitle></link> opcodes to <link linkend="linenr"><citetitle>linenr</citetitle></link>, <link linkend="linsegr"><citetitle>linsegr</citetitle></link>, and <link linkend="expsegr"><citetitle>expsegr</citetitle></link>, respectively, except for a de-clicking or damping envelope. This will not materially change score-driven performance.</para></listitem>
           <listitem><para>Add the following lines at the beginning of the instrument definition:

              <informalexample>
                <programlisting>
; Ensures that a MIDI-activated instrument
; will have a positive p3 field.
mididefault 60, p3 
; Puts MIDI key translated to cycles per
; second into p4, and MIDI velocity into p5
midinoteoncps p4, p5 
                </programlisting>
              </informalexample>

             Obviously, <emphasis>midinoteoncps</emphasis> could be changed to <emphasis>midinoteonoct</emphasis> or any of the other options, and the choice of p-fields is arbitrary.</para></listitem>
        </itemizedlist>
      </para>
    </note>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <para>
      <link linkend="midichannelaftertouch"><citetitle>midichannelaftertouch</citetitle></link>, 
      <link linkend="mididefault"><citetitle>mididefault</citetitle></link>, 
      <link linkend="midinoteoff"><citetitle>midinoteoff</citetitle></link>, 
      <link linkend="midinoteoncps"><citetitle>midinoteoncps</citetitle></link>, 
      <link linkend="midinoteonkey"><citetitle>midinoteonkey</citetitle></link>, 
      <link linkend="midinoteonoct"><citetitle>midinoteonoct</citetitle></link>, 
      <link linkend="midinoteonpch"><citetitle>midinoteonpch</citetitle></link>, 
      <link linkend="midipitchbend"><citetitle>midipitchbend</citetitle></link>, 
      <link linkend="midipolyaftertouch"><citetitle>midipolyaftertouch</citetitle></link>, 
      <link linkend="midiprogramchange"><citetitle>midiprogramchange</citetitle></link>
    </para>
  </refsect1>

  <refsect1>
    <title>Credits</title>
    <para>Author: Michael Gogins</para>
    <para>New in version 4.20</para>
    <para>Thanks goes to &namerasmus; for pointing out the correct MIDI channel and controller number ranges.</para>
  </refsect1>
</refentry>
