Browse Source

app/cmTimeLine.h/c,cmScoreProc.c:The time-line now takes a prefix path rather

then included explicit paths as part of the time-line data file.
master
kpl 10 years ago
parent
commit
e918c4308b
3 changed files with 44 additions and 16 deletions
  1. 10
    1
      app/cmScoreProc.c
  2. 30
    11
      app/cmTimeLine.c
  3. 4
    4
      app/cmTimeLine.h

+ 10
- 1
app/cmScoreProc.c View File

@@ -85,6 +85,7 @@ cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn  )
85 85
   cmSpRC_t        rc     = kOkSpRC;
86 86
   const cmChar_t* scFn   = NULL;
87 87
   const cmChar_t* tlFn   = NULL;
88
+  const cmChar_t* tlPrefixPath = NULL;
88 89
 
89 90
   p->srate = 96000;
90 91
 
@@ -111,6 +112,14 @@ cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn  )
111 112
     goto errLabel;
112 113
   }
113 114
 
115
+  // get the time line data file prefix path
116
+  if( cmJsonPathToString( p->jsH, NULL, NULL, "tlPrefixPath", &tlPrefixPath ) != kOkJsRC )
117
+  {
118
+    rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to locate the time line data file prefix path in the main resource file:%s",cmStringNullGuard(rsrcFn));
119
+    goto errLabel;
120
+  }
121
+
122
+
114 123
   // read the dynamics reference array
115 124
   if((rc = _cmJsonReadDynArray( p->jsH, &p->dynArray, &p->dynCnt )) != kOkSpRC )
116 125
   {
@@ -127,7 +136,7 @@ cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn  )
127 136
   }
128 137
 
129 138
   // load the time-line file
130
-  if( cmTimeLineInitializeFromFile(ctx, &p->tlH, NULL, NULL, tlFn ) != kOkTlRC )
139
+  if( cmTimeLineInitializeFromFile(ctx, &p->tlH, NULL, NULL, tlFn, tlPrefixPath ) != kOkTlRC )
131 140
   {
132 141
     rc = cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line load failed for time line file:%s.",cmStringNullGuard(tlFn));
133 142
     goto errLabel;

+ 30
- 11
app/cmTimeLine.c View File

@@ -10,6 +10,7 @@
10 10
 #include "cmAudioFile.h"
11 11
 #include "cmMidi.h"
12 12
 #include "cmMidiFile.h"
13
+#include "cmFileSys.h"
13 14
 #include "cmTimeLine.h"
14 15
 
15 16
 // id's used to track the type of a serialized object
@@ -55,6 +56,7 @@ typedef struct
55 56
   unsigned        nextSeqId;
56 57
   cmTlCb_t        cbFunc;
57 58
   void*           cbArg;
59
+  cmChar_t*       prefixPath;
58 60
   unsigned        nextUId;
59 61
   char*           tmpBuf;  
60 62
   unsigned        seqCnt;
@@ -592,10 +594,17 @@ cmTlRC_t _cmTlAllocAudioFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmC
592 594
   cmRC_t            afRC        = cmOkRC;
593 595
   cmTlRC_t          rc;
594 596
   _cmTlObj_t*       op          = NULL;
597
+
598
+  // prepend the time-line path prefix to the filename
599
+  fn = cmFsMakeFn( p->prefixPath, fn, NULL, NULL );
600
+
595 601
   unsigned          recdByteCnt = sizeof(cmTlAudioFile_t) + strlen(fn) + 1;
596 602
 
597 603
   if( cmAudioFileIsValid( afH = cmAudioFileNewOpen(fn, &info, &afRC, p->err.rpt )) == false )
598
-    return cmErrMsg(&p->err,kAudioFileFailTlRC,"The time line audio file '%s' could not be opened.",cmStringNullGuard(fn));
604
+  {
605
+    rc = cmErrMsg(&p->err,kAudioFileFailTlRC,"The time line audio file '%s' could not be opened.",cmStringNullGuard(fn));
606
+    goto errLabel;
607
+  }
599 608
 
600 609
   if((rc = _cmTlAllocRecd(p,nameStr,refIdStr,begSmpIdx,info.frameCnt,kAudioFileTlId,seqId,recdByteCnt,&op)) != kOkTlRC )
601 610
     goto errLabel;
@@ -621,6 +630,8 @@ cmTlRC_t _cmTlAllocAudioFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmC
621 630
   //_cmTlNotifyListener(p, kInsertMsgTlId, op );
622 631
 
623 632
  errLabel:
633
+  cmFsFreeFn(fn);
634
+
624 635
   if( rc != kOkTlRC )
625 636
     cmAudioFileDelete(&afH);
626 637
   
@@ -718,6 +729,9 @@ cmTlRC_t _cmTlAllocMidiFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmCh
718 729
   cmTlRC_t      rc  = kOkTlRC;
719 730
   _cmTlObj_t*   op  = NULL;
720 731
 
732
+  // prepend the time-line path prefix to the filename
733
+  fn = cmFsMakeFn( p->prefixPath, fn, NULL, NULL );
734
+
721 735
   // open the midi file
722 736
   if( cmMidiFileOpen(fn, &mfH, &p->ctx ) != kOkMfRC )
723 737
     return cmErrMsg(&p->err,kMidiFileFailTlRC,"The time line midi file '%s' could not be opened.",cmStringNullGuard(fn));
@@ -763,6 +777,8 @@ cmTlRC_t _cmTlAllocMidiFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmCh
763 777
 
764 778
   
765 779
  errLabel:
780
+  cmFsFreeFn(fn);
781
+
766 782
   if( rc != kOkTlRC )
767 783
   {
768 784
     cmMidiFileClose(&mfH);
@@ -890,6 +906,8 @@ cmTlRC_t _cmTimeLineFinalize( _cmTl_t* p )
890 906
 
891 907
   cmMemPtrFree(&p->tmpBuf);
892 908
 
909
+  cmMemPtrFree(&p->prefixPath);
910
+
893 911
   cmMemPtrFree(&p);
894 912
 
895 913
 
@@ -899,7 +917,7 @@ cmTlRC_t _cmTimeLineFinalize( _cmTl_t* p )
899 917
   return cmErrMsg(&p->err,kFinalizeFailTlRC,"Finalize failed.");
900 918
 }
901 919
 
902
-cmTlRC_t cmTimeLineInitialize( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg )
920
+cmTlRC_t cmTimeLineInitialize( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* prefixPath )
903 921
 {
904 922
   cmTlRC_t rc;
905 923
 
@@ -909,9 +927,10 @@ cmTlRC_t cmTimeLineInitialize( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void*
909 927
   _cmTl_t* p = cmMemAllocZ( _cmTl_t, 1 );
910 928
 
911 929
   cmErrSetup(&p->err,&ctx->rpt,"Time Line");
912
-  p->ctx    = *ctx;
913
-  p->cbFunc = cbFunc;
914
-  p->cbArg  = cbArg;
930
+  p->ctx        = *ctx;
931
+  p->cbFunc     = cbFunc;
932
+  p->cbArg      = cbArg;
933
+  p->prefixPath = cmMemAllocStr(prefixPath);
915 934
 
916 935
   if(cmLHeapIsValid( p->lH = cmLHeapCreate( 8192, ctx )) == false )
917 936
   {
@@ -928,10 +947,10 @@ cmTlRC_t cmTimeLineInitialize( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void*
928 947
   return rc;
929 948
 }
930 949
 
931
-cmTlRC_t   cmTimeLineInitializeFromFile( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* fn )
950
+cmTlRC_t   cmTimeLineInitializeFromFile( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* fn, const cmChar_t* prefixPath )
932 951
 {
933 952
   cmTlRC_t rc;
934
-  if((rc = cmTimeLineInitialize(ctx,hp,cbFunc,cbArg)) != kOkTlRC )
953
+  if((rc = cmTimeLineInitialize(ctx,hp,cbFunc,cbArg,prefixPath)) != kOkTlRC )
935 954
     return rc;
936 955
 
937 956
   return cmTimeLineReadJson(hp,fn);
@@ -1595,12 +1614,12 @@ cmTlRC_t cmTimeLinePrint( cmTlH_t h, cmRpt_t* rpt )
1595 1614
   return kOkTlRC;
1596 1615
 }
1597 1616
 
1598
-cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* fn, cmRpt_t* rpt )
1617
+cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* fn, const cmChar_t* prefixPath, cmRpt_t* rpt )
1599 1618
 {
1600 1619
   cmTlRC_t rc;
1601 1620
   cmTlH_t h = cmTimeLineNullHandle;
1602 1621
 
1603
-  if((rc = cmTimeLineInitializeFromFile(ctx,&h,NULL,NULL,fn)) != kOkTlRC )
1622
+  if((rc = cmTimeLineInitializeFromFile(ctx,&h,NULL,NULL,fn,prefixPath)) != kOkTlRC )
1604 1623
     return rc;
1605 1624
 
1606 1625
   cmTimeLinePrint(h,rpt);
@@ -1609,12 +1628,12 @@ cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* fn, cmRpt_t* rpt )
1609 1628
 }
1610 1629
 
1611 1630
 
1612
-cmTlRC_t     cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* jsFn )
1631
+cmTlRC_t     cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* jsFn, const cmChar_t* prefixPath )
1613 1632
 {
1614 1633
   cmTlRC_t rc  = kOkTlRC;
1615 1634
   cmTlH_t  tlH = cmTimeLineNullHandle;
1616 1635
 
1617
-  if((rc = cmTimeLineInitialize(ctx,&tlH,NULL,NULL)) != kOkTlRC )
1636
+  if((rc = cmTimeLineInitialize(ctx,&tlH,NULL,NULL,prefixPath)) != kOkTlRC )
1618 1637
     return rc;
1619 1638
 
1620 1639
   if((rc = cmTimeLineReadJson(&tlH,jsFn)) != kOkTlRC )

+ 4
- 4
app/cmTimeLine.h View File

@@ -103,8 +103,8 @@ extern "C" {
103 103
   extern cmTlH_t cmTimeLineNullHandle;
104 104
 
105 105
   // 
106
-  cmTlRC_t        cmTimeLineInitialize( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg );
107
-  cmTlRC_t        cmTimeLineInitializeFromFile( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* fn );
106
+  cmTlRC_t        cmTimeLineInitialize( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* prefixPath );
107
+  cmTlRC_t        cmTimeLineInitializeFromFile( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* fn, const cmChar_t* prefixPath );
108 108
 
109 109
   const cmChar_t* cmTimeLineFileName( cmTlH_t h );
110 110
 
@@ -194,9 +194,9 @@ extern "C" {
194 194
   cmTlRC_t cmTimeLineWrite( cmTlH_t h, const cmChar_t* fn );
195 195
 
196 196
   cmTlRC_t cmTimeLinePrint( cmTlH_t h, cmRpt_t* rpt );
197
-  cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* fn, cmRpt_t* rpt );
197
+  cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath, cmRpt_t* rpt );
198 198
 
199
-  cmTlRC_t cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* jsFn  );
199
+  cmTlRC_t cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath  );
200 200
 
201 201
   // The time-line notifies listeners of initialization and finalization
202 202
   // events via calling a cmTlCbFunc_t function.  The argument to this 

Loading…
Cancel
Save