Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,11 @@ void setSong(Song *newsong)
updateSampleList(song->getInstrument(0));

inst = song->getInstrument(0);
if(inst != 0)
handleSampleChange(0);
handleSampleChange(0);


volEnvSetInst(song->getInstrument(0));

inst = song->getInstrument(0);
if(inst != 0)
{
cbvolenvenabled->setChecked(inst->getVolEnvEnabled());
Expand Down Expand Up @@ -1715,6 +1714,14 @@ void handleRestartPosChange(s32 restartpos)
DC_FlushAll();
}

void confirmZap(void (*onConfirm)(void))
{
deleteMessageBox();
mb = new MessageBox(&sub_vram, "are you sure", 2, "yes", onConfirm, "cancel", deleteMessageBox);
gui->registerOverlayWidget(mb, 0, SUB_SCREEN);
mb->reveal();
}

void zapPatterns(void)
{
song->zapPatterns();
Expand Down Expand Up @@ -1742,6 +1749,47 @@ void zapPatterns(void)
updateMemoryState(true);
}

void zapUnusedInstruments(void) {
bool used_insts[MAX_INSTRUMENTS] = { false };

song->zapUnusedInstruments(used_insts);

for (int i = 0; i < MAX_INSTRUMENTS; i++) {
if (used_insts[i]) continue;

lbinstruments->set(i, "");
if (lbinstruments->getidx() == i) {
sampledisplay->setSample(NULL);
handleSampleChange(0);
for(u8 i=0;i<MAX_INSTRUMENT_SAMPLES;++i) {
lbsamples->set(i, "");
}
}
}

DC_FlushAll();
deleteMessageBox();
CommandSetSong(song);
updateMemoryState(true);
}

void zapCurrentInstrument(void) {
PrintFreeMem();
u8 inst = lbinstruments->getidx();
song->zapInstrument(inst);
sampledisplay->setSample(NULL);
handleSampleChange(0);
DC_FlushAll();
deleteMessageBox();

lbinstruments->set(inst, "");
for(u8 i=0;i<MAX_INSTRUMENT_SAMPLES;++i) {
lbsamples->set(i, "");
}
CommandSetSong(song);
updateMemoryState(true);
}

void zapInstruments(void)
{
song->zapInstruments();
Expand All @@ -1766,19 +1814,45 @@ void zapInstruments(void)
setHasUnsavedChanges(true);
}


void zapSong(void) {
deleteMessageBox();
delete song;
setSong(new Song());
updateMemoryState(true);
}

void confirmZapSong(void)
{
confirmZap(zapSong);
}

void confirmZapInsts(void)
{
confirmZap(zapInstruments);
}

void confirmZapPatterns(void)
{
confirmZap(zapPatterns);
}

void zapInstrumentsChoice(void)
{
deleteMessageBox();
mb = new MessageBox(&sub_vram, "which instruments", 4, "selected", zapCurrentInstrument, "unused", zapUnusedInstruments,
" all ", confirmZapInsts, "cancel",
deleteMessageBox);
gui->registerOverlayWidget(mb, 0, SUB_SCREEN);
mb->reveal();
}

void handleZap(void)
{
stopPlay(); // Safety first

mb = new MessageBox(&sub_vram, "what to zap", 4, "patterns", zapPatterns,
"instruments", zapInstruments, "song", zapSong, "cancel",
mb = new MessageBox(&sub_vram, "what to zap", 4, "patterns", confirmZapPatterns,
"instruments", zapInstrumentsChoice, "song", confirmZapSong, "cancel",
deleteMessageBox);
gui->registerOverlayWidget(mb, 0, SUB_SCREEN);
mb->reveal();
Expand Down Expand Up @@ -4249,4 +4323,4 @@ int main(int argc, char **argv) {
if (launch_path) ntxm_free(launch_path);

return 0;
}
}
Loading