printf
Prev | Orchestra Opcodes and Operators | Next

## printf

printf — printf-style formatted output

## Description

printf and printf_i write formatted output, similarly to the C function printf(). printf_i runs at i-time only, while printf runs both at initialization and performance time.

## Syntax

    printf_i Sfmt, itrig, [iarg1[, iarg2[, ... ]]]

    printf Sfmt, ktrig, [xarg1[, xarg2[, ... ]]]

## Initialization

Sfmt -- format string, has the same format as in printf() and other similar C functions, except length modifiers (l, ll, h, etc.) are not supported. The following conversion specifiers are allowed:

- d, i, o, u, x, X, e, E, f, F, g, G, c, s

iarg1, iarg2, ... -- input arguments (max. 30) for format. Integer formats like %d round the input values to the nearest integer.

itrig -- if greater than zero the opcode performs the printing; otherwise it is an null operation.

## Performance

ktrig -- if greater than zero and different from the value on the previous control cycle the opcode performs the requested printing. Initially this previous value is taken as zero.

xarg1, xarg2, ... -- input arguments (max. 30) for format. Integer formats like %d round the input values to the nearest integer. Note that only k-rate and i-rate arguments are valid (no a-rate printing)

## Examples

Here is an example of the printf opcode. It uses the file printf.csd.

Example 731. Example of the printf opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac     ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ;-o printf.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    instr 1
    Sfile     strget    p4
    ivld      filevalid Sfile

    if ivld=0 then
              printf_i  "Audiofile '%s' does not exist!\n", 1, Sfile
    else
    asig      diskin2   Sfile, 1
              outs      asig, asig
    endif

    endin

    </CsInstruments>
    <CsScore>

    i 1 0 3 "frox.wav";file does not exist!!!
    i 1 + 3 "fox.wav";but this one certainly does...

    e
    </CsScore>
    </CsoundSynthesizer>

The example will produce the following output:

    Audiofile 'frox.wav' does not exist!

## See Also

More information about printf: http://www.cplusplus.com/reference/clibrary/cstdio/printf/

## Credits

Author: Istvan Varga
2005

Prev | Up | Next
print | Home | printk2