|
@@ -24,6 +24,7 @@
|
24
|
24
|
#include "cmOp.h"
|
25
|
25
|
#include "cmMath.h"
|
26
|
26
|
|
|
27
|
+
|
27
|
28
|
#include "cmAudioFile.h"
|
28
|
29
|
#include "cmFileSys.h"
|
29
|
30
|
#include "cmProcObj.h"
|
|
@@ -33,6 +34,12 @@
|
33
|
34
|
#include "cmProc2.h"
|
34
|
35
|
#include "cmVectOpsTemplateMain.h"
|
35
|
36
|
|
|
37
|
+#include "cmAudioFile.h"
|
|
38
|
+#include "cmMidiFile.h"
|
|
39
|
+#include "cmTimeLine.h"
|
|
40
|
+#include "cmScore.h"
|
|
41
|
+#include "cmProc4.h"
|
|
42
|
+
|
36
|
43
|
enum
|
37
|
44
|
{
|
38
|
45
|
kWndSmpCntKrId,
|
|
@@ -227,12 +234,20 @@ struct cmDspClass_str* cmKrClassCons( cmDspCtx_t* ctx )
|
227
|
234
|
|
228
|
235
|
|
229
|
236
|
//==========================================================================================================================================
|
|
237
|
+// Time Line UI Object
|
|
238
|
+
|
230
|
239
|
enum
|
231
|
240
|
{
|
232
|
|
- kValTlId,
|
233
|
|
- kLblTlId,
|
234
|
241
|
kTlFileTlId,
|
235
|
|
- kAudPathTlId
|
|
242
|
+ kAudPathTlId,
|
|
243
|
+ kSelTlId,
|
|
244
|
+ kAudFnTlId,
|
|
245
|
+ kMidiFnTlId,
|
|
246
|
+ kBegAudSmpIdxTlId,
|
|
247
|
+ kEndAudSmpIdxTlId,
|
|
248
|
+ kBegMidiSmpIdxTlId,
|
|
249
|
+ kEndMidiSmpIdxTlId
|
|
250
|
+
|
236
|
251
|
};
|
237
|
252
|
|
238
|
253
|
cmDspClass_t _cmTimeLineDC;
|
|
@@ -240,38 +255,113 @@ cmDspClass_t _cmTimeLineDC;
|
240
|
255
|
typedef struct
|
241
|
256
|
{
|
242
|
257
|
cmDspInst_t inst;
|
|
258
|
+ cmTlH_t tlH;
|
243
|
259
|
} cmDspTimeLine_t;
|
244
|
260
|
|
245
|
261
|
cmDspInst_t* _cmDspTimeLineAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
246
|
262
|
{
|
247
|
263
|
cmDspVarArg_t args[] =
|
248
|
264
|
{
|
249
|
|
- { "val", kValTlId, 0, 0, kInDsvFl | kOutDsvFl | kStrzDsvFl | kReqArgDsvFl | kSendDfltDsvFl, "Current string"},
|
250
|
|
- { "lbl", kLblTlId, 0, 0, kStrzDsvFl | kOptArgDsvFl, "Label"},
|
|
265
|
+ { "tlfile", kTlFileTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Time line file." },
|
|
266
|
+ { "path", kAudPathTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Audio path" },
|
|
267
|
+ { "sel", kSelTlId, 0, 0, kInDsvFl | kInDsvFl | kOutDsvFl | kUIntDsvFl, "Selected marker id."},
|
|
268
|
+ { "afn", kAudFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected Audio file." },
|
|
269
|
+ { "mfn", kMidiFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected MIDI file." },
|
|
270
|
+ { "absi", kBegAudSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "Begin audio sample index."},
|
|
271
|
+ { "aesi", kEndAudSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "End audio sample index."},
|
|
272
|
+ { "mbsi", kBegMidiSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "Begin MIDI sample index."},
|
|
273
|
+ { "mesi", kEndMidiSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "End MIDI sample index."},
|
251
|
274
|
{ NULL, 0, 0, 0, 0 }
|
252
|
275
|
};
|
253
|
276
|
|
254
|
277
|
cmDspTimeLine_t* p = cmDspInstAlloc(cmDspTimeLine_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
278
|
+
|
|
279
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kSelTlId, 0, cmInvalidId);
|
|
280
|
+ cmDspSetDefaultStrcz(ctx, &p->inst, kAudFnTlId, NULL, "");
|
|
281
|
+ cmDspSetDefaultStrcz(ctx, &p->inst, kMidiFnTlId, NULL, "");
|
|
282
|
+ cmDspSetDefaultInt( ctx, &p->inst, kBegAudSmpIdxTlId, 0, cmInvalidIdx);
|
|
283
|
+ cmDspSetDefaultInt( ctx, &p->inst, kEndAudSmpIdxTlId, 0, cmInvalidIdx);
|
|
284
|
+ cmDspSetDefaultInt( ctx, &p->inst, kBegMidiSmpIdxTlId, 0, cmInvalidIdx);
|
|
285
|
+ cmDspSetDefaultInt( ctx, &p->inst, kEndMidiSmpIdxTlId, 0, cmInvalidIdx);
|
255
|
286
|
|
256
|
287
|
// create the UI control
|
257
|
|
- cmDspUiTimeLineCreate(ctx,&p->inst,kValTlId,kLblTlId,kTlFileTlId,kAudPathTlId);
|
|
288
|
+ cmDspUiTimeLineCreate(ctx,&p->inst,kTlFileTlId,kAudPathTlId,kSelTlId);
|
|
289
|
+
|
|
290
|
+ p->tlH = cmTimeLineNullHandle;
|
258
|
291
|
|
259
|
292
|
return &p->inst;
|
260
|
293
|
}
|
261
|
294
|
|
|
295
|
+cmDspRC_t _cmDspTimeLineFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
296
|
+{
|
|
297
|
+ cmDspRC_t rc = kOkDspRC;
|
|
298
|
+ cmDspTimeLine_t* p = (cmDspTimeLine_t*)inst;
|
|
299
|
+
|
|
300
|
+ if( cmTimeLineFinalize(&p->tlH) != kOkTlRC )
|
|
301
|
+ return cmErrMsg(&inst->classPtr->err, kInstFinalFailDspRC, "Time-line finalize failed.");
|
|
302
|
+
|
|
303
|
+ return rc;
|
|
304
|
+}
|
|
305
|
+
|
|
306
|
+
|
262
|
307
|
cmDspRC_t _cmDspTimeLineReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
263
|
308
|
{
|
|
309
|
+ cmDspRC_t rc = kOkDspRC;
|
|
310
|
+ cmDspTimeLine_t* p = (cmDspTimeLine_t*)inst;
|
|
311
|
+
|
264
|
312
|
cmDspApplyAllDefaults(ctx,inst);
|
265
|
|
- return kOkDspRC;
|
|
313
|
+
|
|
314
|
+ const cmChar_t* tlFn;
|
|
315
|
+ if((tlFn = cmDspStrcz(inst, kTlFileTlId )) != NULL )
|
|
316
|
+ if( cmTimeLineInitializeFromFile(ctx->cmCtx, &p->tlH, NULL, NULL, tlFn ) != kOkTlRC )
|
|
317
|
+ rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "Time-line file open failed.");
|
|
318
|
+
|
|
319
|
+ return rc;
|
266
|
320
|
}
|
267
|
321
|
|
268
|
322
|
cmDspRC_t _cmDspTimeLineRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
269
|
323
|
{
|
|
324
|
+ cmDspTimeLine_t* p = (cmDspTimeLine_t*)inst;
|
270
|
325
|
|
271
|
326
|
switch( evt->dstVarId )
|
272
|
327
|
{
|
273
|
|
- case kValTlId:
|
274
|
|
- cmDspSetEvent(ctx,inst,evt);
|
|
328
|
+ case kSelTlId:
|
|
329
|
+ {
|
|
330
|
+ unsigned markerId;
|
|
331
|
+ cmDspSetEvent(ctx,inst,evt);
|
|
332
|
+
|
|
333
|
+ // get the id of the selected marker
|
|
334
|
+ if((markerId = cmDspUInt(inst,kSelTlId)) != cmInvalidId )
|
|
335
|
+ {
|
|
336
|
+ // get the marker object
|
|
337
|
+ cmTlObj_t* op;
|
|
338
|
+ if((op = cmTimeLineIdToObj(p->tlH, cmInvalidId, markerId )) != NULL )
|
|
339
|
+ {
|
|
340
|
+ assert(op->typeId == kMarkerTlId);
|
|
341
|
+
|
|
342
|
+ cmDspSetInt(ctx, inst, kBegAudSmpIdxTlId, op->begSmpIdx );
|
|
343
|
+ cmDspSetInt(ctx, inst, kEndAudSmpIdxTlId, op->begSmpIdx + op->durSmpCnt );
|
|
344
|
+
|
|
345
|
+ // locate the audio file assoc'd with the marker
|
|
346
|
+ cmTlAudioFile_t* afp;
|
|
347
|
+ if((afp = cmTimeLineAudioFileAtTime(p->tlH,op->seqId,op->seqSmpIdx)) != NULL)
|
|
348
|
+ cmDspSetStrcz(ctx, inst, kAudFnTlId, afp->fn );
|
|
349
|
+
|
|
350
|
+ // locate the midi file assoc'd with the marker
|
|
351
|
+ cmTlMidiFile_t* mfp;
|
|
352
|
+ if((mfp = cmTimeLineMidiFileAtTime(p->tlH,op->seqId,op->seqSmpIdx)) != NULL )
|
|
353
|
+ {
|
|
354
|
+ cmDspSetInt(ctx, inst, kBegMidiSmpIdxTlId, op->seqSmpIdx - mfp->obj.seqSmpIdx );
|
|
355
|
+ cmDspSetInt(ctx, inst, kEndMidiSmpIdxTlId, op->seqSmpIdx + op->durSmpCnt - mfp->obj.seqSmpIdx );
|
|
356
|
+
|
|
357
|
+ cmDspSetStrcz(ctx, inst, kMidiFnTlId, mfp->fn );
|
|
358
|
+ }
|
|
359
|
+ }
|
|
360
|
+
|
|
361
|
+ }
|
|
362
|
+
|
|
363
|
+ }
|
|
364
|
+
|
275
|
365
|
break;
|
276
|
366
|
|
277
|
367
|
default:
|
|
@@ -286,7 +376,7 @@ struct cmDspClass_str* cmTimeLineClassCons( cmDspCtx_t* ctx )
|
286
|
376
|
cmDspClassSetup(&_cmTimeLineDC,ctx,"TimeLine",
|
287
|
377
|
NULL,
|
288
|
378
|
_cmDspTimeLineAlloc,
|
289
|
|
- NULL,
|
|
379
|
+ _cmDspTimeLineFree,
|
290
|
380
|
_cmDspTimeLineReset,
|
291
|
381
|
NULL,
|
292
|
382
|
_cmDspTimeLineRecv,
|
|
@@ -296,3 +386,339 @@ struct cmDspClass_str* cmTimeLineClassCons( cmDspCtx_t* ctx )
|
296
|
386
|
return &_cmTimeLineDC;
|
297
|
387
|
}
|
298
|
388
|
|
|
389
|
+//==========================================================================================================================================
|
|
390
|
+// MIDI File Player
|
|
391
|
+
|
|
392
|
+enum
|
|
393
|
+{
|
|
394
|
+ kFnMfId,
|
|
395
|
+ kSelMfId,
|
|
396
|
+ kBsiMfId,
|
|
397
|
+ kEsiMfId,
|
|
398
|
+ kStatusMfId,
|
|
399
|
+ kD0MfId,
|
|
400
|
+ kD1MfId
|
|
401
|
+};
|
|
402
|
+
|
|
403
|
+cmDspClass_t _cmMidiFilePlayDC;
|
|
404
|
+
|
|
405
|
+typedef struct
|
|
406
|
+{
|
|
407
|
+ cmDspInst_t inst;
|
|
408
|
+ cmMidiFileH_t mfH;
|
|
409
|
+ unsigned curMsgIdx; // current midi file msg index
|
|
410
|
+ int csi; // current sample index
|
|
411
|
+ int bsi; // starting sample index
|
|
412
|
+ int esi; // ending sample index
|
|
413
|
+ unsigned startSymId;
|
|
414
|
+ unsigned stopSymId;
|
|
415
|
+ unsigned contSymId;
|
|
416
|
+} cmDspMidiFilePlay_t;
|
|
417
|
+
|
|
418
|
+/*
|
|
419
|
+ 'bsi' and 'esi' give the starting and ending sample for MIDI file playback.
|
|
420
|
+ These indexes are relative to the start of the file.
|
|
421
|
+ When the player recieves a 'start' msg it sets the current sample index
|
|
422
|
+ 'si' to 'bsi' and begins scanning for the next note to play.
|
|
423
|
+ On each call to the _cmDspMidiFilePlayExec() msgs that fall in the interval
|
|
424
|
+ si:si+sPc-1 will be transmitted. (where sPc are the number of samples per DSP cycle).
|
|
425
|
+ */
|
|
426
|
+
|
|
427
|
+cmDspInst_t* _cmDspMidiFilePlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
428
|
+{
|
|
429
|
+ cmDspVarArg_t args[] =
|
|
430
|
+ {
|
|
431
|
+ { "fn", kFnMfId, 0, 0, kInDsvFl | kStrzDsvFl, "File name"},
|
|
432
|
+ { "sel", kSelMfId, 0, 0, kInDsvFl | kSymDsvFl, "start | stop | continue" },
|
|
433
|
+ { "bsi", kBsiMfId, 0, 0, kInDsvFl | kIntDsvFl, "Starting sample." },
|
|
434
|
+ { "esi", kEsiMfId, 0, 0, kInDsvFl | kIntDsvFl, "Ending sample."},
|
|
435
|
+ { "status", kStatusMfId, 0, 0, kOutDsvFl | kIntDsvFl, "Status value output" },
|
|
436
|
+ { "d0", kD0MfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 0" },
|
|
437
|
+ { "d1", kD1MfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 1" },
|
|
438
|
+ { NULL, 0, 0, 0, 0 }
|
|
439
|
+ };
|
|
440
|
+
|
|
441
|
+ cmDspMidiFilePlay_t* p = cmDspInstAlloc(cmDspMidiFilePlay_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
442
|
+
|
|
443
|
+ p->startSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"start");
|
|
444
|
+ p->stopSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"stop");
|
|
445
|
+ p->contSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"continue");
|
|
446
|
+ p->mfH = cmMidiFileNullHandle;
|
|
447
|
+
|
|
448
|
+ cmDspSetDefaultStrcz( ctx, &p->inst, kFnMfId, NULL, "");
|
|
449
|
+ cmDspSetDefaultSymbol(ctx, &p->inst, kSelMfId, p->stopSymId);
|
|
450
|
+ cmDspSetDefaultInt( ctx, &p->inst, kBsiMfId, 0, 0);
|
|
451
|
+ cmDspSetDefaultInt( ctx, &p->inst, kEsiMfId, 0, 0);
|
|
452
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kStatusMfId, 0, 0);
|
|
453
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kD0MfId, 0, 0);
|
|
454
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kD1MfId, 0, 0);
|
|
455
|
+
|
|
456
|
+ return &p->inst;
|
|
457
|
+}
|
|
458
|
+
|
|
459
|
+cmDspRC_t _cmDspMidiFilePlayFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
460
|
+{
|
|
461
|
+ cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
462
|
+ if( cmMidiFileClose(&p->mfH) )
|
|
463
|
+ return cmErrMsg(&inst->classPtr->err, kInstFinalFailDspRC, "MIDI file close failed.");
|
|
464
|
+ return kOkDspRC;
|
|
465
|
+}
|
|
466
|
+
|
|
467
|
+// return the index of the msg following smpIdx
|
|
468
|
+unsigned _cmDspMidiFilePlaySeekMsgIdx( cmDspCtx_t* ctx, cmDspMidiFilePlay_t* p, unsigned smpIdx )
|
|
469
|
+{
|
|
470
|
+ unsigned i;
|
|
471
|
+ unsigned n = cmMidiFileMsgCount(p->mfH);
|
|
472
|
+ const cmMidiTrackMsg_t** a = cmMidiFileMsgArray(p->mfH);
|
|
473
|
+
|
|
474
|
+ for(i=0; i<n; ++i)
|
|
475
|
+ if( a[i]->dtick > smpIdx )
|
|
476
|
+ break;
|
|
477
|
+
|
|
478
|
+ return i==n ? cmInvalidIdx : i;
|
|
479
|
+}
|
|
480
|
+
|
|
481
|
+cmDspRC_t _cmDspMidiFilePlayOpen(cmDspCtx_t* ctx, cmDspInst_t* inst )
|
|
482
|
+{
|
|
483
|
+ cmDspRC_t rc = kOkDspRC;
|
|
484
|
+ const cmChar_t* fn = cmDspStrcz(inst,kFnMfId);
|
|
485
|
+ cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
486
|
+
|
|
487
|
+ if( fn==NULL || strlen(fn)==0 )
|
|
488
|
+ return rc;
|
|
489
|
+
|
|
490
|
+ if( cmMidiFileOpen( fn, &p->mfH, ctx->cmCtx ) != kOkFileRC )
|
|
491
|
+ rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "MIDI file open failed.");
|
|
492
|
+ else
|
|
493
|
+ {
|
|
494
|
+ p->curMsgIdx = 0;
|
|
495
|
+ p->bsi = cmDspInt(inst,kBsiMfId);
|
|
496
|
+ p->esi = cmDspInt(inst,kEsiMfId);
|
|
497
|
+ p->csi = 0;
|
|
498
|
+
|
|
499
|
+ // force the first msg to occurr one quarter note into the file
|
|
500
|
+ cmMidiFileSetDelay(p->mfH, cmMidiFileTicksPerQN(p->mfH) );
|
|
501
|
+
|
|
502
|
+ // convert midi msg times to absolute time in samples
|
|
503
|
+ cmMidiFileTickToSamples(p->mfH,cmDspSampleRate(ctx),true);
|
|
504
|
+ }
|
|
505
|
+ return rc;
|
|
506
|
+}
|
|
507
|
+
|
|
508
|
+cmDspRC_t _cmDspMidiFilePlayReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
509
|
+{
|
|
510
|
+ cmDspApplyAllDefaults(ctx,inst);
|
|
511
|
+
|
|
512
|
+ return _cmDspMidiFilePlayOpen(ctx,inst);
|
|
513
|
+}
|
|
514
|
+
|
|
515
|
+cmDspRC_t _cmDspMidiFilePlayExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
516
|
+{
|
|
517
|
+ cmDspRC_t rc = kOkDspRC;
|
|
518
|
+ cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
519
|
+ unsigned sPc = cmDspSamplesPerCycle(ctx);
|
|
520
|
+
|
|
521
|
+ if( cmDspSymbol(inst,kSelMfId) != p->stopSymId )
|
|
522
|
+ {
|
|
523
|
+ const cmMidiTrackMsg_t** mpp = cmMidiFileMsgArray(p->mfH);
|
|
524
|
+ unsigned msgN = cmMidiFileMsgCount(p->mfH);
|
|
525
|
+
|
|
526
|
+ for(; p->curMsgIdx < msgN && p->csi <= mpp[p->curMsgIdx]->dtick && mpp[p->curMsgIdx]->dtick < (p->csi + sPc); ++p->curMsgIdx )
|
|
527
|
+ {
|
|
528
|
+ const cmMidiTrackMsg_t* mp = mpp[p->curMsgIdx];
|
|
529
|
+ switch( mp->status )
|
|
530
|
+ {
|
|
531
|
+ case kNoteOnMdId:
|
|
532
|
+ case kCtlMdId:
|
|
533
|
+ cmDspSetUInt(ctx,inst, kD1MfId, mp->u.chMsgPtr->d1);
|
|
534
|
+ cmDspSetUInt(ctx,inst, kD0MfId, mp->u.chMsgPtr->d0);
|
|
535
|
+ cmDspSetUInt(ctx,inst, kStatusMfId, mp->status);
|
|
536
|
+ break;
|
|
537
|
+ }
|
|
538
|
+ }
|
|
539
|
+ }
|
|
540
|
+
|
|
541
|
+ p->csi += sPc;
|
|
542
|
+
|
|
543
|
+ return rc;
|
|
544
|
+}
|
|
545
|
+
|
|
546
|
+cmDspRC_t _cmDspMidiFilePlayRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
547
|
+{
|
|
548
|
+ cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
549
|
+
|
|
550
|
+ cmDspSetEvent(ctx,inst,evt);
|
|
551
|
+
|
|
552
|
+ switch(evt->dstVarId)
|
|
553
|
+ {
|
|
554
|
+ case kFnMfId:
|
|
555
|
+ _cmDspMidiFilePlayOpen(ctx, inst );
|
|
556
|
+ break;
|
|
557
|
+
|
|
558
|
+ case kSelMfId:
|
|
559
|
+ {
|
|
560
|
+ if( cmDspSymbol(inst,kSelMfId)==p->startSymId )
|
|
561
|
+ {
|
|
562
|
+ p->csi = cmDspInt(inst,kBsiMfId);
|
|
563
|
+ p->curMsgIdx = _cmDspMidiFilePlaySeekMsgIdx(ctx, p, p->csi );
|
|
564
|
+ }
|
|
565
|
+ break;
|
|
566
|
+ }
|
|
567
|
+
|
|
568
|
+ }
|
|
569
|
+ return kOkDspRC;
|
|
570
|
+}
|
|
571
|
+
|
|
572
|
+struct cmDspClass_str* cmMidiFilePlayClassCons( cmDspCtx_t* ctx )
|
|
573
|
+{
|
|
574
|
+ cmDspClassSetup(&_cmMidiFilePlayDC,ctx,"MidiFilePlay",
|
|
575
|
+ NULL,
|
|
576
|
+ _cmDspMidiFilePlayAlloc,
|
|
577
|
+ _cmDspMidiFilePlayFree,
|
|
578
|
+ _cmDspMidiFilePlayReset,
|
|
579
|
+ _cmDspMidiFilePlayExec,
|
|
580
|
+ _cmDspMidiFilePlayRecv,
|
|
581
|
+ NULL,NULL,
|
|
582
|
+ "Time tagged text file.");
|
|
583
|
+
|
|
584
|
+ return &_cmMidiFilePlayDC;
|
|
585
|
+}
|
|
586
|
+
|
|
587
|
+//==========================================================================================================================================
|
|
588
|
+enum
|
|
589
|
+{
|
|
590
|
+ kFnSfId,
|
|
591
|
+ kWndCntSfId,
|
|
592
|
+ kWndMsSfId,
|
|
593
|
+ kIndexSfId,
|
|
594
|
+ kStatusSfId,
|
|
595
|
+ kD0SfId,
|
|
596
|
+ kD1SfId,
|
|
597
|
+ kOutSfId
|
|
598
|
+};
|
|
599
|
+
|
|
600
|
+cmDspClass_t _cmScFolDC;
|
|
601
|
+
|
|
602
|
+typedef struct
|
|
603
|
+{
|
|
604
|
+ cmDspInst_t inst;
|
|
605
|
+ cmScFol* sfp;
|
|
606
|
+ cmScH_t scH;
|
|
607
|
+} cmDspScFol_t;
|
|
608
|
+
|
|
609
|
+cmDspInst_t* _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
610
|
+{
|
|
611
|
+ cmDspVarArg_t args[] =
|
|
612
|
+ {
|
|
613
|
+ { "fn", kFnSfId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Score file." },
|
|
614
|
+ { "wndcnt",kWndCntSfId, 0, 0, kInDsvFl | kUIntDsvFl, "Event window element count." },
|
|
615
|
+ { "wndms", kWndMsSfId, 0, 0, kInDsvFl | kUIntDsvFl, "Event window length milliseconds."},
|
|
616
|
+ { "index", kIndexSfId, 0, 0, kInDsvFl | kUIntDsvFl, "Tracking start location."},
|
|
617
|
+ { "status",kStatusSfId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI status byte"},
|
|
618
|
+ { "d0", kD0SfId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI data byte 0"},
|
|
619
|
+ { "d1", kD1SfId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI data byte 1"},
|
|
620
|
+ { "out", kOutSfId, 0, 0, kOutDsvFl| kUIntDsvFl, "Current score index."},
|
|
621
|
+ { NULL, 0, 0, 0, 0, NULL }
|
|
622
|
+ };
|
|
623
|
+
|
|
624
|
+ cmDspScFol_t* p;
|
|
625
|
+
|
|
626
|
+ if((p = cmDspInstAlloc(cmDspScFol_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl)) == NULL )
|
|
627
|
+ return NULL;
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+ p->sfp = cmScFolAlloc(ctx->cmProcCtx, NULL, 0, 0, 0, cmScNullHandle );
|
|
631
|
+
|
|
632
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kWndCntSfId, 0, 10);
|
|
633
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kWndMsSfId, 0, 5000);
|
|
634
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kIndexSfId, 0, 0);
|
|
635
|
+ cmDspSetDefaultUInt( ctx, &p->inst, kOutSfId, 0, 0);
|
|
636
|
+
|
|
637
|
+ return &p->inst;
|
|
638
|
+}
|
|
639
|
+
|
|
640
|
+cmDspRC_t _cmDspScFolFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
641
|
+{
|
|
642
|
+ cmDspScFol_t* p = (cmDspScFol_t*)inst;
|
|
643
|
+ cmScFolFree(&p->sfp);
|
|
644
|
+ cmScoreFinalize(&p->scH);
|
|
645
|
+ return kOkDspRC;
|
|
646
|
+}
|
|
647
|
+
|
|
648
|
+cmDspRC_t _cmDspScFolOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
|
|
649
|
+{
|
|
650
|
+ const cmChar_t* fn;
|
|
651
|
+ cmDspScFol_t* p = (cmDspScFol_t*)inst;
|
|
652
|
+
|
|
653
|
+ if((fn = cmDspStrcz(inst,kFnSfId)) == NULL || strlen(fn)==0 )
|
|
654
|
+ return cmErrMsg(&inst->classPtr->err, kInvalidArgDspRC, "No score file name supplied.");
|
|
655
|
+
|
|
656
|
+ if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, NULL, NULL ) != kOkScRC )
|
|
657
|
+ return cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
|
|
658
|
+
|
|
659
|
+ return kOkDspRC;
|
|
660
|
+}
|
|
661
|
+
|
|
662
|
+cmDspRC_t _cmDspScFolReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
663
|
+{
|
|
664
|
+ cmDspRC_t rc = kOkDspRC;
|
|
665
|
+ cmDspScFol_t* p = (cmDspScFol_t*)inst;
|
|
666
|
+ rc = cmDspApplyAllDefaults(ctx,inst);
|
|
667
|
+
|
|
668
|
+ if((rc = _cmDspScFolOpenScore(ctx,inst)) != kOkDspRC )
|
|
669
|
+ return rc;
|
|
670
|
+
|
|
671
|
+ if( cmScoreIsValid(p->scH) )
|
|
672
|
+ if( cmScFolInit(p->sfp, cmDspSampleRate(ctx), cmDspUInt(inst,kWndCntSfId), cmDspUInt(inst,kWndMsSfId), p->scH) != cmOkRC )
|
|
673
|
+ rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Internal score follower allocation failed.");
|
|
674
|
+
|
|
675
|
+ return rc;
|
|
676
|
+}
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+cmDspRC_t _cmDspScFolRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
680
|
+{
|
|
681
|
+ cmDspRC_t rc = kOkDspRC;
|
|
682
|
+ cmDspScFol_t* p = (cmDspScFol_t*)inst;
|
|
683
|
+
|
|
684
|
+ if((rc = cmDspSetEvent(ctx,inst,evt)) == kOkDspRC && p->sfp != NULL )
|
|
685
|
+ {
|
|
686
|
+ switch( evt->dstVarId )
|
|
687
|
+ {
|
|
688
|
+ case kIndexSfId:
|
|
689
|
+ if( cmScFolReset( p->sfp, cmDspUInt(inst,kIndexSfId) ) != cmOkRC )
|
|
690
|
+ cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Score follower reset to score index '%i' failed.");
|
|
691
|
+ break;
|
|
692
|
+
|
|
693
|
+ case kStatusSfId:
|
|
694
|
+ {
|
|
695
|
+ unsigned idx = cmScFolExec(p->sfp, ctx->cycleCnt, cmDspUInt(inst,kStatusSfId), cmDspUInt(inst,kD0SfId), cmDspUInt(inst,kD1SfId));
|
|
696
|
+ if( idx != cmInvalidIdx )
|
|
697
|
+ cmDspSetUInt(ctx,inst,kOutSfId,idx);
|
|
698
|
+ }
|
|
699
|
+ break;
|
|
700
|
+
|
|
701
|
+ case kFnSfId:
|
|
702
|
+ _cmDspScFolOpenScore(ctx,inst);
|
|
703
|
+ break;
|
|
704
|
+ }
|
|
705
|
+ }
|
|
706
|
+
|
|
707
|
+ return rc;
|
|
708
|
+}
|
|
709
|
+
|
|
710
|
+struct cmDspClass_str* cmScFolClassCons( cmDspCtx_t* ctx )
|
|
711
|
+{
|
|
712
|
+ cmDspClassSetup(&_cmScFolDC,ctx,"ScFol",
|
|
713
|
+ NULL,
|
|
714
|
+ _cmDspScFolAlloc,
|
|
715
|
+ _cmDspScFolFree,
|
|
716
|
+ _cmDspScFolReset,
|
|
717
|
+ NULL,
|
|
718
|
+ _cmDspScFolRecv,
|
|
719
|
+ NULL,NULL,
|
|
720
|
+ "Score Follower");
|
|
721
|
+
|
|
722
|
+ return &_cmScFolDC;
|
|
723
|
+}
|
|
724
|
+
|