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

This commit is contained in:
kevin 2016-09-15 18:00:04 -04:00
parent 7eac59b3ca
commit 85878f995b

View File

@ -3111,13 +3111,15 @@ unsigned _cmXsHistValue( cmXsHist_t* hist, unsigned histN )
return n; return n;
} }
// Measure the score complexity for the the time window 'wndSecs' seconds
// prior to the note n1 and following n0.
const cmXsNote_t* _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t* n1, double wndSecs ) const cmXsNote_t* _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t* n1, double wndSecs )
{ {
const cmXsNote_t* n2 = NULL; const cmXsNote_t* n2 = NULL;
unsigned l_pch_0 = 0; unsigned l_pch_0 = 0;
unsigned l_pch_value = 0; unsigned l_pch_value = 0;
unsigned l_pch_cnt = 0; unsigned l_pch_cnt = n1->staff==1 ? 0 : 1;
unsigned r_pch_0 = 0; unsigned r_pch_0 = n1->staff==1 ? 1 : 0;
unsigned r_pch_value = 0; unsigned r_pch_value = 0;
unsigned r_pch_cnt = 0; unsigned r_pch_cnt = 0;
unsigned i = 0; unsigned i = 0;
@ -3136,38 +3138,29 @@ const cmXsNote_t* _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t
{ {
// if this event is less than wndSecs behind 'n1' and is not a sounding note ... // if this event is less than wndSecs behind 'n1' and is not a sounding note ...
if( n1->secs - n->secs <= wndSecs && cmIsFlag(n->flags,kOnsetXsFl) ) if( n1->secs - n->secs <= wndSecs && cmIsFlag(n->flags,kOnsetXsFl) )
{
// if this is not the first note in the window
if( i > 0 )
{ {
_cmXsHistUpdateI( velHist, histN, n->dynamics ); _cmXsHistUpdateI( velHist, histN, n->dynamics );
_cmXsHistUpdateF( rymHist, histN, n->rvalue ); _cmXsHistUpdateF( rymHist, histN, n->rvalue );
switch( n->staff ) switch( n->staff )
{ {
case 1: case 1: // treble cleff
if( i > 0 )
{
r_pch_value += r_pch_0 > n->pitch ? r_pch_0-n->pitch : n->pitch-r_pch_0; r_pch_value += r_pch_0 > n->pitch ? r_pch_0-n->pitch : n->pitch-r_pch_0;
r_pch_cnt += 1; r_pch_cnt += 1;
break;
case 2:
l_pch_value += l_pch_0 > n->pitch ? l_pch_0-n->pitch : n->pitch-l_pch_0;
r_pch_cnt += 1;
break;
default:
{ assert(0); }
}
} }
// store the pitch values to compare on the next interation
switch( n->staff )
{
case 1:
r_pch_0 = n->pitch; r_pch_0 = n->pitch;
break; break;
case 2: case 2: // bass cleff
if( i > 0 )
{
l_pch_value += l_pch_0 > n->pitch ? l_pch_0-n->pitch : n->pitch-l_pch_0;
l_pch_cnt += 1;
}
l_pch_0 = n->pitch; l_pch_0 = n->pitch;
break; break;
@ -3202,6 +3195,7 @@ const cmXsNote_t* _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t
} }
// update the cplx record in n1 with the results of this window analysis
n1->cplx.sum_d_vel = _cmXsHistValue( velHist, histN ); n1->cplx.sum_d_vel = _cmXsHistValue( velHist, histN );
n1->cplx.sum_d_rym = _cmXsHistValue( rymHist, histN ); n1->cplx.sum_d_rym = _cmXsHistValue( rymHist, histN );
n1->cplx.sum_d_lpch = l_pch_value; n1->cplx.sum_d_lpch = l_pch_value;
@ -3212,6 +3206,8 @@ const cmXsNote_t* _cmXsMeasComplexityInWindow( const cmXsNote_t* n0, cmXsNote_t
return n2; return n2;
} }
// Measure the score complexity and fill in the cmXsComplexity_t record associated
// with the cmXsNote_t record of each sounding note.
cmXsRC_t _cmXsMeasComplexity( cmXsH_t h, double wndSecs ) cmXsRC_t _cmXsMeasComplexity( cmXsH_t h, double wndSecs )
{ {
cmXsRC_t rc = kOkXsRC; cmXsRC_t rc = kOkXsRC;
@ -3361,8 +3357,6 @@ cmXsRC_t _cmXsWriteMidiFile( cmCtx_t* ctx, cmXsH_t h, const cmChar_t* dir, const
return rc; return rc;
} }
typedef struct cmXsSvgEvt_str typedef struct cmXsSvgEvt_str
{ {
unsigned flags; // k???XsFl unsigned flags; // k???XsFl
@ -3630,7 +3624,6 @@ cmXsRC_t _cmXScoreGenSvg( cmCtx_t* ctx, cmXsH_t h, const cmChar_t* dir, const cm
return _cmXsWriteMidiSvg( ctx, p, &mf, dir, fn ); return _cmXsWriteMidiSvg( ctx, p, &mf, dir, fn );
} }
cmXsRC_t cmXScoreTest( cmXsRC_t cmXScoreTest(
@ -3683,6 +3676,8 @@ cmXsRC_t cmXScoreTest(
if( midiOutFn != NULL ) if( midiOutFn != NULL )
{ {
// measure the score complexity
double wndSecs = 1.0; double wndSecs = 1.0;
_cmXsMeasComplexity(h,wndSecs); _cmXsMeasComplexity(h,wndSecs);