Browse Source

cmXScore.c : Minor improvements and bug-fixes for _cmXsMeasComplexity()

master
kevin 7 years ago
parent
commit
85878f995b
1 changed files with 28 additions and 33 deletions
  1. 28
    33
      app/cmXScore.c

+ 28
- 33
app/cmXScore.c View File

@@ -3111,13 +3111,15 @@ unsigned _cmXsHistValue( cmXsHist_t* hist, unsigned histN )
3111 3111
   return n;
3112 3112
 }
3113 3113
 
3114
+// Measure the score complexity for the the time window 'wndSecs' seconds
3115
+// prior to the note n1 and following n0.
3114 3116
 const cmXsNote_t*  _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t* n1, double wndSecs )
3115 3117
 {
3116 3118
   const cmXsNote_t* n2          = NULL;
3117 3119
   unsigned    l_pch_0     = 0;
3118 3120
   unsigned    l_pch_value = 0;
3119
-  unsigned    l_pch_cnt   = 0;
3120
-  unsigned    r_pch_0     = 0;
3121
+  unsigned    l_pch_cnt   = n1->staff==1 ? 0 : 1;
3122
+  unsigned    r_pch_0     = n1->staff==1 ? 1 : 0;
3121 3123
   unsigned    r_pch_value = 0;
3122 3124
   unsigned    r_pch_cnt   = 0;
3123 3125
   unsigned    i           = 0;
@@ -3137,44 +3139,35 @@ const cmXsNote_t*  _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t
3137 3139
     // if this event is less than wndSecs behind 'n1' and is not a sounding note ...
3138 3140
     if( n1->secs - n->secs <= wndSecs && cmIsFlag(n->flags,kOnsetXsFl) )
3139 3141
     {
3140
-      // if this is not the first note in the window
3141
-      if( i > 0 )
3142
+      _cmXsHistUpdateI( velHist,  histN, n->dynamics );
3143
+      _cmXsHistUpdateF( rymHist,  histN, n->rvalue );
3144
+
3145
+      switch( n->staff )
3142 3146
       {
3143
-        _cmXsHistUpdateI( velHist,  histN, n->dynamics );
3144
-        _cmXsHistUpdateF( rymHist,  histN, n->rvalue );         
3145
-      
3146
-        switch( n->staff )
3147
-        {
3148
-          case 1:
3147
+        case 1:        // treble cleff
3148
+          if( i > 0 )
3149
+          {
3149 3150
             r_pch_value += r_pch_0 > n->pitch ? r_pch_0-n->pitch : n->pitch-r_pch_0;
3150 3151
             r_pch_cnt   += 1;
3151
-            break;
3152
-          
3153
-          case 2:
3154
-            l_pch_value += l_pch_0 > n->pitch ? l_pch_0-n->pitch : n->pitch-l_pch_0;
3155
-            r_pch_cnt   += 1;
3156
-            break;
3152
+          }
3157 3153
           
3158
-          default:
3159
-            { assert(0); }
3160
-        }
3161
-      }
3162
-
3163
-      // store the pitch values to compare on the next interation
3164
-      switch( n->staff )
3165
-      {
3166
-        case 1:
3167 3154
           r_pch_0 = n->pitch;
3168 3155
           break;
3169
-        
3170
-        case 2:
3171
-          l_pch_0 = n->pitch;
3156
+          
3157
+        case 2:        // bass cleff
3158
+          if( i > 0 )
3159
+          {
3160
+            l_pch_value += l_pch_0 > n->pitch ? l_pch_0-n->pitch : n->pitch-l_pch_0;
3161
+            l_pch_cnt   += 1;
3162
+          }
3163
+          
3164
+          l_pch_0 = n->pitch;                      
3172 3165
           break;
3173
-        
3166
+          
3174 3167
         default:
3175 3168
           { assert(0); }
3176 3169
       }
3177
-
3170
+      
3178 3171
       // track the first note that is inside the window
3179 3172
       if( i == 0 )
3180 3173
         n2 = n;
@@ -3202,6 +3195,7 @@ const cmXsNote_t*  _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t
3202 3195
     
3203 3196
   }
3204 3197
 
3198
+  // update the cplx record in n1 with the results of this window analysis
3205 3199
   n1->cplx.sum_d_vel  = _cmXsHistValue( velHist, histN );
3206 3200
   n1->cplx.sum_d_rym  = _cmXsHistValue( rymHist, histN );
3207 3201
   n1->cplx.sum_d_lpch = l_pch_value;
@@ -3212,6 +3206,8 @@ const cmXsNote_t*  _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t
3212 3206
   return n2;
3213 3207
 }
3214 3208
 
3209
+// Measure the score complexity and fill in the cmXsComplexity_t record associated
3210
+// with the cmXsNote_t record of each sounding note.
3215 3211
 cmXsRC_t _cmXsMeasComplexity( cmXsH_t h, double wndSecs )
3216 3212
 {
3217 3213
   cmXsRC_t    rc = kOkXsRC;
@@ -3361,8 +3357,6 @@ cmXsRC_t _cmXsWriteMidiFile( cmCtx_t* ctx, cmXsH_t h, const cmChar_t* dir, const
3361 3357
   return rc;
3362 3358
 }
3363 3359
 
3364
-
3365
-
3366 3360
 typedef struct cmXsSvgEvt_str
3367 3361
 {
3368 3362
   unsigned         flags;     // k???XsFl
@@ -3630,7 +3624,6 @@ cmXsRC_t _cmXScoreGenSvg( cmCtx_t* ctx, cmXsH_t h, const cmChar_t* dir, const cm
3630 3624
 
3631 3625
 
3632 3626
   return _cmXsWriteMidiSvg( ctx, p, &mf, dir, fn );
3633
-
3634 3627
 }
3635 3628
 
3636 3629
 cmXsRC_t cmXScoreTest(
@@ -3683,6 +3676,8 @@ cmXsRC_t cmXScoreTest(
3683 3676
   
3684 3677
   if( midiOutFn != NULL )
3685 3678
   {
3679
+
3680
+    // measure the score complexity
3686 3681
     double wndSecs = 1.0;
3687 3682
     _cmXsMeasComplexity(h,wndSecs);
3688 3683
 

Loading…
Cancel
Save