2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 Primitives for Symbol.
28 #include "PyrPrimitive.h"
29 #include "PyrSymbol.h"
30 #include "VMGlobals.h"
31 #include "PyrKernel.h"
35 int prSymbolString(struct VMGlobals *g, int numArgsPushed);
36 int prSymbolString(struct VMGlobals *g, int numArgsPushed)
42 if (NotSym(a)) return errWrongType;
43 string = newPyrString(g->gc, slotRawSymbol(a)->name, 0, true);
49 int prSymbolIsPrefix(struct VMGlobals
*g
, int numArgsPushed
);
50 int prSymbolIsPrefix(struct VMGlobals
*g
, int numArgsPushed
)
57 if (!IsSym(a
) || !IsSym(b
)) return errWrongType
;
58 int32 alen
= slotRawSymbol(a
)->length
;
59 int32 blen
= slotRawSymbol(b
)->length
;
60 length
= sc_min(alen
, blen
);
61 if (memcmp(slotRawSymbol(a
)->name
, slotRawSymbol(b
)->name
, length
) == 0) {
69 int prSymbolClass(struct VMGlobals
*g
, int numArgsPushed
);
70 int prSymbolClass(struct VMGlobals
*g
, int numArgsPushed
)
77 if (slotRawSymbol(a
)->flags
& sym_Class
) {
78 //firstChar = slotRawSymbol(a)->name[0];
79 //if (firstChar >= 'A' && firstChar <= 'Z') {
80 classobj
= slotRawSymbol(a
)->u
.classobj
;
82 SetObject(a
, classobj
);
92 int prSymbolIsSetter(struct VMGlobals
*g
, int numArgsPushed
);
93 int prSymbolIsSetter(struct VMGlobals
*g
, int numArgsPushed
)
98 if (slotRawSymbol(a
)->flags
& sym_Setter
) {
106 int prSymbolAsSetter(struct VMGlobals
*g
, int numArgsPushed
);
107 int prSymbolAsSetter(struct VMGlobals
*g
, int numArgsPushed
)
114 if (!(slotRawSymbol(a
)->flags
& sym_Setter
)) {
115 if ((slotRawSymbol(a
)->flags
& sym_Class
) || (slotRawSymbol(a
)->flags
& sym_Primitive
)) {
116 error("Cannot convert class names or primitive names to setters.\n");
119 if (strlen(slotRawSymbol(a
)->name
)>255) {
120 error("symbol name too long.\n");
123 strcpy(str
, slotRawSymbol(a
)->name
);
128 //postfl("prSymbolAsSetter %s\n", str);
129 SetRaw(a
, getsym(str
));
134 int prSymbolAsGetter(struct VMGlobals
*g
, int numArgsPushed
);
135 int prSymbolAsGetter(struct VMGlobals
*g
, int numArgsPushed
)
141 if ((slotRawSymbol(a
)->flags
& sym_Setter
)) {
142 if ((slotRawSymbol(a
)->flags
& sym_Class
) || (slotRawSymbol(a
)->flags
& sym_Primitive
)) {
143 error("Cannot convert class names or primitive names to getters.\n");
146 strcpy(str
, slotRawSymbol(a
)->name
);
147 str
[strlen(str
)-1] = 0;
148 //postfl("prSymbolAsGetter %s\n", str);
149 SetRaw(a
, getsym(str
));
154 int prSymbolIsClassName(struct VMGlobals
*g
, int numArgsPushed
);
155 int prSymbolIsClassName(struct VMGlobals
*g
, int numArgsPushed
)
160 if (slotRawSymbol(a
)->flags
& sym_Class
) {
168 int prSymbolIsMetaClassName(struct VMGlobals
*g
, int numArgsPushed
);
169 int prSymbolIsMetaClassName(struct VMGlobals
*g
, int numArgsPushed
)
174 if (slotRawSymbol(a
)->flags
& sym_MetaClass
) {
182 int prSymbol_AsInteger(struct VMGlobals
*g
, int numArgsPushed
);
183 int prSymbol_AsInteger(struct VMGlobals
*g
, int numArgsPushed
)
187 char *str
= slotRawSymbol(a
)->name
;
188 SetInt(a
, atoi(str
));
193 int prSymbol_PrimitiveIndex(struct VMGlobals
*g
, int numArgsPushed
);
194 int prSymbol_PrimitiveIndex(struct VMGlobals
*g
, int numArgsPushed
)
198 SetInt(a
, slotRawSymbol(a
)->u
.index
);
203 int prSymbol_SpecialIndex(struct VMGlobals
*g
, int numArgsPushed
);
204 int prSymbol_SpecialIndex(struct VMGlobals
*g
, int numArgsPushed
)
208 SetInt(a
, slotRawSymbol(a
)->specialIndex
);
214 int prSymbol_AsFloat(struct VMGlobals
*g
, int numArgsPushed
);
215 int prSymbol_AsFloat(struct VMGlobals
*g
, int numArgsPushed
)
219 char *str
= slotRawSymbol(a
)->name
;
220 SetFloat(a
, atof(str
));
225 int prSymbol_matchOSCPattern(struct VMGlobals
*g
, int numArgsPushed
);
226 int prSymbol_matchOSCPattern(struct VMGlobals
*g
, int numArgsPushed
)
233 if (!IsSym(a
) || !IsSym(b
)) return errWrongType
;
234 // int32 alen = slotRawSymbol(a)->length;
235 // int32 blen = slotRawSymbol(b)->length;
236 // length = sc_min(alen, blen);
237 if (lo_pattern_match(slotRawSymbol(a
)->name
, slotRawSymbol(b
)->name
)) {
245 int prSymbol_isMap(struct VMGlobals
*g
, int numArgsPushed
);
246 int prSymbol_isMap(struct VMGlobals
*g
, int numArgsPushed
)
250 char *str
= slotRawSymbol(a
)->name
;
251 if(strlen(str
)>1 && (str
[0]=='a' || str
[0]=='c') && str
[1]>='0' && str
[1]<='9')
261 void initSymbolPrimitives();
262 void initSymbolPrimitives()
266 base
= nextPrimitiveIndex();
268 definePrimitive(base
, index
++, "_SymbolIsPrefix", prSymbolIsPrefix
, 2, 0);
269 //definePrimitive(base, index++, "_SymbolString", prSymbolString, 1, 0);
270 definePrimitive(base
, index
++, "_SymbolClass", prSymbolClass
, 1, 0);
271 definePrimitive(base
, index
++, "_SymbolIsClassName", prSymbolIsClassName
, 1, 0);
272 definePrimitive(base
, index
++, "_SymbolIsMetaClassName", prSymbolIsMetaClassName
, 1, 0);
273 definePrimitive(base
, index
++, "_SymbolIsSetter", prSymbolIsSetter
, 1, 0);
274 definePrimitive(base
, index
++, "_SymbolAsSetter", prSymbolAsSetter
, 1, 0);
275 definePrimitive(base
, index
++, "_SymbolAsGetter", prSymbolAsGetter
, 1, 0);
276 definePrimitive(base
, index
++, "_Symbol_AsInteger", prSymbol_AsInteger
, 1, 0);
277 definePrimitive(base
, index
++, "_Symbol_PrimitiveIndex", prSymbol_PrimitiveIndex
, 1, 0);
278 definePrimitive(base
, index
++, "_Symbol_SpecialIndex", prSymbol_SpecialIndex
, 1, 0);
279 definePrimitive(base
, index
++, "_Symbol_AsFloat", prSymbol_AsFloat
, 1, 0);
280 definePrimitive(base
, index
++, "_Symbol_matchOSCPattern", prSymbol_matchOSCPattern
, 2, 0);
281 definePrimitive(base
, index
++, "_Symbol_IsMap", prSymbol_isMap
, 1, 0);
287 #include "SCPlugin.h"
289 // export the function that SC will call to load the plug in.
291 extern "C" { SCPlugIn
* loadPlugIn(void); }
295 // define plug in object
296 class APlugIn
: public SCPlugIn
302 virtual void AboutToCompile();
307 // constructor for plug in
312 // destructor for plug in
315 void APlugIn::AboutToCompile()
317 // this is called each time the class library is compiled.
318 initSymbolPrimitives();
321 // This function is called when the plug in is loaded into SC.
322 // It returns an instance of APlugIn.
323 SCPlugIn
* loadPlugIn()
325 return new APlugIn();