diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 6a726d4fe..797b94cdd 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -9121,7 +9121,8 @@ FurnaceGUI::FurnaceGUI(): romMultiFile(false), romExportSave(false), pendingExport(NULL), - romExportExists(false) { + romExportExists(false), + desBpm(150.0) { // value keys valueKeys[SDLK_0]=0; valueKeys[SDLK_1]=1; diff --git a/src/gui/gui.h b/src/gui/gui.h index 6aaaf741e..db558b4c5 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2835,6 +2835,8 @@ class FurnaceGUI { std::vector randomDemoSong; + double desBpm; + void commandExportOptions(); void drawExportAudio(bool onWindow=false); diff --git a/src/gui/speed.cpp b/src/gui/speed.cpp index 02e04481a..56d6871d3 100644 --- a/src/gui/speed.cpp +++ b/src/gui/speed.cpp @@ -21,6 +21,7 @@ #include "imgui.h" #include "misc/cpp/imgui_stdlib.h" #include "intConst.h" +#include "IconsFontAwesome4.h" void FurnaceGUI::drawSpeed(bool asChild) { if (nextWindow==GUI_WINDOW_SPEED) { @@ -49,7 +50,7 @@ void FurnaceGUI::drawSpeed(bool asChild) { } } ImGui::TableNextColumn(); - float avail=ImGui::GetContentRegionAvail().x; + float avail=ImGui::GetContentRegionAvail().x-ImGui::GetStyle().ItemSpacing.x*2-ImGui::GetFontSize(); float halfAvail=(avail-ImGui::GetStyle().ItemSpacing.x)*0.5; ImGui::SetNextItemWidth(halfAvail); float setHz=tempoView?e->curSubSong->hz*2.5:e->curSubSong->hz; @@ -161,6 +162,37 @@ void FurnaceGUI::drawSpeed(bool asChild) { } } } + ImGui::SameLine(); + ImGui::Button(ICON_FA_CALCULATOR "##grooveCalc"); + if (ImGui::BeginPopupContextItem("##grooveCalc", ImGuiPopupFlags_MouseButtonLeft)) { + ImGui::InputDouble("Desired BPM", &desBpm); + if (ImGui::Button("OK")) {; + e->lockEngine([this]() { + unsigned char* out=e->curSubSong->speeds.val; + memset(out, 0, 16*sizeof(char)); + double calcBpm=0, tickTrack=0; + int len=0; + while (len<16) { + if (fabs(desBpm-calcBpm)<2.2204460492503130808472633361816e-12) break; + double noteTime=(1.0/(desBpm/60.0))/e->curSubSong->hilightA; + double noteTick=noteTime*e->curSubSong->hz; + tickTrack+=noteTick; + int totalNum=0; + for (int i=0; icurSubSong->hz)*e->curSubSong->hilightA); + } + e->curSubSong->speeds.len=len; + }); + if (e->isPlaying()) play(); + MARK_MODIFIED; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + avail=ImGui::GetContentRegionAvail().x; + halfAvail=(avail-ImGui::GetStyle().ItemSpacing.x)*0.5; ImGui::TableNextRow(); ImGui::TableNextColumn();