GUI: move all preview actions to callback

This commit is contained in:
tildearrow 2022-04-15 23:47:39 -05:00
parent 6b294933bc
commit a81393472c
2 changed files with 48 additions and 50 deletions

View file

@ -1179,45 +1179,6 @@ void FurnaceGUI::keyDown(SDL_Event& ev) {
}
} catch (std::out_of_range& e) {
}
// PER-WINDOW PREVIEW KEYS
// TODO: move this to new event handler
switch (curWindow) {
case GUI_WINDOW_SAMPLE_EDIT:
case GUI_WINDOW_SAMPLE_LIST:
if (!ev.key.repeat) {
try {
int key=noteKeys.at(ev.key.keysym.scancode);
int num=12*curOctave+key;
if (key!=100 && key!=101 && key!=102) {
e->previewSample(curSample,num);
samplePreviewOn=true;
samplePreviewKey=ev.key.keysym.scancode;
samplePreviewNote=num;
}
} catch (std::out_of_range& e) {
}
}
break;
case GUI_WINDOW_WAVE_LIST:
case GUI_WINDOW_WAVE_EDIT:
if (!ev.key.repeat) {
try {
int key=noteKeys.at(ev.key.keysym.scancode);
int num=12*curOctave+key;
if (key!=100 && key!=101 && key!=102) {
e->previewWave(curWave,num);
wavePreviewOn=true;
wavePreviewKey=ev.key.keysym.scancode;
wavePreviewNote=num;
}
} catch (std::out_of_range& e) {
}
}
break;
default:
break;
}
}
void FurnaceGUI::keyUp(SDL_Event& ev) {
@ -1998,7 +1959,39 @@ int _processEvent(void* instance, SDL_Event* event) {
int FurnaceGUI::processEvent(SDL_Event* ev) {
if (ev->type==SDL_KEYDOWN) {
if (!ev->key.repeat) {
if (!ev->key.repeat && !wantCaptureKeyboard) {
switch (curWindow) {
case GUI_WINDOW_SAMPLE_EDIT:
case GUI_WINDOW_SAMPLE_LIST:
try {
int key=noteKeys.at(ev->key.keysym.scancode);
int num=12*curOctave+key;
if (key!=100 && key!=101 && key!=102) {
e->previewSample(curSample,num);
samplePreviewOn=true;
samplePreviewKey=ev->key.keysym.scancode;
samplePreviewNote=num;
}
} catch (std::out_of_range& e) {
}
break;
case GUI_WINDOW_WAVE_LIST:
case GUI_WINDOW_WAVE_EDIT:
try {
int key=noteKeys.at(ev->key.keysym.scancode);
int num=12*curOctave+key;
if (key!=100 && key!=101 && key!=102) {
e->previewWave(curWave,num);
wavePreviewOn=true;
wavePreviewKey=ev->key.keysym.scancode;
wavePreviewNote=num;
}
} catch (std::out_of_range& e) {
}
break;
case GUI_WINDOW_ORDERS: // ignore here
break;
default:
try {
int key=noteKeys.at(ev->key.keysym.scancode);
int num=12*curOctave+key;
@ -2011,6 +2004,8 @@ int FurnaceGUI::processEvent(SDL_Event* ev) {
}
} catch (std::out_of_range& e) {
}
break;
}
}
} else if (ev->type==SDL_KEYUP) {
stopPreviewNote(ev->key.keysym.scancode,true);
@ -2168,6 +2163,8 @@ bool FurnaceGUI::loop() {
}
}
wantCaptureKeyboard=ImGui::GetIO().WantCaptureKeyboard;
while (true) {
midiLock.lock();
if (midiQueue.empty()) {
@ -3417,6 +3414,7 @@ FurnaceGUI::FurnaceGUI():
displayError(false),
displayExporting(false),
vgmExportLoop(true),
wantCaptureKeyboard(false),
displayNew(false),
vgmExportVersion(0x171),
curFileDialog(GUI_FILE_OPEN),

View file

@ -711,7 +711,7 @@ class FurnaceGUI {
String mmlString[17];
String mmlStringW;
bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop;
bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, wantCaptureKeyboard;
bool displayNew;
bool willExport[32];
int vgmExportVersion;