GUI
This commit is contained in:
4
Makefile
4
Makefile
@@ -49,9 +49,9 @@ SOURCE_DIRS := source
|
|||||||
EXTRA_OUTPUT_FILES :=
|
EXTRA_OUTPUT_FILES :=
|
||||||
|
|
||||||
LIBRARY_DIRS := $(DEVKITPRO)/libctru $(DEVKITPRO)/portlibs/armv6k $(DEVKITPRO)/portlibs/3ds
|
LIBRARY_DIRS := $(DEVKITPRO)/libctru $(DEVKITPRO)/portlibs/armv6k $(DEVKITPRO)/portlibs/3ds
|
||||||
LIBRARIES := sidplay mpg123 vorbisidec opusfile opus ogg ctru m
|
LIBRARIES := citro2d citro3d sidplay mpg123 vorbisidec opusfile opus ogg ctru m
|
||||||
|
|
||||||
BUILD_FLAGS := -Wall -Wextra -I$(DEVKITPRO)/portlibs/armv6k/include/opus -I$(DEVKITPRO)/portlibs/3ds/include/opus -O3 -g3 -ffunction-sections -fdata-sections
|
BUILD_FLAGS := -Wall -Wextra -I$(DEVKITPRO)/libctru/include -I$(DEVKITPRO)/portlibs/armv6k/include/opus -I$(DEVKITPRO)/portlibs/3ds/include/opus -O3 -g3 -ffunction-sections -fdata-sections
|
||||||
# -O0 -g3 -fstack-protector-strong -fsanitize=undefined -fsanitize-trap
|
# -O0 -g3 -fstack-protector-strong -fsanitize=undefined -fsanitize-trap
|
||||||
RUN_FLAGS :=
|
RUN_FLAGS :=
|
||||||
|
|
||||||
|
|||||||
111
include/gui.h
Normal file
111
include/gui.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#ifndef mice_gui_h
|
||||||
|
#define mice_gui_h
|
||||||
|
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "metadata.h"
|
||||||
|
|
||||||
|
/* GUI color definitions */
|
||||||
|
#define GUI_COLOR_BG_TOP C2D_Color32(20, 20, 30, 255)
|
||||||
|
#define GUI_COLOR_BG_BOTTOM C2D_Color32(15, 15, 25, 255)
|
||||||
|
#define GUI_COLOR_TEXT C2D_Color32(255, 255, 255, 255)
|
||||||
|
#define GUI_COLOR_TEXT_DIM C2D_Color32(180, 180, 180, 255)
|
||||||
|
#define GUI_COLOR_ACCENT C2D_Color32(100, 150, 255, 255)
|
||||||
|
#define GUI_COLOR_HIGHLIGHT C2D_Color32(50, 80, 150, 255)
|
||||||
|
|
||||||
|
/* Screen dimensions */
|
||||||
|
#define TOP_SCREEN_WIDTH 400
|
||||||
|
#define TOP_SCREEN_HEIGHT 240
|
||||||
|
#define BOTTOM_SCREEN_WIDTH 320
|
||||||
|
#define BOTTOM_SCREEN_HEIGHT 240
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the GUI system
|
||||||
|
*
|
||||||
|
* \return 0 on success, -1 on failure
|
||||||
|
*/
|
||||||
|
int guiInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up and exit the GUI system
|
||||||
|
*/
|
||||||
|
void guiExit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begin rendering a frame
|
||||||
|
*/
|
||||||
|
void guiBeginFrame(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End rendering a frame and display it
|
||||||
|
*/
|
||||||
|
void guiEndFrame(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the top screen
|
||||||
|
*/
|
||||||
|
void guiClearTopScreen(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the bottom screen
|
||||||
|
*/
|
||||||
|
void guiClearBottomScreen(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display metadata on the top screen
|
||||||
|
*
|
||||||
|
* \param metadata Pointer to metadata structure
|
||||||
|
* \param filename Filename to display if no title is available
|
||||||
|
*/
|
||||||
|
void guiDisplayMetadata(struct metadata_t* metadata, const char* filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display log messages on the top screen
|
||||||
|
*
|
||||||
|
* \param messages Array of message strings
|
||||||
|
* \param count Number of messages
|
||||||
|
* \param scroll Scroll offset for messages
|
||||||
|
*/
|
||||||
|
void guiDisplayLog(const char** messages, int count, int scroll);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display file list on the bottom screen
|
||||||
|
*
|
||||||
|
* \param files Array of filenames
|
||||||
|
* \param count Number of files
|
||||||
|
* \param selected Index of selected file
|
||||||
|
* \param scroll Scroll offset
|
||||||
|
*/
|
||||||
|
void guiDisplayFileList(const char** files, int count, int selected, int scroll);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display playback controls and status on the bottom screen
|
||||||
|
*
|
||||||
|
* \param isPlaying Whether playback is active
|
||||||
|
* \param isPaused Whether playback is paused
|
||||||
|
* \param position Current position in seconds
|
||||||
|
* \param duration Total duration in seconds
|
||||||
|
*/
|
||||||
|
void guiDisplayPlaybackStatus(bool isPlaying, bool isPaused, float position, float duration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display version text
|
||||||
|
*
|
||||||
|
* \param version Version string to display
|
||||||
|
*/
|
||||||
|
void guiDisplayVersion(const char* version);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a simple text string at specified position
|
||||||
|
*
|
||||||
|
* \param screen Target screen (GFX_TOP or GFX_BOTTOM)
|
||||||
|
* \param x X coordinate
|
||||||
|
* \param y Y coordinate
|
||||||
|
* \param text Text to display
|
||||||
|
* \param color Text color
|
||||||
|
* \param scale Text scale (default 0.5f)
|
||||||
|
*/
|
||||||
|
void guiDrawText(gfxScreen_t screen, float x, float y, const char* text, u32 color, float scale);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
#define mice_main_h
|
#define mice_main_h
|
||||||
|
|
||||||
/* Application version */
|
/* Application version */
|
||||||
#define MICE_VERSION "dev28"
|
#define MICE_VERSION "dev36"
|
||||||
|
|
||||||
/* Default folder */
|
/* Default folder */
|
||||||
#define DEFAULT_DIR "sdmc:/"
|
#define DEFAULT_DIR "sdmc:/"
|
||||||
|
|||||||
@@ -80,6 +80,11 @@ void stopPlayback(void);
|
|||||||
*/
|
*/
|
||||||
bool isPlaying(void);
|
bool isPlaying(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether playback is currently paused.
|
||||||
|
*/
|
||||||
|
bool isPaused(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should only be called from a new thread only, and have only one playback
|
* Should only be called from a new thread only, and have only one playback
|
||||||
* thread at time. This function has not been written for more than one
|
* thread at time. This function has not been written for more than one
|
||||||
|
|||||||
345
source/gui.c
Normal file
345
source/gui.c
Normal file
@@ -0,0 +1,345 @@
|
|||||||
|
#include <3ds.h>
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "gui.h"
|
||||||
|
#include "metadata.h"
|
||||||
|
|
||||||
|
static C3D_RenderTarget* topTarget = NULL;
|
||||||
|
static C3D_RenderTarget* bottomTarget = NULL;
|
||||||
|
static C2D_TextBuf textBuf = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the GUI system
|
||||||
|
*/
|
||||||
|
int guiInit(void)
|
||||||
|
{
|
||||||
|
gfxInitDefault();
|
||||||
|
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||||
|
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
|
||||||
|
C2D_Prepare();
|
||||||
|
|
||||||
|
/* Create render targets for top and bottom screens */
|
||||||
|
topTarget = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
|
||||||
|
bottomTarget = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
|
||||||
|
|
||||||
|
if(!topTarget || !bottomTarget)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Create text buffer */
|
||||||
|
textBuf = C2D_TextBufNew(4096);
|
||||||
|
if(!textBuf)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up and exit the GUI system
|
||||||
|
*/
|
||||||
|
void guiExit(void)
|
||||||
|
{
|
||||||
|
if(textBuf)
|
||||||
|
C2D_TextBufDelete(textBuf);
|
||||||
|
|
||||||
|
C2D_Fini();
|
||||||
|
C3D_Fini();
|
||||||
|
gfxExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begin rendering a frame
|
||||||
|
*/
|
||||||
|
void guiBeginFrame(void)
|
||||||
|
{
|
||||||
|
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End rendering a frame and display it
|
||||||
|
*/
|
||||||
|
void guiEndFrame(void)
|
||||||
|
{
|
||||||
|
C3D_FrameEnd(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the top screen
|
||||||
|
*/
|
||||||
|
void guiClearTopScreen(void)
|
||||||
|
{
|
||||||
|
C2D_TargetClear(topTarget, GUI_COLOR_BG_TOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the bottom screen
|
||||||
|
*/
|
||||||
|
void guiClearBottomScreen(void)
|
||||||
|
{
|
||||||
|
C2D_TargetClear(bottomTarget, GUI_COLOR_BG_BOTTOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a simple text string at specified position
|
||||||
|
*/
|
||||||
|
void guiDrawText(gfxScreen_t screen, float x, float y, const char* text, u32 color, float scale)
|
||||||
|
{
|
||||||
|
if(!text || !textBuf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
C2D_Text c2dText;
|
||||||
|
C2D_TextBufClear(textBuf);
|
||||||
|
C2D_TextParse(&c2dText, textBuf, text);
|
||||||
|
C2D_TextOptimize(&c2dText);
|
||||||
|
|
||||||
|
C3D_RenderTarget* target = (screen == GFX_TOP) ? topTarget : bottomTarget;
|
||||||
|
C2D_SceneBegin(target);
|
||||||
|
C2D_DrawText(&c2dText, C2D_WithColor, x, y, 0.5f, scale, scale, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display metadata on the top screen
|
||||||
|
*/
|
||||||
|
void guiDisplayMetadata(struct metadata_t* metadata, const char* filename)
|
||||||
|
{
|
||||||
|
if(!metadata || !filename || !textBuf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
C2D_SceneBegin(topTarget);
|
||||||
|
|
||||||
|
/* Extract just the filename without path and extension for fallback */
|
||||||
|
const char* basename = strrchr(filename, '/');
|
||||||
|
if(!basename)
|
||||||
|
basename = filename;
|
||||||
|
else
|
||||||
|
basename++;
|
||||||
|
|
||||||
|
/* Remove file extension for display */
|
||||||
|
char displayName[64];
|
||||||
|
strncpy(displayName, basename, sizeof(displayName) - 1);
|
||||||
|
displayName[sizeof(displayName) - 1] = '\0';
|
||||||
|
char* dot = strrchr(displayName, '.');
|
||||||
|
if(dot) *dot = '\0';
|
||||||
|
|
||||||
|
C2D_Text text;
|
||||||
|
float y = 10.0f;
|
||||||
|
float scale = 0.6f;
|
||||||
|
float lineHeight = 20.0f;
|
||||||
|
|
||||||
|
C2D_TextBufClear(textBuf);
|
||||||
|
|
||||||
|
/* Draw title */
|
||||||
|
if(metadata->title[0])
|
||||||
|
{
|
||||||
|
char titleBuf[64];
|
||||||
|
snprintf(titleBuf, sizeof(titleBuf), "%.47s", metadata->title);
|
||||||
|
C2D_TextParse(&text, textBuf, titleBuf);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale, scale, GUI_COLOR_TEXT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char titleBuf[64];
|
||||||
|
snprintf(titleBuf, sizeof(titleBuf), "%.47s", displayName);
|
||||||
|
C2D_TextParse(&text, textBuf, titleBuf);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale, scale, GUI_COLOR_TEXT);
|
||||||
|
}
|
||||||
|
y += lineHeight;
|
||||||
|
|
||||||
|
/* Draw artist */
|
||||||
|
if(metadata->artist[0])
|
||||||
|
{
|
||||||
|
char artistBuf[64];
|
||||||
|
snprintf(artistBuf, sizeof(artistBuf), "%.45s", metadata->artist);
|
||||||
|
C2D_TextParse(&text, textBuf, artistBuf);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale * 0.8f, scale * 0.8f, GUI_COLOR_TEXT_DIM);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
C2D_TextParse(&text, textBuf, "Unknown Artist");
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale * 0.8f, scale * 0.8f, GUI_COLOR_TEXT_DIM);
|
||||||
|
}
|
||||||
|
y += lineHeight;
|
||||||
|
|
||||||
|
/* Draw album */
|
||||||
|
if(metadata->album[0])
|
||||||
|
{
|
||||||
|
char albumBuf[64];
|
||||||
|
snprintf(albumBuf, sizeof(albumBuf), "%.45s", metadata->album);
|
||||||
|
C2D_TextParse(&text, textBuf, albumBuf);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale * 0.8f, scale * 0.8f, GUI_COLOR_TEXT_DIM);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
C2D_TextParse(&text, textBuf, "Unknown Album");
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale * 0.8f, scale * 0.8f, GUI_COLOR_TEXT_DIM);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Draw album art indicator if available */
|
||||||
|
if(metadata->hasAlbumArt)
|
||||||
|
{
|
||||||
|
C2D_TextParse(&text, textBuf, "[Art]");
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 350.0f, 10.0f, 0.5f, 0.4f, 0.4f, GUI_COLOR_ACCENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display log messages on the top screen
|
||||||
|
*/
|
||||||
|
void guiDisplayLog(const char** messages, int count, int scroll)
|
||||||
|
{
|
||||||
|
if(!messages || count <= 0 || !textBuf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
C2D_SceneBegin(topTarget);
|
||||||
|
|
||||||
|
C2D_Text text;
|
||||||
|
float y = 70.0f; /* Start below metadata area */
|
||||||
|
float scale = 0.4f;
|
||||||
|
float lineHeight = 12.0f;
|
||||||
|
int maxLines = 14;
|
||||||
|
|
||||||
|
C2D_TextBufClear(textBuf);
|
||||||
|
|
||||||
|
for(int i = scroll; i < count && (i - scroll) < maxLines; i++)
|
||||||
|
{
|
||||||
|
if(messages[i])
|
||||||
|
{
|
||||||
|
C2D_TextParse(&text, textBuf, messages[i]);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale, scale, GUI_COLOR_TEXT);
|
||||||
|
y += lineHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display file list on the bottom screen
|
||||||
|
*/
|
||||||
|
void guiDisplayFileList(const char** files, int count, int selected, int scroll)
|
||||||
|
{
|
||||||
|
if(!files || count <= 0 || !textBuf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
C2D_SceneBegin(bottomTarget);
|
||||||
|
|
||||||
|
C2D_Text text;
|
||||||
|
float y = 10.0f;
|
||||||
|
float scale = 0.5f;
|
||||||
|
float lineHeight = 16.0f;
|
||||||
|
int maxLines = 14;
|
||||||
|
|
||||||
|
C2D_TextBufClear(textBuf);
|
||||||
|
|
||||||
|
for(int i = scroll; i < count && (i - scroll) < maxLines; i++)
|
||||||
|
{
|
||||||
|
if(files[i])
|
||||||
|
{
|
||||||
|
/* Check if this is a directory */
|
||||||
|
size_t len = strlen(files[i]);
|
||||||
|
bool isDir = (len > 0 && files[i][len-1] == '/');
|
||||||
|
|
||||||
|
/* Draw selection highlight */
|
||||||
|
if(i == selected)
|
||||||
|
{
|
||||||
|
C2D_DrawRectSolid(5.0f, y - 2.0f, 0.5f, 310.0f, lineHeight, GUI_COLOR_HIGHLIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Truncate if too long */
|
||||||
|
char displayName[48];
|
||||||
|
snprintf(displayName, sizeof(displayName), "%.40s", files[i]);
|
||||||
|
|
||||||
|
C2D_TextParse(&text, textBuf, displayName);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
|
||||||
|
/* Use different color for directories */
|
||||||
|
u32 color;
|
||||||
|
if(i == selected)
|
||||||
|
color = GUI_COLOR_ACCENT;
|
||||||
|
else if(isDir)
|
||||||
|
color = C2D_Color32(100, 200, 255, 255); /* Light blue for folders */
|
||||||
|
else
|
||||||
|
color = GUI_COLOR_TEXT;
|
||||||
|
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, scale, scale, color);
|
||||||
|
y += lineHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display playback controls and status on the top screen
|
||||||
|
*/
|
||||||
|
void guiDisplayPlaybackStatus(bool isPlaying, bool isPaused, float position, float duration)
|
||||||
|
{
|
||||||
|
if(!textBuf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
C2D_SceneBegin(topTarget);
|
||||||
|
|
||||||
|
C2D_Text text;
|
||||||
|
C2D_TextBufClear(textBuf);
|
||||||
|
|
||||||
|
/* Display status and time at bottom of top screen */
|
||||||
|
float y = 215.0f;
|
||||||
|
|
||||||
|
/* Display status */
|
||||||
|
char statusBuf[64];
|
||||||
|
if(isPlaying)
|
||||||
|
{
|
||||||
|
if(isPaused)
|
||||||
|
snprintf(statusBuf, sizeof(statusBuf), "Paused");
|
||||||
|
else
|
||||||
|
snprintf(statusBuf, sizeof(statusBuf), "Playing");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(statusBuf, sizeof(statusBuf), "Stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
C2D_TextParse(&text, textBuf, statusBuf);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 10.0f, y, 0.5f, 0.5f, 0.5f, GUI_COLOR_TEXT);
|
||||||
|
|
||||||
|
/* Display time if playing */
|
||||||
|
if(isPlaying && duration > 0)
|
||||||
|
{
|
||||||
|
char timeBuf[32];
|
||||||
|
int posMin = (int)position / 60;
|
||||||
|
int posSec = (int)position % 60;
|
||||||
|
int durMin = (int)duration / 60;
|
||||||
|
int durSec = (int)duration % 60;
|
||||||
|
snprintf(timeBuf, sizeof(timeBuf), "%02d:%02d / %02d:%02d", posMin, posSec, durMin, durSec);
|
||||||
|
|
||||||
|
C2D_TextParse(&text, textBuf, timeBuf);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 280.0f, y, 0.5f, 0.5f, 0.5f, GUI_COLOR_TEXT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display version text and credits at bottom of bottom screen
|
||||||
|
*/
|
||||||
|
void guiDisplayVersion(const char* version)
|
||||||
|
{
|
||||||
|
if(!textBuf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
C2D_SceneBegin(bottomTarget);
|
||||||
|
|
||||||
|
C2D_Text text;
|
||||||
|
C2D_TextBufClear(textBuf);
|
||||||
|
|
||||||
|
/* Display "mice - by sillyangel" at bottom center */
|
||||||
|
const char* credits = "mice - by sillyangel";
|
||||||
|
C2D_TextParse(&text, textBuf, credits);
|
||||||
|
C2D_TextOptimize(&text);
|
||||||
|
C2D_DrawText(&text, C2D_WithColor, 80.0f, 220.0f, 0.5f, 0.45f, 0.45f, GUI_COLOR_TEXT_DIM);
|
||||||
|
}
|
||||||
343
source/main.c
343
source/main.c
@@ -21,23 +21,31 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
#include "playback.h"
|
#include "playback.h"
|
||||||
|
#include "gui.h"
|
||||||
|
|
||||||
volatile bool runThreads = true;
|
volatile bool runThreads = true;
|
||||||
|
|
||||||
/**
|
/* Log message buffer for GUI display */
|
||||||
* Prints the current key mappings to stdio.
|
#define MAX_LOG_MESSAGES 100
|
||||||
*/
|
static char* logMessages[MAX_LOG_MESSAGES] = {0};
|
||||||
static void showControls(void)
|
static int logMessageCount = 0;
|
||||||
{
|
static int logScroll = 0;
|
||||||
printf("Button mappings:\n"
|
|
||||||
"Pause: L+R or L+Up\n"
|
static void addLogMessage(const char* msg) {
|
||||||
"Previous/Next Song: ZL/ZR or L/R\n"
|
if (logMessageCount >= MAX_LOG_MESSAGES) {
|
||||||
"A: Open File\n"
|
/* Remove oldest message */
|
||||||
"B: Go up folder\n"
|
free(logMessages[0]);
|
||||||
"Start: Exit\n"
|
memmove(logMessages, logMessages + 1, (MAX_LOG_MESSAGES - 1) * sizeof(char*));
|
||||||
"Browse: Up, Down, Left or Right\n");
|
logMessageCount--;
|
||||||
|
}
|
||||||
|
logMessages[logMessageCount++] = strdup(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the current key mappings (removed - not needed for GUI)
|
||||||
|
*/
|
||||||
|
/* Controls are now implied by the GUI interface */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows the playback thread to return any error messages that it may
|
* Allows the playback thread to return any error messages that it may
|
||||||
* encounter.
|
* encounter.
|
||||||
@@ -56,19 +64,17 @@ void playbackWatchdog(void* infoIn)
|
|||||||
|
|
||||||
if(*info->errInfo->error > 0)
|
if(*info->errInfo->error > 0)
|
||||||
{
|
{
|
||||||
continue;
|
char errorMsg[256];
|
||||||
consoleSelect(info->screen);
|
snprintf(errorMsg, sizeof(errorMsg), "Error %d: %s",
|
||||||
printf("Error %d: %s\n", *info->errInfo->error,
|
*info->errInfo->error, mice_strerror(*info->errInfo->error));
|
||||||
mice_strerror(*info->errInfo->error));
|
addLogMessage(errorMsg);
|
||||||
}
|
}
|
||||||
else if (*info->errInfo->error == -1)
|
else if (*info->errInfo->error == -1)
|
||||||
{
|
{
|
||||||
continue;
|
|
||||||
/* Used to signify that playback has stopped.
|
/* Used to signify that playback has stopped.
|
||||||
* Not technically an error.
|
* Not technically an error. Don't spam logs.
|
||||||
*/
|
*/
|
||||||
consoleSelect(info->screen);
|
/* addLogMessage("Stopped"); */
|
||||||
puts("Stopped");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +121,7 @@ static int changeFile(const char* ep_file, struct playbackInfo_t* playbackInfo)
|
|||||||
//playbackInfo->file = strdup(ep_file);
|
//playbackInfo->file = strdup(ep_file);
|
||||||
if (memccpy(playbackInfo->file, ep_file, '\0', sizeof(playbackInfo->file)) == NULL)
|
if (memccpy(playbackInfo->file, ep_file, '\0', sizeof(playbackInfo->file)) == NULL)
|
||||||
{
|
{
|
||||||
puts("Error: File path too long\n");
|
addLogMessage("Error: File path too long");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +170,7 @@ static int getDir(struct dirList_t* dirList)
|
|||||||
free(dirList->currentDir);
|
free(dirList->currentDir);
|
||||||
|
|
||||||
if((dirList->currentDir = strdup(wd)) == NULL)
|
if((dirList->currentDir = strdup(wd)) == NULL)
|
||||||
puts("Failure");
|
addLogMessage("Memory allocation failure");
|
||||||
|
|
||||||
if((dp = opendir(wd)) == NULL)
|
if((dp = opendir(wd)) == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
@@ -177,7 +183,7 @@ static int getDir(struct dirList_t* dirList)
|
|||||||
dirList->directories = realloc(dirList->directories, (dirNum + 1) * sizeof(char*));
|
dirList->directories = realloc(dirList->directories, (dirNum + 1) * sizeof(char*));
|
||||||
|
|
||||||
if((dirList->directories[dirNum] = strdup(ep->d_name)) == NULL)
|
if((dirList->directories[dirNum] = strdup(ep->d_name)) == NULL)
|
||||||
puts("Failure");
|
addLogMessage("Memory allocation failure");
|
||||||
|
|
||||||
dirNum++;
|
dirNum++;
|
||||||
continue;
|
continue;
|
||||||
@@ -187,7 +193,7 @@ static int getDir(struct dirList_t* dirList)
|
|||||||
dirList->files = realloc(dirList->files, (fileNum + 1) * sizeof(char*));
|
dirList->files = realloc(dirList->files, (fileNum + 1) * sizeof(char*));
|
||||||
|
|
||||||
if((dirList->files[fileNum] = strdup(ep->d_name)) == NULL)
|
if((dirList->files[fileNum] = strdup(ep->d_name)) == NULL)
|
||||||
puts("Failure");
|
addLogMessage("Memory allocation failure");
|
||||||
|
|
||||||
fileNum++;
|
fileNum++;
|
||||||
}
|
}
|
||||||
@@ -207,59 +213,53 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List current directory.
|
* Build file list for GUI display.
|
||||||
*
|
* Creates a combined list of directories and files for rendering.
|
||||||
* \param from First entry in directory to list.
|
|
||||||
* \param max Maximum number of entries to list. Must be > 0.
|
|
||||||
* \param select File to show as selected. Must be > 0.
|
|
||||||
* \return Number of entries listed or negative on error.
|
|
||||||
*/
|
*/
|
||||||
static int listDir(int from, int max, int select, struct dirList_t dirList)
|
static void buildFileListForGUI(struct dirList_t dirList, const char*** outList, int* outCount, int from)
|
||||||
{
|
{
|
||||||
int fileNum = 0;
|
static const char* combinedList[512];
|
||||||
int listed = 0;
|
static char entryBuffer[512][256];
|
||||||
|
int index = 0;
|
||||||
printf("\033[0;0H");
|
|
||||||
printf("Dir: %.33s\n", dirList.currentDir);
|
/* Add parent directory option */
|
||||||
|
|
||||||
if(from == 0)
|
if(from == 0)
|
||||||
{
|
{
|
||||||
printf("\33[2K%c../\n", select == 0 ? '>' : ' ');
|
snprintf(entryBuffer[index], sizeof(entryBuffer[index]), "../");
|
||||||
listed++;
|
combinedList[index] = entryBuffer[index];
|
||||||
max--;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(dirList.fileNum + dirList.dirNum > fileNum)
|
/* Add all directories */
|
||||||
|
for(int i = 0; i < dirList.dirNum && index < 512; i++)
|
||||||
{
|
{
|
||||||
fileNum++;
|
snprintf(entryBuffer[index], sizeof(entryBuffer[index]), "%s/", dirList.directories[i]);
|
||||||
|
combinedList[index] = entryBuffer[index];
|
||||||
if(fileNum <= from)
|
index++;
|
||||||
continue;
|
|
||||||
|
|
||||||
listed++;
|
|
||||||
|
|
||||||
if(dirList.dirNum >= fileNum)
|
|
||||||
{
|
|
||||||
printf("\33[2K%c\x1b[34;1m%.37s/\x1b[0m\n",
|
|
||||||
select == fileNum ? '>' : ' ',
|
|
||||||
dirList.directories[fileNum - 1]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fileNum must be referring to a file instead of a directory. */
|
|
||||||
if(dirList.dirNum < fileNum)
|
|
||||||
{
|
|
||||||
printf("\33[2K%c%.37s\n",
|
|
||||||
select == fileNum ? '>' : ' ',
|
|
||||||
dirList.files[fileNum - dirList.dirNum - 1]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fileNum == max + from)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add all files */
|
||||||
|
for(int i = 0; i < dirList.fileNum && index < 512; i++)
|
||||||
|
{
|
||||||
|
snprintf(entryBuffer[index], sizeof(entryBuffer[index]), "%s", dirList.files[i]);
|
||||||
|
combinedList[index] = entryBuffer[index];
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*outList = combinedList;
|
||||||
|
*outCount = index;
|
||||||
|
}
|
||||||
|
|
||||||
return listed;
|
/**
|
||||||
|
* Dummy function kept for compatibility (no longer used with GUI)
|
||||||
|
*/
|
||||||
|
static int listDir(int from __attribute__((unused)),
|
||||||
|
int max __attribute__((unused)),
|
||||||
|
int select __attribute__((unused)),
|
||||||
|
struct dirList_t dirList __attribute__((unused)))
|
||||||
|
{
|
||||||
|
/* This function is no longer used with GUI rendering */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,13 +290,12 @@ err:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
|
||||||
{
|
{
|
||||||
PrintConsole topScreenLog, topScreenInfo, bottomScreen;
|
|
||||||
int fileMax;
|
int fileMax;
|
||||||
int fileNum = 0;
|
int fileNum = 0;
|
||||||
int from = 0;
|
int from = 0;
|
||||||
Thread watchdogThread;
|
Thread watchdogThread __attribute__((unused));
|
||||||
Handle playbackFailEvent;
|
Handle playbackFailEvent;
|
||||||
struct watchdogInfo watchdogInfoIn;
|
struct watchdogInfo watchdogInfoIn;
|
||||||
struct errInfo_t errInfo;
|
struct errInfo_t errInfo;
|
||||||
@@ -309,26 +308,17 @@ int main(int argc, char **argv)
|
|||||||
bool keyLComboPressed = false;
|
bool keyLComboPressed = false;
|
||||||
bool keyRComboPressed = false;
|
bool keyRComboPressed = false;
|
||||||
|
|
||||||
gfxInitDefault();
|
/* Initialize GUI system */
|
||||||
consoleInit(GFX_TOP, &topScreenLog);
|
if(guiInit() != 0)
|
||||||
consoleInit(GFX_TOP, &topScreenInfo);
|
{
|
||||||
consoleInit(GFX_BOTTOM, &bottomScreen);
|
return -1;
|
||||||
|
}
|
||||||
/* Set console sizes. */
|
|
||||||
// (y-1) + (height) <= 30 (top screen only fits 30 lines)
|
|
||||||
consoleSetWindow(&topScreenLog, 1, 4, 50, 27);
|
|
||||||
consoleSetWindow(&topScreenInfo, 1, 1, 50, 3);
|
|
||||||
|
|
||||||
consoleSelect(&bottomScreen);
|
|
||||||
|
|
||||||
/* Display version in bottom right corner */
|
|
||||||
printf("\033[28;30H%s", MICE_VERSION);
|
|
||||||
|
|
||||||
svcCreateEvent(&playbackFailEvent, RESET_ONESHOT);
|
svcCreateEvent(&playbackFailEvent, RESET_ONESHOT);
|
||||||
errInfo.error = &error;
|
errInfo.error = &error;
|
||||||
errInfo.failEvent = &playbackFailEvent;
|
errInfo.failEvent = &playbackFailEvent;
|
||||||
|
|
||||||
watchdogInfoIn.screen = &topScreenLog;
|
watchdogInfoIn.screen = NULL; /* No longer using console */
|
||||||
watchdogInfoIn.errInfo = &errInfo;
|
watchdogInfoIn.errInfo = &errInfo;
|
||||||
watchdogThread = threadCreate(playbackWatchdog,
|
watchdogThread = threadCreate(playbackWatchdog,
|
||||||
&watchdogInfoIn, 4 * 1024, 0x20, -2, true);
|
&watchdogInfoIn, 4 * 1024, 0x20, -2, true);
|
||||||
@@ -346,13 +336,7 @@ int main(int argc, char **argv)
|
|||||||
/* TODO: Not actually possible to get less than 0 */
|
/* TODO: Not actually possible to get less than 0 */
|
||||||
if(getDir(&dirList) < 0)
|
if(getDir(&dirList) < 0)
|
||||||
{
|
{
|
||||||
puts("Unable to obtain directory information");
|
addLogMessage("Unable to obtain directory information");
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(listDir(from, MAX_LIST, 0, dirList) < 0)
|
|
||||||
{
|
|
||||||
err_print("Unable to list directory.");
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,25 +355,22 @@ int main(int argc, char **argv)
|
|||||||
u32 kUp;
|
u32 kUp;
|
||||||
static u64 mill = 0;
|
static u64 mill = 0;
|
||||||
|
|
||||||
gfxFlushBuffers();
|
/* Begin GUI frame */
|
||||||
gspWaitForVBlank();
|
guiBeginFrame();
|
||||||
gfxSwapBuffers();
|
guiClearTopScreen();
|
||||||
|
guiClearBottomScreen();
|
||||||
|
|
||||||
hidScanInput();
|
hidScanInput();
|
||||||
kDown = hidKeysDown();
|
kDown = hidKeysDown();
|
||||||
kHeld = hidKeysHeld();
|
kHeld = hidKeysHeld();
|
||||||
kUp = hidKeysUp();
|
kUp = hidKeysUp();
|
||||||
|
|
||||||
consoleSelect(&bottomScreen);
|
|
||||||
|
|
||||||
/* Exit mice */
|
/* Exit mice */
|
||||||
if(kDown & KEY_START)
|
if(kDown & KEY_START)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
consoleSelect(&topScreenLog);
|
/* Debug info logged if needed */
|
||||||
printf("\rNum: %d, Max: %d, from: %d ", fileNum, fileMax, from);
|
|
||||||
consoleSelect(&bottomScreen);
|
|
||||||
#endif
|
#endif
|
||||||
if(kDown)
|
if(kDown)
|
||||||
mill = osGetTime();
|
mill = osGetTime();
|
||||||
@@ -402,11 +383,10 @@ int main(int argc, char **argv)
|
|||||||
if(isPlaying() == false)
|
if(isPlaying() == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
consoleSelect(&topScreenLog);
|
|
||||||
if(togglePlayback() == true)
|
if(togglePlayback() == true)
|
||||||
puts("Paused");
|
addLogMessage("Paused");
|
||||||
else
|
else
|
||||||
puts("Playing");
|
addLogMessage("Playing");
|
||||||
|
|
||||||
keyLComboPressed = true;
|
keyLComboPressed = true;
|
||||||
// distinguish between L+R and L+Up
|
// distinguish between L+R and L+Up
|
||||||
@@ -416,11 +396,9 @@ int main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show controls */
|
/* Show controls - no longer needed with GUI */
|
||||||
if(kDown & KEY_LEFT)
|
if(kDown & KEY_LEFT)
|
||||||
{
|
{
|
||||||
consoleSelect(&topScreenLog);
|
|
||||||
showControls();
|
|
||||||
keyLComboPressed = true;
|
keyLComboPressed = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -431,11 +409,10 @@ int main(int argc, char **argv)
|
|||||||
if(isPlaying() == false)
|
if(isPlaying() == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
consoleSelect(&topScreenLog);
|
|
||||||
if(togglePlayback() == true)
|
if(togglePlayback() == true)
|
||||||
puts("Paused");
|
addLogMessage("Paused");
|
||||||
else
|
else
|
||||||
puts("Playing");
|
addLogMessage("Playing");
|
||||||
|
|
||||||
keyLComboPressed = true;
|
keyLComboPressed = true;
|
||||||
keyRComboPressed = true;
|
keyRComboPressed = true;
|
||||||
@@ -485,12 +462,9 @@ int main(int argc, char **argv)
|
|||||||
if(fileMax - fileNum > MAX_LIST-2 && from != 0)
|
if(fileMax - fileNum > MAX_LIST-2 && from != 0)
|
||||||
{
|
{
|
||||||
from -= skip;
|
from -= skip;
|
||||||
if(from < 0)
|
if(from < 0)
|
||||||
from = 0;
|
from = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(listDir(from, MAX_LIST, fileNum, dirList) < 0)
|
|
||||||
err_print("Unable to list directory.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if((kDown & KEY_RIGHT ||
|
if((kDown & KEY_RIGHT ||
|
||||||
@@ -511,9 +485,6 @@ int main(int argc, char **argv)
|
|||||||
if(from > fileMax - MAX_LIST)
|
if(from > fileMax - MAX_LIST)
|
||||||
from = fileMax - MAX_LIST;
|
from = fileMax - MAX_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(listDir(from, MAX_LIST, fileNum, dirList) < 0)
|
|
||||||
err_print("Unable to list directory.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -524,7 +495,6 @@ int main(int argc, char **argv)
|
|||||||
((kDown & KEY_A) && (from == 0 && fileNum == 0)))
|
((kDown & KEY_A) && (from == 0 && fileNum == 0)))
|
||||||
{
|
{
|
||||||
chdir("..");
|
chdir("..");
|
||||||
consoleClear();
|
|
||||||
fileMax = getDir(&dirList);
|
fileMax = getDir(&dirList);
|
||||||
|
|
||||||
fileNum = prevPosition[0];
|
fileNum = prevPosition[0];
|
||||||
@@ -537,9 +507,6 @@ int main(int argc, char **argv)
|
|||||||
prevPosition[MAX_DIRECTORIES-1] = 0;
|
prevPosition[MAX_DIRECTORIES-1] = 0;
|
||||||
prevFrom[MAX_DIRECTORIES-1] = 0;
|
prevFrom[MAX_DIRECTORIES-1] = 0;
|
||||||
|
|
||||||
if(listDir(from, MAX_LIST, fileNum, dirList) < 0)
|
|
||||||
err_print("Unable to list directory.");
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,7 +515,6 @@ int main(int argc, char **argv)
|
|||||||
if(dirList.dirNum >= fileNum)
|
if(dirList.dirNum >= fileNum)
|
||||||
{
|
{
|
||||||
chdir(dirList.directories[fileNum - 1]);
|
chdir(dirList.directories[fileNum - 1]);
|
||||||
consoleClear();
|
|
||||||
fileMax = getDir(&dirList);
|
fileMax = getDir(&dirList);
|
||||||
|
|
||||||
oldFileNum = fileNum;
|
oldFileNum = fileNum;
|
||||||
@@ -556,36 +522,23 @@ int main(int argc, char **argv)
|
|||||||
fileNum = 0;
|
fileNum = 0;
|
||||||
from = 0;
|
from = 0;
|
||||||
|
|
||||||
if(listDir(from, MAX_LIST, fileNum, dirList) < 0)
|
/* save old position in folder */
|
||||||
{
|
for (int i=MAX_DIRECTORIES-1; i>0; i--) {
|
||||||
err_print("Unable to list directory.");
|
prevPosition[i] = prevPosition[i-1];
|
||||||
}
|
prevFrom[i] = prevFrom[i-1];
|
||||||
else
|
|
||||||
{
|
|
||||||
/* save old position in folder */
|
|
||||||
for (int i=MAX_DIRECTORIES-1; i>0; i--) {
|
|
||||||
prevPosition[i] = prevPosition[i-1];
|
|
||||||
prevFrom[i] = prevFrom[i-1];
|
|
||||||
}
|
|
||||||
prevPosition[0] = oldFileNum;
|
|
||||||
prevFrom[0] = oldFrom;
|
|
||||||
}
|
}
|
||||||
|
prevPosition[0] = oldFileNum;
|
||||||
|
prevFrom[0] = oldFrom;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dirList.dirNum < fileNum)
|
if(dirList.dirNum < fileNum)
|
||||||
{
|
{
|
||||||
consoleSelect(&topScreenInfo);
|
|
||||||
consoleClear();
|
|
||||||
|
|
||||||
/* Extract and display metadata */
|
/* Extract and display metadata */
|
||||||
char fullPath[512];
|
char fullPath[512];
|
||||||
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
extractMetadata(fullPath, ¤tMetadata);
|
extractMetadata(fullPath, ¤tMetadata);
|
||||||
displayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
guiDisplayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
|
|
||||||
consoleSelect(&topScreenLog);
|
|
||||||
//consoleClear();
|
|
||||||
|
|
||||||
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
||||||
error = 0;
|
error = 0;
|
||||||
@@ -608,21 +561,15 @@ int main(int argc, char **argv)
|
|||||||
if(fileNum >= MAX_LIST && fileMax - fileNum >= 0 &&
|
if(fileNum >= MAX_LIST && fileMax - fileNum >= 0 &&
|
||||||
from < fileMax - MAX_LIST)
|
from < fileMax - MAX_LIST)
|
||||||
from++;
|
from++;
|
||||||
consoleSelect(&topScreenInfo);
|
|
||||||
consoleClear();
|
|
||||||
|
|
||||||
/* Extract and display metadata */
|
/* Extract and display metadata */
|
||||||
char fullPath[512];
|
char fullPath[512];
|
||||||
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
extractMetadata(fullPath, ¤tMetadata);
|
extractMetadata(fullPath, ¤tMetadata);
|
||||||
displayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
guiDisplayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
|
|
||||||
consoleSelect(&topScreenLog);
|
|
||||||
//consoleClear();
|
|
||||||
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
||||||
error = 0;
|
error = 0;
|
||||||
consoleSelect(&bottomScreen);
|
|
||||||
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) err_print("Unable to list directory.");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ignore L release if key combo with L used
|
// ignore L release if key combo with L used
|
||||||
@@ -639,21 +586,15 @@ int main(int argc, char **argv)
|
|||||||
fileNum -= 1;
|
fileNum -= 1;
|
||||||
if(fileMax - fileNum > MAX_LIST-2 && from != 0)
|
if(fileMax - fileNum > MAX_LIST-2 && from != 0)
|
||||||
from--;
|
from--;
|
||||||
consoleSelect(&topScreenInfo);
|
|
||||||
consoleClear();
|
|
||||||
|
|
||||||
/* Extract and display metadata */
|
/* Extract and display metadata */
|
||||||
char fullPath[512];
|
char fullPath[512];
|
||||||
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
extractMetadata(fullPath, ¤tMetadata);
|
extractMetadata(fullPath, ¤tMetadata);
|
||||||
displayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
guiDisplayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
|
|
||||||
consoleSelect(&topScreenLog);
|
|
||||||
//consoleClear();
|
|
||||||
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
||||||
error = 0;
|
error = 0;
|
||||||
consoleSelect(&bottomScreen);
|
|
||||||
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) err_print("Unable to list directory.");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,78 +606,70 @@ int main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fileNum += 1;
|
fileNum += 1;
|
||||||
consoleSelect(&topScreenInfo);
|
|
||||||
consoleClear();
|
|
||||||
|
|
||||||
/* Extract and display metadata */
|
/* Extract and display metadata */
|
||||||
char fullPath[512];
|
char fullPath[512];
|
||||||
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
snprintf(fullPath, sizeof(fullPath), "%s", dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
extractMetadata(fullPath, ¤tMetadata);
|
extractMetadata(fullPath, ¤tMetadata);
|
||||||
displayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
guiDisplayMetadata(¤tMetadata, dirList.files[fileNum - dirList.dirNum - 1]);
|
||||||
|
|
||||||
consoleSelect(&topScreenLog);
|
|
||||||
//consoleClear();
|
|
||||||
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
changeFile(dirList.files[fileNum - dirList.dirNum - 1], &playbackInfo);
|
||||||
error = 0;
|
error = 0;
|
||||||
consoleSelect(&bottomScreen);
|
|
||||||
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) err_print("Unable to list directory.");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* After 1000ms, update playback time. */
|
/* Render GUI elements */
|
||||||
while(osGetTime() - mill > 1000)
|
const char** fileList;
|
||||||
|
int fileListCount;
|
||||||
|
buildFileListForGUI(dirList, &fileList, &fileListCount, from);
|
||||||
|
|
||||||
|
/* Display metadata if we have any */
|
||||||
|
if(currentMetadata.title[0] || currentMetadata.artist[0] || currentMetadata.album[0])
|
||||||
{
|
{
|
||||||
consoleSelect(&topScreenLog);
|
const char* currentFile = (fileNum > 0 && fileNum <= dirList.dirNum + dirList.fileNum) ?
|
||||||
/* Position cursor at bottom of log area for time display */
|
(fileNum > dirList.dirNum ? dirList.files[fileNum - dirList.dirNum - 1] : "..") : "";
|
||||||
printf("\033[29;0H\033[K"); /* Move to line 29, clear line */
|
guiDisplayMetadata(¤tMetadata, currentFile);
|
||||||
|
|
||||||
/* Avoid divide by zero. */
|
|
||||||
if(playbackInfo.samples_per_second == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
{
|
|
||||||
unsigned hr, min, sec;
|
|
||||||
size_t seconds_played;
|
|
||||||
|
|
||||||
seconds_played = playbackInfo.samples_played / playbackInfo.samples_per_second;
|
|
||||||
|
|
||||||
hr = (seconds_played/3600);
|
|
||||||
min = (seconds_played - (3600*hr))/60;
|
|
||||||
sec = (seconds_played -(3600*hr)-(min*60));
|
|
||||||
|
|
||||||
printf("%02d:%02d:%02d", hr, min, sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(playbackInfo.samples_total != 0)
|
|
||||||
{
|
|
||||||
unsigned hr, min, sec;
|
|
||||||
size_t seconds_total;
|
|
||||||
|
|
||||||
seconds_total = playbackInfo.samples_total / playbackInfo.samples_per_second;
|
|
||||||
|
|
||||||
hr = (seconds_total/3600);
|
|
||||||
min = (seconds_total - (3600*hr))/60;
|
|
||||||
sec = (seconds_total -(3600*hr)-(min*60));
|
|
||||||
|
|
||||||
printf(" %02d:%02d:%02d", hr, min, sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Display file list on bottom screen */
|
||||||
|
guiDisplayFileList(fileList, fileListCount, fileNum, from);
|
||||||
|
|
||||||
|
/* Display logs on top screen */
|
||||||
|
guiDisplayLog((const char**)logMessages, logMessageCount, logScroll);
|
||||||
|
|
||||||
|
/* Display playback status */
|
||||||
|
if(playbackInfo.samples_per_second > 0)
|
||||||
|
{
|
||||||
|
float position = (float)playbackInfo.samples_played / playbackInfo.samples_per_second;
|
||||||
|
float duration = (float)playbackInfo.samples_total / playbackInfo.samples_per_second;
|
||||||
|
guiDisplayPlaybackStatus(isPlaying(), isPaused(), position, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Display version */
|
||||||
|
guiDisplayVersion(MICE_VERSION);
|
||||||
|
|
||||||
|
/* End GUI frame */
|
||||||
|
guiEndFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
puts("Exiting...");
|
addLogMessage("Exiting...");
|
||||||
runThreads = false;
|
runThreads = false;
|
||||||
clearMetadata(¤tMetadata);
|
clearMetadata(¤tMetadata);
|
||||||
svcSignalEvent(playbackFailEvent);
|
svcSignalEvent(playbackFailEvent);
|
||||||
changeFile(NULL, &playbackInfo);
|
changeFile(NULL, &playbackInfo);
|
||||||
|
|
||||||
gfxExit();
|
/* Cleanup GUI */
|
||||||
|
guiExit();
|
||||||
|
|
||||||
|
/* Cleanup log messages */
|
||||||
|
for(int i = 0; i < logMessageCount; i++)
|
||||||
|
free(logMessages[i]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
puts("A fatal error occurred. Press START to exit.");
|
addLogMessage("A fatal error occurred. Press START to exit.");
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "all.h"
|
#include "all.h"
|
||||||
|
#include "gui.h"
|
||||||
|
|
||||||
/* Internal helper functions */
|
/* Internal helper functions */
|
||||||
static int extractId3v2Metadata(FILE* fp, struct metadata_t* metadata);
|
static int extractId3v2Metadata(FILE* fp, struct metadata_t* metadata);
|
||||||
@@ -96,56 +97,11 @@ void clearMetadata(struct metadata_t* metadata)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Display metadata on the top screen
|
* Display metadata on the top screen
|
||||||
|
* (Now uses GUI rendering - this is a wrapper for compatibility)
|
||||||
*/
|
*/
|
||||||
void displayMetadata(struct metadata_t* metadata, const char* filename)
|
void displayMetadata(struct metadata_t* metadata, const char* filename)
|
||||||
{
|
{
|
||||||
if(!metadata || !filename)
|
guiDisplayMetadata(metadata, filename);
|
||||||
return;
|
|
||||||
|
|
||||||
/* Clear the top screen info area */
|
|
||||||
consoleClear();
|
|
||||||
|
|
||||||
/* Extract just the filename without path and extension for fallback */
|
|
||||||
const char* basename = strrchr(filename, '/');
|
|
||||||
if(!basename)
|
|
||||||
basename = filename;
|
|
||||||
else
|
|
||||||
basename++; /* Skip the '/' */
|
|
||||||
|
|
||||||
/* Remove file extension for display */
|
|
||||||
char displayName[64];
|
|
||||||
strncpy(displayName, basename, sizeof(displayName) - 1);
|
|
||||||
displayName[sizeof(displayName) - 1] = '\0';
|
|
||||||
char* dot = strrchr(displayName, '.');
|
|
||||||
if(dot) *dot = '\0';
|
|
||||||
|
|
||||||
/* Display song title */
|
|
||||||
if(metadata->title[0])
|
|
||||||
printf("%.47s\n", metadata->title);
|
|
||||||
else
|
|
||||||
printf("%.47s\n", displayName);
|
|
||||||
|
|
||||||
/* Display album */
|
|
||||||
if(metadata->album[0])
|
|
||||||
printf("%.47s\n", metadata->album);
|
|
||||||
else
|
|
||||||
printf("Unknown Album\n");
|
|
||||||
|
|
||||||
/* Display artist with album art indicator */
|
|
||||||
if(metadata->artist[0])
|
|
||||||
{
|
|
||||||
printf("%.45s", metadata->artist);
|
|
||||||
if(metadata->hasAlbumArt)
|
|
||||||
printf(" 🖼️");
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Unknown Artist");
|
|
||||||
if(metadata->hasAlbumArt)
|
|
||||||
printf(" 🖼️");
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ bool isPlaying(void)
|
|||||||
return !stop;
|
return !stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether playback is currently paused.
|
||||||
|
*/
|
||||||
|
bool isPaused(void)
|
||||||
|
{
|
||||||
|
if(stop)
|
||||||
|
return false;
|
||||||
|
return ndspChnIsPaused(CHANNEL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should only be called from a new thread only, and have only one playback
|
* Should only be called from a new thread only, and have only one playback
|
||||||
* thread at time. This function has not been written for more than one
|
* thread at time. This function has not been written for more than one
|
||||||
|
|||||||
Reference in New Issue
Block a user