cwPianoScore.h/cpp : Added loc_count() and is_loc_valid().

This commit is contained in:
kevin 2021-11-05 22:23:18 -04:00
parent 5afd37c259
commit 9d223eafb3
2 changed files with 24 additions and 3 deletions

View File

@ -14,6 +14,7 @@ namespace cw
{ {
event_t* base; event_t* base;
event_t* end; event_t* end;
unsigned maxLocId;
} score_t; } score_t;
score_t* _handleToPtr(handle_t h) score_t* _handleToPtr(handle_t h)
@ -103,6 +104,10 @@ namespace cw
p->base = e; p->base = e;
p->end = e; p->end = e;
// track the max 'loc' id
if( e->loc > p->maxLocId )
p->maxLocId = e->loc;
} }
@ -196,8 +201,7 @@ unsigned cw::score::event_count( handle_t h )
for(event_t* e=p->base; e!=nullptr; e=e->link) for(event_t* e=p->base; e!=nullptr; e=e->link)
++n; ++n;
return n; return n;
} }
const cw::score::event_t* cw::score::base_event( handle_t h ) const cw::score::event_t* cw::score::base_event( handle_t h )
@ -232,3 +236,15 @@ cw::rc_t cw::score::event_to_string( handle_t h, unsigned uid, char* buf, unsig
return rc; return rc;
} }
unsigned cw::score::loc_count( handle_t h )
{
score_t* p = _handleToPtr(h);
return p->maxLocId;
}
bool cw::score::is_loc_valid( handle_t h, unsigned locId )
{
score_t* p = _handleToPtr(h);
return locId < p->maxLocId;
}

View File

@ -33,9 +33,14 @@ namespace cw
rc_t create( handle_t& hRef, const object_t* cfg ); rc_t create( handle_t& hRef, const object_t* cfg );
rc_t destroy( handle_t& hRef ); rc_t destroy( handle_t& hRef );
unsigned event_count( handle_t h ); unsigned event_count( handle_t h );
const event_t* base_event( handle_t h ); const event_t* base_event( handle_t h );
unsigned loc_count( handle_t h );
bool is_loc_valid( handle_t h, unsigned locId );
// 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 );