Pārlūkot izejas kodu

cmDspKr.h/c : Many changes to cmDspTakeSeqBldr.

Added cmDspTakeSeqRend processor.
master
Kevin Larke 9 gadus atpakaļ
vecāks
revīzija
5c028bca2f
2 mainītis faili ar 270 papildinājumiem un 8 dzēšanām
  1. 269
    8
      dsp/cmDspKr.c
  2. 1
    0
      dsp/cmDspKr.h

+ 269
- 8
dsp/cmDspKr.c Parādīt failu

@@ -714,6 +714,7 @@ cmDspInst_t*  _cmDspMidiFilePlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, u
714 714
   p->startSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"start");
715 715
   p->stopSymId  = cmSymTblRegisterStaticSymbol(ctx->stH,"stop");
716 716
   p->contSymId  = cmSymTblRegisterStaticSymbol(ctx->stH,"continue");
717
+
717 718
   p->mfH        = cmMidiFileNullHandle;
718 719
 
719 720
   cmDspSetDefaultStrcz( ctx, &p->inst, kFnMfId,   NULL, "");
@@ -3240,7 +3241,11 @@ struct cmDspClass_str* cmSyncRecdClassCons( cmDspCtx_t* ctx )
3240 3241
 //==========================================================================================================================================
3241 3242
 enum
3242 3243
 {
3243
-  kFnTbsId,
3244
+  kFnTsbId,
3245
+  kBldrTsbId,
3246
+  kSelTsbId,
3247
+  kRefreshTsbId,
3248
+  kSendTsbId
3244 3249
 };
3245 3250
 
3246 3251
 cmDspClass_t _cmTakeSeqBldrDC;
@@ -3249,20 +3254,29 @@ typedef struct
3249 3254
 {
3250 3255
   cmDspInst_t      inst;
3251 3256
   cmTakeSeqBldrH_t h;
3257
+  bool             errFl;
3252 3258
 } cmDspTakeSeqBldr_t;
3253 3259
 
3254 3260
 
3255 3261
 cmDspInst_t*  _cmDspTakeSeqBldrAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
3256 3262
 {
3257 3263
   cmDspTakeSeqBldr_t* p = cmDspInstAllocV(cmDspTakeSeqBldr_t,ctx,classPtr,instSymId,id,storeSymId,va_cnt,vl,
3258
-    1,       "fn",  kFnScId,     0, 0, kInDsvFl  | kStrzDsvFl | kReqArgDsvFl, "Score Tracking file.",
3264
+    1,       "fn",      kFnTsbId, 0, 0, kInDsvFl  | kStrzDsvFl | kReqArgDsvFl, "Score Tracking file.",
3265
+    1,      "bldr",   kBldrTsbId, 0, 0, kOutDsvFl | kPtrDsvFl, "Bldr Ref",
3266
+    1,       "sel",   kSelTsbId,  0, 0, kOutDsvFl | kUIntDsvFl,   "Selected score element location index.",
3267
+    1,   "refresh",kRefreshTsbId, 0, 0, kOutDsvFl | kUIntDsvFl,   "Refresh",
3268
+    1,      "send",   kSendTsbId, 0, 0, kInDsvFl  | kTypeDsvMask,  "Resend last selected score element location.",
3259 3269
     0 );
3260 3270
 
3271
+  p->errFl      = false;
3272
+
3273
+  cmDspSetDefaultInt(   ctx, &p->inst,  kRefreshTsbId, 0, 0);
3274
+
3261 3275
   if( cmTakeSeqBldrAlloc(ctx->cmCtx, &p->h ) != kOkTsbRC )
3262 3276
     cmErrMsg(&p->inst.classPtr->err, kSubSysFailDspRC, "Allocate TaskSeqBldr object.");
3263 3277
   else
3264 3278
   {
3265
-    cmDspUiTakeSeqBldrCreate(ctx,&p->inst,kFnTbsId);
3279
+    cmDspUiTakeSeqBldrCreate(ctx,&p->inst,kFnTsbId,kBldrTsbId,kSelTsbId,kRefreshTsbId);
3266 3280
   }
3267 3281
 
3268 3282
   return &p->inst;
@@ -3273,9 +3287,15 @@ cmDspRC_t _cmDspTakeSeqBldrSetup( cmDspCtx_t* ctx, cmDspInst_t* inst )
3273 3287
   cmDspRC_t           rc = kOkDspRC;
3274 3288
   cmDspTakeSeqBldr_t* p  = (cmDspTakeSeqBldr_t*)inst;
3275 3289
   
3276
-  if( cmTakeSeqBldrInitialize(p->h, cmDspStrcz(inst,kFnTbsId) ) != kOkTsbRC )
3277
-    rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to initialize the internal TakeSeqBldr object with %s.",cmStringNullGuard(cmDspStrcz(inst,kFnTbsId)));
3278
-
3290
+  if( cmTakeSeqBldrInitialize(p->h, cmDspStrcz(inst,kFnTsbId) ) != kOkTsbRC )
3291
+  {
3292
+    rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to initialize the internal TakeSeqBldr object with %s.",cmStringNullGuard(cmDspStrcz(inst,kFnTsbId)));
3293
+  }
3294
+  else
3295
+  {
3296
+    cmDspSetPtr(ctx,inst,kBldrTsbId,p->h.h);
3297
+    p->errFl = false;
3298
+  }
3279 3299
   return rc;
3280 3300
 }
3281 3301
 
@@ -3300,13 +3320,33 @@ cmDspRC_t _cmDspTakeSeqBldrReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
3300 3320
 
3301 3321
 cmDspRC_t _cmDspTakeSeqBldrExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3302 3322
 {
3303
-  cmDspRC_t rc  = kOkDspRC;
3323
+  cmDspRC_t            rc  = kOkDspRC;
3304 3324
   return rc;
3305 3325
 }
3306 3326
 
3307 3327
 cmDspRC_t _cmDspTakeSeqBldrRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3308 3328
 {
3309
-  //cmDspTakeSeqBldr_t*  p  = (cmDspTakeSeqBldr_t*)inst;
3329
+
3330
+  // not matter what arrives at the 'send' input ....
3331
+  if( evt->dstVarId == kSendTsbId )
3332
+  {
3333
+    // send the last score loc 
3334
+    unsigned selIdx;
3335
+    if((selIdx = cmDspUInt(inst,kSelTsbId)) != cmInvalidIdx )
3336
+      cmDspSetUInt(ctx,inst,kSelTsbId, selIdx );
3337
+    
3338
+    return kOkDspRC;
3339
+  }
3340
+
3341
+  cmDspSetEvent(ctx,inst,evt);
3342
+
3343
+  switch(evt->dstVarId)
3344
+  {
3345
+    case kFnTsbId:
3346
+      _cmDspMidiFilePlayOpen(ctx, inst );
3347
+      break;
3348
+
3349
+  }
3310 3350
   return kOkDspRC;
3311 3351
 }
3312 3352
 
@@ -3326,3 +3366,224 @@ struct cmDspClass_str* cmTakeSeqBldrClassCons( cmDspCtx_t* ctx )
3326 3366
   return &_cmTakeSeqBldrDC;
3327 3367
 }
3328 3368
 
3369
+
3370
+
3371
+
3372
+//==========================================================================================================================================
3373
+enum
3374
+{
3375
+  kBldrTsrId,
3376
+  kRefreshTsrId,
3377
+  kCmdTsrId,
3378
+  kSelTsrId,
3379
+  kStatusTsrId,
3380
+  kD0TsrId,
3381
+  kD1TsrId,
3382
+  kSmpIdxTsrId
3383
+};
3384
+
3385
+cmDspClass_t _cmTakeSeqRendDC;
3386
+
3387
+typedef struct
3388
+{
3389
+  cmDspInst_t      inst;
3390
+  cmTakeSeqBldrH_t h;
3391
+  unsigned         startSymId;
3392
+  unsigned         stopSymId;
3393
+  unsigned         contSymId;
3394
+  unsigned         onSymId;
3395
+  unsigned         offSymId;
3396
+  bool             errFl;
3397
+} cmDspTakeSeqRend_t;
3398
+
3399
+
3400
+cmDspInst_t*  _cmDspTakeSeqRendAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
3401
+{
3402
+  cmDspTakeSeqRend_t* p = cmDspInstAllocV(cmDspTakeSeqRend_t,ctx,classPtr,instSymId,id,storeSymId,va_cnt,vl,
3403
+    1,      "bldr",   kBldrTsrId, 0, 0, kInDsvFl  | kPtrDsvFl  | kOptArgDsvFl, "Take Sequene Builder Ref",
3404
+    1,   "refresh",kRefreshTsrId, 0, 0, kInDsvFl  | kUIntDsvFl | kOptArgDsvFl, "Refresh",
3405
+    1,       "cmd",    kCmdTsrId, 0, 0, kInDsvFl  | kSymDsvFl,  "start | stop | continue" ,
3406
+    1,       "sel",    kSelTsrId, 0, 0, kInDsvFl  | kUIntDsvFl, "Selected score element location index input.",
3407
+    1,    "status", kStatusTsrId, 0, 0, kOutDsvFl | kIntDsvFl,  "Status value output",
3408
+    1,       "d0",      kD0TsrId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 0" ,
3409
+    1,       "d1",      kD1TsrId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 1",
3410
+    1,    "smpidx", kSmpIdxTsrId, 0, 0, kOutDsvFl | kUIntDsvFl, "Msg time tag as a sample index.",
3411
+    0 );
3412
+
3413
+  p->startSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"start");
3414
+  p->stopSymId  = cmSymTblRegisterStaticSymbol(ctx->stH,"stop");
3415
+  p->contSymId  = cmSymTblRegisterStaticSymbol(ctx->stH,"continue");
3416
+  p->onSymId    = cmSymTblRegisterStaticSymbol(ctx->stH,"on");
3417
+  p->offSymId   = cmSymTblRegisterStaticSymbol(ctx->stH,"off");
3418
+
3419
+  p->errFl      = false;
3420
+
3421
+  cmDspSetDefaultInt(   ctx, &p->inst,  kRefreshTsrId, 0, 0);
3422
+  cmDspSetDefaultSymbol(ctx, &p->inst,  kCmdTsrId,    p->stopSymId);
3423
+  cmDspSetDefaultInt(   ctx, &p->inst,  kSmpIdxTsrId, 0, 0);
3424
+  cmDspSetDefaultUInt(  ctx, &p->inst,  kStatusTsrId, 0, 0);
3425
+  cmDspSetDefaultUInt(  ctx, &p->inst,  kD0TsrId,     0, 0);
3426
+  cmDspSetDefaultUInt(  ctx, &p->inst,  kD1TsrId,     0, 0);
3427
+
3428
+  cmDspUiTakeSeqRendCreate(ctx,&p->inst,kBldrTsrId,kRefreshTsrId,kSelTsrId);
3429
+
3430
+  return &p->inst;
3431
+}
3432
+
3433
+cmDspRC_t _cmDspTakeSeqRendFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3434
+{
3435
+  cmDspRC_t           rc = kOkDspRC;
3436
+  return rc;
3437
+}
3438
+
3439
+cmDspRC_t _cmDspTakeSeqRendReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3440
+{
3441
+  //cmDspTakeSeqRend_t* p = (cmDspTakeSeqRend_t*)inst;
3442
+
3443
+  cmDspApplyAllDefaults(ctx,inst);
3444
+  return kOkDspRC;
3445
+} 
3446
+
3447
+typedef struct
3448
+{
3449
+  cmDspCtx_t*  ctx;
3450
+  cmDspInst_t* inst;
3451
+} _cmDspTakeSeqRendCbArg_t;
3452
+
3453
+// Called from cmDspTakeSeqRendExec() -> cmTakeSeqRendPlayExec() to
3454
+// deliver MIDI messages which need to be transmitted.
3455
+void _cmDspTakeSeqRendMidiCb( void* arg, const cmTksbEvent_t* e )
3456
+{
3457
+  _cmDspTakeSeqRendCbArg_t* a = (_cmDspTakeSeqRendCbArg_t*)arg;
3458
+
3459
+  switch( e->status )
3460
+  {
3461
+    case kNoteOffMdId:
3462
+    case kNoteOnMdId:
3463
+    case kCtlMdId:
3464
+      //if( !cmMidiIsPedal(e->status,e->d0))
3465
+      {
3466
+        cmDspSetUInt(a->ctx,a->inst, kSmpIdxTsrId, e->smpIdx);
3467
+        cmDspSetUInt(a->ctx,a->inst, kD1TsrId,     e->d1);
3468
+        cmDspSetUInt(a->ctx,a->inst, kD0TsrId,     e->d0);
3469
+        cmDspSetUInt(a->ctx,a->inst, kStatusTsrId, e->status);
3470
+      }
3471
+      break;
3472
+  }
3473
+  
3474
+}
3475
+
3476
+void _cmDspTakeSeqRendPedalsUp( cmDspCtx_t* ctx, cmDspInst_t* inst )
3477
+{
3478
+  _cmDspTakeSeqRendCbArg_t a;
3479
+  a.ctx = ctx;
3480
+  a.inst = inst;
3481
+
3482
+  cmTksbEvent_t e[] =
3483
+  {
3484
+    { 0, kCtlMdId, kSustainCtlMdId,   0 },
3485
+    { 0, kCtlMdId, kPortamentoCtlMdId,0 },
3486
+    { 0, kCtlMdId, kSostenutoCtlMdId, 0 },
3487
+    { 0, kCtlMdId, kSoftPedalCtlMdId, 0 },
3488
+    { 0, kCtlMdId, kLegatoCtlMdId,    0 }
3489
+  };
3490
+
3491
+  unsigned n = sizeof(e)/sizeof(e[0]);
3492
+  unsigned i;
3493
+  for(i=0; i<n; ++i)
3494
+    _cmDspTakeSeqRendMidiCb(&a,e+i);
3495
+}
3496
+
3497
+
3498
+cmDspRC_t _cmDspTakeSeqRendExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3499
+{
3500
+  cmDspRC_t            rc  = kOkDspRC;
3501
+  cmDspTakeSeqRend_t*  p   = (cmDspTakeSeqRend_t*)inst;
3502
+
3503
+  if( cmDspSymbol(inst,kCmdTsrId) != p->stopSymId )
3504
+  {
3505
+    if( cmTakeSeqBldrIsValid(p->h) == false )
3506
+    {
3507
+      if( p->errFl==false )
3508
+      {
3509
+        rc = cmErrMsg(&inst->classPtr->err, kInvalidStateDspRC,"The Take Sequence Builder not been given a valid file.");
3510
+        p->errFl = true;
3511
+      }
3512
+      return rc;
3513
+    }
3514
+
3515
+    unsigned                 sPc = cmDspSamplesPerCycle(ctx);
3516
+    _cmDspTakeSeqRendCbArg_t arg;
3517
+    arg.inst = inst;
3518
+    arg.ctx  = ctx;
3519
+
3520
+    // This call may result in multiple callbacks  
3521
+    // to _cmDspTakeSeqRendMidiCb() from within the function.
3522
+    cmTakeSeqBldrPlayExec(p->h,sPc,_cmDspTakeSeqRendMidiCb, &arg );
3523
+  }
3524
+
3525
+  return rc;
3526
+}
3527
+
3528
+
3529
+cmDspRC_t _cmDspTakeSeqRendRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3530
+{
3531
+  cmDspTakeSeqRend_t* p = (cmDspTakeSeqRend_t*)inst;
3532
+  
3533
+  printf("Recv:%s\n",cmStringNullGuard(cmDspVarLabel(ctx, inst, evt->dstVarId)) );
3534
+  
3535
+  cmDspSetEvent(ctx,inst,evt);
3536
+
3537
+  switch(evt->dstVarId)
3538
+  {
3539
+    case kBldrTsrId:
3540
+      p->h.h = cmDspPtr(inst,kBldrTsrId);
3541
+      break;
3542
+
3543
+    case kCmdTsrId:
3544
+      {
3545
+        unsigned symId = cmDspSymbol(inst,kCmdTsrId);
3546
+
3547
+        if( symId == p->onSymId )
3548
+          cmDspSetSymbol( ctx, inst, kCmdTsrId, p->startSymId );
3549
+        else
3550
+          if( symId == p->offSymId )
3551
+            cmDspSetSymbol( ctx, inst, kCmdTsrId, p->stopSymId );
3552
+
3553
+        if( cmTakeSeqBldrIsValid(p->h) && cmDspSymbol(inst,kCmdTsrId)==p->startSymId ) 
3554
+        {
3555
+          _cmDspTakeSeqRendPedalsUp( ctx, inst );
3556
+          cmTakeSeqBldrPlaySeekLoc(p->h, cmInvalidId );
3557
+        }
3558
+      }
3559
+      break;
3560
+
3561
+    case kSelTsrId:
3562
+      {
3563
+        // seek the playback position to the scLocIdx.
3564
+        unsigned scLocIdx = cmDspUInt(inst,kSelTsrId);        
3565
+        if( cmTakeSeqBldrIsValid(p->h)  && cmTakeSeqBldrPlaySeekLoc(p->h, scLocIdx ) != kOkTsbRC )
3566
+          return cmDspInstErr(ctx,&p->inst,kSubSysFailDspRC,"Take Sequence Bldr Seek failed on score location index %i.", scLocIdx);
3567
+      }
3568
+      break;
3569
+
3570
+  }
3571
+  return kOkDspRC;
3572
+}
3573
+
3574
+struct cmDspClass_str* cmTakeSeqRendClassCons( cmDspCtx_t* ctx )
3575
+{
3576
+  cmDspClassSetup(&_cmTakeSeqRendDC,ctx,"TakeSeqRend",
3577
+    NULL,
3578
+    _cmDspTakeSeqRendAlloc,
3579
+    _cmDspTakeSeqRendFree,
3580
+    _cmDspTakeSeqRendReset,
3581
+    _cmDspTakeSeqRendExec,
3582
+    _cmDspTakeSeqRendRecv,
3583
+    NULL,
3584
+    NULL,
3585
+    "TakeSeqRend");
3586
+
3587
+  return &_cmTakeSeqRendDC;
3588
+}
3589
+

+ 1
- 0
dsp/cmDspKr.h Parādīt failu

@@ -20,6 +20,7 @@ extern "C" {
20 20
   struct cmDspClass_str* cmGoertzelClassCons( cmDspCtx_t* ctx );
21 21
   struct cmDspClass_str* cmSyncRecdClassCons( cmDspCtx_t* ctx );
22 22
   struct cmDspClass_str* cmTakeSeqBldrClassCons( cmDspCtx_t* ctx );
23
+  struct cmDspClass_str* cmTakeSeqRendClassCons( cmDspCtx_t* ctx );
23 24
 
24 25
 #ifdef __cplusplus
25 26
 }

Notiek ielāde…
Atcelt
Saglabāt