~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to synti/stklib/SKINI11.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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. */        
8
 
/*                                        */
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  */
16
 
/*                                        */
17
 
/******************************************/
18
 
 
19
 
#include "SKINI11.h"
20
 
 
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");
25
 
  this->nextMessage();
26
 
}
27
 
 
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   */
31
 
 
32
 
SKINI11 :: ~SKINI11()
33
 
{
34
 
}
35
 
 
36
 
/*****************  SOME HANDY ROUTINES   *******************/
37
 
 
38
 
#include "SKINI11.tbl"
39
 
 
40
 
#define __SK_MAX_FIELDS_ 5
41
 
#define __SK_MAX_SIZE_ 32
42
 
 
43
 
short ignore(char aChar)
44
 
{
45
 
  short ignoreIt = 0;
46
 
  if (aChar == 0)   ignoreIt = 1;        //  Null String Termination
47
 
  if (aChar == '\n')  ignoreIt = 1;      //  Carraige Return???
48
 
  if (aChar == '/') ignoreIt = 2;        //  Comment Line
49
 
  return ignoreIt;
50
 
}
51
 
 
52
 
short delimit(char aChar)
53
 
{
54
 
  if (aChar == ' ' ||           // Space
55
 
      aChar == ','  ||          // Or Comma
56
 
      aChar == '\t')            // Or Tab
57
 
    return 1;
58
 
  else
59
 
    return 0;
60
 
}
61
 
 
62
 
short nextChar(char* aString)
63
 
{
64
 
  int i;
65
 
 
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
70
 
            return i;
71
 
  }
72
 
  return 1024;
73
 
}
74
 
 
75
 
int subStrings(char *aString, 
76
 
           char someStrings[__SK_MAX_FIELDS_][__SK_MAX_SIZE_], 
77
 
           int  somePointrs[__SK_MAX_FIELDS_],
78
 
           char *remainderString)
79
 
{
80
 
  int notDone,howMany,point,temp;
81
 
  notDone = 1;
82
 
  howMany = 0;
83
 
  point = 0;
84
 
  temp = nextChar(aString);
85
 
  if (temp >= __SK_MAX_SIZE_)    {
86
 
    notDone = 0;
87
 
    printf("Confusion here: Ignoring this line\n");
88
 
    printf("%s\n",aString);
89
 
    return howMany;
90
 
  }
91
 
  point = temp;
92
 
  somePointrs[howMany] = point;
93
 
  temp = 0;
94
 
  while (notDone)    {
95
 
    if (aString[point] == '\n') {
96
 
      notDone = 0;
97
 
    }
98
 
    else        {
99
 
      someStrings[howMany][temp++] = aString[point++];
100
 
      if (temp >= __SK_MAX_SIZE_)      {
101
 
        howMany = 0;
102
 
        return howMany;
103
 
      }
104
 
      if (delimit(aString[point]) || aString[point] == '\n') {
105
 
        someStrings[howMany][temp] = 0;
106
 
        howMany += 1;
107
 
        if (howMany < __SK_MAX_FIELDS_)       {
108
 
          temp = nextChar(&aString[point]);
109
 
          point += temp;
110
 
          somePointrs[howMany-1] = point;
111
 
          temp = 0;
112
 
        }
113
 
        else   {
114
 
          temp = 0;
115
 
          somePointrs[howMany-1] = point;
116
 
          while(aString[point] != '\n')
117
 
            remainderString[temp++] = aString[point++];
118
 
          remainderString[temp] = aString[point];
119
 
        }
120
 
      }
121
 
    }   
122
 
  }
123
 
  //     printf("Got: %i Strings:\n",howMany);
124
 
  //     for (temp=0;temp<howMany;temp++) 
125
 
  //         printf("%s\n",someStrings[temp]);
126
 
  return howMany;
127
 
         
128
 
}
129
 
 
130
 
/****************  THE ENCHILLADA !!!!  **********************/
131
 
/***   This function parses a single string (if it can)   ****/
132
 
/***   of SKINI message, setting the appropriate variables ***/
133
 
/*************************************************************/
134
 
 
135
 
long SKINI11 :: parseThis(char* aString)
136
 
{
137
 
  int which,aField;
138
 
  int temp,temp2;
139
 
  char someStrings[__SK_MAX_FIELDS_][__SK_MAX_SIZE_];
140
 
  int  somePointrs[__SK_MAX_FIELDS_];
141
 
     
142
 
  temp = nextChar(aString);
143
 
  if ((which = ignore(aString[temp]))) {
144
 
    if (which == 2) printf("// CommentLine: %s\n",aString);
145
 
    messageType = 0;
146
 
    return messageType;
147
 
  }
148
 
  else        {
149
 
    temp = subStrings(aString,someStrings,somePointrs,remainderString);
150
 
    if (temp > 0)    
151
 
      which = 0;
152
 
    aField = 0;
153
 
    strcpy(msgTypeString,someStrings[aField]);
154
 
    while ((which < __SK_MaxMsgTypes_) && 
155
 
           (strcmp(msgTypeString,
156
 
                   skini_msgs[which].messageString)))  {
157
 
            which += 1;  
158
 
    }
159
 
    if (which >= __SK_MaxMsgTypes_)  {
160
 
            messageType = -1;
161
 
            printf("Couldn't parse this message field: =%s\n %s\n",
162
 
             msgTypeString,aString);
163
 
            return messageType;
164
 
    }
165
 
    else  {
166
 
            messageType = skini_msgs[which].type;
167
 
      // printf("Message Token = %s type = %i\n", msgTypeString,messageType);
168
 
    }
169
 
    aField += 1;
170
 
 
171
 
    if (someStrings[0][0] == '=')        {
172
 
            deltaTime = (MY_FLOAT) atof(&someStrings[aField][1]);
173
 
            deltaTime = -deltaTime;
174
 
    }
175
 
    else    {
176
 
            deltaTime = (MY_FLOAT) atof(someStrings[aField]);
177
 
    }
178
 
    // printf("DeltaTime = %f\n",deltaTime);
179
 
    aField += 1;
180
 
        
181
 
    channel = atoi(someStrings[aField]);    
182
 
    // printf("Channel = %i\n",channel);
183
 
    aField += 1;
184
 
        
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;
189
 
            }
190
 
            else if (skini_msgs[which].data2 == SK_DBL)       {
191
 
        byteTwo = (MY_FLOAT) atof(someStrings[aField]);    
192
 
        byteTwoInt = (long) byteTwo;
193
 
            }
194
 
            else if (skini_msgs[which].data2 == SK_STR)       {
195
 
        temp = somePointrs[aField-1];    /*  Hack Danger Here, Why -1??? */
196
 
        temp2 = 0;
197
 
        while (aString[temp] != '\n')   { 
198
 
          remainderString[temp2++] = aString[temp++];
199
 
        }
200
 
        remainderString[temp2] = 0;
201
 
      }
202
 
            else {
203
 
        byteTwoInt = skini_msgs[which].data2;
204
 
        byteTwo = (MY_FLOAT) byteTwoInt;
205
 
        aField -= 1;
206
 
            }
207
 
            
208
 
            aField += 1;
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;
213
 
        }
214
 
        else if (skini_msgs[which].data3 == SK_DBL)   {
215
 
          byteThree = (MY_FLOAT) atof(someStrings[aField]);    
216
 
          byteThreeInt = (long) byteThree;
217
 
        }
218
 
        else if (skini_msgs[which].data3 == SK_STR)   {
219
 
          temp = somePointrs[aField-1]; /*  Hack Danger Here, Why -1??? */
220
 
          temp2 = 0;
221
 
          while (aString[temp] != '\n')   { 
222
 
            remainderString[temp2++] = aString[temp++];
223
 
          }
224
 
          remainderString[temp2] = 0;
225
 
        }
226
 
        else {
227
 
          byteThreeInt = skini_msgs[which].data3;
228
 
          byteThree = (MY_FLOAT) byteThreeInt;
229
 
        }
230
 
            }
231
 
            else {
232
 
        byteThreeInt = byteTwoInt;
233
 
        byteThree = byteTwo;
234
 
            }
235
 
    }
236
 
  }
237
 
  return messageType;
238
 
}
239
 
 
240
 
long SKINI11 ::  nextMessage()
241
 
{
242
 
  int notDone;
243
 
  char inputString[1024];
244
 
 
245
 
  notDone = 1;
246
 
  while (notDone)     {
247
 
    notDone = 0;
248
 
    if (!fgets(inputString,1024,myFile)) {    
249
 
            printf("//End of Score. Thanks for using SKINI0.9  Bye Bye!!\n");
250
 
            messageType = -1;
251
 
            return messageType;
252
 
    }
253
 
    else if (parseThis(inputString) == 0)   {
254
 
            notDone = 1;
255
 
    }
256
 
  }
257
 
  return messageType;
258
 
}
259
 
 
260
 
long SKINI11 ::  getType()
261
 
{
262
 
  return messageType;
263
 
}
264
 
 
265
 
long SKINI11 ::  getChannel()
266
 
{
267
 
  return channel;
268
 
}
269
 
 
270
 
MY_FLOAT SKINI11 :: getDelta()
271
 
{
272
 
  return deltaTime;
273
 
}
274
 
 
275
 
MY_FLOAT SKINI11 :: getByteTwo()
276
 
{
277
 
  return byteTwo;
278
 
}
279
 
 
280
 
long SKINI11 :: getByteTwoInt()
281
 
{
282
 
  return byteTwoInt;
283
 
}
284
 
 
285
 
MY_FLOAT SKINI11 :: getByteThree()
286
 
{
287
 
  return byteThree;
288
 
}
289
 
 
290
 
long SKINI11 :: getByteThreeInt()
291
 
{
292
 
  return byteThreeInt;
293
 
}
294
 
 
295
 
char* SKINI11 :: getRemainderString()
296
 
{
297
 
  return remainderString;
298
 
}
299
 
 
300
 
char* SKINI11 :: getMessageTypeString()
301
 
{
302
 
  return msgTypeString;
303
 
}
304
 
 
305
 
char sk_tempString[1024];
306
 
 
307
 
char* SKINI11 :: whatsThisType(long type)
308
 
{
309
 
  int i = 0;
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,",");
315
 
    }
316
 
  }
317
 
  return sk_tempString;            
318
 
}
319
 
 
320
 
char* SKINI11 :: whatsThisController(long contNum)
321
 
{
322
 
  int i = 0;
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,",");
329
 
    }
330
 
  }
331
 
  return sk_tempString;
332
 
}
333
 
 
334
 
/************   Test Main Program   *****************/
335
 
/*
336
 
void main(int argc,char *argv[])
337
 
{
338
 
    SKINI11 testFile(argv[1]);
339
 
    
340
 
    while(testFile.nextMessage() > 0)   ;
341
 
 
342
 
}
343
 
*/
344