Skip to content

compilestr

Compiles a new orchestra passed in as an ASCII string.

Compilestr will compile one or more instruments at init time, which will be added to the running engine. In case of existing instrument numbers or names, these will be replaced, but any instance still running of the old instrument definition will still perform until it terminates. Only new instances will use the new definition. Multi-line strings are accepted, using {{ }} to enclose the string.

Use compilestr with the existing instrument number or name to replace a definition while keeping its number. Include the instr and endin statements in the string. By contrast, create and createinstr compile an instrument body into a new definition in a free number slot; assigning that result to an existing InstrDef variable does not replace its previous definition.

Syntax

ires = compilestr(Sorch)
ires compilestr Sorch

Initialization

“Sorch” -- a string (in double-quotes or enclosed by {{ }}) containing one or more instruments.

ires -- returns 0 if compilation was successful, or -1 if not.

Examples

Here is an example of the compilestr opcode. It uses the file compilestr-modern.csd.

Example of the compilestr opcode.
<CsoundSynthesizer>
<CsOptions>
-o dac -d
</CsOptions>
<CsInstruments>
sr = 44100
nchnls = 1
ksmps = 32
0dbfs =  1

instr 1
  ;will fail because of wrong code
  res:i = compilestr({{
  instr 2
    a1 = oscilb(p4, p5, 0)
    out(a1)
  endin 
  }})
  print(res) ; returns -1 because not successfull

  ;will compile ...
  res = compilestr({{
  instr 2
    a1 = oscils(p4, p5, 0)
    out(a1)
  endin 
  }})
  print(res) ; ... and returns 0

  ;call the new instrument
  ;(note that the overall performance is extended)
  scoreline_i("i 2 0 3 0.2 415")
endin

</CsInstruments>
<CsScore>
i1 0 1
</CsScore>
</CsoundSynthesizer>

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

Example of the compilestr opcode.
<CsoundSynthesizer>
<CsOptions>
-o dac -d
</CsOptions>
<CsInstruments>
sr = 44100
nchnls = 1
ksmps = 32
0dbfs = 1

instr 1

 ;will fail because of wrong code
ires compilestr {{
instr 2 
a1 oscilb p4, p5, 0
out a1 
endin 
}}
print ires ; returns -1 because not successfull

 ;will compile ...
ires compilestr {{
instr 2 
a1 oscils p4, p5, 0
out a1 
endin 
}}
print ires ; ... and returns 0

 ;call the new instrument
 ;(note that the overall performance is extended)
scoreline_i "i 2 0 3 .2 415"

endin

</CsInstruments>
<CsScore>
i1 0 1
</CsScore>
</CsoundSynthesizer>

See also

Instrument Invocation

Credits

Author: Victor Lazzarini, 2013