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

    <refpurpose>
      Informs when a krate signal crosses a threshold.
      <indexterm id="IndexTrigger"><primary>trigger</primary></indexterm>
    </refpurpose>
  </refnamediv>
 
  <refsect1>
    <title>Description</title>
    <para>
      Informs when a krate signal crosses a threshold.
    </para>
  </refsect1>
 
  <refsect1>
    <title>Syntax</title>
    <synopsis>kout <command>trigger</command> ksig, kthreshold, kmode</synopsis>
  </refsect1>
 
  <refsect1>
    <title>Performance</title>
    <para>
      <emphasis>ksig</emphasis> -- input signal
    </para>

    <para>
      <emphasis>kthreshold</emphasis> -- trigger threshold
    </para>

    <para>
      <emphasis>kmode</emphasis> -- can be 0 , 1 or 2
    </para>

    <para>
      Normally <emphasis>trigger</emphasis> outputs zeroes: only each time <emphasis>ksig</emphasis> crosses <emphasis>kthreshold</emphasis> <emphasis>trigger</emphasis> outputs a 1. There are three modes of using <emphasis>ktrig</emphasis>:
      <itemizedlist>
        <listitem><para><emphasis>kmode</emphasis> = 0 - (down-up) <emphasis>ktrig</emphasis> outputs a 1 when current value of <emphasis>ksig</emphasis> is higher than <emphasis>kthreshold,</emphasis> while old value of <emphasis>ksig</emphasis> was equal to or lower than <emphasis>kthreshold</emphasis>.</para></listitem>
        <listitem><para><emphasis>kmode</emphasis> = 1 - (up-down) <emphasis>ktrig</emphasis> outputs a 1 when current value of <emphasis>ksig</emphasis> is lower than <emphasis>kthreshold</emphasis> while old value of <emphasis>ksig</emphasis> was equal or higher than <emphasis>kthreshold</emphasis>.</para></listitem>
        <listitem><para><emphasis>kmode</emphasis> = 2  - (both) <emphasis>ktrig</emphasis> outputs a 1 in both the two previous cases.</para></listitem>
      </itemizedlist>
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      Here is an example of the trigger opcode. It uses the files <ulink url="examples/trigger.orc"><citetitle>trigger.orc</citetitle></ulink> and <ulink url="examples/trigger.sco"><citetitle>trigger.sco</citetitle></ulink>.

      <example>
        <title>Example of the trigger opcode.</title>

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

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

      Its output should include lines like this:
      <screen>
time = 0.050340 seconds, trigger = 1.000000
time = 0.150340 seconds, trigger = 1.000000
time = 0.250340 seconds, trigger = 1.000000
time = 0.350340 seconds, trigger = 1.000000
time = 0.450340 seconds, trigger = 1.000000
time = 0.550340 seconds, trigger = 1.000000
time = 0.650340 seconds, trigger = 1.000000
time = 0.750340 seconds, trigger = 1.000000
time = 0.850340 seconds, trigger = 1.000000
time = 0.950340 seconds, trigger = 1.000000
      </screen>
    </para>
  </refsect1>
 
  <refsect1>
    <title>Credits</title>
    <para>
      <simplelist>
        <member>Author: &namegabriel;</member>
        <member>Italy</member>
      </simplelist>
    </para>
    <para>Example written by &namekevin;.</para>

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