diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index 93e3ece6..bd34daa5 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -323,6 +323,7 @@ bool DivSample::insert(unsigned int pos, unsigned int length) { #define RESAMPLE_END \ if (loopStart>=0) loopStart=(double)loopStart*(r/(double)rate); \ + centerRate=(int)((double)centerRate*(r/(double)rate)); \ rate=r; \ samples=finalCount; \ if (depth==16) { \ diff --git a/src/gui/dataList.cpp b/src/gui/dataList.cpp index 9557cc57..8a02c40e 100644 --- a/src/gui/dataList.cpp +++ b/src/gui/dataList.cpp @@ -290,6 +290,10 @@ void FurnaceGUI::drawSampleList() { doAction(GUI_ACTION_SAMPLE_LIST_ADD); } ImGui::SameLine(); + if (ImGui::Button(ICON_FA_FILES_O "##SampleClone")) { + doAction(GUI_ACTION_SAMPLE_LIST_DUPLICATE); + } + ImGui::SameLine(); if (ImGui::Button(ICON_FA_FOLDER_OPEN "##SampleLoad")) { doAction(GUI_ACTION_SAMPLE_LIST_OPEN); } diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index a1b974e3..26fbd39f 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -567,6 +567,29 @@ void FurnaceGUI::doAction(int what) { curSample=e->addSample(); MARK_MODIFIED; break; + case GUI_ACTION_SAMPLE_LIST_DUPLICATE: + if (curSample>=0 && curSample<(int)e->song.sample.size()) { + DivSample* prevSample=e->getSample(curSample); + curSample=e->addSample(); + e->lockEngine([this,prevSample]() { + DivSample* sample=e->getSample(curSample); + if (sample!=NULL) { + sample->rate=prevSample->rate; + sample->centerRate=prevSample->centerRate; + sample->name=prevSample->name; + sample->loopStart=prevSample->loopStart; + sample->depth=prevSample->depth; + if (sample->init(prevSample->samples)) { + if (prevSample->getCurBuf()!=NULL) { + memcpy(sample->getCurBuf(),prevSample->getCurBuf(),prevSample->getCurBufLen()); + } + } + } + e->renderSamples(); + }); + MARK_MODIFIED; + } + break; case GUI_ACTION_SAMPLE_LIST_OPEN: openFileDialog(GUI_FILE_SAMPLE_OPEN); break; diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 34cb23d5..4ff8761e 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -29,11 +29,9 @@ #include "util.h" // TODO: -// - resample should change C-4 note // - clicking on waveform should give this window focus // - add "create instrument using this sample" option // - .dmc loading -// - duplicate sample void FurnaceGUI::drawSampleEdit() { if (nextWindow==GUI_WINDOW_SAMPLE_EDIT) { sampleEditOpen=true;