GUI: implement clear

This commit is contained in:
tildearrow 2022-04-24 17:39:18 -05:00
parent e414056f2d
commit 521b311692
3 changed files with 96 additions and 1 deletions

View file

@ -19,21 +19,57 @@
#include "song.h" #include "song.h"
void DivSong::clearSongData() {
for (int i=0; i<DIV_MAX_CHANS; i++) {
pat[i].wipePatterns();
}
memset(orders.ord,0,DIV_MAX_CHANS*256);
ordersLen=1;
}
void DivSong::clearInstruments() {
for (DivInstrument* i: ins) {
delete i;
}
ins.clear();
insLen=0;
}
void DivSong::clearWavetables() {
for (DivWavetable* i: wave) {
delete i;
}
wave.clear();
waveLen=0;
}
void DivSong::clearSamples() {
for (DivSample* i: sample) {
delete i;
}
sample.clear();
sampleLen=0;
}
void DivSong::unload() { void DivSong::unload() {
for (DivInstrument* i: ins) { for (DivInstrument* i: ins) {
delete i; delete i;
} }
ins.clear(); ins.clear();
insLen=0;
for (DivWavetable* i: wave) { for (DivWavetable* i: wave) {
delete i; delete i;
} }
wave.clear(); wave.clear();
waveLen=0;
for (DivSample* i: sample) { for (DivSample* i: sample) {
delete i; delete i;
} }
sample.clear(); sample.clear();
sampleLen=0;
for (int i=0; i<DIV_MAX_CHANS; i++) { for (int i=0; i<DIV_MAX_CHANS; i++) {
pat[i].wipePatterns(); pat[i].wipePatterns();

View file

@ -339,6 +339,27 @@ struct DivSong {
DivWavetable nullWave; DivWavetable nullWave;
DivSample nullSample; DivSample nullSample;
/**
* clear orders and patterns.
*/
void clearSongData();
/**
* clear instruments.
*/
void clearInstruments();
/**
* clear wavetables.
*/
void clearWavetables();
/**
* clear samples.
*/
void clearSamples();
/** /**
* unloads the song, freeing all memory associated with it. * unloads the song, freeing all memory associated with it.
* use before destroying the object. * use before destroying the object.

View file

@ -3374,26 +3374,64 @@ bool FurnaceGUI::loop() {
break; break;
case GUI_WARN_CLEAR: case GUI_WARN_CLEAR:
if (ImGui::Button("Song (orders and patterns)")) { if (ImGui::Button("Song (orders and patterns)")) {
stop();
e->lockEngine([this]() {
e->song.clearSongData();
});
e->setOrder(0);
curOrder=0;
oldOrder=0;
oldOrder1=0;
MARK_MODIFIED;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Pattern")) { if (ImGui::Button("Pattern")) {
stop();
e->lockEngine([this]() {
for (int i=0; i<e->getTotalChannelCount(); i++) {
DivPattern* pat=e->song.pat[i].getPattern(e->song.orders.ord[i][curOrder],true);
memset(pat->data,-1,256*32*sizeof(short));
for (int j=0; j<256; j++) {
pat->data[j][0]=0;
pat->data[j][1]=0;
}
}
});
MARK_MODIFIED;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Instruments")) { if (ImGui::Button("Instruments")) {
stop();
e->lockEngine([this]() {
e->song.clearInstruments();
});
curIns=-1;
MARK_MODIFIED;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Wavetables")) { if (ImGui::Button("Wavetables")) {
stop();
e->lockEngine([this]() {
e->song.clearWavetables();
});
curWave=0;
MARK_MODIFIED;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Samples")) { if (ImGui::Button("Samples")) {
stop();
e->lockEngine([this]() {
e->song.clearSamples();
});
curSample=0;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
if (ImGui::Button("Wait! What am I doing?")) { if (ImGui::Button("Wait! What am I doing? Cancel!")) {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
break; break;