2012-10-30 03:52:39 +00:00
|
|
|
#ifndef cmScore_h
|
|
|
|
#define cmScore_h
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-11-16 19:59:27 +00:00
|
|
|
//( { file_desc:"Object for managing musical score data." kw:[score]}
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
kOkScRC = cmOkRC,
|
|
|
|
kCsvFailScRC,
|
|
|
|
kSyntaxErrScRC,
|
|
|
|
kInvalidIdxScRC,
|
2012-12-13 23:38:45 +00:00
|
|
|
kTimeLineFailScRC,
|
2013-11-05 20:52:07 +00:00
|
|
|
kInvalidDynRefCntScRC,
|
2015-02-24 23:42:24 +00:00
|
|
|
kMidiFileFailScRC,
|
2016-03-17 23:28:35 +00:00
|
|
|
kPedalInvalidScRC,
|
|
|
|
kFileFailScRC
|
2012-10-30 03:52:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kInvalidEvtScId = 0,
|
|
|
|
kTimeSigEvtScId,
|
|
|
|
kKeySigEvtScId,
|
|
|
|
kTempoEvtScId,
|
|
|
|
kTrackEvtScId,
|
|
|
|
kTextEvtScId,
|
2013-12-10 21:25:16 +00:00
|
|
|
kNameEvtScId,
|
2012-10-30 03:52:39 +00:00
|
|
|
kEOTrackEvtScId,
|
|
|
|
kCopyEvtScId,
|
|
|
|
kBlankEvtScId,
|
|
|
|
kBarEvtScId,
|
|
|
|
kPgmEvtScId,
|
|
|
|
kCtlEvtScId,
|
2015-02-24 23:42:24 +00:00
|
|
|
kNonEvtScId,
|
|
|
|
kPedalEvtScId
|
2012-10-30 03:52:39 +00:00
|
|
|
};
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
// Flags used by cmScoreEvt_t.flags
|
2012-10-30 03:52:39 +00:00
|
|
|
enum
|
|
|
|
{
|
2013-11-19 06:31:19 +00:00
|
|
|
kEvenScFl = 0x001, // This note is marked for evenness measurement
|
|
|
|
kDynScFl = 0x002, // This note is marked for dynamics measurement
|
|
|
|
kTempoScFl = 0x004, // This note is marked for tempo measurement
|
|
|
|
kSkipScFl = 0x008, // This isn't a real event (e.g. tied note) skip over it
|
|
|
|
kGraceScFl = 0x010, // This is a grace note
|
2015-02-24 23:42:24 +00:00
|
|
|
kInvalidScFl = 0x020, // This note has a calculated time
|
2015-02-25 23:14:37 +00:00
|
|
|
kPedalDnScFl = 0x040, // This is a pedal down event (pitch holds the pedal id and durSecs holds the time the pedal will remain down.)
|
|
|
|
kPedalUpScFl = 0x080 // This is a pedal up event (pitch holds the pedal id)
|
2012-10-30 03:52:39 +00:00
|
|
|
};
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
|
|
|
|
// Id's used by cmScoreSet_t.varId and as indexes into
|
|
|
|
// cmScoreSection_t.vars[].
|
|
|
|
enum
|
|
|
|
{
|
2013-12-11 17:42:26 +00:00
|
|
|
kInvalidVarScId,
|
2012-12-13 23:38:45 +00:00
|
|
|
kEvenVarScId,
|
|
|
|
kDynVarScId,
|
|
|
|
kTempoVarScId,
|
|
|
|
kScVarCnt
|
|
|
|
};
|
|
|
|
|
2012-12-04 01:17:55 +00:00
|
|
|
struct cmScoreLoc_str;
|
2012-12-13 23:38:45 +00:00
|
|
|
struct cmScoreSet_str;
|
2012-12-04 01:17:55 +00:00
|
|
|
|
|
|
|
// The score can be divided into arbitrary non-overlapping sections.
|
|
|
|
typedef struct
|
|
|
|
{
|
2013-01-18 17:29:48 +00:00
|
|
|
const cmChar_t* label; // section label
|
|
|
|
unsigned index; // index of this record in the internal section array
|
|
|
|
struct cmScoreLoc_str* locPtr; // location where this section starts
|
|
|
|
unsigned begEvtIndex; // score element index where this section starts
|
|
|
|
unsigned setCnt; // Count of elements in setArray[]
|
|
|
|
struct cmScoreSet_str** setArray; // Ptrs to sets which are applied to this section.
|
2012-12-13 23:38:45 +00:00
|
|
|
double vars[ kScVarCnt ]; // Set to DBL_MAX by default.
|
2012-12-04 01:17:55 +00:00
|
|
|
} cmScoreSection_t;
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned type; // Event type
|
2012-11-15 04:11:07 +00:00
|
|
|
double secs; // Time location in seconds
|
|
|
|
double durSecs; // Duration in seconds
|
2012-12-04 01:17:55 +00:00
|
|
|
unsigned index; // Index of this event in the event array.
|
2012-12-13 23:38:45 +00:00
|
|
|
unsigned locIdx; // Index of the location containing this event
|
2015-02-24 23:42:24 +00:00
|
|
|
cmMidiByte_t pitch; // MIDI pitch of this note or the MIDI pedal id of pedal down/up msg (64=sustain 65=sostenuto 66=soft)
|
2016-06-16 16:51:55 +00:00
|
|
|
cmMidiByte_t vel; // MIDI velocity of this note
|
2012-10-30 03:52:39 +00:00
|
|
|
unsigned flags; // Attribute flags for this event
|
|
|
|
unsigned dynVal; // Dynamcis value pppp to ffff (1 to 11) for this note.
|
2013-01-14 00:46:39 +00:00
|
|
|
double frac; // Note's time value for tempo and non-grace evenness notes.
|
2012-12-04 01:17:55 +00:00
|
|
|
unsigned barNumb; // Bar id of the measure containing this event.
|
|
|
|
unsigned barNoteIdx; // Index of this note in this bar
|
|
|
|
unsigned csvRowNumb; // File row number (not index) from which this record originated
|
|
|
|
unsigned perfSmpIdx; // Time this event was performed or cmInvalidIdx if the event was not performed.
|
|
|
|
unsigned perfVel; // Velocity of the performed note or 0 if the note was not performed.
|
2012-12-13 23:38:45 +00:00
|
|
|
unsigned perfDynLvl; // Index into dynamic level ref. array assoc'd with perfVel
|
2013-07-09 21:04:40 +00:00
|
|
|
unsigned line; // Line number of this event in the score file.
|
2016-03-02 23:51:51 +00:00
|
|
|
unsigned csvEventId; // EventId from CSV 'evt' column.
|
2012-10-30 03:52:39 +00:00
|
|
|
} cmScoreEvt_t;
|
|
|
|
|
2015-02-08 16:55:40 +00:00
|
|
|
// A 'set' is a collection of events that are grouped in time and all marked with a given attribute.
|
|
|
|
// (e.g. eveness, tempo, dynamcs ... )
|
2012-12-04 01:17:55 +00:00
|
|
|
typedef struct cmScoreSet_str
|
2012-11-15 04:11:07 +00:00
|
|
|
{
|
2012-12-13 23:38:45 +00:00
|
|
|
unsigned varId; // See kXXXVarScId flags above
|
|
|
|
cmScoreEvt_t** eleArray; // Events that make up this set in time order
|
|
|
|
unsigned eleCnt; //
|
2013-03-02 01:29:01 +00:00
|
|
|
cmScoreSection_t** sectArray; // Sections this set will be applied to
|
|
|
|
unsigned sectCnt; //
|
|
|
|
unsigned* symArray; // symArray[sectCnt] - symbol name of all variables represented by this set (e.g '1a-e', '1b-e', '2-t', etc)
|
|
|
|
unsigned* costSymArray; // costSymArray[sectCnt] - same as symbols in symArray[] with 'c' prepended to front
|
2012-12-13 23:38:45 +00:00
|
|
|
bool doneFl;
|
|
|
|
double value;
|
|
|
|
struct cmScoreSet_str* llink; // cmScoreLoc_t setList link
|
2012-12-04 01:17:55 +00:00
|
|
|
} cmScoreSet_t;
|
2013-11-19 06:31:19 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
kInvalidScMId,
|
|
|
|
kRecdBegScMId,
|
|
|
|
kRecdEndScMId,
|
|
|
|
kFadeScMId,
|
|
|
|
kPlayBegScMId,
|
|
|
|
kPlayEndScMId
|
|
|
|
} cmMarkScMId_t;
|
|
|
|
|
|
|
|
// score markers
|
|
|
|
typedef struct cmScoreMarker_str
|
|
|
|
{
|
|
|
|
cmMarkScMId_t markTypeId; // marker type
|
|
|
|
unsigned labelSymId; // marker label
|
|
|
|
struct cmScoreLoc_str* scoreLocPtr; // score location of the marker
|
|
|
|
unsigned csvRowIdx; // score CSV file line assoc'd w/ this marker
|
|
|
|
struct cmScoreMarker_str* link; // cmScoreLoc_t.markList links
|
|
|
|
} cmScoreMarker_t;
|
2012-12-04 01:17:55 +00:00
|
|
|
|
|
|
|
// All events which are simultaneous are collected into a single
|
|
|
|
// cmScoreLoc_t record.
|
|
|
|
typedef struct cmScoreLoc_str
|
2012-12-13 23:38:45 +00:00
|
|
|
{
|
|
|
|
unsigned index; // index of this location record
|
2012-12-04 01:17:55 +00:00
|
|
|
double secs; // Time of this location
|
|
|
|
unsigned evtCnt; // Count of events in evtArray[].
|
|
|
|
cmScoreEvt_t** evtArray; // Events which occur at this time.
|
|
|
|
unsigned barNumb; // Bar number this event is contained by.
|
2012-12-13 23:38:45 +00:00
|
|
|
cmScoreSet_t* setList; // Set's which end on this time location (linked through cmScoreSet_t.llink)
|
2012-12-04 01:17:55 +00:00
|
|
|
cmScoreSection_t* begSectPtr; // NULL if this location does not start a section
|
2013-11-19 06:31:19 +00:00
|
|
|
cmScoreMarker_t* markList; // List of markers assigned to this location
|
2012-11-15 04:11:07 +00:00
|
|
|
} cmScoreLoc_t;
|
|
|
|
|
2012-11-03 02:06:34 +00:00
|
|
|
typedef void (*cmScCb_t)( void* arg, const void* data, unsigned byteCnt );
|
2012-10-30 03:52:39 +00:00
|
|
|
|
|
|
|
typedef cmRC_t cmScRC_t;
|
|
|
|
typedef cmHandle_t cmScH_t;
|
|
|
|
|
|
|
|
extern cmScH_t cmScNullHandle;
|
|
|
|
|
2012-11-03 02:06:34 +00:00
|
|
|
const cmChar_t* cmScEvtTypeIdToLabel( unsigned id );
|
|
|
|
const cmChar_t* cmScDynIdToLabel( unsigned id );
|
2015-11-18 20:49:40 +00:00
|
|
|
const cmChar_t* cmScStatusToOpString( unsigned id );
|
2012-11-03 02:06:34 +00:00
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
// Initialize a score object from a CSV File generated from a score spreadsheet.
|
2012-12-13 23:38:45 +00:00
|
|
|
// The dynRefArray[dynRefCnt] and cbFunc(cbArg) are optional if these
|
|
|
|
// features are not used.
|
|
|
|
// If provided the dynRefArray[] is copied into an internal array.
|
|
|
|
// The physical array passed here therefore does not need to remain valid.
|
2013-01-14 00:46:39 +00:00
|
|
|
// Set 'srate' to zero if the score will not be used to perform measurement calculations.
|
2013-03-02 01:29:01 +00:00
|
|
|
// The symbol table is only necessary if valid symbols are to be assigned to the cmScoreSet_t.symArray[].
|
|
|
|
cmScRC_t cmScoreInitialize( cmCtx_t* ctx, cmScH_t* hp, const cmChar_t* fn, double srate, const unsigned* dynRefArray, unsigned dynRefCnt, cmScCb_t cbFunc, void* cbArg, cmSymTblH_t stH );
|
2012-11-03 02:06:34 +00:00
|
|
|
cmScRC_t cmScoreFinalize( cmScH_t* hp );
|
|
|
|
|
|
|
|
// Filename of last successfuly loaded score file.
|
|
|
|
const cmChar_t* cmScoreFileName( cmScH_t h );
|
2013-01-30 19:55:52 +00:00
|
|
|
|
|
|
|
// Sample rate as set in cmScoreInitialize()
|
|
|
|
double cmScoreSampleRate( cmScH_t h );
|
2012-10-30 03:52:39 +00:00
|
|
|
|
2012-12-04 01:17:55 +00:00
|
|
|
// Validate the score handle
|
2012-10-30 03:52:39 +00:00
|
|
|
bool cmScoreIsValid( cmScH_t h );
|
|
|
|
|
|
|
|
// Access the score data.
|
|
|
|
unsigned cmScoreEvtCount( cmScH_t h );
|
|
|
|
cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx );
|
|
|
|
|
2013-07-08 19:28:49 +00:00
|
|
|
// Given a bar number return the associated 'bar' event record.
|
2016-06-16 16:51:55 +00:00
|
|
|
const cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb );
|
|
|
|
|
|
|
|
// Given a csvEventId return the associated event
|
|
|
|
const cmScoreEvt_t* cmScoreIdToEvt( cmScH_t h, unsigned csvEventId );
|
2013-07-08 19:28:49 +00:00
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
// Access section records
|
|
|
|
unsigned cmScoreSectionCount( cmScH_t h );
|
|
|
|
cmScoreSection_t* cmScoreSection( cmScH_t h, unsigned idx );
|
|
|
|
|
2012-11-15 04:11:07 +00:00
|
|
|
// Access the score location data
|
|
|
|
unsigned cmScoreLocCount( cmScH_t h );
|
|
|
|
cmScoreLoc_t* cmScoreLoc( cmScH_t h, unsigned idx );
|
2012-12-04 01:17:55 +00:00
|
|
|
void cmScorePrintLoc( cmScH_t h );
|
2012-11-15 04:11:07 +00:00
|
|
|
|
2013-07-08 19:28:49 +00:00
|
|
|
// Return the location associated with a given score event.
|
|
|
|
cmScoreLoc_t* cmScoreEvtLoc( cmScH_t h, const cmScoreEvt_t* evt );
|
|
|
|
|
2013-01-18 17:29:48 +00:00
|
|
|
// Return the count of sets.
|
|
|
|
unsigned cmScoreSetCount( cmScH_t h );
|
|
|
|
|
2013-11-19 06:31:19 +00:00
|
|
|
unsigned cmScoreMarkerLabelCount( cmScH_t h );
|
|
|
|
unsigned cmScoreMarkerLabelSymbolId( cmScH_t h, unsigned idx );
|
|
|
|
const cmScoreMarker_t* cmScoreMarker( cmScH_t h, cmMarkScMId_t markMId, unsigned labelSymId );
|
|
|
|
|
2012-12-04 01:17:55 +00:00
|
|
|
// Make callbacks for all events in the score. The callbacks
|
|
|
|
// contain cmScMsg_t records serialized as a byte stream.
|
|
|
|
// Use cmScoreDecode() to convert the byte string to a
|
|
|
|
// cmScMsg_t record.
|
2012-11-03 02:06:34 +00:00
|
|
|
cmScRC_t cmScoreSeqNotify( cmScH_t h );
|
2015-03-30 20:05:31 +00:00
|
|
|
cmScRC_t cmScoreSeqNotifyCb( cmScH_t h, cmScCb_t cbFunc, void* cbArg );
|
2012-12-04 01:17:55 +00:00
|
|
|
|
|
|
|
void cmScoreClearPerfInfo( cmScH_t h );
|
2012-12-13 23:38:45 +00:00
|
|
|
|
|
|
|
// Assign 'smpIdx' and 'vel' to the event matching 'pitch' at 'locIdx'
|
|
|
|
// but do not trigger any variable calculations. Return true if as a
|
|
|
|
// result of this call all events assigned to 'locIdx' have been received
|
|
|
|
// otherwise return false.
|
|
|
|
bool cmScoreSetPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
|
|
|
|
|
|
|
|
// Assign 'smpIdx' and 'vel' to the event matching 'pitch' at 'locIdx'
|
|
|
|
// but and trigger any variable calculations which may happen on, or before, 'locIdx'.
|
|
|
|
void cmScoreExecPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
|
|
|
|
|
|
|
|
// Assign 'value' to the section at, or before, 'locIdx'.
|
|
|
|
void cmScoreSetPerfValue( cmScH_t h, unsigned locIdx, unsigned varId, double value );
|
2012-11-03 02:06:34 +00:00
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
// Set the performed dynamic level of a score event.
|
|
|
|
void cmScoreSetPerfDynLevel( cmScH_t h, unsigned evtIdx, unsigned dynLvl );
|
2013-07-08 19:28:49 +00:00
|
|
|
|
2012-11-03 02:06:34 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
kInvalidMsgScId,
|
|
|
|
kBeginMsgScId,
|
|
|
|
kEventMsgScId,
|
2012-12-13 23:38:45 +00:00
|
|
|
kSectionMsgScId,
|
|
|
|
kEndMsgScId,
|
|
|
|
kVarMsgScId,
|
|
|
|
kDynMsgScId
|
2012-11-03 02:06:34 +00:00
|
|
|
} cmScMsgTypeId_t;
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned varId; // see kXXXVarScId from cmScoreSet_t.varId
|
|
|
|
double value; // value of a variable
|
|
|
|
} cmScMeas_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned evtIdx;
|
|
|
|
unsigned dynLvl;
|
|
|
|
} cmScDyn_t;
|
|
|
|
|
2012-11-03 02:06:34 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmScMsgTypeId_t typeId;
|
2012-12-13 23:38:45 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
cmScoreEvt_t evt; // only used when typeId == kEventMsgScId
|
|
|
|
cmScMeas_t meas; // only used when typeId == kVarMsgScId
|
|
|
|
cmScoreSection_t sect; // only used when typeId == kSectionMsgScId
|
|
|
|
cmScDyn_t dyn; // only used when typeId == kDynLvlMsgScId
|
|
|
|
} u;
|
2012-11-03 02:06:34 +00:00
|
|
|
} cmScMsg_t;
|
|
|
|
|
2012-12-04 01:17:55 +00:00
|
|
|
// Decode a serialized cmScMsg_t from a byte stream as passed to the
|
|
|
|
// cmScCb_t function.
|
2012-11-03 02:06:34 +00:00
|
|
|
cmScRC_t cmScoreDecode( const void* msg, unsigned msgByteCnt, cmScMsg_t* );
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
void cmScorePrint( cmScH_t h, cmRpt_t* rpt );
|
2016-04-23 19:41:19 +00:00
|
|
|
void cmScorePrintSets( cmScH_t h, cmRpt_t* rpt );
|
2012-10-30 03:52:39 +00:00
|
|
|
|
2013-11-05 20:52:07 +00:00
|
|
|
// Generate a new score file from a MIDI file.
|
|
|
|
cmScRC_t cmScoreFileFromMidi( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* scoreFn );
|
|
|
|
|
2016-09-14 17:47:19 +00:00
|
|
|
// Print open the score file 'fn' and report the contents. This function
|
|
|
|
// simply wraps calls to cmScoreInitialize() and cmScorePrint().
|
|
|
|
void cmScoreReport( cmCtx_t* ctx, const cmChar_t* fn );
|
2012-10-30 03:52:39 +00:00
|
|
|
|
2016-09-14 17:47:19 +00:00
|
|
|
void cmScoreTest( cmCtx_t* ctx, const cmChar_t* fn );
|
|
|
|
|
2015-11-16 19:59:27 +00:00
|
|
|
//)
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|