From ad98677dac624dd527b410d044fe0b9318a0faea Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 9 Dec 2013 20:17:32 -0500 Subject: [PATCH] Remapped key layout to support one octave increments. Makes playing pieces that makes extensive use of keys between old modifier boundaries MUCH easier. Here are the modifier in octaves increased: Ctrl+Shift: -2 Ctrl: -1 (None): 0 Shift: 1 Alt: 2 Ctrl+Alt: 3 Shift+Alt: 4 --- src/MainWindow.cpp | 62 ++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a9de4ad..559c2bc 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -306,10 +306,9 @@ WORD MainWindow::GetRealKeyCode(WORD wQWERTYCode) return wQWERTYCode; } -int GetMIDINote(WPARAM wCode) -{ +int ModifyNote(int note, bool &half) { int state = 0; - int note; + if (GetKeyState(VK_CONTROL) < 0) state |= 0x001; if (GetKeyState(VK_SHIFT) < 0) @@ -317,31 +316,57 @@ int GetMIDINote(WPARAM wCode) if (GetKeyState(VK_MENU) < 0) state |= 0x100; - note = keymap[wCode]; switch (state) { - case 0x001: + case 0x011: note -= 24; + half = false; + break; + case 0x001: + note -= 12; + half = true; break; case 0x010: - note += 24; + note += 12; + half = true; break; case 0x100: + note += 24; + half = false; + break; + case 0x101: + note += 36; + half = true; + break; + case 0x110: note += 48; + half = false; break; } return note; } +int GetMIDINote(WPARAM wCode, bool &half) +{ + int note = keymap[wCode]; + note = ModifyNote(note, half); + return note; +} + bool MainWindow::Play(WPARAM wParam, LPARAM lParam, bool down) { int note; + bool half; WORD wCode = GetQWERTYKeyCode((WORD) wParam); if (wCode > 255 || !keymap[wCode] || (down && (lParam & 0x40000000))) return false; - note = GetMIDINote(wCode); + note = GetMIDINote(wCode, half); PlayNote(note, down); - piano->SetKeyStatus((note - 6) % 24, down); + note -= 6; + if (half) + note += 12; + note %= 24; + piano->SetKeyStatus(note, down); return true; } @@ -608,26 +633,9 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) SetWindowLongPtr(m_hwnd, GWL_EXSTYLE, GetWindowLongPtr(m_hwnd, GWL_EXSTYLE) & ~WS_EX_COMPOSITED); return 0; case MMWM_NOTEID: { - int state = 0; - if (GetKeyState(VK_CONTROL) < 0) - state |= 0x001; - if (GetKeyState(VK_SHIFT) < 0) - state |= 0x010; - if (GetKeyState(VK_MENU) < 0) - state |= 0x100; - int note = wParam + 54; - switch (state) { - case 0x001: - note -= 24; - break; - case 0x010: - note += 24; - break; - case 0x100: - note += 48; - break; - } + bool half; + note = ModifyNote(note, half); return note; } case MMWM_TURNNOTE: