Browse Source

Merge branch 'master' of klarke.webfactional.com:webapps/git/repos/libcm

master
kevin 11 years ago
parent
commit
6d317d54ca
10 changed files with 1535 additions and 104 deletions
  1. 8
    2
      Makefile.am
  2. 724
    0
      app/cmSdb.c
  3. 169
    0
      app/cmSdb.h
  4. 24
    24
      cmCsv.c
  5. 1
    1
      cmCsv.h
  6. 464
    0
      cmHashTbl.c
  7. 67
    0
      cmHashTbl.h
  8. 62
    61
      cmSyncRecd.c
  9. 11
    11
      cmSyncRecd.h
  10. 5
    5
      dsp/cmDspKr.c

+ 8
- 2
Makefile.am View File

@@ -6,8 +6,11 @@ cmSRC =
6 6
 cmHDR += src/libcm/cmErr.h src/libcm/cmCtx.h src/libcm/cmRpt.h src/libcm/cmGlobal.h src/libcm/cmComplexTypes.h src/libcm/cmFloatTypes.h src/libcm/cmPrefix.h
7 7
 cmSRC += src/libcm/cmErr.c src/libcm/cmCtx.c src/libcm/cmRpt.c src/libcm/cmGlobal.c 
8 8
 
9
-cmHDR += src/libcm/cmSerialize.h src/libcm/cmSymTbl.h src/libcm/cmFileSys.h src/libcm/cmFile.h src/libcm/cmMem.h src/libcm/cmTime.h src/libcm/cmPgmOpts.h
10
-cmSRC += src/libcm/cmSerialize.c src/libcm/cmSymTbl.c src/libcm/cmFileSys.c src/libcm/cmFile.c src/libcm/cmMem.c src/libcm/cmTime.c src/libcm/cmPgmOpts.c
9
+cmHDR += src/libcm/cmSerialize.h src/libcm/cmSymTbl.h src/libcm/cmHashTbl.h src/libcm/cmFileSys.h src/libcm/cmFile.h 
10
+cmSRC += src/libcm/cmSerialize.c src/libcm/cmSymTbl.c src/libcm/cmHashTbl.c src/libcm/cmFileSys.c src/libcm/cmFile.c 
11
+
12
+cmHDR += src/libcm/cmMem.h src/libcm/cmTime.h src/libcm/cmPgmOpts.h
13
+cmSRC += src/libcm/cmMem.c src/libcm/cmTime.c src/libcm/cmPgmOpts.c
11 14
 
12 15
 cmHDR += src/libcm/cmData.h src/libcm/cmLib.h src/libcm/cmText.h src/libcm/cmTextTemplate.h
13 16
 cmSRC += src/libcm/cmData.c src/libcm/cmLib.c src/libcm/cmText.c src/libcm/cmTextTemplate.c
@@ -71,6 +74,9 @@ cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/
71 74
 cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmScoreProc.h 
72 75
 cmSRC += src/libcm/app/cmOnset.c src/libcm/app/cmTimeLine.c src/libcm/app/cmScore.c src/libcm/app/cmScoreProc.c 
73 76
 
77
+cmHDR += src/libcm/app/cmSdb.h  
78
+cmSRC += src/libcm/app/cmSdb.c  
79
+
74 80
 cmHDR += src/libcm/app/cmPickup.h src/libcm/cmRbm.h src/libcm/cmTaskMgr.h  src/libcm/cmSyncRecd.h
75 81
 cmSRC += src/libcm/app/cmPickup.c src/libcm/cmRbm.c src/libcm/cmTaskMgr.c  src/libcm/cmSyncRecd.c
76 82
 

+ 724
- 0
app/cmSdb.c View File

@@ -0,0 +1,724 @@
1
+#include "cmGlobal.h"
2
+#include "cmRpt.h"
3
+#include "cmErr.h"
4
+#include "cmCtx.h"
5
+#include "cmMem.h"
6
+#include "cmMallocDebug.h"
7
+#include "cmLinkedHeap.h"
8
+#include "cmLex.h"
9
+#include "cmCsv.h"
10
+#include "cmSdb.h"
11
+#include "cmText.h"
12
+
13
+typedef enum
14
+{
15
+  kUuidColIdx,
16
+  kBaseUuidColIdx,
17
+  kChIdxColIdx,
18
+  kObiColIdx,
19
+  kIbiColIdx,
20
+  kIeiColIdx,
21
+  kOeiColIdx,
22
+  kSrcColIdx,
23
+  kMidiColIdx,
24
+  kInstrColIdx,
25
+  kSrateColIdx,
26
+  kChCntColIdx,
27
+  kNotesColIdx,
28
+  kAfnColIdx,
29
+  kInvalidColIdx
30
+} cmSdbColIdx_t;
31
+
32
+struct cmSdb_str;
33
+
34
+typedef struct cmSdbRspBlk_str
35
+{
36
+  unsigned*               indexV;  // indexV[ cmSdb_t.blkIdxAllocCnt ]
37
+  unsigned                cnt;     // count of indexes used
38
+  struct cmSdbRspBlk_str* link;    // cmSdbRsp_t.blocks link
39
+} cmSdbRspBlk_t;
40
+
41
+typedef struct cmSdbRsp_str
42
+{
43
+  struct cmSdb_str*    p;       // 
44
+  cmSdbRspBlk_t*       blocks;  // first block ptr
45
+  cmSdbRspBlk_t*       ebp;     // end block ptr
46
+  unsigned             cnt;     // total count of indexes
47
+  struct cmSdbRsp_str* link;    // cmSdb_t.responses link
48
+} cmSdbRsp_t;
49
+
50
+typedef struct cmSdb_str
51
+{
52
+  cmCtx_t              ctx;
53
+  cmLHeapH_t           lhH;
54
+  cmCsvH_t             csvH;
55
+  cmSdbEvent_t*        eV;
56
+  unsigned             eN;
57
+  unsigned             blkIdxAllocCnt;
58
+  struct cmSdbRsp_str* responses;
59
+} cmSdb_t;
60
+
61
+cmSdbH_t         cmSdbNullHandle         = cmSTATIC_NULL_HANDLE;
62
+cmSdbResponseH_t cmSdbResponseNullHandle = cmSTATIC_NULL_HANDLE;
63
+
64
+cmSdb_t* _cmSdbHandleToPtr( cmSdbH_t h )
65
+{
66
+  cmSdb_t* p = (cmSdb_t*)h.h;
67
+  assert( p != NULL );
68
+  return p;
69
+}
70
+
71
+cmSdbRsp_t* _cmSdbRspHandleToPtr( cmSdbResponseH_t h )
72
+{
73
+  cmSdbRsp_t* p = (cmSdbRsp_t*)h.h;
74
+  assert( p != NULL );
75
+  return p;
76
+}
77
+
78
+void _cmSdbRspBlkFree( cmSdb_t* p, cmSdbRspBlk_t* bp )
79
+{
80
+  cmLhFree(p->lhH, bp->indexV);
81
+  cmLhFree(p->lhH, bp);
82
+}
83
+
84
+
85
+cmSdbRspBlk_t*  _cmSdbRspBlkUnlink( cmSdbRsp_t* rp, cmSdbRspBlk_t* bp )
86
+{
87
+  cmSdbRspBlk_t* dp = rp->blocks;
88
+  cmSdbRspBlk_t* pp = NULL;
89
+  for(; dp!=NULL; dp=dp->link)
90
+  {
91
+    if( dp == bp )
92
+    {
93
+      if( pp == NULL )
94
+        rp->blocks = dp->link;
95
+      else
96
+        pp->link = dp->link;
97
+
98
+      return bp;
99
+    }
100
+
101
+    pp = dp;
102
+  }
103
+
104
+  assert(0);
105
+  return NULL;
106
+}
107
+
108
+void _cmSdbRspInsertIndex( cmSdb_t* p, cmSdbRsp_t* rp, unsigned evtIndex )
109
+{
110
+
111
+  if( rp->ebp == NULL || rp->ebp->cnt == p->blkIdxAllocCnt )
112
+  {
113
+    cmSdbRspBlk_t* bp = cmLhAllocZ(p->lhH,cmSdbRspBlk_t,1);
114
+    bp->indexV = cmLhAllocZ(p->lhH,unsigned,p->blkIdxAllocCnt);
115
+
116
+    if( rp->ebp != NULL )
117
+      rp->ebp->link = bp;
118
+
119
+    if( rp->blocks == NULL )
120
+      rp->blocks = bp;
121
+
122
+    rp->ebp  = bp;
123
+
124
+  }
125
+
126
+  assert( rp->ebp!=NULL && rp->ebp->cnt < p->blkIdxAllocCnt );
127
+
128
+  rp->ebp->indexV[ rp->ebp->cnt++ ] = evtIndex;
129
+  rp->cnt += 1;
130
+}
131
+
132
+void _cmSdbRspRelease( cmSdbRsp_t* rp )
133
+{
134
+  while( rp->blocks != NULL )
135
+  {
136
+    cmSdbRspBlk_t* np = rp->blocks->link;
137
+    cmSdbRspBlk_t* bp;
138
+
139
+    if((bp = _cmSdbRspBlkUnlink(rp,rp->blocks)) != NULL )
140
+      _cmSdbRspBlkFree(rp->p,bp);
141
+    
142
+    rp->blocks = np;
143
+  }
144
+
145
+  cmLhFree(rp->p->lhH,rp);
146
+}
147
+
148
+cmSdbRsp_t*  _cmSdbRspUnlink( cmSdbRsp_t* rp )
149
+{
150
+  cmSdb_t*    p  = rp->p;
151
+  cmSdbRsp_t* dp = p->responses;
152
+  cmSdbRsp_t* pp = NULL;
153
+
154
+  for(; dp!=NULL; dp=dp->link)
155
+  {
156
+    if( dp == rp )
157
+    {
158
+      if( pp == NULL )
159
+        p->responses = dp->link;
160
+      else
161
+        pp->link = dp->link;
162
+
163
+      return rp;
164
+    }
165
+
166
+    pp = dp;
167
+  }
168
+
169
+  assert( 0 );
170
+
171
+  return NULL;
172
+}
173
+
174
+
175
+void _cmSdbRspFree( cmSdbRsp_t* rp )
176
+{
177
+  _cmSdbRspUnlink(rp);
178
+  _cmSdbRspRelease(rp);
179
+}
180
+
181
+cmSdbRsp_t* _cmSdbRspAlloc( cmSdb_t* p, cmSdbResponseH_t* rhp )
182
+{
183
+  if( cmSdbResponseFree(rhp) != kOkSdbRC )
184
+    return NULL;
185
+
186
+  cmSdbRsp_t* rp = cmLhAllocZ(p->lhH,cmSdbRsp_t,1);
187
+  rp->p = p;
188
+  rp->link = p->responses;
189
+  p->responses = rp;
190
+
191
+  rhp->h = rp;
192
+
193
+  return rp;
194
+}
195
+
196
+cmSdbRC_t _cmSdbDestroy( cmSdb_t* p )
197
+{
198
+  cmSdbRC_t rc = kOkSdbRC;
199
+
200
+  if( cmCsvFinalize(&p->csvH) != kOkCsvRC )
201
+    rc = cmErrMsg(&p->ctx.err,kCsvFailSdbRC,"CSV file finalize failed.");
202
+
203
+  while( p->responses != NULL )
204
+    _cmSdbRspRelease(p->responses);
205
+
206
+  cmLHeapDestroy(&p->lhH);
207
+  cmMemFree(p);
208
+  return rc;
209
+}
210
+
211
+cmSdbRC_t cmSdbCreate( cmCtx_t* ctx,  cmSdbH_t* hp, const cmChar_t* audioDir, const cmChar_t* csvFn )
212
+{
213
+  cmSdbRC_t rc;
214
+  if((rc = cmSdbDestroy(hp)) != kOkSdbRC )
215
+    return rc;
216
+
217
+  cmSdb_t* p = cmMemAllocZ(cmSdb_t,1);
218
+  p->ctx = *ctx;
219
+  p->blkIdxAllocCnt  = 1024;
220
+
221
+  cmErrSetup(&p->ctx.err,&ctx->rpt,"sdb");
222
+
223
+  if( cmLHeapIsValid( p->lhH = cmLHeapCreate(8192,ctx)) == false )
224
+  {
225
+    rc = cmErrMsg(&p->ctx.err,kLHeapFailSdbRC,"Linked heap mgr. allocation failed.");
226
+    goto errLabel;
227
+  }
228
+
229
+  hp->h = p;
230
+
231
+  if( csvFn != NULL )
232
+    if((rc = cmSdbLoad(*hp,csvFn)) != kOkSdbRC )
233
+      goto errLabel;
234
+
235
+ errLabel:
236
+  if( rc != kOkSdbRC )
237
+    _cmSdbDestroy(p);
238
+
239
+  return rc;
240
+}
241
+
242
+cmSdbRC_t cmSdbDestroy( cmSdbH_t* hp )
243
+{
244
+  cmSdbRC_t rc = kOkSdbRC;
245
+
246
+  if( hp==NULL || cmSdbIsValid(*hp)==false )
247
+    return rc;
248
+
249
+  cmSdb_t* p = _cmSdbHandleToPtr(*hp);
250
+
251
+  if((rc = _cmSdbDestroy(p)) != kOkSdbRC )
252
+    return rc;
253
+
254
+  hp->h = NULL;
255
+
256
+  return rc;
257
+}
258
+
259
+bool     cmSdbIsValid( cmSdbH_t h )
260
+{ return h.h != NULL; }
261
+
262
+
263
+cmSdbRC_t _cmSdbSyntaxError(cmSdb_t* p, const cmChar_t* csvFn, unsigned rowIdx, unsigned colIdx, const cmChar_t* colLabel )
264
+{
265
+  return cmErrMsg(&p->ctx.err,kSyntaxErrSdbRC,"A syntax error was found at row %i col %i (label:%s) in '%s'.",rowIdx+1,colIdx+1,cmStringNullGuard(colLabel),cmStringNullGuard(csvFn));
266
+}
267
+
268
+
269
+cmSdbRC_t cmSdbLoad( cmSdbH_t h, const cmChar_t* csvFn )
270
+{
271
+  cmSdbRC_t rc   = kOkSdbRC;
272
+  unsigned  i;
273
+
274
+  cmSdb_t* p = _cmSdbHandleToPtr(h);
275
+
276
+  if( cmCsvInitializeFromFile(&p->csvH, csvFn, 0, &p->ctx ) != kOkCsvRC )
277
+  {
278
+    rc = cmErrMsg(&p->ctx.err,kCsvFailSdbRC,"CSV file load fail on '%s'.",cmStringNullGuard(csvFn));
279
+    goto errLabel;
280
+  }
281
+
282
+  p->eN = cmCsvRowCount(p->csvH)-1;
283
+  
284
+  // release all the memory held by the linked heap
285
+  cmLHeapClear(p->lhH,true);
286
+
287
+  p->eV = cmLhAllocZ(p->lhH,cmSdbEvent_t,p->eN);
288
+
289
+
290
+  for(i=0; rc==kOkSdbRC && i<p->eN; ++i)
291
+  {
292
+    unsigned rowIdx = i+1;
293
+
294
+    if((p->eV[i].uuid = cmCsvCellUInt(p->csvH,rowIdx,kUuidColIdx)) == UINT_MAX )
295
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kUuidColIdx,"uuid");
296
+
297
+    if((p->eV[i].baseUuid = cmCsvCellUInt(p->csvH,rowIdx,kBaseUuidColIdx)) == UINT_MAX )
298
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kBaseUuidColIdx,"baseUuid");
299
+
300
+    if((p->eV[i].chIdx = cmCsvCellUInt(p->csvH,rowIdx,kChIdxColIdx)) == UINT_MAX )
301
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kChIdxColIdx,"chIdx");
302
+    else
303
+      p->eV[i].chIdx -= 1; // CSV channel index is 1 based
304
+
305
+    if((p->eV[i].obi = cmCsvCellUInt(p->csvH,rowIdx,kObiColIdx)) == UINT_MAX )
306
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kObiColIdx,"obi");
307
+    else
308
+      p->eV[i].obi -= 1;
309
+
310
+    if((p->eV[i].ibi = cmCsvCellUInt(p->csvH,rowIdx,kIbiColIdx)) == UINT_MAX )
311
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kIbiColIdx,"ibi");
312
+    else
313
+      p->eV[i].ibi -= 1;
314
+
315
+    if((p->eV[i].iei = cmCsvCellUInt(p->csvH,rowIdx,kIeiColIdx)) == UINT_MAX )
316
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kIeiColIdx,"obi");
317
+    else
318
+      p->eV[i].iei -= 1;
319
+
320
+    if((p->eV[i].oei = cmCsvCellUInt(p->csvH,rowIdx,kOeiColIdx)) == UINT_MAX )
321
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kOeiColIdx,"ibi");
322
+    else
323
+      p->eV[i].oei -= 1;
324
+
325
+    if((p->eV[i].src = cmCsvCellText(p->csvH,rowIdx,kSrcColIdx)) == NULL )
326
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kSrcColIdx,"src");
327
+
328
+    if((p->eV[i].midi = cmCsvCellInt(p->csvH,rowIdx,kMidiColIdx)) == INT_MAX )
329
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kMidiColIdx,"midi");
330
+
331
+    if((p->eV[i].instr = cmCsvCellText(p->csvH,rowIdx,kInstrColIdx)) == NULL )
332
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kInstrColIdx,"instr");
333
+
334
+    if((p->eV[i].srate = cmCsvCellUInt(p->csvH,rowIdx,kSrateColIdx)) == UINT_MAX )
335
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kSrateColIdx,"srate");
336
+
337
+    if((p->eV[i].chCnt = cmCsvCellUInt(p->csvH,rowIdx,kChCntColIdx)) == UINT_MAX )
338
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kChCntColIdx,"chCnt");
339
+
340
+     
341
+    cmCsvCell_t* c;
342
+    if((c = cmCsvCellPtr(p->csvH,rowIdx,kNotesColIdx)) == NULL )
343
+    {
344
+      rc = cmErrMsg(&p->ctx.err,kSyntaxErrSdbRC,"Syntax Error: No 'notes' or 'audio file name' field for row %i in '%s'.",rowIdx+1,cmStringNullGuard(csvFn));
345
+      goto errLabel;
346
+    }
347
+    
348
+    // count the number of 'notes'
349
+    unsigned nn = 0;
350
+    for(; c->rowPtr != NULL; c=c->rowPtr)
351
+      ++nn;
352
+
353
+    if( nn > 0 )
354
+    {
355
+      unsigned k  = 0;
356
+
357
+      // allocate the 'notes' ptr array - the last entry is set to NULL.
358
+      p->eV[i].notesV = cmLhAllocZ(p->lhH,const cmChar_t*,nn+1);
359
+
360
+      // read each note
361
+      for(c=cmCsvCellPtr(p->csvH,rowIdx,kNotesColIdx); c!=NULL&&c->rowPtr!=NULL; c=c->rowPtr,++k)
362
+        if(( p->eV[i].notesV[k] = cmCsvCellText(p->csvH,rowIdx,kNotesColIdx+k)) == NULL )
363
+          rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kNotesColIdx+k,"notes");
364
+
365
+      assert(k==nn);
366
+    }
367
+
368
+    // read the audio file name
369
+    if((p->eV[i].afn = cmCsvCellText(p->csvH,rowIdx,kNotesColIdx+nn)) == NULL )
370
+      rc = _cmSdbSyntaxError(p,csvFn,rowIdx,kNotesColIdx+nn,"afn");
371
+
372
+  }
373
+
374
+ errLabel:
375
+
376
+  return rc;
377
+
378
+}
379
+
380
+// Compare 'label' to every string in tV[i] and return true if any comparision is a match.
381
+// If 'subFlV[i]' is set then 'label' must only contain tV[i] as a substring to match.
382
+// If 'negFlV[i]' is set then return true if any comparision is a mismatch.
383
+bool _cmSdbSelectText( const cmSdbEvent_t* r, const cmChar_t** tV, const bool* subFlV, const bool* negFlV, const cmChar_t* label )
384
+{
385
+  unsigned        i;
386
+
387
+  if( label == NULL )
388
+    return false;
389
+
390
+  if( tV == NULL )
391
+    return true;
392
+
393
+  for(i=0; tV[i]!=NULL; ++i)
394
+  {
395
+    bool matchFl = false;
396
+    if( subFlV[i] )
397
+      matchFl = strstr(label,tV[i]) != NULL;
398
+    else
399
+      matchFl = strcmp(tV[i],label)==0;
400
+
401
+    if( negFlV[i] )
402
+      matchFl = !matchFl;
403
+
404
+    if(matchFl)
405
+      return true;
406
+  }
407
+
408
+  return false;
409
+}
410
+
411
+unsigned _cmSdbStrVectCnt( const cmChar_t** v )
412
+{
413
+  unsigned n = 0;
414
+  unsigned i = 0;
415
+
416
+  if( v == NULL )
417
+    return 0;
418
+
419
+  for(i=0; v[i]!=NULL; ++i)
420
+    ++n;
421
+  return n;
422
+}
423
+
424
+void _cmSdbStrVectFlags( const cmChar_t** v, bool* sV, bool* nV )
425
+{
426
+  unsigned i = 0;
427
+  if( v == NULL )
428
+    return;
429
+
430
+  for(i=0; v[i]!=NULL; ++i)
431
+  {
432
+    nV[i] = false;
433
+    sV[i] = false;
434
+
435
+    if( strncmp(v[i],"*!",2)==0 || strncmp(v[i],"!*",2)==0)
436
+    {
437
+      sV[i] = nV[i] = true;
438
+      v[i] += 2;
439
+    }
440
+    else
441
+    {
442
+      if( strncmp(v[i],"!",1)==0 )
443
+      {
444
+        nV[i] = true;
445
+        v[i] += 1;
446
+      }
447
+
448
+      if( strncmp(v[i],"*",1)==0 )
449
+      {
450
+        sV[i] = true;
451
+        v[i] += 1;
452
+      }
453
+    }
454
+
455
+    
456
+  }
457
+}
458
+
459
+cmSdbRC_t cmSdbSelect( 
460
+    cmSdbH_t         h,
461
+    double           srate,
462
+    const cmChar_t** instrV,
463
+    const cmChar_t** srcV,
464
+    const cmChar_t** notesV,
465
+    double           minDurSec,
466
+    double           maxDurSec,
467
+    unsigned         minChCnt,
468
+    cmSdbResponseH_t* rhp )
469
+{
470
+  cmSdbRC_t rc = kOkSdbRC;
471
+  cmSdb_t*  p  = _cmSdbHandleToPtr(h);
472
+  unsigned  i;
473
+
474
+  cmSdbRsp_t* rp   = _cmSdbRspAlloc(p,rhp);
475
+
476
+  // get the length of each string vector
477
+  unsigned    srcN = _cmSdbStrVectCnt(srcV);
478
+  unsigned    insN = _cmSdbStrVectCnt(instrV);
479
+  unsigned    notN = _cmSdbStrVectCnt(notesV);
480
+
481
+  // allocate flag vectors
482
+  bool srcSubFlV[ srcN ];
483
+  bool srcNegFlV[ srcN ];
484
+  bool insSubFlV[ insN ];
485
+  bool insNegFlV[ insN ];
486
+  bool notSubFlV[ notN ];
487
+  bool notNegFlV[ notN ];
488
+  
489
+  // fill the flag vectors
490
+  _cmSdbStrVectFlags(srcV,  srcSubFlV,srcNegFlV);
491
+  _cmSdbStrVectFlags(instrV,insSubFlV,insNegFlV);
492
+  _cmSdbStrVectFlags(notesV,notSubFlV,notNegFlV);
493
+
494
+  for(i=0; i<p->eN; ++i)
495
+  {
496
+    const cmSdbEvent_t* r      = p->eV + i;
497
+    double              durSec = (double)r->srate * (r->oei - r->obi);
498
+    unsigned            j;
499
+
500
+    if( srate!=0 && srate!=r->srate )
501
+      continue;
502
+
503
+    if( durSec < minDurSec || (maxDurSec!=0 && maxDurSec < durSec) )
504
+      continue;
505
+
506
+    if( minChCnt!=0 && r->chCnt > minChCnt )
507
+      continue;
508
+
509
+    if( !_cmSdbSelectText(r,srcV,srcSubFlV,srcNegFlV,r->src) )
510
+      continue;
511
+    
512
+    if( !_cmSdbSelectText(r,instrV,insSubFlV,insNegFlV,r->instr) )
513
+      continue;
514
+
515
+    if( r->notesV != NULL )
516
+      for(j=0; r->notesV[j]!=NULL; ++j)
517
+        if( _cmSdbSelectText(r,notesV,notSubFlV,notNegFlV,r->notesV[j]) == true )
518
+          break;
519
+
520
+    if( r->notesV[j]==NULL )
521
+      continue;
522
+
523
+    
524
+    _cmSdbRspInsertIndex(p,rp,i);
525
+  }
526
+  
527
+  return rc;
528
+}
529
+
530
+cmSdbRC_t cmSdbSelectChPairs( cmSdbH_t h, const cmSdbEvent_t* ep, cmSdbResponseH_t* rhp )
531
+{
532
+  cmSdbRC_t   rc = kOkSdbRC;
533
+  cmSdb_t*    p  = _cmSdbHandleToPtr(h);
534
+  cmSdbRsp_t* rp = _cmSdbRspAlloc(p,rhp);
535
+  unsigned    i;
536
+
537
+  // for each channel of this event
538
+  for(i=0; i<ep->chCnt; ++i)
539
+  {
540
+     // if i channel is not the known events channel
541
+    if( ep->chIdx != i )
542
+    {
543
+      unsigned j;
544
+
545
+      // examine each record
546
+      for(j=0; j<p->eN; ++j)
547
+        // if eV[j] shares a baseUuid but is on a different channel than *ep  ...
548
+        if( p->eV[j].baseUuid == ep->baseUuid && p->eV[j].chIdx==i )
549
+        {
550
+          // .. then a match has been found
551
+          _cmSdbRspInsertIndex(p,rp,j);
552
+          break;
553
+        }
554
+
555
+      if( j== p->eN )
556
+      {
557
+        rc = cmErrMsg(&p->ctx.err,kChPairNotFoundSdbRC,"The channel pair associated with 'id:%i instr:%s src:%s ch index:%i could not be found.",ep->uuid,cmStringNullGuard(ep->instr),cmStringNullGuard(ep->src),ep->chIdx);
558
+      }
559
+    }
560
+  }
561
+
562
+  return rc;
563
+
564
+}
565
+
566
+
567
+unsigned cmSdbResponseCount( cmSdbResponseH_t rh )
568
+{
569
+  cmSdbRsp_t* rp = _cmSdbRspHandleToPtr(rh);
570
+  return rp->cnt;
571
+}
572
+
573
+const cmSdbEvent_t* cmSdbResponseEvent( cmSdbResponseH_t rh, unsigned index )
574
+{
575
+  cmSdbRsp_t* rp = _cmSdbRspHandleToPtr(rh);
576
+
577
+  if( index >= rp->cnt )
578
+    return NULL;
579
+
580
+  cmSdbRspBlk_t* bp = rp->blocks;
581
+  unsigned i;
582
+  for(i=0; bp!=NULL; i+=bp->cnt,bp=bp->link)
583
+    if( i <= index && index < (i + bp->cnt) )
584
+      return rp->p->eV + bp->indexV[index-i];
585
+  
586
+  cmErrMsg(&rp->p->ctx.err,kInvalidRspIdxSdbRC,"Invalid query response index=%i.",index);
587
+  return NULL;
588
+}
589
+
590
+bool cmSdbResponseIsValid( cmSdbResponseH_t rh )
591
+{ return rh.h != NULL; }
592
+
593
+cmSdbRC_t cmSdbResponseFree( cmSdbResponseH_t* rhp )
594
+{
595
+  cmSdbRC_t rc = kOkSdbRC;
596
+
597
+  if( rhp == NULL || cmSdbResponseIsValid(*rhp)==false )
598
+    return rc;
599
+
600
+  cmSdbRsp_t* rp = _cmSdbRspHandleToPtr(*rhp);
601
+
602
+  _cmSdbRspFree(rp);
603
+
604
+  rhp->h = NULL;
605
+
606
+  return rc;
607
+}
608
+
609
+void   cmSdbResponsePrint( cmSdbResponseH_t rh, cmRpt_t* rpt )
610
+{
611
+  unsigned n = cmSdbResponseCount(rh);
612
+  unsigned i;
613
+  for(i=0; i<n; ++i)
614
+  {
615
+    const cmSdbEvent_t* e = cmSdbResponseEvent(rh,i);
616
+    if( e != NULL )
617
+      cmRptPrintf(rpt,"%6i %6i %2i %12i %12i %12i %12i %2i %6i %2i %10s %15s\n",
618
+        e->uuid,e->baseUuid,e->chIdx,e->obi,e->ibi,e->iei,e->oei,e->midi,e->srate,e->chCnt,
619
+        cmStringNullGuard(e->src), cmStringNullGuard(e->instr) );
620
+  }
621
+}
622
+
623
+cmSdbRC_t  cmSdbSyncChPairs( cmSdbH_t h )
624
+{
625
+  cmSdbRC_t rc = kOkSdbRC;
626
+  cmSdb_t* p = _cmSdbHandleToPtr(h);
627
+  unsigned i;
628
+  // for each multi-channel event
629
+  for(i=0; i<p->eN; ++i)
630
+    if(p->eV[i].chCnt > 1 )
631
+    {
632
+      const cmSdbEvent_t* ep = p->eV + i;
633
+      unsigned iV[ep->chCnt];
634
+      unsigned j,k;
635
+
636
+      // load iV[] with the event indexes of the channel pairs
637
+      for(j=0,k=0; j<p->eN && k<ep->chCnt; ++j)
638
+        if( p->eV[j].baseUuid == ep->baseUuid )
639
+        {
640
+          assert( p->eV[j].chIdx < ep->chCnt );
641
+
642
+          iV[p->eV[j].chIdx] = j;
643
+          ++k;
644
+        }
645
+
646
+      if( k != ep->chCnt )
647
+        rc = cmErrMsg(&p->ctx.err,kChPairNotFoundSdbRC,"The channel pair associated with 'id:%i instr:%s src:%s ch index:%i could not be found.",ep->uuid,cmStringNullGuard(ep->instr),cmStringNullGuard(ep->src),ep->chIdx);
648
+      else
649
+      {
650
+        unsigned mobi = ep->obi;
651
+        unsigned mibi = ep->ibi;
652
+        unsigned miei = ep->iei;
653
+        unsigned moei = ep->oei;
654
+
655
+        // get the min onsets and max offsets
656
+        for(j=0; j<ep->chCnt; ++j)
657
+        {
658
+          mobi = cmMin(mobi,p->eV[ iV[j] ].obi);
659
+          mibi = cmMin(mibi,p->eV[ iV[j] ].ibi);
660
+          miei = cmMax(miei,p->eV[ iV[j] ].iei);
661
+          moei = cmMax(moei,p->eV[ iV[j] ].oei);
662
+        }
663
+
664
+        // set the onsets to the min onset / offsets to max offsets 
665
+        for(j=0; j<ep->chCnt; ++j)
666
+        {
667
+          p->eV[ iV[j] ].obi = mobi;
668
+          p->eV[ iV[j] ].ibi = mibi;
669
+          p->eV[ iV[j] ].iei = miei;
670
+          p->eV[ iV[j] ].oei = moei;
671
+        }
672
+      }
673
+    }
674
+ 
675
+  return rc;
676
+}
677
+
678
+
679
+cmSdbRC_t cmSdbTest( cmCtx_t* ctx )
680
+{
681
+  cmSdbRC_t       rc       = kOkSdbRC;
682
+  cmSdbH_t        h        = cmSdbNullHandle;
683
+  const cmChar_t* audioDir = "/home/kevin/media/audio";
684
+  const cmChar_t* csvFn    = "/home/kevin/temp/sdb0/sdb_master.csv";
685
+  cmErr_t         err;
686
+
687
+  cmErrSetup(&err,&ctx->rpt,"sdb test");
688
+
689
+  if((rc = cmSdbCreate(ctx,  &h, audioDir, csvFn )) != kOkSdbRC )
690
+  {
691
+    rc = cmErrMsg(&err,rc,"sdb create failed.");
692
+    goto errLabel;
693
+  }
694
+
695
+  if((rc = cmSdbSyncChPairs(h)) != kOkSdbRC )
696
+  {
697
+    rc = cmErrMsg(&err,rc,"sdb sync-ch-pairs failed.");
698
+    goto errLabel;
699
+  }
700
+
701
+  if(0)
702
+  {
703
+    cmSdbResponseH_t rH = cmSdbResponseNullHandle;
704
+
705
+    const cmChar_t* instrV[] = { "*viol", NULL };
706
+
707
+    if((rc = cmSdbSelect(h,0,instrV,NULL,NULL,0,0,0,&rH)) != kOkSdbRC )
708
+    {
709
+      rc = cmErrMsg(&err,rc,"sdb query failed.");
710
+      goto errLabel;
711
+    }
712
+
713
+
714
+    cmSdbResponsePrint(rH,&ctx->rpt);
715
+
716
+    cmSdbResponseFree(&rH);
717
+  }
718
+
719
+ errLabel:
720
+  if((rc = cmSdbDestroy(&h)) != kOkSdbRC )
721
+    rc = cmErrMsg(&err,rc,"sdb destroy failed.");
722
+
723
+  return rc;
724
+}

+ 169
- 0
app/cmSdb.h View File

@@ -0,0 +1,169 @@
1
+#ifndef cmSdb_h
2
+#define cmSdb_h
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+  /*
9
+    The data for this object is stored in a CSV file with the following column syntax.
10
+    
11
+    Column Name     Type  Description
12
+    ------ -------- ----- -----------------------------------------------------
13
+       1   uuid     uint  Unique integer identifier for this event
14
+       2   baseUuid uint  uuid of channel 0 for this event
15
+       3   chIdx    uint  Channel index (stereo: 1=left 2=right)
16
+       4   obi      uint  Outer onset sample index into 'afn'.
17
+       5   ibi      uint  Inner onset sample index into 'afn'.
18
+       6   iei      uint  Inner offset sample index into 'afn'.
19
+       7   oei      uint  Outer offset sample index into 'afn'.
20
+       8   src      text  Source label for this event (e.g. mcgill, ui )       
21
+       9   midi     uint  MIDI pitch number or -1 if the sample is not pitched
22
+      10   instr    text  Instrument label.
23
+      11   srate    uint  Sample rate of audio file reference by 'afn'.
24
+      10   chCnt    uint  Count of channels for this event.
25
+      *    notes    text  0 or more free form double quoted text notes.
26
+      *    afn      text  File name of the audio file this event occurs in.
27
+
28
+     Notes:
29
+     #. Each event represents a mono audio signal.  If the event is drawn
30
+        from a multi-channel audio file then the 'chCnt' field will be
31
+        greater than one.  If 'chCnt' is greater than one then the associated
32
+        samples can be found by collecting all events that share the
33
+        same 'baseUuid'.
34
+
35
+     #. There may be zero or more columns of 'notes'. If there are no
36
+        notes then the 'afn' field is in column 11.
37
+
38
+     #. The index values (chIdx,obi,ibi,iei,oei) as stored in the CSV file
39
+         are 1 based. These values are decreased by 1 by the cmSdb CSV reader
40
+        so that their cmSdb value is zero based.  See cmSdbLoad().
41
+ 
42
+   */
43
+
44
+  enum
45
+  {
46
+    kOkSdbRC,
47
+    kLHeapFailSdbRC,
48
+    kCsvFailSdbRC,
49
+    kSyntaxErrSdbRC,
50
+    kInvalidRspIdxSdbRC,
51
+    kChPairNotFoundSdbRC
52
+  };
53
+
54
+  typedef cmHandle_t cmSdbH_t;
55
+  typedef cmHandle_t cmSdbResponseH_t;
56
+
57
+  typedef cmRC_t     cmSdbRC_t;
58
+  extern cmSdbH_t cmSdbNullHandle_t;
59
+  extern cmSdbResponseH_t cmSdbResponseNullHandle_t;
60
+  
61
+  typedef struct
62
+  {
63
+    unsigned         uuid;     // unique id of this sample
64
+    unsigned         baseUuid; // uuid of channel 0
65
+    unsigned         chIdx;   // channel index (0=left,1=right)
66
+    unsigned         obi;     // outer onset
67
+    unsigned         ibi;     // inner onset
68
+    unsigned         iei;     // inner offset
69
+    unsigned         oei;     // outer offset
70
+    unsigned         midi;    // MIDI pitch or -1 for unpitched instruments
71
+    unsigned         srate;   // sample rate
72
+    unsigned         chCnt;   // source channel count
73
+    const cmChar_t*  src;     // sample source (e.g. mcgill, ui )
74
+    const cmChar_t*  instr;   // instrument label
75
+    const cmChar_t*  afn;     // audio file name 
76
+    const cmChar_t** notesV;  // NULL terminated list of terms describing the event.
77
+  } cmSdbEvent_t;
78
+
79
+
80
+  cmSdbRC_t cmSdbCreate( cmCtx_t* ctx,  cmSdbH_t* hp, const cmChar_t* audioDir, const cmChar_t* csvFn );
81
+  cmSdbRC_t cmSdbDestroy( cmSdbH_t* hp );
82
+
83
+  bool      cmSdbIsValid( cmSdbH_t h );
84
+
85
+  cmSdbRC_t cmSdbLoad( cmSdbH_t h, const cmChar_t* csvFn );
86
+
87
+  // Select a set of events from the sample database.
88
+  //
89
+  // The possible selection criteria are:
90
+  //   sample rate
91
+  //   instrument label
92
+  //   source label
93
+  //   notes labels
94
+  //   event duration
95
+  //
96
+  // In order to match an event all active criteria
97
+  // must match.  In other words the match implies a
98
+  // logical AND operation on each match criteria.
99
+  // Each of the criteria can be made inactive by 
100
+  // specifying particular key values.
101
+  //   sample rate      = 0
102
+  //   instrument label = NULL
103
+  //   source label     = NULL
104
+  //   notes labels     = NULL
105
+  //   event duration   = minDurSec=0 maxDurSec=0
106
+  //
107
+  // For the text array arguments (instrV,srcV,notesV) 
108
+  // each element of the array is a key which is attempts to
109
+  // match the associated field in each event record.
110
+  // By default a match is triggered if the key text is identical to the 
111
+  // event field text.  The match algorithm can be modified by
112
+  // specifying a '*' as the first character in the key field.
113
+  // In this case a the key need only be a substring of the
114
+  // event field to trigger a match.  For example "*viol" 
115
+  // will return events that match both "violin" and "viola".
116
+  // 
117
+  // To specify a mismatch as a successful match 
118
+  // (i.e. to return events which do not match the key text) 
119
+  // prefix the key with a '!' character. 
120
+  // 
121
+  // Note that it is legal to specify both '!' and '*'. In
122
+  // which case a match will be triggered by fields where
123
+  // the key text is not a substring of the field text.
124
+  //
125
+  // All query response handles returned from this function
126
+  // should eventualy be released by the application via a call to
127
+  // cmSdbResponseFree().  
128
+  cmSdbRC_t cmSdbSelect( 
129
+    cmSdbH_t         h,
130
+    double           srate,      // event sample rate or 0 to ignore
131
+    const cmChar_t** instrV,     // array of instrument labels to match
132
+    const cmChar_t** srcV,       // array of 'src' labels to match
133
+    const cmChar_t** notesV,     // array of text 'notes' to match
134
+    double           minDurSec,  // min event duration
135
+    double           maxDurSec,  // max event duration or 0 to ignore
136
+    unsigned         minChCnt,   // min ch cnt or 0 to ignore
137
+    cmSdbResponseH_t* rhp );
138
+
139
+  // Given the event 'ep' locate the channel pairs associated with that event.
140
+  // The response handle returned from this function must be released
141
+  // by a call to cmSdbResponseFree().
142
+  cmSdbRC_t cmSdbSelectChPairs( cmSdbH_t h, const cmSdbEvent_t* ep, cmSdbResponseH_t* rhp );
143
+  
144
+  // Return the count of events in a query response.
145
+  unsigned            cmSdbResponseCount(   cmSdbResponseH_t  rh );
146
+
147
+  // Return the event at 'index' in from a query response.
148
+  // Legal 'index' range: 0<=index<=cmSdbResponseCount().
149
+  const cmSdbEvent_t* cmSdbResponseEvent(   cmSdbResponseH_t  rh, unsigned index );
150
+
151
+  // Return true if the 'rh' is a non-NULL query response handle.
152
+  bool                cmSdbResponseIsValid( cmSdbResponseH_t  rh );
153
+
154
+  // Release the resource held by a query response.  
155
+  cmSdbRC_t           cmSdbResponseFree(    cmSdbResponseH_t* rhp );
156
+  void                cmSdbResponsePrint(   cmSdbResponseH_t  rh, cmRpt_t* rpt );
157
+    
158
+  // Time align all channel pairs by setting the onset times to 
159
+  // the minimum time among all the pairs and the offset times to
160
+  // the maximum among all the pairs.
161
+  cmSdbRC_t cmSdbSyncChPairs( cmSdbH_t h );
162
+
163
+  cmSdbRC_t cmSdbTest( cmCtx_t* ctx );
164
+
165
+#ifdef __cplusplus
166
+}
167
+#endif
168
+
169
+#endif

+ 24
- 24
cmCsv.c View File

@@ -7,7 +7,7 @@
7 7
 #include "cmMallocDebug.h"
8 8
 #include "cmLex.h"
9 9
 #include "cmLinkedHeap.h"
10
-#include "cmSymTbl.h"
10
+#include "cmHashTbl.h"
11 11
 #include "cmCsv.h"
12 12
 #include "cmText.h"
13 13
 
@@ -48,9 +48,9 @@ typedef struct cmCsvUdef_str
48 48
 typedef struct
49 49
 {
50 50
   cmErr_t            err;
51
-  void*              rptDataPtr;     //
52
-  cmLexH             lexH;           // parsing lexer 
53
-  cmSymTblH_t        symTblH;        // all XML identifiers and data is stored as a symbol in this table
51
+  void*              rptDataPtr;   //
52
+  cmLexH             lexH;         // parsing lexer 
53
+  cmHashTblH_t       htH;          // hash table handle
54 54
   cmLHeapH_t         heapH;
55 55
   cmCsvBind_t*       bindPtr;      // base of the binder linked list
56 56
   cmCsvCell_t*       curRowPtr;    // used by the parser to track the row being filled
@@ -95,15 +95,15 @@ cmCsvRC_t cmCsvInitialize( cmCsvH_t *hp, cmCtx_t* ctx )
95 95
 
96 96
   cmErrSetup(&p->err,&ctx->rpt,"CSV");
97 97
 
98
-  // create the symbol table
99
-  if( cmSymTblIsValid(p->symTblH = cmSymTblCreate(cmSymTblNullHandle,0,ctx)) == false )
98
+  // create the hash table
99
+  if( cmHashTblCreate(ctx,&p->htH,8192) != kOkHtRC )
100 100
   {
101
-    rc = _cmCsvError(p,kSymTblErrCsvRC,"Symbol table creation failed.");
101
+    rc = _cmCsvError(p,kHashTblErrCsvRC,"Hash table creation failed.");
102 102
     goto errLabel;
103 103
   }
104 104
 
105 105
   // allocate the linked heap mgr
106
-  if( cmLHeapIsValid(p->heapH = cmLHeapCreate(1024,ctx)) == false )
106
+  if( cmLHeapIsValid(p->heapH = cmLHeapCreate(8192,ctx)) == false )
107 107
   {
108 108
     rc = _cmCsvError(p,kMemAllocErrCsvRC,"Linked heap object allocation failed.");
109 109
     goto errLabel;
@@ -161,8 +161,8 @@ cmCsvRC_t cmCsvFinalize(   cmCsvH_t *hp )
161 161
   if((lexRC = cmLexFinal(&p->lexH)) != kOkLexRC )
162 162
     return _cmCsvError(p,kLexErrCsvRC,"Lexer finalization failed.\nLexer Error:%s",cmLexRcToMsg(lexRC));
163 163
 
164
-  // free the symbol table
165
-  cmSymTblDestroy(&p->symTblH);
164
+  // free the hash table
165
+  cmHashTblDestroy(&p->htH);
166 166
 
167 167
   // free the handle
168 168
   cmMemPtrFree(&hp->h);
@@ -352,8 +352,8 @@ cmCsvRC_t _cmCsvCreateCell( cmCsv_t* p, const char* tokenText, unsigned flags, u
352 352
   cmCsvRC_t    rc     = kOkCsvRC;
353 353
 
354 354
   // register the token text as a symbol
355
-  if((symId = cmSymTblRegisterSymbol(p->symTblH,tokenText)) == cmInvalidId )
356
-    return _cmCsvError(p,kSymTblErrCsvRC,"Symbol registration failed. for '%s' on line %i column %i.",tokenText,lexRow,lexCol);
355
+  if((symId = cmHashTblStoreStr(p->htH,tokenText)) == cmInvalidId )
356
+    return _cmCsvError(p,kHashTblErrCsvRC,"Symbol registration failed. for '%s' on line %i column %i.",tokenText,lexRow,lexCol);
357 357
 
358 358
   // allocate a cell
359 359
   if((rc = _cmCsvAllocCell(p,symId,flags,cellRow,cellCol,&cp,lexTId)) != kOkCsvRC )
@@ -561,8 +561,8 @@ const char* cmCsvCellSymText(   cmCsvH_t h, unsigned symId )
561 561
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
562 562
   const char* cp;
563 563
 
564
-  if((cp =  cmSymTblLabel(p->symTblH,symId)) == NULL )
565
-    _cmCsvError(p,kSymTblErrCsvRC,"The text associated with the symbol '%i' was not found.",symId);
564
+  if((cp =  cmHashTblStr(p->htH,symId)) == NULL )
565
+    _cmCsvError(p,kHashTblErrCsvRC,"The text associated with the symbol '%i' was not found.",symId);
566 566
 
567 567
   return cp;
568 568
 }
@@ -573,7 +573,7 @@ cmCsvRC_t   cmCsvCellSymInt(    cmCsvH_t h, unsigned symId, int* vp )
573 573
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
574 574
 
575 575
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
576
-    return kSymTblErrCsvRC;
576
+    return kHashTblErrCsvRC;
577 577
 
578 578
   if( cmTextToInt(cp,vp,&p->err) != kOkTxRC )
579 579
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to int value failed.");
@@ -587,7 +587,7 @@ cmCsvRC_t  cmCsvCellSymUInt(   cmCsvH_t h, unsigned symId, unsigned* vp )
587 587
   cmCsv_t*    p = _cmCsvHandleToPtr(h);
588 588
 
589 589
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
590
-    return kSymTblErrCsvRC;
590
+    return kHashTblErrCsvRC;
591 591
 
592 592
   if( cmTextToUInt(cp,vp,&p->err) != kOkTxRC )
593 593
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to uint value failed.");
@@ -601,7 +601,7 @@ cmCsvRC_t   cmCsvCellSymFloat(  cmCsvH_t h, unsigned symId, float* vp )
601 601
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
602 602
 
603 603
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
604
-    return kSymTblErrCsvRC;
604
+    return kHashTblErrCsvRC;
605 605
 
606 606
   if( cmTextToFloat(cp,vp,&p->err) != kOkTxRC )
607 607
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to float value failed.");
@@ -615,7 +615,7 @@ cmCsvRC_t    cmCsvCellSymDouble( cmCsvH_t h, unsigned symId, double* vp )
615 615
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
616 616
 
617 617
   if((cp = cmCsvCellSymText(h,symId)) == NULL )
618
-    return kSymTblErrCsvRC;
618
+    return kHashTblErrCsvRC;
619 619
 
620 620
   if( cmTextToDouble(cp,vp,&p->err) != kOkTxRC )
621 621
     return _cmCsvError(p,kDataCvtErrCsvRC,"CSV text to double value failed.");
@@ -695,8 +695,8 @@ unsigned   cmCsvInsertSymText(   cmCsvH_t h, const char* text )
695 695
   cmCsv_t*    p  = _cmCsvHandleToPtr(h);
696 696
   unsigned    symId;
697 697
 
698
-  if((symId = cmSymTblRegisterSymbol(p->symTblH,text)) == cmInvalidId )
699
-    _cmCsvError(p,kSymTblErrCsvRC,"'%s' could not be inserted into the symbol table.",text);
698
+  if((symId = cmHashTblStoreStr(p->htH,text)) == cmInvalidId )
699
+    _cmCsvError(p,kHashTblErrCsvRC,"'%s' could not be inserted into the symbol table.",text);
700 700
 
701 701
   return symId;
702 702
 }
@@ -1134,8 +1134,8 @@ cmCsvRC_t  cmCsvWrite( cmCsvH_t h, const char* fn )
1134 1134
       {
1135 1135
         const char* tp;
1136 1136
 
1137
-        if((tp =  cmSymTblLabel(p->symTblH,cp->symId)) == NULL )
1138
-          return _cmCsvError(p,kSymTblErrCsvRC,"Unable to locate the symbol text for cell at row:%i col:%i.",cp->row,cp->col);
1137
+        if((tp = cmHashTblStr(p->htH,cp->symId)) == NULL )
1138
+          return _cmCsvError(p,kHashTblErrCsvRC,"Unable to locate the symbol text for cell at row:%i col:%i.",cp->row,cp->col);
1139 1139
 
1140 1140
         if( cmIsFlag(cp->flags,kTextTMask) )
1141 1141
           fprintf(fp,"\"");
@@ -1179,8 +1179,8 @@ cmCsvRC_t  cmCsvPrint( cmCsvH_t h, unsigned rowCnt )
1179 1179
       {
1180 1180
         const char* tp;
1181 1181
 
1182
-        if((tp =  cmSymTblLabel(p->symTblH,cp->symId)) == NULL )
1183
-          _cmCsvError(p,kSymTblErrCsvRC,"The text associated with the symbol '%i' was not found.",cp->symId);
1182
+        if((tp =  cmHashTblStr(p->htH,cp->symId)) == NULL )
1183
+          _cmCsvError(p,kHashTblErrCsvRC,"The text associated with the symbol '%i' was not found.",cp->symId);
1184 1184
 
1185 1185
         fputs(tp,stdin);
1186 1186
       }

+ 1
- 1
cmCsv.h View File

@@ -11,7 +11,7 @@ extern "C" {
11 11
     kOkCsvRC = 0,
12 12
     kMemAllocErrCsvRC,
13 13
     kLexErrCsvRC,
14
-    kSymTblErrCsvRC,
14
+    kHashTblErrCsvRC,
15 15
     kSyntaxErrCsvRC,
16 16
     kFileOpenErrCsvRC,
17 17
     kFileCreateErrCsvRC,

+ 464
- 0
cmHashTbl.c View File

@@ -0,0 +1,464 @@
1
+#include "cmGlobal.h"
2
+#include "cmFloatTypes.h"
3
+#include "cmRpt.h"
4
+#include "cmErr.h"
5
+#include "cmCtx.h"
6
+#include "cmMem.h"
7
+#include "cmLinkedHeap.h"
8
+#include "cmMallocDebug.h"
9
+#include "cmMath.h"
10
+#include "cmHashTbl.h"
11
+#include "cmText.h"
12
+
13
+enum
14
+{
15
+  kFreeHtFl = 0x01,
16
+};
17
+
18
+typedef struct cmHtValue_str
19
+{
20
+  unsigned              flags;    // See kXXXHtFl above.
21
+  unsigned              id;       // unique id associated with this value
22
+  void*                 value;    // value blob 
23
+  unsigned              byteCnt;  // size of value blob in bytes
24
+  struct cmHtValue_str* link;     // cmHtBucket_t.list link
25
+} cmHtValue_t;
26
+
27
+typedef struct
28
+{
29
+  cmHtValue_t* list;    // value list
30
+  cmHtValue_t* avail;   // available value slots - formed from cmHashTblRemoved() values.
31
+  unsigned     nextIdx; // next unused index for this bucket
32
+} cmHtBucket_t;
33
+
34
+typedef struct
35
+{
36
+  cmErr_t       err;
37
+  cmLHeapH_t    lhH;            // memory for hash table buckets, values, value blobs.
38
+  unsigned      bucketCnt;      // hash table bucket cnt
39
+  unsigned      linkCnt;        // max length of collision list for each bucket
40
+  unsigned      mask;           // hash id bucket index mask (masks the MSB's of the hash-id)
41
+  unsigned      maskShift;      // shift required to move the lowest 'mask' bit to the LSB.
42
+  cmHtBucket_t* b;              // b[bucketCnt] bucket array
43
+} cmHt_t;
44
+
45
+cmHashTblH_t cmHashTblNullHandle = cmSTATIC_NULL_HANDLE;
46
+
47
+#define _cmHtBucketIndex( p, id ) (((id) & (p)->mask) >> (p)->maskShift)
48
+
49
+cmHt_t* _cmHtHandleToPtr( cmHashTblH_t h )
50
+{
51
+  cmHt_t* p = (cmHt_t*)h.h;
52
+  assert(p!=NULL);
53
+  return p;
54
+}
55
+
56
+// Return the bucket index portion of the hash id.
57
+unsigned _cmHtGenId( cmHt_t* p, const void* v, unsigned byteCnt )
58
+{
59
+  unsigned i,j;
60
+  const char* cv = v;
61
+  unsigned h = 0;
62
+
63
+  for(i=0,j=3; i<byteCnt; ++i,++j)
64
+    h += ((unsigned)cv[i]) << ((j&0x3)*8);
65
+
66
+  return h & p->mask;
67
+}
68
+
69
+
70
+// Given an id find the value.
71
+cmHtValue_t* _cmHtIdToValue( cmHt_t* p, unsigned id )
72
+{
73
+  if( id == cmInvalidId )
74
+    return NULL;
75
+
76
+  unsigned      bi = _cmHtBucketIndex(p,id);
77
+
78
+  assert(bi < p->bucketCnt);
79
+
80
+  cmHtValue_t* v = p->b[bi].list;
81
+  for(; v!=NULL; v=v->link)
82
+    if( v->id == id )
83
+      return v;
84
+
85
+  return NULL;
86
+}
87
+
88
+// Given a value find the id
89
+cmHtValue_t* _cmHtValueToId( cmHt_t* p, const void* value, unsigned byteCnt, unsigned id )
90
+{
91
+  if( id == cmInvalidId )
92
+    id = _cmHtGenId(p,value,byteCnt);
93
+
94
+  unsigned bi = _cmHtBucketIndex(p,id);
95
+
96
+  assert(bi < p->bucketCnt);
97
+
98
+  cmHtValue_t* v = p->b[bi].list;
99
+  for(; v!=NULL; v=v->link)
100
+    if( v->byteCnt==byteCnt && memcmp(value,v->value,byteCnt)==0 )
101
+      return v;
102
+
103
+  return NULL;
104
+}
105
+
106
+cmHtRC_t _cmHtDestroy( cmHt_t* p )
107
+{
108
+  cmHtRC_t rc = kOkHtRC;
109
+  cmLHeapDestroy(&p->lhH);
110
+  cmMemFree(p->b);
111
+  cmMemFree(p);
112
+  return rc;
113
+}
114
+
115
+cmHtRC_t cmHashTblCreate( cmCtx_t* ctx, cmHashTblH_t* hp, unsigned bucketCnt )
116
+{
117
+  cmHtRC_t rc;
118
+  if((rc = cmHashTblDestroy(hp)) != kOkHtRC )
119
+    return rc;
120
+
121
+  cmHt_t* p = cmMemAllocZ(cmHt_t,1);
122
+
123
+  cmErrSetup(&p->err,&ctx->rpt,"hash table");
124
+
125
+  if(cmLHeapIsValid(p->lhH = cmLHeapCreate(8192,ctx)) == false )
126
+  {
127
+    cmErrMsg(&p->err,kLHeapFailHtRC,"Internal linked heap mgr. create failed.");
128
+    goto errLabel;
129
+  }
130
+
131
+  // force the bucket count to be a power of two
132
+  p->bucketCnt = cmNextPowerOfTwo(bucketCnt);
133
+  p->mask      = p->bucketCnt - 1;
134
+
135
+  // calcluate the hash-id bucket mask
136
+  for(p->maskShift=0; (0x80000000 & p->mask) == 0; ++p->maskShift )
137
+    p->mask <<= 1;
138
+  
139
+  // calculate the maximum collisions per bucket mask
140
+  p->linkCnt = ~p->mask;
141
+
142
+  // allocate the bucket array
143
+  p->b = cmMemAllocZ(cmHtBucket_t,p->bucketCnt);
144
+  
145
+  hp->h = p;
146
+
147
+ errLabel:
148
+  if( rc != kOkHtRC )
149
+    _cmHtDestroy(p);
150
+  return rc;
151
+}
152
+
153
+cmHtRC_t cmHashTblDestroy( cmHashTblH_t* hp )
154
+{
155
+  cmHtRC_t rc = kOkHtRC;
156
+  if(hp==NULL || cmHashTblIsValid(*hp)==false )
157
+    return rc;
158
+
159
+  cmHt_t* p = _cmHtHandleToPtr(*hp);
160
+
161
+  if((rc = _cmHtDestroy(p)) != kOkHtRC )
162
+    return rc;
163
+
164
+  hp->h = NULL;
165
+
166
+  return rc;
167
+}
168
+
169
+bool cmHashTblIsValid( cmHashTblH_t h )
170
+{ return h.h!=NULL; }
171
+
172
+unsigned cmHashTblStoreBase(      cmHashTblH_t h, void* v, unsigned byteCnt, bool staticFl )
173
+{
174
+  cmHt_t*      p  = _cmHtHandleToPtr(h);
175
+  cmHtValue_t* vp = NULL;
176
+  unsigned     id = _cmHtGenId(p, v, byteCnt );
177
+
178
+  // if the value is already stored then there is nothing else to do
179
+  if((vp = _cmHtValueToId(p,v,byteCnt,id)) != NULL )
180
+    return vp->id;
181
+
182
+  unsigned bi = _cmHtBucketIndex(p,id);
183
+
184
+  assert(bi < p->bucketCnt );
185
+
186
+  cmHtBucket_t* b  = p->b + bi;
187
+
188
+  if( b->avail != NULL )
189
+  {
190
+    vp       = b->avail;
191
+    b->avail = b->avail->link;
192
+  }
193
+  else
194
+  {
195
+    if( b->nextIdx == p->linkCnt || (id + b->nextIdx) == cmInvalidId )
196
+    {
197
+      cmErrMsg(&p->err,kHashFaultHtRC,"The hash table bucket at index %i is exhaused.",bi);
198
+      return cmInvalidId;
199
+    }
200
+
201
+    vp = cmLhAllocZ(p->lhH,cmHtValue_t,1);
202
+    vp->id = id + b->nextIdx++;
203
+  }  
204
+  
205
+
206
+  assert( vp->id != cmInvalidId );
207
+  
208
+  vp->link = b->list;
209
+  b->list = vp;
210
+  vp->byteCnt = byteCnt;
211
+
212
+  if( staticFl )
213
+    vp->value = v;
214
+  else
215
+  {
216
+    vp->value = cmLhAlloc(p->lhH,char,byteCnt);
217
+    memcpy(vp->value,v,byteCnt);
218
+    vp->flags = cmSetFlag(vp->flags,kFreeHtFl);
219
+  }
220
+
221
+  return vp->id;
222
+}
223
+
224
+unsigned cmHashTblStore(          cmHashTblH_t h, void* v, unsigned byteCnt )
225
+{ return cmHashTblStoreBase(h,v,byteCnt,false); }
226
+
227
+unsigned cmHashTblStoreStatic(    cmHashTblH_t h, void* v, unsigned byteCnt )
228
+{ return cmHashTblStoreBase(h,v,byteCnt,true); }
229
+
230
+unsigned _cmHashTblStoreStr(       cmHashTblH_t h, const cmChar_t* s, bool staticFl )
231
+{ 
232
+  unsigned n = cmTextLength(s);
233
+  if( n == 0 )
234
+  {
235
+    s = "";
236
+    n = 1;
237
+  }
238
+
239
+return cmHashTblStoreBase(h,(void*)s,n+1,staticFl); 
240
+}
241
+
242
+unsigned cmHashTblStoreStr(       cmHashTblH_t h, const cmChar_t* s )
243
+{ return _cmHashTblStoreStr(h,s,false); }
244
+
245
+unsigned cmhashTblStoreStaticStr( cmHashTblH_t h, const cmChar_t* s )
246
+{ return _cmHashTblStoreStr(h,s,true); }
247
+
248
+unsigned cmHashTblStoreV( cmHashTblH_t h, const cmChar_t* fmt, va_list vl )
249
+{
250
+  cmChar_t* s = NULL;
251
+  s = cmTsVPrintfP(s,fmt,vl);
252
+  unsigned id = _cmHashTblStoreStr(h,s,false); 
253
+  cmMemFree(s);
254
+  return id;
255
+}
256
+
257
+unsigned cmHashTblStoreF( cmHashTblH_t h, const cmChar_t* fmt, ... )
258
+{
259
+  va_list vl;
260
+  va_start(vl,fmt);
261
+  unsigned id = cmHashTblStoreV(h,fmt,vl);
262
+  va_end(vl);
263
+  return id;
264
+}
265
+
266
+unsigned cmHashTblId( cmHashTblH_t h, const void* value, unsigned byteCnt )
267
+{
268
+  cmHt_t*  p  = _cmHtHandleToPtr(h);
269
+  cmHtValue_t* vp;
270
+
271
+  if((vp = _cmHtValueToId(p,value,byteCnt,cmInvalidId)) == NULL )
272
+    return cmInvalidId;
273
+
274
+  return vp->id;
275
+}
276
+
277
+unsigned cmHashTblStrToId( cmHashTblH_t h, const cmChar_t* str )
278
+{
279
+  if( str == NULL )
280
+    return cmInvalidId;
281
+
282
+  return cmHashTblId(h,str,cmTextLength(str)+1);
283
+}
284
+
285
+
286
+const void* cmHashTblValue( cmHashTblH_t h, unsigned id, unsigned* byteCntRef )
287
+{
288
+  cmHt_t*      p = _cmHtHandleToPtr(h);
289
+  cmHtValue_t* vp;
290
+
291
+  if((vp = _cmHtIdToValue(p, id)) != NULL )
292
+  {
293
+    if( byteCntRef != NULL )
294
+      *byteCntRef = vp->byteCnt;
295
+
296
+    return vp->value;
297
+  }
298
+
299
+  return NULL; 
300
+}
301
+
302
+
303
+const cmChar_t* cmHashTblStr( cmHashTblH_t h, unsigned id )
304
+{  return (const cmChar_t*)cmHashTblValue(h,id,NULL);  }
305
+
306
+
307
+cmHtRC_t cmHashTblRemove( cmHashTblH_t h, unsigned id )
308
+{
309
+  cmHt_t*       p  = _cmHtHandleToPtr(h);
310
+  unsigned      bi = _cmHtBucketIndex(p,id);
311
+
312
+
313
+
314
+  assert(bi < p->bucketCnt);
315
+
316
+  cmHtBucket_t* b  = p->b + bi;
317
+
318
+  cmHtValue_t*  vp = b->list;
319
+  cmHtValue_t*  pp = NULL;
320
+
321
+  for(; vp!=NULL; vp=vp->link)
322
+  {
323
+    if( vp->id == id )
324
+    {
325
+      if( pp == NULL )
326
+        b->list = vp->link;
327
+      else
328
+        pp->link = vp->link;
329
+
330
+      break;
331
+    }
332
+
333
+    pp = vp;
334
+  }
335
+
336
+  if( vp == NULL )
337
+    return cmErrMsg(&p->err,kInvalidIdHtRC,"A value could not be found for the hash id 0x%x.",id);
338
+  
339
+  if( cmIsFlag(vp->flags,kFreeHtFl ) )
340
+    cmLhFree(p->lhH,vp->value);
341
+  
342
+
343
+  vp->flags   = 0;
344
+  vp->value   = NULL;
345
+  vp->byteCnt = 0;
346
+
347
+  // Note: Do not set the id to zero since we want to consert id's 
348
+  // and this recd will be reused by the next call to cmHashTblStoreBase().
349
+
350
+  return kOkHtRC;
351
+  
352
+}
353
+
354
+
355
+cmHtRC_t cmHashTblLastRC( cmHashTblH_t h )
356
+{
357
+  cmHt_t* p = _cmHtHandleToPtr(h);
358
+  return cmErrLastRC(&p->err);
359
+}
360
+
361
+void _cmHashTblBucketReport( cmHtBucket_t* b, cmRpt_t* rpt )
362
+{
363
+  cmHtValue_t* vp = b->list;
364
+  unsigned i;
365
+  for(i=0; vp!=NULL && i<10; vp=vp->link,++i)
366
+    cmRptPrintf(rpt,"0x%x : %s\n",vp->id,((const cmChar_t*)vp->value));
367
+
368
+  cmRptPrintf(rpt,"\n");
369
+}
370
+
371
+void cmHashTblReport( cmHashTblH_t h, cmRpt_t* rpt )
372
+{
373
+  cmHt_t* p = _cmHtHandleToPtr(h);
374
+  unsigned i;
375
+  for(i=0; i<p->bucketCnt; ++i)
376
+  {
377
+    //if( p->b[i].nextIdx > 0 )
378
+    //  cmRptPrintf(rpt,"%i,%i\n",i,p->b[i].nextIdx);
379
+
380
+    if( p->b[i].nextIdx > 100 )
381
+      _cmHashTblBucketReport(p->b + i,rpt);
382
+  }
383
+}
384
+
385
+
386
+cmHtRC_t cmHashTblTest( cmCtx_t* ctx )
387
+{
388
+  cmHtRC_t     rc = kOkHtRC;
389
+  cmHashTblH_t h  = cmHashTblNullHandle;
390
+  cmErr_t err;
391
+  cmErrSetup(&err,&ctx->rpt,"hash table test");
392
+
393
+  if((rc = cmHashTblCreate(ctx,&h,8192)) != kOkHtRC )
394
+    return cmErrMsg(&err,rc,"Hash table create failed.");
395
+
396
+  const cmChar_t* arr[] = 
397
+  {
398
+    "1",
399
+    "12",
400
+    "123",
401
+    "1234",
402
+    "12345",
403
+    "123456",
404
+    "123456",
405
+    "123456",
406
+    NULL
407
+  };
408
+
409
+  unsigned n = sizeof(arr)/sizeof(arr[0]);
410
+  unsigned ids[ n ];
411
+  int i = 0;
412
+
413
+  // store the values from arr[]
414
+  for(; arr[i]!=NULL; ++i)
415
+    if((ids[i] = cmHashTblStoreStr(h,arr[i])) == cmInvalidId )
416
+    {
417
+      rc = cmErrMsg(&err,cmHashTblLastRC(h),"Hash store failed on: '%s.",cmStringNullGuard(arr[i]));
418
+      goto errLabel;
419
+    }
420
+
421
+  /*
422
+  // remove a value
423
+  unsigned rem_idx = 3;
424
+  if((rc = cmHashTblRemove(h, ids[rem_idx] )) != kOkHtRC )
425
+  {
426
+    rc = cmErrMsg(&err,rc,"Hash removed failed.");
427
+    goto errLabel;
428
+  }
429
+
430
+  // insert the same value - which should restore the removed value
431
+  if((ids[rem_idx] = cmHashTblStoreStr(h,arr[rem_idx])) == cmInvalidId )
432
+  {
433
+    rc = cmErrMsg(&err,cmHashTblLastRC(h),"Hash store failed on: '%s.",cmStringNullGuard(arr[rem_idx]));
434
+    goto errLabel;
435
+  }
436
+  */
437
+  
438
+  // lookup all the stored values by id
439
+  for(--i; i>=0; --i)
440
+  {
441
+    const cmChar_t* s;
442
+
443
+    if((s = cmHashTblStr(h,ids[i])) == NULL )
444
+      rc = cmErrMsg(&err,kInvalidIdHtRC,"The value associated with hash-id:0x%x could not be found.",ids[i]);
445
+    else
446
+      printf("%i : %s\n",i,cmStringNullGuard(s));
447
+  }
448
+
449
+
450
+  for(i=0; arr[i]!=NULL; ++i)
451
+  {
452
+    unsigned id = cmHashTblStrToId(h, arr[i]);
453
+    printf("%i : 0x%x : %s\n",i, id, cmStringNullGuard(cmHashTblStr(h, id)));
454
+  }
455
+
456
+
457
+  cmHashTblReport(h, &ctx->rpt );
458
+
459
+
460
+ errLabel:
461
+  cmHashTblDestroy(&h);
462
+  return rc;
463
+
464
+}

+ 67
- 0
cmHashTbl.h View File

@@ -0,0 +1,67 @@
1
+#ifndef cmHashTbl_h
2
+#define cmHashTbl_h
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+  enum
9
+  {
10
+    kOkHtRC,
11
+    kLHeapFailHtRC,
12
+    kHashFaultHtRC,
13
+    kInvalidIdHtRC
14
+  };
15
+
16
+  typedef cmRC_t cmHtRC_t;
17
+  typedef cmHandle_t cmHashTblH_t;
18
+  extern cmHashTblH_t cmHashTblNullHandle;
19
+  
20
+  cmHtRC_t cmHashTblCreate( cmCtx_t* ctx, cmHashTblH_t* hp, unsigned bucketCnt );
21
+
22
+  cmHtRC_t cmHashTblDestroy( cmHashTblH_t* hp );
23
+
24
+  bool cmHashTblIsValid( cmHashTblH_t h );
25
+
26
+  // cmhashTblStoreBase() is the canonical store function.
27
+  // Set 'staticFl' to true if the value does not need to be reallocated
28
+  // and copied into the internal storage space.
29
+  // Returns a value which uniquely identifies the value.  If a unique
30
+  // identifier cannot be generated then the function returns cmInvalidId
31
+  // and sets the hash table error code to kHashFaultRC.
32
+  unsigned cmHashTblStoreBase(      cmHashTblH_t h, void* v, unsigned byteCnt, bool staticFl );
33
+  
34
+  unsigned cmHashTblStore(          cmHashTblH_t h, void* v, unsigned byteCnt );
35
+  unsigned cmHashTblStoreStatic(    cmHashTblH_t h, void* v, unsigned byteCnt );
36
+  unsigned cmHashTblStoreStr(       cmHashTblH_t h, const cmChar_t* s );
37
+  unsigned cmhashTblStoreStaticStr( cmHashTblH_t h, const cmChar_t* s );
38
+  unsigned cmHashTblStoreV(         cmHashTblH_t h, const cmChar_t* fmt, va_list vl );
39
+  unsigned cmHashTblStoreF(         cmHashTblH_t h, const cmChar_t* fmt, ... );
40
+  
41
+  // Given a value find an id.
42
+  unsigned cmHashTblId( cmHashTblH_t h, const void* value, unsigned byteCnt );
43
+  unsigned cmHashTblStrToId( cmHashTblH_t h, const cmChar_t* str );
44
+
45
+  // Returns NULL if no value is associated with 'id'.
46
+  // 'byteCntRef' is optional.
47
+  const void* cmHashTblValue( cmHashTblH_t h, unsigned id, unsigned* byteCntRef );
48
+
49
+  // Wrapper around cmHashTblValue() which assumes that the stored value is a 
50
+  // zero terminated string.
51
+  const cmChar_t* cmHashTblStr( cmHashTblH_t h, unsigned id );
52
+
53
+  // Remove a value.
54
+  cmHtRC_t cmHashTblRemove( cmHashTblH_t h, unsigned id );
55
+
56
+  // Return the last error id generated by the cmHashTbl object.
57
+  cmHtRC_t cmHashTblLastRC( cmHashTblH_t h );
58
+  
59
+  void cmHashTblReport( cmHashTblH_t h, cmRpt_t* rpt );
60
+
61
+  cmHtRC_t cmHashTblTest( cmCtx_t* ctx );
62
+
63
+#ifdef __cplusplus
64
+}
65
+#endif
66
+
67
+#endif

+ 62
- 61
cmSyncRecd.c View File

@@ -11,6 +11,7 @@
11 11
 #include "cmSyncRecd.h"
12 12
 #include "cmVectOpsTemplateMain.h"
13 13
 #include "cmMidi.h"
14
+
14 15
 typedef enum
15 16
 {
16 17
   kInvalidSrId,
@@ -76,44 +77,44 @@ cmSr_t* _cmSrHtoP( cmSyncRecdH_t h )
76 77
   return p;
77 78
 }
78 79
 
79
-cmSrRC_t _cmSrWriteCache( cmSr_t* p )
80
+cmSyRC_t _cmSrWriteCache( cmSr_t* p )
80 81
 {
81 82
   if( cmFileWrite(p->fH,p->cache,p->ci * sizeof(cmSrRecd_t)) != kOkFileRC )
82
-    return cmErrMsg(&p->err,kFileFailSrRC,"File write failed.");
83
+    return cmErrMsg(&p->err,kFileFailSyRC,"File write failed.");
83 84
 
84 85
   p->fn += p->ci;
85 86
   p->ci = 0;
86 87
   
87
-  return kOkSrRC;
88
+  return kOkSyRC;
88 89
 }
89 90
 
90 91
 
91
-cmSrRC_t _cmSrFinal( cmSr_t* p )
92
+cmSyRC_t _cmSrFinal( cmSr_t* p )
92 93
 {
93
-  cmSrRC_t rc = kOkSrRC;
94
+  cmSyRC_t rc = kOkSyRC;
94 95
   
95 96
   // write any remaining cache records
96 97
   if( cmIsFlag(p->flags,kReadSrFl) == false )
97 98
   {
98
-    if((rc = _cmSrWriteCache(p)) == kOkSrRC )
99
+    if((rc = _cmSrWriteCache(p)) == kOkSyRC )
99 100
     {
100 101
       if(cmFileSeek(p->fH,kBeginFileFl,p->offs) != kOkFileRC )
101
-        rc = cmErrMsg(&p->err,kFileFailSrRC, "File seek fail on file offset positioning.");
102
+        rc = cmErrMsg(&p->err,kFileFailSyRC, "File seek fail on file offset positioning.");
102 103
       else
103 104
         if(cmFileWriteUInt(p->fH,&p->fn,1) != kOkFileRC )
104
-          rc = cmErrMsg(&p->err,kFileFailSrRC, "File write failed on record count.");
105
+          rc = cmErrMsg(&p->err,kFileFailSyRC, "File write failed on record count.");
105 106
     }
106 107
   }
107 108
 
108 109
   // release the audio file object
109 110
   if( cmAudioFileIsValid(p->afH) )
110 111
     if( cmAudioFileDelete(&p->afH) != kOkAfRC )
111
-      return cmErrMsg(&p->err,kAudioFileFailSrRC,"Audio file object delete failed.");
112
+      return cmErrMsg(&p->err,kAudioFileFailSyRC,"Audio file object delete failed.");
112 113
 
113 114
   // release the sync-recd file object
114 115
   if( cmFileIsValid(p->fH) )
115 116
     if( cmFileClose(&p->fH) != kOkFileRC )
116
-      return cmErrMsg(&p->err,kFileFailSrRC,"File close failed.");
117
+      return cmErrMsg(&p->err,kFileFailSyRC,"File close failed.");
117 118
 
118 119
   cmMemFree(p->cache);
119 120
   cmMemFree(p->map);
@@ -134,27 +135,27 @@ cmSr_t*  _cmSrAlloc( cmCtx_t* ctx, unsigned flags )
134 135
   return p;
135 136
 }
136 137
 
137
-cmSrRC_t cmSyncRecdCreate( cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn, const cmChar_t* audioFn, double srate, unsigned chCnt, unsigned bits )
138
+cmSyRC_t cmSyncRecdCreate( cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn, const cmChar_t* audioFn, double srate, unsigned chCnt, unsigned bits )
138 139
 {
139
-  cmSrRC_t rc   = kOkSrRC;
140
+  cmSyRC_t rc   = kOkSyRC;
140 141
   cmRC_t   afRC = kOkAfRC;
141 142
 
142 143
   assert( audioFn != NULL );
143 144
 
144
-  if((rc = cmSyncRecdFinal(hp)) != kOkSrRC )
145
+  if((rc = cmSyncRecdFinal(hp)) != kOkSyRC )
145 146
     return rc;
146 147
 
147 148
   cmSr_t* p = _cmSrAlloc(ctx,0);
148 149
 
149 150
   if( cmFileOpen(&p->fH,srFn,kWriteFileFl,&ctx->rpt) != kOkFileRC )
150 151
   {
151
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to create the sync-recd file '%s'.",cmStringNullGuard(srFn));
152
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to create the sync-recd file '%s'.",cmStringNullGuard(srFn));
152 153
     goto errLabel;
153 154
   }
154 155
 
155 156
   if( cmAudioFileIsValid(p->afH = cmAudioFileNewCreate(audioFn,srate,bits,chCnt,&afRC,&ctx->rpt))==false)
156 157
   {
157
-    rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Unable to create the sync-recd audio file '%s'.",cmStringNullGuard(audioFn));
158
+    rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Unable to create the sync-recd audio file '%s'.",cmStringNullGuard(audioFn));
158 159
     goto errLabel;
159 160
   }
160 161
 
@@ -163,47 +164,47 @@ cmSrRC_t cmSyncRecdCreate( cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
163 164
 
164 165
   if( cmFileWriteUInt(p->fH,&fileUUId,1) != kOkFileRC )
165 166
   {
166
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File write failed on UUID.");
167
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File write failed on UUID.");
167 168
     goto errLabel;
168 169
   }
169 170
 
170 171
   if( cmFileWriteUInt(p->fH,&audioFnCnt,1) != kOkFileRC )
171 172
   {
172
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File write failed on audio file length write count.");
173
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File write failed on audio file length write count.");
173 174
     goto errLabel;
174 175
   }
175 176
 
176 177
   if( cmFileWriteChar(p->fH,audioFn,audioFnCnt) != kOkFileRC )
177 178
   {
178
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File write failed on audio file string.");
179
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File write failed on audio file string.");
179 180
     goto errLabel;
180 181
   }
181 182
 
182 183
   if( cmFileTell(p->fH,&p->offs) != kOkFileRC )
183 184
   {
184
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to determine file offset.");
185
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to determine file offset.");
185 186
     goto errLabel;
186 187
   }
187 188
 
188 189
   if( cmFileWriteUInt(p->fH,&p->fn,1) != kOkFileRC )
189 190
   {
190
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File write failed on initial record count.");
191
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File write failed on initial record count.");
191 192
     goto errLabel;
192 193
   }
193 194
 
194 195
   hp->h = p;
195 196
 
196 197
  errLabel:
197
-  if( rc != kOkSrRC )
198
+  if( rc != kOkSyRC )
198 199
     _cmSrFinal(p);
199 200
 
200 201
   return rc;
201 202
 }
202 203
 
203 204
 
204
-cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn )
205
+cmSyRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn )
205 206
 {
206
-  cmSrRC_t  rc         = kOkSrRC;
207
+  cmSyRC_t  rc         = kOkSyRC;
207 208
   cmRC_t    afRC       = kOkAfRC;
208 209
   unsigned  fileUUId   = cmInvalidId;
209 210
   unsigned  audioFnCnt = 0;
@@ -213,26 +214,26 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
213 214
   unsigned mcnt = 0;
214 215
   unsigned* tiV  = NULL;
215 216
 
216
-  if((rc = cmSyncRecdFinal(hp)) != kOkSrRC )
217
+  if((rc = cmSyncRecdFinal(hp)) != kOkSyRC )
217 218
     return rc;
218 219
 
219 220
   cmSr_t* p = _cmSrAlloc(ctx,kReadSrFl);
220 221
 
221 222
   if( cmFileOpen(&p->fH,srFn,kReadFileFl,&ctx->rpt) != kOkFileRC )
222 223
   {
223
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to open the sync-recd file '%s'.",cmStringNullGuard(srFn));
224
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to open the sync-recd file '%s'.",cmStringNullGuard(srFn));
224 225
     goto errLabel;
225 226
   }
226 227
 
227 228
   if( cmFileReadUInt(p->fH,&fileUUId,1) != kOkFileRC )
228 229
   {
229
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File read failed on UUId.");
230
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File read failed on UUId.");
230 231
     goto errLabel;
231 232
   }
232 233
 
233 234
   if( cmFileReadUInt(p->fH,&audioFnCnt,1) != kOkFileRC )
234 235
   {
235
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File read failed on audio file name count.");
236
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File read failed on audio file name count.");
236 237
     goto errLabel;
237 238
   }
238 239
 
@@ -240,20 +241,20 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
240 241
 
241 242
   if( cmFileReadChar(p->fH,audioFn,audioFnCnt) != kOkFileRC )
242 243
   {
243
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File read failed on audio file string.");
244
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File read failed on audio file string.");
244 245
     goto errLabel;
245 246
   }
246 247
 
247 248
   if( cmFileReadUInt(p->fH,&p->fn,1) != kOkFileRC )
248 249
   {
249
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"File read failed on record count.");
250
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"File read failed on record count.");
250 251
     goto errLabel;
251 252
   }
252 253
 
253 254
   // store the file offset to the first recd
254 255
   if( cmFileTell(p->fH,&p->offs) != kOkFileRC )
255 256
   {
256
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to determine the current file offset.");
257
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to determine the current file offset.");
257 258
     goto errLabel;
258 259
   }
259 260
 
@@ -264,7 +265,7 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
264 265
     cmSrRecd_t r;
265 266
     if( cmFileRead(p->fH,&r,sizeof(r)) != kOkFileRC )
266 267
     {
267
-      rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to read the record at index %i.");
268
+      rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to read the record at index %i.");
268 269
       goto errLabel;
269 270
     }
270 271
 
@@ -288,7 +289,7 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
288 289
   // rewind to the begining of the records
289 290
   if( cmFileSeek(p->fH,kBeginFileFl,p->offs) != kOkFileRC )
290 291
   {
291
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to seek to first recd offset.");
292
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to seek to first recd offset.");
292 293
     goto errLabel;
293 294
   }
294 295
 
@@ -303,7 +304,7 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
303 304
   {
304 305
     if( cmFileRead(p->fH,p->cache + p->ci,sizeof(cmSrRecd_t)) != kOkFileRC )
305 306
     {
306
-      rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to read the record at index %i.");
307
+      rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to read the record at index %i.");
307 308
       goto errLabel;
308 309
     }
309 310
 
@@ -317,7 +318,7 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
317 318
   // rewind to the first recd
318 319
   if( cmFileSeek(p->fH,kBeginFileFl,p->offs) != kOkFileRC )
319 320
   {
320
-    rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to seek to first recd offset.");
321
+    rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to seek to first recd offset.");
321 322
     goto errLabel;
322 323
   }
323 324
 
@@ -328,7 +329,7 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
328 329
     cmSrRecd_t r;
329 330
     if( cmFileRead(p->fH,&r,sizeof(r)) != kOkFileRC )
330 331
     {
331
-      rc = cmErrMsg(&p->err,kFileFailSrRC,"Unable to read the record at index %i.");
332
+      rc = cmErrMsg(&p->err,kFileFailSyRC,"Unable to read the record at index %i.");
332 333
       goto errLabel;
333 334
     }
334 335
 
@@ -358,7 +359,7 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
358 359
   // open the audio file
359 360
   if( cmAudioFileIsValid(p->afH = cmAudioFileNewOpen(audioFn,&p->afInfo,&afRC,&ctx->rpt ))==false)
360 361
   {
361
-    rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Unable to open the sync-recd audio file '%s'.",cmStringNullGuard(audioFn));
362
+    rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Unable to open the sync-recd audio file '%s'.",cmStringNullGuard(audioFn));
362 363
     goto errLabel;
363 364
   }
364 365
  
@@ -371,22 +372,22 @@ cmSrRC_t cmSyncRecdOpen(   cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn
371 372
   cmMemFree(tiV);
372 373
   cmMemFree(audioFn);
373 374
 
374
-  if( rc != kOkSrRC )
375
+  if( rc != kOkSyRC )
375 376
     _cmSrFinal(p);
376 377
 
377 378
   return rc;
378 379
 }
379 380
 
380
-cmSrRC_t cmSyncRecdFinal(  cmSyncRecdH_t* hp )
381
+cmSyRC_t cmSyncRecdFinal(  cmSyncRecdH_t* hp )
381 382
 {
382
-  cmSrRC_t rc = kOkSrRC;
383
+  cmSyRC_t rc = kOkSyRC;
383 384
 
384 385
   if( hp==NULL || cmSyncRecdIsValid(*hp)==false)
385 386
     return rc;
386 387
 
387 388
   cmSr_t* p = _cmSrHtoP(*hp);
388 389
 
389
-  if((rc = _cmSrFinal(p)) != kOkSrRC )
390
+  if((rc = _cmSrFinal(p)) != kOkSyRC )
390 391
     return rc;
391 392
 
392 393
   hp->h = NULL;
@@ -397,9 +398,9 @@ cmSrRC_t cmSyncRecdFinal(  cmSyncRecdH_t* hp )
397 398
 bool     cmSyncRecdIsValid( cmSyncRecdH_t h )
398 399
 { return h.h != NULL; }
399 400
 
400
-cmSrRC_t cmSyncRecdMidiWrite(  cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned status, unsigned d0, unsigned d1 )
401
+cmSyRC_t cmSyncRecdMidiWrite(  cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned status, unsigned d0, unsigned d1 )
401 402
 {
402
-  cmSrRC_t    rc    = kOkSrRC;
403
+  cmSyRC_t    rc    = kOkSyRC;
403 404
   cmSr_t*     p     = _cmSrHtoP(h);
404 405
   cmSrRecd_t* rp    = p->cache + p->ci;
405 406
   rp->tid           = kMidiSrId;
@@ -416,9 +417,9 @@ cmSrRC_t cmSyncRecdMidiWrite(  cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, u
416 417
   return rc;
417 418
 }
418 419
 
419
-cmSrRC_t cmSyncRecdAudioWrite( cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned smpIdx, const cmSample_t* ch[], unsigned chCnt, unsigned frmCnt )
420
+cmSyRC_t cmSyncRecdAudioWrite( cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned smpIdx, const cmSample_t* ch[], unsigned chCnt, unsigned frmCnt )
420 421
 {
421
-  cmSrRC_t    rc    = kOkSrRC;
422
+  cmSyRC_t    rc    = kOkSyRC;
422 423
   cmSr_t*     p     = _cmSrHtoP(h);
423 424
   cmSrRecd_t* rp    = p->cache + p->ci;
424 425
   rp->tid           = kAudioSrId;
@@ -428,25 +429,25 @@ cmSrRC_t cmSyncRecdAudioWrite( cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, u
428 429
   p->ci += 1;
429 430
 
430 431
   if( p->ci == p->cn )
431
-    if((rc = _cmSrWriteCache(p)) != kOkSrRC )
432
+    if((rc = _cmSrWriteCache(p)) != kOkSyRC )
432 433
       goto errLabel;
433 434
 
434 435
   if( cmAudioFileWriteSample(p->afH,frmCnt,chCnt,(cmSample_t**)ch) != kOkAfRC )
435
-    rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Audio file write failed.");
436
+    rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Audio file write failed.");
436 437
 
437 438
  errLabel:
438 439
   return rc;
439 440
 }
440 441
 
441 442
 
442
-cmSrRC_t cmSyncRecdPrint( cmSyncRecdH_t h )
443
+cmSyRC_t cmSyncRecdPrint( cmSyncRecdH_t h )
443 444
 {
444
-  cmSrRC_t rc = kOkSrRC;
445
+  cmSyRC_t rc = kOkSyRC;
445 446
   cmSr_t*  p  = _cmSrHtoP(h);
446 447
   unsigned i;
447 448
 
448 449
   if( cmIsFlag(p->flags,kReadSrFl)==false)
449
-    return cmErrMsg(&p->err,kInvalidOpSrRC,"The 'print' operation is only valid on sync-recd files opened for reading.");
450
+    return cmErrMsg(&p->err,kInvalidOpSyRC,"The 'print' operation is only valid on sync-recd files opened for reading.");
450 451
   
451 452
   for(i=0; i<p->cn; ++i)
452 453
   {
@@ -457,9 +458,9 @@ cmSrRC_t cmSyncRecdPrint( cmSyncRecdH_t h )
457 458
   return rc;
458 459
 }
459 460
 
460
-cmSrRC_t cmSyncRecdAudioFile( cmSyncRecdH_t h, const cmChar_t* fn )
461
+cmSyRC_t cmSyncRecdAudioFile( cmSyncRecdH_t h, const cmChar_t* fn )
461 462
 {
462
-  cmSrRC_t       rc        = kOkSrRC;
463
+  cmSyRC_t       rc        = kOkSyRC;
463 464
   cmSr_t*        p         = _cmSrHtoP(h);
464 465
   cmAudioFileH_t afH       = cmNullAudioFileH;
465 466
   unsigned       chCnt     = 2;
@@ -474,19 +475,19 @@ cmSrRC_t cmSyncRecdAudioFile( cmSyncRecdH_t h, const cmChar_t* fn )
474 475
   chs[1] = buf+frmCnt;
475 476
 
476 477
   if( cmIsFlag(p->flags,kReadSrFl)==false)
477
-    return cmErrMsg(&p->err,kInvalidOpSrRC,"The 'audio-file-output' operation is only valid on sync-recd files opened for reading.");
478
+    return cmErrMsg(&p->err,kInvalidOpSyRC,"The 'audio-file-output' operation is only valid on sync-recd files opened for reading.");
478 479
   
479 480
   /// Open an audio file for writing
480 481
   if(cmAudioFileIsValid(afH = cmAudioFileNewCreate(fn, p->afInfo.srate, p->afInfo.bits, chCnt, &afRC, p->err.rpt))==false)
481 482
   {
482
-    rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Unable to create the synchronized audio file '%s'.",cmStringNullGuard(fn));
483
+    rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Unable to create the synchronized audio file '%s'.",cmStringNullGuard(fn));
483 484
     goto errLabel;
484 485
   }
485 486
   
486 487
   // rewind the input audio file
487 488
   if( cmAudioFileSeek(p->afH,0) != kOkAfRC )
488 489
   {
489
-    rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Seek failed during synchronized audio file output.");
490
+    rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Seek failed during synchronized audio file output.");
490 491
     goto errLabel;
491 492
   }
492 493
 
@@ -500,7 +501,7 @@ cmSrRC_t cmSyncRecdAudioFile( cmSyncRecdH_t h, const cmChar_t* fn )
500 501
     // read frmCnt samples from the first channel of the input audio file
501 502
     if( cmAudioFileReadSample(p->afH, frmCnt, chIdx, 1, chs, &actFrmCnt ) != kOkAfRC )
502 503
     {
503
-      rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Audio file read failed.");
504
+      rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Audio file read failed.");
504 505
       break;
505 506
     }
506 507
 
@@ -515,7 +516,7 @@ cmSrRC_t cmSyncRecdAudioFile( cmSyncRecdH_t h, const cmChar_t* fn )
515 516
     // write the audio output samples
516 517
     if( cmAudioFileWriteSample(afH, frmCnt, chCnt, chs ) != kOkAfRC )
517 518
     {
518
-      rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Synchronized audio file write failed.");
519
+      rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Synchronized audio file write failed.");
519 520
       break;
520 521
     }    
521 522
 
@@ -523,12 +524,12 @@ cmSrRC_t cmSyncRecdAudioFile( cmSyncRecdH_t h, const cmChar_t* fn )
523 524
 
524 525
  errLabel:
525 526
   if( cmAudioFileDelete(&afH) != kOkAfRC )
526
-    rc = cmErrMsg(&p->err,kAudioFileFailSrRC,"Synchronized audio file close failed.");
527
+    rc = cmErrMsg(&p->err,kAudioFileFailSyRC,"Synchronized audio file close failed.");
527 528
 
528 529
   return rc;
529 530
 }
530 531
 
531
-cmSrRC_t cmSyncRecdTest( cmCtx_t* ctx )
532
+cmSyRC_t cmSyncRecdTest( cmCtx_t* ctx )
532 533
 {
533 534
   enum
534 535
   {
@@ -536,7 +537,7 @@ cmSrRC_t cmSyncRecdTest( cmCtx_t* ctx )
536 537
     kTestFailRC,
537 538
   };
538 539
 
539
-  cmSrRC_t rc = kOkSrRC;
540
+  cmSyRC_t rc = kOkSyRC;
540 541
   const cmChar_t* srFn = "/home/kevin/temp/kr/sr/sr0.sr";
541 542
   const cmChar_t* aFn  = "/home/kevin/temp/kr/sr/sync_af.aiff";
542 543
   cmErr_t err;
@@ -545,7 +546,7 @@ cmSrRC_t cmSyncRecdTest( cmCtx_t* ctx )
545 546
   cmErrSetup(&err,&ctx->rpt,"SyncRecdTest");
546 547
   
547 548
 
548
-  if((rc = cmSyncRecdOpen(ctx, &srH, srFn )) != kOkSrRC )
549
+  if((rc = cmSyncRecdOpen(ctx, &srH, srFn )) != kOkSyRC )
549 550
   {
550 551
     cmErrMsg(&err,kTestFailRC,"Sync-recd open failed.");
551 552
     goto errLabel;
@@ -555,7 +556,7 @@ cmSrRC_t cmSyncRecdTest( cmCtx_t* ctx )
555 556
   cmSyncRecdAudioFile(srH,aFn);
556 557
 
557 558
  errLabel:
558
-  if((rc = cmSyncRecdFinal(&srH)) != kOkSrRC )
559
+  if((rc = cmSyncRecdFinal(&srH)) != kOkSyRC )
559 560
     cmErrMsg(&err,kTestFailRC,"Sync-recd close failed.");
560 561
 
561 562
   return rc;

+ 11
- 11
cmSyncRecd.h View File

@@ -7,26 +7,26 @@ extern "C" {
7 7
 
8 8
   enum
9 9
   {
10
-    kOkSrRC,
11
-    kFileFailSrRC,
12
-    kAudioFileFailSrRC,
13
-    kInvalidOpSrRC
10
+    kOkSyRC,
11
+    kFileFailSyRC,
12
+    kAudioFileFailSyRC,
13
+    kInvalidOpSyRC
14 14
   };
15 15
 
16 16
   typedef cmHandle_t cmSyncRecdH_t;
17
-  typedef cmRC_t     cmSrRC_t;
17
+  typedef cmRC_t     cmSyRC_t;
18 18
   extern cmSyncRecdH_t cmSyncRecdNullHandle;
19 19
   
20
-  cmSrRC_t cmSyncRecdCreate(  cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn, const cmChar_t* audioFn, double srate, unsigned chCnt, unsigned bits );
21
-  cmSrRC_t cmSyncRecdOpen(    cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn );
22
-  cmSrRC_t cmSyncRecdFinal(   cmSyncRecdH_t* hp );
20
+  cmSyRC_t cmSyncRecdCreate(  cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn, const cmChar_t* audioFn, double srate, unsigned chCnt, unsigned bits );
21
+  cmSyRC_t cmSyncRecdOpen(    cmCtx_t* ctx, cmSyncRecdH_t* hp, const cmChar_t* srFn );
22
+  cmSyRC_t cmSyncRecdFinal(   cmSyncRecdH_t* hp );
23 23
   bool     cmSyncRecdIsValid( cmSyncRecdH_t h );
24 24
 
25
-  cmSrRC_t cmSyncRecdMidiWrite(  cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned status, unsigned d0, unsigned d1 );
26
-  cmSrRC_t cmSyncRecdAudioWrite( cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned smpIdx, const cmSample_t* ch[], unsigned chCnt, unsigned frmCnt );
25
+  cmSyRC_t cmSyncRecdMidiWrite(  cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned status, unsigned d0, unsigned d1 );
26
+  cmSyRC_t cmSyncRecdAudioWrite( cmSyncRecdH_t h, const cmTimeSpec_t* timestamp, unsigned smpIdx, const cmSample_t* ch[], unsigned chCnt, unsigned frmCnt );
27 27
   
28 28
 
29
-  cmSrRC_t cmSyncRecdTest( cmCtx_t* ctx );
29
+  cmSyRC_t cmSyncRecdTest( cmCtx_t* ctx );
30 30
 
31 31
 #ifdef __cplusplus
32 32
 }

+ 5
- 5
dsp/cmDspKr.c View File

@@ -2383,7 +2383,7 @@ cmDspRC_t _cmDspNanoMapSend( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned st, un
2383 2383
 
2384 2384
 void _cmDspNanoMapPgm( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned pgm )
2385 2385
 {
2386
-  cmDspNanoMap_t* p = (cmDspNanoMap_t*)inst;
2386
+  //cmDspNanoMap_t* p = (cmDspNanoMap_t*)inst;
2387 2387
 
2388 2388
   unsigned i;
2389 2389
         
@@ -2430,7 +2430,7 @@ cmDspRC_t _cmDspNanoMapReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_
2430 2430
 
2431 2431
 cmDspRC_t _cmDspNanoMapRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
2432 2432
 {
2433
-  cmDspNanoMap_t* p = (cmDspNanoMap_t*)inst;
2433
+  //cmDspNanoMap_t* p = (cmDspNanoMap_t*)inst;
2434 2434
 
2435 2435
   switch( evt->dstVarId )
2436 2436
   {
@@ -3070,7 +3070,7 @@ cmDspRC_t _cmDspSyncRecdCreateFile( cmDspCtx_t* ctx, cmDspInst_t* inst )
3070 3070
     return cmDspInstErr(ctx,&p->inst,kFileSysFailDspRC,"Sync-recd file name generation failed for dir='%s' and prefix='%s'.",cmStringNullGuard(dir),cmStringNullGuard(srFn));
3071 3071
 
3072 3072
   unsigned bits = cmDspUInt(inst,kBitsSrId);
3073
-  if( cmSyncRecdCreate(  ctx->cmCtx, &p->srH, p->srFn, p->aFn, cmDspSampleRate(ctx), p->chCnt, bits ) != kOkSrRC )
3073
+  if( cmSyncRecdCreate(  ctx->cmCtx, &p->srH, p->srFn, p->aFn, cmDspSampleRate(ctx), p->chCnt, bits ) != kOkSyRC )
3074 3074
     return cmDspInstErr(ctx,&p->inst,kSubSysFailDspRC,"Sync-recd file create failed for '%s'.",p->srFn);
3075 3075
 
3076 3076
   p->smpIdx = 0;
@@ -3152,7 +3152,7 @@ cmDspRC_t _cmDspSyncRecdExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_
3152 3152
   }
3153 3153
 
3154 3154
   if( n>0 && cmSyncRecdIsValid(p->srH ) )
3155
-    if( cmSyncRecdAudioWrite( p->srH, &ctx->ctx->iTimeStamp, p->smpIdx, x, p->chCnt, n ) != kOkSrRC )
3155
+    if( cmSyncRecdAudioWrite( p->srH, &ctx->ctx->iTimeStamp, p->smpIdx, x, p->chCnt, n ) != kOkSyRC )
3156 3156
       return cmDspInstErr(ctx,&p->inst,kSubSysFailDspRC,"Sync-recd audio update failed.");
3157 3157
 
3158 3158
   p->smpIdx += n;
@@ -3179,7 +3179,7 @@ cmDspRC_t _cmDspSyncRecdRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_
3179 3179
         //printf("%i %i\n",cmDspUInt(inst,kD1SrId),cmTimeElapsedMicros(&ts,&p->ats));
3180 3180
 
3181 3181
         if( cmSyncRecdIsValid(p->srH ) )
3182
-          if( cmSyncRecdMidiWrite(p->srH, &ts, cmDspUInt(inst,kStatusSrId), cmDspUInt(inst,kD0SrId), cmDspUInt(inst,kD1SrId) ) != kOkSrRC )
3182
+          if( cmSyncRecdMidiWrite(p->srH, &ts, cmDspUInt(inst,kStatusSrId), cmDspUInt(inst,kD0SrId), cmDspUInt(inst,kD1SrId) ) != kOkSyRC )
3183 3183
             return cmDspInstErr(ctx,&p->inst,kSubSysFailDspRC,"Sync-recd MIDI update failed.");
3184 3184
       }
3185 3185
       break;

Loading…
Cancel
Save