add ability to move sub-songs

This commit is contained in:
tildearrow 2022-06-01 18:50:30 -05:00
parent 2da92b0433
commit ddcd76328d
4 changed files with 77 additions and 19 deletions

View file

@ -10,7 +10,6 @@
- add another FM editor layout
- if macros have release, note off should release them
- add ability to move selection by dragging
- add ability to move subsongs
- find and replace
- add mono/poly note preview button
- (maybe) add default patch selection

View file

@ -827,6 +827,44 @@ bool DivEngine::removeSubSong(int index) {
return true;
}
void DivEngine::moveSubSongUp(size_t index) {
if (index<1 || index>=song.subsong.size()) return;
BUSY_BEGIN;
saveLock.lock();
if (index==curSubSongIndex) {
curSubSongIndex--;
} else if (index-1==curSubSongIndex) {
curSubSongIndex++;
}
DivSubSong* prev=song.subsong[index-1];
song.subsong[index-1]=song.subsong[index];
song.subsong[index]=prev;
saveLock.unlock();
BUSY_END;
}
void DivEngine::moveSubSongDown(size_t index) {
if (index>=song.subsong.size()-1) return;
BUSY_BEGIN;
saveLock.lock();
if (index==curSubSongIndex) {
curSubSongIndex++;
} else if (index+1==curSubSongIndex) {
curSubSongIndex--;
}
DivSubSong* prev=song.subsong[index+1];
song.subsong[index+1]=song.subsong[index];
song.subsong[index]=prev;
saveLock.unlock();
BUSY_END;
}
void DivEngine::clearSubSongs() {
BUSY_BEGIN;
saveLock.lock();

View file

@ -825,6 +825,10 @@ class DivEngine {
// remove subsong
bool removeSubSong(int index);
// move subsong
void moveSubSongUp(size_t index);
void moveSubSongDown(size_t index);
// clear all subsong data
void clearSubSongs();

View file

@ -20,25 +20,42 @@ void FurnaceGUI::drawSubSongs() {
snprintf(id,1023,"%d. %s",(int)e->getCurrentSubSong()+1,e->curSubSong->name.c_str());
}
if (ImGui::BeginCombo("##SubSong",id)) {
for (size_t i=0; i<e->song.subsong.size(); i++) {
if (e->song.subsong[i]->name.empty()) {
snprintf(id,1023,"%d. <no name>",(int)i+1);
} else {
snprintf(id,1023,"%d. %s",(int)i+1,e->song.subsong[i]->name.c_str());
}
if (ImGui::Selectable(id,i==e->getCurrentSubSong())) {
e->changeSongP(i);
updateScroll(0);
oldOrder=0;
oldOrder1=0;
oldRow=0;
cursor.xCoarse=0;
cursor.xFine=0;
cursor.y=0;
selStart=cursor;
selEnd=cursor;
curOrder=0;
if (ImGui::BeginTable("SubSongSelection",2)) {
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed);
for (size_t i=0; i<e->song.subsong.size(); i++) {
if (e->song.subsong[i]->name.empty()) {
snprintf(id,1023,"%d. <no name>",(int)i+1);
} else {
snprintf(id,1023,"%d. %s",(int)i+1,e->song.subsong[i]->name.c_str());
}
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::Selectable(id,i==e->getCurrentSubSong())) {
e->changeSongP(i);
updateScroll(0);
oldOrder=0;
oldOrder1=0;
oldRow=0;
cursor.xCoarse=0;
cursor.xFine=0;
cursor.y=0;
selStart=cursor;
selEnd=cursor;
curOrder=0;
}
ImGui::TableNextColumn();
ImGui::PushID(i);
if (ImGui::SmallButton(ICON_FA_ARROW_UP "##SubUp")) {
e->moveSubSongUp(i);
}
ImGui::SameLine();
if (ImGui::SmallButton(ICON_FA_ARROW_DOWN "##SubDown")) {
e->moveSubSongDown(i);
}
ImGui::PopID();
}
ImGui::EndTable();
}
ImGui::EndCombo();
}