From 0b673f841914e85b0ecef5af1cd1051c8fc112b0 Mon Sep 17 00:00:00 2001 From: yohannd1 Date: Tue, 20 Jan 2026 02:18:51 -0300 Subject: [PATCH] add "copy to new sample" action --- src/gui/doAction.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ src/gui/gui.h | 1 + src/gui/guiConst.cpp | 1 + src/gui/sampleEdit.cpp | 3 +++ 4 files changed, 54 insertions(+) diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 8f1bcb0b8..dcaeb7750 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1796,6 +1796,55 @@ void FurnaceGUI::doAction(int what) { } break; } + case GUI_ACTION_SAMPLE_MOVE_NEW: { + if (curSample<0 || curSample>=(int)e->song.sample.size()) break; + DivSample* sample=e->song.sample[curSample]; + SAMPLE_OP_BEGIN; + if (end-start<1) { + showError(_("select at least one sample!")); + break; + } + + curSample=e->addSample(); + if (curSample==-1) { + showError(_("too many samples!")); + break; + } + + DivSample* prevSample=sample; + e->lockEngine([this,prevSample,start,end]() { + DivSample* sample=e->getSample(curSample); + if (sample!=NULL) { + int length=end-start; + sample->centerRate=prevSample->centerRate; + sample->name=prevSample->name; + sample->loopStart=prevSample->loopStart; + sample->loopEnd=prevSample->loopEnd; + sample->loop=prevSample->loop; + sample->loopMode=prevSample->loopMode; + sample->brrEmphasis=prevSample->brrEmphasis; + sample->brrNoFilter=prevSample->brrNoFilter; + sample->dither=prevSample->dither; + sample->depth=prevSample->depth; + if (sample->init(length)) { + if (prevSample->getCurBuf()!=NULL) { + int offS=prevSample->getSampleOffset(start,0,sample->depth); + int offE=prevSample->getSampleOffset(end,0,sample->depth); + uint8_t *srcMem=(uint8_t*)prevSample->getCurBuf(); + memcpy(sample->getCurBuf(),&srcMem[offS],offE-offS); + } + } + } + e->renderSamples(); + }); + + // TODO: confirm these + wantScrollListSample=true; + MARK_MODIFIED; + updateSampleTex=true; + notifySampleChange=true; + break; + } case GUI_ACTION_ORDERS_UP: if (curOrder>0) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 6045e8bc2..d87041354 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -962,6 +962,7 @@ enum FurnaceGUIActions { GUI_ACTION_SAMPLE_MAKE_INS, GUI_ACTION_SAMPLE_SET_LOOP, GUI_ACTION_SAMPLE_CREATE_WAVE, + GUI_ACTION_SAMPLE_COPY_NEW, GUI_ACTION_SAMPLE_MAX, GUI_ACTION_ORDERS_MIN, diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index e797eba2a..78391c3ca 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -845,6 +845,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("SAMPLE_MAKE_INS", _N("Sample editor: Create instrument from sample"), 0), D("SAMPLE_SET_LOOP", _N("Sample editor: Set loop to selection"), FURKMOD_CMD|SDLK_l), D("SAMPLE_CREATE_WAVE", _N("Sample editor: Create wavetable from selection"), FURKMOD_CMD|SDLK_w), + D("SAMPLE_COPY_NEW", _N("Sample editor: Copy selection to new sample"), 0), D("SAMPLE_MAX", "", NOT_AN_ACTION), D("ORDERS_MIN", _N("---Orders"), NOT_AN_ACTION), diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 345c3ab77..747a400ec 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -2013,6 +2013,9 @@ void FurnaceGUI::drawSampleEdit() { if (ImGui::MenuItem(_("create wavetable from selection"),BIND_FOR(GUI_ACTION_SAMPLE_CREATE_WAVE))) { doAction(GUI_ACTION_SAMPLE_CREATE_WAVE); } + if (ImGui::MenuItem(_("copy selection to new sample"),BIND_FOR(GUI_ACTION_SAMPLE_MOVE_NEW))) { + doAction(GUI_ACTION_SAMPLE_MOVE_NEW); + } ImGui::EndPopup(); }