|
@@ -40,8 +40,14 @@ typedef struct
|
40
|
40
|
cmJsonH_t jsH;
|
41
|
41
|
const cmChar_t* tlFn;
|
42
|
42
|
const cmChar_t* scFn;
|
43
|
|
- cmTakeTsb_t* takeV;
|
|
43
|
+ const cmChar_t* tlPrefixPath;
|
|
44
|
+
|
|
45
|
+ cmTakeTsb_t* takeV; // takeV[ takeN ]
|
44
|
46
|
unsigned takeN;
|
|
47
|
+
|
|
48
|
+ cmTlH_t tlH;
|
|
49
|
+ cmScH_t scH;
|
|
50
|
+
|
45
|
51
|
} cmTsb_t;
|
46
|
52
|
|
47
|
53
|
cmTakeSeqBldrH_t cmTakeSeqBldrNullHandle = cmSTATIC_NULL_HANDLE;
|
|
@@ -52,111 +58,86 @@ cmTsb_t* _cmTsbHandleToPtr( cmTakeSeqBldrH_t h )
|
52
|
58
|
return p;
|
53
|
59
|
}
|
54
|
60
|
|
55
|
|
-cmTsbRC_t _cmTsbFree( cmTsb_t* p )
|
|
61
|
+cmTsbRC_t _cmTsbScoreTrkFree( cmTsb_t* p )
|
56
|
62
|
{
|
57
|
|
- cmTsbRC_t rc = kOkTsbRC;
|
|
63
|
+ cmTsbRC_t rc = kOkTsbRC;
|
|
64
|
+ unsigned i;
|
58
|
65
|
|
59
|
66
|
if( cmJsonFinalize(&p->jsH) != kOkJsRC )
|
60
|
67
|
{
|
61
|
68
|
rc = cmErrMsg(&p->err,kJsonFailTsbRC,"JSON object finalize failed.");
|
62
|
69
|
goto errLabel;
|
63
|
70
|
}
|
64
|
|
-
|
65
|
|
- cmMemFree(p);
|
66
|
|
-
|
67
|
|
- errLabel:
|
68
|
|
- return rc;
|
69
|
|
-}
|
70
|
|
-
|
71
|
|
-
|
72
|
|
-cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp )
|
73
|
|
-{
|
74
|
|
- cmTsbRC_t rc;
|
75
|
|
- if((rc = cmTakeSeqBldrFree(hp)) != kOkTsbRC )
|
76
|
|
- return kOkTsbRC;
|
77
|
|
-
|
78
|
|
- cmTsb_t* p = cmMemAllocZ(cmTsb_t,1);
|
79
|
|
-
|
80
|
|
- cmErrSetup(&p->err,&ctx->rpt,"TakeSeqBldr");
|
81
|
|
-
|
82
|
|
- p->ctx = *ctx;
|
83
|
|
- hp->h = p;
|
84
|
|
-
|
85
|
71
|
|
|
72
|
+ for(i=0; i<p->takeN; ++i)
|
|
73
|
+ cmMemPtrFree(&p->takeV[i].noteV);
|
86
|
74
|
|
87
|
|
- return rc;
|
88
|
|
-}
|
|
75
|
+ cmMemPtrFree(&p->takeV);
|
89
|
76
|
|
90
|
|
-cmTsbRC_t cmTakeSeqBldrAllocFn( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp, const cmChar_t* tsbFn )
|
91
|
|
-{
|
92
|
|
- cmTsbRC_t rc;
|
93
|
|
- if((rc = cmTakeSeqBldrAlloc(ctx,hp)) != kOkTsbRC )
|
94
|
|
- return rc;
|
|
77
|
+ if( cmTimeLineFinalize(&p->tlH) != kOkTlRC )
|
|
78
|
+ rc = cmErrMsg(&p->err,kTimeLineFailTsbRC,"Time line object finalize failed.");
|
95
|
79
|
|
96
|
|
- if((rc = cmTakeSeqBldrInitialize(*hp,tsbFn)) != kOkTsbRC )
|
97
|
|
- return rc;
|
|
80
|
+ if( cmScoreFinalize(&p->scH) != kOkScRC )
|
|
81
|
+ rc = cmErrMsg(&p->err,kScoreFailTsbRC,"Score finalize failed.");
|
98
|
82
|
|
|
83
|
+ errLabel:
|
99
|
84
|
return rc;
|
100
|
85
|
}
|
101
|
86
|
|
102
|
|
-cmTsbRC_t cmTakeSeqBldrFree( cmTakeSeqBldrH_t* hp )
|
103
|
|
-{
|
104
|
|
- cmRC_t rc = kOkTsbRC;
|
105
|
|
-
|
106
|
|
- if( hp == NULL || cmTakeSeqBldrIsValid(*hp)==false )
|
107
|
|
- return kOkTsbRC;
|
108
|
87
|
|
109
|
|
- cmTsb_t* p = _cmTsbHandleToPtr(*hp);
|
|
88
|
+cmTsbRC_t _cmTsbFree( cmTsb_t* p )
|
|
89
|
+{
|
|
90
|
+ cmTsbRC_t rc = kOkTsbRC;
|
110
|
91
|
|
111
|
|
- if((rc = _cmTsbFree(p)) != kOkTsbRC )
|
112
|
|
- return rc;
|
|
92
|
+ if((rc = _cmTsbScoreTrkFree(p)) != kOkTsbRC )
|
|
93
|
+ goto errLabel;
|
113
|
94
|
|
114
|
|
- hp->h = NULL;
|
|
95
|
+ cmMemFree(p);
|
115
|
96
|
|
|
97
|
+ errLabel:
|
116
|
98
|
return rc;
|
117
|
99
|
}
|
118
|
100
|
|
119
|
|
-bool cmTakeSeqBldrIsValid( cmTakeSeqBldrH_t h )
|
120
|
|
-{ return h.h != NULL; }
|
121
|
|
-
|
122
|
101
|
|
123
|
|
-cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* tsbFn )
|
|
102
|
+cmTsbRC_t _cmTsbLoadScoreTrkFile( cmTsb_t* p, const cmChar_t* scoreTrkFn )
|
124
|
103
|
{
|
125
|
|
- cmTsbRC_t rc = kOkTsbRC;
|
126
|
|
- cmTsb_t* p = _cmTsbHandleToPtr(h);
|
|
104
|
+ cmTsbRC_t rc = kOkTsbRC;
|
127
|
105
|
cmJsonNode_t* tkArrObj = NULL;
|
128
|
106
|
cmJsRC_t jsRC = kOkJsRC;
|
129
|
107
|
const cmChar_t* errMsg = NULL;
|
130
|
108
|
unsigned i;
|
131
|
109
|
|
132
|
110
|
// initialize the TSB json object
|
133
|
|
- if(( rc = cmJsonInitializeFromFile(&p->jsH,tsbFn,&p->ctx)) != kOkJsRC )
|
|
111
|
+ if(( rc = cmJsonInitializeFromFile(&p->jsH,scoreTrkFn,&p->ctx)) != kOkJsRC )
|
134
|
112
|
{
|
135
|
|
- rc = cmErrMsg(&p->err,kJsonFailTsbRC,"The Take Sequence Builder JSON file object could not be initialized from '%s'.",cmStringNullGuard(tsbFn));
|
|
113
|
+ rc = cmErrMsg(&p->err,kJsonFailTsbRC,"The Take Sequence Builder JSON file object could not be initialized from '%s'.",cmStringNullGuard(scoreTrkFn));
|
136
|
114
|
goto errLabel;
|
137
|
115
|
}
|
138
|
116
|
|
139
|
117
|
// parse the header
|
140
|
118
|
if((jsRC = cmJsonMemberValues( cmJsonRoot(p->jsH), &errMsg,
|
141
|
|
- "tlFn",kStringTId,&p->tlFn,
|
142
|
|
- "scFn",kStringTId,&p->scFn,
|
143
|
|
- "takeArray",kArrayTId | kOptArgJsFl,&tkArrObj,
|
|
119
|
+ "timeLineFn", kStringTId, &p->tlFn,
|
|
120
|
+ "scoreFn", kStringTId, &p->scFn,
|
|
121
|
+ "tlPrefixPath", kStringTId, &p->tlPrefixPath,
|
|
122
|
+ "takeArray", kArrayTId | kOptArgJsFl, &tkArrObj,
|
144
|
123
|
0 )) != kOkJsRC )
|
145
|
124
|
{
|
146
|
125
|
if( jsRC == kNodeNotFoundJsRC && errMsg != NULL )
|
147
|
126
|
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file header parse failed missing required field:'%s'",errMsg);
|
148
|
127
|
else
|
149
|
128
|
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file header parse failed.");
|
|
129
|
+
|
|
130
|
+ goto errLabel;
|
150
|
131
|
}
|
151
|
132
|
|
152
|
133
|
// count of take records
|
153
|
|
- unsigned tkArrN = cmJsonChildCount(tkArrObj);
|
|
134
|
+ p->takeN = cmJsonChildCount(tkArrObj);
|
154
|
135
|
|
155
|
136
|
// array of take records
|
156
|
|
- p->takeV = cmMemAllocZ(cmTakeTsb_t,tkArrN);
|
|
137
|
+ p->takeV = cmMemAllocZ(cmTakeTsb_t,p->takeN);
|
157
|
138
|
|
158
|
139
|
// for each take record
|
159
|
|
- for(i=0; i<tkArrN; ++i)
|
|
140
|
+ for(i=0; i<p->takeN; ++i)
|
160
|
141
|
{
|
161
|
142
|
cmJsonNode_t* takeObj = NULL;
|
162
|
143
|
cmJsonNode_t* noteArrObj = NULL;
|
|
@@ -179,7 +160,9 @@ cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* tsbFn )
|
179
|
160
|
if( jsRC == kNodeNotFoundJsRC && errMsg != NULL )
|
180
|
161
|
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file take record parse failed missing required field:'%s'",errMsg);
|
181
|
162
|
else
|
182
|
|
- rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file take record parse failed.");
|
|
163
|
+ rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file take record parse failed.");
|
|
164
|
+
|
|
165
|
+ goto errLabel;
|
183
|
166
|
}
|
184
|
167
|
|
185
|
168
|
// get the count of note records
|
|
@@ -211,21 +194,103 @@ cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* tsbFn )
|
211
|
194
|
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file note record parse failed missing required field:'%s'",errMsg);
|
212
|
195
|
else
|
213
|
196
|
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file note record parse failed.");
|
|
197
|
+
|
|
198
|
+ goto errLabel;
|
214
|
199
|
}
|
215
|
200
|
}
|
216
|
201
|
}
|
|
202
|
+
|
|
203
|
+ errLabel:
|
|
204
|
+ if( rc != kOkTsbRC )
|
|
205
|
+ rc = _cmTsbScoreTrkFree(p);
|
|
206
|
+
|
|
207
|
+ return rc;
|
|
208
|
+}
|
|
209
|
+
|
|
210
|
+cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp )
|
|
211
|
+{
|
|
212
|
+ cmTsbRC_t rc;
|
|
213
|
+ if((rc = cmTakeSeqBldrFree(hp)) != kOkTsbRC )
|
|
214
|
+ return kOkTsbRC;
|
|
215
|
+
|
|
216
|
+ cmTsb_t* p = cmMemAllocZ(cmTsb_t,1);
|
|
217
|
+
|
|
218
|
+ cmErrSetup(&p->err,&ctx->rpt,"TakeSeqBldr");
|
|
219
|
+
|
|
220
|
+ p->ctx = *ctx;
|
|
221
|
+ hp->h = p;
|
|
222
|
+
|
|
223
|
+ return rc;
|
|
224
|
+}
|
|
225
|
+
|
|
226
|
+cmTsbRC_t cmTakeSeqBldrAllocFn( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp, const cmChar_t* scoreTrkFn )
|
|
227
|
+{
|
|
228
|
+ cmTsbRC_t rc;
|
|
229
|
+ if((rc = cmTakeSeqBldrAlloc(ctx,hp)) != kOkTsbRC )
|
|
230
|
+ return rc;
|
|
231
|
+
|
|
232
|
+ if((rc = cmTakeSeqBldrInitialize(*hp,scoreTrkFn)) != kOkTsbRC )
|
|
233
|
+ return rc;
|
|
234
|
+
|
|
235
|
+ return rc;
|
|
236
|
+}
|
|
237
|
+
|
|
238
|
+cmTsbRC_t cmTakeSeqBldrFree( cmTakeSeqBldrH_t* hp )
|
|
239
|
+{
|
|
240
|
+ cmRC_t rc = kOkTsbRC;
|
|
241
|
+
|
|
242
|
+ if( hp == NULL || cmTakeSeqBldrIsValid(*hp)==false )
|
|
243
|
+ return kOkTsbRC;
|
|
244
|
+
|
|
245
|
+ cmTsb_t* p = _cmTsbHandleToPtr(*hp);
|
|
246
|
+
|
|
247
|
+ if((rc = _cmTsbFree(p)) != kOkTsbRC )
|
|
248
|
+ return rc;
|
|
249
|
+
|
|
250
|
+ hp->h = NULL;
|
|
251
|
+
|
|
252
|
+ return rc;
|
|
253
|
+}
|
|
254
|
+
|
|
255
|
+bool cmTakeSeqBldrIsValid( cmTakeSeqBldrH_t h )
|
|
256
|
+{ return h.h != NULL; }
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* scoreTrkFn )
|
|
260
|
+{
|
|
261
|
+ cmTsbRC_t rc = kOkTsbRC;
|
|
262
|
+ cmTsb_t* p = _cmTsbHandleToPtr(h);
|
|
263
|
+
|
|
264
|
+ if(( rc = _cmTsbLoadScoreTrkFile( p, scoreTrkFn )) != kOkTsbRC )
|
|
265
|
+ return rc;
|
217
|
266
|
|
|
267
|
+ if( cmTimeLineInitializeFromFile(&p->ctx, &p->tlH, NULL, NULL, p->tlFn, p->tlPrefixPath ) != kOkTlRC )
|
|
268
|
+ {
|
|
269
|
+ rc = cmErrMsg(&p->err,kTimeLineFailTsbRC,"The time-line file '%s' could not be loaded.",p->tlFn);
|
|
270
|
+ goto errLabel;
|
|
271
|
+ }
|
|
272
|
+
|
|
273
|
+ if( cmScoreInitialize(&p->ctx, &p->scH, p->scFn, 0, NULL, 0, NULL, NULL, cmSymTblNullHandle ) != kOkScRC )
|
|
274
|
+ {
|
|
275
|
+ rc = cmErrMsg(&p->err,kScoreFailTsbRC,"The score file '%s' could not be loaded.",p->scFn);
|
|
276
|
+ goto errLabel;
|
|
277
|
+ }
|
|
278
|
+
|
218
|
279
|
errLabel:
|
|
280
|
+ if( rc != kOkTsbRC )
|
|
281
|
+ _cmTsbScoreTrkFree(p);
|
|
282
|
+
|
|
283
|
+
|
219
|
284
|
return rc;
|
220
|
285
|
}
|
221
|
286
|
|
222
|
|
-cmTsbRC_t cmTakeSeqBldrLoadSection( cmTakeSeqBldrH_t h, unsigned tlMarkUid, bool overwriteFL )
|
|
287
|
+cmTsbRC_t cmTakeSeqBldrLoadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid, bool overwriteFL )
|
223
|
288
|
{
|
224
|
289
|
cmTsbRC_t rc = kOkTsbRC;
|
225
|
290
|
return rc;
|
226
|
291
|
}
|
227
|
292
|
|
228
|
|
-cmTsbRC_t cmTakeSeqBldrUnloadSection( cmTakeSeqBldrH_t h, unsigned tlMarkUid )
|
|
293
|
+cmTsbRC_t cmTakeSeqBldrUnloadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid )
|
229
|
294
|
{
|
230
|
295
|
cmTsbRC_t rc = kOkTsbRC;
|
231
|
296
|
return rc;
|
|
@@ -269,12 +334,12 @@ cmTsbRC_t cmTakeSeqBldrWriteMidiFile( cmTakeSeqBldrH_t h, const char* fn )
|
269
|
334
|
|
270
|
335
|
cmTsbRC_t cmTakeSeqBldrTest( cmCtx_t* ctx )
|
271
|
336
|
{
|
272
|
|
- const cmChar_t* tsbFn = "/home/kevin/src/cmkc/src/kc/data/assoc0.js";
|
|
337
|
+ const cmChar_t* scoreTrkFn = "/home/kevin/src/cmkc/src/kc/data/assoc0.js";
|
273
|
338
|
cmTakeSeqBldrH_t tsbH = cmTakeSeqBldrNullHandle;
|
274
|
339
|
cmTsbRC_t tsbRC = kOkTsbRC;
|
275
|
340
|
|
276
|
|
- if((tsbRC = cmTakeSeqBldrAllocFn(ctx, &tsbH, tsbFn )) != kOkTsbRC )
|
277
|
|
- return cmErrMsg(&ctx->err,tsbRC,"TSB Allocate and parse '%s' failed.",tsbFn);
|
|
341
|
+ if((tsbRC = cmTakeSeqBldrAllocFn(ctx, &tsbH, scoreTrkFn )) != kOkTsbRC )
|
|
342
|
+ return cmErrMsg(&ctx->err,tsbRC,"TSB Allocate and parse '%s' failed.",scoreTrkFn);
|
278
|
343
|
|
279
|
344
|
if((tsbRC = cmTakeSeqBldrFree(&tsbH)) != kOkTsbRC )
|
280
|
345
|
return cmErrMsg(&ctx->err,tsbRC,"TSB Free failed.");
|