Skip to content

Commit

Permalink
create sample from wavetable action
Browse files Browse the repository at this point in the history
  • Loading branch information
Eknous-P committed Dec 8, 2024
1 parent 3289f66 commit 57f38bc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/gui/doAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,38 @@ void FurnaceGUI::doAction(int what) {
case GUI_ACTION_WAVE_LIST_SAVE_RAW:
if (curWave>=0 && curWave<(int)e->song.wave.size()) openFileDialog(GUI_FILE_WAVE_SAVE_RAW);
break;
case GUI_ACTION_WAVE_LIST_CREATE_SAMPLE:
if (curWave>=0 && curWave<(int)e->song.wave.size()) {
DivSample* prevSample=e->getSample(curSample);
curSample=e->addSample();
if (curSample==-1) {
showError(_("too many samples!"));
} else {
e->lockEngine([this,prevSample]() {
DivSample* sample=e->getSample(curSample);
if (sample!=NULL) {
unsigned int waveLen=e->song.wave[curWave]->len;
sample->rate=(int)round(261.343f*waveLen); // c3
sample->centerRate=(int)round(261.343f*waveLen); // c3
sample->loopStart=0;
sample->loopEnd=waveLen;
sample->loop=true;
sample->loopMode=(DivSampleLoopMode)0;
sample->depth=(DivSampleDepth)8;
if (sample->init(waveLen)) {
for (unsigned short i=0; i<waveLen; i++) {
sample->data8[i]=e->song.wave[curWave]->data[i]-waveLen/2;
}
}
}
e->renderSamples();
});
wantScrollListSample=true;
MARK_MODIFIED;
}
updateSampleTex=true;
}
break;
case GUI_ACTION_WAVE_LIST_MOVE_UP:
if (e->moveWaveUp(curWave)) {
curWave--;
Expand Down
1 change: 1 addition & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ enum FurnaceGUIActions {
GUI_ACTION_WAVE_LIST_SAVE,
GUI_ACTION_WAVE_LIST_SAVE_DMW,
GUI_ACTION_WAVE_LIST_SAVE_RAW,
GUI_ACTION_WAVE_LIST_CREATE_SAMPLE,
GUI_ACTION_WAVE_LIST_MOVE_UP,
GUI_ACTION_WAVE_LIST_MOVE_DOWN,
GUI_ACTION_WAVE_LIST_DELETE,
Expand Down
1 change: 1 addition & 0 deletions src/gui/guiConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={
D("WAVE_LIST_SAVE", _N("Save wavetable"), 0),
D("WAVE_LIST_SAVE_DMW", _N("Save wavetable (.dmw)"), 0),
D("WAVE_LIST_SAVE_RAW", _N("Save wavetable (raw)"), 0),
D("WAVE_LIST_CREATE_SAMPLE", _N("Create sample from wavetable"),0),
D("WAVE_LIST_MOVE_UP", _N("Move wavetable up in list"), FURKMOD_SHIFT|SDLK_UP),
D("WAVE_LIST_MOVE_DOWN", _N("Move wavetable down in list"), FURKMOD_SHIFT|SDLK_DOWN),
D("WAVE_LIST_DELETE", _N("Delete wavetable"), 0),
Expand Down
7 changes: 7 additions & 0 deletions src/gui/waveEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ void FurnaceGUI::drawWaveEdit() {
ImGui::EndPopup();
}
ImGui::SameLine();
if (ImGui::Button(ICON_FA_UPLOAD)) {
doAction(GUI_ACTION_WAVE_LIST_CREATE_SAMPLE);
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(_("create sample from wavetable"));
}
ImGui::SameLine();

if (ImGui::RadioButton(_("Steps"),waveEditStyle==0)) {
waveEditStyle=0;
Expand Down

0 comments on commit 57f38bc

Please sign in to comment.