| 1 | <refentry id="nstance"> |
| 2 | <indexterm id="IndexNstance"><primary>nstance</primary></indexterm> |
| 3 | <refentryinfo><title>Instrument Control:Invocation</title></refentryinfo> |
| 4 | <refmeta> |
| 5 | <refentrytitle>nstance</refentrytitle> |
| 6 | </refmeta> |
| 7 | |
| 8 | <refnamediv> |
| 9 | <refname>nstance</refname> |
| 10 | <refpurpose> |
| 11 | Schedules a new instrument instance, storing the instance handle in a variable. |
| 12 | </refpurpose> |
| 13 | </refnamediv> |
| 14 | |
| 15 | <refsect1> |
| 16 | <title>Description</title> |
| 17 | <para> |
| 18 | Schedules a new instrument nstance, returning a handle that can be used later to |
| 19 | refer directly to the running nstance. This opcode is similar to schedule, but has the added |
| 20 | facility of retrieving the nstance handle. |
| 21 | </para> |
| 22 | </refsect1> |
| 23 | |
| 24 | <refsect1> |
| 25 | <title>Syntax</title> |
| 26 | <synopsis>iHandle <command>nstance</command> insnum, iwhen, idur [, ip4] [, ip5] [...]</synopsis> |
| 27 | <synopsis>iHandle <command>nstance</command> "insname", iwhen, idur [, ip4] [, ip5] [...]</synopsis> |
| 28 | </refsect1> |
| 29 | |
| 30 | <refsect1> |
| 31 | <title>Initialization</title> |
| 32 | <para> |
| 33 | <emphasis>iHandle</emphasis> -- this variable will contain a handle to the event instance. It can be used, for example, to |
| 34 | stop the given instrument instance via the turnoff opcode. Note that the instance handle is only valid once the instrument is initialised. |
| 35 | </para> |
| 36 | <para> |
| 37 | <emphasis>insnum</emphasis> -- instrument number. Equivalent to p1 in a score <link linkend="i"><citetitle>i statement</citetitle></link>. <emphasis>insnum</emphasis> must be a number greater than the number of the calling instrument. |
| 38 | </para> |
| 39 | |
| 40 | <para> |
| 41 | <emphasis><quote>insname</quote></emphasis> -- A string (in double-quotes) representing a named instrument. |
| 42 | </para> |
| 43 | |
| 44 | <para> |
| 45 | <emphasis>iwhen</emphasis> -- start time of the new event. Equivalent to p2 in a score <link linkend="i"><citetitle>i statement</citetitle></link>. <emphasis>iwhen</emphasis> must be nonnegative. If <emphasis>iwhen</emphasis> is zero, <emphasis>insum</emphasis> must be greater than or equal to the p1 of the current instrument. |
| 46 | </para> |
| 47 | |
| 48 | <para> |
| 49 | <emphasis>idur</emphasis> -- duration of event. Equivalent to p3 in a score <link linkend="i"><citetitle>i statement</citetitle></link>. |
| 50 | </para> |
| 51 | |
| 52 | <para> |
| 53 | <emphasis>ip4, ip5, ...</emphasis> -- Equivalent to p4, p5, etc., in a score <link linkend="i"><citetitle>i statement</citetitle></link>. |
| 54 | </para> |
| 55 | </refsect1> |
| 56 | |
| 57 | <refsect1> |
| 58 | <title>Performance</title> |
| 59 | <para> |
| 60 | <emphasis>nstance</emphasis> adds a new score event. The arguments, including options, are the same as in a score. The <emphasis>iwhen</emphasis> time (p2) is measured from the time of this event. |
| 61 | </para> |
| 62 | |
| 63 | <para> |
| 64 | If the duration is zero or negative the new event is of MIDI type, and inherits the release sub-event from the scheduling instruction. |
| 65 | </para> |
| 66 | <note> |
| 67 | <para> Note that the <emphasis>nstance</emphasis> opcode cannot accept string p-fields. If you need to pass strings when instantiating an instrument, use the <link linkend="scoreline"><citetitle>scoreline</citetitle></link> or <link linkend="scoreline_i"><citetitle>scoreline_i</citetitle></link> opcode.</para> |
| 68 | </note> |
| 69 | </refsect1> |
| 70 | |
| 71 | <refsect1> |
| 72 | <title>Examples</title> |
| 73 | <para> |
| 74 | Here is an example of the nstance opcode. It uses the file <ulink url="examples/nstance.csd"><citetitle>nstance.csd</citetitle></ulink>. |
| 75 | <example> |
| 76 | <title>Example of the nstance opcode.</title> |
| 77 | <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para> |
| 78 | <xi:include href="examples-xml/nstance.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 79 | </example> |
| 80 | </para> |
| 81 | </refsect1> |
| 82 | |
| 83 | <refsect1> |
| 84 | <title>See also</title> |
| 85 | <para><link linkend="ControlInvocat"><citetitle>Instrument Invocation</citetitle></link></para> |
| 86 | <para> More information on this opcode: <ulink url="http://www.csoundjournal.com/issue15/phrase_loops.html"><citetitle>http://www.csoundjournal.com/issue15/phrase_loops.html</citetitle></ulink> , written by Jim Aikin </para> |
| 87 | </refsect1> |
| 88 | |
| 89 | <refsect1> |
| 90 | <title>Credits</title> |
| 91 | <para> |
| 92 | <simplelist> |
| 93 | <member>Author: &namevictor;</member> |
| 94 | <member>November 2013</member> |
| 95 | </simplelist> |
| 96 | </para> |
| 97 | </refsect1> |
| 98 | </refentry> |