cmMidi.h/c: Added conversion to/from 14bit values and Pitch Bend.

This commit is contained in:
kevin 2013-04-08 23:05:05 -07:00
parent a39e5f620c
commit 7859bd0a8c
2 changed files with 136 additions and 107 deletions

View File

@ -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 )

View File

@ -89,6 +89,10 @@ const char* cmMidiMetaStatusToLabel( cmMidiByte_t metaStatus );
// 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