From dae7a9a0997e2f4400b53b8419744d772a5dee42 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 12 Apr 2022 03:00:57 -0500 Subject: [PATCH] GUI: add "Create instrument from sample" option --- src/gui/doAction.cpp | 11 +++++++++++ src/gui/gui.h | 1 + src/gui/guiConst.cpp | 1 + src/gui/sampleEdit.cpp | 15 ++++++++++++++- src/gui/settings.cpp | 1 + 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 26fbd39f..0fb6b062 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1083,6 +1083,17 @@ void FurnaceGUI::doAction(int what) { updateSampleTex=true; } break; + case GUI_ACTION_SAMPLE_MAKE_INS: { + if (curSample<0 || curSample>=(int)e->song.sample.size()) break; + DivSample* sample=e->song.sample[curSample]; + curIns=e->addInstrument(cursor.xCoarse); + e->song.ins[curIns]->type=DIV_INS_AMIGA; + e->song.ins[curIns]->name=sample->name; + e->song.ins[curIns]->amiga.initSample=curSample; + nextWindow=GUI_WINDOW_INS_EDIT; + MARK_MODIFIED; + break; + } case GUI_ACTION_ORDERS_UP: if (e->getOrder()>0) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 6c1b984c..73fc4d87 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -436,6 +436,7 @@ enum FurnaceGUIActions { GUI_ACTION_SAMPLE_ZOOM_IN, GUI_ACTION_SAMPLE_ZOOM_OUT, GUI_ACTION_SAMPLE_ZOOM_AUTO, + GUI_ACTION_SAMPLE_MAKE_INS, GUI_ACTION_SAMPLE_MAX, GUI_ACTION_ORDERS_MIN, diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index bc5345aa..e826f8cc 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -327,6 +327,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("SAMPLE_ZOOM_IN", "Zoom in", FURKMOD_CMD|SDLK_EQUALS), D("SAMPLE_ZOOM_OUT", "Zoom out", FURKMOD_CMD|SDLK_MINUS), D("SAMPLE_ZOOM_AUTO", "Toggle auto-zoom", FURKMOD_CMD|SDLK_0), + D("SAMPLE_MAKE_INS", "Create instrument from sample", 0), D("SAMPLE_MAX", "", NOT_AN_ACTION), D("ORDERS_MIN", "---Orders", NOT_AN_ACTION), diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 07aeef8a..a84c852f 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -29,7 +29,6 @@ #include "util.h" // TODO: -// - add "create instrument using this sample" option // - .dmc loading void FurnaceGUI::drawSampleEdit() { if (nextWindow==GUI_WINDOW_SAMPLE_EDIT) { @@ -528,6 +527,13 @@ void FurnaceGUI::drawSampleEdit() { if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Stop sample preview"); } + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UPLOAD "##MakeIns")) { + doAction(GUI_ACTION_SAMPLE_MAKE_INS); + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Create instrument from sample"); + } ImGui::SameLine(); double zoomPercent=100.0/sampleZoom; @@ -1040,6 +1046,13 @@ void FurnaceGUI::drawSampleEdit() { ImGui::SetTooltip("Stop sample preview"); } ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UPLOAD "##MakeIns")) { + doAction(GUI_ACTION_SAMPLE_MAKE_INS); + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Create instrument from sample"); + } + ImGui::SameLine(); double zoomPercent=100.0/sampleZoom; ImGui::Text("Zoom"); ImGui::SameLine(); diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index ad122058..8bb7addd 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1427,6 +1427,7 @@ void FurnaceGUI::drawSettings() { UI_KEYBIND_CONFIG(GUI_ACTION_SAMPLE_ZOOM_IN); UI_KEYBIND_CONFIG(GUI_ACTION_SAMPLE_ZOOM_OUT); UI_KEYBIND_CONFIG(GUI_ACTION_SAMPLE_ZOOM_AUTO); + UI_KEYBIND_CONFIG(GUI_ACTION_SAMPLE_MAKE_INS); KEYBIND_CONFIG_END; ImGui::TreePop();