From f27802e41b817841ca99ec8f421f240ad0a67914 Mon Sep 17 00:00:00 2001 From: Viper Date: Sun, 22 Dec 2024 22:30:25 +0000 Subject: [PATCH 1/4] Fix lag --- src/jsonReader/Json.hpp | 2 ++ src/main.cpp | 62 +++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/jsonReader/Json.hpp b/src/jsonReader/Json.hpp index 162da54..3275edf 100644 --- a/src/jsonReader/Json.hpp +++ b/src/jsonReader/Json.hpp @@ -25,6 +25,7 @@ class JsonReader { bool hassomedata = false; void loadData() { + std::thread([=] { auto configDir = Mod::get()->getConfigDir(); auto clicksPath = configDir / "Clicks" / "clicks-main"; if (std::filesystem::exists(clicksPath)) { @@ -35,6 +36,7 @@ class JsonReader { } else { //log::error("Unable to load Categories"); } + }).detach(); } void loadCategoryData(const std::filesystem::path& categoryDir, std::map& categoryData) { diff --git a/src/main.cpp b/src/main.cpp index d7754a5..ebc3834 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,46 +168,48 @@ class $modify(PlayerObject) { } }; -EventListener m_listener; class $modify(MenuLayer) { void SendRequestAPI() { - m_listener.bind([] (web::WebTask::Event* e) { - if (web::WebResponse* res = e->getValue()) { - if (res->string().unwrapOr("failed") == "failed") { - indexzip.Failed = true; - indexzip.Finished = true; - return; - } - if (res->into(Mod::get()->getConfigDir() / "Clicks.zip")) { - auto unzip = file::Unzip::create(Mod::get()->getConfigDir() / "Clicks.zip"); - if (!unzip) { + std::thread([=] { + web::WebRequest().get("https://github.com/clicksounds/clicks/archive/refs/heads/main.zip").listen([=](auto res) { + if (res->string().unwrapOr("failed") == "failed") { indexzip.Failed = true; indexzip.Finished = true; return; } - std::filesystem::remove_all(Mod::get()->getConfigDir() / "Clicks"); - (void) unzip.unwrap().extractAllTo(Mod::get()->getConfigDir() / "Clicks"); + if (res->into(Mod::get()->getConfigDir() / "Clicks.zip")) { + auto unzip = file::Unzip::create(Mod::get()->getConfigDir() / "Clicks.zip"); + if (!unzip) { + indexzip.Failed = true; + indexzip.Finished = true; + return; + } + std::filesystem::remove_all(Mod::get()->getConfigDir() / "Clicks"); + (void) unzip.unwrap().extractAllTo(Mod::get()->getConfigDir() / "Clicks"); + indexzip.Finished = true; + ClickJson->loadData(); + onsettingsUpdate(); + } + }, + [](auto prog){}, + [=]() { + indexzip.Failed = true; indexzip.Finished = true; - ClickJson->loadData(); - onsettingsUpdate(); - } - } else if (e->isCancelled()) { - indexzip.Failed = true; - indexzip.Finished = true; - } - }); - m_listener.setFilter(web::WebRequest().get("https://github.com/clicksounds/clicks/archive/refs/heads/main.zip")); + }); + }).detach(); } - bool init() { + bool init() { if (!indexzip.StartedDownloading) { indexzip.StartedDownloading = true; - std::thread([=] { - // on boot set Sound Caches - ClickJson->loadData(); - onsettingsUpdate(); - this->SendRequestAPI(); - }).detach(); - } + geode::Loader::get()->queueInMainThread([=] { + std::thread([=] { + // on boot set Sound Caches + ClickJson->loadData(); + onsettingsUpdate(); + this->SendRequestAPI(); + }).detach(); + }); + } return MenuLayer::init(); } }; From abec98e4d52b620204512087f1fba244e8a2180c Mon Sep 17 00:00:00 2001 From: Viper Date: Mon, 23 Dec 2024 23:53:11 +0000 Subject: [PATCH 2/4] add pitch shifter (clicksounds lite was going to have it first and i am not letting that slide) --- mod.json | 11 +++++ src/StaticClasses.hpp | 99 ++++++++++++++++++++++++++----------------- 2 files changed, 70 insertions(+), 40 deletions(-) diff --git a/mod.json b/mod.json index d4f1356..5d24dd6 100644 --- a/mod.json +++ b/mod.json @@ -137,6 +137,17 @@ "description": "When enabled, a settings button appears in the pause menu.", "type": "bool", "default": true + }, + "sfx-semitone": { + "name": "Pitch of the sounds", + "description": "Determines the pitch of click/release sounds using semitone. The Default semitones is set 1 (2 semitones = 1 Octave)", + "type": "int", + "default": 1, + "min": -6, + "max": 6, + "control": { + "slider": true + } } } } diff --git a/src/StaticClasses.hpp b/src/StaticClasses.hpp index be95c04..010f1fe 100644 --- a/src/StaticClasses.hpp +++ b/src/StaticClasses.hpp @@ -12,56 +12,75 @@ struct downloadedzipStruc { }; static downloadedzipStruc indexzip; - +FMOD::ChannelGroup* CS_Group; +FMOD::DSP* pitchShifterDSP; using namespace geode::prelude; // Custom class for Caching sounds (Make it less laggy for mobile platforms and such) class SoundCache { - public: - std::string m_soundFile = ""; - FMOD::Sound* m_sound; - std::string Volume; - std::string custom; - FMOD::Channel* Soundchannel; - - SoundCache(std::string x,std::string x2) { - Volume = x; - custom = x2; - }; - void Setsound(std::string soundFile) { - if (soundFile.c_str()) { - if (FMODAudioEngine::sharedEngine()->m_system->createSound(soundFile.c_str(), FMOD_DEFAULT, nullptr, &m_sound) == FMOD_OK) { - m_sound->setMode(FMOD_LOOP_OFF); - m_soundFile = soundFile; - } - } +public: + std::string m_soundFile = ""; + FMOD::Sound* m_sound; + std::string Volume; + std::string custom; + FMOD::Channel* Soundchannel; + + SoundCache(std::string x, std::string x2) : Volume(x), custom(x2), Soundchannel(nullptr) { + if (!CS_Group) { + FMODAudioEngine::sharedEngine()->m_system->createChannelGroup("CS_Group", &CS_Group); } - void Play(bool TestButton = false) { - std::string Paths = GetSettingJsonRead(custom).Custom_Sound_Path; - if (m_soundFile != Paths) { - Setsound(Paths); - } - if (!m_sound) { - return; - } - PlayModded(TestButton); - }; - void PlayModded(bool TestButton = false) { - float GetVolume = Mod::get()->getSettingValue(Volume); - if (GetVolume <= 0) { - GetVolume = 1; - } - FMODAudioEngine::sharedEngine()->m_system->playSound(m_sound, nullptr, false, &Soundchannel); - Soundchannel->setVolume(GetVolume / 50.f); + + if (!pitchShifterDSP) { + FMODAudioEngine::sharedEngine()->m_system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &pitchShifterDSP); + CS_Group->addDSP(0, pitchShifterDSP); } + } - ~SoundCache() { - if (m_sound) { - m_sound->release(); + void Setsound(std::string soundFile) { + if (soundFile.c_str()) { + if (FMODAudioEngine::sharedEngine()->m_system->createSound(soundFile.c_str(), FMOD_DEFAULT, nullptr, &m_sound) == FMOD_OK) { + m_sound->setMode(FMOD_LOOP_OFF); + m_soundFile = soundFile; } - }; + } + } + void Play(bool TestButton = false) { + std::string Paths = GetSettingJsonRead(custom).Custom_Sound_Path; + if (m_soundFile != Paths) { + Setsound(Paths); + } + if (!m_sound) { + return; + } + PlayModded(TestButton); + } + + void PlayModded(bool TestButton = false) { + float GetVolume = Mod::get()->getSettingValue(Volume); + if (GetVolume <= 0 && TestButton == true) { + GetVolume = 1; + } + FMODAudioEngine::sharedEngine()->m_system->playSound(m_sound, CS_Group, false, &Soundchannel); + Soundchannel->setVolume(GetVolume / 50.f); + double semitone = static_cast(Mod::get()->getSettingValue("sfx-semitone")) / 2; + if (semitone < 0) { + semitone = std::pow(2,semitone); // fix negtive octave + } else { + + semitone+=1; + } + pitchShifterDSP->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, semitone); // semitone is half a octave + FMODAudioEngine::sharedEngine()->m_system->update(); + } + + ~SoundCache() { + if (m_sound) { + m_sound->release(); + } + } }; + class MultiSoundCache { public: std::vector m_sounds; From 567c1c6b76f0f5eb504f5b754f2915c194f68aa6 Mon Sep 17 00:00:00 2001 From: Viper Date: Mon, 23 Dec 2024 23:59:00 +0000 Subject: [PATCH 3/4] oops default is 0 --- mod.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod.json b/mod.json index 5d24dd6..8993bc2 100644 --- a/mod.json +++ b/mod.json @@ -140,9 +140,9 @@ }, "sfx-semitone": { "name": "Pitch of the sounds", - "description": "Determines the pitch of click/release sounds using semitone. The Default semitones is set 1 (2 semitones = 1 Octave)", + "description": "Determines the pitch of click/release sounds using semitone. The Default semitones is set 0 (2 semitones = 1 Octave)", "type": "int", - "default": 1, + "default": 0, "min": -6, "max": 6, "control": { From b66bb7c8395ad6d036bd59f00038ea7d21685aad Mon Sep 17 00:00:00 2001 From: Viper Date: Tue, 24 Dec 2024 00:09:18 +0000 Subject: [PATCH 4/4] fix something --- mod.json | 2 +- src/StaticClasses.hpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/mod.json b/mod.json index 8993bc2..22fdbf0 100644 --- a/mod.json +++ b/mod.json @@ -140,7 +140,7 @@ }, "sfx-semitone": { "name": "Pitch of the sounds", - "description": "Determines the pitch of click/release sounds using semitone. The Default semitones is set 0 (2 semitones = 1 Octave)", + "description": "Determines the pitch of click/release sounds using semitones. The Default semitones is set 0 (2 semitones = 1 Octave)", "type": "int", "default": 0, "min": -6, diff --git a/src/StaticClasses.hpp b/src/StaticClasses.hpp index 010f1fe..68fcd5c 100644 --- a/src/StaticClasses.hpp +++ b/src/StaticClasses.hpp @@ -66,11 +66,9 @@ class SoundCache { if (semitone < 0) { semitone = std::pow(2,semitone); // fix negtive octave } else { - semitone+=1; } pitchShifterDSP->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, semitone); // semitone is half a octave - FMODAudioEngine::sharedEngine()->m_system->update(); } ~SoundCache() {