おーぷんmidiぷろじぇくとというライブラリを使用しています。
電子ドラムで叩いた音を楽譜に表示させようとしているのですが、
叩いた音は表示できているものの、何故か一度しか叩いていないのですが、2回たたいたことになり、音符が2個ならんで、2回叩いた判定になってしまいます。原因が分からず、困っています。元々ピアノベースに作られたプログラムなので、鍵盤を押したときと、離した時の判定がドラムにも同じような判定になってしまっていると考えているのですが、それにしても、1度叩いて2個並ぶ音符の表示に少し距離があるので、分からずです。原因であろう箇所のプログラムだけおいてます(入りきらないので)。よろしくお願いします。
c++
1HANDLE hGetNotesMutex; //ミューテックスのハンドル 2HANDLE hNoteXMutex; 3 4std::vector<int> note_correct_x; 5std::vector<int> note_correct_y; 6std::vector<int> note_player_x; 7std::vector<int> note_player_y; 8 9 10 11void PutNoteData(int mode, cv::Mat& sheet, unsigned char status, unsigned char data1, unsigned char data2, long duration, cv::Scalar color, int note_x) { 12 int index = -1; 13 PutNote(sheet, status, data1, data2, duration, color, note_x, index); 14 if (mode == 0) { // 楽譜構築モード 15 note_correct_x.push_back(note_x); 16 note_correct_y.push_back(index); 17 } 18 else if (mode == 1) { // ユーザによる演奏音符反映モード 19 note_player_x.push_back(note_x); 20 note_player_y.push_back(index); 21 } 22 else { 23 // mode == -1 // 時刻に対応する音符反映モード 24 } 25} 26 27unsigned __stdcall GetNotesThread(void *p) 28{ 29 30 long lLen; 31 unsigned char byMessage[256]; 32 33 /* MIDIメッセージの取得ループ */ 34 while (g_bContinue) { 35 WaitForSingleObject(hGetNotesMutex, INFINITE); //mutex 間は他のスレッドから変数を変更できない 36 lLen = MIDIIn_GetMIDIMessage(pMIDIIn, byMessage, 256); 37 ReleaseMutex(hGetNotesMutex); 38 39 /* MIDIメッセージを取得した */ 40 if (lLen > 0) { 41 42 /* スレッド */ 43 WaitForSingleObject(hGetNotesMutex, INFINITE); 44 MIDIOut_PutMIDIMessage(pMIDIOut, byMessage, lLen); 45 for (int i = 0; i < lLen; i++) { 46 std::cerr << "0x" << std::setw(2) << std::setfill('0') << std::hex << std::uppercase << (int)byMessage[i] << " "; 47 } 48 std::cerr << "/ ";; 49 ReleaseMutex(hGetNotesMutex); 50 51 unsigned char status = byMessage[0]; 52 unsigned char data1 = byMessage[1]; 53 unsigned char data2 = byMessage[2]; 54 if ((status & 0xF0) == 0x90 && ((status & 0x0F) == 9 || data2 != 0x00)) { 55 hitcount++; 56 57 WaitForSingleObject(hNoteXMutex, INFINITE); //mutex 間は他のスレッドから変数を変更できない 58 PutNoteData(1, sheet_base2[0], status, data1, data2, 120, cv::Scalar(127, 127, 127), current_x); 59 60 int key_x = note_player_x[note_player_x.size() - 1]; 61 int key_y = note_player_y[note_player_y.size() - 1]; 62 63 int nearest_index = 0; 64 int nearest_length = 99999; 65 66 for (int i = 0; i < note_correct_x.size(); i++) { 67 if (abs(note_correct_x[i] - key_x) < nearest_length) { 68 nearest_index = i; 69 nearest_length = abs(note_correct_x[i] - key_x); 70 } 71 } 72 73 int near_x = note_correct_x[nearest_index]; 74 int near_y = note_correct_y[nearest_index]; 75 double diff;
ドラムですとチャタリングのような影響が大きいと思いますが対策はしていますか?
回答1件
あなたの回答
tips
プレビュー