evalstr

evalstr — Evalstrs evaluates a string containing Csound code, returning a value.

Description

Evalstr compiles and runs Csound code and returns a value from the global space (instr 0). This opcode can be also used to compile new instruments (as compilestr).

Syntax

ires evalstr Scode 
kres evalstr Scode, ktrig 

Initialization

Scode -- a string to be compiled and evaluated.

Performance

ktrig -- triggers the compilation/evaluation if non-zero.

Examples

Here is an example of the evalstr opcode in conjunction with return:

Example 271. 

ival evalstr "return 2 + 2"
print ival
 


Here is a complete example of the evalstr opcode. It uses the file evalstr.csd.

Example 272. Example of the evalstr opcode.

<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 evalstr.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 44100
nchnls = 1
ksmps = 32
0dbfs = 1

; example by Stefano Cucchi - 2024

instr 2

ires1 evalstr {{
instr 3 
a1 poscil p4, p5
out a1 
endin 
}}
print ires1 ; ... and returns 0

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

endin

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


See Also

String Manipulation Opcodes

Credits

Author: Victor Lazzarini, 2013