<!-- Converted to DocBook/SGML by Kevin Conder -->
<refentry id="define">
  <refmeta>
    <refentrytitle>&num;define</refentrytitle>
  </refmeta>
 
  <refnamediv>
    <refname>&num;define</refname>

    <refpurpose>
      Defines a macro.
      <indexterm id="IndexDefine"><primary>&num;define</primary></indexterm>
      <indexterm id="IndexDefineOrch"><primary>&num;define</primary><secondary>orchestra</secondary></indexterm>
      <indexterm id="IndexDefineMacros"><primary>macros</primary><secondary>orchestra</secondary></indexterm>
    </refpurpose>
  </refnamediv>
 
  <refsect1>
    <title>Description</title>
    <para>
      Macros are textual replacements which are made in the orchestra as it is being read.  The macro system in Csound is a very simple one, and uses the characters &num; and &dollar; to define and call macros. This can save typing, and can lead to a coherent structure and consistent style.  This is similar to, but independent of, the <link linkend="ScoreMacros"><citetitle>macro system in the score language</citetitle></link>.
    </para>

    <para>
      <emphasis>&num;define NAME</emphasis> -- defines a simple macro. The name of the macro must begin with a letter and can consist of any combination of letters and numbers. Case is significant. This form is limiting, in that the variable names are fixed.  More flexibility can be obtained by using a macro with arguments, described below.
    </para>

    <para>
      <emphasis>&num;define NAME</emphasis>(<emphasis>a&apos; b&apos; c&apos;</emphasis>) -- defines a macro with arguments. This can be used in more complex situations. The name of the macro must begin with a letter and can consist of any combination of letters and numbers. Within the replacement text, the arguments can be substituted by the form: &dollar;A.  In fact, the implementation defines the arguments as simple macros.  There may be up to 5 arguments, and the names may be any choice of letters.  Remember that case is significant in macro names.
    </para>
  </refsect1>
 
  <refsect1>
    <title>Syntax</title>
    <synopsis><command>&num;define</command> NAME &num; replacement text &num;</synopsis>

    <synopsis><command>&num;define</command> NAME(a&apos; b&apos; c&apos;) &num; replacement text &num;</synopsis>
  </refsect1>

  <refsect1>
    <title>Initialization</title>
    <para>
      <emphasis>&num; replacement text &num;</emphasis> --  The replacement text is any character string (not containing a &num;) and can extend over mutliple lines. The replacement text is enclosed within the &num; characters, which ensure that additional characters are not inadvertently captured.
    </para>
  </refsect1>

  <refsect1>
    <title>Performance</title>
    <para>
      Some care is needed with textual replacement macros, as they can sometimes do strange things.  They take no notice of any meaning, so spaces are significant. This is why, unlike the C programming language, the definition has the replacement text surrounded by &num; characters. Used carefully, this simple macro system is a powerful concept, but it can be abused.
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      Here is a simple example of the defining a macro. It uses the files <ulink url="examples/define.orc"><citetitle>define.orc</citetitle></ulink> and <ulink url="examples/define.sco"><citetitle>define.sco</citetitle></ulink>.

      <example>
        <title>Simple example of the define macro.</title>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/define.orc" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/define.sco" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>
      </example>

      Its output should include lines like this:
      <screen>
Macro definition for VOLUME
Macro definition for CPS
Macro definition for TABLE
      </screen>
    </para>

    <para>
      Here is an example of the defining a macro with arguments. It uses the files <ulink url="examples/define_args.orc"><citetitle>define_args.orc</citetitle></ulink> and <ulink url="examples/define_args.sco"><citetitle>define_args.sco</citetitle></ulink>.

      <example>
        <title>Example of the define macro with arguments.</title>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/define_args.orc" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/define_args.sco" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>
      </example>

      Its output should include lines like this:
      <screen>
Macro definition for OSCMACRO
      </screen>
    </para>
  </refsect1>
 
  <refsect1>
    <title>See Also</title>
    <para>
      <link linkend="dollar"><citetitle>&dollar;NAME</citetitle></link>, 
      <link linkend="undef"><citetitle>&num;undef</citetitle></link>
    </para>
  </refsect1>
 
  <refsect1>
    <title>Credits</title>
    <para>
      <simplelist>
        <member>Author: &namejohn;</member>
        <member>University of Bath/Codemist Ltd.</member>
        <member>Bath, UK</member>
        <member>April 1998</member>
      </simplelist>
    </para>
    <para>Examples written by &namekevin;.</para>

    <para>New in Csound version 3.48</para>
  </refsect1>
</refentry>
