※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

トップページ


MIDIメッセージ処理(改良版)

MIDIメッセージにあわせて動作するVSTのサンプルの改良版である。
下記VSTはSynthとしてロードされ、常にノイズを発生させる。実行時は音量に注意してほしい。
ノイズのボリュームをMIDI CC7でコントロールできる。

サンプルコード全体


【CMidiMsg.h】
  1. #pragma once
  2. #include <string.h>
  3. #include "audioeffectx.h"
  4.  
  5. // ============================================================================================
  6. // MIDI処理用の定義
  7. // ============================================================================================
  8. #define MIDIMSG_MAXNUM 255
  9.  
  10. struct MidiMessage
  11. {
  12. VstInt32 deltaFrames; //MIDIメッセージを処理するタイミング
  13. unsigned char message; //MIDIメッセージ番号
  14. unsigned char channel; //MIDIチャンネル
  15. unsigned char data1; //MIDIデータ1
  16. unsigned char data2; //MIDIデータ2
  17. };
  18.  
  19. class CMidiMsg
  20. {
  21. protected:
  22. int cur; //読み込み中のMIDIの位置
  23. int num; //受け取ったMIDIメッセージの数
  24. MidiMessage buf[MIDIMSG_MAXNUM]; //受け取ったMIDIメッセージを保管するバッファ
  25. public:
  26. CMidiMsg(void);
  27. ~CMidiMsg(void);
  28.  
  29. // バッファのクリア等を行う。
  30. virtual void clearMidiMsg();
  31.  
  32. // MIDIメッセージをバッファに追加する
  33. // バッファへの追加が成功すると1、失敗すると0を返す
  34. virtual int addMidiMsg(VstMidiEvent *midievent);
  35. virtual int addMidiMsg(MidiMessage msg);
  36.  
  37. // バッファからMIDIメッセージを取り出す
  38. virtual MidiMessage getMidiMsg();
  39.  
  40. // バッファ中にあるMIDIメッセージの数を返す
  41. virtual VstInt32 getMidiMessageNum();
  42.  
  43. // バッファから最初に取り出せるMIDIメッセージのDeltaFramesを返す
  44. virtual VstInt32 getNextDeltaFrames();
  45.  
  46. // MIDIメッセージが何かを判断し、そのメッセージに対応した
  47. // onMidiKeyOn()関数、onMidiControlChange()関数等を呼び出す。
  48. virtual void midiProc(MidiMessage mididata);
  49.  
  50. // midiProc()関数から呼び出される。
  51. // それぞれのMIDIメッセージに応じて処理を行う
  52. // 以下6つはオーバーライドして使うとよい
  53. virtual void onMidiKeyOn (unsigned char channel, unsigned char noteNo, unsigned char velo) {}; // 関数の中身は空
  54. virtual void onMidiKeyOff (unsigned char channel, unsigned char noteNo, unsigned char velo) {}; // 関数の中身は空
  55. virtual void onMidiProgramChange(unsigned char channel, unsigned char program) {}; // 関数の中身は空
  56. virtual void onMidiPoliKeyPress (unsigned char channel, unsigned char noteNo, unsigned char pressure) {}; // 関数の中身は空
  57. virtual void onMidiChannelPress (unsigned char channel, unsigned char pressure) {}; // 関数の中身は空
  58. virtual void onMidiPitchBend (unsigned char channel, short pb) {}; // 関数の中身は空
  59. // 以下2つはあまりオーバーライドして使う必要はない
  60. virtual void onMidiSystemMessage(unsigned char systemmsg, unsigned char data1, unsigned char data2); // 中身はCMidiMsg.cppに記載
  61. virtual void onMidiControlChange(unsigned char channel, unsigned char cc, unsigned char value); // 中身はCMidiMsg.cppに記載
  62.  
  63. // onMidiSystemMessage()関数より呼び出される。
  64. // システムメッセージに応じて処理する関数
  65. // オーバーライドして使うとよい
  66. // (ただし、ホストアプリケーションからSystem Messageが送られることはあまり無い?)
  67. virtual void onMidiQuarterFrame(unsigned char data) {};
  68. virtual void onMidiSongPointer(short songpoint) {};
  69. virtual void onMidiSongSelect(unsigned char data) {};
  70. virtual void onMidiChainRequest() {};
  71. virtual void onMidiTimingClock() {};
  72. virtual void onMidiStart() {};
  73. virtual void onMidiContinue() {};
  74. virtual void onMidiStop(){};
  75. virtual void onMidiActiveSensing() {};
  76. virtual void onMidiSystemReset() {};
  77.  
  78. // onMidiControlChange()関数より呼び出される。
  79. // コントロールチェンジメッセージに応じて処理する関数
  80. // オーバーライドして使うとよい
  81. virtual void onMidiCC000 (unsigned char channel, unsigned char value) {};
  82. virtual void onMidiCC001 (unsigned char channel, unsigned char value) {}; // ModulationDepth
  83. virtual void onMidiCC002 (unsigned char channel, unsigned char value) {};
  84. virtual void onMidiCC003 (unsigned char channel, unsigned char value) {};
  85. virtual void onMidiCC004 (unsigned char channel, unsigned char value) {};
  86. virtual void onMidiCC005 (unsigned char channel, unsigned char value) {}; // PortamentTime
  87. virtual void onMidiCC006 (unsigned char channel, unsigned char value) {};
  88. virtual void onMidiCC007 (unsigned char channel, unsigned char value) {}; // ChannelVolume
  89. virtual void onMidiCC008 (unsigned char channel, unsigned char value) {};
  90. virtual void onMidiCC009 (unsigned char channel, unsigned char value) {};
  91. virtual void onMidiCC010 (unsigned char channel, unsigned char value) {}; // Pan
  92. virtual void onMidiCC011 (unsigned char channel, unsigned char value) {};
  93. virtual void onMidiCC012 (unsigned char channel, unsigned char value) {}; // Expression
  94. virtual void onMidiCC013 (unsigned char channel, unsigned char value) {};
  95. virtual void onMidiCC014 (unsigned char channel, unsigned char value) {};
  96. virtual void onMidiCC015 (unsigned char channel, unsigned char value) {};
  97. virtual void onMidiCC016 (unsigned char channel, unsigned char value) {};
  98. virtual void onMidiCC017 (unsigned char channel, unsigned char value) {};
  99. virtual void onMidiCC018 (unsigned char channel, unsigned char value) {};
  100. virtual void onMidiCC019 (unsigned char channel, unsigned char value) {};
  101. virtual void onMidiCC020 (unsigned char channel, unsigned char value) {};
  102. virtual void onMidiCC021 (unsigned char channel, unsigned char value) {};
  103. virtual void onMidiCC022 (unsigned char channel, unsigned char value) {};
  104. virtual void onMidiCC023 (unsigned char channel, unsigned char value) {};
  105. virtual void onMidiCC024 (unsigned char channel, unsigned char value) {};
  106. virtual void onMidiCC025 (unsigned char channel, unsigned char value) {};
  107. virtual void onMidiCC026 (unsigned char channel, unsigned char value) {};
  108. virtual void onMidiCC027 (unsigned char channel, unsigned char value) {};
  109. virtual void onMidiCC028 (unsigned char channel, unsigned char value) {};
  110. virtual void onMidiCC029 (unsigned char channel, unsigned char value) {};
  111. virtual void onMidiCC030 (unsigned char channel, unsigned char value) {};
  112. virtual void onMidiCC031 (unsigned char channel, unsigned char value) {};
  113. virtual void onMidiCC032 (unsigned char channel, unsigned char value) {};
  114. virtual void onMidiCC033 (unsigned char channel, unsigned char value) {};
  115. virtual void onMidiCC034 (unsigned char channel, unsigned char value) {};
  116. virtual void onMidiCC035 (unsigned char channel, unsigned char value) {};
  117. virtual void onMidiCC036 (unsigned char channel, unsigned char value) {};
  118. virtual void onMidiCC037 (unsigned char channel, unsigned char value) {};
  119. virtual void onMidiCC038 (unsigned char channel, unsigned char value) {};
  120. virtual void onMidiCC039 (unsigned char channel, unsigned char value) {};
  121. virtual void onMidiCC040 (unsigned char channel, unsigned char value) {};
  122. virtual void onMidiCC041 (unsigned char channel, unsigned char value) {};
  123. virtual void onMidiCC042 (unsigned char channel, unsigned char value) {};
  124. virtual void onMidiCC043 (unsigned char channel, unsigned char value) {};
  125. virtual void onMidiCC044 (unsigned char channel, unsigned char value) {};
  126. virtual void onMidiCC045 (unsigned char channel, unsigned char value) {};
  127. virtual void onMidiCC046 (unsigned char channel, unsigned char value) {};
  128. virtual void onMidiCC047 (unsigned char channel, unsigned char value) {};
  129. virtual void onMidiCC048 (unsigned char channel, unsigned char value) {};
  130. virtual void onMidiCC049 (unsigned char channel, unsigned char value) {};
  131. virtual void onMidiCC050 (unsigned char channel, unsigned char value) {};
  132. virtual void onMidiCC051 (unsigned char channel, unsigned char value) {};
  133. virtual void onMidiCC052 (unsigned char channel, unsigned char value) {};
  134. virtual void onMidiCC053 (unsigned char channel, unsigned char value) {};
  135. virtual void onMidiCC054 (unsigned char channel, unsigned char value) {};
  136. virtual void onMidiCC055 (unsigned char channel, unsigned char value) {};
  137. virtual void onMidiCC056 (unsigned char channel, unsigned char value) {};
  138. virtual void onMidiCC057 (unsigned char channel, unsigned char value) {};
  139. virtual void onMidiCC058 (unsigned char channel, unsigned char value) {};
  140. virtual void onMidiCC059 (unsigned char channel, unsigned char value) {};
  141. virtual void onMidiCC060 (unsigned char channel, unsigned char value) {};
  142. virtual void onMidiCC061 (unsigned char channel, unsigned char value) {};
  143. virtual void onMidiCC062 (unsigned char channel, unsigned char value) {};
  144. virtual void onMidiCC063 (unsigned char channel, unsigned char value) {};
  145. virtual void onMidiCC064 (unsigned char channel, unsigned char value) {}; // DumperPedal
  146. virtual void onMidiCC065 (unsigned char channel, unsigned char value) {}; // PortamentOnOff
  147. virtual void onMidiCC066 (unsigned char channel, unsigned char value) {}; // SostenutoPedal
  148. virtual void onMidiCC067 (unsigned char channel, unsigned char value) {}; // SoftPedal
  149. virtual void onMidiCC068 (unsigned char channel, unsigned char value) {};
  150. virtual void onMidiCC069 (unsigned char channel, unsigned char value) {};
  151. virtual void onMidiCC070 (unsigned char channel, unsigned char value) {};
  152. virtual void onMidiCC071 (unsigned char channel, unsigned char value) {}; // Resonance
  153. virtual void onMidiCC072 (unsigned char channel, unsigned char value) {}; // ReleaseTime
  154. virtual void onMidiCC073 (unsigned char channel, unsigned char value) {}; // AttackTime
  155. virtual void onMidiCC074 (unsigned char channel, unsigned char value) {}; // Brightness
  156. virtual void onMidiCC075 (unsigned char channel, unsigned char value) {}; // DecayTime
  157. virtual void onMidiCC076 (unsigned char channel, unsigned char value) {}; // VibratoRate
  158. virtual void onMidiCC077 (unsigned char channel, unsigned char value) {}; // VibratoDepth
  159. virtual void onMidiCC078 (unsigned char channel, unsigned char value) {}; // VibratoDelay
  160. virtual void onMidiCC079 (unsigned char channel, unsigned char value) {};
  161. virtual void onMidiCC080 (unsigned char channel, unsigned char value) {};
  162. virtual void onMidiCC081 (unsigned char channel, unsigned char value) {};
  163. virtual void onMidiCC082 (unsigned char channel, unsigned char value) {};
  164. virtual void onMidiCC083 (unsigned char channel, unsigned char value) {};
  165. virtual void onMidiCC084 (unsigned char channel, unsigned char value) {};
  166. virtual void onMidiCC085 (unsigned char channel, unsigned char value) {};
  167. virtual void onMidiCC086 (unsigned char channel, unsigned char value) {};
  168. virtual void onMidiCC087 (unsigned char channel, unsigned char value) {};
  169. virtual void onMidiCC088 (unsigned char channel, unsigned char value) {};
  170. virtual void onMidiCC089 (unsigned char channel, unsigned char value) {};
  171. virtual void onMidiCC090 (unsigned char channel, unsigned char value) {};
  172. virtual void onMidiCC091 (unsigned char channel, unsigned char value) {}; // ReverbSend
  173. virtual void onMidiCC092 (unsigned char channel, unsigned char value) {}; // ChorusSend
  174. virtual void onMidiCC093 (unsigned char channel, unsigned char value) {};
  175. virtual void onMidiCC094 (unsigned char channel, unsigned char value) {};
  176. virtual void onMidiCC095 (unsigned char channel, unsigned char value) {};
  177. virtual void onMidiCC096 (unsigned char channel, unsigned char value) {};
  178. virtual void onMidiCC097 (unsigned char channel, unsigned char value) {};
  179. virtual void onMidiCC098 (unsigned char channel, unsigned char value) {};
  180. virtual void onMidiCC099 (unsigned char channel, unsigned char value) {};
  181. virtual void onMidiCC100 (unsigned char channel, unsigned char value) {};
  182. virtual void onMidiCC101 (unsigned char channel, unsigned char value) {};
  183. virtual void onMidiCC102 (unsigned char channel, unsigned char value) {};
  184. virtual void onMidiCC103 (unsigned char channel, unsigned char value) {};
  185. virtual void onMidiCC104 (unsigned char channel, unsigned char value) {};
  186. virtual void onMidiCC105 (unsigned char channel, unsigned char value) {};
  187. virtual void onMidiCC106 (unsigned char channel, unsigned char value) {};
  188. virtual void onMidiCC107 (unsigned char channel, unsigned char value) {};
  189. virtual void onMidiCC108 (unsigned char channel, unsigned char value) {};
  190. virtual void onMidiCC109 (unsigned char channel, unsigned char value) {};
  191. virtual void onMidiCC110 (unsigned char channel, unsigned char value) {};
  192. virtual void onMidiCC111 (unsigned char channel, unsigned char value) {};
  193. virtual void onMidiCC112 (unsigned char channel, unsigned char value) {};
  194. virtual void onMidiCC113 (unsigned char channel, unsigned char value) {};
  195. virtual void onMidiCC114 (unsigned char channel, unsigned char value) {};
  196. virtual void onMidiCC115 (unsigned char channel, unsigned char value) {};
  197. virtual void onMidiCC116 (unsigned char channel, unsigned char value) {};
  198. virtual void onMidiCC117 (unsigned char channel, unsigned char value) {};
  199. virtual void onMidiCC118 (unsigned char channel, unsigned char value) {};
  200. virtual void onMidiCC119 (unsigned char channel, unsigned char value) {};
  201. virtual void onMidiCC120 (unsigned char channel, unsigned char value) {}; // AllSoundOff
  202. virtual void onMidiCC121 (unsigned char channel, unsigned char value) {}; // AllControlReset
  203. virtual void onMidiCC122 (unsigned char channel, unsigned char value) {};
  204. virtual void onMidiCC123 (unsigned char channel, unsigned char value) {};
  205. virtual void onMidiCC124 (unsigned char channel, unsigned char value) {};
  206. virtual void onMidiCC125 (unsigned char channel, unsigned char value) {};
  207. virtual void onMidiCC126 (unsigned char channel, unsigned char value) {}; // MonoModeOnOff
  208. virtual void onMidiCC127 (unsigned char channel, unsigned char value) {}; // PoliModeOnOff
  209. };

【CMidiMsg.cpp】
  1. #include "CMidiMsg.h"
  2.  
  3. CMidiMsg::CMidiMsg(void)
  4. {
  5. clearMidiMsg();
  6. }
  7.  
  8. CMidiMsg::~CMidiMsg(void)
  9. {
  10. }
  11.  
  12. void CMidiMsg::clearMidiMsg()
  13. {
  14. // メンバー変数を初期化する
  15. cur=0;
  16. num=0;
  17. memset(buf, 0, sizeof(MidiMessage)*MIDIMSG_MAXNUM);
  18. }
  19.  
  20. int CMidiMsg::addMidiMsg(VstMidiEvent *midievent)
  21. {
  22. MidiMessage tmp;
  23. tmp.deltaFrames = midievent->deltaFrames;
  24. tmp.message = midievent->midiData[0] & 0xF0;
  25. tmp.channel = midievent->midiData[0] & 0x0F;
  26. tmp.data1 = midievent->midiData[1];
  27. tmp.data2 = midievent->midiData[2];
  28.  
  29. return addMidiMsg(tmp);
  30. }
  31.  
  32. int CMidiMsg::addMidiMsg(MidiMessage msg)
  33. {
  34. // バッファがいっぱいなら0を返す
  35. if (num >= MIDIMSG_MAXNUM)
  36. return 0;
  37.  
  38. buf[num] = msg;
  39.  
  40. num++;
  41. if (num > MIDIMSG_MAXNUM) {num = MIDIMSG_MAXNUM;}
  42.  
  43. return 1;
  44. };
  45.  
  46. MidiMessage CMidiMsg::getMidiMsg()
  47. {
  48. MidiMessage tmp = buf[cur];
  49.  
  50. num--;
  51. if( num < 0) { num = 0; }
  52.  
  53. cur++;
  54. if( cur >= MIDIMSG_MAXNUM) { cur = MIDIMSG_MAXNUM -1;}
  55.  
  56. return tmp;
  57. }
  58.  
  59. VstInt32 CMidiMsg::getMidiMessageNum()
  60. {
  61. return num;
  62. }
  63.  
  64. VstInt32 CMidiMsg::getNextDeltaFrames()
  65. {
  66. return buf[cur].deltaFrames;
  67. }
  68.  
  69.  
  70. void CMidiMsg::midiProc(MidiMessage mididata)
  71. {
  72. short msb = 0;
  73. short lsb = 0;
  74. short pitchbend = 0;
  75.  
  76. switch (mididata.message & 0xF0)
  77. {
  78. case 0x80: // ノートオフメッセージ
  79. onMidiKeyOff(mididata.channel, mididata.data1, mididata.data2);
  80. break;
  81.  
  82. case 0x90: // ノートオンメッセージ
  83. // ヴェロシティが0の場合はノートオフメッセージとして扱う
  84. if (mididata.data2 > 0)
  85. {
  86. onMidiKeyOn(mididata.channel, mididata.data1, mididata.data2);
  87. }
  88. else
  89. {
  90. onMidiKeyOff(mididata.channel, mididata.data1, mididata.data2);
  91. }
  92. break;
  93.  
  94. case 0xA0: // キープレッシャーメッセージ
  95. onMidiPoliKeyPress(mididata.channel, mididata.data1, mididata.data2);
  96. break;
  97.  
  98. case 0xB0: // コントロールチェンジメッセージ
  99. onMidiControlChange(mididata.channel, mididata.data1, mididata.data2);
  100. break;
  101.  
  102. case 0xC0: // プログラムチェンジメッセージ
  103. onMidiProgramChange(mididata.channel, mididata.data1);
  104. break;
  105.  
  106. case 0xD0: // チャンネルプレッシャーメッセージ
  107. onMidiChannelPress(mididata.channel, mididata.data1);
  108. break;
  109.  
  110. case 0xE0: // ピッチベンドメッセージ
  111. lsb = (mididata.data1);
  112. msb = (mididata.data2);
  113. pitchbend = ((msb << 7) | lsb) - 8192;
  114. onMidiPitchBend(mididata.channel, pitchbend);
  115. break;
  116.  
  117. case 0xF0: // システムメッセージ
  118. onMidiSystemMessage((mididata.message & 0xF0) | (mididata.channel & 0x0F), mididata.data1, mididata.data2);
  119. break;
  120. }
  121. }
  122.  
  123. void CMidiMsg::onMidiSystemMessage(unsigned char systemmsg, unsigned char data1, unsigned char data2)
  124. {
  125.  
  126. short lsb = (data1);
  127. short msb = (data2);
  128. switch(systemmsg)
  129. {
  130. case 0xF1: onMidiQuarterFrame(data1); break;
  131. case 0xF2: onMidiSongPointer( (msb << 7) | lsb ); break;
  132. case 0xF3: onMidiSongSelect(data1); break;
  133. case 0xF6: onMidiChainRequest(); break;
  134. case 0xF8: onMidiTimingClock(); break;
  135. case 0xFA: onMidiStart(); break;
  136. case 0xFB: onMidiContinue(); break;
  137. case 0xFC: onMidiStop(); break;
  138. case 0xFE: onMidiActiveSensing(); break;
  139. case 0xFF: onMidiSystemReset(); break;
  140. default: break;
  141. }
  142. }
  143.  
  144. void CMidiMsg::onMidiControlChange(unsigned char channel, unsigned char cc, unsigned char value)
  145. {
  146. switch(cc)
  147. {
  148. case 0: onMidiCC000 (channel, value); break;
  149. case 1: onMidiCC001 (channel, value); break;
  150. case 2: onMidiCC002 (channel, value); break;
  151. case 3: onMidiCC003 (channel, value); break;
  152. case 4: onMidiCC004 (channel, value); break;
  153. case 5: onMidiCC005 (channel, value); break;
  154. case 6: onMidiCC006 (channel, value); break;
  155. case 7: onMidiCC007 (channel, value); break;
  156. case 8: onMidiCC008 (channel, value); break;
  157. case 9: onMidiCC009 (channel, value); break;
  158. case 10: onMidiCC010 (channel, value); break;
  159. case 11: onMidiCC011 (channel, value); break;
  160. case 12: onMidiCC012 (channel, value); break;
  161. case 13: onMidiCC013 (channel, value); break;
  162. case 14: onMidiCC014 (channel, value); break;
  163. case 15: onMidiCC015 (channel, value); break;
  164. case 16: onMidiCC016 (channel, value); break;
  165. case 17: onMidiCC017 (channel, value); break;
  166. case 18: onMidiCC018 (channel, value); break;
  167. case 19: onMidiCC019 (channel, value); break;
  168. case 20: onMidiCC020 (channel, value); break;
  169. case 21: onMidiCC021 (channel, value); break;
  170. case 22: onMidiCC022 (channel, value); break;
  171. case 23: onMidiCC023 (channel, value); break;
  172. case 24: onMidiCC024 (channel, value); break;
  173. case 25: onMidiCC025 (channel, value); break;
  174. case 26: onMidiCC026 (channel, value); break;
  175. case 27: onMidiCC027 (channel, value); break;
  176. case 28: onMidiCC028 (channel, value); break;
  177. case 29: onMidiCC029 (channel, value); break;
  178. case 30: onMidiCC030 (channel, value); break;
  179. case 31: onMidiCC031 (channel, value); break;
  180. case 32: onMidiCC032 (channel, value); break;
  181. case 33: onMidiCC033 (channel, value); break;
  182. case 34: onMidiCC034 (channel, value); break;
  183. case 35: onMidiCC035 (channel, value); break;
  184. case 36: onMidiCC036 (channel, value); break;
  185. case 37: onMidiCC037 (channel, value); break;
  186. case 38: onMidiCC038 (channel, value); break;
  187. case 39: onMidiCC039 (channel, value); break;
  188. case 40: onMidiCC040 (channel, value); break;
  189. case 41: onMidiCC041 (channel, value); break;
  190. case 42: onMidiCC042 (channel, value); break;
  191. case 43: onMidiCC043 (channel, value); break;
  192. case 44: onMidiCC044 (channel, value); break;
  193. case 45: onMidiCC045 (channel, value); break;
  194. case 46: onMidiCC046 (channel, value); break;
  195. case 47: onMidiCC047 (channel, value); break;
  196. case 48: onMidiCC048 (channel, value); break;
  197. case 49: onMidiCC049 (channel, value); break;
  198. case 50: onMidiCC050 (channel, value); break;
  199. case 51: onMidiCC051 (channel, value); break;
  200. case 52: onMidiCC052 (channel, value); break;
  201. case 53: onMidiCC053 (channel, value); break;
  202. case 54: onMidiCC054 (channel, value); break;
  203. case 55: onMidiCC055 (channel, value); break;
  204. case 56: onMidiCC056 (channel, value); break;
  205. case 57: onMidiCC057 (channel, value); break;
  206. case 58: onMidiCC058 (channel, value); break;
  207. case 59: onMidiCC059 (channel, value); break;
  208. case 60: onMidiCC060 (channel, value); break;
  209. case 61: onMidiCC061 (channel, value); break;
  210. case 62: onMidiCC062 (channel, value); break;
  211. case 63: onMidiCC063 (channel, value); break;
  212. case 64: onMidiCC064 (channel, value); break;
  213. case 65: onMidiCC065 (channel, value); break;
  214. case 66: onMidiCC066 (channel, value); break;
  215. case 67: onMidiCC067 (channel, value); break;
  216. case 68: onMidiCC068 (channel, value); break;
  217. case 69: onMidiCC069 (channel, value); break;
  218. case 70: onMidiCC070 (channel, value); break;
  219. case 71: onMidiCC071 (channel, value); break;
  220. case 72: onMidiCC072 (channel, value); break;
  221. case 73: onMidiCC073 (channel, value); break;
  222. case 74: onMidiCC074 (channel, value); break;
  223. case 75: onMidiCC075 (channel, value); break;
  224. case 76: onMidiCC076 (channel, value); break;
  225. case 77: onMidiCC077 (channel, value); break;
  226. case 78: onMidiCC078 (channel, value); break;
  227. case 79: onMidiCC079 (channel, value); break;
  228. case 80: onMidiCC080 (channel, value); break;
  229. case 81: onMidiCC081 (channel, value); break;
  230. case 82: onMidiCC082 (channel, value); break;
  231. case 83: onMidiCC083 (channel, value); break;
  232. case 84: onMidiCC084 (channel, value); break;
  233. case 85: onMidiCC085 (channel, value); break;
  234. case 86: onMidiCC086 (channel, value); break;
  235. case 87: onMidiCC087 (channel, value); break;
  236. case 88: onMidiCC088 (channel, value); break;
  237. case 89: onMidiCC089 (channel, value); break;
  238. case 90: onMidiCC090 (channel, value); break;
  239. case 91: onMidiCC091 (channel, value); break;
  240. case 92: onMidiCC092 (channel, value); break;
  241. case 93: onMidiCC093 (channel, value); break;
  242. case 94: onMidiCC094 (channel, value); break;
  243. case 95: onMidiCC095 (channel, value); break;
  244. case 96: onMidiCC096 (channel, value); break;
  245. case 97: onMidiCC097 (channel, value); break;
  246. case 98: onMidiCC098 (channel, value); break;
  247. case 99: onMidiCC099 (channel, value); break;
  248. case 100: onMidiCC100 (channel, value); break;
  249. case 101: onMidiCC101 (channel, value); break;
  250. case 102: onMidiCC102 (channel, value); break;
  251. case 103: onMidiCC103 (channel, value); break;
  252. case 104: onMidiCC104 (channel, value); break;
  253. case 105: onMidiCC105 (channel, value); break;
  254. case 106: onMidiCC106 (channel, value); break;
  255. case 107: onMidiCC107 (channel, value); break;
  256. case 108: onMidiCC108 (channel, value); break;
  257. case 109: onMidiCC109 (channel, value); break;
  258. case 110: onMidiCC110 (channel, value); break;
  259. case 111: onMidiCC111 (channel, value); break;
  260. case 112: onMidiCC112 (channel, value); break;
  261. case 113: onMidiCC113 (channel, value); break;
  262. case 114: onMidiCC114 (channel, value); break;
  263. case 115: onMidiCC115 (channel, value); break;
  264. case 116: onMidiCC116 (channel, value); break;
  265. case 117: onMidiCC117 (channel, value); break;
  266. case 118: onMidiCC118 (channel, value); break;
  267. case 119: onMidiCC119 (channel, value); break;
  268. case 120: onMidiCC120 (channel, value); break;
  269. case 121: onMidiCC121 (channel, value); break;
  270. case 122: onMidiCC122 (channel, value); break;
  271. case 123: onMidiCC123 (channel, value); break;
  272. case 124: onMidiCC124 (channel, value); break;
  273. case 125: onMidiCC125 (channel, value); break;
  274. case 126: onMidiCC126 (channel, value); break;
  275. case 127: onMidiCC127 (channel, value); break;
  276. default: break;
  277. }
  278. }

【MyMidiSample2VST.cpp】
  1. // ============================================================================================
  2. // インクルードファイル
  3. // ============================================================================================
  4. #include <stdlib.h>
  5. #include "audioeffectx.h"
  6.  
  7. #include "CMidiMsg.h"
  8.  
  9. // ============================================================================================
  10. // 設計情報の記入
  11. // ============================================================================================
  12. #define MY_VST_INPUT_NUM 2 //入力数。モノラル入力=1、ステレオ入力=2
  13. #define MY_VST_OUTPUT_NUM 2 //出力数。モノラル出力=1、ステレオ出力=2
  14.  
  15. #define MY_VST_UNIQUE_ID 'SMPL' //ユニークID
  16. //公開する場合は以下URLで発行されたユニークIDを入力する。
  17. //http://ygrabit.steinberg.de/~ygrabit/public_html/index.html
  18.  
  19. #define MY_VST_PRESET_NUM 1 //プリセットプログラムの数
  20. #define MY_VST_PARAMETER_NUM 0 //パラメータの数
  21.  
  22. // ============================================================================================
  23. // VSTの基本となるクラス
  24. // ============================================================================================
  25. class MyMidiSample2VST : public AudioEffectX , public CMidiMsg
  26. {
  27. protected:
  28. float volume;
  29. public:
  30. MyMidiSample2VST (audioMasterCallback audioMaster);
  31.  
  32. // 音声信号を処理するメンバー関数
  33. virtual void processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames);
  34.  
  35. // MIDIメッセージをホストアプリケーションから受け取るためのメンバー関数
  36. VstInt32 processEvents (VstEvents* events);
  37.  
  38.  
  39. void onMidiCC007(unsigned char channel, unsigned char value);
  40. };
  41.  
  42. // ============================================================================================
  43. // このVSTのを生成するための関数
  44. // ============================================================================================
  45. AudioEffect* createEffectInstance (audioMasterCallback audioMaster)
  46. {
  47. //newでこのVSTを生成したポインタを返す
  48. return new MyMidiSample2VST (audioMaster);
  49. }
  50.  
  51. MyMidiSample2VST::MyMidiSample2VST (audioMasterCallback audioMaster)
  52. : AudioEffectX (audioMaster, MY_VST_PRESET_NUM, MY_VST_PARAMETER_NUM)
  53. {
  54. //VSTの初期化を行う。
  55.  
  56. //以下の関数を呼び出して入力数、出力数等の情報を設定する。
  57. //必ず呼び出さなければならない。
  58. setNumInputs (MY_VST_INPUT_NUM); //入力数の設定
  59. setNumOutputs (MY_VST_OUTPUT_NUM); //出力数の設定
  60. setUniqueID (MY_VST_UNIQUE_ID); //ユニークIDの設定
  61.  
  62. isSynth (true); //このVSTがSynthかどうかのフラグを設定。
  63. //Synthの場合…true、Effectorの場合…false
  64.  
  65. canProcessReplacing (); //このVSTが音声処理可能かどうかのフラグを設定。
  66. //音声処理を行わないVSTはないので必ずこの関数を呼び出す。
  67.  
  68. //上記の関数を呼び出した後に初期化を行う
  69. volume = 1.0f;
  70. }
  71.  
  72. void MyMidiSample2VST::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
  73. {
  74. //入力、出力は2次元配列で渡される。
  75. //入力は-1.0f~1.0fの間で渡される。
  76. //出力は-1.0f~1.0fの間で書き込む必要がある。
  77. //sampleFramesが処理するバッファのサイズ
  78. float* outL = outputs[0]; //出力 左用
  79. float* outR = outputs[1]; //出力 右用
  80.  
  81. for (int i = 0; i < sampleFrames; i++)
  82. {
  83. //ここで音声処理を行う。
  84.  
  85. // MIDIメッセージがあるか確認
  86. if ( getMidiMessageNum() > 0)
  87. {
  88. // MIDIメッセージを処理するタイミングかどうかを確認する。
  89. if( getNextDeltaFrames() <= i)
  90. {
  91. // MIDIメッセージをバッファから取り出し処理する
  92. midiProc( getMidiMsg() );
  93. }
  94. }
  95.  
  96. //出力バッファへ書き込む。
  97. outL[i] = volume * (float)((rand() % 256) -128) / 255.0f;
  98. outR[i] = volume * (float)((rand() % 256) -128) / 255.0f;
  99. }
  100. }
  101.  
  102. // MIDIメッセージを処理するメンバー関数
  103. // processReplacing()の前に必ず1度だけ呼び出される。
  104. //
  105. VstInt32 MyMidiSample2VST::processEvents (VstEvents* events)
  106. {
  107. // MIDIのリストを初期化します。
  108. clearMidiMsg();
  109.  
  110. int loops = (events->numEvents);
  111.  
  112. // VSTイベントの回数だけループをまわす。
  113. for (int i = 0;i < loops; i++)
  114. {
  115. // 与えられたイベントがMIDIならばmidimsgbufにストックする
  116. if ((events->events[i])->type == kVstMidiType)
  117. {
  118. VstMidiEvent *midievent = (VstMidiEvent*)(events->events[i]);
  119. if( !addMidiMsg(midievent) )
  120. {
  121. break;
  122. }
  123. }
  124. }
  125.  
  126. // 1を返さなければならない
  127. return 1;
  128. }
  129.  
  130. //
  131. // onMidiCC007()関数をオーバーライドして、MIDI CC7の場合の動作を定義する。
  132. // ここではチャンネルに関係なく、MIDI CC7メッセージを受け取るとノイズのボリュームを
  133. // 変更するようにしている。
  134. void MyMidiSample2VST::onMidiCC007 (unsigned char channel, unsigned char value)
  135. {
  136. volume = (float)(value) / 127.0f;
  137. }





同一カテゴリのTips


項目 No. 概要


javascript plugin Error : このプラグインで利用できない命令または文字列が入っています。