Browse Source

Merge branch 'master' of klarke.webfactional.com:webapps/git/repos/libcm

master
kevin 11 years ago
parent
commit
9dc8a4eb8c
9 changed files with 304 additions and 97 deletions
  1. 25
    19
      app/cmScore.c
  2. 43
    0
      cmProc4.c
  3. 2
    0
      cmProc4.h
  4. 43
    0
      cmText.c
  5. 5
    0
      cmText.h
  6. 137
    42
      dsp/cmDspKr.c
  7. 40
    33
      dsp/cmDspPgmKr.c
  8. 1
    0
      osx/cmAudioPortOsx.c
  9. 8
    3
      osx/cmMidiOsx.c

+ 25
- 19
app/cmScore.c View File

613
   if( cmSymTblIsValid(p->stH) == false )
613
   if( cmSymTblIsValid(p->stH) == false )
614
     return kOkScRC;
614
     return kOkScRC;
615
 
615
 
616
-  // go to command/id space
617
-  if((ip = cmTextNextWhiteOrEosC(text)) == NULL )
618
-    goto errLabel;
619
-
620
-  // goto label 
621
-  if((ip = cmTextNextNonWhiteC(ip)) == NULL )
622
-    goto errLabel;
623
-
624
-  // goto end of label
625
-  if((ep = cmTextNextWhiteOrEosC(ip)) == NULL )
626
-    goto errLabel;
627
-  else
616
+  for(;(cp = cmTextNextNonWhiteC(cp)) != NULL; cp=ep )
628
   {
617
   {
629
-    unsigned n =  (ep-ip)+1;
630
-    cmChar_t markTextStr[n+1];
631
-    strncpy(markTextStr,ip,n);
618
+    // go to command/id space
619
+    if((ip = cmTextNextWhiteOrEosC(cp)) == NULL )
620
+      goto errLabel;
621
+
622
+    // goto label 
623
+    if((ip = cmTextNextNonWhiteC(ip)) == NULL )
624
+      goto errLabel;
632
 
625
 
633
-    // for each command code
634
-    // (there may be more than one character)
635
-    for(; *cp && !isspace(*cp); ++cp)
626
+    // goto end of label
627
+    if((ep = cmTextNextWhiteOrEosC(ip)) == NULL )
628
+      goto errLabel;
629
+    else
636
     {
630
     {
637
-      cmMarkScMId_t cmdId = kInvalidScMId;
631
+      unsigned n =  (ep-ip)+1;
632
+      cmChar_t markTextStr[n+1];
633
+      strncpy(markTextStr,ip,n);
634
+      markTextStr[n] = 0;
638
 
635
 
636
+      // remove any trailing white space
637
+      cmTextTrimEnd(markTextStr);
638
+
639
+      cmMarkScMId_t cmdId = kInvalidScMId;
640
+      
639
       switch( *cp )
641
       switch( *cp )
640
       {
642
       {
641
         case 'c': cmdId = kRecdBegScMId; break;
643
         case 'c': cmdId = kRecdBegScMId; break;
653
       mp->scoreIdx   = scoreIdx;
655
       mp->scoreIdx   = scoreIdx;
654
       mp->csvRowIdx  = rowIdx;
656
       mp->csvRowIdx  = rowIdx;
655
 
657
 
658
+      //printf("%i %c '%s'\n",rowIdx,*cp,markTextStr);
659
+
656
       // insert the new mark at the end of the list
660
       // insert the new mark at the end of the list
657
       if( p->markList == NULL )
661
       if( p->markList == NULL )
658
         p->markList = mp;
662
         p->markList = mp;
665
         ep->link = mp;
669
         ep->link = mp;
666
       }    
670
       }    
667
     }
671
     }
672
+
668
   }
673
   }
674
+
669
   return kOkScRC;
675
   return kOkScRC;
670
 
676
 
671
  errLabel:
677
  errLabel:

+ 43
- 0
cmProc4.c View File

4352
   return  cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The fragment label symbol id '%i' not found for 'end record'.",labelSymId);      
4352
   return  cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The fragment label symbol id '%i' not found for 'end record'.",labelSymId);      
4353
 }
4353
 }
4354
 
4354
 
4355
+cmRC_t         cmRecdPlayInsertRecord(cmRecdPlay* p, unsigned labelSymId, const cmChar_t* wavFn )
4356
+{
4357
+  cmRC_t rc = cmOkRC;
4358
+  unsigned i;
4359
+
4360
+  for(i=0; i<p->fragCnt; ++i)
4361
+    if( p->frags[i].labelSymId == labelSymId )
4362
+    {
4363
+      cmAudioFileH_t    afH  = cmNullAudioFileH;
4364
+      cmAudioFileInfo_t afInfo;
4365
+      cmRC_t            afRC = kOkAfRC;
4366
+
4367
+      // open the audio file
4368
+      if( cmAudioFileIsValid( afH = cmAudioFileNewOpen(wavFn, &afInfo, &afRC, p->obj.err.rpt )) == false )
4369
+        return  cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The audio file '%s' could not be opened'.",cmStringNullGuard(wavFn));    
4370
+
4371
+      // ignore blank
4372
+      if( afInfo.frameCnt == 0 )
4373
+        return cmOkRC;
4374
+          
4375
+      // allocate buffer space
4376
+      unsigned j;
4377
+      for(j=0; j<p->chCnt; ++j)
4378
+        p->frags[i].chArray[j] = cmMemResize(cmSample_t,p->frags[i].chArray[j],afInfo.frameCnt);
4379
+
4380
+      p->frags[i].allocCnt = afInfo.frameCnt;
4381
+
4382
+      // read samples into the buffer space
4383
+      unsigned chIdx = 0;
4384
+      unsigned chCnt = cmMin(p->chCnt,afInfo.chCnt);
4385
+      unsigned actFrmCnt = 0;
4386
+      if( cmAudioFileReadSample(afH,afInfo.frameCnt,chIdx,chCnt,p->frags[i].chArray, &actFrmCnt) != kOkAfRC )
4387
+        return cmCtxRtCondition(&p->obj, cmSubSysFailRC, "Read failed on the audio file '%s'.",cmStringNullGuard(wavFn));
4388
+
4389
+      p->frags[i].recdIdx  = actFrmCnt;
4390
+
4391
+      return rc;
4392
+    }
4393
+
4394
+    return  cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The fragment label symbol id '%i' not found for 'begin record'.",labelSymId);    
4395
+}
4396
+
4397
+
4355
 cmRC_t         cmRecdPlayBeginPlay(   cmRecdPlay* p, unsigned labelSymId )
4398
 cmRC_t         cmRecdPlayBeginPlay(   cmRecdPlay* p, unsigned labelSymId )
4356
 {
4399
 {
4357
   unsigned i;
4400
   unsigned i;

+ 2
- 0
cmProc4.h View File

688
 
688
 
689
   cmRC_t         cmRecdPlayBeginRecord( cmRecdPlay* p, unsigned labelSymId );
689
   cmRC_t         cmRecdPlayBeginRecord( cmRecdPlay* p, unsigned labelSymId );
690
   cmRC_t         cmRecdPlayEndRecord(   cmRecdPlay* p, unsigned labelSymId );
690
   cmRC_t         cmRecdPlayEndRecord(   cmRecdPlay* p, unsigned labelSymId );
691
+  cmRC_t         cmRecdPlayInsertRecord(cmRecdPlay* p, unsigned labelSymId, const cmChar_t* wavFn );
692
+
691
   cmRC_t         cmRecdPlayBeginPlay(   cmRecdPlay* p, unsigned labelSymId );
693
   cmRC_t         cmRecdPlayBeginPlay(   cmRecdPlay* p, unsigned labelSymId );
692
   cmRC_t         cmRecdPlayEndPlay(     cmRecdPlay* p, unsigned labelSymId );
694
   cmRC_t         cmRecdPlayEndPlay(     cmRecdPlay* p, unsigned labelSymId );
693
 
695
 

+ 43
- 0
cmText.c View File

539
     
539
     
540
 }
540
 }
541
 
541
 
542
+cmChar_t* cmTextTrimBegin( cmChar_t* s )
543
+{
544
+  if( s==NULL || strlen(s) == 0 )
545
+    return s;
546
+
547
+  cmChar_t* s0 = cmTextNextNonWhite(s);
548
+
549
+  // no non-white char's exist
550
+  if( s0 == NULL )
551
+  {
552
+    s[0] = 0;
553
+    return s;
554
+  }
555
+
556
+  if( s0 != s )
557
+    cmTextShrinkS(s,s,s0-s);
558
+
559
+  return s;
560
+}
561
+
562
+cmChar_t* cmTextTrimEnd( cmChar_t* s )
563
+{
564
+  unsigned sn;
565
+
566
+  if( s==NULL || (sn = strlen(s))==0)
567
+    return s;
568
+
569
+  cmChar_t* s0 = cmTextLastNonWhiteChar(s);
570
+
571
+  if(s0-s+1 < sn )
572
+    s[s0-s+1] = 0;
573
+
574
+
575
+  return s;
576
+}
577
+
578
+cmChar_t* cmTextTrim( cmChar_t* s)
579
+{
580
+  cmTextTrimBegin(s);
581
+  cmTextTrimEnd(s);
582
+  return s;
583
+}
584
+
542
 
585
 
543
 cmChar_t* cmTextExpandS( cmChar_t* s, const cmChar_t* t, unsigned tn )
586
 cmChar_t* cmTextExpandS( cmChar_t* s, const cmChar_t* t, unsigned tn )
544
 { return cmVOC_Expand(s,strlen(s)+1,t,tn); }
587
 { return cmVOC_Expand(s,strlen(s)+1,t,tn); }

+ 5
- 0
cmText.h View File

166
   // Remove the last n characters from s by inserting a '\0' at s[ strlen(s)-n ].
166
   // Remove the last n characters from s by inserting a '\0' at s[ strlen(s)-n ].
167
   void      cmTextClip(    cmChar_t* s, unsigned n );
167
   void      cmTextClip(    cmChar_t* s, unsigned n );
168
 
168
 
169
+  // Trim white space from the begining/end/both of a string
170
+  cmChar_t* cmTextTrimBegin( cmChar_t* s );
171
+  cmChar_t* cmTextTrimEnd( cmChar_t* s );
172
+  cmChar_t* cmTextTrim( cmChar_t* );
173
+
169
   // Expand s by copying all bytes past t to t+tn.
174
   // Expand s by copying all bytes past t to t+tn.
170
   cmChar_t* cmTextExpandS( cmChar_t* s, const cmChar_t* t, unsigned tn );
175
   cmChar_t* cmTextExpandS( cmChar_t* s, const cmChar_t* t, unsigned tn );
171
 
176
 

+ 137
- 42
dsp/cmDspKr.c View File

27
 #include "cmDspSys.h"
27
 #include "cmDspSys.h"
28
 #include "cmMath.h"
28
 #include "cmMath.h"
29
 
29
 
30
-
31
 #include "cmAudioFile.h"
30
 #include "cmAudioFile.h"
32
 #include "cmFileSys.h"
31
 #include "cmFileSys.h"
33
 #include "cmProcObj.h"
32
 #include "cmProcObj.h"
2371
 typedef struct
2370
 typedef struct
2372
 {
2371
 {
2373
   cmDspInst_t inst;
2372
   cmDspInst_t inst;
2373
+
2374
 } cmDspNanoMap_t;
2374
 } cmDspNanoMap_t;
2375
 
2375
 
2376
 cmDspRC_t _cmDspNanoMapSend( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned st, unsigned d0, unsigned d1 )
2376
 cmDspRC_t _cmDspNanoMapSend( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned st, unsigned d0, unsigned d1 )
2383
 
2383
 
2384
 void _cmDspNanoMapPgm( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned pgm )
2384
 void _cmDspNanoMapPgm( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned pgm )
2385
 {
2385
 {
2386
+  cmDspNanoMap_t* p = (cmDspNanoMap_t*)inst;
2387
+
2386
   unsigned i;
2388
   unsigned i;
2387
         
2389
         
2388
   for(i=0; i<kMidiChCnt; ++i)
2390
   for(i=0; i<kMidiChCnt; ++i)
2428
 
2430
 
2429
 cmDspRC_t _cmDspNanoMapRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
2431
 cmDspRC_t _cmDspNanoMapRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
2430
 {
2432
 {
2431
-  //cmDspNanoMap_t* p = (cmDspNanoMap_t*)inst;
2433
+  cmDspNanoMap_t* p = (cmDspNanoMap_t*)inst;
2432
 
2434
 
2433
   switch( evt->dstVarId )
2435
   switch( evt->dstVarId )
2434
   {
2436
   {
2439
 
2441
 
2440
     case kStatusNmId:
2442
     case kStatusNmId:
2441
       {
2443
       {
2442
-        unsigned status = cmDsvGetUInt(evt->valuePtr);
2444
+        unsigned status = cmDsvGetUInt(evt->valuePtr);        
2443
         if( (status & 0xf0) == kNoteOnMdId )
2445
         if( (status & 0xf0) == kNoteOnMdId )
2444
         {
2446
         {
2445
           unsigned d0 = cmDspUInt(inst,kD0NmId);
2447
           unsigned d0 = cmDspUInt(inst,kD0NmId);
2447
           status = (status & 0xf0) + ch;
2449
           status = (status & 0xf0) + ch;
2448
           cmDspSetUInt(ctx,inst,kStatusNmId,status);
2450
           cmDspSetUInt(ctx,inst,kStatusNmId,status);
2449
         }
2451
         }
2452
+       
2450
       }
2453
       }
2451
       break;
2454
       break;
2452
 
2455
 
2485
   kMaxLaSecsPrId,
2488
   kMaxLaSecsPrId,
2486
   kCurLaSecsPrId,
2489
   kCurLaSecsPrId,
2487
   kFadeRatePrId,
2490
   kFadeRatePrId,
2491
+  kScInitLocIdxPrId,
2488
   kScLocIdxPrId,
2492
   kScLocIdxPrId,
2489
   kCmdPrId,
2493
   kCmdPrId,
2490
   kInAudioBasePrId
2494
   kInAudioBasePrId
2501
   unsigned    offSymId;
2505
   unsigned    offSymId;
2502
   unsigned    audioOutBaseId;
2506
   unsigned    audioOutBaseId;
2503
   unsigned    chCnt;
2507
   unsigned    chCnt;
2504
-  unsigned    scLocIdx;
2508
+  //unsigned    scLocIdx;
2505
 } cmDspRecdPlay_t;
2509
 } cmDspRecdPlay_t;
2506
 
2510
 
2511
+cmDspRC_t _cmDspRecdPlayParseRsrc( cmDspCtx_t* ctx, cmDspInst_t* inst, cmRecdPlay* rcdply )
2512
+{
2513
+  cmDspRC_t       rc   = kOkDspRC;
2514
+  const cmChar_t* path = NULL;
2515
+
2516
+  // read the 'recdplay' audio file path
2517
+  if( cmDspRsrcString( ctx->dspH, &path, "recdPlayPath", NULL ) != kOkDspRC )
2518
+  {
2519
+    cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The 'recdPlayPath' resource string was not found.");
2520
+  }
2521
+
2522
+  if( path == NULL )
2523
+    path = "";
2524
+
2525
+  cmJsonH_t     jsH = cmDspSysPgmRsrcHandle(ctx->dspH);
2526
+  cmJsonNode_t* jnp = cmJsonFindValue(jsH,"recdPlay",NULL, kArrayTId);
2527
+
2528
+  if( jnp == NULL || cmJsonIsArray(jnp)==false )
2529
+  {
2530
+    // this is really a warning - the object does not require preloaded segments.
2531
+    cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The 'recdPlay' resource used to define pre-loaded segments was not found.");
2532
+    return kOkDspRC;
2533
+  }
2534
+
2535
+  unsigned n = cmJsonChildCount(jnp);
2536
+  unsigned i;
2537
+
2538
+  // for each 'recdplay' segment record
2539
+  for(i=0; i<n && rc==kOkDspRC; ++i)
2540
+  {
2541
+    cmJsonNode_t*   cnp      = cmJsonArrayElement(jnp,i);
2542
+    const cmChar_t* label    = NULL;
2543
+    unsigned        segSymId = cmInvalidId;
2544
+    const cmChar_t* errLabel = NULL;
2545
+    const cmChar_t* fn       = NULL;
2546
+
2547
+    // read the ith segment record
2548
+    if( cmJsonMemberValues(cnp,&errLabel,
2549
+        "label", kStringTId, &label,
2550
+        "file",  kStringTId, &fn,
2551
+        NULL) != kOkJsRC )
2552
+    {
2553
+      rc = cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The record at index %i in the 'recdPlay' pre-loaded segment list could not be parsed.",i);
2554
+      goto errLabel;
2555
+    }
2556
+
2557
+    // find or generate the symbol id for the segment label symbol
2558
+    if((segSymId = cmSymTblRegisterSymbol(ctx->stH,label)) == cmInvalidId )
2559
+    {
2560
+      rc = cmDspInstErr(ctx,inst,kSymNotFoundDspRC,"The 'recdPlay' pre-load segment symbol '%s' could not be found or registered.",cmStringNullGuard(label));
2561
+      goto errLabel;
2562
+    }
2563
+
2564
+    // create the full path name for the segment audio file
2565
+    if((fn = cmFsMakeFn( path, fn, NULL, NULL )) == NULL )
2566
+    {
2567
+      rc = cmDspInstErr(ctx,inst,kFileSysFailDspRC,"The 'recdPlay' file name '%s/%s' could not be generated.",cmStringNullGuard(path),cmStringNullGuard(fn));
2568
+      goto errLabel;
2569
+    }
2570
+    
2571
+
2572
+    // pre-load the segment
2573
+    if( cmRecdPlayInsertRecord(rcdply,segSymId,fn) != cmOkRC )
2574
+      rc = cmDspInstErr(ctx,inst,kSubSysFailDspRC,"The 'recdPlay' segment label:'%s'  file:'%s' could not be loaded.",cmStringNullGuard(label),cmStringNullGuard(fn));
2575
+
2576
+   
2577
+    cmFsFreeFn(fn);
2578
+        
2579
+  }
2580
+  
2581
+ errLabel:
2582
+  return rc;
2583
+}
2584
+
2507
 cmDspRC_t _cmDspRecdPlayOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
2585
 cmDspRC_t _cmDspRecdPlayOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
2508
 {
2586
 {
2509
   cmDspRC_t rc =kOkDspRC;
2587
   cmDspRC_t rc =kOkDspRC;
2511
 
2589
 
2512
   cmDspRecdPlay_t* p = (cmDspRecdPlay_t*)inst;
2590
   cmDspRecdPlay_t* p = (cmDspRecdPlay_t*)inst;
2513
 
2591
 
2514
-  p->scLocIdx = 0;
2592
+  //p->scLocIdx = 0;
2515
 
2593
 
2516
 
2594
 
2517
   if((fn = cmDspStrcz(inst,kFnPrId)) == NULL || strlen(fn)==0 )
2595
   if((fn = cmDspStrcz(inst,kFnPrId)) == NULL || strlen(fn)==0 )
2518
-    return cmErrMsg(&inst->classPtr->err, kInvalidArgDspRC, "No score file name supplied.");
2596
+    return cmDspInstErr(ctx,inst, kInvalidArgDspRC, "No score file name supplied.");
2519
 
2597
 
2520
   if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, cmDspSampleRate(ctx), NULL, 0, NULL, NULL, ctx->stH ) != kOkScRC )
2598
   if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, cmDspSampleRate(ctx), NULL, 0, NULL, NULL, ctx->stH ) != kOkScRC )
2521
-    return cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
2599
+    return cmDspInstErr(ctx,inst, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
2522
 
2600
 
2523
   if( cmScoreIsValid(p->scH) )
2601
   if( cmScoreIsValid(p->scH) )
2524
   {
2602
   {
2537
     for(i=0; i<markerCnt; ++i)
2615
     for(i=0; i<markerCnt; ++i)
2538
       cmRecdPlayRegisterFrag(p->rcdply,i, cmScoreMarkerLabelSymbolId(p->scH,i ));
2616
       cmRecdPlayRegisterFrag(p->rcdply,i, cmScoreMarkerLabelSymbolId(p->scH,i ));
2539
 
2617
 
2618
+    if((rc = _cmDspRecdPlayParseRsrc(ctx,inst,p->rcdply)) != kOkDspRC )
2619
+      rc = cmDspInstErr(ctx,inst,kInstResetFailDspRC,"The 'recdplay' segment pre-load failed.");
2620
+
2621
+    //p->scLocIdx = cmDspUInt(inst,kScInitLocIdxPrId);
2622
+
2540
   }
2623
   }
2541
 
2624
 
2542
   return rc;
2625
   return rc;
2565
     1,         "maxla",  kMaxLaSecsPrId,  0,0, kInDsvFl   | kDoubleDsvFl | kReqArgDsvFl, "Maximum look-ahead buffer in seconds.",
2648
     1,         "maxla",  kMaxLaSecsPrId,  0,0, kInDsvFl   | kDoubleDsvFl | kReqArgDsvFl, "Maximum look-ahead buffer in seconds.",
2566
     1,         "curla",  kCurLaSecsPrId,  0,0, kInDsvFl   | kDoubleDsvFl | kOptArgDsvFl, "Current look-head buffer in seconds.",
2649
     1,         "curla",  kCurLaSecsPrId,  0,0, kInDsvFl   | kDoubleDsvFl | kOptArgDsvFl, "Current look-head buffer in seconds.",
2567
     1,         "frate",  kFadeRatePrId,   0,0, kInDsvFl   | kDoubleDsvFl | kOptArgDsvFl, "Fade rate in dB per second.",
2650
     1,         "frate",  kFadeRatePrId,   0,0, kInDsvFl   | kDoubleDsvFl | kOptArgDsvFl, "Fade rate in dB per second.",
2651
+    1,         "initIdx",kScInitLocIdxPrId,0,0,kInDsvFl   | kUIntDsvFl,                  "Score search start location.",
2568
     1,         "index",  kScLocIdxPrId,   0,0, kInDsvFl   | kUIntDsvFl,                "Score follower location index.",
2652
     1,         "index",  kScLocIdxPrId,   0,0, kInDsvFl   | kUIntDsvFl,                "Score follower location index.",
2569
     1,         "cmd",    kCmdPrId,        0,0, kInDsvFl   | kSymDsvFl,                 "on=reset off=stop.",
2653
     1,         "cmd",    kCmdPrId,        0,0, kInDsvFl   | kSymDsvFl,                 "on=reset off=stop.",
2570
     chCnt,     "in",     kInAudioBasePrId,0,1, kInDsvFl   | kAudioBufDsvFl,            "Audio input",
2654
     chCnt,     "in",     kInAudioBasePrId,0,1, kInDsvFl   | kAudioBufDsvFl,            "Audio input",
2577
   p->offSymId       = cmSymTblId(ctx->stH,"off");
2661
   p->offSymId       = cmSymTblId(ctx->stH,"off");
2578
   p->audioOutBaseId = audioOutBase;
2662
   p->audioOutBaseId = audioOutBase;
2579
   p->chCnt          = chCnt;
2663
   p->chCnt          = chCnt;
2580
-  p->scLocIdx       = 0;
2664
+  //p->scLocIdx       = 0;
2581
 
2665
 
2582
   printf("0 max la secs:%f\n",cmDspDouble(&p->inst,kMaxLaSecsPrId));
2666
   printf("0 max la secs:%f\n",cmDspDouble(&p->inst,kMaxLaSecsPrId));
2583
 
2667
 
2585
   cmDspSetDefaultDouble(ctx,&p->inst, kMaxLaSecsPrId,0.0, 2.0);
2669
   cmDspSetDefaultDouble(ctx,&p->inst, kMaxLaSecsPrId,0.0, 2.0);
2586
   cmDspSetDefaultDouble(ctx,&p->inst, kCurLaSecsPrId,0.0, 0.1);
2670
   cmDspSetDefaultDouble(ctx,&p->inst, kCurLaSecsPrId,0.0, 0.1);
2587
   cmDspSetDefaultDouble(ctx,&p->inst, kFadeRatePrId, 0.0, 1.0);
2671
   cmDspSetDefaultDouble(ctx,&p->inst, kFadeRatePrId, 0.0, 1.0);
2672
+  cmDspSetDefaultUInt(  ctx,&p->inst, kScInitLocIdxPrId,0,0);
2588
 
2673
 
2589
   printf("1 max la secs:%f\n",cmDspDouble(&p->inst,kMaxLaSecsPrId));
2674
   printf("1 max la secs:%f\n",cmDspDouble(&p->inst,kMaxLaSecsPrId));
2590
 
2675
 
2676
+  
2677
+
2591
 
2678
 
2592
   return &p->inst;
2679
   return &p->inst;
2593
 }
2680
 }
2670
       {
2757
       {
2671
         printf("rewind\n");
2758
         printf("rewind\n");
2672
         cmRecdPlayRewind(p->rcdply);
2759
         cmRecdPlayRewind(p->rcdply);
2673
-        p->scLocIdx = 0;
2760
+        //p->scLocIdx = cmDspUInt(inst,kScInitLocIdxPrId);
2674
       }
2761
       }
2675
       else
2762
       else
2676
         if( cmDspSymbol(inst,kCmdPrId) == p->offSymId )
2763
         if( cmDspSymbol(inst,kCmdPrId) == p->offSymId )
2683
       cmRecdPlaySetLaSecs(p->rcdply, cmDspDouble(inst,kCurLaSecsPrId));
2770
       cmRecdPlaySetLaSecs(p->rcdply, cmDspDouble(inst,kCurLaSecsPrId));
2684
       break;
2771
       break;
2685
 
2772
 
2773
+    case kScInitLocIdxPrId:
2774
+      printf("init-idx:%i\n",cmDspUInt(inst,kScInitLocIdxPrId));
2775
+      break;
2776
+
2686
     case kScLocIdxPrId:
2777
     case kScLocIdxPrId:
2687
       {
2778
       {
2688
-        unsigned endScLocIdx = cmDspUInt(inst,kScLocIdxPrId) ;
2779
+        unsigned endScLocIdx = cmDspUInt(inst,kScLocIdxPrId);
2689
 
2780
 
2690
-        for(; p->scLocIdx<=endScLocIdx; p->scLocIdx+=1)
2691
-        {
2692
-          cmScoreLoc_t*    loc = cmScoreLoc(p->scH, p->scLocIdx );
2693
-          cmScoreMarker_t* mp  = loc->markList;
2781
+        if( endScLocIdx < cmDspUInt(inst,kScInitLocIdxPrId) )
2782
+          break;
2694
 
2783
 
2695
-          for(; mp!=NULL; mp=mp->link)
2696
-            switch( mp->markTypeId )
2697
-            {
2698
-              case kRecdBegScMId:
2699
-                printf("recd-beg\n");
2700
-                cmRecdPlayBeginRecord(p->rcdply, mp->labelSymId );
2701
-                break;
2784
+        cmScoreLoc_t*    loc = cmScoreLoc(p->scH, endScLocIdx );
2785
+        if( loc == NULL )
2786
+          break;
2787
+
2788
+        cmScoreMarker_t* mp  = loc->markList;
2789
+
2790
+        for(; mp!=NULL; mp=mp->link)
2791
+          switch( mp->markTypeId )
2792
+          {
2793
+            case kRecdBegScMId:
2794
+              printf("recd-beg %s\n",cmSymTblLabel(ctx->stH,mp->labelSymId));
2795
+              cmRecdPlayBeginRecord(p->rcdply, mp->labelSymId );
2796
+              break;
2702
                 
2797
                 
2703
-              case kRecdEndScMId:
2704
-                printf("recd-end\n");
2705
-                cmRecdPlayEndRecord(p->rcdply, mp->labelSymId );
2706
-                break;
2798
+            case kRecdEndScMId:
2799
+              printf("recd-end %s\n",cmSymTblLabel(ctx->stH,mp->labelSymId));
2800
+              cmRecdPlayEndRecord(p->rcdply, mp->labelSymId );
2801
+              break;
2707
                 
2802
                 
2708
-              case kPlayBegScMId:
2709
-                printf("play-beg\n");
2710
-                cmRecdPlayBeginPlay(p->rcdply, mp->labelSymId );
2711
-                break;
2803
+            case kPlayBegScMId:
2804
+              printf("play-beg\n");
2805
+              cmRecdPlayBeginPlay(p->rcdply, mp->labelSymId );
2806
+              break;
2712
 
2807
 
2713
-              case kPlayEndScMId:
2714
-                printf("play-end\n");
2715
-                cmRecdPlayEndPlay(p->rcdply, mp->labelSymId );
2716
-                break;
2808
+            case kPlayEndScMId:
2809
+              printf("play-end\n");
2810
+              cmRecdPlayEndPlay(p->rcdply, mp->labelSymId );
2811
+              break;
2717
 
2812
 
2718
-              case kFadeScMId:
2719
-                printf("fade-beg\n");
2720
-                cmRecdPlayBeginFade(p->rcdply, mp->labelSymId, cmDspDouble(inst,kFadeRatePrId) );
2721
-                break;
2813
+            case kFadeScMId:
2814
+              printf("fade-beg\n");
2815
+              cmRecdPlayBeginFade(p->rcdply, mp->labelSymId, cmDspDouble(inst,kFadeRatePrId) );
2816
+              break;
2722
 
2817
 
2723
-              default:
2724
-                break;
2725
-            }
2726
-        }
2818
+            default:
2819
+              break;
2820
+          }
2821
+        
2727
 
2822
 
2728
-        p->scLocIdx = endScLocIdx+1;
2823
+        //p->scLocIdx = endScLocIdx+1;
2729
       }
2824
       }
2730
       break;
2825
       break;
2731
   }
2826
   }

+ 40
- 33
dsp/cmDspPgmKr.c View File

61
   cmDspRsrcString(h,&r->midiDevice,  "midiDevice",   NULL);
61
   cmDspRsrcString(h,&r->midiDevice,  "midiDevice",   NULL);
62
   cmDspRsrcString(h,&r->midiOutPort, "midiOutPort",  NULL);
62
   cmDspRsrcString(h,&r->midiOutPort, "midiOutPort",  NULL);
63
 
63
 
64
-  
65
-
66
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
64
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
67
     cmErrMsg(err,rc,"A KR DSP resource load failed.");
65
     cmErrMsg(err,rc,"A KR DSP resource load failed.");
68
     
66
     
363
   cmCtx_t*        cmCtx      = cmDspSysPgmCtx(h);
361
   cmCtx_t*        cmCtx      = cmDspSysPgmCtx(h);
364
   cmErr_t         err;
362
   cmErr_t         err;
365
   krRsrc_t        r;
363
   krRsrc_t        r;
366
-  bool            fragFl     = false;
364
+  bool            fragFl     = true;
365
+  bool            useWtFl    = false;
367
   unsigned        wtLoopCnt  = 1;                            // 1=play once (-1=loop forever)
366
   unsigned        wtLoopCnt  = 1;                            // 1=play once (-1=loop forever)
368
   unsigned        wtInitMode = 0;                            // initial wt mode is 'silence'
367
   unsigned        wtInitMode = 0;                            // initial wt mode is 'silence'
369
   unsigned        wtSmpCnt   = floor(cmDspSysSampleRate(h)); // wt length == srate
368
   unsigned        wtSmpCnt   = floor(cmDspSysSampleRate(h)); // wt length == srate
398
   cmDspInst_t* mop  = cmDspSysAllocInst(h,"MidiOut",     NULL,  2, r.midiDevice,r.midiOutPort);
397
   cmDspInst_t* mop  = cmDspSysAllocInst(h,"MidiOut",     NULL,  2, r.midiDevice,r.midiOutPort);
399
   cmDspInst_t* sfp  = cmDspSysAllocInst(h,"ScFol",       NULL,  1, r.scFn, sfBufCnt, sfMaxWndCnt, sfMinVel, sfEnaMeasFl );
398
   cmDspInst_t* sfp  = cmDspSysAllocInst(h,"ScFol",       NULL,  1, r.scFn, sfBufCnt, sfMaxWndCnt, sfMinVel, sfEnaMeasFl );
400
   cmDspInst_t* amp  = cmDspSysAllocInst(h,"ActiveMeas",  NULL,  1, 100 );
399
   cmDspInst_t* amp  = cmDspSysAllocInst(h,"ActiveMeas",  NULL,  1, 100 );
401
-  cmDspInst_t* rpp  = cmDspSysAllocInst(h,"RecdPlay",    NULL,  6, 2, r.scFn, recdPlayInitAllocSecs, recdPlayMaxLaSecs, recdPlayCurLaSecs, recdPlayFadeRateDbPerSec );
400
+  cmDspInst_t* rpp  = cmDspSysAllocInst(h,"RecdPlay",    NULL,  6, 2, r.scFn, recdPlayInitAllocSecs, recdPlayMaxLaSecs, recdPlayCurLaSecs, recdPlayFadeRateDbPerSec);
402
   cmDspInst_t* modp = cmDspSysAllocInst(h,"ScMod",       NULL,  2, r.modFn, "m1" );
401
   cmDspInst_t* modp = cmDspSysAllocInst(h,"ScMod",       NULL,  2, r.modFn, "m1" );
403
   cmDspInst_t* modr = cmDspSysAllocInst(h,"ScMod",       NULL,  2, r.modFn, "m1" );
402
   cmDspInst_t* modr = cmDspSysAllocInst(h,"ScMod",       NULL,  2, r.modFn, "m1" );
404
  
403
  
498
   // Audio connections
497
   // Audio connections
499
   cmDspSysConnectAudio(h, php,  "out",   wtp,  "phs" );     // phs -> wt
498
   cmDspSysConnectAudio(h, php,  "out",   wtp,  "phs" );     // phs -> wt
500
 
499
 
501
-  cmDspSysConnectAudio(h, wtp,    "out",   au0Sw, "a-in-0" ); // wt  -> sw
502
-
503
-  /*
504
-  cmDspSysConnectAudio(h, ai0p,   "out",   au0Sw, "a-in-1" ); // ain -> sw
505
-  cmDspSysConnectAudio(h, ai0p,   "out",   mi0p,  "in" );     
506
-  cmDspSysConnectAudio(h, au0Sw,  "a-out", rpp,   "in-0");    // sw  -> rcdply
507
-  cmDspSysConnectAudio(h, au0Sw,  "a-out", c0.kr0,"in"  );    // sw  -> kr
508
-  cmDspSysConnectAudio(h, au0Sw,  "a-out", c0.kr1,"in"  );    // sw  -> kr
509
-  */
510
-
511
-
512
-  cmDspSysConnectAudio(h, ai0p,  "out", rpp,   "in-0");    // sw  -> rcdply
513
-  cmDspSysConnectAudio(h, ai0p,   "out",   c0.kr0, "in" ); // ain -> sw
514
-  cmDspSysConnectAudio(h, ai0p,   "out",   c0.kr1, "in" ); // ain -> sw
515
-  cmDspSysConnectAudio(h, ai0p,   "out",   mi0p,  "in" );     
500
+  if( useWtFl )
501
+  {
502
+    cmDspSysConnectAudio(h, wtp,    "out",   au0Sw, "a-in-0" ); // wt  -> sw
503
+    cmDspSysConnectAudio(h, ai0p,   "out",   au0Sw, "a-in-1" ); // ain -> sw
504
+    cmDspSysConnectAudio(h, ai0p,   "out",   mi0p,  "in" );     
505
+    cmDspSysConnectAudio(h, au0Sw,  "a-out", rpp,   "in-0");    // sw  -> rcdply
506
+    cmDspSysConnectAudio(h, au0Sw,  "a-out", c0.kr0,"in"  );    // sw  -> kr
507
+    cmDspSysConnectAudio(h, au0Sw,  "a-out", c0.kr1,"in"  );    // sw  -> kr
508
+  }
509
+  else
510
+  {
511
+    cmDspSysConnectAudio(h, ai0p,  "out", rpp,   "in-0");    // sw  -> rcdply
512
+    cmDspSysConnectAudio(h, ai0p,   "out",   c0.kr0, "in" ); // ain -> sw
513
+    cmDspSysConnectAudio(h, ai0p,   "out",   c0.kr1, "in" ); // ain -> sw
514
+    cmDspSysConnectAudio(h, ai0p,   "out",   mi0p,  "in" );     
515
+  }
516
 
516
 
517
   if( fragFl )
517
   if( fragFl )
518
   {
518
   {
525
   else
525
   else
526
   {
526
   {
527
     cmDspSysConnectAudio(h, c0.cmp, "out", ao0p, "in" );
527
     cmDspSysConnectAudio(h, c0.cmp, "out", ao0p, "in" );
528
+    //cmDspSysConnectAudio(h, wtp, "out", ao0p, "in" );
528
   }
529
   }
529
 
530
 
530
 
531
 
531
-  cmDspSysConnectAudio(h, wtp,    "out",   au1Sw, "a-in-0" ); // wt  -> sw
532
-  /*
533
-  cmDspSysConnectAudio(h, ai1p,   "out",   au1Sw, "a-in-1" ); // ain -> sw
534
-  cmDspSysConnectAudio(h, ai1p,   "out",   mi1p,  "in" );
535
-  cmDspSysConnectAudio(h, au1Sw,  "a-out", rpp,   "in-1");    // sw  -> rcdply
536
-  cmDspSysConnectAudio(h, au1Sw,  "a-out", c1.kr0,"in"  );    // sw  -> kr
537
-  cmDspSysConnectAudio(h, au1Sw,  "a-out", c1.kr1,"in"  );    // sw  -> kr
538
-  */
539
-
540
-  cmDspSysConnectAudio(h, ai1p,  "out", rpp,   "in-1");    // sw  -> rcdply
541
-  cmDspSysConnectAudio(h, ai1p,   "out",   c1.kr0, "in" ); // ain -> sw
542
-  cmDspSysConnectAudio(h, ai1p,   "out",   c1.kr1, "in" ); // ain -> sw
543
-  cmDspSysConnectAudio(h, ai1p,   "out",   mi1p,  "in" );
532
+  if( useWtFl )
533
+  {
534
+    cmDspSysConnectAudio(h, wtp,    "out",   au1Sw, "a-in-0" ); // wt  -> sw
535
+    cmDspSysConnectAudio(h, ai1p,   "out",   au1Sw, "a-in-1" ); // ain -> sw
536
+    cmDspSysConnectAudio(h, ai1p,   "out",   mi1p,  "in" );
537
+    cmDspSysConnectAudio(h, au1Sw,  "a-out", rpp,   "in-1");    // sw  -> rcdply
538
+    cmDspSysConnectAudio(h, au1Sw,  "a-out", c1.kr0,"in"  );    // sw  -> kr
539
+    cmDspSysConnectAudio(h, au1Sw,  "a-out", c1.kr1,"in"  );    // sw  -> kr
540
+  }
541
+  else
542
+  {
543
+    cmDspSysConnectAudio(h, ai1p,  "out", rpp,   "in-1");    // sw  -> rcdply
544
+    cmDspSysConnectAudio(h, ai1p,   "out",   c1.kr0, "in" ); // ain -> sw
545
+    cmDspSysConnectAudio(h, ai1p,   "out",   c1.kr1, "in" ); // ain -> sw
546
+    cmDspSysConnectAudio(h, ai1p,   "out",   mi1p,  "in" );
547
+  }
544
 
548
 
545
   if( fragFl )
549
   if( fragFl )
546
   {
550
   {
553
   else
557
   else
554
   {
558
   {
555
     cmDspSysConnectAudio(h, c1.cmp, "out",   ao1p,  "in" );   // cmp -> mix 0
559
     cmDspSysConnectAudio(h, c1.cmp, "out",   ao1p,  "in" );   // cmp -> mix 0
560
+    //cmDspSysConnectAudio(h, wtp, "out", ao1p, "in" );
561
+
556
   }
562
   }
557
 
563
 
558
   cmDspSysConnectAudio(h, c0.cmp, "out", afop, "in0" );    // comp -> audio_file_out
564
   cmDspSysConnectAudio(h, c0.cmp, "out", afop, "in0" );    // comp -> audio_file_out
689
   cmDspSysInstallCb(h, scp, "sel",    sfp, "index",  NULL );
695
   cmDspSysInstallCb(h, scp, "sel",    sfp, "index",  NULL );
690
   cmDspSysInstallCb(h, scp, "sel",    modp,"reset", NULL );
696
   cmDspSysInstallCb(h, scp, "sel",    modp,"reset", NULL );
691
   cmDspSysInstallCb(h, scp, "sel",    modr,"reset", NULL );
697
   cmDspSysInstallCb(h, scp, "sel",    modr,"reset", NULL );
692
-  
698
+  cmDspSysInstallCb(h, scp, "sel",    rpp, "initIdx", NULL );
699
+  cmDspSysInstallCb(h, scp, "sel",    prp, "in", NULL );
693
   //cmDspSysInstallCb(h, reload,"out",  modp, "reload", NULL );
700
   //cmDspSysInstallCb(h, reload,"out",  modp, "reload", NULL );
694
 
701
 
695
 
702
 

+ 1
- 0
osx/cmAudioPortOsx.c View File

6
 #include "cmPrefix.h"
6
 #include "cmPrefix.h"
7
 #include "cmGlobal.h"
7
 #include "cmGlobal.h"
8
 #include "cmRpt.h"
8
 #include "cmRpt.h"
9
+#include "cmTime.h"
9
 #include "cmAudioPort.h"
10
 #include "cmAudioPort.h"
10
 #include "cmMem.h"
11
 #include "cmMem.h"
11
 #include "cmMallocDebug.h"
12
 #include "cmMallocDebug.h"

+ 8
- 3
osx/cmMidiOsx.c View File

10
 #include "cmCtx.h"
10
 #include "cmCtx.h"
11
 #include "cmMem.h"
11
 #include "cmMem.h"
12
 #include "cmMallocDebug.h"
12
 #include "cmMallocDebug.h"
13
+#include "cmTime.h"
13
 #include "cmMidi.h"
14
 #include "cmMidi.h"
14
 #include "cmMidiPort.h"
15
 #include "cmMidiPort.h"
15
 
16
 
507
 
508
 
508
     double nano = 1e-9 * ( (double) _cmMpRoot.timeBaseInfo.numer) / ((double) _cmMpRoot.timeBaseInfo.denom);
509
     double nano = 1e-9 * ( (double) _cmMpRoot.timeBaseInfo.numer) / ((double) _cmMpRoot.timeBaseInfo.denom);
509
 
510
 
510
-    // so here's the delta in nanoseconds:
511
+    // so here's the timestamp in nanoseconds:
511
     double nanoSeconds = ((double) packetPtr->timeStamp) * nano;
512
     double nanoSeconds = ((double) packetPtr->timeStamp) * nano;
512
 
513
 
513
     // 1000 times that for microSeconds:
514
     // 1000 times that for microSeconds:
516
     // BUG BUG BUG: How can multiplying the nanoseconds produce microseconds?
517
     // BUG BUG BUG: How can multiplying the nanoseconds produce microseconds?
517
     // Shouldn't the nano to micro conversion be a divide?
518
     // Shouldn't the nano to micro conversion be a divide?
518
 
519
 
519
-    double deltaMicroSecs = microSecs - pp->prevMicroSecs;
520
+    //double deltaMicroSecs = microSecs - pp->prevMicroSecs;
520
 
521
 
521
     pp->prevMicroSecs = microSecs;
522
     pp->prevMicroSecs = microSecs;
522
 
523
 
524
+    cmTimeSpec_t ts;
525
+    ts.tv_sec  = floor(microSecs / 1000000.0);
526
+    ts.tv_nsec = (microSecs - ts.tv_sec * 1000000.0) * 1000.0;
527
+
523
     assert( pp->inputFl == true );
528
     assert( pp->inputFl == true );
524
     
529
     
525
-    cmMpParseMidiData( pp->parserH, (unsigned)deltaMicroSecs, packetPtr->data, packetPtr->length );
530
+    cmMpParseMidiData( pp->parserH, &ts, packetPtr->data, packetPtr->length );
526
 
531
 
527
 		packetPtr = MIDIPacketNext(packetPtr);
532
 		packetPtr = MIDIPacketNext(packetPtr);
528
 	}
533
 	}

Loading…
Cancel
Save