Skip to content

printtype

Prints the type of a variable or expression.

Use printtype to inspect types while debugging an orchestra or a user-defined opcode. It prints the type name through Csound's message output. It has no output arguments and does not print the argument's value.

print_type is the older spelling and performs the same operation. Use printtype in new Csound 7 code.

Syntax

printtype(xarg)
print_type(xarg)
printtype xarg
print_type xarg

Initialization

xarg is one argument of any Csound type. It can be a variable or an expression.

The opcode prints once each time it initializes, including when the argument is a k-rate value or an audio signal. It does not print again on every control cycle. No testing option is required.

The message starts with Variable Type and gives the internal type name. Common names are shown below.

Printed type Meaning
i An i-rate number
k A k-rate number
a An audio signal
S A string
[ An array

For arrays, printtype prints only [. It does not show the element type, number of dimensions or length. Other types use their internal names.

Examples

This example inspects several variables and an expression that combines an i-rate number with a k-rate value. It uses printtype.csd.

Inspect variable and expression types
<CsoundSynthesizer>
<CsOptions>
-n -d -m0
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

instr 1
  iOffset = 2
  kValue init 3
  aSignal init 0
  Sname = "flute"
  iNotes[] fillarray 60, 64, 67

  ; Each call prints the type once, when this note starts.
  printtype(iOffset)
  printtype(kValue)
  printtype(aSignal)
  printtype(Sname)
  printtype(iNotes)

  ; The expression has k-rate because one of its inputs is k-rate.
  printtype(iOffset + kValue)
endin
</CsInstruments>
<CsScore>
i 1 0 0.1
e
</CsScore>
</CsoundSynthesizer>

The output includes these lines in order.

Variable Type: i
Variable Type: k
Variable Type: a
Variable Type: S
Variable Type: [
Variable Type: k

The final line shows that adding the i-rate number to the k-rate value produces a k-rate expression. Replacing printtype with print_type gives the same type messages.

See also

Printing and Display, print, printf

Credits

Opcode by Steven Yi, July 2014.

print_type is available from Csound 6.04. The printtype spelling is available from Csound 7.