From 8772439d3eaf4e6b3871cfd3853bbcdbb5da77e5 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 6 Feb 2022 00:42:07 -0500 Subject: [PATCH] add ability to play by one row --- src/engine/engine.cpp | 25 +++++++++++++++++++++++-- src/engine/engine.h | 9 ++++++++- src/engine/playback.cpp | 3 ++- src/gui/gui.cpp | 20 +++++++++++++++++++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index d327e7f5..3a9d0807 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -4756,6 +4756,7 @@ void DivEngine::playSub(bool preserveDrift, int goalRow) { int goal=curOrder; curOrder=0; curRow=0; + stepPlay=0; int prevDrift; prevDrift=clockDrift; clockDrift=0; @@ -4815,8 +4816,12 @@ int DivEngine::calcFreq(int base, int pitch, bool period, int octave) { void DivEngine::play() { isBusy.lock(); - freelance=false; - playSub(false); + if (stepPlay==0) { + freelance=false; + playSub(false); + } else { + stepPlay=0; + } isBusy.unlock(); } @@ -4827,11 +4832,23 @@ void DivEngine::playToRow(int row) { isBusy.unlock(); } +void DivEngine::stepOne(int row) { + isBusy.lock(); + if (!isPlaying()) { + freelance=false; + playSub(false,row); + } + stepPlay=2; + ticks=1; + isBusy.unlock(); +} + void DivEngine::stop() { isBusy.lock(); freelance=false; playing=false; extValuePresent=false; + stepPlay=0; remainingLoops=-1; isBusy.unlock(); } @@ -5086,6 +5103,10 @@ bool DivEngine::isPlaying() { return (playing && !freelance); } +bool DivEngine::isStepping() { + return !(stepPlay==0); +} + bool DivEngine::isChannelMuted(int chan) { return isMuted[chan]; } diff --git a/src/engine/engine.h b/src/engine/engine.h index 6c4e146f..60efe630 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -150,7 +150,7 @@ class DivEngine { bool halted; bool forceMono; int ticks, curRow, curOrder, remainingLoops, nextSpeed, divider; - int cycles, clockDrift; + int cycles, clockDrift, stepPlay; int changeOrd, changePos, totalSeconds, totalTicks, totalTicksR, totalCmds, lastCmds, cmdsPerSecond, globalPitch; unsigned char extValue; unsigned char speed1, speed2; @@ -288,6 +288,9 @@ class DivEngine { // play to row void playToRow(int row); + // play by one row + void stepOne(int row); + // stop void stop(); @@ -406,6 +409,9 @@ class DivEngine { // is playing bool isPlaying(); + // is stepping + bool isStepping(); + // is exporting bool isExporting(); @@ -587,6 +593,7 @@ class DivEngine { divider(60), cycles(0), clockDrift(0), + stepPlay(0), changeOrd(-1), changePos(0), totalSeconds(0), diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 6bd38f2f..0232735a 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -844,7 +844,7 @@ bool DivEngine::nextTick(bool noAccum) { } if (!freelance) { - if (--ticks<=0) { + if (stepPlay!=1) if (--ticks<=0) { ret=endOfSong; if (endOfSong) { if (song.loopModality!=2) { @@ -852,6 +852,7 @@ bool DivEngine::nextTick(bool noAccum) { } } endOfSong=false; + if (stepPlay==2) stepPlay=1; nextRow(); } // process stuff diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index bf7d2e0c..e0e5710b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -645,6 +645,10 @@ void FurnaceGUI::drawEditControls() { if (ImGui::Checkbox("Repeat pattern",&repeatPattern)) { e->setRepeatPattern(repeatPattern); } + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_ARROW_DOWN "##StepOne")) { + e->stepOne(cursor.y); + } } if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_EDIT_CONTROLS; ImGui::End(); @@ -658,6 +662,10 @@ void FurnaceGUI::drawEditControls() { if (ImGui::Button(ICON_FA_PLAY "##Play")) { play(); } + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_ARROW_DOWN "##StepOne")) { + e->stepOne(cursor.y); + } ImGui::SameLine(); bool repeatPattern=e->getRepeatPattern(); @@ -722,6 +730,9 @@ void FurnaceGUI::drawEditControls() { if (ImGui::Button(ICON_FA_STOP "##Stop")) { stop(); } + if (ImGui::Button(ICON_FA_ARROW_DOWN "##StepOne")) { + e->stepOne(cursor.y); + } bool repeatPattern=e->getRepeatPattern(); ImGui::PushStyleColor(ImGuiCol_Button,ImVec4(0.2f,(repeatPattern)?0.6f:0.2f,0.2f,1.0f)); @@ -792,6 +803,10 @@ void FurnaceGUI::drawEditControls() { if (ImGui::Button(ICON_FA_PLAY_CIRCLE "##PlayAgain")) { play(); } + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_ARROW_DOWN "##StepOne")) { + e->stepOne(cursor.y); + } ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_Button,ImVec4(0.2f,(edit)?0.6f:0.2f,0.2f,1.0f)); @@ -4719,6 +4734,9 @@ void FurnaceGUI::keyDown(SDL_Event& ev) { doUndo(); } break; + case SDLK_RETURN: + e->stepOne(cursor.y); + break; } } else switch (ev.key.keysym.sym) { case SDLK_F5: @@ -4758,7 +4776,7 @@ void FurnaceGUI::keyDown(SDL_Event& ev) { } break; case SDLK_RETURN: - if (e->isPlaying()) { + if (e->isPlaying() && !e->isStepping()) { stop(); } else { if (ev.key.keysym.mod&KMOD_SHIFT) {