1 /*
2     namedins.h:
3 
4     Copyright (C) 2002 Istvan Varga
5 
6     This file is part of Csound.
7 
8     The Csound Library is free software; you can redistribute it
9     and/or modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12 
13     Csound is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with Csound; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21     02110-1301 USA
22 */
23 
24 /* namedins.h -- written by Istvan Varga, Oct 2002 */
25 
26 #ifndef CSOUND_NAMEDINS_H
27 #define CSOUND_NAMEDINS_H
28 
29 #include "csoundCore.h"         /* for INSTRTXT */
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /* check if the string s is a valid instrument or opcode name */
36 /* return value is zero if the string is not a valid name */
37 
38 int check_instr_name(char *);
39 
40 /* find the instrument number for the specified name */
41 /* return value is zero if none was found */
42 
43 int32 named_instr_find(CSOUND *, char *);
44 
45 /* convert opcode string argument to instrument number */
46 /* return value is -1 if the instrument cannot be found */
47 /* (in such cases, csoundInitError() is also called) */
48 
49 int32 strarg2insno(CSOUND *, void *, int);
50 
51 /* same as strarg2insno, but runs at perf time, */
52 /* and does not support numbered instruments */
53 /* (used by opcodes like event or schedkwhen) */
54 
55 int32 strarg2insno_p(CSOUND *, char *);
56 
57 /* convert opcode string argument to instrument number */
58 /* (also allows user defined opcode names); if the integer */
59 /* argument is non-zero, only opcode names are searched */
60 /* return value is -1 if the instrument cannot be found */
61 /* (in such cases, csoundInitError() is also called) */
62 
63 int32 strarg2opcno(CSOUND *, void *, int, int);
64 
65 /* create file name from opcode argument (string or MYFLT)      */
66 /*   CSOUND *csound:                                            */
67 /*      pointer to Csound instance                              */
68 /*   char *s:                                                   */
69 /*      output buffer, should have enough space; if NULL, the   */
70 /*      required amount of memory is allocated and returned     */
71 /*   void *p:                                                   */
72 /*      opcode argument, is interpreted as char* or MYFLT*,     */
73 /*      depending on the 'is_string' parameter                  */
74 /*   const char *baseName:                                      */
75 /*      name prefix to be used if the 'p' argument is MYFLT,    */
76 /*      and it is neither SSTRCOD, nor a valid index to strset  */
77 /*      space.                                                  */
78 /*      For example, if "soundin." is passed as baseName, file  */
79 /*      names in the format "soundin.%d" will be generated.     */
80 /*      baseName may be an empty string, but should not be NULL */
81 /*   int is_string:                                             */
82 /*      if non-zero, 'p' is interpreted as a char* pointer and  */
83 /*      is used as the file name. Otherwise, it is expected to  */
84 /*      point to a MYFLT value, and the following are tried:    */
85 /*        1. if the value is SSTRCOD, the string argument of    */
86 /*           the current score event is used (string p-field)   */
87 /*        2. if the value, rounded to the nearest integer, is a */
88 /*           valid index to strset space, the strset string is  */
89 /*           used                                               */
90 /*        3. the file name is generated using baseName and the  */
91 /*           value rounded to the nearest integer, as described */
92 /*           above                                              */
93 /*   return value:                                              */
94 /*      pointer to the output string; if 's' is not NULL, it is */
95 /*      always the same as 's', otherwise it is allocated with  */
96 /*      mmalloc() and the caller is responsible for freeing the */
97 /*      allocated memory with mfree() or csound->Free()         */
98 
99 char *strarg2name(CSOUND *, char *, void *, const char *, int);
100 
101 /* ----------------------------------------------------------------------- */
102 
sCmp(const char * x,const char * y)103 static inline int sCmp(const char *x, const char *y)
104 {
105     int   i = 0;
106     while (x[i] == y[i] && x[i] != (char) 0)
107       i++;
108     return (x[i] != y[i]);
109 }
110 
111 /* ----------------------------------------------------------------------- */
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif          /* CSOUND_NAMEDINS_H */
118 
119