Skip to content

Commit 4134eeb

Browse files
committed
mass refactor--fix constant shuffle mode
1 parent 79ea246 commit 4134eeb

File tree

9 files changed

+54
-114
lines changed

9 files changed

+54
-114
lines changed

src/EditorPauseLayer.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@
55
using namespace geode::prelude;
66

77
class $modify(MenuLoopEPLHook, EditorPauseLayer) {
8-
struct Fields {
9-
SongManager &songManager = SongManager::get();
10-
};
118
#ifndef __APPLE__
129
void onExitEditor(CCObject *sender) {
13-
if (Utils::getBool("randomizeWhenExitingEditor"))
14-
m_fields->songManager.pickRandomSong();
10+
if (Utils::getBool("randomizeWhenExitingEditor")) SongManager::get().pickRandomSong();
1511

1612
EditorPauseLayer::onExitEditor(sender);
1713

1814
Utils::removeCardRemotely();
1915

20-
if (Utils::getBool("playlistMode")) {
21-
Utils::constantShuffleModePLAndEPL();
22-
Utils::constantShuffleModeNewSong();
23-
}
16+
// if (Utils::getBool("playlistMode")) {
17+
// Utils::constantShuffleModePLAndEPL();
18+
// Utils::constantShuffleModeNewSong();
19+
// }
2420
}
2521
#else
2622
/*
@@ -37,17 +33,16 @@ class $modify(MenuLoopEPLHook, EditorPauseLayer) {
3733
-- raydeeux
3834
*/
3935
void onSaveAndExit(CCObject *sender) {
40-
if (Utils::getBool("randomizeWhenExitingEditor"))
41-
m_fields->songManager.pickRandomSong();
36+
if (Utils::getBool("randomizeWhenExitingEditor")) SongManager::get().pickRandomSong();
4237

4338
EditorPauseLayer::onSaveAndExit(sender);
4439

4540
Utils::removeCardRemotely();
4641

47-
if (Utils::getBool("playlistMode")) {
48-
Utils::constantShuffleModePLAndEPL();
49-
Utils::constantShuffleModeNewSong();
50-
}
42+
// if (Utils::getBool("playlistMode")) {
43+
// Utils::constantShuffleModePLAndEPL();
44+
// Utils::constantShuffleModeNewSong();
45+
// }
5146
}
5247
void FLAlert_Clicked(FLAlertLayer* p0, bool btnTwo) {
5348
bool shouldClose = p0->getTag() == 1 && btnTwo;
@@ -86,17 +81,16 @@ class $modify(MenuLoopEPLHook, EditorPauseLayer) {
8681

8782
if (!shouldClose) return EditorPauseLayer::FLAlert_Clicked(p0, btnTwo);
8883

89-
if (Utils::getBool("randomizeWhenExitingEditor"))
90-
m_fields->songManager.pickRandomSong();
84+
if (Utils::getBool("randomizeWhenExitingEditor")) SongManager::get().pickRandomSong();
9185

9286
EditorPauseLayer::FLAlert_Clicked(p0, btnTwo);
9387

9488
Utils::removeCardRemotely();
9589

96-
if (Utils::getBool("playlistMode")) {
97-
Utils::constantShuffleModePLAndEPL();
98-
Utils::constantShuffleModeNewSong();
99-
}
90+
// if (Utils::getBool("playlistMode")) {
91+
// Utils::constantShuffleModePLAndEPL();
92+
// Utils::constantShuffleModeNewSong();
93+
// }
10094
}
10195
#endif
10296
};

src/FMODAudioEngine.cpp

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,34 @@ const static std::regex geometryDashRegex = std::regex(R"(^.*(?:(?:Geometry ?Das
99
const static std::regex terribleLoopRegex = std::regex(R"(^[\w]+\.mp3$)");
1010

1111
class $modify(MenuLoopFMODHook, FMODAudioEngine) {
12-
void playMusic(gd::string path, bool shouldLoop, float fadeInTime, int channel) {
13-
SongManager& songManager = SongManager::get();
14-
const bool isLavaChicken = geode::utils::string::contains(static_cast<std::string>(path), "sawblade.steves_lava_chicken");
15-
songManager.setLavaChicken(isLavaChicken);
16-
if (isLavaChicken) {
17-
songManager.setCurrentSong(static_cast<std::string>(path));
12+
void update(float dt) {
13+
FMODAudioEngine::update(dt);
14+
if (!SongManager::get().getConstantShuffleMode()) return;
15+
if (VANILLA_GD_MENU_LOOP_DISABLED) return;
16+
if (GJBaseGameLayer::get() || SongManager::get().isOriginalMenuLoop() || SongManager::get().getSongsSize() < 2) return;
17+
constexpr int channelNumber = 0;
18+
FMOD::Channel* menuLoopChannelProbably = FMODAudioEngine::get()->getActiveMusicChannel(0);
19+
const bool isSongManagerSong = FMODAudioEngine::get()->getActiveMusic(channelNumber) == SongManager::get().getCurrentSong();
20+
log::info("isSongManagerSong: {}", isSongManagerSong);
21+
// unsigned int position = 0;
22+
bool isPlaying = true;
23+
unsigned int position = 0;
24+
FMOD::Sound* sound;
25+
unsigned int length = 0;
26+
menuLoopChannelProbably->isPlaying(&isPlaying);
27+
menuLoopChannelProbably->getPosition(&position, 1);
28+
menuLoopChannelProbably->getCurrentSound(&sound);
29+
sound->getLength(&length, 1);
30+
log::info("position: {}", position);
31+
log::info("isPlaying: {}", isPlaying);
32+
log::info("length - 50: {}", length - 50);
33+
log::info("(length - 50) < position: {}", (length - 50) < position);
34+
log::info("===========================");
35+
if ((length - 50) < position) {
36+
geode::log::info("song is probably finished. Switching songs.");
37+
Utils::removeCard();
38+
Utils::constantShuffleModeNewSong();
1839
Utils::newCardAndDisplayNameFromCurrentSong();
1940
}
20-
if (!Utils::getBool("playlistMode") || isLavaChicken)
21-
return FMODAudioEngine::get()->playMusic(path, shouldLoop, fadeInTime, channel);
22-
log::info("Constant Shuffle Mode enabled.\n=== Constant Shuffle Mode DEBUG INFO ===\npath: {}\nshouldLoop: {}\nfadeInTime: {}\nchannel: {}", path, shouldLoop, fadeInTime, channel);
23-
if (CCScene* scene = CCScene::get(); Utils::getBool("advancedLogs") && scene && scene->getChildren()) {
24-
for (CCObject* object : CCArrayExt<CCObject*>(scene->getChildren())) {
25-
const auto node = typeinfo_cast<CCNode*>(object);
26-
if (node) log::info("there is a CCNode with ID: \"{}\"", node->getID());
27-
}
28-
}
29-
bool desiredShouldLoop = shouldLoop;
30-
std::string gdStringSucks = path;
31-
std::smatch smatch;
32-
if (std::regex_match(gdStringSucks, smatch, terribleLoopRegex)) return log::info("terrible loop detected while Constant Shuffle Mode is active: {}", gdStringSucks);
33-
const bool isMenuLoop = std::regex_match(gdStringSucks, smatch, geometryDashRegex);
34-
if (GJBaseGameLayer::get() && !isMenuLoop) return FMODAudioEngine::get()->playMusic(path, desiredShouldLoop, fadeInTime, channel);
35-
if (fadeInTime == 0 && gdStringSucks == "shop.mp3") return;
36-
if (shouldLoop && fadeInTime == 1.0f) {
37-
if (!isMenuLoop && !utils::string::contains(gdStringSucks, "/Library/Caches/")) {
38-
log::info("non-menu loop found while constant shuffle mode is enabled: {}", gdStringSucks);
39-
return FMODAudioEngine::get()->playMusic(path, desiredShouldLoop, fadeInTime, channel);
40-
}
41-
/*
42-
if and ONLY if the song being is determined to be:
43-
- not the original menuLoop.mp3
44-
- is from Newgrounds, the Music Library, or config directory
45-
then set loop to false for songmanager function to work properly
46-
*/
47-
log::info("menu loop detected.");
48-
desiredShouldLoop = false;
49-
// T0D0: maybe ifdef these few lines. it works on macos intel
50-
if (channel == 0) return log::info("attempted to loop menu music on channel zero! see if on windows or not. aborting early.");
51-
#ifdef GEODE_IS_WINDOWS
52-
if (!songManager.getCalledOnce()) songManager.setCalledOnce(true);
53-
#endif
54-
return FMODAudioEngine::get()->playMusic(path, desiredShouldLoop, 0.0f, channel);
55-
}
56-
FMODAudioEngine::get()->playMusic(path, desiredShouldLoop, fadeInTime, channel);
5741
}
5842
};

src/PlayLayer.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
using namespace geode::prelude;
66

77
class $modify(MenuLoopPLHook, PlayLayer) {
8-
struct Fields {
9-
SongManager &songManager = SongManager::get();
10-
};
118
void onQuit() {
12-
if (Utils::getBool("randomizeWhenExitingLevel"))
13-
m_fields->songManager.pickRandomSong();
9+
if (Utils::getBool("randomizeWhenExitingLevel")) SongManager::get().pickRandomSong();
1410

1511
PlayLayer::onQuit();
1612
Utils::removeCardRemotely();
1713

18-
if (Utils::getBool("playlistMode")) {
19-
Utils::constantShuffleModePLAndEPL();
20-
Utils::constantShuffleModeNewSong();
21-
}
14+
// if (Utils::getBool("playlistMode")) {
15+
// Utils::constantShuffleModePLAndEPL();
16+
// Utils::constantShuffleModeNewSong();
17+
// }
2218
}
2319
};

src/SongControl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace SongControl {
2828
}
2929
FMODAudioEngine::get()->m_backgroundMusicChannel->stop();
3030
songManager.setCurrentSong(previousSong);
31-
if (Utils::getBool("playlistMode")) FMODAudioEngine::get()->playMusic(songManager.getCurrentSong(), true, 1.0f, 1);
32-
else GameManager::sharedState()->playMenuMusic();
31+
GameManager::sharedState()->playMenuMusic();
3332
Utils::newCardAndDisplayNameFromCurrentSong();
3433
}
3534
void holdSong(SongManager& songManager) {
@@ -46,8 +45,7 @@ namespace SongControl {
4645
if (!formerHeldSong.empty()) {
4746
FMODAudioEngine::get()->m_backgroundMusicChannel->stop();
4847
songManager.setCurrentSong(formerHeldSong);
49-
if (Utils::getBool("playlistMode")) FMODAudioEngine::get()->playMusic(songManager.getCurrentSong(), true, 1.0f, 1);
50-
else GameManager::sharedState()->playMenuMusic();
48+
GameManager::sharedState()->playMenuMusic();
5149
return Utils::newCardAndDisplayNameFromCurrentSong();
5250
}
5351
if (!Utils::getBool("playlistMode")) Utils::setNewSong();

src/SongManager.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,6 @@ std::string SongManager::getPlaylistFileName() {
9494
return m_playlistName;
9595
}
9696

97-
void SongManager::update(float dt) const {
98-
// split for readability
99-
if (VANILLA_GD_MENU_LOOP_DISABLED || !m_constantShuffleMode) return;
100-
if (GJBaseGameLayer::get() || m_isMenuLoop || m_songs.size() < 2) return;
101-
auto fmod = FMODAudioEngine::get();
102-
if (!fmod) return;
103-
// geode::log::info("channelIsPlaying: {}", fmod->isMusicPlaying(0));
104-
#ifdef GEODE_IS_WINDOWS
105-
if (fmod->isMusicPlaying(0)) return;
106-
#else
107-
if (fmod->isMusicPlaying(1)) return;
108-
#endif
109-
geode::log::info("song is probably finished. Switching songs.");
110-
Utils::removeCard();
111-
Utils::constantShuffleModeNewSong();
112-
Utils::newCardAndDisplayNameFromCurrentSong();
113-
}
114-
11597
void SongManager::setCalledOnce(const bool value) {
11698
m_calledOnce = value;
11799
}

src/SongManager.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ class SongManager {
1313
return instance;
1414
}
1515

16-
void updateWrapper(float dt) const {
17-
/*
18-
if GameManager::get()->m_menuLayer is not included in the conditional statement
19-
then music will be played at full blast before being set to user's preferred volume.
20-
i don't think anyone wants that.
21-
-- raydeeux
22-
*/
23-
if (GameManager::get()->m_menuLayer) SongManager::get().update(dt);
24-
}
25-
2616
std::vector<std::string> getSongs();
2717
void addSong(const std::string&);
2818
void removeSong(const std::string& path);
@@ -37,7 +27,6 @@ class SongManager {
3727
std::string getCurrentSong();
3828
void setCurrentSong(const std::string&);
3929
void setCurrentSongToSavedSong();
40-
void update(float) const;
4130
bool getCalledOnce() const;
4231
void setCalledOnce(const bool);
4332
bool getGeodify() const;

src/Utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ void Utils::setNewSong() {
7272
void Utils::constantShuffleModeNewSong(const bool fromGJBGL) {
7373
if (VANILLA_GD_MENU_LOOP_DISABLED) return;
7474
if (!Utils::getBool("playlistMode")) return Utils::setNewSong();
75-
geode::log::info("attempting to hijack menuloop channel to use Constant Shuffle Mode");
7675
const auto fmod = FMODAudioEngine::sharedEngine();
7776
float fmodIsCBrained;
7877
const FMOD_RESULT fmodResult = fmod->m_backgroundMusicChannel->getVolume(&fmodIsCBrained);
@@ -88,14 +87,14 @@ void Utils::constantShuffleModeNewSong(const bool fromGJBGL) {
8887
geode::log::info("is it over?");
8988
if (songManager.getCalledOnce() || !Utils::getBool("saveSongOnGameClose")) {
9089
geode::log::info("playing song as normal");
91-
fmod->playMusic(songManager.getCurrentSong(), true, 1.0f, 1);
90+
GameManager::sharedState()->playMenuMusic();
9291
if (!songManager.isOverride()) geode::Mod::get()->setSavedValue<std::string>("lastMenuLoop", songManager.getCurrentSong());
9392
} else {
9493
const bool override = songManager.isOverride();
9594
const std::string& song = override ? songManager.getOverrideSong() : geode::Mod::get()->getSavedValue<std::string>("lastMenuLoop");
9695
geode::log::info("playing song from {}: {}", override ? "override" : "saved value", song);
9796
songManager.setCurrentSong(song);
98-
fmod->playMusic(song, true, 1.0f, 1);
97+
GameManager::sharedState()->playMenuMusic();
9998
}
10099
songManager.setCalledOnce(true);
101100
}
@@ -415,6 +414,7 @@ void Utils::populateVector(const bool customSongs, const std::filesystem::path&
415414
const bool qualifiedForOGMenuBlacklist = geode::Mod::get()->getSavedValue<bool>("isEry");
416415
for (const auto song : geode::cocos::CCArrayExt<SongInfoObject*>(downloadManager->getDownloadedSongs())) {
417416
if (!song) continue;
417+
if (downloadManager->isResourceSong(song->m_songID)) continue; // resource songs not supported!!!
418418

419419
std::string songPath = downloadManager->pathForSong(song->m_songID);
420420
if (!Utils::isSupportedFile(songPath)) continue;

src/main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ bool originalOverrideWasEmpty = false;
7878
if (!std::filesystem::exists(configDir / R"(store_your_disabled_menuloops_here)")) {
7979
std::filesystem::create_directory(configDir / R"(store_your_disabled_menuloops_here)");
8080
}
81-
GameManager::get()->schedule(reinterpret_cast<SEL_SCHEDULE>(&SongManager::updateWrapper));
8281
listenForSettingChanges<bool>("useCustomSongs", [](bool useCustomSongs) {
8382
Utils::resetSongManagerRefreshVectorSetNewSongBecause("useCustomSongs");
8483
});
@@ -115,7 +114,7 @@ bool originalOverrideWasEmpty = false;
115114
if (VANILLA_GD_MENU_LOOP_DISABLED) return;
116115
Utils::queueUpdateSCMLabel();
117116
if (constantShuffleMode) {
118-
FMODAudioEngine::get()->playMusic(songManager.getCurrentSong(), true, 1.0f, 1);
117+
GameManager::sharedState()->playMenuMusic();
119118
return ConstantShuffleModeWarning::create(songManager.getGeodify())->show();
120119
}
121120
GameManager::sharedState()->playMenuMusic();
@@ -135,7 +134,6 @@ bool originalOverrideWasEmpty = false;
135134
} else Utils::setNewSong();
136135
}
137136
geode::Loader::get()->queueInMainThread([] { Utils::queueUpdateSCMLabel(); });
138-
if (Utils::getBool("playlistMode")) return FMODAudioEngine::get()->playMusic(SongManager::get().getCurrentSong(), true, 1.0f, 1);
139137
GameManager::sharedState()->playMenuMusic();
140138
});
141139
listenForSettingChanges<bool>("dangerousBlacklisting", [](bool dangerousBlacklisting) {

src/ui/MLRSongCell.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ void MLRSongCell::onPlaySong(CCObject*) {
9393
songManager.setPreviousSong(currentSong);
9494
songManager.setCurrentSong(m_songData.actualFilePath);
9595
fmod->m_backgroundMusicChannel->stop();
96-
if (Utils::getBool("playlistMode")) fmod->playMusic(songManager.getCurrentSong(), true, 1.0f, 1);
97-
else GameManager::sharedState()->playMenuMusic();
96+
GameManager::sharedState()->playMenuMusic();
9897
Utils::newCardAndDisplayNameFromCurrentSong();
9998
}
10099

0 commit comments

Comments
 (0)