瀏覽代碼

cmMidi.h/c : Added pedal related functions and control codes.

master
Kevin Larke 9 年之前
父節點
當前提交
bd5daa08bd
共有 2 個檔案被更改,包括 32 行新增6 行删除
  1. 21
    5
      cmMidi.c
  2. 11
    1
      cmMidi.h

+ 21
- 5
cmMidi.c 查看文件

@@ -4,16 +4,12 @@
4 4
 #include "cmMidi.h"
5 5
 
6 6
 
7
-enum
8
-{
9
-  mdStatusDescLabelCharCnt = 5
10
-};
11 7
 
12 8
 typedef struct
13 9
 {
14 10
   cmMidiByte_t   status;
15 11
   cmMidiByte_t  byteCnt;
16
-  char     label[ mdStatusDescLabelCharCnt+1 ];
12
+  const char*     label;
17 13
 } cmMidiStatusDesc;
18 14
 
19 15
 cmMidiStatusDesc _cmMidiStatusDescArray[] =
@@ -72,6 +68,16 @@ cmMidiStatusDesc _cmMidiMetaStatusDescArray[] =
72 68
   { kInvalidMetaMdId, kInvalidMidiByte, "ERROR"}
73 69
 };
74 70
 
71
+cmMidiStatusDesc _cmMidiPedalLabel[] = 
72
+{
73
+  { kSustainCtlMdId,    0, "sustn" },
74
+  { kPortamentoCtlMdId, 0, "porta" },
75
+  { kSostenutoCtlMdId,  0, "sostn" },
76
+  { kSoftPedalCtlMdId,  0, "soft"  },
77
+  { kLegatoCtlMdId,     0, "legat" },
78
+  { kInvalidMidiByte, kInvalidMidiByte, "ERROR"}
79
+};
80
+
75 81
 //====================================================================================================
76 82
 
77 83
 const char* cmMidiStatusToLabel( cmMidiByte_t status )
@@ -102,6 +108,16 @@ const char*   cmMidiMetaStatusToLabel( cmMidiByte_t metaStatus )
102 108
   return _cmMidiMetaStatusDescArray[i].label; 
103 109
 }
104 110
 
111
+const char* cmMidiPedalLabel( cmMidiByte_t d0 )
112
+{
113
+  int i;
114
+  for(i=0; _cmMidiPedalLabel[i].status != kInvalidMidiByte; ++i)
115
+    if( _cmMidiPedalLabel[i].status == d0 )
116
+      break;
117
+
118
+  return _cmMidiPedalLabel[i].label;
119
+}
120
+
105 121
 cmMidiByte_t cmMidiStatusToByteCount( cmMidiByte_t status )
106 122
 {
107 123
   unsigned i;

+ 11
- 1
cmMidi.h 查看文件

@@ -68,7 +68,11 @@ extern "C" {
68 68
     kSeqSpecMdId     = 0x7f,
69 69
     kInvalidMetaMdId = 0x80,
70 70
 
71
-    kSustainCtlMdId = 64
71
+    kSustainCtlMdId    = 0x40,
72
+    kPortamentoCtlMdId = 0x41,
73
+    kSostenutoCtlMdId  = 0x42,
74
+    kSoftPedalCtlMdId  = 0x43,
75
+    kLegatoCtlMdId     = 0x44
72 76
   
73 77
   };
74 78
 
@@ -89,8 +93,14 @@ extern "C" {
89 93
 #define cmMidiIsSustainPedalDown( s, d0, d1) ( cmMidiIsSustainPedal(s,d0) && (d1)>=64 )
90 94
 #define cmMidiIsSustainPedalUp(   s, d0, d1) ( cmMidiIsSustainPedal(s,d0) && (d1)<64 )
91 95
 
96
+#define cmMidiIsPedal(     s, d0 )      ( kCtlMdId <= (s) && (s) <= (kCtlMdId + kMidiChCnt) && (d0)>=kSustainCtlMdId && (d0)<=kLegatoCtlMdId )
97
+#define cmMidiIsPedalDown( s, d0, d1 )  ( cmMidiIsPedal(s,d0) && (d1)>=64 )
98
+#define cmMidiIsPedalUp(   s, d0, d1 )  ( cmMidiIsPedal(s,d0) && (d1)<64  )
99
+
100
+
92 101
   const char*   cmMidiStatusToLabel(     cmMidiByte_t status );
93 102
   const char*   cmMidiMetaStatusToLabel( cmMidiByte_t metaStatus );
103
+  const char*   cmMidiPedalLabel(        cmMidiByte_t d0 );
94 104
 
95 105
   // Returns kInvalidMidiByte if status is not a valid status byte
96 106
   cmMidiByte_t  cmMidiStatusToByteCount( cmMidiByte_t status );

Loading…
取消
儲存