Csound

OPCODE GUIDE: INSTRUMENT CONTROL

  • SCORE PARAMETER ACCESS

    p(x) gets the value of a specified p-field. (So, 'p(5)' and 'p5' both return the value of the fifth parameter in a certain score line, but in the former case you can insert a variable to specify the p-field.

    pindex does actually the same, but as an opcode instead of an expression.

    pset sets p-field values in case there is no value from a scoreline.

    passign assigns a range of p-fields to i-variables.

    pcount returns the number of p-fields belonging to a note event.
  • TIME AND TEMPO

    • Time Reading

      times / timek return the time in seconds (times) or in control cycles (timek) since the start of the current Csound performance.

      timeinsts / timeinstk return the time in seconds (timeinsts) or in control cycles (timeinstk) since the start of the instrument in which they are defined.

      date / dates return the number of seconds since 1 January 1970, using the operating system's clock, either as a number (date) or as a string (dates).

      setscorepos sets the playback position of the current score performance to a given position.
    • Tempo Reading

      tempo allows the performance speed of Csound scored events to be controlled from within an orchestra.

      miditempo returns the current tempo at k-rate, of either the midi file (if available) or the score.

      tempoval reads the current value of the tempo.

    • Duration Modifications

      ihold forces a finite-duration note to become a 'held' note.

      xtratim extend the duration of the current instrument instance by a specified time duration.
    • Time Signal Generators

      metro outputs a metronome-like control signal (1 value impulses separated by zeroes). Rate of impulses can be specified as impulses per second

      mpulse generates an impulse for one sample of user definable amplitude, followed by a user-definable time gap.
  • CONDITIONS AND LOOPS

    changed reports whether any of its k-rate variable inputs has changed.

    trigger informs whether a k-rate signal crosses a certain threshold, either in an upward direction, in a downward direction or both.

    if branches conditionally at initialisation or during performance time.

    loop_lt, loop_le, loop_gt and loop_ge perform loops either at i-time or at k-rate.
  • PROGRAM FLOW

    init initializes a k- or a-variable (assigns a value to a k- or a-variable which is valid at i-time).

    igoto jumps to a label at i-time.

    kgoto jumps to a label at k-rate.

    timout jumps to a label for a given time. Can be used in conjunction with reinit to perform time loops (see the chapter about Control Structures for more information).

    reinit / rigoto / rireturn forces a certain section of code to be reinitialised (i.e. i-rate variables will be refreshed).
  • EVENT TRIGGERING

    event_i / event: Generate an instrument event at i-time (event_i) or at k-time (event). Easy to use, but you cannot send a string to the subinstrument.

    scoreline_i / scoreline: Generate an instrument at i-time (scoreline_i) or at k-time (scoreline). Like event_i/event, but you can send to more than one instrument but unlike event_i/event you can send strings. On the other hand, you must usually pre-format your scoreline-string using sprintf.

    schedkwhen triggers an instrument event at k-time if a certain condition is given.

    seqtime / seqtime2 can be used to generate a trigger signal according to time values in a function table.

    timedseq is an event-sequencer in which time can be controlled by a time-pointer. Sequence data is stored in a function table or text file.

  • INSTRUMENT SUPERVISION

    • Instances And Allocation

      active returns the number of active instances of an instrument.

      maxalloc limits the number of allocations (instances) of an instrument.

      prealloc creates space for instruments but does not run them.
    • Turning On And Off

      turnon activates an instrument for an indefinite time.

      turnoff / turnoff2 enables an instrument to turn itself, or another instrument, off.

      mute mutes/unmutes new instances of a given instrument.

      remove removes the definition of an instrument as long as it is not in use.

      exitnow causes Csound to exit as fast as possible and with no cleaning up.
    • Named Instruments

      nstrnum returns the number of a named instrument.

  • SIGNAL EXCHANGE AND MIXING

    • chn opcodes

      chn_k, chn_a, and chn_S declare a control, audio, or string channel. Note that this can be done implicitly in most cases by chnset/chnget.

      chnset writes a value (i, k, S or a) to a software channel (which is identified by a string as its name).

      chnget gets the value of a named software channel.

      chnmix writes audio data to an named audio channel, mixing to the previous output.

      chnclear clears an audio channel of the named software bus to zero.
    • zak 

      zakinit initialised zak space for the storage of zak variables.

      zaw, zkw and ziw write to (or overwrite) a-rate, k-rate or i-rate zak variables respectively.

      zawm, zkwm and ziwm mix (accumulate) a-rate, k-rate or i-rate zak variables respectively.

      zar, zkr and zir read from a-rate, k-rate or i-rate zak variables respectively.

      zacl and zkcl clears a range of a-rate or k-rate zak variables respectively.