printks
Prev | Orchestra Opcodes and Operators | Next

## printks

printks — Prints at k-rate using a printf() style syntax.

## Description

Prints at k-rate using a printf() style syntax.

## Syntax

    printks "string", itime [, xval1] [, xval2] [...]

## Initialization

"string" -- the text string to be printed. Can be up to 8192 characters and must be in double quotes.

itime -- time in seconds between printings.

## Performance

xval1, xval2, ... (optional) -- The k-rate values to be printed. These are specified in “string” with the standard C value specifier (%f, %d, %s etc.) in the order given.

In Csound version 4.23, you can use as many kval variables as you like. In versions prior to 4.23, you must specify 4 and only 4 kvals (using 0 for unused kvals).

printks prints numbers and text which can be i-time or k-rate values. printks is highly flexible, and if used together with cursor positioning codes, could be used to write specific values to locations in the screen as the Csound processing proceeds.

A special mode of operation allows this printks to convert kval1 input parameter into a 0 to 255 value and to use it as the first character to be printed. This enables a Csound program to send arbitrary characters to the console. To achieve this, make the first character of the string a # and then, if desired continue with normal text and format specifiers.

This opcode can be run on every k-cycle it is run in the instrument. To every accomplish this, set itime to 0.

When itime is not 0, the opcode print on the first k-cycle it is called, and subsequently when every itime period has elapsed. The time cycles start from the time the opcode is initialized - typically the initialization of the instrument.

## Print Output Formatting

All standard C language printf() control characters may be used. For example, if kval1 = 153.26789 then some common formatting options are:

1. %f prints with full precision: 153.26789

2. %5.2f prints: 153.26

3. %d prints integers-only: 153

4. %c treats kval1 as an ascii character code.

In addition to all the printf() codes, printks supports these useful character codes:

printks Code | Character Code
--- | ---
\\r, \\R, %r, or %R | return character (\r)
\\n, \\N, %n, %N | newline character (\n)
\\t, \\T, %t, or %T | tab character (\t)
%! | semicolon character (;) This was needed because a “;” is interpreted as an comment.
^ | escape character (0x1B)
^ ^ | caret character (^)
˜ | ESC[ (escape+[ is the escape sequence for ANSI consoles)
˜˜ | tilde (˜)

For more information about printf() formatting, consult any C language documentation.

| Note
Prior to version 4.23, only the %f format code was supported.

## Examples

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

Example 734. Example of the printks 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
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o printks.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 44100
    ksmps = 1
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; Change a value linearly from 0 to 100,
      ; over the period defined by p3.
      kup line 0, p3, 100
      ; Change a value linearly from 30 to 10,
      ; over the period defined by p3.
      kdown line 30, p3, 10

      ; Print the value of kup and kdown, once per second.
      printks "kup = %f, kdown = %f\\n", 1, kup, kdown
    endin

    </CsInstruments>
    <CsScore>

    ; Play Instrument #1 for 5 seconds.
    i 1 0 5
    e

    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like this:

    kup = 0.000000, kdown = 30.000000
    kup = 20.010843, kdown = 25.962524
    kup = 40.029991, kdown = 21.925049
    kup = 60.049141, kdown = 17.887573
    kup = 79.933266, kdown = 13.872493

## See Also

printk2 and printk

## Credits

Author: Robin Whittle
Australia
May 1997

Example written by Kevin Conder.

Thanks goes to Luis Jure for pointing out a mistake with the itime parameter.

Thanks to Matt Ingalls, updated the documentation for version 4.23.

Prev | Up | Next
printk | Home | printks2