Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instrument edit history vZoom/vScroll issue #2139

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/gui/debugWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ static void _drawOsc(const ImDrawList* drawList, const ImDrawCmd* cmd) {
}
}

void drawDebugUndoTableItem(const CursorJumpPoint& spot) {
ImGui::Text("[%d:%d] <%d:%d, %d>", spot.subSong, spot.order, spot.point.xCoarse, spot.point.xFine, spot.point.y);
}

void drawDebugUndoTableItem(const DivInstrumentUndoStep* step) {
if (step->nameValid) {
ImGui::Text("%s", step->name.c_str());
} else {
ImGui::Text("patch %d:%d", (int)step->podPatch.offset, (int)step->podPatch.size);
}
}

template <typename t_collection> void drawDebugUndoTable(const char* id, t_collection* undo, t_collection* redo) {
if (ImGui::BeginChild(id, ImVec2(0, 300), true)) {
if (ImGui::BeginTable("##UndoDebugTable", 2, ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) {
for (size_t row=0; row<MAX(undo->size(),redo->size()); ++row) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (row<undo->size()) drawDebugUndoTableItem((*undo)[undo->size()-row-1]);
ImGui::TableNextColumn();
if (row<redo->size()) drawDebugUndoTableItem((*redo)[redo->size()-row-1]);
}
ImGui::EndTable();
}
}
ImGui::EndChild();
}

void FurnaceGUI::drawDebug() {
static int bpOrder;
static int bpRow;
Expand Down Expand Up @@ -732,22 +760,14 @@ void FurnaceGUI::drawDebug() {
ImGui::TreePop();
}
if (ImGui::TreeNode("Cursor Undo Debug")) {
auto DrawSpot=[&](const CursorJumpPoint& spot) {
ImGui::Text("[%d:%d] <%d:%d, %d>", spot.subSong, spot.order, spot.point.xCoarse, spot.point.xFine, spot.point.y);
};
if (ImGui::BeginChild("##CursorUndoDebugChild", ImVec2(0, 300), true)) {
if (ImGui::BeginTable("##CursorUndoDebug", 2, ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) {
for (size_t row=0; row<MAX(cursorUndoHist.size(),cursorRedoHist.size()); ++row) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (row<cursorUndoHist.size()) DrawSpot(cursorUndoHist[cursorUndoHist.size()-row-1]);
ImGui::TableNextColumn();
if (row<cursorRedoHist.size()) DrawSpot(cursorRedoHist[cursorRedoHist.size()-row-1]);
}
ImGui::EndTable();
}
drawDebugUndoTable("##CursorUndoDebugChild", &cursorUndoHist, &cursorRedoHist);
ImGui::TreePop();
}
if (ImGui::TreeNode("Instrument Editor Undo Debug")) {
if (curIns>=0 && curIns<(int)e->song.ins.size()) {
DivInstrument* ins=e->song.ins[curIns];
drawDebugUndoTable("##InstrumentEditorUndoDebugChild", &ins->undoHist, &ins->redoHist);
}
ImGui::EndChild();
ImGui::TreePop();
}
if (ImGui::TreeNode("User Interface")) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/doAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ void FurnaceGUI::doAction(int what) {
e->song.ins[curIns]->esfm.op[i].outLvl=0;
}
}
insEditInitVZoomAndVScroll(e->song.ins[curIns]);
wantScrollListIns=true;
MARK_MODIFIED;
wavePreviewInit=true;
Expand Down Expand Up @@ -1630,6 +1631,7 @@ void FurnaceGUI::doAction(int what) {
e->song.ins[curIns]->name=sample->name;
e->song.ins[curIns]->amiga.initSample=curSample;
if (insType!=DIV_INS_AMIGA) e->song.ins[curIns]->amiga.useSample=true;
insEditInitVZoomAndVScroll(e->song.ins[curIns]);
nextWindow=GUI_WINDOW_INS_EDIT;
MARK_MODIFIED;
wavePreviewInit=true;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
int sampleCountBefore=e->song.sampleLen;
std::vector<DivInstrument*> instruments=e->instrumentFromFile(path,false);
if (!instruments.empty()) {
for (DivInstrument* i : instruments) insEditSanitizeVZoomAndVScroll(i);
if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP();
}
Expand Down Expand Up @@ -2410,6 +2411,7 @@ int FurnaceGUI::load(String path) {
return 1;
}
}
for (DivInstrument* i : e->song.ins) insEditSanitizeVZoomAndVScroll( i );
backupLock.lock();
curFileName=path;
backupLock.unlock();
Expand Down Expand Up @@ -3858,6 +3860,7 @@ bool FurnaceGUI::loop() {
DivWavetable* droppedWave=NULL;
//DivSample* droppedSample=NULL;
if (!instruments.empty()) {
for (DivInstrument* i : instruments) insEditSanitizeVZoomAndVScroll(i);
if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP();
}
Expand Down Expand Up @@ -5462,6 +5465,7 @@ bool FurnaceGUI::loop() {
int sampleCountBefore=e->song.sampleLen;
for (String i: fileDialog->getFileName()) {
std::vector<DivInstrument*> insTemp=e->instrumentFromFile(i.c_str(),true,settings.readInsNames);
for (DivInstrument* i : insTemp) insEditSanitizeVZoomAndVScroll(i);
if (insTemp.empty()) {
warn=true;
warns+=fmt::sprintf(_("> %s: cannot load instrument! (%s)\n"),i,e->getLastError());
Expand Down Expand Up @@ -5513,6 +5517,7 @@ bool FurnaceGUI::loop() {
int sampleCountBefore=e->song.sampleLen;
std::vector<DivInstrument*> instruments=e->instrumentFromFile(copyOfName.c_str(),true,settings.readInsNames);
if (!instruments.empty()) {
for (DivInstrument* i : instruments) insEditSanitizeVZoomAndVScroll(i);
if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP();
}
Expand Down Expand Up @@ -6539,6 +6544,7 @@ bool FurnaceGUI::loop() {
}
}

insEditInitVZoomAndVScroll(e->song.ins[curIns]);
MARK_MODIFIED;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,18 @@ class FurnaceGUI {
void decodeMMLStr(String& source, int* macro, unsigned char& macroLen, unsigned char& macroLoop, int macroMin, int macroMax, unsigned char& macroRel, bool bit30=false);
void decodeMMLStrW(String& source, int* macro, int& macroLen, int macroMin, int macroMax, bool hex=false);

int insEditGetOpCount(DivInstrument* ins);
void insEditBuildMacroListAll(DivInstrument* ins, std::vector<FurnaceGUIMacroDesc>& macroList);
void insEditBuildMacroListBase(DivInstrument* ins, std::vector<FurnaceGUIMacroDesc>& macroList);
void insEditBuildMacroListFMBase(DivInstrument* ins, std::vector<FurnaceGUIMacroDesc>& macroList);
void insEditBuildMacroListFMOP(DivInstrument* ins, std::vector<FurnaceGUIMacroDesc>& macroList, int op);
void insEditBuildMacroListTimer(DivInstrument* ins, std::vector<FurnaceGUIMacroDesc>& macroList);
void insEditInitVZoomAndVScroll(DivInstrument* ins);
void insEditResetFixedPitchMacroVZoom(DivInstrument* ins, int op);
void insEditSanitizeVZoomAndVScroll(DivInstrument* ins);
void insEditSanitizeVZoomAndVScroll(FurnaceGUIMacroDesc& i);
void insEditSanitizeVZoomAndVScroll(DivInstrument* ins, DivInstrumentMacro* macro);

String encodeKeyMap(std::map<int,int>& map);
void decodeKeyMap(std::map<int,int>& map, String source);

Expand Down
Loading