diff --git a/TODO.md b/TODO.md index 1c6e9a7b..5657f97f 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index b2066205..f086d19c 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -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(); diff --git a/src/engine/engine.h b/src/engine/engine.h index 1ad8eb2e..78a56178 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -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(); diff --git a/src/gui/subSongs.cpp b/src/gui/subSongs.cpp index 2b6030cb..b13b8420 100644 --- a/src/gui/subSongs.cpp +++ b/src/gui/subSongs.cpp @@ -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; isong.subsong.size(); i++) { - if (e->song.subsong[i]->name.empty()) { - snprintf(id,1023,"%d. ",(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; isong.subsong.size(); i++) { + if (e->song.subsong[i]->name.empty()) { + snprintf(id,1023,"%d. ",(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(); }