Initial directory changes
Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
2
Makefile
2
Makefile
@@ -49,7 +49,7 @@ SOURCE_DIRS := source
|
|||||||
EXTRA_OUTPUT_FILES :=
|
EXTRA_OUTPUT_FILES :=
|
||||||
|
|
||||||
LIBRARY_DIRS := $(DEVKITPRO)/libctru $(DEVKITPRO)/portlibs/armv6k
|
LIBRARY_DIRS := $(DEVKITPRO)/libctru $(DEVKITPRO)/portlibs/armv6k
|
||||||
LIBRARIES := ctru opusfile opus ogg m
|
LIBRARIES := sftd freetype opusfile opus ogg sf2d citro3d ctru m
|
||||||
|
|
||||||
BUILD_FLAGS :=
|
BUILD_FLAGS :=
|
||||||
RUN_FLAGS :=
|
RUN_FLAGS :=
|
||||||
|
|||||||
125
source/main.c
125
source/main.c
@@ -20,7 +20,10 @@
|
|||||||
#include "opus.h"
|
#include "opus.h"
|
||||||
#include "wav.h"
|
#include "wav.h"
|
||||||
|
|
||||||
#define AUDIO_FOLDER "sdmc:/MUSIC/"
|
/* Default folder */
|
||||||
|
#define TOP_FOLDER "sdmc:/"
|
||||||
|
/* Maximum number of lines that can be displayed */
|
||||||
|
#define MAX_LIST 28
|
||||||
|
|
||||||
enum file_types {
|
enum file_types {
|
||||||
FILE_TYPE_ERROR = -1,
|
FILE_TYPE_ERROR = -1,
|
||||||
@@ -36,39 +39,23 @@ int main(int argc, char **argv)
|
|||||||
struct dirent *ep;
|
struct dirent *ep;
|
||||||
PrintConsole topScreen;
|
PrintConsole topScreen;
|
||||||
PrintConsole bottomScreen;
|
PrintConsole bottomScreen;
|
||||||
u8 fileMax = 0;
|
int fileMax;
|
||||||
u8 fileNum = 1;
|
int fileNum = 0;
|
||||||
|
|
||||||
gfxInitDefault();
|
gfxInitDefault();
|
||||||
consoleInit(GFX_TOP, &topScreen);
|
consoleInit(GFX_TOP, &topScreen);
|
||||||
consoleInit(GFX_BOTTOM, &bottomScreen);
|
consoleInit(GFX_BOTTOM, &bottomScreen);
|
||||||
consoleSelect(&topScreen);
|
|
||||||
|
|
||||||
puts("Scanning audio directory.");
|
|
||||||
|
|
||||||
dp = opendir(AUDIO_FOLDER);
|
|
||||||
if(dp != NULL)
|
|
||||||
{
|
|
||||||
while((ep = readdir(dp)) != NULL)
|
|
||||||
printf("%d: %s\n", ++fileMax, ep->d_name);
|
|
||||||
|
|
||||||
if(closedir(dp) != 0)
|
|
||||||
err_print("Closing directory failed.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
err_print("Opening directory failed.");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fileMax == 0)
|
|
||||||
{
|
|
||||||
err_print("No files in audio folder.");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
consoleSelect(&bottomScreen);
|
consoleSelect(&bottomScreen);
|
||||||
|
|
||||||
|
if((fileMax = listDir(TOP_FOLDER, 0, MAX_LIST)) < 0)
|
||||||
|
{
|
||||||
|
err_print("Unable to list directory.");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
consoleSelect(&topScreen);
|
||||||
|
puts("Queue");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This allows for music to continue playing through the headphones whilst
|
* This allows for music to continue playing through the headphones whilst
|
||||||
* the 3DS is closed.
|
* the 3DS is closed.
|
||||||
@@ -92,34 +79,35 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if(kDown & KEY_UP)
|
if(kDown & KEY_UP)
|
||||||
{
|
{
|
||||||
printf("\33[2K\rSelected file %d",
|
if(fileNum < fileMax)
|
||||||
++fileNum > fileMax ? 1 : fileNum);
|
fileNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(kDown & KEY_DOWN)
|
if(kDown & KEY_DOWN)
|
||||||
{
|
{
|
||||||
printf("\33[2K\rSelected file %d",
|
if(fileNum > 0)
|
||||||
--fileNum == 0 ? fileMax : fileNum);
|
fileNum--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileNum == 0)
|
if(kDown & (KEY_DOWN | KEY_UP))
|
||||||
fileNum = fileMax;
|
{
|
||||||
else if(fileNum > fileMax)
|
printf("\33[2K\rSelected file %d", fileNum);
|
||||||
fileNum = 1;
|
}
|
||||||
|
|
||||||
if(kDown & (KEY_A | KEY_R))
|
if(kDown & (KEY_A | KEY_R))
|
||||||
{
|
{
|
||||||
u8 audioFileNum = 0;
|
int audioFileNum = 0;
|
||||||
dp = opendir(AUDIO_FOLDER);
|
dp = opendir(TOP_FOLDER);
|
||||||
char* file = NULL;
|
char* file = NULL;
|
||||||
|
|
||||||
if (dp != NULL)
|
if (dp != NULL)
|
||||||
{
|
{
|
||||||
while((ep = readdir(dp)) != NULL)
|
while((ep = readdir(dp)) != NULL)
|
||||||
{
|
{
|
||||||
audioFileNum++;
|
|
||||||
if(audioFileNum == fileNum)
|
if(audioFileNum == fileNum)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
audioFileNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(asprintf(&file, "%s%s", AUDIO_FOLDER, ep->d_name) == -1)
|
if(asprintf(&file, "%s%s", AUDIO_FOLDER, ep->d_name) == -1)
|
||||||
@@ -165,6 +153,65 @@ out:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List directory.
|
||||||
|
*
|
||||||
|
* \param dir Path of directory.
|
||||||
|
* \param from First entry in directory to list.
|
||||||
|
* \param max Maximum number of entries to list. Must be > 0.
|
||||||
|
* \return Number of entries listed or negative on error.
|
||||||
|
*/
|
||||||
|
int listDir(const char *dir, int from, int max)
|
||||||
|
{
|
||||||
|
DIR *dp;
|
||||||
|
struct dirent *ep;
|
||||||
|
int fileNum = 0;
|
||||||
|
int countChr = 0;
|
||||||
|
int listed = 0;
|
||||||
|
|
||||||
|
if((dp = opendir(dir)) == NULL)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Count number of occurrences of character in string. */
|
||||||
|
for(int i = 0; i < strlen(dir); i++)
|
||||||
|
{
|
||||||
|
if(dir[i] == '/')
|
||||||
|
countChr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There should always be one slash. So error out here. */
|
||||||
|
if(countChr < 1)
|
||||||
|
{
|
||||||
|
errno = ENOMSG;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(countChr > 1 && from == 0)
|
||||||
|
puts("../");
|
||||||
|
|
||||||
|
while((ep = readdir(dp)) != NULL)
|
||||||
|
{
|
||||||
|
fileNum++;
|
||||||
|
|
||||||
|
if(fileNum < from)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(fileNum + from == max)
|
||||||
|
break;
|
||||||
|
|
||||||
|
listed++;
|
||||||
|
printf(" %.48s%s\n", ep->d_name, ep->d_type == DT_DIR ? "/" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(closedir(dp) != 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
return listed;
|
||||||
|
|
||||||
|
err:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains file type.
|
* Obtains file type.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,6 +7,16 @@
|
|||||||
* LICENSE file.
|
* LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List directory.
|
||||||
|
*
|
||||||
|
* \param dir Path of directory.
|
||||||
|
* \param from First entry in directory to list.
|
||||||
|
* \param max Maximum number of entries to list. Must be > 0.
|
||||||
|
* \return Number of entries listed or negative on error.
|
||||||
|
*/
|
||||||
|
int listDir(const char *dir, int from, int max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains file type.
|
* Obtains file type.
|
||||||
*
|
*
|
||||||
@@ -14,11 +24,3 @@
|
|||||||
* \return File type, else negative.
|
* \return File type, else negative.
|
||||||
*/
|
*/
|
||||||
int getFileType(const char *file);
|
int getFileType(const char *file);
|
||||||
|
|
||||||
/**
|
|
||||||
* Plays a WAV file.
|
|
||||||
*
|
|
||||||
* \param file File location of WAV file.
|
|
||||||
* \return Zero if successful, else failure.
|
|
||||||
*/
|
|
||||||
int playWav(const char *wav);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user