2023-07-26 00:24:03 +00:00
# include "cwCommon.h"
# include "cwLog.h"
# include "cwCommonImpl.h"
# include "cwMem.h"
# include "cwText.h"
# include "cwObject.h"
# include "cwMidi.h"
# include "cwFileSys.h"
2023-08-20 21:11:53 +00:00
# include "cwDynRefTbl.h"
# include "cwScoreParse.h"
2023-07-26 00:24:03 +00:00
# include "cwSfScore.h"
# include "cwCsv.h"
# include "cwNumericConvert.h"
# include "cwTime.h"
# include "cwVectOps.h"
2023-08-05 16:34:46 +00:00
# include "cwMidi.h"
2023-07-26 00:24:03 +00:00
namespace cw
{
namespace sfscore
{
typedef struct sfscore_str
{
2023-08-20 21:11:53 +00:00
bool deleteParserH_Fl ;
score_parse : : handle_t parserH ;
double srate ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
event_t * eventA ;
2023-08-20 21:11:53 +00:00
unsigned eventAllocN ;
2023-08-05 16:34:46 +00:00
unsigned eventN ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
set_t * setA ;
unsigned setN ;
2023-07-26 00:24:03 +00:00
section_t * sectionA ;
unsigned sectionN ;
2023-08-05 16:34:46 +00:00
loc_t * locA ;
unsigned locN ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
} sfscore_t ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
typedef struct rpt_evt_str
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
event_t * event ;
loc_t * loc ;
section_t * section ;
2023-08-20 21:11:53 +00:00
set_t * setA [ score_parse : : kVarCnt ] ;
2023-08-05 16:34:46 +00:00
} rpt_event_t ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
sfscore_t * _handleToPtr ( handle_t h )
{ return handleToPtr < handle_t , sfscore_t > ( h ) ; }
2023-07-26 00:24:03 +00:00
void _destroy_set ( set_t * s )
{
mem : : release ( s - > eleArray ) ;
mem : : release ( s - > sectArray ) ;
mem : : release ( s ) ;
}
void _destroy_section ( section_t * s )
{
char * ss = ( char * ) ( s - > label ) ;
mem : : release ( ss ) ;
2023-08-05 16:34:46 +00:00
mem : : release ( s - > setArray ) ;
2023-07-26 00:24:03 +00:00
}
rc_t _destroy ( sfscore_t * p )
{
rc_t rc = kOkRC ;
2023-08-05 16:34:46 +00:00
for ( unsigned i = 0 ; i < p - > locN ; + + i )
mem : : release ( p - > locA [ i ] . evtArray ) ;
mem : : release ( p - > locA ) ;
for ( unsigned i = 0 ; i < p - > setN ; + + i )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
mem : : release ( p - > setA [ i ] . eleArray ) ;
mem : : release ( p - > setA [ i ] . sectArray ) ;
}
mem : : release ( p - > setA ) ;
2023-07-26 00:24:03 +00:00
for ( unsigned i = 0 ; i < p - > sectionN ; + + i )
_destroy_section ( p - > sectionA + i ) ;
mem : : release ( p - > sectionA ) ;
mem : : release ( p - > eventA ) ;
2023-08-20 21:11:53 +00:00
if ( p - > deleteParserH_Fl )
destroy ( p - > parserH ) ;
2023-07-26 00:24:03 +00:00
mem : : release ( p ) ;
return rc ;
}
2023-08-20 21:11:53 +00:00
event_t * _hash_to_event ( sfscore_t * p , unsigned hash )
{
for ( unsigned i = 0 ; i < p - > eventN ; + + i )
if ( p - > eventA [ i ] . hash = = hash )
return p - > eventA + i ;
return nullptr ;
}
double _calc_frac ( double rval , unsigned dot_cnt )
{
double mult = 1.0 ;
if ( dot_cnt > 0 )
{
for ( unsigned i = 0 ; i < dot_cnt ; + + i )
mult + = 1.0 / ( 1 < < i ) ;
}
return mult / rval ;
}
2023-08-05 16:34:46 +00:00
rc_t _create_event_array ( sfscore_t * p )
2023-07-26 00:24:03 +00:00
{
rc_t rc = kOkRC ;
2023-08-20 21:11:53 +00:00
const score_parse : : event_t * pe_array = score_parse : : event_array ( p - > parserH ) ;
2023-08-05 16:34:46 +00:00
2023-08-20 21:11:53 +00:00
p - > eventAllocN = score_parse : : event_count ( p - > parserH ) ;
p - > eventN = 0 ;
if ( pe_array = = nullptr | | p - > eventAllocN = = 0 )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
rc = cwLogError ( kInvalidStateRC , " No events were found. " ) ;
2023-07-26 00:24:03 +00:00
goto errLabel ;
}
2023-08-20 21:11:53 +00:00
p - > eventA = mem : : allocZ < event_t > ( p - > eventAllocN ) ;
2023-08-05 16:34:46 +00:00
p - > locN = 0 ;
2023-07-26 00:24:03 +00:00
2023-08-20 21:11:53 +00:00
for ( unsigned i = 0 ; i < p - > eventAllocN ; + + i )
2023-08-05 16:34:46 +00:00
{
2023-08-20 21:11:53 +00:00
event_t * e = p - > eventA + p - > eventN ;
const score_parse : : event_t * pe = pe_array + i ;
if ( cwIsFlag ( pe - > flags , score_parse : : kOnsetFl ) )
{
e - > type = pe - > opId ;
e - > secs = pe - > sec ;
e - > index = p - > eventN ;
e - > locIdx = pe - > oloc ;
e - > pitch = pe - > d0 ;
e - > vel = pe - > d1 ;
e - > flags = 0 ;
e - > dynVal = pe - > dynLevel ;
e - > frac = _calc_frac ( pe - > rval , pe - > dotCnt ) ;
e - > barNumb = pe - > barNumb ;
e - > barNoteIdx = pe - > barPitchIdx ;
e - > csvRowNumb = pe - > csvRowNumb ;
e - > line = pe - > csvRowNumb ;
e - > csvEventId = kInvalidId ; // pe->csvId;
e - > hash = pe - > hash ;
for ( unsigned i = score_parse : : kMinVarIdx ; i < score_parse : : kVarCnt ; + + i )
{
e - > varA [ i ] = pe - > varA [ i ] . flags ;
e - > flags | = pe - > varA [ i ] . flags ;
}
if ( e - > locIdx > p - > locN )
p - > locN = e - > locIdx ;
p - > eventN + = 1 ;
}
2023-08-05 16:34:46 +00:00
}
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
p - > locN + = 1 ; // add one to convert locN from index to count
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
cwLogInfo ( " %i locations. " , p - > locN ) ;
2023-07-26 00:24:03 +00:00
errLabel :
return rc ;
}
2023-08-05 16:34:46 +00:00
rc_t _create_loc_array ( sfscore_t * p )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
rc_t rc = kOkRC ;
unsigned ebi = 0 ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
if ( p - > locN = = 0 )
{
rc = cwLogError ( kInvalidStateRC , " No locations were found. " ) ;
2023-07-26 00:24:03 +00:00
goto errLabel ;
2023-08-05 16:34:46 +00:00
}
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
p - > locA = mem : : allocZ < loc_t > ( p - > locN ) ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
for ( unsigned i = 0 ; i < p - > eventN ; + + i )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
const event_t * e = p - > eventA + i ;
if ( e - > locIdx ! = p - > eventA [ ebi ] . locIdx | | i = = p - > eventN - 1 )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
unsigned locIdx = p - > eventA [ ebi ] . locIdx ;
assert ( locIdx < p - > locN ) ;
loc_t * loc = p - > locA + locIdx ;
loc - > index = p - > eventA [ ebi ] . locIdx ;
loc - > secs = p - > eventA [ ebi ] . secs ;
loc - > barNumb = p - > eventA [ ebi ] . barNumb ;
loc - > evtCnt = ( i - ebi ) + ( i = = p - > eventN - 1 ? 1 : 0 ) ;
loc - > evtArray = mem : : allocZ < event_t * > ( loc - > evtCnt ) ;
for ( unsigned j = 0 ; j < loc - > evtCnt ; + + j )
{
assert ( ebi + j < p - > eventN ) ;
loc - > evtArray [ j ] = p - > eventA + ( ebi + j ) ;
}
ebi = i ;
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
errLabel :
2023-07-26 00:24:03 +00:00
return rc ;
}
2023-08-05 16:34:46 +00:00
rc_t _create_section_array ( sfscore_t * p )
2023-07-26 00:24:03 +00:00
{
rc_t rc = kOkRC ;
2023-08-20 21:11:53 +00:00
p - > sectionN = score_parse : : section_count ( p - > parserH ) ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
// the location array must have already been created.
assert ( p - > locA ! = nullptr ) ;
if ( p - > sectionN = = 0 )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
rc = cwLogError ( kInvalidStateRC , " No sections were found. " ) ;
goto errLabel ;
2023-07-26 00:24:03 +00:00
}
else
{
2023-08-05 16:34:46 +00:00
p - > sectionA = mem : : allocZ < section_t > ( p - > sectionN ) ;
2023-08-20 21:11:53 +00:00
const score_parse : : section_t * ps = score_parse : : section_list ( p - > parserH ) ;
2023-08-05 16:34:46 +00:00
for ( unsigned i = 0 ; i < p - > sectionN ; + + i )
2023-07-26 00:24:03 +00:00
{
2023-08-20 21:11:53 +00:00
if ( ps - > begEvent ! = nullptr )
{
section_t * section = p - > sectionA + i ;
event_t * begEvt = _hash_to_event ( p , ps - > begEvent - > hash ) ;
if ( begEvt = = nullptr )
{
rc = cwLogError ( kInvalidStateRC , " The section '%s' does not have a 'begin' event with hash:%x. " , cwStringNullGuard ( ps - > label ) , ps - > begEvent - > hash ) ;
goto errLabel ;
}
section - > label = mem : : duplStr ( ps - > label ) ;
section - > index = i ;
section - > begEvtIndex = begEvt - > index ;
section - > locPtr = p - > locA + p - > eventA [ begEvt - > index ] . locIdx ;
section - > locPtr - > begSectPtr = section ;
for ( unsigned j = 0 ; j < score_parse : : kVarCnt ; + + j )
section - > vars [ j ] = DBL_MAX ;
}
2023-08-05 16:34:46 +00:00
ps = ps - > link ;
}
2023-07-26 00:24:03 +00:00
}
errLabel :
2023-08-05 16:34:46 +00:00
return rc ;
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
section_t * _label_to_section ( sfscore_t * p , const char * label )
{
for ( unsigned i = 0 ; i < p - > sectionN ; + + i )
if ( textIsEqual ( p - > sectionA [ i ] . label , label ) )
return p - > sectionA + i ;
return nullptr ;
}
rc_t _create_set_array ( sfscore_t * p )
2023-07-26 00:24:03 +00:00
{
rc_t rc = kOkRC ;
2023-08-20 21:11:53 +00:00
const score_parse : : set_t * ps = set_list ( p - > parserH ) ;
2023-07-26 00:24:03 +00:00
2023-08-20 21:11:53 +00:00
p - > setN = score_parse : : set_count ( p - > parserH ) ;
2023-08-05 16:34:46 +00:00
if ( p - > setN = = 0 )
{
rc = cwLogError ( kInvalidStateRC , " No sets were found. " ) ;
2023-07-26 00:24:03 +00:00
goto errLabel ;
2023-08-05 16:34:46 +00:00
}
else
{
p - > setA = mem : : allocZ < set_t > ( p - > setN ) ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
// for each set
for ( unsigned i = 0 ; i < p - > setN ; + + i , ps = ps - > link )
{
assert ( ps ! = nullptr ) ;
section_t * section = nullptr ;
set_t * set = p - > setA + i ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
set - > id = ps - > id ;
set - > varId = ps - > varTypeId ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
// fill in the events belonging to this list
set - > eleCnt = ps - > eventN ;
set - > eleArray = mem : : allocZ < event_t * > ( set - > eleCnt ) ;
for ( unsigned j = 0 ; j < set - > eleCnt ; + + j )
2023-08-20 21:11:53 +00:00
{
set - > eleArray [ j ] = _hash_to_event ( p , ps - > eventA [ j ] - > hash ) ;
if ( set - > eleArray [ j ] = = nullptr )
{
rc = cwLogError ( kInvalidStateRC , " The '%s' set event in measure:%i with hash %x (CSV Row:%i) could not be found. " , score_parse : : var_index_to_char ( ps - > varTypeId ) , ps - > eventA [ j ] - > barNumb , ps - > eventA [ j ] - > hash , ps - > eventA [ j ] - > csvRowNumb ) ;
goto errLabel ;
}
}
2023-08-05 16:34:46 +00:00
// add this set to the setList for the set's end loc
if ( set - > eleCnt > 0 )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
loc_t * end_loc = p - > locA + set - > eleArray [ set - > eleCnt - 1 ] - > locIdx ;
set - > llink = end_loc - > setList ;
end_loc - > setList = set ;
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
// set the target-section related fields fro this set
2023-08-20 21:11:53 +00:00
if ( ps - > targetSection ! = nullptr )
2023-07-26 00:24:03 +00:00
{
2023-08-20 21:11:53 +00:00
if ( ( section = _label_to_section ( p , ps - > targetSection - > label ) ) = = nullptr )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
rc = cwLogError ( kInvalidIdRC , " The section '%s' was not found. " ) ;
2023-07-26 00:24:03 +00:00
goto errLabel ;
}
2023-08-05 16:34:46 +00:00
set - > sectCnt = 1 ;
set - > sectArray = mem : : allocZ < section_t * > ( set - > sectCnt ) ;
set - > sectArray [ 0 ] = section ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
section - > setCnt + = 1 ;
section - > setArray = mem : : resizeZ ( section - > setArray , section - > setCnt ) ;
section - > setArray [ section - > setCnt - 1 ] = set ;
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
}
}
2023-07-26 00:24:03 +00:00
errLabel :
2023-08-05 16:34:46 +00:00
return rc ;
2023-07-26 00:24:03 +00:00
}
2023-08-20 21:11:53 +00:00
rc_t _create ( handle_t & hRef ,
score_parse : : handle_t spH ,
bool deleteParserH_Fl )
{
rc_t rc ;
if ( ( rc = destroy ( hRef ) ) ! = kOkRC )
return rc ;
sfscore_t * p = mem : : allocZ < sfscore_t > ( ) ;
p - > deleteParserH_Fl = deleteParserH_Fl ;
p - > parserH = spH ;
if ( ( rc = _create_event_array ( p ) ) ! = kOkRC )
goto errLabel ;
if ( ( rc = _create_loc_array ( p ) ) ! = kOkRC )
goto errLabel ;
if ( ( rc = _create_section_array ( p ) ) ! = kOkRC )
goto errLabel ;
if ( ( rc = _create_set_array ( p ) ) ! = kOkRC )
goto errLabel ;
hRef . set ( p ) ;
errLabel :
if ( rc ! = kOkRC )
{
rc = cwLogError ( rc , " sfscore create failed. " ) ;
_destroy ( p ) ;
}
return rc ;
}
2023-08-05 16:34:46 +00:00
void _report_print ( sfscore_t * p , rpt_event_t * rptA , unsigned rptN )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
unsigned bar0 = 0 ;
const char * sec0 = nullptr ;
const char * blank_str = " " ;
const char * sec_str = " S: " ;
const char * bar_str = " B: " ;
2023-07-26 00:24:03 +00:00
2023-08-20 21:11:53 +00:00
printf ( " e idx oloc secs op sectn sdx bar bdx scip vel frac \n " ) ;
2023-08-05 16:34:46 +00:00
printf ( " ----- ----- ------- --- ------ --- ----- --- ---- --- ----- \n " ) ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
for ( rpt_event_t * r = rptA ; r < rptA + rptN ; + + r )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
const event_t * e = r - > event ;
const section_t * section = r - > section ;
const char * d_bar_str = bar0 ! = e - > barNumb ? bar_str : blank_str ;
const char * d_sec_str = textIsEqual ( sec0 , section - > label ) ? blank_str : sec_str ;
char sciPitch [ 5 ] ;
midi : : midiToSciPitch ( e - > pitch , sciPitch , 5 ) ;
bar0 = e - > barNumb ;
sec0 = section - > label ;
printf ( " %5i %5i %7.3f %3s %2s%4s %3i %2s%3i %3i %4s %3i %5.3f " ,
e - > index ,
e - > locIdx ,
e - > secs ,
2023-08-20 21:11:53 +00:00
score_parse : : opcode_id_to_label ( e - > type ) ,
2023-08-05 16:34:46 +00:00
d_sec_str ,
section = = nullptr ? " " : cwStringNullGuard ( section - > label ) ,
section - > index ,
d_bar_str ,
e - > barNumb ,
e - > barNoteIdx ,
sciPitch ,
e - > vel ,
e - > frac ) ;
2023-08-20 21:11:53 +00:00
for ( unsigned vi = score_parse : : kMinVarIdx ; vi < score_parse : : kVarCnt ; + + vi )
2023-07-26 00:24:03 +00:00
{
2023-08-20 21:11:53 +00:00
set_t * set = r - > setA [ vi ] ;
2023-08-05 16:34:46 +00:00
if ( set = = nullptr | | set - > sectCnt = = 0 )
printf ( " " ) ;
else
{
const char * sect_label = set - > sectArray [ 0 ] = = nullptr ? " **** " : set - > sectArray [ 0 ] - > label ;
2023-08-20 21:11:53 +00:00
printf ( " %s-%03i-%s " , score_parse : : var_flags_to_char ( e - > varA [ vi ] ) , set - > id , sect_label ) ;
2023-08-05 16:34:46 +00:00
}
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
printf ( " \n " ) ;
}
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
rpt_event_t * _report_create ( sfscore_t * p )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
rpt_event_t * rptA = mem : : allocZ < rpt_event_t > ( p - > eventN ) ;
unsigned curSectionIdx = 0 ;
// for each location
for ( unsigned i = 0 ; i < p - > locN ; + + i )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
loc_t * loc = p - > locA + i ;
assert ( loc - > index = = i ) ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
// for each event assigned to this location
for ( unsigned j = 0 ; j < loc - > evtCnt ; + + j )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
unsigned event_idx = loc - > evtArray [ j ] - > index ;
rpt_event_t * r = rptA + event_idx ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
// store the event
r - > event = p - > eventA + event_idx ;
r - > loc = loc ;
assert ( r - > event - > index = = event_idx ) ;
assert ( r - > event - > barNumb = = loc - > barNumb ) ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
// if this event is the first event in the next section
if ( curSectionIdx < p - > sectionN - 1 & & r - > event - > index = = p - > sectionA [ curSectionIdx + 1 ] . begEvtIndex )
curSectionIdx + = 1 ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
r - > section = p - > sectionA + curSectionIdx ;
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
}
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
for ( unsigned i = 0 ; i < p - > setN ; + + i )
{
set_t * set = p - > setA + i ;
for ( unsigned j = 0 ; j < set - > eleCnt ; + + j )
{
event_t * e = set - > eleArray [ j ] ;
rpt_event_t * r = rptA + e - > index ;
assert ( r - > setA [ set - > varId ] = = nullptr ) ;
r - > setA [ set - > varId ] = set ;
}
}
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
return rptA ;
2023-07-26 00:24:03 +00:00
}
2023-08-05 16:34:46 +00:00
rc_t _report ( sfscore_t * p )
{
rc_t rc = kOkRC ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
rpt_event_t * rptA = nullptr ;
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
if ( ( rptA = _report_create ( p ) ) ! = nullptr )
2023-07-26 00:24:03 +00:00
{
2023-08-05 16:34:46 +00:00
_report_print ( p , rptA , p - > eventN ) ;
mem : : release ( rptA ) ;
}
2023-07-26 00:24:03 +00:00
2023-08-05 16:34:46 +00:00
return rc ;
2023-07-26 00:24:03 +00:00
}
}
}
2023-08-20 21:11:53 +00:00
cw : : rc_t cw : : sfscore : : create ( handle_t & hRef ,
score_parse : : handle_t spH )
{
return _create ( hRef , spH , false ) ;
}
2023-07-26 00:24:03 +00:00
cw : : rc_t cw : : sfscore : : create ( handle_t & hRef ,
const char * fname ,
double srate ,
2023-08-20 21:11:53 +00:00
dyn_ref_tbl : : handle_t dynRefH )
2023-07-26 00:24:03 +00:00
{
rc_t rc ;
2023-08-20 21:11:53 +00:00
score_parse : : handle_t spH ;
2023-07-26 00:24:03 +00:00
2023-08-20 21:11:53 +00:00
if ( ( rc = score_parse : : create ( spH , fname , srate , dynRefH ) ) ! = kOkRC )
2023-07-26 00:24:03 +00:00
{
rc = cwLogError ( rc , " sfscore parse failed. " ) ;
goto errLabel ;
}
2023-08-05 16:34:46 +00:00
2023-08-20 21:11:53 +00:00
rc = _create ( hRef , spH , true ) ;
2023-08-05 16:34:46 +00:00
2023-07-26 00:24:03 +00:00
errLabel :
return rc ;
2023-08-20 21:11:53 +00:00
2023-07-26 00:24:03 +00:00
}
cw : : rc_t cw : : sfscore : : destroy ( handle_t & hRef )
{
rc_t rc = kOkRC ;
if ( ! hRef . isValid ( ) )
return rc ;
sfscore_t * p = _handleToPtr ( hRef ) ;
if ( ( rc = _destroy ( p ) ) ! = kOkRC )
{
rc = cwLogError ( rc , " Destroy failed. " ) ;
goto errLabel ;
}
hRef . clear ( ) ;
errLabel :
return rc ;
}
2023-08-20 21:11:53 +00:00
double cw : : sfscore : : sample_rate ( handle_t & h )
{
sfscore_t * p = _handleToPtr ( h ) ;
return sample_rate ( p - > parserH ) ;
}
2023-07-26 00:24:03 +00:00
unsigned cw : : sfscore : : event_count ( handle_t h )
{
sfscore_t * p = _handleToPtr ( h ) ;
return p - > eventN ;
}
2023-08-05 16:34:46 +00:00
cw : : sfscore : : event_t * cw : : sfscore : : event ( handle_t h , unsigned idx )
{
sfscore_t * p = _handleToPtr ( h ) ;
return p - > eventA + idx ;
}
2023-08-20 21:11:53 +00:00
cw : : sfscore : : event_t * cw : : sfscore : : hash_to_event ( handle_t h , unsigned hash )
{
sfscore_t * p = _handleToPtr ( h ) ;
for ( unsigned i = 0 ; p - > eventN ; + + i )
if ( p - > eventA [ i ] . hash = = hash )
return p - > eventA + i ;
return nullptr ;
}
2023-08-05 16:34:46 +00:00
unsigned cw : : sfscore : : loc_count ( handle_t h )
{
sfscore_t * p = _handleToPtr ( h ) ;
return p - > locN ;
}
cw : : sfscore : : loc_t * cw : : sfscore : : loc ( handle_t h , unsigned idx )
{
sfscore_t * p = _handleToPtr ( h ) ;
return p - > locA + idx ;
}
2023-08-20 21:11:53 +00:00
void cw : : sfscore : : report ( handle_t h , const char * out_fname )
2023-07-26 00:24:03 +00:00
{
sfscore_t * p = _handleToPtr ( h ) ;
2023-08-05 16:34:46 +00:00
printf ( " Score Report \n " ) ;
_report ( p ) ;
2023-07-26 00:24:03 +00:00
}
2023-08-20 21:11:53 +00:00
void cw : : sfscore : : parse_report ( handle_t h )
2023-07-26 00:24:03 +00:00
{
2023-08-20 21:11:53 +00:00
sfscore_t * p = _handleToPtr ( h ) ;
report ( p - > parserH ) ;
2023-07-26 00:24:03 +00:00
}
2023-08-20 21:11:53 +00:00