From ae24afd2ae3691939d580da098f3c28d9eb9d060 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 16 Apr 2025 15:21:05 -0400 Subject: [PATCH] cwPianoScore.h/cpp : Added event_t.chord_note_cnt and chord_note_idx and _get_loc_count() and _setup_chord_info(). --- cwPianoScore.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++--- cwPianoScore.h | 2 ++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/cwPianoScore.cpp b/cwPianoScore.cpp index 3be6036..2f4f039 100644 --- a/cwPianoScore.cpp +++ b/cwPianoScore.cpp @@ -40,6 +40,8 @@ namespace cw unsigned min_uid; bool has_locs_fl; + bool uses_oloc_fl; + } score_t; @@ -106,7 +108,47 @@ namespace cw } } + } + unsigned _get_loc_count( const score_t* p ) + { + unsigned max_loc = 0; + for(const event_t* e=p->base; e!=nullptr; e=e->link) + if(midi::isNoteOn(e->status,e->d1)) + if( e->loc != kInvalidId && e->loc > max_loc ) + max_loc = e->loc; + + return max_loc+1; + } + + void _setup_chord_info( score_t* p ) + { + unsigned locN = _get_loc_count(p); + unsigned* locA = mem::allocZ(locN); + + // get the count of notes per loc and set event_t.chord_note_cnt + for(event_t* e=p->base; e!=nullptr; e=e->link) + { + if(midi::isNoteOn(e->status,e->d1)) + { + assert( e->loc < locN ); + e->chord_note_idx = locA[ e->loc ]; + locA[ e->loc ] += 1; + } + else + { + e->chord_note_idx = kInvalidIdx; + e->chord_note_cnt = 0; + } + } + + // set the event_t.chord_note_cnt + for(event_t* e=p->base; e!=nullptr; e=e->link) + if(midi::isNoteOn(e->status,e->d1)) + e->chord_note_cnt = locA[ e->loc ]; + + mem::free(locA); + } @@ -251,7 +293,8 @@ namespace cw { csv::handle_t csvH; rc_t rc = kOkRC; - bool score_fl = false; + + p->uses_oloc_fl = false; if((rc = csv::create(csvH,csvFname)) != kOkRC ) { @@ -263,10 +306,10 @@ namespace cw // an 'oloc' field and the recorded performance // files which do not. if( title_col_index(csvH,"oloc") != kInvalidIdx ) - score_fl = true; + p->uses_oloc_fl = true; for(unsigned i=0; (rc = next_line(csvH)) == kOkRC; ++i ) - if((rc = _read_csv_line(p,score_fl,csvH)) != kOkRC ) + if((rc = _read_csv_line(p,p->uses_oloc_fl,csvH)) != kOkRC ) { rc = cwLogError(rc,"Error reading CSV line number:%i.",i+1); goto errLabel; @@ -485,6 +528,9 @@ cw::rc_t cw::perf_score::create( handle_t& hRef, const char* fn ) p->has_locs_fl = false; } + if( p->uses_oloc_fl ) + _setup_chord_info(p); + _setup_feat_vectors(p); hRef.set(p); diff --git a/cwPianoScore.h b/cwPianoScore.h index 2d6adda..88a8123 100644 --- a/cwPianoScore.h +++ b/cwPianoScore.h @@ -38,6 +38,8 @@ namespace cw unsigned bar; // bar number or 0 unsigned barPitchIdx; // bar pitch index or 0 unsigned section; // section number or 0 + unsigned chord_note_cnt;// count of notes in the chord which this note-on msg is part of + unsigned chord_note_idx;// which note in the chord is this note-on msg (or kInvalididx if this is not a note-on msg) bool valid_stats_fl; // is statsA valid in this record[] stats_t statsA[ perf_meas::kValCnt ];