|
@@ -0,0 +1,157 @@
|
|
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 "cmMallocDebug.h"
|
|
8
|
+#include "cmLinkedHeap.h"
|
|
9
|
+#include "cmSymTbl.h"
|
|
10
|
+#include "cmJson.h"
|
|
11
|
+#include "cmMidi.h"
|
|
12
|
+#include "cmMidiFile.h"
|
|
13
|
+#include "cmAudioFile.h"
|
|
14
|
+#include "cmScore.h"
|
|
15
|
+#include "cmTimeLine.h"
|
|
16
|
+#include "cmScoreProc.h"
|
|
17
|
+
|
|
18
|
+enum
|
|
19
|
+{
|
|
20
|
+ kOkSpRC,
|
|
21
|
+ kJsonFailSpRC,
|
|
22
|
+ kScoreFailSpRC,
|
|
23
|
+ kTimeLineFailSpRC
|
|
24
|
+};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+typedef struct
|
|
28
|
+{
|
|
29
|
+ cmErr_t err;
|
|
30
|
+ cmScH_t scH;
|
|
31
|
+ const cmChar_t* tlFn;
|
|
32
|
+ cmTlH_t tlH;
|
|
33
|
+ cmJsonH_t jsH;
|
|
34
|
+ unsigned* dynArray;
|
|
35
|
+ unsigned dynCnt;
|
|
36
|
+ double srate;
|
|
37
|
+} cmSp_t;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+cmSpRC_t _cmJsonReadDynArray( cmJsonH_t jsH, unsigned** dynArray, unsigned* dynCnt )
|
|
41
|
+{
|
|
42
|
+ cmJsonNode_t* np;
|
|
43
|
+ int i;
|
|
44
|
+
|
|
45
|
+ if( cmJsonPathToArray(jsH, NULL, NULL, "dynRef", &np ) != kOkJsRC )
|
|
46
|
+ return kJsonFailSpRC;
|
|
47
|
+
|
|
48
|
+ *dynCnt = cmJsonChildCount(np);
|
|
49
|
+
|
|
50
|
+ *dynArray = cmMemAllocZ(unsigned,*dynCnt);
|
|
51
|
+
|
|
52
|
+ for(i=0; i<*dynCnt; ++i)
|
|
53
|
+ if( cmJsonUIntValue( cmJsonArrayElement(np,i), (*dynArray)+i ) != kOkJsRC )
|
|
54
|
+ return kJsonFailSpRC;
|
|
55
|
+
|
|
56
|
+ return kOkSpRC;
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
|
|
60
|
+{
|
|
61
|
+ cmSpRC_t rc = kOkSpRC;
|
|
62
|
+ const cmChar_t* scFn = NULL;
|
|
63
|
+ const cmChar_t* tlFn = NULL;
|
|
64
|
+
|
|
65
|
+ p->srate = 96000;
|
|
66
|
+
|
|
67
|
+ cmErrSetup(&p->err,&ctx->rpt,"ScoreProc");
|
|
68
|
+
|
|
69
|
+ // open the resource file
|
|
70
|
+ if( cmJsonInitializeFromFile( &p->jsH, rsrcFn, ctx ) != kOkJsRC )
|
|
71
|
+ {
|
|
72
|
+ rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to load the main resource file:%s.",cmStringNullGuard(rsrcFn));
|
|
73
|
+ goto errLabel;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ // get the time line fn
|
|
77
|
+ if( cmJsonPathToString( p->jsH, NULL, NULL, "timeLineFn", &tlFn ) != kOkJsRC )
|
|
78
|
+ {
|
|
79
|
+ rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to locate the time line file name in the main resource file:%s",cmStringNullGuard(rsrcFn));
|
|
80
|
+ goto errLabel;
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ // get the score file name
|
|
84
|
+ if( cmJsonPathToString( p->jsH, NULL, NULL, "scoreFn", &scFn ) != kOkJsRC )
|
|
85
|
+ {
|
|
86
|
+ rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to locate the score file name in the main resource file:%s",cmStringNullGuard(rsrcFn));
|
|
87
|
+ goto errLabel;
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ // read the dynamics reference array
|
|
91
|
+ if((rc = _cmJsonReadDynArray( p->jsH, &p->dynArray, &p->dynCnt )) != kOkSpRC )
|
|
92
|
+ {
|
|
93
|
+ rc = cmErrMsg(&p->err,rc,"Unable to read dynamics reference array resource from the main resource file:%s",cmStringNullGuard(rsrcFn));
|
|
94
|
+ goto errLabel;
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+ // load the score file
|
|
99
|
+ if( cmScoreInitialize(ctx, &p->scH, scFn, p->srate, NULL, 0, NULL, NULL, cmSymTblNullHandle ) != kOkScRC )
|
|
100
|
+ {
|
|
101
|
+ rc = cmErrMsg(&p->err,kScoreFailSpRC,"Score load failed for score file:%s.",cmStringNullGuard(scFn));
|
|
102
|
+ goto errLabel;
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ if( cmTimeLineInitialize(ctx, &p->tlH, NULL, NULL ) != kOkTlRC )
|
|
106
|
+ {
|
|
107
|
+ rc = cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line load failed for time line file:%s.",cmStringNullGuard(tlFn));
|
|
108
|
+ goto errLabel;
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ errLabel:
|
|
112
|
+ return rc;
|
|
113
|
+}
|
|
114
|
+
|
|
115
|
+cmSpRC_t _cmScoreProcFinal( cmSp_t* p )
|
|
116
|
+{
|
|
117
|
+ cmSpRC_t rc = kOkSpRC;
|
|
118
|
+
|
|
119
|
+ if( cmScoreFinalize(&p->scH) != kOkScRC )
|
|
120
|
+ cmErrMsg(&p->err,kScoreFailSpRC,"Score finalize failed.");
|
|
121
|
+
|
|
122
|
+ if( cmTimeLineFinalize(&p->tlH) != kOkTlRC )
|
|
123
|
+ cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line finalize failed.");
|
|
124
|
+
|
|
125
|
+ if( cmJsonFinalize(&p->jsH) != kOkJsRC )
|
|
126
|
+ cmErrMsg(&p->err,kJsonFailSpRC,"JSON finalize failed.");
|
|
127
|
+
|
|
128
|
+ cmMemFree(p->dynArray);
|
|
129
|
+
|
|
130
|
+ return rc;
|
|
131
|
+}
|
|
132
|
+
|
|
133
|
+unsigned cmScoreProc(cmCtx_t* ctx)
|
|
134
|
+{
|
|
135
|
+ cmSpRC_t rc = kOkSpRC;
|
|
136
|
+ const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js";
|
|
137
|
+ cmSp_t sp;
|
|
138
|
+
|
|
139
|
+ memset(&sp,0,sizeof(sp));
|
|
140
|
+
|
|
141
|
+ cmRptPrintf(&ctx->rpt,"Score Proc Start\n");
|
|
142
|
+
|
|
143
|
+ if((rc = _cmScoreProcInit(ctx,&sp,rsrcFn)) != kOkSpRC )
|
|
144
|
+ goto errLabel;
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+ errLabel:
|
|
150
|
+ _cmScoreProcFinal(&sp);
|
|
151
|
+
|
|
152
|
+ cmRptPrintf(&ctx->rpt,"Score Proc End\n");
|
|
153
|
+
|
|
154
|
+ return rc;
|
|
155
|
+
|
|
156
|
+}
|
|
157
|
+
|