From 053675a94c2ae2d0f63e1afe7342b3c842d25552 Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 3 Dec 2023 11:21:26 -0500 Subject: [PATCH] cwPianoScore.cpp : Use cwCsv to read either score followed MIDI files or the score file. --- cwPianoScore.cpp | 233 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 207 insertions(+), 26 deletions(-) diff --git a/cwPianoScore.cpp b/cwPianoScore.cpp index dec0457..f2d05fb 100644 --- a/cwPianoScore.cpp +++ b/cwPianoScore.cpp @@ -17,7 +17,33 @@ namespace cw { namespace perf_score { - typedef struct score_str + /* + 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; event_t* end; @@ -31,6 +57,24 @@ 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(h); @@ -72,6 +116,164 @@ namespace cw } } + + rc_t _read_csv_line( score_t* p, bool score_fl, csv::handle_t csvH ) + { + rc_t rc = kOkRC; + event_t* e = mem::allocZ(); + const char* sci_pitch; + unsigned sci_pitch_char_cnt; + + if((rc = getv(csvH, + "meas",e->meas, + "loc",e->loc, + "sec",e->sec, + "sci_pitch", sci_pitch, + "status", e->status, + "d0", e->d0, + "d1", e->d1, + "bar", e->bar, + "section", e->section )) != kOkRC ) + { + rc = cwLogError(rc,"Error parsing CSV."); + goto errLabel; + } + + if( score_fl ) + { + if((rc = getv(csvH,"oloc",e->loc )) != kOkRC ) + { + rc = cwLogError(rc,"Error parsing CSV."); + goto errLabel; + } + + } + else + { + if((rc = getv(csvH, + "even", e->even, + "dyn", e->dyn, + "tempo", e->tempo, + "cost", e->cost )) != kOkRC ) + { + rc = cwLogError(rc,"Error parsing CSV."); + goto errLabel; + } + } + + if((rc = field_char_count( csvH, title_col_index(csvH,"sci_pitch"), sci_pitch_char_cnt )) != kOkRC ) + { + rc = cwLogError(rc,"Error retrieving the sci. pitch char count."); + goto errLabel; + } + + strncpy(e->sci_pitch,sci_pitch,sizeof(e->sci_pitch)); + + if( p->end == nullptr ) + { + p->base = e; + p->end = e; + } + else + { + p->end->link = 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: + + if( rc != kOkRC ) + mem::release(e); + + return rc; + } + + rc_t _read_csv( score_t* p, const char* csvFname ) + { + 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