Skip to content
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ The latest 3DSX/CIA/3DS download can be found on the <a href="https://github.com
* Ability to browse directories.

## Controls
L+R or L+Up: Pause
**L+R/L+Up**: Pause

ZL/ZR or L/R: Previous/Next Song
**ZL/ZR**: Previous/Next Song
**Hold 1s L/R**: Previous/Next Song

L+Left: Show Controls
**L+Left**: Show Controls

A: Play file or change to selected directory
**A**: Play file or change to selected directory

B: Go up folder
**B**: Go up folder

Up & down = Move cursor
**Up & down**: Move cursor

Left & right = Move cursor skipping 13 files at a time.
**Left & right**: Move cursor skipping 13 files at a time.

Start: Exit
**Start**: Exit

# Contributing

Expand Down
144 changes: 105 additions & 39 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ volatile bool runThreads = true;
*/
static void showControls(void)
{
printf("Button mappings:\n"
printf("\n"
"Button mappings:\n"
"Pause: L+R or L+Up\n"
"Previous/Next Song: ZL/ZR or L/R\n"
"Previous/Next Song: ZL/ZR\n"
"Previous/Next Song: Hold L/R 1s\n"
"A: Open File\n"
"B: Go up folder\n"
"Start: Exit\n"
"Browse: Up, Down, Left or Right\n");
"Browse: Up, Down, Left or Right\n\n");
}

/**
Expand All @@ -55,20 +57,20 @@ void playbackWatchdog(void* infoIn)

if(*info->errInfo->error > 0)
{
continue;
//continue;
consoleSelect(info->screen);
printf("Error %d: %s\n", *info->errInfo->error,
ctrmus_strerror(*info->errInfo->error));
}
else if (*info->errInfo->error == -1)
{
continue;
/* Used to signify that playback has stopped.
* Not technically an error.
*/
consoleSelect(info->screen);
puts("Stopped");
}
// else if (*info->errInfo->error == -1)
// {
// //continue;
// /* Used to signify that playback has stopped.
// * Not technically an error.
// */
// consoleSelect(info->screen);
// puts("Stopped");
// }
}

return;
Expand Down Expand Up @@ -169,6 +171,10 @@ static int getDir(struct dirList_t* dirList)

while((ep = readdir(dp)) != NULL)
{
/* Skip hidden entries (names starting with '.') */
if(ep->d_name[0] == '.')
continue;

if(ep->d_type == DT_DIR)
{
/* Add more space for another pointer to a dirent struct */
Expand Down Expand Up @@ -275,9 +281,12 @@ int getNumberFiles(void)
if((dp = opendir(".")) == NULL)
goto err;

while((ep = readdir(dp)) != NULL)
while((ep = readdir(dp)) != NULL) {
if(ep->d_name[0] == '.')
continue;
ret++;

}

closedir(dp);

out:
Expand Down Expand Up @@ -306,6 +315,12 @@ int main(int argc, char **argv)
bool keyLComboPressed = false;
bool keyRComboPressed = false;

/* track hold time for L and R so they only change song after 1s hold */
u64 lPressTime = 0;
u64 rPressTime = 0;
bool lHoldTriggered = false;
bool rHoldTriggered = false;

gfxInitDefault();
consoleInit(GFX_TOP, &topScreenLog);
consoleInit(GFX_TOP, &topScreenInfo);
Expand Down Expand Up @@ -374,6 +389,28 @@ int main(int argc, char **argv)
kHeld = hidKeysHeld();
kUp = hidKeysUp();

/* track press times for L and R to support 1s hold to change songs */
if (kDown & KEY_L) {
lPressTime = osGetTime();
lHoldTriggered = false;
}
if (kDown & KEY_R) {
rPressTime = osGetTime();
rHoldTriggered = false;
}
if (kUp & KEY_L) {
lPressTime = 0;
lHoldTriggered = false;
/* clear combo flag on release */
keyLComboPressed = false;
}
if (kUp & KEY_R) {
rPressTime = 0;
rHoldTriggered = false;
/* clear combo flag on release */
keyRComboPressed = false;
}

consoleSelect(&bottomScreen);

/* Exit ctrmus */
Expand Down Expand Up @@ -580,56 +617,85 @@ int main(int argc, char **argv)
}
}

// 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;
// check that next entry is a file
if (goToNextFile && fileNum < fileMax && dirList.dirNum < fileNum+1) {
/*
* Handle song change for R and L:
* - Instant change with ZR / ZL (unchanged)
* - L/R physical buttons now require a 1 second continuous hold
* and are ignored if they were part of a combo (pause) press.
*/

/* Instant next (ZR) */
if ((kDown & KEY_ZR) && fileNum < fileMax && dirList.dirNum < fileNum+1) {
fileNum += 1;
if(fileNum >= MAX_LIST && fileMax - fileNum >= 0 &&
from < fileMax - MAX_LIST)
from++;
consoleSelect(&topScreenInfo);
consoleClear();
consoleSelect(&topScreenLog);
//consoleClear();
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
error = 0;
consoleSelect(&bottomScreen);
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 ../ and check that previous entry is a file
if (goToPrevFile && fileNum > 1 && dirList.dirNum < fileNum-1) {

/* Instant previous (ZL) */
if ((kDown & KEY_ZL) && fileNum > 1 && dirList.dirNum < fileNum-1) {
fileNum -= 1;
if(fileMax - fileNum > MAX_LIST-2 && from != 0)
from--;
consoleSelect(&topScreenInfo);
consoleClear();
consoleSelect(&topScreenLog);
//consoleClear();
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
error = 0;
consoleSelect(&bottomScreen);
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) err_print("Unable to list directory.");
continue;
}

/* R held for >=1000ms: Next song (only if not part of combo) */
if ((kHeld & KEY_R) && rPressTime != 0 && !rHoldTriggered && !keyRComboPressed) {
if (osGetTime() - rPressTime >= 1000) {
if (fileNum < fileMax && dirList.dirNum < fileNum+1) {
fileNum += 1;
if(fileNum >= MAX_LIST && fileMax - fileNum >= 0 &&
from < fileMax - MAX_LIST)
from++;
consoleSelect(&topScreenInfo);
consoleClear();
consoleSelect(&topScreenLog);
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
error = 0;
consoleSelect(&bottomScreen);
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) err_print("Unable to list directory.");
}
rHoldTriggered = true;
continue;
}
}

/* L held for >=1000ms: Previous song (only if not part of combo) */
if ((kHeld & KEY_L) && lPressTime != 0 && !lHoldTriggered && !keyLComboPressed) {
if (osGetTime() - lPressTime >= 1000) {
if (fileNum > 1 && dirList.dirNum < fileNum-1) {
fileNum -= 1;
if(fileMax - fileNum > MAX_LIST-2 && from != 0)
from--;
consoleSelect(&topScreenInfo);
consoleClear();
consoleSelect(&topScreenLog);
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
error = 0;
consoleSelect(&bottomScreen);
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) err_print("Unable to list directory.");
}
lHoldTriggered = true;
continue;
}
}

// play next song automatically
if (error == -1) {
// don't try to play folders
Expand Down