From bd5daa08bda7f105317f5361267cd2fe3a263ea8 Mon Sep 17 00:00:00 2001 From: Kevin Larke Date: Mon, 30 Mar 2015 13:06:48 -0700 Subject: [PATCH] cmMidi.h/c : Added pedal related functions and control codes. --- cmMidi.c | 26 +++++++++++++++++++++----- cmMidi.h | 12 +++++++++++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cmMidi.c b/cmMidi.c index b3a7dd8..6a375c2 100644 --- a/cmMidi.c +++ b/cmMidi.c @@ -4,16 +4,12 @@ #include "cmMidi.h" -enum -{ - mdStatusDescLabelCharCnt = 5 -}; typedef struct { cmMidiByte_t status; cmMidiByte_t byteCnt; - char label[ mdStatusDescLabelCharCnt+1 ]; + const char* label; } cmMidiStatusDesc; cmMidiStatusDesc _cmMidiStatusDescArray[] = @@ -72,6 +68,16 @@ cmMidiStatusDesc _cmMidiMetaStatusDescArray[] = { kInvalidMetaMdId, kInvalidMidiByte, "ERROR"} }; +cmMidiStatusDesc _cmMidiPedalLabel[] = +{ + { kSustainCtlMdId, 0, "sustn" }, + { kPortamentoCtlMdId, 0, "porta" }, + { kSostenutoCtlMdId, 0, "sostn" }, + { kSoftPedalCtlMdId, 0, "soft" }, + { kLegatoCtlMdId, 0, "legat" }, + { kInvalidMidiByte, kInvalidMidiByte, "ERROR"} +}; + //==================================================================================================== const char* cmMidiStatusToLabel( cmMidiByte_t status ) @@ -102,6 +108,16 @@ const char* cmMidiMetaStatusToLabel( cmMidiByte_t metaStatus ) return _cmMidiMetaStatusDescArray[i].label; } +const char* cmMidiPedalLabel( cmMidiByte_t d0 ) +{ + int i; + for(i=0; _cmMidiPedalLabel[i].status != kInvalidMidiByte; ++i) + if( _cmMidiPedalLabel[i].status == d0 ) + break; + + return _cmMidiPedalLabel[i].label; +} + cmMidiByte_t cmMidiStatusToByteCount( cmMidiByte_t status ) { unsigned i; diff --git a/cmMidi.h b/cmMidi.h index fa1245e..51373d4 100644 --- a/cmMidi.h +++ b/cmMidi.h @@ -68,7 +68,11 @@ extern "C" { kSeqSpecMdId = 0x7f, kInvalidMetaMdId = 0x80, - kSustainCtlMdId = 64 + kSustainCtlMdId = 0x40, + kPortamentoCtlMdId = 0x41, + kSostenutoCtlMdId = 0x42, + kSoftPedalCtlMdId = 0x43, + kLegatoCtlMdId = 0x44 }; @@ -89,8 +93,14 @@ extern "C" { #define cmMidiIsSustainPedalDown( s, d0, d1) ( cmMidiIsSustainPedal(s,d0) && (d1)>=64 ) #define cmMidiIsSustainPedalUp( s, d0, d1) ( cmMidiIsSustainPedal(s,d0) && (d1)<64 ) +#define cmMidiIsPedal( s, d0 ) ( kCtlMdId <= (s) && (s) <= (kCtlMdId + kMidiChCnt) && (d0)>=kSustainCtlMdId && (d0)<=kLegatoCtlMdId ) +#define cmMidiIsPedalDown( s, d0, d1 ) ( cmMidiIsPedal(s,d0) && (d1)>=64 ) +#define cmMidiIsPedalUp( s, d0, d1 ) ( cmMidiIsPedal(s,d0) && (d1)<64 ) + + const char* cmMidiStatusToLabel( cmMidiByte_t status ); const char* cmMidiMetaStatusToLabel( cmMidiByte_t metaStatus ); + const char* cmMidiPedalLabel( cmMidiByte_t d0 ); // Returns kInvalidMidiByte if status is not a valid status byte cmMidiByte_t cmMidiStatusToByteCount( cmMidiByte_t status );