Skip to content

Commit 4b2ea5d

Browse files
committed
increment/decrement?
1 parent c68cac3 commit 4b2ea5d

File tree

7 files changed

+96
-60
lines changed

7 files changed

+96
-60
lines changed

src/SongControl.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include "Utils.hpp"
33
#include <Geode/ui/GeodeUI.hpp>
44

5+
#define CAN_USE_PLAYBACK_CONTROLS (songManager.getFinishedCalculatingSongLengths() && songManager.getUndefined0Alk1m123TouchPrio() && songManager.getShowPlaybackProgressAndControls())
6+
#define INCREMENT_DECREMENT_AMOUNT songManager.getIncrementDecrementByMilliseconds()
7+
58
namespace SongControl {
69
void woahThereBuddy(const std::string& reason) {
710
geode::createQuickPopup(
@@ -239,4 +242,60 @@ namespace SongControl {
239242
geode::NotificationIcon::Success, 5.f
240243
)->show();
241244
}
245+
void skipBackward() {
246+
SongManager& songManager = SongManager::get();
247+
if (!CAN_USE_PLAYBACK_CONTROLS || VANILLA_GD_MENU_LOOP_DISABLED) return;
248+
249+
FMODAudioEngine* fmod = FMODAudioEngine::get();
250+
const std::string& currSong = songManager.getCurrentSong();
251+
if (fmod->getActiveMusic(0) != currSong || !songManager.getSongToSongDataEntries().contains(currSong)) return;
252+
253+
const int fullLength = songManager.getSongToSongDataEntries().find(songManager.getCurrentSong())->second.songLength;
254+
const int lastPosition = songManager.getLastMenuLoopPosition();
255+
256+
songManager.setPauseSongPositionTracking(true);
257+
int newPosition = 0;
258+
if ((lastPosition - INCREMENT_DECREMENT_AMOUNT) < 0) {
259+
if (songManager.getConstantShuffleMode()) {
260+
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
261+
} else if (fullLength > 0 && fullLength < std::numeric_limits<unsigned int>::max()) {
262+
newPosition = ((((lastPosition % fullLength) + fullLength) % fullLength) - (INCREMENT_DECREMENT_AMOUNT % fullLength) + fullLength) % fullLength;
263+
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
264+
}
265+
} else {
266+
newPosition = lastPosition - INCREMENT_DECREMENT_AMOUNT;
267+
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
268+
}
269+
songManager.setLastMenuLoopPosition(newPosition);
270+
songManager.setPauseSongPositionTracking(false);
271+
}
272+
void skipForward() {
273+
SongManager& songManager = SongManager::get();
274+
if (!CAN_USE_PLAYBACK_CONTROLS || VANILLA_GD_MENU_LOOP_DISABLED) return;
275+
276+
FMODAudioEngine* fmod = FMODAudioEngine::get();
277+
const std::string& currSong = songManager.getCurrentSong();
278+
if (fmod->getActiveMusic(0) != currSong || !songManager.getSongToSongDataEntries().contains(currSong)) return;
279+
280+
const int fullLength = songManager.getSongToSongDataEntries().find(songManager.getCurrentSong())->second.songLength;
281+
const int lastPosition = songManager.getLastMenuLoopPosition();
282+
283+
songManager.setPauseSongPositionTracking(true);
284+
int newPosition = 0;
285+
if ((lastPosition + INCREMENT_DECREMENT_AMOUNT) > fullLength) {
286+
if (songManager.getConstantShuffleMode()) {
287+
SongControl::shuffleSong();
288+
Utils::queueUpdateFrontfacingLabelsInSCMAndSLL();
289+
songManager.setPauseSongPositionTracking(false);
290+
} else if (fullLength > 0 && fullLength < std::numeric_limits<unsigned int>::max()) {
291+
newPosition = ((((lastPosition % fullLength) + fullLength) % fullLength) + (INCREMENT_DECREMENT_AMOUNT % fullLength)) % fullLength;
292+
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
293+
}
294+
} else {
295+
newPosition = lastPosition + INCREMENT_DECREMENT_AMOUNT;
296+
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
297+
}
298+
songManager.setLastMenuLoopPosition(newPosition);
299+
songManager.setPauseSongPositionTracking(false);
300+
}
242301
}

src/SongControl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ namespace SongControl {
1212
void regenSong();
1313
void shuffleSong(const SongManager& songManager = SongManager::get());
1414
void addSongToPlaylist(const std::string& songPath = SongManager::get().getCurrentSong());
15+
void skipBackward();
16+
void skipForward();
1517
}

src/Utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ void Utils::queueUpdateFrontfacingLabelsInSCMAndSLL() {
682682
else if (SongListLayer* sll = cocos2d::CCScene::get()->getChildByType<SongListLayer>(0); SongManager::get().getUndefined0Alk1m123TouchPrio() && sll && sll->m_mainLayer->getChildByIDRecursive(SEARCH_BAR_NODE_ID)) geode::Loader::get()->queueInMainThread([sll] { sll->displayCurrentSongByLimitingPlaceholderLabelWidth(static_cast<geode::TextInput*>(sll->m_mainLayer->getChildByIDRecursive(SEARCH_BAR_NODE_ID))->getInputNode(), false); });
683683
}
684684

685-
void Utils::addButton(const std::string& name, const cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target, const bool dontAddBG) {
686-
if (!menu || !target || name.empty()) return;
685+
CCMenuItemSpriteExtra* Utils::addButton(const std::string& name, const cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target, const bool dontAddBG) {
686+
if (!menu || !target || name.empty()) return nullptr;
687687

688688
cocos2d::CCSprite* btnSprite = cocos2d::CCSprite::create(fmt::format("{}-btn-sprite.png"_spr, name).c_str());
689689
btnSprite->setID(fmt::format("{}-button-sprite"_spr, name));
@@ -706,6 +706,7 @@ void Utils::addButton(const std::string& name, const cocos2d::SEL_MenuHandler fu
706706

707707
menu->addChild(btn);
708708
if (menu->getLayout()) menu->updateLayout();
709+
return btn;
709710
}
710711

711712
void Utils::addViewModeToggle(const bool relevantBoolean, const std::string& toggleIcon, const std::string_view nodeID, const cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target, const bool dontAddBG) {

src/Utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Utils {
3737
static void fadeOutCardRemotely(cocos2d::CCNode*);
3838
static void removeCardRemotely(cocos2d::CCNode*);
3939
static void queueUpdateFrontfacingLabelsInSCMAndSLL();
40-
static void addButton(const std::string& name, const cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target, const bool dontAddBG = false);
40+
static CCMenuItemSpriteExtra* addButton(const std::string& name, const cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target, const bool dontAddBG = false);
4141
static void addViewModeToggle(const bool relevantBoolean, const std::string& toggleIcon, const std::string_view nodeID, cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target, const bool dontAddBG = false);
4242
static void showMDPopup(const std::string_view title, const std::string& bodyText, const int tag, const std::string_view nodeID);
4343
static bool notFavoritesNorBlacklist(const std::filesystem::path&);

src/ui/MLRSongCell.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "MLRSongCell.hpp"
2+
#include "../SongControl.hpp"
23
#include "../Utils.hpp"
34

45
MLRSongCell* MLRSongCell::create(const SongData& SongData, const bool isEven, const bool isCompact) {
@@ -104,14 +105,26 @@ bool MLRSongCell::init(const SongData& songData, const bool isEven, const bool i
104105
CCMenuItemSpriteExtra* playButton = CCMenuItemSpriteExtra::create(cocos2d::CCSprite::createWithSpriteFrameName("GJ_playMusicBtn_001.png"), this, menu_selector(MLRSongCell::onPlaySong));
105106
playButton->setID("song-cell-play-button"_spr);
106107

108+
CCMenuItemSpriteExtra* skipBkwd = Utils::addButton("skip-bkwd", menu_selector(MLRSongCell::onSkipBkwdButton), menu, this);
109+
CCMenuItemSpriteExtra* skipFwrd = Utils::addButton("skip-fwrd", menu_selector(MLRSongCell::onSkipFwrdButton), menu, this);
110+
skipBkwd->setVisible(false);
111+
skipFwrd->setVisible(false);
112+
113+
geode::Layout* layout = geode::RowLayout::create()->setGap(0.f)->setAutoScale(true)->setAxisReverse(false)->setDefaultScaleLimits(.0001f, .75f);
114+
layout->ignoreInvisibleChildren(true);
115+
107116
menu->addChild(playButton);
108-
menu->setLayout(geode::RowLayout::create()->setGap(0.f)->setAutoScale(true)->setAxisReverse(true)->setDefaultScaleLimits(.0001f, .75f));
117+
menu->addChild(skipBkwd);
118+
menu->addChild(skipFwrd);
119+
menu->setLayout(layout);
109120

110121
this->m_menu = menu;
111122
this->m_songNameLabel = songNameLabel;
112123
if (extraInfoLabl) this->m_extraInfoLabl = extraInfoLabl;
113124
this->m_divider = divider;
114125
this->m_playButton = playButton;
126+
this->m_bkwdButton = skipBkwd;
127+
this->m_ffwdButton = skipFwrd;
115128

116129
this->addChild(songNameLabel);
117130
if (extraInfoLabl) this->addChild(extraInfoLabl);
@@ -158,8 +171,9 @@ void MLRSongCell::checkIfCurrentSong() const {
158171
this->m_songNameLabel->setColor({255, 255, 255});
159172
}
160173

161-
if (this->m_menu) this->m_menu->setVisible(!isCurrentSong);
162174
if (this->m_playButton) this->m_playButton->setEnabled(!isCurrentSong);
175+
if (this->m_bkwdButton) this->m_bkwdButton->setEnabled(isCurrentSong);
176+
if (this->m_ffwdButton) this->m_ffwdButton->setEnabled(isCurrentSong);
163177
}
164178

165179
void MLRSongCell::toggleEven(const bool isEven) {
@@ -170,4 +184,12 @@ void MLRSongCell::toggleEven(const bool isEven) {
170184

171185
void MLRSongCell::checkIfCurrentSongScheduler(float) {
172186
MLRSongCell::checkIfCurrentSong();
187+
}
188+
189+
void MLRSongCell::onSkipBkwdButton(CCObject*) {
190+
SongControl::skipBackward();
191+
}
192+
193+
void MLRSongCell::onSkipFwrdButton(CCObject*) {
194+
SongControl::skipForward();
173195
}

src/ui/MLRSongCell.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ class MLRSongCell final : public cocos2d::CCLayerColor {
1313
bool init(const SongData& songData, const bool isEven, const bool isCompact = true);
1414
bool initEmpty(const bool);
1515
void onPlaySong(CCObject*);
16-
void checkIfCurrentSong() const;
1716
void toggleEven(const bool);
17+
void checkIfCurrentSong() const;
18+
void onSkipBkwdButton(CCObject*);
19+
void onSkipFwrdButton(CCObject*);
1820
void checkIfCurrentSongScheduler(float);
1921
SongData m_songData;
2022
cocos2d::CCLabelBMFont* m_songNameLabel;
2123
cocos2d::CCLabelBMFont* m_extraInfoLabl;
2224
cocos2d::CCLayerColor* m_divider;
2325
cocos2d::CCMenu* m_menu;
2426
CCMenuItemSpriteExtra* m_playButton;
27+
CCMenuItemSpriteExtra* m_bkwdButton;
28+
CCMenuItemSpriteExtra* m_ffwdButton;
2529
};

src/ui/SongControlMenu.cpp

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#define REST_OF_THE_OWL this->m_songControlsMenu, this
88
#define DEFAULT_FOOTER_TEXT fmt::format("Hi! Menu Loop Randomizer will never resemble Spotify or its distant cousin EditorMusic. Please respect that. :) [Platform: {}]", Utils::getPlatform())
9-
#define CAN_USE_PLAYBACK_CONTROLS (songManager.getFinishedCalculatingSongLengths() && songManager.getUndefined0Alk1m123TouchPrio() && songManager.getShowPlaybackProgressAndControls())
10-
#define INCREMENT_DECREMENT_AMOUNT songManager.getIncrementDecrementByMilliseconds()
119

1210
bool SongControlMenu::setup() {
1311
this->setTitle("Menu Loop Randomizer - Control Panel");
@@ -353,61 +351,11 @@ void SongControlMenu::onSettingsButton(CCObject*) {
353351
}
354352

355353
void SongControlMenu::onSkipBkwdButton(CCObject*) {
356-
SongManager& songManager = SongManager::get();
357-
if (!CAN_USE_PLAYBACK_CONTROLS || VANILLA_GD_MENU_LOOP_DISABLED) return;
358-
359-
FMODAudioEngine* fmod = FMODAudioEngine::get();
360-
const std::string& currSong = songManager.getCurrentSong();
361-
if (fmod->getActiveMusic(0) != currSong || !songManager.getSongToSongDataEntries().contains(currSong)) return;
362-
363-
const int fullLength = songManager.getSongToSongDataEntries().find(songManager.getCurrentSong())->second.songLength;
364-
const int lastPosition = songManager.getLastMenuLoopPosition();
365-
366-
songManager.setPauseSongPositionTracking(true);
367-
int newPosition = 0;
368-
if ((lastPosition - INCREMENT_DECREMENT_AMOUNT) < 0) {
369-
if (songManager.getConstantShuffleMode()) {
370-
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
371-
} else if (fullLength > 0 && fullLength < std::numeric_limits<unsigned int>::max()) {
372-
newPosition = ((((lastPosition % fullLength) + fullLength) % fullLength) - (INCREMENT_DECREMENT_AMOUNT % fullLength) + fullLength) % fullLength;
373-
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
374-
}
375-
} else {
376-
newPosition = lastPosition - INCREMENT_DECREMENT_AMOUNT;
377-
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
378-
}
379-
songManager.setLastMenuLoopPosition(newPosition);
380-
songManager.setPauseSongPositionTracking(false);
354+
SongControl::skipBackward();
381355
}
382356

383357
void SongControlMenu::onSkipFwrdButton(CCObject*) {
384-
SongManager& songManager = SongManager::get();
385-
if (!CAN_USE_PLAYBACK_CONTROLS || VANILLA_GD_MENU_LOOP_DISABLED) return;
386-
387-
FMODAudioEngine* fmod = FMODAudioEngine::get();
388-
const std::string& currSong = songManager.getCurrentSong();
389-
if (fmod->getActiveMusic(0) != currSong || !songManager.getSongToSongDataEntries().contains(currSong)) return;
390-
391-
const int fullLength = songManager.getSongToSongDataEntries().find(songManager.getCurrentSong())->second.songLength;
392-
const int lastPosition = songManager.getLastMenuLoopPosition();
393-
394-
songManager.setPauseSongPositionTracking(true);
395-
int newPosition = 0;
396-
if ((lastPosition + INCREMENT_DECREMENT_AMOUNT) > fullLength) {
397-
if (songManager.getConstantShuffleMode()) {
398-
SongControl::shuffleSong();
399-
SongControlMenu::updateCurrentLabel();
400-
songManager.setPauseSongPositionTracking(false);
401-
} else if (fullLength > 0 && fullLength < std::numeric_limits<unsigned int>::max()) {
402-
newPosition = ((((lastPosition % fullLength) + fullLength) % fullLength) + (INCREMENT_DECREMENT_AMOUNT % fullLength)) % fullLength;
403-
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
404-
}
405-
} else {
406-
newPosition = lastPosition + INCREMENT_DECREMENT_AMOUNT;
407-
fmod->getActiveMusicChannel(0)->setPosition(newPosition, FMOD_TIMEUNIT_MS);
408-
}
409-
songManager.setLastMenuLoopPosition(newPosition);
410-
songManager.setPauseSongPositionTracking(false);
358+
SongControl::skipForward();
411359
}
412360

413361
void SongControlMenu::updateCurrentLabel() {

0 commit comments

Comments
 (0)