diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 23d96cd1f..13a380b41 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -2905,7 +2905,7 @@ int FurnaceGUI::processEvent(SDL_Event* ev) { } #endif if (ev->type==SDL_KEYDOWN) { - if (!ev->key.repeat && latchTarget==0 && !wantCaptureKeyboard && (ev->key.keysym.mod&(~(KMOD_NUM|KMOD_CAPS|KMOD_SCROLL)))==0) { + if (!ev->key.repeat && latchTarget==0 && !wantCaptureKeyboard && !sampleMapWaitingInput && (ev->key.keysym.mod&(~(KMOD_NUM|KMOD_CAPS|KMOD_SCROLL)))==0) { if (settings.notePreviewBehavior==0) return 1; switch (curWindow) { case GUI_WINDOW_SAMPLE_EDIT: @@ -5561,6 +5561,8 @@ bool FurnaceGUI::loop() { } } } + + sampleMapWaitingInput=(curWindow==GUI_WINDOW_INS_EDIT && sampleMapFocused); curWindowThreadSafe=curWindow; diff --git a/src/gui/gui.h b/src/gui/gui.h index 4dcb78ee1..fb193c20a 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1683,7 +1683,7 @@ class FurnaceGUI { int sampleMapSelEnd; int sampleMapDigit; int sampleMapColumn; - bool sampleMapFocused; + bool sampleMapFocused, sampleMapWaitingInput; ImVec2 macroDragStart; ImVec2 macroDragAreaSize; @@ -1938,6 +1938,7 @@ class FurnaceGUI { void drawMacroEdit(FurnaceGUIMacroDesc& i, int totalFit, float availableWidth, int index); void drawMacros(std::vector& macros, FurnaceGUIMacroEditState& state); + void alterSampleMap(bool isNote, int val); void drawOrderButtons(); diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 349376c26..9ec9da044 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -2023,6 +2023,57 @@ void FurnaceGUI::drawMacros(std::vector& macros, FurnaceGUI } } +void FurnaceGUI::alterSampleMap(bool isNote, int val) { + if (curIns<0 || curIns>=(int)e->song.ins.size()) return; + DivInstrument* ins=e->song.ins[curIns]; + int sampleMapMin=sampleMapSelStart; + int sampleMapMax=sampleMapSelEnd; + if (sampleMapMin>sampleMapMax) { + sampleMapMin^=sampleMapMax; + sampleMapMax^=sampleMapMin; + sampleMapMin^=sampleMapMax; + } + + for (int i=sampleMapMin; i<=sampleMapMax; i++) { + if (i<0 || i>=120) continue; + + if (sampleMapColumn==1 && isNote) { + ins->amiga.noteMap[i].freq=val; + } else if (sampleMapColumn==0 && !isNote) { + if (val<0) { + ins->amiga.noteMap[i].map=-1; + } else if (sampleMapDigit>0) { + ins->amiga.noteMap[i].map*=10; + ins->amiga.noteMap[i].map+=val; + } else { + ins->amiga.noteMap[i].map=val; + } + if (ins->amiga.noteMap[i].map>=(int)e->song.sample.size()) { + ins->amiga.noteMap[i].map=((int)e->song.sample.size())-1; + } + } + } + + bool advance=false; + if (sampleMapColumn==1 && isNote) { + advance=true; + } else if (sampleMapColumn==0 && !isNote) { + int digits=1; + if (e->song.sample.size()>=10) digits=2; + if (e->song.sample.size()>=100) digits=3; + if (++sampleMapDigit>=digits) { + sampleMapDigit=0; + advance=true; + } + } + + if (advance && sampleMapMin==sampleMapMax) { + sampleMapSelStart++; + if (sampleMapSelStart>119) sampleMapSelStart=119; + sampleMapSelEnd=sampleMapSelStart; + } +} + #define DRUM_FREQ(name,db,df,prop) \ ImGui::TableNextRow(); \ ImGui::TableNextColumn(); \ @@ -4405,9 +4456,9 @@ void FurnaceGUI::drawInsEdit() { ImGui::BeginDisabled(ins->amiga.useWave); P(ImGui::Checkbox("Use sample map",&ins->amiga.useNoteMap)); if (ins->amiga.useNoteMap) { - if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - sampleMapFocused=false; - } + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsWindowHovered()) sampleMapFocused=false; + if (curWindowLast!=GUI_WINDOW_INS_EDIT) sampleMapFocused=false; + if (!sampleMapFocused) sampleMapDigit=0; if (ImGui::BeginTable("NoteMap",4,ImGuiTableFlags_ScrollY|ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) { ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed); @@ -4454,6 +4505,7 @@ void FurnaceGUI::drawInsEdit() { if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) { sampleMapFocused=true; sampleMapColumn=0; + sampleMapDigit=0; sampleMapSelStart=i; sampleMapSelEnd=i; ImGui::InhibitInertialScroll(); @@ -4475,6 +4527,7 @@ void FurnaceGUI::drawInsEdit() { if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) { sampleMapFocused=true; sampleMapColumn=1; + sampleMapDigit=0; sampleMapSelStart=i; sampleMapSelEnd=i; ImGui::InhibitInertialScroll(); diff --git a/src/gui/piano.cpp b/src/gui/piano.cpp index fe451c3f7..baae316d1 100644 --- a/src/gui/piano.cpp +++ b/src/gui/piano.cpp @@ -415,10 +415,14 @@ void FurnaceGUI::drawPiano() { e->previewSample(curSample,note); break; default: - e->synchronized([this,note]() { - e->autoNoteOn(-1,curIns,note); - }); - if (edit && curWindow!=GUI_WINDOW_INS_LIST && curWindow!=GUI_WINDOW_INS_EDIT) noteInput(note,0); + if (sampleMapWaitingInput) { + alterSampleMap(true,note); + } else { + e->synchronized([this,note]() { + e->autoNoteOn(-1,curIns,note); + }); + if (edit && curWindow!=GUI_WINDOW_INS_LIST && curWindow!=GUI_WINDOW_INS_EDIT) noteInput(note,0); + } break; } }