cmMidi.h/c: Added conversion to/from 14bit values and Pitch Bend.
This commit is contained in:
parent
a39e5f620c
commit
7859bd0a8c
25
cmMidi.c
25
cmMidi.c
@ -121,6 +121,31 @@ cmMidiByte_t cmMidiStatusToByteCount( cmMidiByte_t status )
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned cmMidiTo14Bits( cmMidiByte_t d0, cmMidiByte_t d1 )
|
||||
{
|
||||
unsigned val = d0;
|
||||
val <<= 7;
|
||||
val += d1;
|
||||
return val;
|
||||
}
|
||||
|
||||
void cmMidiSplit14Bits( unsigned v, cmMidiByte_t* d0Ref, cmMidiByte_t* d1Ref )
|
||||
{
|
||||
*d0Ref = (v & 0x3f80) >> 7;
|
||||
*d1Ref = v & 0x7f;
|
||||
}
|
||||
|
||||
int cmMidiToPbend( cmMidiByte_t d0, cmMidiByte_t d1 )
|
||||
{
|
||||
int v = cmMidiTo14Bits(d0,d1);
|
||||
return v - 8192;
|
||||
}
|
||||
|
||||
void cmMidiSplitPbend( int v, cmMidiByte_t* d0Ref, cmMidiByte_t* d1Ref )
|
||||
{
|
||||
unsigned uv = v + 8192;
|
||||
cmMidiSplit14Bits(uv,d0Ref,d1Ref);
|
||||
}
|
||||
|
||||
//====================================================================================================
|
||||
const char* cmMidiToSciPitch( cmMidiByte_t pitch, char* label, unsigned labelCharCnt )
|
||||
|
82
cmMidi.h
82
cmMidi.h
@ -5,8 +5,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
enum
|
||||
{
|
||||
kMidiChCnt = 16,
|
||||
kInvalidMidiByte = 128,
|
||||
kMidiNoteCnt = kInvalidMidiByte,
|
||||
@ -17,12 +17,12 @@ enum
|
||||
kInvalidMidiCtl = kInvalidMidiByte,
|
||||
kInvalidMidiPgm = kInvalidMidiByte,
|
||||
kMidiSciPitchCharCnt = 5 // A#-1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// MIDI status bytes
|
||||
enum
|
||||
{
|
||||
// MIDI status bytes
|
||||
enum
|
||||
{
|
||||
kInvalidStatusMdId = 0x00,
|
||||
kNoteOffMdId = 0x80,
|
||||
kNoteOnMdId = 0x90,
|
||||
@ -70,68 +70,72 @@ enum
|
||||
|
||||
kSustainCtlMdId = 64
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
typedef unsigned char cmMidiByte_t;
|
||||
typedef unsigned char cmMidiByte_t;
|
||||
|
||||
//===============================================================================================
|
||||
// Utility Functions
|
||||
//
|
||||
//===============================================================================================
|
||||
// Utility Functions
|
||||
//
|
||||
|
||||
#define cmMidiIsStatus( s ) (kNoteOffMdId <= (s) /*&& ((unsigned)(s)) <= kSysRtResetMdId*/ )
|
||||
#define cmMidiIsChStatus( s ) (kNoteOffMdId <= (s) && (s) < kSysExMdId)
|
||||
|
||||
|
||||
const char* cmMidiStatusToLabel( cmMidiByte_t status );
|
||||
const char* cmMidiMetaStatusToLabel( cmMidiByte_t metaStatus );
|
||||
const char* cmMidiStatusToLabel( cmMidiByte_t status );
|
||||
const char* cmMidiMetaStatusToLabel( cmMidiByte_t metaStatus );
|
||||
|
||||
// Returns kInvalidMidiByte if status is not a valid status byte
|
||||
cmMidiByte_t cmMidiStatusToByteCount( cmMidiByte_t status );
|
||||
// Returns kInvalidMidiByte if status is not a valid status byte
|
||||
cmMidiByte_t cmMidiStatusToByteCount( cmMidiByte_t status );
|
||||
|
||||
unsigned cmMidiTo14Bits( cmMidiByte_t d0, cmMidiByte_t d1 );
|
||||
void cmMidiSplit14Bits( unsigned v, cmMidiByte_t* d0Ref, cmMidiByte_t* d1Ref );
|
||||
int cmMidiToPbend( cmMidiByte_t d0, cmMidiByte_t d1 );
|
||||
void cmMidiSplitPbend( int v, cmMidiByte_t* d0Ref, cmMidiByte_t* d1Ref );
|
||||
|
||||
//===============================================================================================
|
||||
// MIDI Communication data types
|
||||
//
|
||||
//===============================================================================================
|
||||
// MIDI Communication data types
|
||||
//
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
unsigned deltaUs; // time since last MIDI msg in microseconds
|
||||
cmMidiByte_t status; // midi status byte
|
||||
cmMidiByte_t d0; // midi data byte 0
|
||||
cmMidiByte_t d1; // midi data byte 1
|
||||
cmMidiByte_t pad;
|
||||
} cmMidiMsg;
|
||||
} cmMidiMsg;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
void* cbDataPtr; // application supplied reference value from mdParserCreate()
|
||||
unsigned devIdx; // the device the msg originated from
|
||||
unsigned portIdx; // the port index on the source device
|
||||
cmMidiMsg* msgArray; // pointer to an array of 'msgCnt' mdMsg records or NULL if sysExMsg is non-NULL
|
||||
cmMidiByte_t* sysExMsg; // pointer to a sys-ex msg or NULL if msgArray is non-NULL (see note below)
|
||||
unsigned msgCnt; // count of mdMsg records or sys-ex bytes
|
||||
} cmMidiPacket_t;
|
||||
} cmMidiPacket_t;
|
||||
|
||||
// Notes: If the sys-ex message can be contained in a single msg then
|
||||
// then the first msg byte is kSysExMdId and the last is kSysComEoxMdId.
|
||||
// If the sys-ex message is broken into multiple pieces then only the
|
||||
// first will begin with kSysExMdId and the last will end with kSysComEoxMdId.
|
||||
// Notes: If the sys-ex message can be contained in a single msg then
|
||||
// then the first msg byte is kSysExMdId and the last is kSysComEoxMdId.
|
||||
// If the sys-ex message is broken into multiple pieces then only the
|
||||
// first will begin with kSysExMdId and the last will end with kSysComEoxMdId.
|
||||
|
||||
|
||||
// If label is NULL or labelCharCnt==0 then a pointer to an internal static
|
||||
// buffer is returned. If label[] is given the it
|
||||
// should have at least 5 (kMidiPitchCharCnt) char's (including the terminating zero).
|
||||
// If 'pitch' is outside of the range 0-127 then a blank string is returned.
|
||||
const char* cmMidiToSciPitch( cmMidiByte_t pitch, char* label, unsigned labelCharCnt );
|
||||
// If label is NULL or labelCharCnt==0 then a pointer to an internal static
|
||||
// buffer is returned. If label[] is given the it
|
||||
// should have at least 5 (kMidiPitchCharCnt) char's (including the terminating zero).
|
||||
// If 'pitch' is outside of the range 0-127 then a blank string is returned.
|
||||
const char* cmMidiToSciPitch( cmMidiByte_t pitch, char* label, unsigned labelCharCnt );
|
||||
|
||||
|
||||
// Scientific pitch string: [A-Ga-g][#b][#] where # may be -1 to 9.
|
||||
// Return kInvalidMidiPitch if sciPtichStr does not contain a valid
|
||||
// scientific pitch string. This function will convert C-1 to G9 to
|
||||
// valid MIDI pitch values 0 to 127. Scientific pitch strings outside
|
||||
// of this range will be returned as kInvalidMidiPitch.
|
||||
cmMidiByte_t cmSciPitchToMidi( const char* sciPitchStr );
|
||||
// Scientific pitch string: [A-Ga-g][#b][#] where # may be -1 to 9.
|
||||
// Return kInvalidMidiPitch if sciPtichStr does not contain a valid
|
||||
// scientific pitch string. This function will convert C-1 to G9 to
|
||||
// valid MIDI pitch values 0 to 127. Scientific pitch strings outside
|
||||
// of this range will be returned as kInvalidMidiPitch.
|
||||
cmMidiByte_t cmSciPitchToMidi( const char* sciPitchStr );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user