Browse Source

Many changes to add score/performance feedback to GUI

master
kevin 11 years ago
parent
commit
e9c4d0edd2
8 changed files with 830 additions and 400 deletions
  1. 540
    336
      app/cmScore.c
  2. 82
    20
      app/cmScore.h
  3. 44
    3
      cmGrPlot.c
  4. 1
    0
      cmGrPlot.h
  5. 2
    5
      dsp/cmDspClass.h
  6. 126
    25
      dsp/cmDspKr.c
  7. 24
    9
      dsp/cmDspPgmKr.c
  8. 11
    2
      dsp/cmDspUi.c

+ 540
- 336
app/cmScore.c
File diff suppressed because it is too large
View File


+ 82
- 20
app/cmScore.h View File

@@ -11,7 +11,8 @@ extern "C" {
11 11
     kCsvFailScRC,
12 12
     kSyntaxErrScRC,
13 13
     kInvalidIdxScRC,
14
-    kTimeLineFailScRC
14
+    kTimeLineFailScRC,
15
+    kInvalidDynRefCntScRC
15 16
   
16 17
   };
17 18
 
@@ -32,6 +33,7 @@ extern "C" {
32 33
     kNonEvtScId
33 34
   };
34 35
 
36
+  // Flags used by cmScoreEvt_t.flags
35 37
   enum
36 38
   {
37 39
     kEvenScFl    = 0x01,        // This note is marked for evenness measurement
@@ -41,17 +43,31 @@ extern "C" {
41 43
     kInvalidScFl = 0x10         // This note has a calculated time
42 44
   };
43 45
 
46
+
47
+  // Id's used by cmScoreSet_t.varId and as indexes into
48
+  // cmScoreSection_t.vars[].
49
+  enum
50
+  {
51
+    kEvenVarScId,
52
+    kDynVarScId,
53
+    kTempoVarScId,
54
+    kScVarCnt
55
+  };
56
+
57
+
44 58
   struct cmScoreLoc_str;
59
+  struct cmScoreSet_str;
45 60
 
46 61
   // The score can be divided into arbitrary non-overlapping sections.
47 62
   typedef struct
48 63
   {
49
-    const cmChar_t*        label;      // section label
50
-    struct cmScoreLoc_str* locPtr;     // location where this section starts
51
-    unsigned               begIndex;   // score element index where this section starts
52
-    double                 evenCoeff;  // 
53
-    double                 dynCoeff;   //
54
-    double                 tempoCeoff; //
64
+    const cmChar_t*         label;      // section label
65
+    unsigned                index;      // index of this record in the internal section array
66
+    struct cmScoreLoc_str*  locPtr;     // location where this section starts
67
+    unsigned                begEvtIndex;   // score element index where this section starts    
68
+    unsigned                setCnt;     // Count of elements in setArray[]
69
+    struct cmScoreSet_str** setArray;   // Ptrs to sets which are applied to this section.
70
+    double                  vars[ kScVarCnt ]; // Set to DBL_MAX by default.
55 71
   } cmScoreSection_t;
56 72
 
57 73
   typedef struct
@@ -60,6 +76,7 @@ extern "C" {
60 76
     double       secs;         // Time location in seconds 
61 77
     double       durSecs;      // Duration in seconds
62 78
     unsigned     index;        // Index of this event in the event array.
79
+    unsigned     locIdx;       // Index of the location containing this event
63 80
     cmMidiByte_t pitch;        // MIDI pitch of this note
64 81
     unsigned     flags;        // Attribute flags for this event
65 82
     unsigned     dynVal;       // Dynamcis value pppp to ffff (1 to 11) for this note.
@@ -68,28 +85,30 @@ extern "C" {
68 85
     unsigned     csvRowNumb;   // File row number (not index) from which this record originated
69 86
     unsigned     perfSmpIdx;   // Time this event was performed or cmInvalidIdx if the event was not performed.
70 87
     unsigned     perfVel;      // Velocity of the performed note or 0 if the note was not performed.
88
+    unsigned     perfDynLvl;   // Index into dynamic level ref. array assoc'd with perfVel  
71 89
   } cmScoreEvt_t;
72 90
 
73 91
   typedef struct cmScoreSet_str
74 92
   {
75
-    unsigned           typeFl;     // See kXXXScFl flags above
76
-    cmScoreEvt_t**     eleArray;   // Events that make up this set in time order
77
-    unsigned           eleCnt;     // 
78
-    cmScoreSection_t** sectArray;  // Array of pointers to sections to apply this set to
79
-    unsigned           sectCnt;    //
80
-    struct cmScoreSet_str* link;   // cmScoreLoc_t setList link
93
+    unsigned               varId;      // See kXXXVarScId flags above
94
+    cmScoreEvt_t**         eleArray;   // Events that make up this set in time order
95
+    unsigned               eleCnt;     // 
96
+    bool                   doneFl;
97
+    double                 value;
98
+    struct cmScoreSet_str* llink;      // cmScoreLoc_t setList link
81 99
   } cmScoreSet_t;
82 100
   
83 101
 
84 102
   // All events which are simultaneous are collected into a single
85 103
   // cmScoreLoc_t record.
86 104
   typedef struct cmScoreLoc_str
87
-  {
105
+  {    
106
+    unsigned          index;         // index of this location record
88 107
     double            secs;          // Time of this location
89 108
     unsigned          evtCnt;        // Count of events in evtArray[].
90 109
     cmScoreEvt_t**    evtArray;      // Events which occur at this time.
91 110
     unsigned          barNumb;       // Bar number this event is contained by.                            
92
-    cmScoreSet_t*     setList;       // Set's which end on this time location
111
+    cmScoreSet_t*     setList;       // Set's which end on this time location (linked through cmScoreSet_t.llink)
93 112
     cmScoreSection_t* begSectPtr;    // NULL if this location does not start a section
94 113
   } cmScoreLoc_t;
95 114
 
@@ -107,7 +126,11 @@ extern "C" {
107 126
 
108 127
 
109 128
   // Initialize a score object from a CSV File generated from a score spreadsheet.
110
-  cmScRC_t      cmScoreInitialize( cmCtx_t* ctx, cmScH_t* hp, const cmChar_t* fn, cmScCb_t cbFunc, void* cbArg );
129
+  // The dynRefArray[dynRefCnt] and cbFunc(cbArg) are optional if these 
130
+  // features are not used.
131
+  // If provided the dynRefArray[] is copied into an internal array.
132
+  // The physical array passed here therefore does not need to remain valid.
133
+  cmScRC_t      cmScoreInitialize( cmCtx_t* ctx, cmScH_t* hp, const cmChar_t* fn, const unsigned* dynRefArray, unsigned dynRefCnt, cmScCb_t cbFunc, void* cbArg );
111 134
   cmScRC_t      cmScoreFinalize(   cmScH_t* hp );
112 135
 
113 136
   // Filename of last successfuly loaded score file.
@@ -120,6 +143,10 @@ extern "C" {
120 143
   unsigned      cmScoreEvtCount( cmScH_t h );
121 144
   cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx );
122 145
 
146
+  // Access section records
147
+  unsigned      cmScoreSectionCount( cmScH_t h );
148
+  cmScoreSection_t* cmScoreSection( cmScH_t h, unsigned idx );
149
+
123 150
   // Access the score location data
124 151
   unsigned      cmScoreLocCount( cmScH_t h );
125 152
   cmScoreLoc_t* cmScoreLoc( cmScH_t h, unsigned idx );
@@ -132,21 +159,56 @@ extern "C" {
132 159
   cmScRC_t      cmScoreSeqNotify( cmScH_t h );
133 160
 
134 161
   void          cmScoreClearPerfInfo( cmScH_t h );
135
-  void          cmScoreSetPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
136
-  
162
+
163
+  // Assign 'smpIdx' and 'vel'  to the event matching 'pitch' at 'locIdx'
164
+  // but do not trigger any variable calculations. Return true if as a
165
+  // result of this call all events assigned to 'locIdx' have been received
166
+  // otherwise return false.
167
+  bool          cmScoreSetPerfEvent(  cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
168
+
169
+  // Assign 'smpIdx' and 'vel'  to the event matching 'pitch' at 'locIdx'
170
+  // but and trigger any variable calculations which may happen on, or before, 'locIdx'.
171
+  void          cmScoreExecPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
172
+
173
+  // Assign 'value' to the section at, or before, 'locIdx'.
174
+  void          cmScoreSetPerfValue(  cmScH_t h, unsigned locIdx, unsigned varId, double value );
137 175
   
176
+  // Set the performed dynamic level of a score event.
177
+  void          cmScoreSetPerfDynLevel( cmScH_t h, unsigned evtIdx, unsigned dynLvl );
178
+
138 179
   typedef enum
139 180
   {
140 181
     kInvalidMsgScId,
141 182
     kBeginMsgScId,
142 183
     kEventMsgScId,
143
-    kEndMsgScId
184
+    kSectionMsgScId,
185
+    kEndMsgScId,
186
+    kVarMsgScId,
187
+    kDynMsgScId
144 188
   } cmScMsgTypeId_t;
145 189
 
146 190
   typedef struct
147 191
   {
192
+    unsigned varId;  // see kXXXVarScId from cmScoreSet_t.varId
193
+    double   value;   // value of a variable
194
+  } cmScMeas_t;
195
+
196
+  typedef struct
197
+  {
198
+    unsigned evtIdx;
199
+    unsigned dynLvl;
200
+  } cmScDyn_t;
201
+
202
+  typedef struct
203
+  {
148 204
     cmScMsgTypeId_t typeId;
149
-    cmScoreEvt_t    evt;    // only used when typeId == kEventMsgScId
205
+    union
206
+    {
207
+      cmScoreEvt_t     evt;      // only used when typeId == kEventMsgScId
208
+      cmScMeas_t       meas;     // only used when typeId == kVarMsgScId 
209
+      cmScoreSection_t sect;     // only used when typeId == kSectionMsgScId
210
+      cmScDyn_t        dyn;      // only used when typeId == kDynLvlMsgScId
211
+    } u;
150 212
   } cmScMsg_t;
151 213
 
152 214
   // Decode a serialized cmScMsg_t from a byte stream as passed to the 

+ 44
- 3
cmGrPlot.c View File

@@ -47,6 +47,7 @@ typedef struct cmGrPlotObj_str
47 47
   unsigned          fontSize;
48 48
   unsigned          fontStyle;
49 49
   void*             userPtr;
50
+  unsigned          userByteCnt; // 0 if userPtr does not need to be realease on object destruction
50 51
   cmGrPlotCbFunc_t  cbFunc;
51 52
   void*             cbArg;
52 53
 
@@ -102,6 +103,12 @@ cmGrPlRC_t _cmGrPlotObjDelete( cmGrPlotObj_t* op )
102 103
   if( cmGrObjDestroy( op->grH, &op->grObjH ) != kOkGrRC )
103 104
     return cmErrMsg( &p->err, kGrFailGrPlRC, "Delete failed on the object label='%s' id=%i\n",cmStringNullGuard( op->label ), cmGrObjId(op->grObjH) );
104 105
  
106
+  if( op->userByteCnt != 0 )
107
+  {
108
+    cmMemFree(op->userPtr);
109
+    op->userByteCnt = 0;
110
+  }
111
+
105 112
   return kOkGrPlRC;
106 113
 }
107 114
 
@@ -424,12 +431,13 @@ bool _cmGrPlotObjRender(   cmGrObjFuncArgs_t* args, cmGrDcH_t dcH )
424 431
   // expand the ext's according to the physical offsets
425 432
   cmGrPExtExpand(&pext,op->loffs,op->toffs,op->roffs,op->boffs);
426 433
 
434
+
427 435
   switch( op->typeId )
428 436
   {
429 437
     case kLineGrPlId:
430
-      cmGrDcSetColor(    dcH, _cmGrPlotColor(op,op->drawColors) );
431
-      cmGrDcDrawLine(    dcH, cmGrPExtL(&pext), cmGrPExtT(&pext), cmGrPExtR(&pext), cmGrPExtB(&pext) );
432
-      break;
438
+      //cmGrDcSetColor(    dcH, _cmGrPlotColor(op,op->drawColors) );
439
+      //cmGrDcDrawLine(    dcH, cmGrPExtL(&pext), cmGrPExtT(&pext), cmGrPExtR(&pext), cmGrPExtB(&pext) );
440
+      //break;
433 441
 
434 442
     case kStarGrPlId:
435 443
     case kCrossGrPlId:
@@ -476,6 +484,9 @@ bool _cmGrPlotObjRender(   cmGrObjFuncArgs_t* args, cmGrDcH_t dcH )
476 484
               cmGrDcFillRect( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h);
477 485
               break;
478 486
 
487
+            case kLineGrPlId:
488
+              break;
489
+
479 490
             default:
480 491
               { assert(0); }
481 492
           }
@@ -522,6 +533,9 @@ bool _cmGrPlotObjRender(   cmGrObjFuncArgs_t* args, cmGrDcH_t dcH )
522 533
               cmGrDcDrawLine( dcH, cmGrPExtL(&pext),                       cmGrPExtT(&pext) + cmGrPExtH(&pext)/2, cmGrPExtR(&pext),                       cmGrPExtT(&pext) + cmGrPExtH(&pext)/2);
523 534
               break;
524 535
 
536
+            case kLineGrPlId:
537
+              cmGrDcDrawLine(    dcH, cmGrPExtL(&pext), cmGrPExtT(&pext), cmGrPExtR(&pext), cmGrPExtB(&pext) );
538
+              break;
525 539
 
526 540
             case kRectGrPlId:
527 541
             case kHLineGrPlId:
@@ -884,8 +898,35 @@ void            cmGrPlotObjSetId( cmGrPlObjH_t oh, unsigned id )
884 898
 void            cmGrPlotObjSetUserPtr(  cmGrPlObjH_t oh, void* userPtr )
885 899
 {
886 900
   cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
901
+  if( op->userByteCnt != 0 )
902
+  {
903
+    cmMemFree(op->userPtr);
904
+    op->userByteCnt = 0;
905
+  }
906
+
887 907
   op->userPtr = userPtr;
888 908
 }
909
+
910
+void            cmGrPlotObjAllocUser( cmGrPlObjH_t oh, const void* data, unsigned byteCnt )
911
+{
912
+  cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
913
+
914
+  if( op->userByteCnt != byteCnt )
915
+  {
916
+    if( op->userByteCnt != 0  )
917
+    {
918
+      cmMemFree(op->userPtr);
919
+      op->userByteCnt = 0;
920
+    }
921
+
922
+    op->userPtr     = cmMemAlloc(char,byteCnt);
923
+    op->userByteCnt = byteCnt;
924
+  }
925
+
926
+  memcpy(op->userPtr,data,byteCnt);
927
+  
928
+}
929
+
889 930
 void*           cmGrPlotObjUserPtr( cmGrPlObjH_t oh )
890 931
 {
891 932
   cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);

+ 1
- 0
cmGrPlot.h View File

@@ -148,6 +148,7 @@ extern "C" {
148 148
   unsigned          cmGrPlotObjId(            cmGrPlObjH_t oh );
149 149
 
150 150
   void              cmGrPlotObjSetUserPtr(    cmGrPlObjH_t oh, void* userPtr );
151
+  void              cmGrPlotObjAllocUser(     cmGrPlObjH_t oh, const void* data, unsigned byteCnt );
151 152
   void*             cmGrPlotObjUserPtr(       cmGrPlObjH_t oh );
152 153
 
153 154
   void              cmGrPlotObjSetLabel(      cmGrPlObjH_t oh, const cmChar_t* label );

+ 2
- 5
dsp/cmDspClass.h View File

@@ -31,7 +31,6 @@ extern "C" {
31 31
     kInstMsgRcvFailDspRC,
32 32
     kNetSendAllocFailDspRC,
33 33
 
34
-
35 34
     kClassNotFoundDspRC,
36 35
     kInstNotFoundDspRC,
37 36
     kDuplInstSymIdDspRC,
@@ -60,7 +59,6 @@ extern "C" {
60 59
 
61 60
     kSerializeUiMsgFailDspRC,
62 61
 
63
-
64 62
     kSendToHostFailDspRC,
65 63
     kUiEleCreateFailDspRC,
66 64
 
@@ -75,7 +73,6 @@ extern "C" {
75 73
 
76 74
     kInvalidPgmIdxDspRC,
77 75
     kPgmCfgFailDspRC
78
-
79 76
   };
80 77
 
81 78
 
@@ -287,7 +284,7 @@ extern "C" {
287 284
   // Possible values for cmDspSetXXX()
288 285
   enum
289 286
   {
290
-    kUpdateUiDspFl   = 0x00,  
287
+    kUpdateUiDspFl   = 0x00,  // 
291 288
     kNoUpdateUiDspFl = 0x01,  // don't callback the UI
292 289
     kNoAllocDspFl    = 0x02,  // the caller is handling memory mgmt for the incoming value don't allocate space for it internally
293 290
     kSetDefaultDspFl = 0x04,  // set the var default value rather than the current value
@@ -393,7 +390,7 @@ extern "C" {
393 390
   cmDspRC_t  cmDspUiButtonCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned typeDuiId, unsigned outVarId, unsigned lblVarId );
394 391
   cmDspRC_t  cmDspUiLabelCreate(  cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned lblVarId,  unsigned alignVarId );
395 392
   cmDspRC_t  cmDspUiTimeLineCreate(cmDspCtx_t* ctx,cmDspInst_t* inst, unsigned tlFileVarId,  unsigned audPathVarId, unsigned selVarId, unsigned cursVarId );
396
-  cmDspRC_t  cmDspUiScoreCreate(   cmDspCtx_t* ctx,cmDspInst_t* inst, unsigned scFileVarId,  unsigned selVarId );
393
+  cmDspRC_t  cmDspUiScoreCreate(   cmDspCtx_t* ctx,cmDspInst_t* inst, unsigned scFileVarId,  unsigned selVarId, unsigned smpIdxVarId, unsigned pitchVarId, unsigned velVarId, unsigned locIdxVarIdx, unsigned evtIdxVarIdx, unsigned dynLvlVarIdx, unsigned valTypeVarIdx, unsigned valueVarIdx );
397 394
 
398 395
   cmDspRC_t  cmDspUiNewColumn(        cmDspCtx_t* ctx, unsigned colW );
399 396
   cmDspRC_t  cmDspUiInsertHorzBorder( cmDspCtx_t* ctx );

+ 126
- 25
dsp/cmDspKr.c View File

@@ -21,6 +21,7 @@
21 21
 #include "cmDspCtx.h"
22 22
 #include "cmDspClass.h"
23 23
 #include "cmDspUi.h"
24
+#include "cmDspSys.h"
24 25
 #include "cmMath.h"
25 26
 
26 27
 
@@ -404,7 +405,16 @@ enum
404 405
 {
405 406
   kFnScId,
406 407
   kSelScId,
407
-  kSendScId
408
+  kSendScId,
409
+  kStatusScId,
410
+  kD0ScId,
411
+  kD1ScId,
412
+  kSmpIdxScId,
413
+  kLocIdxScId,
414
+  kEvtIdxScId,
415
+  kDynScId,
416
+  kValTypeScId,
417
+  kValueScId
408 418
 };
409 419
 
410 420
 cmDspClass_t _cmScoreDC;
@@ -413,15 +423,25 @@ typedef struct
413 423
 {
414 424
   cmDspInst_t inst;
415 425
   cmScH_t     scH;
426
+  cmDspCtx_t* ctx;   // temporary ctx ptr used during cmScore callback in _cmDspScoreRecv()
416 427
 } cmDspScore_t;
417 428
 
418 429
 cmDspInst_t*  _cmDspScoreAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
419 430
 {
420 431
   cmDspVarArg_t args[] =
421 432
   {
422
-    { "fn",      kFnScId,             0, 0, kInDsvFl   | kStrzDsvFl | kReqArgDsvFl, "Score file." },
423
-    { "sel",     kSelScId,            0, 0, kInDsvFl   |  kOutDsvFl | kUIntDsvFl,   "Selected score element index."},
424
-    { "send",    kSendScId,           0, 0, kInDsvFl   | kTypeDsvMask,              "Resend last selected score element."},
433
+    { "fn",      kFnScId,     0, 0, kInDsvFl  | kStrzDsvFl | kReqArgDsvFl, "Score file." },
434
+    { "sel",     kSelScId,    0, 0, kInDsvFl  | kOutDsvFl  | kUIntDsvFl,   "Selected score element index input."},
435
+    { "send",    kSendScId,   0, 0, kInDsvFl  | kTypeDsvMask,              "Resend last selected score element."},
436
+    { "status",  kStatusScId, 0, 0, kInDsvFl  | kIntDsvFl,                 "Performed MIDI status value output" },
437
+    { "d0",      kD0ScId,     0, 0, kInDsvFl  | kUIntDsvFl,                "Performed MIDI msg data byte 0" },
438
+    { "d1",      kD1ScId,     0, 0, kInDsvFl  | kUIntDsvFl,                "Performed MIDI msg data byte 1" },
439
+    { "smpidx",  kSmpIdxScId, 0, 0, kInDsvFl  | kUIntDsvFl,                "Performed MIDi msg time tag as a sample index." }, 
440
+    { "loc",     kLocIdxScId, 0, 0, kInDsvFl  | kUIntDsvFl,                "Performance score location."},
441
+    { "evtidx",  kEvtIdxScId, 0, 0, kOutDsvFl | kUIntDsvFl,                "Performed event index of following dynamcis level."},
442
+    { "dyn",     kDynScId,    0, 0, kOutDsvFl | kUIntDsvFl,                "Dynamic level of previous event index."},
443
+    { "type",    kValTypeScId,0, 0, kOutDsvFl | kUIntDsvFl,                "Output variable type."},
444
+    { "value",   kValueScId,  0, 0, kOutDsvFl | kDoubleDsvFl,              "Output variable value."},
425 445
     { NULL, 0, 0, 0, 0 }
426 446
   };
427 447
 
@@ -430,7 +450,7 @@ cmDspInst_t*  _cmDspScoreAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
430 450
   cmDspSetDefaultUInt( ctx, &p->inst,  kSelScId,           0, cmInvalidId);
431 451
 
432 452
   // create the UI control
433
-  cmDspUiScoreCreate(ctx,&p->inst,kFnScId,kSelScId);
453
+  cmDspUiScoreCreate(ctx,&p->inst,kFnScId,kSelScId,kSmpIdxScId,kD0ScId,kD1ScId,kLocIdxScId,kEvtIdxScId,kDynScId,kValTypeScId,kValueScId);
434 454
 
435 455
   p->scH = cmScNullHandle;
436 456
 
@@ -448,40 +468,94 @@ cmDspRC_t _cmDspScoreFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
448 468
   return rc;
449 469
 }
450 470
 
471
+// Callback from cmScore triggered from _cmDspScoreRecv() during call to cmScoreSetPerfEvent().
472
+void _cmDspScoreCb( void* arg, const void* data, unsigned byteCnt )
473
+{
474
+  cmDspInst_t*  inst = (cmDspInst_t*)arg;
475
+  cmDspScore_t* p    = (cmDspScore_t*)inst;
476
+  cmScMsg_t m;
477
+  if( cmScoreDecode(data,byteCnt,&m) == kOkScRC )
478
+  {
479
+    switch( m.typeId )
480
+    {
481
+      case kDynMsgScId:
482
+        cmDspSetUInt( p->ctx,inst, kEvtIdxScId, m.u.dyn.evtIdx );
483
+        cmDspSetUInt( p->ctx,inst, kDynScId,    m.u.dyn.dynLvl );
484
+        break;
485
+
486
+      case kVarMsgScId:
487
+        cmDspSetUInt(  p->ctx,inst, kValTypeScId, m.u.meas.varId);
488
+        cmDspSetDouble(p->ctx,inst, kValueScId,   m.u.meas.value);
489
+        break;
490
+
491
+      default:
492
+        { assert(0); }
493
+    }
494
+  }
495
+}
451 496
 
452 497
 cmDspRC_t _cmDspScoreReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
453 498
 {
454
-  cmDspRC_t        rc = kOkDspRC;
455
-  cmDspScore_t* p  = (cmDspScore_t*)inst;
499
+  cmDspRC_t       rc          = kOkDspRC;
500
+  cmDspScore_t*   p           = (cmDspScore_t*)inst;
501
+  const cmChar_t* tlFn        = NULL;
502
+  unsigned*       dynRefArray = NULL;
503
+  unsigned        dynRefCnt   = 0;
456 504
 
457 505
   cmDspApplyAllDefaults(ctx,inst);
458 506
 
459
-  const cmChar_t* tlFn;
507
+
508
+  if( cmDspRsrcUIntArray(ctx->dspH, &dynRefCnt, &dynRefArray, "dynRef", NULL ) != kOkDspRC )
509
+  {
510
+    rc = cmErrMsg(&inst->classPtr->err, kRsrcNotFoundDspRC, "The dynamics reference array resource was not found.");
511
+    goto errLabel;
512
+  }
513
+
460 514
   if((tlFn =  cmDspStrcz(inst, kFnScId )) !=  NULL )
461
-    if( cmScoreInitialize(ctx->cmCtx, &p->scH, tlFn, NULL, NULL ) != kOkTlRC )
515
+    if( cmScoreInitialize(ctx->cmCtx, &p->scH, tlFn, dynRefArray, dynRefCnt, _cmDspScoreCb, p ) != kOkTlRC )
462 516
       rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "Score file open failed.");
463 517
 
518
+ errLabel:
464 519
   return rc;
465 520
 }
466 521
 
467 522
 cmDspRC_t _cmDspScoreRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
468 523
 {
524
+  cmDspScore_t* p  = (cmDspScore_t*)inst;
525
+
526
+  if( evt->dstVarId == kSendScId )
527
+  {
528
+    unsigned selIdx;
529
+    if((selIdx = cmDspUInt(inst,kSelScId)) != cmInvalidIdx )
530
+    {
531
+      cmDspSetUInt(ctx,inst,kSelScId, selIdx );
532
+      cmScoreClearPerfInfo(p->scH);
533
+    }
534
+    return kOkDspRC;
535
+  }
536
+
537
+  cmDspSetEvent(ctx,inst,evt);
538
+
469 539
   switch( evt->dstVarId )
470 540
   {
471 541
     case kSelScId:
472
-      cmDspSetEvent(ctx,inst,evt);
542
+      cmScoreClearPerfInfo(p->scH);
473 543
       break;
474 544
 
475
-    case kSendScId:
545
+    case kStatusScId:
546
+      //printf("st:%x\n",cmDspUInt(inst,kStatusScId));
547
+      break;
548
+
549
+    case kLocIdxScId:
476 550
       {
477
-        unsigned selIdx;
478
-        if((selIdx = cmDspUInt(inst,kSelScId)) != cmInvalidIdx )
479
-          cmDspSetUInt(ctx,inst,kSelScId, selIdx );
551
+        assert( cmDspUInt(inst,kStatusScId ) == kNoteOnMdId );
552
+        p->ctx = ctx; // setup p->ctx for use in _cmDspScoreCb()
553
+
554
+        // this call may result in callbacks to _cmDspScoreCb()
555
+        cmScoreExecPerfEvent(p->scH, cmDspUInt(inst,kLocIdxScId), cmDspUInt(inst,kSmpIdxScId), cmDspUInt(inst,kD0ScId), cmDspUInt(inst,kD1ScId) );      
480 556
       }
481 557
       break;
482 558
 
483
-    default:
484
-      {assert(0);}
485 559
   }
486 560
 
487 561
   return kOkDspRC;
@@ -619,6 +693,7 @@ cmDspRC_t _cmDspMidiFilePlayOpen(cmDspCtx_t* ctx, cmDspInst_t* inst )
619 693
 
620 694
     // convert midi msg times to absolute time in samples
621 695
     cmMidiFileTickToSamples(p->mfH,cmDspSampleRate(ctx),true);
696
+
622 697
   }
623 698
   return rc;
624 699
 }
@@ -716,6 +791,7 @@ enum
716 791
   kD0SfId,
717 792
   kD1SfId,
718 793
   kSmpIdxSfId,
794
+  kCmdSfId,
719 795
   kOutSfId
720 796
 };
721 797
 
@@ -724,8 +800,10 @@ cmDspClass_t _cmScFolDC;
724 800
 typedef struct
725 801
 {
726 802
   cmDspInst_t inst;
727
-  cmScFol*    sfp;
803
+  cmScTrk*    sfp;
728 804
   cmScH_t     scH;
805
+  unsigned    printSymId;
806
+  unsigned    quietSymId;
729 807
 } cmDspScFol_t;
730 808
 
731 809
 cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
@@ -742,6 +820,7 @@ cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
742 820
     { "d0",    kD0SfId,       0, 0, kInDsvFl | kUIntDsvFl,                    "MIDI data byte 0"},
743 821
     { "d1",    kD1SfId,       0, 0, kInDsvFl | kUIntDsvFl,                    "MIDI data byte 1"},
744 822
     { "smpidx",kSmpIdxSfId,   0, 0, kInDsvFl | kUIntDsvFl,                    "MIDI time tag as a sample index"},
823
+    { "cmd",   kCmdSfId,      0, 0, kInDsvFl | kSymDsvFl,                     "Command input: print | quiet"},
745 824
     { "out",   kOutSfId,      0, 0, kOutDsvFl| kUIntDsvFl,                    "Current score index."},
746 825
     { NULL,    0,             0, 0, 0, NULL }
747 826
   };
@@ -752,7 +831,9 @@ cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
752 831
     return NULL;
753 832
   
754 833
 
755
-  p->sfp = cmScFolAlloc(ctx->cmProcCtx, NULL, 0, cmScNullHandle, 0, 0, 0, 0 );
834
+  p->sfp = cmScTrkAlloc(ctx->cmProcCtx, NULL, 0, cmScNullHandle, 0, 0, 0, 0 );
835
+  p->printSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"print");
836
+  p->quietSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"quiet");
756 837
 
757 838
   cmDspSetDefaultUInt( ctx, &p->inst,  kBufCntSfId,     0,     7);
758 839
   cmDspSetDefaultUInt( ctx, &p->inst,  kMinLkAhdSfId,   0,    10);
@@ -760,6 +841,7 @@ cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
760 841
   cmDspSetDefaultUInt( ctx, &p->inst,  kMinVelSfId,     0,     5);
761 842
   cmDspSetDefaultUInt( ctx, &p->inst,  kIndexSfId,      0,     0);  
762 843
   cmDspSetDefaultUInt( ctx, &p->inst,  kOutSfId,        0,     0);
844
+  cmDspSetDefaultSymbol(ctx,&p->inst,  kCmdSfId,         p->quietSymId );
763 845
 
764 846
   return &p->inst;
765 847
 }
@@ -767,23 +849,33 @@ cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
767 849
 cmDspRC_t _cmDspScFolFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
768 850
 {
769 851
   cmDspScFol_t* p = (cmDspScFol_t*)inst;
770
-  cmScFolFree(&p->sfp);
852
+  cmScTrkFree(&p->sfp);
771 853
   cmScoreFinalize(&p->scH);
772 854
   return kOkDspRC;
773 855
 }
774 856
 
775 857
 cmDspRC_t _cmDspScFolOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
776 858
 {
859
+  cmDspRC_t       rc          = kOkDspRC;
860
+  cmDspScFol_t*   p           = (cmDspScFol_t*)inst;
861
+  unsigned*       dynRefArray = NULL;
862
+  unsigned        dynRefCnt   = 0;
777 863
   const cmChar_t* fn;
778
-  cmDspScFol_t* p  = (cmDspScFol_t*)inst;
779 864
 
780 865
   if((fn = cmDspStrcz(inst,kFnSfId)) == NULL || strlen(fn)==0 )
781 866
     return cmErrMsg(&inst->classPtr->err, kInvalidArgDspRC, "No score file name supplied.");
782 867
 
783
-  if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, NULL, NULL ) != kOkScRC )
868
+  if( cmDspRsrcUIntArray(ctx->dspH, &dynRefCnt, &dynRefArray, "dynRef", NULL ) != kOkDspRC )
869
+  {
870
+    rc = cmErrMsg(&inst->classPtr->err, kRsrcNotFoundDspRC, "The dynamics reference array resource was not found.");
871
+    goto errLabel;
872
+  }
873
+
874
+  if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, NULL, 0, NULL, NULL ) != kOkScRC )
784 875
     return cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
785 876
 
786
-  return kOkDspRC;
877
+ errLabel:
878
+  return rc;
787 879
 }
788 880
 
789 881
 cmDspRC_t _cmDspScFolReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
@@ -796,7 +888,7 @@ cmDspRC_t _cmDspScFolReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
796 888
     return rc;
797 889
 
798 890
   if( cmScoreIsValid(p->scH) )
799
-    if( cmScFolInit(p->sfp, cmDspSampleRate(ctx),  p->scH, cmDspUInt(inst,kBufCntSfId), cmDspUInt(inst,kMinLkAhdSfId), cmDspUInt(inst,kMaxWndCntSfId), cmDspUInt(inst,kMinVelSfId) ) != cmOkRC )
891
+    if( cmScTrkInit(p->sfp, cmDspSampleRate(ctx),  p->scH, cmDspUInt(inst,kBufCntSfId), cmDspUInt(inst,kMinLkAhdSfId), cmDspUInt(inst,kMaxWndCntSfId), cmDspUInt(inst,kMinVelSfId) ) != cmOkRC )
800 892
       rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Internal score follower allocation failed.");
801 893
 
802 894
   return rc;  
@@ -814,14 +906,14 @@ cmDspRC_t _cmDspScFolRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
814 906
     {
815 907
       case kIndexSfId:
816 908
         if( cmScoreIsValid(p->scH) )
817
-          if( cmScFolReset( p->sfp, cmDspUInt(inst,kIndexSfId) ) != cmOkRC )
909
+          if( cmScTrkReset( p->sfp, cmDspUInt(inst,kIndexSfId) ) != cmOkRC )
818 910
             cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Score follower reset to score index '%i' failed.");
819 911
         break;
820 912
 
821 913
       case kStatusSfId:
822 914
         if( cmScoreIsValid(p->scH))
823 915
         {
824
-          unsigned idx = cmScFolExec(p->sfp, ctx->cycleCnt, cmDspUInt(inst,kStatusSfId), cmDspUInt(inst,kD0SfId), cmDspUInt(inst,kD1SfId));
916
+          unsigned idx = cmScTrkExec(p->sfp, ctx->cycleCnt, cmDspUInt(inst,kStatusSfId), cmDspUInt(inst,kD0SfId), cmDspUInt(inst,kD1SfId));
825 917
           if( idx != cmInvalidIdx )
826 918
             cmDspSetUInt(ctx,inst,kOutSfId,idx);
827 919
         }
@@ -830,6 +922,15 @@ cmDspRC_t _cmDspScFolRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
830 922
       case kFnSfId:
831 923
         _cmDspScFolOpenScore(ctx,inst);
832 924
         break;
925
+
926
+      case kCmdSfId:
927
+        if( cmDspSymbol(inst,kCmdSfId) == p->printSymId )
928
+          p->sfp->printFl = true;
929
+        else
930
+          if( cmDspSymbol(inst,kCmdSfId) == p->quietSymId )
931
+            p->sfp->printFl = false;
932
+
933
+        break;
833 934
     }
834 935
   }
835 936
 

+ 24
- 9
dsp/cmDspPgmKr.c View File

@@ -86,11 +86,12 @@ cmDspRC_t _cmDspSysPgm_TimeLine(cmDspSysH_t h, void** userPtrPtr )
86 86
   cmDspSysNewPage(h,"Controls");
87 87
   cmDspInst_t* onb  = cmDspSysAllocInst(h,"Button", "start",  2, kButtonDuiId, 1.0 );
88 88
   cmDspInst_t* offb = cmDspSysAllocInst(h,"Button", "stop",   2, kButtonDuiId, 1.0 );
89
+  cmDspInst_t* prtb = cmDspSysAllocInst(h,"Button", "print",  2, kButtonDuiId, 1.0 );
90
+  cmDspInst_t* qtb  = cmDspSysAllocInst(h,"Button", "quiet",  2, kButtonDuiId, 1.0 );
91
+  cmDspInst_t* prp  = cmDspSysAllocInst(h,"Printer", NULL,   1, ">" );
92
+  //cmDspInst_t* prd  = cmDspSysAllocInst(h,"Printer", NULL,   1, "DYN:" );
93
+  //cmDspInst_t* pre  = cmDspSysAllocInst(h,"Printer", NULL,   1, "EVEN:" );
89 94
 
90
-
91
-
92
-  cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL,   1, ">" );
93
-  
94 95
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
95 96
     return rc;
96 97
 
@@ -125,14 +126,23 @@ cmDspRC_t _cmDspSysPgm_TimeLine(cmDspSysH_t h, void** userPtrPtr )
125 126
   cmDspSysInstallCb(h, tlp, "mesi", mfp, "esi",   NULL );
126 127
   cmDspSysInstallCb(h, tlp, "mfn",  mfp, "fn",    NULL );
127 128
 
128
-  // score to score follower
129
+  // score to score follower - to set initial search location
129 130
   cmDspSysInstallCb(h, scp, "sel",    sfp, "index",  NULL );
131
+  
130 132
 
131
-
132
-  // MIDI file player to score-follower
133
-  cmDspSysInstallCb(h, mfp, "status", sfp, "status", NULL );
134
-  cmDspSysInstallCb(h, mfp, "d0",     sfp, "d0",     NULL );
133
+  // MIDI file player to score-follower and score - the order of connections is the same
134
+  // as the msg transmision order from MFP
135
+  cmDspSysInstallCb(h, mfp, "smpidx", scp, "smpidx", NULL );
136
+  cmDspSysInstallCb(h, mfp, "d1",     scp, "d1",     NULL );
135 137
   cmDspSysInstallCb(h, mfp, "d1",     sfp, "d1",     NULL );
138
+  cmDspSysInstallCb(h, mfp, "d0",     scp, "d0",     NULL );
139
+  cmDspSysInstallCb(h, mfp, "d0",     sfp, "d0",     NULL );
140
+  cmDspSysInstallCb(h, mfp, "status", scp, "status", NULL );
141
+  cmDspSysInstallCb(h, mfp, "status", sfp, "status", NULL );
142
+
143
+
144
+  // score follower to score
145
+  cmDspSysInstallCb(h, sfp, "out",  scp, "loc", NULL );
136 146
 
137 147
 
138 148
   // Printer connections
@@ -141,6 +151,11 @@ cmDspRC_t _cmDspSysPgm_TimeLine(cmDspSysH_t h, void** userPtrPtr )
141 151
   cmDspSysInstallCb(h, tlp, "sel",  prp, "in",  NULL );
142 152
   //cmDspSysInstallCb(h, sfp, "out",  prp, "in",     NULL );
143 153
 
154
+  //cmDspSysInstallCb(h, scp, "even", pre, "in", NULL );
155
+  //cmDspSysInstallCb(h, scp, "dyn",  prd, "in", NULL );
156
+
157
+  cmDspSysInstallCb(h, prtb, "sym", sfp, "cmd", NULL );
158
+  cmDspSysInstallCb(h, qtb,  "sym", sfp, "cmd", NULL );
144 159
 
145 160
   return rc;
146 161
 }

+ 11
- 2
dsp/cmDspUi.c View File

@@ -386,10 +386,10 @@ cmDspRC_t  cmDspUiTimeLineCreate(   cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned
386 386
   return rc;
387 387
 }
388 388
 
389
-cmDspRC_t  cmDspUiScoreCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned scFileVarId, unsigned selVarId )
389
+cmDspRC_t  cmDspUiScoreCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned scFileVarId, unsigned selVarId, unsigned smpIdxVarId, unsigned pitchVarId, unsigned velVarId, unsigned locIdxVarId, unsigned evtIdxVarId, unsigned dynVarId, unsigned valTypeVarId, unsigned valueVarId )
390 390
 {
391 391
   cmDspRC_t    rc;
392
-  unsigned     arr[] = { scFileVarId, selVarId  };
392
+  unsigned     arr[] = { scFileVarId, selVarId, smpIdxVarId, pitchVarId, velVarId, locIdxVarId, evtIdxVarId, dynVarId, valTypeVarId, valueVarId };
393 393
   cmDspValue_t v;
394 394
   unsigned     vn    = sizeof(arr)/sizeof(arr[0]);
395 395
   cmDsvSetUIntMtx(&v,arr,vn,1);
@@ -402,6 +402,15 @@ cmDspRC_t  cmDspUiScoreCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned scFi
402 402
   // Setting this flag will cause their values to be sent to the UI whenever they change.
403 403
   cmDspInstVarSetFlags( ctx, inst, scFileVarId,  kUiDsvFl );
404 404
   cmDspInstVarSetFlags( ctx, inst, selVarId,     kUiDsvFl );
405
+  cmDspInstVarSetFlags( ctx, inst, smpIdxVarId,  kUiDsvFl );
406
+  cmDspInstVarSetFlags( ctx, inst, pitchVarId,   kUiDsvFl );
407
+  cmDspInstVarSetFlags( ctx, inst, velVarId,     kUiDsvFl );
408
+  cmDspInstVarSetFlags( ctx, inst, locIdxVarId,  kUiDsvFl );
409
+  cmDspInstVarSetFlags( ctx, inst, evtIdxVarId,  kUiDsvFl );
410
+  cmDspInstVarSetFlags( ctx, inst, dynVarId,     kUiDsvFl );
411
+  cmDspInstVarSetFlags( ctx, inst, valTypeVarId, kUiDsvFl );
412
+  cmDspInstVarSetFlags( ctx, inst, valueVarId,   kUiDsvFl );
413
+
405 414
   return rc;
406 415
 }
407 416
 

Loading…
Cancel
Save