Переглянути джерело

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

master
kevin 7 роки тому
джерело
коміт
85878f995b
1 змінених файлів з 28 додано та 33 видалено
  1. 28
    33
      app/cmXScore.c

+ 28
- 33
app/cmXScore.c Переглянути файл

3111
   return n;
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
 const cmXsNote_t*  _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t* n1, double wndSecs )
3116
 const cmXsNote_t*  _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t* n1, double wndSecs )
3115
 {
3117
 {
3116
   const cmXsNote_t* n2          = NULL;
3118
   const cmXsNote_t* n2          = NULL;
3117
   unsigned    l_pch_0     = 0;
3119
   unsigned    l_pch_0     = 0;
3118
   unsigned    l_pch_value = 0;
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
   unsigned    r_pch_value = 0;
3123
   unsigned    r_pch_value = 0;
3122
   unsigned    r_pch_cnt   = 0;
3124
   unsigned    r_pch_cnt   = 0;
3123
   unsigned    i           = 0;
3125
   unsigned    i           = 0;
3137
     // if this event is less than wndSecs behind 'n1' and is not a sounding note ...
3139
     // if this event is less than wndSecs behind 'n1' and is not a sounding note ...
3138
     if( n1->secs - n->secs <= wndSecs && cmIsFlag(n->flags,kOnsetXsFl) )
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
             r_pch_value += r_pch_0 > n->pitch ? r_pch_0-n->pitch : n->pitch-r_pch_0;
3150
             r_pch_value += r_pch_0 > n->pitch ? r_pch_0-n->pitch : n->pitch-r_pch_0;
3150
             r_pch_cnt   += 1;
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
           r_pch_0 = n->pitch;
3154
           r_pch_0 = n->pitch;
3168
           break;
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
           break;
3165
           break;
3173
-        
3166
+          
3174
         default:
3167
         default:
3175
           { assert(0); }
3168
           { assert(0); }
3176
       }
3169
       }
3177
-
3170
+      
3178
       // track the first note that is inside the window
3171
       // track the first note that is inside the window
3179
       if( i == 0 )
3172
       if( i == 0 )
3180
         n2 = n;
3173
         n2 = n;
3202
     
3195
     
3203
   }
3196
   }
3204
 
3197
 
3198
+  // update the cplx record in n1 with the results of this window analysis
3205
   n1->cplx.sum_d_vel  = _cmXsHistValue( velHist, histN );
3199
   n1->cplx.sum_d_vel  = _cmXsHistValue( velHist, histN );
3206
   n1->cplx.sum_d_rym  = _cmXsHistValue( rymHist, histN );
3200
   n1->cplx.sum_d_rym  = _cmXsHistValue( rymHist, histN );
3207
   n1->cplx.sum_d_lpch = l_pch_value;
3201
   n1->cplx.sum_d_lpch = l_pch_value;
3212
   return n2;
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
 cmXsRC_t _cmXsMeasComplexity( cmXsH_t h, double wndSecs )
3211
 cmXsRC_t _cmXsMeasComplexity( cmXsH_t h, double wndSecs )
3216
 {
3212
 {
3217
   cmXsRC_t    rc = kOkXsRC;
3213
   cmXsRC_t    rc = kOkXsRC;
3361
   return rc;
3357
   return rc;
3362
 }
3358
 }
3363
 
3359
 
3364
-
3365
-
3366
 typedef struct cmXsSvgEvt_str
3360
 typedef struct cmXsSvgEvt_str
3367
 {
3361
 {
3368
   unsigned         flags;     // k???XsFl
3362
   unsigned         flags;     // k???XsFl
3630
 
3624
 
3631
 
3625
 
3632
   return _cmXsWriteMidiSvg( ctx, p, &mf, dir, fn );
3626
   return _cmXsWriteMidiSvg( ctx, p, &mf, dir, fn );
3633
-
3634
 }
3627
 }
3635
 
3628
 
3636
 cmXsRC_t cmXScoreTest(
3629
 cmXsRC_t cmXScoreTest(
3683
   
3676
   
3684
   if( midiOutFn != NULL )
3677
   if( midiOutFn != NULL )
3685
   {
3678
   {
3679
+
3680
+    // measure the score complexity
3686
     double wndSecs = 1.0;
3681
     double wndSecs = 1.0;
3687
     _cmXsMeasComplexity(h,wndSecs);
3682
     _cmXsMeasComplexity(h,wndSecs);
3688
 
3683
 

Завантаження…
Відмінити
Зберегти