Skip to content

str

Returns the name of an instrument definition.

Syntax

Sname = str(definition)
Sname str definition

Initialization

definition is an InstrDef for a named instrument. Sname receives its name as a string. The conversion runs once at initialization.

Use this when you have a typed definition and need its name for a message or another opcode that takes a string. For example, str(Tone) returns "Tone".

Use str with named definitions. An unnamed definition, such as one compiled from an instrument body with create, has no name to return. Use instrnum to obtain its number instead. To look up a name from a number, use instrstr.

Examples

The example prints the name from an InstrDef, then looks up the same name from its instrument number. It uses instrument-names.csd.

Convert an instrument definition to a name
<CsoundSynthesizer>
<CsOptions>
-odac -d -m0
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

instr Tone
  aTone poscil 0.1, p4
  out aTone
endin

instr 1
  definition:InstrDef = Tone
  Sname = str(definition)
  iNumber = instrnum(definition)
  Slookup = instrstr(iNumber)
  printf_i "Definition name %s\n", 1, Sname
  printf_i "Number lookup gives %s\n", 1, Slookup
  ; The typed definition can also go straight to schedule.
  schedule(definition, 0, 0.2, 440)
endin
</CsInstruments>
<CsScore>
i 1 0 0.3
e
</CsScore>
</CsoundSynthesizer>

See also

instrnum, instrstr, create, Instrument definitions, instances and opcode objects

Credits

Author Victor Lazzarini.

New in Csound 7.