Skip to content

Commit d48fe81

Browse files
committed
finally add song label updating for blacklisting songs
1 parent 707e357 commit d48fe81

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/SongControl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,16 @@ namespace SongControl {
120120
if (!Utils::getBool("playlistMode")) Utils::setNewSong();
121121
else Utils::constantShuffleModeNewSong();
122122

123+
Utils::composeAndSetCurrentSongDisplayNameOnlyWhenBlacklistingSongs();
124+
Utils::queueUpdateSCMLabel();
125+
123126
if (songManager.isOriginalMenuLoop()) {
124127
if (useCustomSongs && !customSong.empty()) return Utils::newNotification(fmt::format("Blacklisted {}. Have fun with the original menu loop. :)", customSong));
125128
if (!useCustomSongs && !songName.empty()) return Utils::newNotification(fmt::format("Blacklisted {}. Have fun with the original menu loop. :)", songName));
126129
}
127130

128131
if (!useCustomSongs) return Utils::newNotification(fmt::format("Blacklisted {} by {} ({}), now playing {}.", songName, songArtist, songID, Utils::getSongName()));
129132
if (!customSong.empty()) return Utils::newNotification(fmt::format("Blacklisted {}, now playing {}.", customSong, Utils::currentCustomSong()));
130-
131-
Utils::queueUpdateSCMLabel();
132133
}
133134
void copySong() {
134135
if (VANILLA_GD_MENU_LOOP_DISABLED) return;
@@ -140,7 +141,7 @@ namespace SongControl {
140141
if (VANILLA_GD_MENU_LOOP_DISABLED || !Utils::getBool("enableNotification")) return;
141142
Utils::newCardAndDisplayNameFromCurrentSong();
142143
}
143-
void shuffleSong(SongManager& songManager) {
144+
void shuffleSong(const SongManager& songManager) {
144145
Utils::removeCard();
145146
if (VANILLA_GD_MENU_LOOP_DISABLED) return;
146147

src/SongControl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ namespace SongControl {
1010
void blacklistSong(SongManager& songManager = SongManager::get());
1111
void copySong();
1212
void regenSong();
13-
void shuffleSong(SongManager& songManager = SongManager::get());
13+
void shuffleSong(const SongManager& songManager = SongManager::get());
1414
void addSongToPlaylist(const std::string& songPath = SongManager::get().getCurrentSong());
1515
}

src/Utils.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ void Utils::newNotification(const std::string& notifString, const bool checkSett
131131
card->runAction(sequence);
132132
}
133133

134+
void Utils::composeAndSetCurrentSongDisplayNameOnlyWhenBlacklistingSongs() {
135+
SongManager& songManager = SongManager::get();
136+
const std::filesystem::path& currentSong = std::filesystem::path(songManager.getCurrentSong());
137+
const std::string& songFileName = Utils::toNormalizedString(currentSong.filename());
138+
const std::string& songFileExtension = Utils::toNormalizedString(currentSong.extension());
139+
const std::string& customSongDisplayName = geode::utils::string::replace(songFileName, songFileExtension, "");
140+
if (songManager.getLavaChicken()) return songManager.setCurrentSongDisplayName(fmt::format("{} (My condolences for your ears.)", songFileName));
141+
if (Utils::getBool("useCustomSongs") && songManager.getPlaylistIsEmpty()) return songManager.setCurrentSongDisplayName(customSongDisplayName);
142+
if (songManager.isOriginalMenuLoop()) return songManager.setCurrentSongDisplayName("Original Menu Loop by RobTop");
143+
const size_t dotPos = songFileName.find_last_of('.');
144+
if (dotPos == std::string::npos) return songManager.setCurrentSongDisplayName("Unknown");
145+
const std::string& songFileNameWithoutExtension = songFileName.substr(0, dotPos);
146+
geode::Result<int> songFileNameAsID = geode::utils::numFromString<int>(songFileNameWithoutExtension);
147+
if (songFileNameAsID.isErr()) {
148+
if (!songManager.getPlaylistIsEmpty()) return songManager.setCurrentSongDisplayName(songFileNameWithoutExtension);
149+
return songManager.setCurrentSongDisplayName(fmt::format("Unknown ({})", songFileNameWithoutExtension));
150+
}
151+
if (SongInfoObject* songInfo = MusicDownloadManager::sharedState()->getSongInfoObject(songFileNameAsID.unwrap())) return songManager.setCurrentSongDisplayName(Utils::getFormattedNGMLSongName(songInfo));
152+
return songManager.setCurrentSongDisplayName(customSongDisplayName);
153+
}
154+
134155
std::string Utils::composedNotifString(std::string notifString, const std::string& middle, const std::string& suffix) {
135156
SongManager& songManager = SongManager::get();
136157
if (!Utils::getBool("useCustomSongs") || !songManager.getPlaylistIsEmpty()) songManager.setCurrentSongDisplayName(middle);
@@ -164,7 +185,7 @@ void Utils::newCardAndDisplayNameFromCurrentSong() {
164185

165186
geode::log::info("attempting to play {}", songFileName);
166187
// if it's not menuLoop.mp3, then get info
167-
size_t dotPos = songFileName.find_last_of('.');
188+
const size_t dotPos = songFileName.find_last_of('.');
168189

169190
if (dotPos == std::string::npos) {
170191
geode::log::error("{} was not a valid file name...? [NG/Music Library]", songFileName);

src/Utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Utils {
1313
static void setNewSong();
1414
static void constantShuffleModeNewSong(const bool fromGJBGL = false);
1515
static void newNotification(const std::string& notifString, const bool checkSetting = false);
16+
static void composeAndSetCurrentSongDisplayNameOnlyWhenBlacklistingSongs();
1617
static std::string composedNotifString(std::string notifString, const std::string& middle, const std::string& suffix);
1718
static void newCardAndDisplayNameFromCurrentSong();
1819
static std::string getFormattedNGMLSongName(SongInfoObject* songInfo);

0 commit comments

Comments
 (0)