Csound Csound-dev Csound-tekno Search About

[Cs-dev] SSTRCOD

Date2005-04-26 02:17
From"Michael Gogins"
Subject[Cs-dev] SSTRCOD
I assume that SSTRCOD also is to be deprecated? How then will functions test 
whether a parameter is a string?




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-04-26 15:02
FromIstvan Varga
SubjectRe: [Cs-dev] SSTRCOD
Michael Gogins wrote:

> I assume that SSTRCOD also is to be deprecated?

Unfortunately it is still in use for string p-fields in the score.

> How then will functions test whether a parameter is a string?

p->XSTRCODE (which expands to p->h.optext->t.xincod_str) is similar
to p->XINCODE, and can be used to find out if an argument is char*
or MYFLT*:

   p->XSTRCODE & 1 is non-zero if the first arg is a string
   p->XSTRCODE & 2 is non-zero if the second arg is a string
   p->XSTRCODE & 4 is non-zero if the third arg is a string
   p->XSTRCODE & 8 is non-zero if the fourth arg is a string
   etc.

There is also p->XOUTSTRCODE (p->h.optext->t.xoutcod_str) for outputs,
but this is not very useful because there is no multi-rate string/MYFLT
type for output.
Note also the change in OENTRY types:
   S:  string only, for input and output (string variable names are in the
       format Sfoo for a local and gSfoo for a global variable)
   T:  string or i-rate (input only)
   U:  string, or i- or k-rate (input only)

ENVIRON.strVarMaxLen is the number of bytes allocated for string variables,
while ENVIRON.strVarSamples is the same in MYFLT units.

There is also a new function (csound->strarg2name()) for file names, to be
used by soundin, diskin, etc.:

/* create file name from opcode argument (string or MYFLT)      */
/*   ENVIRON *csound:                                           */
/*      pointer to Csound instance                              */
/*   char *s:                                                   */
/*      output buffer, should have enough space; if NULL, the   */
/*      required amount of memory is allocated and returned     */
/*   void *p:                                                   */
/*      opcode argument, is interpreted as char* or MYFLT*,     */
/*      depending on the 'is_string' parameter                  */
/*   const char *baseName:                                      */
/*      name prefix to be used if the 'p' argument is MYFLT,    */
/*      and it is neither SSTRCOD, nor a valid index to strset  */
/*      space.                                                  */
/*      For example, if "soundin." is passed as baseName, file  */
/*      names in the format "soundin.%d" will be generated.     */
/*      baseName may be an empty string, but should not be NULL */
/*   int is_string:                                             */
/*      if non-zero, 'p' is interpreted as a char* pointer and  */
/*      is used as the file name. Otherwise, it is expected to  */
/*      point to a MYFLT value, and the following are tried:    */
/*        1. if the value is SSTRCOD, the string argument of    */
/*           the current score event is used (string p-field)   */
/*        2. if the value, rounded to the nearest integer, is a */
/*           valid index to strset space, the strset string is  */
/*           used                                               */
/*        3. the file name is generated using baseName and the  */
/*           value rounded to the nearest integer, as described */
/*           above                                              */
/*      'is_string' is usually p->XSTRCODE for an opcode with   */
/*      only one string argument, otherwise it is               */
/*      p->XSTRCODE & (1 << (argno - 1))                        */
/*   return value:                                              */
/*      pointer to the output string; if 's' is not NULL, it is */
/*      always the same as 's', otherwise it is allocated with  */
/*      mmalloc() and the caller is responsible for freeing the */
/*      allocated memory with mfree() or csound->Free()         */

char *strarg2name(ENVIRON *csound, char *s, void *p, const char *baseName,
                                    int is_string);

An example (from Opcodes/ugens9.c):

     char     cvfilnam[MAXNAME];
     [...]
     csound->strarg2name(csound, cvfilnam, p->ifilno, "convolve.",
                                 p->XSTRCODE);


-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start!  http://www.idcswdc.com/cgi-bin/survey?id=105hix
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net