cwPianoScore.h/cpp : Comment unused loc_???() functions. Added create_from_midi_csv() and has_loc_info_flag().
This commit is contained in:
parent
440c35201a
commit
8832ae60e0
109
cwPianoScore.cpp
109
cwPianoScore.cpp
@ -7,6 +7,7 @@
|
|||||||
#include "cwMidi.h"
|
#include "cwMidi.h"
|
||||||
#include "cwTime.h"
|
#include "cwTime.h"
|
||||||
#include "cwFile.h"
|
#include "cwFile.h"
|
||||||
|
#include "cwCsv.h"
|
||||||
|
|
||||||
namespace cw
|
namespace cw
|
||||||
{
|
{
|
||||||
@ -22,6 +23,8 @@ namespace cw
|
|||||||
unsigned uid_mapN;
|
unsigned uid_mapN;
|
||||||
unsigned min_uid;
|
unsigned min_uid;
|
||||||
|
|
||||||
|
bool has_locs_fl;
|
||||||
|
|
||||||
} score_t;
|
} score_t;
|
||||||
|
|
||||||
score_t* _handleToPtr(handle_t h)
|
score_t* _handleToPtr(handle_t h)
|
||||||
@ -326,6 +329,60 @@ namespace cw
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc_t _parse_midi_csv( score_t* p, const char* fn )
|
||||||
|
{
|
||||||
|
rc_t rc = kOkRC;
|
||||||
|
csv::handle_t csvH;
|
||||||
|
const char* titleA[] = { "dev","port","microsec","id","sec","ch","status","sci_pitch","d0","d1" };
|
||||||
|
const unsigned titleN = sizeof(titleA)/sizeof(titleA[0]);
|
||||||
|
|
||||||
|
if((rc = csv::create(csvH,fn,titleA, titleN)) != kOkRC )
|
||||||
|
{
|
||||||
|
rc = cwLogError(rc,"CSV object create failed on '%s'.",cwStringNullGuard(fn));
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned i=0; (rc = next_line(csvH)) == kOkRC; ++i )
|
||||||
|
{
|
||||||
|
unsigned ch = 0;
|
||||||
|
event_t* e = mem::allocZ<event_t>();
|
||||||
|
|
||||||
|
|
||||||
|
if((rc = csv::getv(csvH,
|
||||||
|
"id",e->uid,
|
||||||
|
"sec",e->sec,
|
||||||
|
"ch",ch,
|
||||||
|
"status",e->status,
|
||||||
|
"d0",e->d0,
|
||||||
|
"d1",e->d1)) != kOkRC )
|
||||||
|
{
|
||||||
|
rc = cwLogError(rc,"CSV parse failed on line index:%i of '%s'.",i,cwStringNullGuard(fn));
|
||||||
|
mem::release(e);
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
e->status += ch;
|
||||||
|
e->loc = e->uid;
|
||||||
|
|
||||||
|
// link the event into the event list
|
||||||
|
if( p->end != nullptr )
|
||||||
|
p->end->link = e;
|
||||||
|
else
|
||||||
|
p->base = e;
|
||||||
|
|
||||||
|
p->end = e;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
errLabel:
|
||||||
|
if((rc = csv::destroy(csvH)) != kOkRC )
|
||||||
|
rc = cwLogError(rc,"CSV object destroy failed on '%s'.",cwStringNullGuard(fn));
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const event_t* _uid_to_event( score_t* p, unsigned uid )
|
const event_t* _uid_to_event( score_t* p, unsigned uid )
|
||||||
{
|
{
|
||||||
const event_t* e = p->base;
|
const event_t* e = p->base;
|
||||||
@ -360,26 +417,13 @@ cw::rc_t cw::score::create( handle_t& hRef, const char* fn )
|
|||||||
if((rc = destroy(hRef)) != kOkRC )
|
if((rc = destroy(hRef)) != kOkRC )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
// parse the cfg file
|
|
||||||
/*
|
|
||||||
if((rc = objectFromFile( fn, cfg )) != kOkRC )
|
|
||||||
{
|
|
||||||
rc = cwLogError(rc,"Score parse failed on file: '%s'.", fn);
|
|
||||||
goto errLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = create(hRef,cfg);
|
|
||||||
*/
|
|
||||||
|
|
||||||
p = mem::allocZ< score_t >();
|
p = mem::allocZ< score_t >();
|
||||||
|
|
||||||
rc = _parse_csv(p,fn);
|
rc = _parse_csv(p,fn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hRef.set(p);
|
hRef.set(p);
|
||||||
|
|
||||||
//errLabel:
|
p->has_locs_fl = true;
|
||||||
|
|
||||||
if( cfg != nullptr )
|
if( cfg != nullptr )
|
||||||
cfg->free();
|
cfg->free();
|
||||||
@ -405,6 +449,8 @@ cw::rc_t cw::score::create( handle_t& hRef, const object_t* cfg )
|
|||||||
goto errLabel;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p->has_locs_fl = true;
|
||||||
|
|
||||||
hRef.set(p);
|
hRef.set(p);
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
@ -414,6 +460,33 @@ cw::rc_t cw::score::create( handle_t& hRef, const object_t* cfg )
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cw::rc_t cw::score::create_from_midi_csv( handle_t& hRef, const char* fn )
|
||||||
|
{
|
||||||
|
rc_t rc;
|
||||||
|
if((rc = destroy(hRef)) != kOkRC )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
score_t* p = mem::allocZ< score_t >();
|
||||||
|
|
||||||
|
// parse the event list
|
||||||
|
if((rc = _parse_midi_csv(p, fn)) != kOkRC )
|
||||||
|
{
|
||||||
|
rc = cwLogError(rc,"Score event list parse failed.");
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->has_locs_fl = false;
|
||||||
|
|
||||||
|
hRef.set(p);
|
||||||
|
|
||||||
|
errLabel:
|
||||||
|
if( rc != kOkRC )
|
||||||
|
destroy(hRef);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
cw::rc_t cw::score::destroy( handle_t& hRef )
|
cw::rc_t cw::score::destroy( handle_t& hRef )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
@ -432,6 +505,12 @@ cw::rc_t cw::score::destroy( handle_t& hRef )
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cw::score::has_loc_info_flag( handle_t h )
|
||||||
|
{
|
||||||
|
score_t* p = _handleToPtr(h);
|
||||||
|
return p->has_locs_fl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned cw::score::event_count( handle_t h )
|
unsigned cw::score::event_count( handle_t h )
|
||||||
{
|
{
|
||||||
@ -455,6 +534,7 @@ const cw::score::event_t* cw::score::loc_to_event( handle_t h, unsigned loc )
|
|||||||
return _loc_to_event(p,loc);
|
return _loc_to_event(p,loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
unsigned cw::score::loc_count( handle_t h )
|
unsigned cw::score::loc_count( handle_t h )
|
||||||
{
|
{
|
||||||
score_t* p = _handleToPtr(h);
|
score_t* p = _handleToPtr(h);
|
||||||
@ -497,6 +577,7 @@ double cw::score::locs_to_diff_seconds( handle_t h, unsigned loc0Id, unsigned l
|
|||||||
|
|
||||||
return e1->sec - e0->sec;
|
return e1->sec - e0->sec;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
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 )
|
||||||
{
|
{
|
||||||
|
@ -31,19 +31,27 @@ namespace cw
|
|||||||
|
|
||||||
rc_t create( handle_t& hRef, const char* fn );
|
rc_t create( handle_t& hRef, const char* fn );
|
||||||
rc_t create( handle_t& hRef, const object_t* cfg );
|
rc_t create( handle_t& hRef, const object_t* cfg );
|
||||||
|
|
||||||
|
// Read a CSV as written by cwIoMidiRecordPlay.save_csv().
|
||||||
|
// In this case event.loc == event.muid.
|
||||||
|
rc_t create_from_midi_csv( handle_t& hRef, const char* fn );
|
||||||
rc_t destroy( handle_t& hRef );
|
rc_t destroy( handle_t& hRef );
|
||||||
|
|
||||||
|
|
||||||
|
bool has_loc_info_flag( handle_t h );
|
||||||
|
|
||||||
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 );
|
||||||
|
|
||||||
const event_t* loc_to_event( handle_t h, unsigned loc );
|
const event_t* loc_to_event( handle_t h, unsigned loc );
|
||||||
|
|
||||||
|
/*
|
||||||
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_measure( handle_t h, unsigned locId );
|
||||||
unsigned loc_to_next_note_on_measure( handle_t h, unsigned locId );
|
unsigned loc_to_next_note_on_measure( handle_t h, unsigned locId );
|
||||||
double locs_to_diff_seconds( handle_t h, unsigned loc0Id, unsigned loc1Id );
|
double locs_to_diff_seconds( handle_t h, unsigned loc0Id, unsigned loc1Id );
|
||||||
|
*/
|
||||||
|
|
||||||
const event_t* uid_to_event( handle_t h, unsigned uid );
|
const event_t* uid_to_event( handle_t h, unsigned uid );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user