mirror of
https://github.com/quantum5/MusicKeyboard.git
synced 2025-04-24 13:11:58 -04:00
Make the MIDI writing feature actually usable.
This commit is contained in:
parent
3721262ef6
commit
32809c148b
|
@ -38,6 +38,7 @@
|
||||||
#define KEYBOARD_SAVE_FILE 0xAB01
|
#define KEYBOARD_SAVE_FILE 0xAB01
|
||||||
#define KEYBOARD_BROWSE 0xAB02
|
#define KEYBOARD_BROWSE 0xAB02
|
||||||
#define KEYBOARD_REOPEN 0xAB03
|
#define KEYBOARD_REOPEN 0xAB03
|
||||||
|
#define KEYBOARD_CLOSE_FILE 0xAB04
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T clamp(T v, T a, T b) {
|
T clamp(T v, T a, T b) {
|
||||||
|
@ -60,6 +61,7 @@ protected:
|
||||||
WORD GetRealKeyCode(WORD wQWERTYCode);
|
WORD GetRealKeyCode(WORD wQWERTYCode);
|
||||||
virtual void PaintContent(PAINTSTRUCT *pps);
|
virtual void PaintContent(PAINTSTRUCT *pps);
|
||||||
void OnReOpenMIDI();
|
void OnReOpenMIDI();
|
||||||
|
void OnCloseMIDI();
|
||||||
void OnAdjust();
|
void OnAdjust();
|
||||||
|
|
||||||
int GetMIDINote(WPARAM wCode, bool &half, int &base);
|
int GetMIDINote(WPARAM wCode, bool &half, int &base);
|
||||||
|
@ -87,7 +89,7 @@ protected:
|
||||||
HWND m_keyLabel, m_keySelect;
|
HWND m_keyLabel, m_keySelect;
|
||||||
bool adjusting;
|
bool adjusting;
|
||||||
HWND m_beepCheck;
|
HWND m_beepCheck;
|
||||||
HWND m_saveCheck, m_saveLabel, m_saveFile, m_saveBrowse, m_reopen;
|
HWND m_saveCheck, m_saveLabel, m_saveFile, m_saveBrowse, m_reopen, m_closeFile;
|
||||||
int m_instrument, m_volume, m_force, m_adjust;
|
int m_instrument, m_volume, m_force, m_adjust;
|
||||||
HMIDIOUT m_midi;
|
HMIDIOUT m_midi;
|
||||||
bool isQWERTY;
|
bool isQWERTY;
|
||||||
|
|
|
@ -223,6 +223,9 @@ LRESULT MainWindow::OnCreate()
|
||||||
m_reopen = CreateWindow(WC_BUTTON, L"R&eopen",
|
m_reopen = CreateWindow(WC_BUTTON, L"R&eopen",
|
||||||
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED | WS_TABSTOP,
|
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED | WS_TABSTOP,
|
||||||
0, 0, 0, 0, m_hwnd, (HMENU) KEYBOARD_REOPEN, GetInstance(), NULL);
|
0, 0, 0, 0, m_hwnd, (HMENU) KEYBOARD_REOPEN, GetInstance(), NULL);
|
||||||
|
m_closeFile = CreateWindow(WC_BUTTON, L"&Close",
|
||||||
|
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED | WS_TABSTOP,
|
||||||
|
0, 0, 0, 0, m_hwnd, (HMENU) KEYBOARD_CLOSE_FILE, GetInstance(), NULL);
|
||||||
|
|
||||||
m_beepCheck = CreateWindow(WC_BUTTON, L"&Beep?", WS_CHILD | WS_VISIBLE | BS_CHECKBOX | WS_TABSTOP,
|
m_beepCheck = CreateWindow(WC_BUTTON, L"&Beep?", WS_CHILD | WS_VISIBLE | BS_CHECKBOX | WS_TABSTOP,
|
||||||
0, 0, 0, 0, m_hwnd, (HMENU) KEYBOARD_USE_BEEP, GetInstance(), NULL);
|
0, 0, 0, 0, m_hwnd, (HMENU) KEYBOARD_USE_BEEP, GetInstance(), NULL);
|
||||||
|
@ -268,6 +271,7 @@ LRESULT MainWindow::OnCreate()
|
||||||
SETFONT(m_saveFile);
|
SETFONT(m_saveFile);
|
||||||
SETFONT(m_saveBrowse);
|
SETFONT(m_saveBrowse);
|
||||||
SETFONT(m_reopen);
|
SETFONT(m_reopen);
|
||||||
|
SETFONT(m_closeFile);
|
||||||
#undef SETFONT
|
#undef SETFONT
|
||||||
|
|
||||||
SendMessage(m_keySelect, CB_INITSTORAGE, 12, 128);
|
SendMessage(m_keySelect, CB_INITSTORAGE, 12, 128);
|
||||||
|
@ -524,6 +528,17 @@ void MainWindow::OnReOpenMIDI()
|
||||||
midiFileSetTracksDefaultChannel(m_midifile, 1, MIDI_CHANNEL_1);
|
midiFileSetTracksDefaultChannel(m_midifile, 1, MIDI_CHANNEL_1);
|
||||||
midiTrackAddProgramChange(m_midifile, 1, m_instrument);
|
midiTrackAddProgramChange(m_midifile, 1, m_instrument);
|
||||||
midiSongAddSimpleTimeSig(m_midifile, 1, 4, MIDI_NOTE_CROCHET);
|
midiSongAddSimpleTimeSig(m_midifile, 1, 4, MIDI_NOTE_CROCHET);
|
||||||
|
|
||||||
|
EnableWindow(m_closeFile, TRUE);
|
||||||
|
SetFocus(m_hwnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::OnCloseMIDI()
|
||||||
|
{
|
||||||
|
if (m_midifile)
|
||||||
|
midiFileClose(m_midifile);
|
||||||
|
m_midifile = NULL;
|
||||||
|
EnableWindow(m_closeFile, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK MainWindow::LowLevelKeyboardHook(HHOOK hHook, int nCode, WPARAM wParam, LPARAM lParam) {
|
LRESULT CALLBACK MainWindow::LowLevelKeyboardHook(HHOOK hHook, int nCode, WPARAM wParam, LPARAM lParam) {
|
||||||
|
@ -646,9 +661,10 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
REPOS(m_keySelect, BOTTOM(390, client.bottom - 67, 65, 22));
|
REPOS(m_keySelect, BOTTOM(390, client.bottom - 67, 65, 22));
|
||||||
REPOS(m_saveCheck, BOTTOM(22, client.bottom - 42, 50, 20));
|
REPOS(m_saveCheck, BOTTOM(22, client.bottom - 42, 50, 20));
|
||||||
REPOS(m_saveLabel, BOTTOM(27, client.bottom - 19, 30, 20));
|
REPOS(m_saveLabel, BOTTOM(27, client.bottom - 19, 30, 20));
|
||||||
REPOS(m_saveFile, BOTTOM(62, client.bottom - 17, client.right - 249, 25));
|
REPOS(m_saveFile, BOTTOM(62, client.bottom - 17, client.right - 334, 25));
|
||||||
REPOS(m_saveBrowse, BOTTOMRIGHT(client.right - 102, client.bottom - 17, 80, 25));
|
REPOS(m_saveBrowse, BOTTOMRIGHT(client.right - 187, client.bottom - 17, 80, 25));
|
||||||
REPOS(m_reopen, BOTTOMRIGHT(client.right - 17, client.bottom - 17, 80, 25));
|
REPOS(m_reopen, BOTTOMRIGHT(client.right - 102, client.bottom - 17, 80, 25));
|
||||||
|
REPOS(m_closeFile, BOTTOMRIGHT(client.right - 17, client.bottom - 17, 80, 25));
|
||||||
REPOS(m_beepCheck, BOTTOMRIGHT(client.right - 17, client.bottom - 42, 60, 20));
|
REPOS(m_beepCheck, BOTTOMRIGHT(client.right - 17, client.bottom - 42, 60, 20));
|
||||||
EndDeferWindowPos(hdwp);
|
EndDeferWindowPos(hdwp);
|
||||||
#undef REPOS
|
#undef REPOS
|
||||||
|
@ -693,6 +709,7 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
EnableWindow(m_saveFile, checked);
|
EnableWindow(m_saveFile, checked);
|
||||||
EnableWindow(m_saveBrowse, checked);
|
EnableWindow(m_saveBrowse, checked);
|
||||||
EnableWindow(m_reopen, Edit_GetTextLength(m_saveFile) > 0 ? checked : FALSE);
|
EnableWindow(m_reopen, Edit_GetTextLength(m_saveFile) > 0 ? checked : FALSE);
|
||||||
|
EnableWindow(m_closeFile, m_midifile != NULL);
|
||||||
saving = checked == TRUE;
|
saving = checked == TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -723,11 +740,14 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
case KEYBOARD_REOPEN:
|
case KEYBOARD_REOPEN:
|
||||||
OnReOpenMIDI();
|
OnReOpenMIDI();
|
||||||
break;
|
break;
|
||||||
|
case KEYBOARD_CLOSE_FILE:
|
||||||
|
OnCloseMIDI();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EN_CHANGE:
|
case EN_CHANGE:
|
||||||
switch (LOWORD(wParam))
|
switch (LOWORD(wParam)) {
|
||||||
case KEYBOARD_OCTAVE: {
|
case KEYBOARD_OCTAVE:
|
||||||
if (!adjusting) {
|
if (!adjusting) {
|
||||||
int o = GetDlgItemInt(m_hwnd, KEYBOARD_OCTAVE, NULL, TRUE);
|
int o = GetDlgItemInt(m_hwnd, KEYBOARD_OCTAVE, NULL, TRUE);
|
||||||
int octave = clamp(o, -3, 3);
|
int octave = clamp(o, -3, 3);
|
||||||
|
@ -754,9 +774,9 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEYBOARD_SAVE_FILE:
|
case KEYBOARD_SAVE_FILE:
|
||||||
if (IsDlgButtonChecked(m_hwnd, KEYBOARD_SAVE) &&
|
EnableWindow(m_reopen, IsDlgButtonChecked(m_hwnd, KEYBOARD_SAVE) &&
|
||||||
Edit_GetTextLength(m_saveFile) > 0)
|
Edit_GetTextLength(m_saveFile) > 0);
|
||||||
EnableWindow(m_reopen, TRUE);
|
EnableWindow(m_closeFile, m_midifile != NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue