1
/******************************************/
2
/* 3nd generation SKINI Text File Reader */
3
/* Class, by Perry R. Cook, 1999 */
4
/* This Object can open a SKINI File */
5
/* and parse it. The file spec is mine */
6
/* and mine alone, but it's all text so */
7
/* that should help you figuring it out. */
9
/* SKINI (Synthesis toolKit Instrument */
10
/* Network Interface) is like MIDI, but */
11
/* allows for floating point control */
12
/* changes, note numbers, etc. Example: */
13
/* noteOn 60.01 111.132 plays a sharp */
14
/* middle C with a velocity of 111.132 */
15
/* See SKINI11.txt for more information */
17
/******************************************/
21
SKINI11 :: SKINI11(char *fileName) /* Constructor for reading SKINI files */
22
{ /* Use nextMessage() method */
23
myFile = fopen(fileName,"r");
24
if ((int) myFile < 0) printf("SKINI11: Can't open SKINI score file\n");
28
SKINI11 :: SKINI11() /* Constructor to use this object for parsing */
29
{ /* SKINI Strings (coming over socket for example */
30
} /* Use parseThis() method with string argument */
36
/***************** SOME HANDY ROUTINES *******************/
38
#include "SKINI11.tbl"
40
#define __SK_MAX_FIELDS_ 5
41
#define __SK_MAX_SIZE_ 32
43
short ignore(char aChar)
46
if (aChar == 0) ignoreIt = 1; // Null String Termination
47
if (aChar == '\n') ignoreIt = 1; // Carraige Return???
48
if (aChar == '/') ignoreIt = 2; // Comment Line
52
short delimit(char aChar)
54
if (aChar == ' ' || // Space
55
aChar == ',' || // Or Comma
56
aChar == '\t') // Or Tab
62
short nextChar(char* aString)
66
for (i=0;i<__SK_MAX_SIZE_;i++) {
67
if ( aString[i] != ' ' && // Space
68
aString[i] != ',' && // Or Comma
69
aString[i] != '\t' ) // Or Tab
75
int subStrings(char *aString,
76
char someStrings[__SK_MAX_FIELDS_][__SK_MAX_SIZE_],
77
int somePointrs[__SK_MAX_FIELDS_],
78
char *remainderString)
80
int notDone,howMany,point,temp;
84
temp = nextChar(aString);
85
if (temp >= __SK_MAX_SIZE_) {
87
printf("Confusion here: Ignoring this line\n");
88
printf("%s\n",aString);
92
somePointrs[howMany] = point;
95
if (aString[point] == '\n') {
99
someStrings[howMany][temp++] = aString[point++];
100
if (temp >= __SK_MAX_SIZE_) {
104
if (delimit(aString[point]) || aString[point] == '\n') {
105
someStrings[howMany][temp] = 0;
107
if (howMany < __SK_MAX_FIELDS_) {
108
temp = nextChar(&aString[point]);
110
somePointrs[howMany-1] = point;
115
somePointrs[howMany-1] = point;
116
while(aString[point] != '\n')
117
remainderString[temp++] = aString[point++];
118
remainderString[temp] = aString[point];
123
// printf("Got: %i Strings:\n",howMany);
124
// for (temp=0;temp<howMany;temp++)
125
// printf("%s\n",someStrings[temp]);
130
/**************** THE ENCHILLADA !!!! **********************/
131
/*** This function parses a single string (if it can) ****/
132
/*** of SKINI message, setting the appropriate variables ***/
133
/*************************************************************/
135
long SKINI11 :: parseThis(char* aString)
139
char someStrings[__SK_MAX_FIELDS_][__SK_MAX_SIZE_];
140
int somePointrs[__SK_MAX_FIELDS_];
142
temp = nextChar(aString);
143
if ((which = ignore(aString[temp]))) {
144
if (which == 2) printf("// CommentLine: %s\n",aString);
149
temp = subStrings(aString,someStrings,somePointrs,remainderString);
153
strcpy(msgTypeString,someStrings[aField]);
154
while ((which < __SK_MaxMsgTypes_) &&
155
(strcmp(msgTypeString,
156
skini_msgs[which].messageString))) {
159
if (which >= __SK_MaxMsgTypes_) {
161
printf("Couldn't parse this message field: =%s\n %s\n",
162
msgTypeString,aString);
166
messageType = skini_msgs[which].type;
167
// printf("Message Token = %s type = %i\n", msgTypeString,messageType);
171
if (someStrings[0][0] == '=') {
172
deltaTime = (MY_FLOAT) atof(&someStrings[aField][1]);
173
deltaTime = -deltaTime;
176
deltaTime = (MY_FLOAT) atof(someStrings[aField]);
178
// printf("DeltaTime = %f\n",deltaTime);
181
channel = atoi(someStrings[aField]);
182
// printf("Channel = %i\n",channel);
185
if (skini_msgs[which].data2 != NOPE) {
186
if (skini_msgs[which].data2 == SK_INT) {
187
byteTwoInt = atoi(someStrings[aField]);
188
byteTwo = (MY_FLOAT) byteTwoInt;
190
else if (skini_msgs[which].data2 == SK_DBL) {
191
byteTwo = (MY_FLOAT) atof(someStrings[aField]);
192
byteTwoInt = (long) byteTwo;
194
else if (skini_msgs[which].data2 == SK_STR) {
195
temp = somePointrs[aField-1]; /* Hack Danger Here, Why -1??? */
197
while (aString[temp] != '\n') {
198
remainderString[temp2++] = aString[temp++];
200
remainderString[temp2] = 0;
203
byteTwoInt = skini_msgs[which].data2;
204
byteTwo = (MY_FLOAT) byteTwoInt;
209
if (skini_msgs[which].data3 != NOPE) {
210
if (skini_msgs[which].data3 == SK_INT) {
211
byteThreeInt = atoi(someStrings[aField]);
212
byteThree = (MY_FLOAT) byteThreeInt;
214
else if (skini_msgs[which].data3 == SK_DBL) {
215
byteThree = (MY_FLOAT) atof(someStrings[aField]);
216
byteThreeInt = (long) byteThree;
218
else if (skini_msgs[which].data3 == SK_STR) {
219
temp = somePointrs[aField-1]; /* Hack Danger Here, Why -1??? */
221
while (aString[temp] != '\n') {
222
remainderString[temp2++] = aString[temp++];
224
remainderString[temp2] = 0;
227
byteThreeInt = skini_msgs[which].data3;
228
byteThree = (MY_FLOAT) byteThreeInt;
232
byteThreeInt = byteTwoInt;
240
long SKINI11 :: nextMessage()
243
char inputString[1024];
248
if (!fgets(inputString,1024,myFile)) {
249
printf("//End of Score. Thanks for using SKINI0.9 Bye Bye!!\n");
253
else if (parseThis(inputString) == 0) {
260
long SKINI11 :: getType()
265
long SKINI11 :: getChannel()
270
MY_FLOAT SKINI11 :: getDelta()
275
MY_FLOAT SKINI11 :: getByteTwo()
280
long SKINI11 :: getByteTwoInt()
285
MY_FLOAT SKINI11 :: getByteThree()
290
long SKINI11 :: getByteThreeInt()
295
char* SKINI11 :: getRemainderString()
297
return remainderString;
300
char* SKINI11 :: getMessageTypeString()
302
return msgTypeString;
305
char sk_tempString[1024];
307
char* SKINI11 :: whatsThisType(long type)
310
sk_tempString[0] = 0;
311
for (i=0;i<__SK_MaxMsgTypes_;i++) {
312
if (type == skini_msgs[i].type) {
313
strcat(sk_tempString,skini_msgs[i].messageString);
314
strcat(sk_tempString,",");
317
return sk_tempString;
320
char* SKINI11 :: whatsThisController(long contNum)
323
sk_tempString[0] = 0;
324
for (i=0;i<__SK_MaxMsgTypes_;i++) {
325
if (skini_msgs[i].type == __SK_ControlChange_
326
&& contNum == skini_msgs[i].data2) {
327
strcat(sk_tempString,skini_msgs[i].messageString);
328
strcat(sk_tempString,",");
331
return sk_tempString;
334
/************ Test Main Program *****************/
336
void main(int argc,char *argv[])
338
SKINI11 testFile(argv[1]);
340
while(testFile.nextMessage() > 0) ;