cwPianoScore.h/cpp : Added loc_to_measure() and loc_to_next_note_on_measure()

This commit is contained in:
kevin 2022-12-05 17:21:02 -05:00
parent 6a9351b043
commit b680d46487
2 changed files with 37 additions and 2 deletions

View File

@ -326,6 +326,17 @@ namespace cw
return nullptr; return nullptr;
} }
const event_t* _loc_to_event( score_t* p, unsigned loc )
{
const event_t* e = p->base;
for(; e!=nullptr; e=e->link)
if( e->loc == loc )
return e;
return nullptr;
}
} }
} }
@ -467,10 +478,31 @@ bool cw::score::is_loc_valid( handle_t h, unsigned locId )
return locId < p->maxLocId; return locId < p->maxLocId;
} }
unsigned cw::score::loc_to_measure( handle_t h, unsigned locId )
{
score_t* p = _handleToPtr(h);
const event_t* e;
if((e = _loc_to_event(p,locId)) == nullptr )
return 0;
return kInvalidId;
}
unsigned cw::score::loc_to_next_note_on_measure( handle_t h, unsigned locId )
{
score_t* p = _handleToPtr(h);
const event_t* e = _loc_to_event(p,locId);
while( e != nullptr )
if( midi::isNoteOn(e->status))
return e->meas;
return kInvalidId;
}
const cw::score::event_t* cw::score::uid_to_event( handle_t h, unsigned uid ) const cw::score::event_t* cw::score::uid_to_event( handle_t h, unsigned uid )
{ {
//hscore_t* p = _handleToPtr(h);
score_t* p = _handleToPtr(h);
return nullptr; return nullptr;
} }

View File

@ -39,9 +39,12 @@ namespace cw
unsigned loc_count( handle_t h ); unsigned loc_count( handle_t h );
bool is_loc_valid( handle_t h, unsigned locId ); bool is_loc_valid( handle_t h, unsigned locId );
unsigned loc_to_measure( handle_t h, unsigned locId );
unsigned loc_to_next_note_on_measure( handle_t h, unsigned locId );
const event_t* uid_to_event( handle_t h, unsigned uid ); const event_t* uid_to_event( handle_t h, unsigned uid );
// Format the event as a string for printing. // Format the event as a string for printing.
rc_t event_to_string( handle_t h, unsigned uid, char* buf, unsigned buf_byte_cnt ); rc_t event_to_string( handle_t h, unsigned uid, char* buf, unsigned buf_byte_cnt );