String variables added to Csound5

A string variable is defined by using ‘S’ as the type letter, and can
be either global (gSname) or local (Sname). Operations on string
variables are performed at i-time, however, some string opcodes will
also run at performance time.

By default, the maximum allowed length of string variables is 255
characters, however, this limit can be changed with the -+max_str_len
command line option; for example, -+max_str_len=1000 will set the
maximum length to 999 characters.
Note: the length of string constants is not limited.

Currently, the following opcodes can be used for manipulating strings,
but more should be available soon. Existing opcodes that expect a quoted
string constant as input argument should also work with string variables.

     strset  indx, Sstr

set string value in strset table at the specified index to Sstr.
The opcode can be used both in the orchestra header and in instruments,
and runs at i-time, dynamically extending the table if needed.

Sr  strget  indx

copies value from strset table at the specified index to Sr, or, if
the index is a string p-field from the score, then that string is
copied. If no string is defined for indx, Sr is set to empty string.

Sr  strcpy  Sstr

copies Sstr to Sr. Using the same variable for input and output is
allowed (the opcode has no effect in this case).

Sr  strcpyk Sstr

same as strcpy, but runs both at initialization and performance time.

Sr  strcat  Sstr1, Sstr2

concatenates strings, by appending Sstr2 to Sstr1, and leaves the result
in Sr. It is allowed for Sr to be the same variable as Sstr1 or Sstr2.

Sr  strcatk Sstr1, Sstr2

same as strcat, but runs both at initialization and performance time.

ir  strcmp  Sstr1, Sstr2

compares two strings, and sets ir to -1, 0, or 1 if Sstr1 is less than,
equal to, or greater than Sstr2, respectively.

kr  strcmpk Sstr1, Sstr2

same as strcmp, but runs both at initialization and performance time.

Example:

S1  strcpy “foo”
S2  strcpy “bar.wav”
S3  strcat S1, S2
a1  diskin2 S3, 1  ; reads foobar.wav

Leave a Comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.