Merge pull request #79 from narayanx/feature/switch-song-lr

Allow switching with L/R, fix with pause/play, remove stop song
This commit is contained in:
Mahyar Koshkouei
2025-08-25 14:21:49 +01:00
committed by GitHub
2 changed files with 49 additions and 23 deletions

View File

@@ -13,7 +13,7 @@ The latest 3DSX/CIA/3DS download can be found on the <a href="https://github.com
## Controls
L+R or L+Up: Pause
L+B: Stop
ZL/ZR or L/R: Previous/Next Song
L+Left: Show Controls

View File

@@ -30,7 +30,7 @@ static void showControls(void)
{
printf("Button mappings:\n"
"Pause: L+R or L+Up\n"
"Stop: L+B\n"
"Previous/Next Song: ZL/ZR or L/R\n"
"A: Open File\n"
"B: Go up folder\n"
"Start: Exit\n"
@@ -302,6 +302,10 @@ int main(int argc, char **argv)
volatile int error = 0;
struct dirList_t dirList = { 0 };
/* ignore key release of L/R if L+R or L+down was pressed */
bool keyLComboPressed = false;
bool keyRComboPressed = false;
gfxInitDefault();
consoleInit(GFX_TOP, &topScreenLog);
consoleInit(GFX_TOP, &topScreenInfo);
@@ -358,6 +362,7 @@ int main(int argc, char **argv)
{
u32 kDown;
u32 kHeld;
u32 kUp;
static u64 mill = 0;
gfxFlushBuffers();
@@ -367,6 +372,7 @@ int main(int argc, char **argv)
hidScanInput();
kDown = hidKeysDown();
kHeld = hidKeysHeld();
kUp = hidKeysUp();
consoleSelect(&bottomScreen);
@@ -396,6 +402,11 @@ int main(int argc, char **argv)
else
puts("Playing");
keyLComboPressed = true;
// distinguish between L+R and L+Up
if (KEY_R & kDown) {
keyRComboPressed = true;
}
continue;
}
@@ -404,27 +415,25 @@ int main(int argc, char **argv)
{
consoleSelect(&topScreenLog);
showControls();
keyLComboPressed = true;
continue;
}
/* Stop */
if(kDown & KEY_B)
{
stopPlayback();
/* Clear playback information. */
consoleSelect(&topScreenInfo);
consoleClear();
consoleSelect(&topScreenLog);
//consoleClear();
changeFile(NULL, &playbackInfo);
/* If the playback thread is currently playing, it will now
* stop and tell the Watchdog thread to display "Stopped".
*/
}
// if R is pressed first
if ((kHeld & KEY_R) && (kDown & KEY_L))
{
if(isPlaying() == false)
continue;
}
consoleSelect(&topScreenLog);
if(togglePlayback() == true)
puts("Paused");
else
puts("Playing");
keyLComboPressed = true;
keyRComboPressed = true;
continue;
}
if((kDown & KEY_UP ||
@@ -571,7 +580,16 @@ int main(int argc, char **argv)
}
}
if (kDown & KEY_ZR && fileNum < fileMax) {
// ignore R release if key combo with R used
bool keyRActivation = false;
if (kUp & KEY_R) {
if (!keyRComboPressed) {
keyRActivation = true;
}
keyRComboPressed = false;
}
bool goToNextFile = (kDown & KEY_ZR) || keyRActivation;
if (goToNextFile && fileNum < fileMax) {
fileNum += 1;
if(fileNum >= MAX_LIST && fileMax - fileNum >= 0 &&
from < fileMax - MAX_LIST)
@@ -586,9 +604,17 @@ int main(int argc, char **argv)
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) err_print("Unable to list directory.");
continue;
}
// ignore L release if key combo with L used
bool keyLActivation = false;
if (kUp & KEY_L) {
if (!keyLComboPressed) {
keyLActivation = true;
}
keyLComboPressed = false;
}
bool goToPrevFile = (kDown & KEY_ZL) || keyLActivation;
// don't go to ../
if (kDown & KEY_ZL && fileNum > 1) {
if (goToPrevFile && fileNum > 1) {
fileNum -= 1;
if(fileMax - fileNum > MAX_LIST-2 && from != 0)
from--;