cwPianoScore.cpp : Removed dead code.
This commit is contained in:
parent
4e11bfa7ee
commit
a571951d95
328
cwPianoScore.cpp
328
cwPianoScore.cpp
@ -17,32 +17,6 @@ namespace cw
|
||||
{
|
||||
namespace perf_score
|
||||
{
|
||||
/*
|
||||
enum {
|
||||
kMeasColIdx = 0,
|
||||
kLocColIdx,
|
||||
kSecColIdx,
|
||||
kSciPitchColIdx,
|
||||
kStatusColIdx,
|
||||
kD0ColIdx,
|
||||
kD1ColIdx,
|
||||
kBarColIdx,
|
||||
kSectionColIdx,
|
||||
kEvenColIdx,
|
||||
kDynColIdx,
|
||||
kTempoColIdx,
|
||||
kCostColIdx,
|
||||
kColCnt
|
||||
};
|
||||
|
||||
typedef struct col_map_str
|
||||
{
|
||||
unsigned colId;
|
||||
const char* label;
|
||||
bool enableFl;
|
||||
} col_map_t;
|
||||
*/
|
||||
|
||||
typedef struct score_str
|
||||
{
|
||||
event_t* base;
|
||||
@ -57,24 +31,6 @@ namespace cw
|
||||
|
||||
} score_t;
|
||||
|
||||
/*
|
||||
col_map_t col_map_array[] = {
|
||||
{ kMeasColIdx, "meas", true },
|
||||
{ kLocColIdx, "loc", true },
|
||||
{ kLocColIdx, "oloc", false },
|
||||
{ kSecColIdx, "sec", true },
|
||||
{ kSciPitchColIdx, "sci_pitch", true },
|
||||
{ kStatusColIdx, "status", true },
|
||||
{ kD0ColIdx, "d0", true },
|
||||
{ kD1ColIdx, "d1", true },
|
||||
{ kBarColIdx, "bar", true },
|
||||
{ kSectionColIdx, "section", true },
|
||||
{ kEvenColIdx, "even", true },
|
||||
{ kDynColIdx, "dyn", true },
|
||||
{ kTempoColIdx, "tempo", true },
|
||||
{ kCostColIdx, "cost", true },
|
||||
};
|
||||
*/
|
||||
score_t* _handleToPtr(handle_t h)
|
||||
{
|
||||
return handleToPtr<handle_t,score_t>(h);
|
||||
@ -203,16 +159,6 @@ namespace cw
|
||||
csv::handle_t csvH;
|
||||
rc_t rc = kOkRC;
|
||||
bool score_fl = false;
|
||||
/*
|
||||
//unsigned titleN = sizeof(col_map_array)/sizeof(col_map_array[0]);
|
||||
//const char* titleA[ titleN ];
|
||||
|
||||
for(unsigned i=0; i<titleN; ++i)
|
||||
{
|
||||
titleA[i] = col_map_array[i].label;
|
||||
assert( col_map_array[i].colId == i );
|
||||
}
|
||||
*/
|
||||
|
||||
if((rc = csv::create(csvH,csvFname)) != kOkRC )
|
||||
{
|
||||
@ -220,21 +166,12 @@ namespace cw
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// Distinguish between the score file which has
|
||||
// an 'oloc' field and the recorded performance
|
||||
// files which do not.
|
||||
if( title_col_index(csvH,"oloc") != kInvalidIdx )
|
||||
score_fl = true;
|
||||
|
||||
/*
|
||||
for(unsigned i=0; i<titleN; ++i)
|
||||
if( col_map_array[i].enableFl )
|
||||
{
|
||||
if((col_map_array[i].colIdx = title_col_index(csvH,col_map_array[i].label)) == kInvalidIdx )
|
||||
{
|
||||
rc = cwLogError(rc,"The performance score column '%s' was not found in the score file:'%s'.",col_map_array[i].label,cwStringNullGuard(csvFname));
|
||||
goto errLabel;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
for(unsigned i=0; (rc = next_line(csvH)) == kOkRC; ++i )
|
||||
if((rc = _read_csv_line(p,score_fl,csvH)) != kOkRC )
|
||||
{
|
||||
@ -273,255 +210,6 @@ namespace cw
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
unsigned _scan_to_end_of_field( const char* lineBuf, unsigned buf_idx, unsigned bufCharCnt )
|
||||
{
|
||||
for(; buf_idx < bufCharCnt; ++buf_idx )
|
||||
{
|
||||
if( lineBuf[buf_idx] == '"' )
|
||||
{
|
||||
for(++buf_idx; buf_idx < bufCharCnt; ++buf_idx)
|
||||
if( lineBuf[buf_idx] == '"' )
|
||||
break;
|
||||
}
|
||||
|
||||
if( lineBuf[buf_idx] == ',')
|
||||
break;
|
||||
}
|
||||
|
||||
return buf_idx;
|
||||
}
|
||||
|
||||
rc_t _parse_csv_string( const char* lineBuf, unsigned bfi, unsigned efi, char* val, unsigned valCharN )
|
||||
{
|
||||
unsigned n = std::min(efi-bfi,valCharN);
|
||||
strncpy(val,lineBuf+bfi,n);
|
||||
val[std::min(n,valCharN-1)] = 0;
|
||||
return kOkRC;
|
||||
}
|
||||
|
||||
rc_t _parse_csv_double( const char* lineBuf, unsigned bfi, unsigned efi, double &valueRef )
|
||||
{
|
||||
errno = 0;
|
||||
valueRef = strtod(lineBuf+bfi,nullptr);
|
||||
if( errno != 0 )
|
||||
return cwLogError(kOpFailRC,"CSV String to number conversion failed.");
|
||||
|
||||
return kOkRC;
|
||||
}
|
||||
|
||||
rc_t _parse_csv_unsigned( const char* lineBuf, unsigned bfi, unsigned efi, unsigned &valueRef )
|
||||
{
|
||||
rc_t rc;
|
||||
double v;
|
||||
if((rc = _parse_csv_double(lineBuf,bfi,efi,v)) == kOkRC )
|
||||
valueRef = (unsigned)v;
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc_t _parse_csv_line( score_t* p, event_t* e, char* line_buf, unsigned lineBufCharCnt )
|
||||
{
|
||||
enum
|
||||
{
|
||||
kMeas_FIdx,
|
||||
kIndex_FIdx,
|
||||
kVoice_FIdx,
|
||||
kLoc_FIdx,
|
||||
kTick_FIdx,
|
||||
kSec_FIdx,
|
||||
kDur_FIdx,
|
||||
kRval_FIdx,
|
||||
kDots_FIdx,
|
||||
kSPitch_FIdx,
|
||||
kDMark_FIdx,
|
||||
kDLevel_FIdx,
|
||||
kStatus_FIdx,
|
||||
kD0_FIdx,
|
||||
kD1_FIdx,
|
||||
kBar_FIdx,
|
||||
kSection_FIdx,
|
||||
kBpm_FIdx,
|
||||
kGrace_FIdx,
|
||||
kPedal_FIdx,
|
||||
kEven_FIdx,
|
||||
kDyn_FIdx,
|
||||
kTempo_FIdx,
|
||||
kCost_FIdx,
|
||||
kMax_FIdx
|
||||
};
|
||||
|
||||
rc_t rc = kOkRC;
|
||||
unsigned bfi = 0;
|
||||
unsigned efi = 0;
|
||||
unsigned field_idx = 0;
|
||||
|
||||
|
||||
for(field_idx=0; field_idx != kMax_FIdx; ++field_idx)
|
||||
{
|
||||
if((efi = _scan_to_end_of_field(line_buf,efi,lineBufCharCnt)) == kInvalidIdx )
|
||||
{
|
||||
rc = cwLogError( rc, "End of field scan failed");
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if( bfi != efi )
|
||||
{
|
||||
switch( field_idx )
|
||||
{
|
||||
case kMeas_FIdx:
|
||||
rc = _parse_csv_unsigned( line_buf, bfi, efi, e->meas );
|
||||
break;
|
||||
|
||||
case kLoc_FIdx:
|
||||
rc = _parse_csv_unsigned( line_buf, bfi, efi, e->loc );
|
||||
break;
|
||||
|
||||
case kSec_FIdx:
|
||||
rc = _parse_csv_double( line_buf, bfi, efi, e->sec );
|
||||
break;
|
||||
|
||||
case kStatus_FIdx:
|
||||
rc = _parse_csv_unsigned( line_buf, bfi, efi, e->status );
|
||||
break;
|
||||
|
||||
case kD0_FIdx:
|
||||
rc = _parse_csv_unsigned( line_buf, bfi, efi, e->d0 );
|
||||
break;
|
||||
|
||||
case kD1_FIdx:
|
||||
rc = _parse_csv_unsigned( line_buf, bfi, efi, e->d1 );
|
||||
break;
|
||||
|
||||
case kBar_FIdx:
|
||||
rc = _parse_csv_unsigned( line_buf, bfi, efi, e->bar );
|
||||
break;
|
||||
|
||||
case kSection_FIdx:
|
||||
rc = _parse_csv_unsigned( line_buf, bfi, efi, e->section );
|
||||
break;
|
||||
|
||||
case kSPitch_FIdx:
|
||||
rc = _parse_csv_string( line_buf, bfi, efi, e->sci_pitch, sizeof(e->sci_pitch) );
|
||||
break;
|
||||
|
||||
case kEven_FIdx:
|
||||
e->even = INVALID_PERF_MEAS;
|
||||
if( efi > bfi+1 )
|
||||
rc = _parse_csv_double( line_buf, bfi, efi, e->even );
|
||||
break;
|
||||
|
||||
case kDyn_FIdx:
|
||||
e->dyn = INVALID_PERF_MEAS;
|
||||
if( efi > bfi+1 )
|
||||
rc = _parse_csv_double( line_buf, bfi, efi, e->dyn );
|
||||
break;
|
||||
|
||||
case kTempo_FIdx:
|
||||
e->tempo = INVALID_PERF_MEAS;
|
||||
if( efi > bfi+1 )
|
||||
rc = _parse_csv_double( line_buf, bfi, efi, e->tempo );
|
||||
break;
|
||||
|
||||
case kCost_FIdx:
|
||||
e->cost = INVALID_PERF_MEAS;
|
||||
if( efi > bfi+1 )
|
||||
rc = _parse_csv_double( line_buf, bfi, efi, e->cost );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bfi = efi + 1;
|
||||
efi = efi + 1;
|
||||
|
||||
}
|
||||
|
||||
errLabel:
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
rc_t _parse_csv( score_t* p, const char* fn )
|
||||
{
|
||||
rc_t rc;
|
||||
file::handle_t fH;
|
||||
unsigned line_count = 0;
|
||||
char* lineBufPtr = nullptr;
|
||||
unsigned lineBufCharCnt = 0;
|
||||
event_t* e = nullptr;
|
||||
|
||||
if((rc = file::open( fH, fn, file::kReadFl )) != kOkRC )
|
||||
{
|
||||
rc = cwLogError( rc, "Piano score file open failed on '%s'.",cwStringNullGuard(fn));
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if((rc = file::lineCount(fH,&line_count)) != kOkRC )
|
||||
{
|
||||
rc = cwLogError( rc, "Line count query failed on '%s'.",cwStringNullGuard(fn));
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
p->min_uid = kInvalidId;
|
||||
p->uid_mapN = 0;
|
||||
|
||||
for(unsigned line=0; line<line_count; ++line)
|
||||
{
|
||||
if((rc = getLineAuto( fH, &lineBufPtr, &lineBufCharCnt )) != kOkRC )
|
||||
{
|
||||
if( rc != kEofRC )
|
||||
rc = cwLogError( rc, "Line read failed on '%s' line number '%i'.",cwStringNullGuard(fn),line+1);
|
||||
else
|
||||
rc = kOkRC;
|
||||
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if( line > 0 ) // skip column title line
|
||||
{
|
||||
|
||||
e = mem::allocZ<event_t>();
|
||||
|
||||
if((rc = _parse_csv_line( p, e, lineBufPtr, lineBufCharCnt )) != kOkRC )
|
||||
{
|
||||
mem::release(e);
|
||||
rc = cwLogError( rc, "Line parse failed on '%s' line number '%i'.",cwStringNullGuard(fn),line+1);
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// assign the UID
|
||||
e->uid = line;
|
||||
|
||||
// link the event into the event list
|
||||
if( p->end != nullptr )
|
||||
p->end->link = e;
|
||||
else
|
||||
p->base = e;
|
||||
|
||||
p->end = e;
|
||||
|
||||
// track the max 'loc' id
|
||||
if( e->loc > p->maxLocId )
|
||||
p->maxLocId = e->loc;
|
||||
|
||||
if( p->min_uid == kInvalidId || e->uid < p->min_uid )
|
||||
p->min_uid = e->uid;
|
||||
|
||||
p->uid_mapN += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
errLabel:
|
||||
mem::release(lineBufPtr);
|
||||
file::close(fH);
|
||||
|
||||
return rc;
|
||||
}
|
||||
*/
|
||||
rc_t _parse_event_list( score_t* p, const object_t* cfg )
|
||||
{
|
||||
rc_t rc;
|
||||
@ -574,16 +262,6 @@ namespace cw
|
||||
textCopy( e->sci_pitch,sizeof(e->sci_pitch),sci_pitch);
|
||||
textCopy( e->dmark,sizeof(e->dmark),dmark);
|
||||
textCopy( e->grace_mark, sizeof(e->grace_mark),grace_mark);
|
||||
/*
|
||||
if( sci_pitch != nullptr )
|
||||
strncpy(e->sci_pitch,sci_pitch,sizeof(e->sci_pitch)-1);
|
||||
|
||||
if( dmark != nullptr )
|
||||
strncpy(e->dmark,dmark,sizeof(e->dmark)-1);
|
||||
|
||||
if( grace_mark != nullptr )
|
||||
strncpy(e->grace_mark,grace_mark,sizeof(e->grace_mark)-1);
|
||||
*/
|
||||
|
||||
// assign the UID
|
||||
e->uid = i;
|
||||
|
Loading…
Reference in New Issue
Block a user