diff --git a/CMakeLists.txt b/CMakeLists.txt index a9876a5..bdde90f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,20 @@ cmake_minimum_required(VERSION 2.8) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) - if(DEFINED ENV{VITASDK}) - set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file") + if(DEFINED ENV{DOLCESDK}) + set(CMAKE_TOOLCHAIN_FILE "$ENV{DOLCESDK}/share/dolce.toolchain.cmake" CACHE PATH "toolchain file") else() - message(FATAL_ERROR "Please define VITASDK to point to your SDK path!") + message(FATAL_ERROR "Please define DOLCESDK to point to your SDK path!") endif() endif() +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/boot_param.bin + COMMAND dolce-make-bootparam app_memsize 0x4000 attribute 0x02 ${CMAKE_CURRENT_BINARY_DIR}/boot_param.bin +) + project(ElevenMPV) -include("${VITASDK}/share/vita.cmake" REQUIRED) +include("${DOLCESDK}/share/dolce.cmake" REQUIRED) set(VITA_APP_NAME "Eleven Music Player") set(VITA_TITLEID "ELEVENMPV") @@ -17,7 +22,6 @@ set(VITA_VERSION "02.10") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall -Werror") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1") FUNCTION(ADD_RESOURCES out_var) SET(result) @@ -80,10 +84,10 @@ add_executable(${PROJECT_NAME} ) target_link_libraries(${PROJECT_NAME} - vita2d + vita2d_sys freetype png - jpeg + SceJpeg_stub z c FLAC @@ -110,8 +114,10 @@ target_link_libraries(${PROJECT_NAME} SceTouch_stub ) -vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME} UNSAFE) -vita_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} ${PROJECT_NAME}.self +set(DOLCE_MKSFOEX_FLAGS "${DOLCE_MKSFOEX_FLAGS} -d ATTRIBUTE=17731976 -s CATEGORY=gdc" -d PARENTAL_LEVEL=1) + +dolce_create_self(${PROJECT_NAME}.self ${PROJECT_NAME} UNSAFE BOOT_PARAM ${CMAKE_CURRENT_BINARY_DIR}/boot_param.bin) +dolce_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} ${PROJECT_NAME}.self VERSION ${VITA_VERSION} NAME ${VITA_APP_NAME} FILE sce_sys/icon0.png sce_sys/icon0.png diff --git a/include/audio/audio.h b/include/audio/audio.h index fea6061..3a4efb5 100644 --- a/include/audio/audio.h +++ b/include/audio/audio.h @@ -2,7 +2,7 @@ #define _ELEVENMPV_AUDIO_H_ #include -#include +#include extern SceBool playing, paused; diff --git a/include/common.h b/include/common.h index db63f5f..469f749 100644 --- a/include/common.h +++ b/include/common.h @@ -3,7 +3,7 @@ #include #include -#include +#include /// Checks whether a result code indicates success. #define R_SUCCEEDED(res) ((res)>=0) diff --git a/include/textures.h b/include/textures.h index e3c0f51..ca5d1c1 100644 --- a/include/textures.h +++ b/include/textures.h @@ -1,7 +1,7 @@ #ifndef _ELEVENMPV_TEXTURES_H_ #define _ELEVENMPV_TEXTURES_H_ -#include +#include vita2d_texture *icon_dir, *icon_file, *icon_audio, *battery_20, *battery_20_charging, *battery_30, *battery_30_charging, *battery_50, *battery_50_charging, \ *battery_60, *battery_60_charging, *battery_80, *battery_80_charging, *battery_90, *battery_90_charging, *battery_full, *battery_full_charging, \ diff --git a/include/utils.h b/include/utils.h index 60495dd..2d6ac73 100644 --- a/include/utils.h +++ b/include/utils.h @@ -13,5 +13,6 @@ char *Utils_Basename(const char *filename); void Utils_InitPowerTick(void); void Utils_LockPower(void); void Utils_UnlockPower(void); +int Utils_AppStatusIsRunning(void); #endif diff --git a/source/main.c b/source/main.c index 3323507..18e640e 100644 --- a/source/main.c +++ b/source/main.c @@ -1,54 +1,69 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common.h" -#include "config.h" -#include "dirbrowse.h" -#include "fs.h" -#include "menu_displayfiles.h" -#include "textures.h" -#include "touch.h" -#include "utils.h" - -int main(int argc, char *argv[]) { - vita2d_init(); - font = vita2d_load_font_file("app0:Roboto-Regular.ttf"); - Textures_Load(); - - sceIoMkdir("ux0:data/ElevenMPV", 0777); - Config_Load(); - Config_GetLastDirectory(); - - Utils_InitAppUtil(); - SCE_CTRL_ENTER = Utils_GetEnterButton(); - SCE_CTRL_CANCEL = Utils_GetCancelButton(); - - sceAppMgrAcquireBgmPort(); - - Touch_Init(); - - sceShellUtilInitEvents(0); - sceSysmoduleLoadModule(SCE_SYSMODULE_MUSIC_EXPORT); - Utils_InitPowerTick(); - - Menu_DisplayFiles(); - - sceSysmoduleUnloadModule(SCE_SYSMODULE_MUSIC_EXPORT); - - Touch_Shutdown(); - sceAppMgrReleaseBgmPort(); - Utils_TermAppUtil(); - - Textures_Free(); - vita2d_free_font(font); - vita2d_fini(); - - sceKernelExitProcess(0); - return 0; -} +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "config.h" +#include "dirbrowse.h" +#include "fs.h" +#include "menu_displayfiles.h" +#include "textures.h" +#include "touch.h" +#include "utils.h" + +#define CLIB_HEAP_SIZE 1 * 1024 * 1024 + +int _newlib_heap_size_user = 1 * 1024 * 1024; + +int sceAppMgrAcquireBgmPortForMusicPlayer(void); + +int main(int argc, char *argv[]) { + + void* clibm_base; + void* mspace; + SceUID clib_heap = sceKernelAllocMemBlock("ClibHeap", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, CLIB_HEAP_SIZE, NULL); + sceKernelGetMemBlockBase(clib_heap, &clibm_base); + mspace = sceClibMspaceCreate(clibm_base, CLIB_HEAP_SIZE); + + vita2d_clib_pass_mspace(mspace); + vita2d_init(); + font = vita2d_load_font_file("app0:Roboto-Regular.ttf"); + Textures_Load(); + + sceIoMkdir("ux0:data/ElevenMPV", 0777); + Config_Load(); + Config_GetLastDirectory(); + + Utils_InitAppUtil(); + SCE_CTRL_ENTER = Utils_GetEnterButton(); + SCE_CTRL_CANCEL = Utils_GetCancelButton(); + + sceAppMgrAcquireBgmPortForMusicPlayer(); + + Touch_Init(); + + sceShellUtilInitEvents(0); + sceSysmoduleLoadModule(SCE_SYSMODULE_MUSIC_EXPORT); + Utils_InitPowerTick(); + + Menu_DisplayFiles(); + + sceSysmoduleUnloadModule(SCE_SYSMODULE_MUSIC_EXPORT); + + Touch_Shutdown(); + sceAppMgrReleaseBgmPort(); + Utils_TermAppUtil(); + + Textures_Free(); + vita2d_free_font(font); + vita2d_fini(); + + sceKernelExitProcess(0); + return 0; +} diff --git a/source/menus/menu_audioplayer.c b/source/menus/menu_audioplayer.c index 6351ea2..87c1992 100644 --- a/source/menus/menu_audioplayer.c +++ b/source/menus/menu_audioplayer.c @@ -1,311 +1,311 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "audio.h" -#include "common.h" -#include "config.h" -#include "fs.h" -#include "menu_displayfiles.h" -#include "status_bar.h" -#include "touch.h" -#include "textures.h" -#include "utils.h" - -#define BUTTON_WIDTH 68 -#define BUTTON_HEIGHT 68 - -typedef enum { - MUSIC_STATE_NONE, // 0 - MUSIC_STATE_REPEAT, // 1 - MUSIC_STATE_SHUFFLE // 2 -} Music_State; - -static char playlist[1024][512]; -static int count = 0, selection = 0, state = 0; -static int length_time_width = 0; -char *position_time = NULL, *length_time = NULL, *filename = NULL; - -static int Menu_GetMusicList(void) { - SceUID dir = 0; - - if (R_SUCCEEDED(dir = sceIoDopen(cwd))) { - int entryCount = 0, i = 0; - SceIoDirent *entries = (SceIoDirent *)calloc(MAX_FILES, sizeof(SceIoDirent)); - - while (sceIoDread(dir, &entries[entryCount]) > 0) - entryCount++; - - sceIoDclose(dir); - qsort(entries, entryCount, sizeof(SceIoDirent), Utils_Alphasort); - - for (i = 0; i < entryCount; i++) { - if ((!strncasecmp(FS_GetFileExt(entries[i].d_name), "flac", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "it", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mod", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mp3", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "ogg", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "opus", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "s3m", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "wav", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "xm", 4))) { - strcpy(playlist[count], cwd); - strcpy(playlist[count] + strlen(playlist[count]), entries[i].d_name); - count++; - } - } - - free(entries); - } - else { - sceIoDclose(dir); - return dir; - } - - return 0; -} - -static int Music_GetCurrentIndex(char *path) { - for(int i = 0; i < count; ++i) { - if (!strcmp(playlist[i], path)) - return i; - } - - return 0; -} - -static void Menu_ConvertSecondsToString(char *string, SceUInt64 seconds) { - int h = 0, m = 0, s = 0; - h = (seconds / 3600); - m = (seconds - (3600 * h)) / 60; - s = (seconds - (3600 * h) - (m * 60)); - - if (h > 0) - snprintf(string, 35, "%02d:%02d:%02d", h, m, s); - else - snprintf(string, 35, "%02d:%02d", m, s); -} - -static void Menu_InitMusic(char *path) { - Audio_Init(path); - if (sceAudioOutSetAlcMode(config.alc_mode) < 0) - return; - - filename = malloc(128); - snprintf(filename, 128, Utils_Basename(path)); - position_time = malloc(35); - length_time = malloc(35); - length_time_width = 0; - - Menu_ConvertSecondsToString(length_time, Audio_GetLengthSeconds()); - length_time_width = vita2d_font_text_width(font, 25, length_time); - selection = Music_GetCurrentIndex(path); -} - -static void Music_HandleNext(SceBool forward, int state) { - if (state == MUSIC_STATE_NONE) { - if (forward) - selection++; - else - selection--; - } - else if (state == MUSIC_STATE_SHUFFLE) { - int old_selection = selection; - time_t t; - srand((unsigned) time(&t)); - selection = rand() % (count - 1); - - if (selection == old_selection) - selection--; - } - - Utils_SetMax(&selection, 0, (count - 1)); - Utils_SetMin(&selection, (count - 1), 0); - - Audio_Stop(); - - free(filename); - free(length_time); - free(position_time); - - if ((metadata.has_meta) && (metadata.cover_image)) { - vita2d_wait_rendering_done(); - vita2d_free_texture(metadata.cover_image); - } - - Audio_Term(); - Menu_InitMusic(playlist[selection]); -} - -void Menu_PlayAudio(char *path) { - Menu_GetMusicList(); - Menu_InitMusic(path); - - Utils_LockPower(); - - while(SCE_TRUE) { - vita2d_start_drawing(); - vita2d_clear_screen(); - - vita2d_draw_texture(default_artwork_blur, 0, 0); - vita2d_draw_rectangle(0, 0, 960, 40, RGBA8(97, 97, 97, 255)); - vita2d_draw_texture(icon_back, 10, 60); - StatusBar_Display(); - - if ((metadata.has_meta) && (metadata.title[0] != '\0') && (metadata.artist[0] != '\0')) { - vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(metadata.title))) + 20, RGBA8(255, 255, 255, 255), 25, strupr(metadata.title)); - vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(metadata.artist))) + 55, RGBA8(255, 255, 255, 255), 25, strupr(metadata.artist)); - } - else if ((metadata.has_meta) && (metadata.title[0] != '\0')) - vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(metadata.title))) + 15, RGBA8(255, 255, 255, 255), 25, strupr(metadata.title)); - else - vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(filename))) + 15, RGBA8(255, 255, 255, 255), 25, filename); - - vita2d_draw_rectangle(0, 124, 400, 400, RGBA8(97, 97, 97, 255)); - - if ((metadata.has_meta) && (metadata.cover_image)) - vita2d_draw_texture_scale(metadata.cover_image, 0, 124, 400.0f/vita2d_texture_get_width(metadata.cover_image), 400.0f/vita2d_texture_get_height(metadata.cover_image)); - else - vita2d_draw_texture(default_artwork, 0, 124); // Default album art - - vita2d_draw_rectangle(410, 124, 550, 400, RGBA8(45, 48, 50, 255)); // Draw info box (outer) - vita2d_draw_rectangle(420, 134, 530, 380, RGBA8(46, 49, 51, 255)); // Draw info box (inner) - - if ((metadata.has_meta) && (metadata.album[0] != '\0')) - vita2d_font_draw_textf(font, 425, 155, RGBA8(255, 255, 255, 255), 25, "Album: %s\n", metadata.album); - - if ((metadata.has_meta) && (metadata.year[0] != '\0')) - vita2d_font_draw_textf(font, 425, 185, RGBA8(255, 255, 255, 255), 25, "Year: %s\n", metadata.year); - - if ((metadata.has_meta) && (metadata.genre[0] != '\0')) - vita2d_font_draw_textf(font, 425, 215, RGBA8(255, 255, 255, 255), 25, "Genre: %s\n", metadata.genre); - - if (!Audio_IsPaused()) - vita2d_draw_texture(btn_pause, 410 + ((550 - BUTTON_WIDTH) / 2), 124 + ((400 - BUTTON_HEIGHT) / 2)); // Playing - else - vita2d_draw_texture(btn_play, 410 + ((550 - BUTTON_WIDTH) / 2), 124 + ((400 - BUTTON_HEIGHT) / 2)); // Paused - - vita2d_draw_texture(btn_rewind, 410 + ((550 - BUTTON_WIDTH) / 2) - 136, 124 + ((400 - BUTTON_HEIGHT) / 2)); - vita2d_draw_texture(btn_forward, 410 + ((550 - BUTTON_WIDTH) / 2) + 136, 124 + ((400 - BUTTON_HEIGHT) / 2)); - - vita2d_draw_texture(state == MUSIC_STATE_SHUFFLE? btn_shuffle_overlay : btn_shuffle, 410 + ((550 - BUTTON_WIDTH) / 2) - 90, 124 + ((400 - BUTTON_HEIGHT) / 2) + 100); - vita2d_draw_texture(state == MUSIC_STATE_REPEAT? btn_repeat_overlay : btn_repeat, 410 + ((550 - BUTTON_WIDTH) / 2) + 90, 124 + ((400 - BUTTON_HEIGHT) / 2) + 100); - - Menu_ConvertSecondsToString(position_time, Audio_GetPositionSeconds()); - vita2d_font_draw_text(font, 460, 480, RGBA8(255, 255, 255, 255), 25, position_time); - vita2d_font_draw_text(font, 910 - length_time_width, 480, RGBA8(255, 255, 255, 255), 25, length_time); - vita2d_draw_rectangle(460, 490, 450, 4, RGBA8(97, 97, 97, 255)); - vita2d_draw_rectangle(460, 490, (((double)Audio_GetPosition()/(double)Audio_GetLength()) * 450.0), 4, RGBA8(255, 255, 255, 255)); - - vita2d_end_drawing(); - vita2d_swap_buffers(); - - if (!playing) { - if (state == MUSIC_STATE_NONE) { - if (count != 0) - Music_HandleNext(SCE_TRUE, MUSIC_STATE_NONE); - } - else if (state == MUSIC_STATE_REPEAT) - Music_HandleNext(SCE_FALSE, MUSIC_STATE_REPEAT); - else if (state == MUSIC_STATE_SHUFFLE) { - if (count != 0) - Music_HandleNext(SCE_FALSE, MUSIC_STATE_SHUFFLE); - } - } - - Utils_ReadControls(); - Touch_Update(); - - if (pressed & SCE_CTRL_ENTER) - Audio_Pause(); - - if (Touch_CheckHeld() && Touch_GetX() >= 460 && Touch_GetX() <= 910 && Touch_GetY() >= 480 && Touch_GetY() <= 505) { - // Pause first if not paused. - if (!Audio_IsPaused()) - Audio_Pause(); - - Audio_Seek(Touch_GetX() - 460); - - // Unpause. - if (Audio_IsPaused()) - Audio_Pause(); - } - - if (pressed & SCE_CTRL_TRIANGLE) { - if (state == MUSIC_STATE_SHUFFLE) - state = MUSIC_STATE_NONE; - else - state = MUSIC_STATE_SHUFFLE; - } - else if (pressed & SCE_CTRL_SQUARE) { - if (state == MUSIC_STATE_REPEAT) - state = MUSIC_STATE_NONE; - else - state = MUSIC_STATE_REPEAT; - } - - if (pressed & SCE_CTRL_LTRIGGER) { - if (count != 0) - Music_HandleNext(SCE_FALSE, MUSIC_STATE_NONE); - } - else if (pressed & SCE_CTRL_RTRIGGER) { - if (count != 0) - Music_HandleNext(SCE_TRUE, MUSIC_STATE_NONE); - } - - if (pressed & SCE_CTRL_START) - scePowerRequestDisplayOff(); - - if (pressed & SCE_CTRL_CANCEL) - break; - - if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2)), (124 + ((400 - BUTTON_HEIGHT) / 2)), ((410 + ((550 - BUTTON_WIDTH) / 2)) + BUTTON_WIDTH), - ((124 + ((400 - BUTTON_HEIGHT) / 2)) + BUTTON_HEIGHT))) - Audio_Pause(); - - if (Touch_Position(10, 57, 60, 107)) - break; - - if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) - 136), (124 + ((400 - BUTTON_HEIGHT) / 2)), ((410 + ((550 - BUTTON_WIDTH) / 2) - 136) + BUTTON_WIDTH), - ((124 + ((400 - BUTTON_HEIGHT) / 2)) + BUTTON_HEIGHT))) { - if (count != 0) - Music_HandleNext(SCE_FALSE, MUSIC_STATE_NONE); - } - else if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) + 136), (124 + ((400 - BUTTON_HEIGHT) / 2)), ((410 + ((550 - BUTTON_WIDTH) / 2) + 136) + BUTTON_WIDTH), - ((124 + ((400 - BUTTON_HEIGHT) / 2)) + BUTTON_HEIGHT))) { - if (count != 0) - Music_HandleNext(SCE_TRUE, MUSIC_STATE_NONE); - } - - if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) - 90), (124 + ((400 - BUTTON_HEIGHT) / 2) + 100), ((410 + ((550 - BUTTON_WIDTH) / 2) - 90) + BUTTON_WIDTH), - ((124 + ((400 - BUTTON_HEIGHT) / 2) + 100) + BUTTON_HEIGHT))) { - if (state == MUSIC_STATE_SHUFFLE) - state = MUSIC_STATE_NONE; - else - state = MUSIC_STATE_SHUFFLE; - } - else if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) + 90), (124 + ((400 - BUTTON_HEIGHT) / 2) + 100), ((410 + ((550 - BUTTON_WIDTH) / 2) + 90) + BUTTON_WIDTH), - ((124 + ((400 - BUTTON_HEIGHT) / 2) + 100) + BUTTON_HEIGHT))) { - if (state == MUSIC_STATE_REPEAT) - state = MUSIC_STATE_NONE; - else - state = MUSIC_STATE_REPEAT; - } - } - - free(filename); - free(length_time); - free(position_time); - - if ((metadata.has_meta) && (metadata.cover_image)) { - vita2d_wait_rendering_done(); - vita2d_free_texture(metadata.cover_image); - } - - Audio_Stop(); - Audio_Term(); - count = 0; - Touch_Reset(); - Utils_UnlockPower(); - Menu_DisplayFiles(); -} +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "audio.h" +#include "common.h" +#include "config.h" +#include "fs.h" +#include "menu_displayfiles.h" +#include "status_bar.h" +#include "touch.h" +#include "textures.h" +#include "utils.h" + +#define BUTTON_WIDTH 68 +#define BUTTON_HEIGHT 68 + +typedef enum { + MUSIC_STATE_NONE, // 0 + MUSIC_STATE_REPEAT, // 1 + MUSIC_STATE_SHUFFLE // 2 +} Music_State; + +static char playlist[1024][512]; +static int count = 0, selection = 0, state = 0; +static int length_time_width = 0; +char *position_time = NULL, *length_time = NULL, *filename = NULL; + +extern int isFG; + +static int Menu_GetMusicList(void) { + SceUID dir = 0; + + if (R_SUCCEEDED(dir = sceIoDopen(cwd))) { + int entryCount = 0, i = 0; + SceIoDirent *entries = (SceIoDirent *)calloc(MAX_FILES, sizeof(SceIoDirent)); + + while (sceIoDread(dir, &entries[entryCount]) > 0) + entryCount++; + + sceIoDclose(dir); + qsort(entries, entryCount, sizeof(SceIoDirent), Utils_Alphasort); + + for (i = 0; i < entryCount; i++) { + if ((!strncasecmp(FS_GetFileExt(entries[i].d_name), "flac", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "it", 4)) || + (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mod", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mp3", 4)) || + (!strncasecmp(FS_GetFileExt(entries[i].d_name), "ogg", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "opus", 4)) || + (!strncasecmp(FS_GetFileExt(entries[i].d_name), "s3m", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "wav", 4)) || + (!strncasecmp(FS_GetFileExt(entries[i].d_name), "xm", 4))) { + strcpy(playlist[count], cwd); + strcpy(playlist[count] + strlen(playlist[count]), entries[i].d_name); + count++; + } + } + + free(entries); + } + else { + sceIoDclose(dir); + return dir; + } + + return 0; +} + +static int Music_GetCurrentIndex(char *path) { + for(int i = 0; i < count; ++i) { + if (!strcmp(playlist[i], path)) + return i; + } + + return 0; +} + +static void Menu_ConvertSecondsToString(char *string, SceUInt64 seconds) { + int h = 0, m = 0, s = 0; + h = (seconds / 3600); + m = (seconds - (3600 * h)) / 60; + s = (seconds - (3600 * h) - (m * 60)); + + if (h > 0) + snprintf(string, 35, "%02d:%02d:%02d", h, m, s); + else + snprintf(string, 35, "%02d:%02d", m, s); +} + +static void Menu_InitMusic(char *path) { + Audio_Init(path); + if (sceAudioOutSetAlcMode(config.alc_mode) < 0) + return; + + filename = malloc(128); + snprintf(filename, 128, Utils_Basename(path)); + position_time = malloc(35); + length_time = malloc(35); + length_time_width = 0; + + Menu_ConvertSecondsToString(length_time, Audio_GetLengthSeconds()); + length_time_width = vita2d_font_text_width(font, 25, length_time); + selection = Music_GetCurrentIndex(path); +} + +static void Music_HandleNext(SceBool forward, int state) { + if (state == MUSIC_STATE_NONE) { + if (forward) + selection++; + else + selection--; + } + else if (state == MUSIC_STATE_SHUFFLE) { + int old_selection = selection; + time_t t; + srand((unsigned) time(&t)); + selection = rand() % (count - 1); + + if (selection == old_selection) + selection--; + } + + Utils_SetMax(&selection, 0, (count - 1)); + Utils_SetMin(&selection, (count - 1), 0); + + Audio_Stop(); + + free(filename); + free(length_time); + free(position_time); + + if ((metadata.has_meta) && (metadata.cover_image)) { + vita2d_wait_rendering_done(); + vita2d_free_texture(metadata.cover_image); + } + + Audio_Term(); + Menu_InitMusic(playlist[selection]); +} + +void Menu_PlayAudio(char *path) { + Menu_GetMusicList(); + Menu_InitMusic(path); + + Utils_LockPower(); + vita2d_set_clear_color(RGBA8(5, 5, 5, 255)); + + while(SCE_TRUE) { + vita2d_start_drawing(); + if (isFG) { + vita2d_clear_screen(); + + vita2d_draw_texture(icon_back, 10, 60); + + if ((metadata.has_meta) && (metadata.title[0] != '\0') && (metadata.artist[0] != '\0')) { + vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(metadata.title))) + 20, RGBA8(255, 255, 255, 255), 25, strupr(metadata.title)); + vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(metadata.artist))) + 55, RGBA8(255, 255, 255, 255), 25, strupr(metadata.artist)); + } + else if ((metadata.has_meta) && (metadata.title[0] != '\0')) + vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(metadata.title))) + 15, RGBA8(255, 255, 255, 255), 25, strupr(metadata.title)); + else + vita2d_font_draw_text(font, 80, 22 + (80 - vita2d_font_text_height(font, 25, strupr(filename))) + 15, RGBA8(255, 255, 255, 255), 25, filename); + + vita2d_draw_rectangle(0, 124, 400, 400, RGBA8(97, 97, 97, 255)); + + vita2d_draw_rectangle(410, 124, 550, 400, RGBA8(45, 48, 50, 255)); // Draw info box (outer) + vita2d_draw_rectangle(420, 134, 530, 380, RGBA8(46, 49, 51, 255)); // Draw info box (inner) + + if ((metadata.has_meta) && (metadata.album[0] != '\0')) + vita2d_font_draw_textf(font, 425, 155, RGBA8(255, 255, 255, 255), 25, "Album: %s\n", metadata.album); + + if ((metadata.has_meta) && (metadata.year[0] != '\0')) + vita2d_font_draw_textf(font, 425, 185, RGBA8(255, 255, 255, 255), 25, "Year: %s\n", metadata.year); + + if ((metadata.has_meta) && (metadata.genre[0] != '\0')) + vita2d_font_draw_textf(font, 425, 215, RGBA8(255, 255, 255, 255), 25, "Genre: %s\n", metadata.genre); + + if (!Audio_IsPaused()) + vita2d_draw_texture(btn_pause, 410 + ((550 - BUTTON_WIDTH) / 2), 124 + ((400 - BUTTON_HEIGHT) / 2)); // Playing + else + vita2d_draw_texture(btn_play, 410 + ((550 - BUTTON_WIDTH) / 2), 124 + ((400 - BUTTON_HEIGHT) / 2)); // Paused + + vita2d_draw_texture(btn_rewind, 410 + ((550 - BUTTON_WIDTH) / 2) - 136, 124 + ((400 - BUTTON_HEIGHT) / 2)); + vita2d_draw_texture(btn_forward, 410 + ((550 - BUTTON_WIDTH) / 2) + 136, 124 + ((400 - BUTTON_HEIGHT) / 2)); + + vita2d_draw_texture(state == MUSIC_STATE_SHUFFLE ? btn_shuffle_overlay : btn_shuffle, 410 + ((550 - BUTTON_WIDTH) / 2) - 90, 124 + ((400 - BUTTON_HEIGHT) / 2) + 100); + vita2d_draw_texture(state == MUSIC_STATE_REPEAT ? btn_repeat_overlay : btn_repeat, 410 + ((550 - BUTTON_WIDTH) / 2) + 90, 124 + ((400 - BUTTON_HEIGHT) / 2) + 100); + + Menu_ConvertSecondsToString(position_time, Audio_GetPositionSeconds()); + vita2d_font_draw_text(font, 460, 480, RGBA8(255, 255, 255, 255), 25, position_time); + vita2d_font_draw_text(font, 910 - length_time_width, 480, RGBA8(255, 255, 255, 255), 25, length_time); + vita2d_draw_rectangle(460, 490, 450, 4, RGBA8(97, 97, 97, 255)); + vita2d_draw_rectangle(460, 490, (((double)Audio_GetPosition() / (double)Audio_GetLength()) * 450.0), 4, RGBA8(255, 255, 255, 255)); + } + else {} + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_end_shfb(); + + if (!playing) { + if (state == MUSIC_STATE_NONE) { + if (count != 0) + Music_HandleNext(SCE_TRUE, MUSIC_STATE_NONE); + } + else if (state == MUSIC_STATE_REPEAT) + Music_HandleNext(SCE_FALSE, MUSIC_STATE_REPEAT); + else if (state == MUSIC_STATE_SHUFFLE) { + if (count != 0) + Music_HandleNext(SCE_FALSE, MUSIC_STATE_SHUFFLE); + } + } + + Utils_ReadControls(); + Touch_Update(); + + if (pressed & SCE_CTRL_ENTER) + Audio_Pause(); + + if (Touch_CheckHeld() && Touch_GetX() >= 460 && Touch_GetX() <= 910 && Touch_GetY() >= 480 && Touch_GetY() <= 505) { + // Pause first if not paused. + if (!Audio_IsPaused()) + Audio_Pause(); + + Audio_Seek(Touch_GetX() - 460); + + // Unpause. + if (Audio_IsPaused()) + Audio_Pause(); + } + + if (pressed & SCE_CTRL_TRIANGLE) { + if (state == MUSIC_STATE_SHUFFLE) + state = MUSIC_STATE_NONE; + else + state = MUSIC_STATE_SHUFFLE; + } + else if (pressed & SCE_CTRL_SQUARE) { + if (state == MUSIC_STATE_REPEAT) + state = MUSIC_STATE_NONE; + else + state = MUSIC_STATE_REPEAT; + } + + if (pressed & SCE_CTRL_LTRIGGER) { + if (count != 0) + Music_HandleNext(SCE_FALSE, MUSIC_STATE_NONE); + } + else if (pressed & SCE_CTRL_RTRIGGER) { + if (count != 0) + Music_HandleNext(SCE_TRUE, MUSIC_STATE_NONE); + } + + if (pressed & SCE_CTRL_CANCEL) + break; + + if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2)), (124 + ((400 - BUTTON_HEIGHT) / 2)), ((410 + ((550 - BUTTON_WIDTH) / 2)) + BUTTON_WIDTH), + ((124 + ((400 - BUTTON_HEIGHT) / 2)) + BUTTON_HEIGHT))) + Audio_Pause(); + + if (Touch_Position(10, 57, 60, 107)) + break; + + if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) - 136), (124 + ((400 - BUTTON_HEIGHT) / 2)), ((410 + ((550 - BUTTON_WIDTH) / 2) - 136) + BUTTON_WIDTH), + ((124 + ((400 - BUTTON_HEIGHT) / 2)) + BUTTON_HEIGHT))) { + if (count != 0) + Music_HandleNext(SCE_FALSE, MUSIC_STATE_NONE); + } + else if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) + 136), (124 + ((400 - BUTTON_HEIGHT) / 2)), ((410 + ((550 - BUTTON_WIDTH) / 2) + 136) + BUTTON_WIDTH), + ((124 + ((400 - BUTTON_HEIGHT) / 2)) + BUTTON_HEIGHT))) { + if (count != 0) + Music_HandleNext(SCE_TRUE, MUSIC_STATE_NONE); + } + + if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) - 90), (124 + ((400 - BUTTON_HEIGHT) / 2) + 100), ((410 + ((550 - BUTTON_WIDTH) / 2) - 90) + BUTTON_WIDTH), + ((124 + ((400 - BUTTON_HEIGHT) / 2) + 100) + BUTTON_HEIGHT))) { + if (state == MUSIC_STATE_SHUFFLE) + state = MUSIC_STATE_NONE; + else + state = MUSIC_STATE_SHUFFLE; + } + else if (Touch_Position((410 + ((550 - BUTTON_WIDTH) / 2) + 90), (124 + ((400 - BUTTON_HEIGHT) / 2) + 100), ((410 + ((550 - BUTTON_WIDTH) / 2) + 90) + BUTTON_WIDTH), + ((124 + ((400 - BUTTON_HEIGHT) / 2) + 100) + BUTTON_HEIGHT))) { + if (state == MUSIC_STATE_REPEAT) + state = MUSIC_STATE_NONE; + else + state = MUSIC_STATE_REPEAT; + } + + if (Utils_AppStatusIsRunning()) + break; + } + + free(filename); + free(length_time); + free(position_time); + + if ((metadata.has_meta) && (metadata.cover_image)) { + vita2d_wait_rendering_done(); + vita2d_free_texture(metadata.cover_image); + } + + Audio_Stop(); + Audio_Term(); + count = 0; + Touch_Reset(); + Utils_UnlockPower(); + Menu_DisplayFiles(); +} diff --git a/source/menus/menu_displayfiles.c b/source/menus/menu_displayfiles.c index 555a42c..be819b3 100644 --- a/source/menus/menu_displayfiles.c +++ b/source/menus/menu_displayfiles.c @@ -1,60 +1,67 @@ -#include - -#include "common.h" -#include "dirbrowse.h" -#include "menu_settings.h" -#include "status_bar.h" -#include "textures.h" -#include "utils.h" - -static void Menu_HandleControls(void) { - if (file_count > 0) { - if (pressed & SCE_CTRL_UP) - position--; - else if (pressed & SCE_CTRL_DOWN) - position++; - - Utils_SetMax(&position, 0, file_count - 1); - Utils_SetMin(&position, file_count - 1, 0); - - if (pressed & SCE_CTRL_LEFT) - position = 0; - else if (pressed & SCE_CTRL_RIGHT) - position = file_count - 1; - - if (pressed & SCE_CTRL_ENTER) - Dirbrowse_OpenFile(); - } - - if ((strcmp(cwd, root_path) != 0) && (pressed & SCE_CTRL_CANCEL)) { - Dirbrowse_Navigate(SCE_TRUE); - Dirbrowse_PopulateFiles(SCE_TRUE); - } -} - -void Menu_DisplayFiles(void) { - Dirbrowse_PopulateFiles(SCE_FALSE); - vita2d_set_clear_color(RGBA8(250, 250, 250, 255)); - - while (SCE_TRUE) { - vita2d_start_drawing(); - vita2d_clear_screen(); - - vita2d_draw_rectangle(0, 0, 960, 40, RGBA8(40, 40, 40, 255)); - vita2d_draw_rectangle(0, 40, 960, 72, RGBA8(51, 51, 51, 255)); - StatusBar_Display(); - Dirbrowse_DisplayFiles(); - - vita2d_end_drawing(); - vita2d_swap_buffers(); - - Utils_ReadControls(); - Menu_HandleControls(); - - if (pressed & SCE_CTRL_SELECT) - Menu_DisplaySettings(); - - if (pressed & SCE_CTRL_START) - break; - } -} +#include +#include + +#include "common.h" +#include "dirbrowse.h" +#include "menu_settings.h" +#include "status_bar.h" +#include "textures.h" +#include "utils.h" + +extern int isFG; + +static void Menu_HandleControls(void) { + if (file_count > 0) { + if (pressed & SCE_CTRL_UP) + position--; + else if (pressed & SCE_CTRL_DOWN) + position++; + + Utils_SetMax(&position, 0, file_count - 1); + Utils_SetMin(&position, file_count - 1, 0); + + if (pressed & SCE_CTRL_LEFT) + position = 0; + else if (pressed & SCE_CTRL_RIGHT) + position = file_count - 1; + + if (pressed & SCE_CTRL_ENTER) + Dirbrowse_OpenFile(); + } + + if ((strcmp(cwd, root_path) != 0) && (pressed & SCE_CTRL_CANCEL)) { + Dirbrowse_Navigate(SCE_TRUE); + Dirbrowse_PopulateFiles(SCE_TRUE); + } +} + +void Menu_DisplayFiles(void) { + Dirbrowse_PopulateFiles(SCE_FALSE); + vita2d_set_clear_color(RGBA8(250, 250, 250, 255)); + + while (SCE_TRUE) { + vita2d_start_drawing(); + if (isFG) { + vita2d_clear_screen(); + + vita2d_draw_rectangle(0, 0, 960, 112, RGBA8(51, 51, 51, 255)); + Dirbrowse_DisplayFiles(); + } + else {} + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_end_shfb(); + + Utils_ReadControls(); + Menu_HandleControls(); + + if (pressed & SCE_CTRL_SELECT) + Menu_DisplaySettings(); + + if (pressed & SCE_CTRL_START) + break; + + if (Utils_AppStatusIsRunning()) + break; + } +} diff --git a/source/menus/menu_settings.c b/source/menus/menu_settings.c index 1701810..11abb34 100644 --- a/source/menus/menu_settings.c +++ b/source/menus/menu_settings.c @@ -1,358 +1,382 @@ -#include -#include - -#include "config.h" -#include "common.h" -#include "dirbrowse.h" -#include "fs.h" -#include "menu_settings.h" -#include "status_bar.h" -#include "textures.h" -#include "utils.h" - -static void Menu_DisplayDeviceSettings(void) { - int selection = 0, max_items = 2; - - const char *menu_items[] = { - "ux0:/", - "ur0:/", - "uma0:/" - }; - - while (SCE_TRUE) { - vita2d_start_drawing(); - vita2d_clear_screen(); - - vita2d_draw_rectangle(0, 0, 960, 40, RGBA8(40, 40, 40, 255)); - vita2d_draw_rectangle(0, 40, 960, 72, RGBA8(51, 51, 51, 255)); - StatusBar_Display(); - - vita2d_draw_texture(icon_back, 25, 54); - vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Device Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Device Settings"); - - int printed = 0; - - for (int i = 0; i < max_items + 1; i++) { - if (printed == FILES_PER_PAGE) - break; - - if (selection < FILES_PER_PAGE || i > (selection - FILES_PER_PAGE)) { - if (i == selection) - vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); - - vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); - - printed++; - } - } - - vita2d_draw_texture(config.device == 0? radio_on : radio_off, 850, 126); - vita2d_draw_texture(config.device == 1? radio_on : radio_off, 850, 198); - vita2d_draw_texture(config.device == 2? radio_on : radio_off, 850, 270); - - vita2d_end_drawing(); - vita2d_swap_buffers(); - - Utils_ReadControls(); - - if (pressed & SCE_CTRL_CANCEL) - break; - - if (pressed & SCE_CTRL_UP) - selection--; - else if (pressed & SCE_CTRL_DOWN) - selection++; - - Utils_SetMax(&selection, 0, max_items); - Utils_SetMin(&selection, max_items, 0); - - if (pressed & SCE_CTRL_ENTER) { - if (FS_DirExists(menu_items[selection])) { - config.device = selection; - Config_Save(config); - strcpy(root_path, menu_items[config.device]); - strcpy(cwd, root_path); - sceIoRemove("ux0:data/ElevenMPV/lastdir.txt"); - Dirbrowse_PopulateFiles(SCE_TRUE); - } - } - } -} - -static void Menu_DisplaySortSettings(void) { - int selection = 0, max_items = 3; - - const char *menu_items[] = { - "By name (ascending)", - "By name (descending)", - "By size (largest first)", - "By size (smallest first)" - }; - - while (SCE_TRUE) { - vita2d_start_drawing(); - vita2d_clear_screen(); - - vita2d_draw_rectangle(0, 0, 960, 40, RGBA8(40, 40, 40, 255)); - vita2d_draw_rectangle(0, 40, 960, 72, RGBA8(51, 51, 51, 255)); - StatusBar_Display(); - - vita2d_draw_texture(icon_back, 25, 54); - vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Sort Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Sort Settings"); - - int printed = 0; - - for (int i = 0; i < max_items + 1; i++) { - if (printed == FILES_PER_PAGE) - break; - - if (selection < FILES_PER_PAGE || i > (selection - FILES_PER_PAGE)) { - if (i == selection) - vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); - - vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); - - printed++; - } - } - - vita2d_draw_texture(config.sort == 0? radio_on : radio_off, 850, 126); - vita2d_draw_texture(config.sort == 1? radio_on : radio_off, 850, 198); - vita2d_draw_texture(config.sort == 2? radio_on : radio_off, 850, 270); - vita2d_draw_texture(config.sort == 3? radio_on : radio_off, 850, 342); - - vita2d_end_drawing(); - vita2d_swap_buffers(); - - Utils_ReadControls(); - - if (pressed & SCE_CTRL_CANCEL) - break; - - if (pressed & SCE_CTRL_UP) - selection--; - else if (pressed & SCE_CTRL_DOWN) - selection++; - - Utils_SetMax(&selection, 0, max_items); - Utils_SetMin(&selection, max_items, 0); - - if (pressed & SCE_CTRL_ENTER) { - config.sort = selection; - Config_Save(config); - Dirbrowse_PopulateFiles(SCE_TRUE); - } - } -} - -static void Menu_DisplayMetadataSettings(void) { - int selection = 0, max_items = 2; - - const char *menu_items[] = { - "Enable FLAC metadata", - "Enable MP3 metadata", - "Enable OPUS metadata" - }; - - while (SCE_TRUE) { - vita2d_start_drawing(); - vita2d_clear_screen(); - - vita2d_draw_rectangle(0, 0, 960, 40, RGBA8(40, 40, 40, 255)); - vita2d_draw_rectangle(0, 40, 960, 72, RGBA8(51, 51, 51, 255)); - StatusBar_Display(); - - vita2d_draw_texture(icon_back, 25, 54); - vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Metadata Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Metadata Settings"); - - int printed = 0; - - for (int i = 0; i < max_items + 1; i++) { - if (printed == FILES_PER_PAGE) - break; - - if (selection < FILES_PER_PAGE || i > (selection - FILES_PER_PAGE)) { - if (i == selection) - vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); - - vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); - - printed++; - } - } - - vita2d_draw_texture(config.meta_flac == SCE_TRUE? toggle_on : toggle_off, 850, 118); - vita2d_draw_texture(config.meta_mp3 == SCE_TRUE? toggle_on : toggle_off, 850, 190); - vita2d_draw_texture(config.meta_opus == SCE_TRUE? toggle_on : toggle_off, 850, 262); - - vita2d_end_drawing(); - vita2d_swap_buffers(); - - Utils_ReadControls(); - - if (pressed & SCE_CTRL_CANCEL) - break; - - if (pressed & SCE_CTRL_UP) - selection--; - else if (pressed & SCE_CTRL_DOWN) - selection++; - - Utils_SetMax(&selection, 0, max_items); - Utils_SetMin(&selection, max_items, 0); - - if (pressed & SCE_CTRL_ENTER) { - switch (selection) { - case 0: - config.meta_flac = !config.meta_flac; - Config_Save(config); - break; - - case 1: - config.meta_mp3 = !config.meta_mp3; - Config_Save(config); - break; - - case 2: - config.meta_opus = !config.meta_opus; - Config_Save(config); - break; - } - } - } -} - -static void Menu_DisplayALCModeSettings(void) { - int selection = 0, max_items = 1; - - const char *menu_items[] = { - "ALC off", - "ALC mode 1" - //"ALC mode max" // Max doesn't seem to work ? - }; - - while (SCE_TRUE) { - vita2d_start_drawing(); - vita2d_clear_screen(); - - vita2d_draw_rectangle(0, 0, 960, 40, RGBA8(40, 40, 40, 255)); - vita2d_draw_rectangle(0, 40, 960, 72, RGBA8(51, 51, 51, 255)); - StatusBar_Display(); - - vita2d_draw_texture(icon_back, 25, 54); - vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Dynamic Normalizer")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Dynamic Normalizer"); - - int printed = 0; - - for (int i = 0; i < max_items + 1; i++) { - if (printed == FILES_PER_PAGE) - break; - - if (selection < FILES_PER_PAGE || i > (selection - FILES_PER_PAGE)) { - if (i == selection) - vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); - - vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); - - printed++; - } - } - - vita2d_draw_texture(config.alc_mode == 0? radio_on : radio_off, 850, 126); - vita2d_draw_texture(config.alc_mode == 1? radio_on : radio_off, 850, 198); - - vita2d_end_drawing(); - vita2d_swap_buffers(); - - Utils_ReadControls(); - - if (pressed & SCE_CTRL_CANCEL) - break; - - if (pressed & SCE_CTRL_UP) - selection--; - else if (pressed & SCE_CTRL_DOWN) - selection++; - - Utils_SetMax(&selection, 0, max_items); - Utils_SetMin(&selection, max_items, 0); - - if (pressed & SCE_CTRL_ENTER) { - config.alc_mode = selection; - Config_Save(config); - Dirbrowse_PopulateFiles(SCE_TRUE); - } - } -} - -void Menu_DisplaySettings(void) { - int selection = 0, max_items = 3; - - const char *menu_items[] = { - "Device settings", - "Sort settings", - "Metadata settings", - "Dynamic normalizer modes" - }; - - while (SCE_TRUE) { - vita2d_start_drawing(); - vita2d_clear_screen(); - - vita2d_draw_rectangle(0, 0, 960, 40, RGBA8(40, 40, 40, 255)); - vita2d_draw_rectangle(0, 40, 960, 72, RGBA8(51, 51, 51, 255)); - StatusBar_Display(); - - vita2d_draw_texture(icon_back, 25, 54); - vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Settings"); - - int printed = 0; - - for (int i = 0; i < max_items + 1; i++) { - if (printed == FILES_PER_PAGE) - break; - - if (selection < FILES_PER_PAGE || i > (selection - FILES_PER_PAGE)) { - if (i == selection) - vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); - - vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); - - printed++; - } - } - - vita2d_end_drawing(); - vita2d_swap_buffers(); - - Utils_ReadControls(); - - if (pressed & SCE_CTRL_CANCEL) - break; - - if (pressed & SCE_CTRL_UP) - selection--; - else if (pressed & SCE_CTRL_DOWN) - selection++; - - Utils_SetMax(&selection, 0, max_items); - Utils_SetMin(&selection, max_items, 0); - - if (pressed & SCE_CTRL_ENTER) { - switch (selection) { - case 0: - Menu_DisplayDeviceSettings(); - break; - case 1: - Menu_DisplaySortSettings(); - break; - case 2: - Menu_DisplayMetadataSettings(); - break; - case 3: - Menu_DisplayALCModeSettings(); - break; - } - } - } -} +#include +#include +#include + +#include "config.h" +#include "common.h" +#include "dirbrowse.h" +#include "fs.h" +#include "menu_settings.h" +#include "status_bar.h" +#include "textures.h" +#include "utils.h" + +extern int isFG; + +static void Menu_DisplayDeviceSettings(void) { + int selection = 0, max_items = 2; + + const char *menu_items[] = { + "ux0:/", + "ur0:/", + "uma0:/" + }; + + while (SCE_TRUE) { + vita2d_start_drawing(); + if (isFG) { + vita2d_clear_screen(); + + vita2d_draw_rectangle(0, 0, 960, 112, RGBA8(51, 51, 51, 255)); + + vita2d_draw_texture(icon_back, 25, 54); + vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Device Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Device Settings"); + + int printed = 0; + + for (int i = 0; i < max_items + 1; i++) { + if (printed == FILES_PER_PAGE) + break; + + if (selection < FILES_PER_PAGE || i >(selection - FILES_PER_PAGE)) { + if (i == selection) + vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); + + vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); + + printed++; + } + } + + vita2d_draw_texture(config.device == 0 ? radio_on : radio_off, 850, 126); + vita2d_draw_texture(config.device == 1 ? radio_on : radio_off, 850, 198); + vita2d_draw_texture(config.device == 2 ? radio_on : radio_off, 850, 270); + } + else {} + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_end_shfb(); + + Utils_ReadControls(); + + if (pressed & SCE_CTRL_CANCEL) + break; + + if (pressed & SCE_CTRL_UP) { + selection--; + } + else if (pressed & SCE_CTRL_DOWN) + selection++; + + Utils_SetMax(&selection, 0, max_items); + Utils_SetMin(&selection, max_items, 0); + + if (pressed & SCE_CTRL_ENTER) { + if (FS_DirExists(menu_items[selection])) { + config.device = selection; + Config_Save(config); + strcpy(root_path, menu_items[config.device]); + strcpy(cwd, root_path); + sceIoRemove("ux0:data/ElevenMPV/lastdir.txt"); + Dirbrowse_PopulateFiles(SCE_TRUE); + } + } + + if (Utils_AppStatusIsRunning()) + break; + } +} + +static void Menu_DisplaySortSettings(void) { + int selection = 0, max_items = 3; + + const char *menu_items[] = { + "By name (ascending)", + "By name (descending)", + "By size (largest first)", + "By size (smallest first)" + }; + + while (SCE_TRUE) { + vita2d_start_drawing(); + if (isFG) { + vita2d_clear_screen(); + + vita2d_draw_rectangle(0, 0, 960, 112, RGBA8(51, 51, 51, 255)); + + vita2d_draw_texture(icon_back, 25, 54); + vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Sort Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Sort Settings"); + + int printed = 0; + + for (int i = 0; i < max_items + 1; i++) { + if (printed == FILES_PER_PAGE) + break; + + if (selection < FILES_PER_PAGE || i >(selection - FILES_PER_PAGE)) { + if (i == selection) + vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); + + vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); + + printed++; + } + } + + vita2d_draw_texture(config.sort == 0 ? radio_on : radio_off, 850, 126); + vita2d_draw_texture(config.sort == 1 ? radio_on : radio_off, 850, 198); + vita2d_draw_texture(config.sort == 2 ? radio_on : radio_off, 850, 270); + vita2d_draw_texture(config.sort == 3 ? radio_on : radio_off, 850, 342); + } + else {} + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_end_shfb(); + + Utils_ReadControls(); + + if (pressed & SCE_CTRL_CANCEL) + break; + + if (pressed & SCE_CTRL_UP) + selection--; + else if (pressed & SCE_CTRL_DOWN) + selection++; + + Utils_SetMax(&selection, 0, max_items); + Utils_SetMin(&selection, max_items, 0); + + if (pressed & SCE_CTRL_ENTER) { + config.sort = selection; + Config_Save(config); + Dirbrowse_PopulateFiles(SCE_TRUE); + } + + if (Utils_AppStatusIsRunning()) + break; + } +} + +static void Menu_DisplayMetadataSettings(void) { + int selection = 0, max_items = 2; + + const char *menu_items[] = { + "Enable FLAC metadata", + "Enable MP3 metadata", + "Enable OPUS metadata" + }; + + while (SCE_TRUE) { + vita2d_start_drawing(); + if (isFG) { + vita2d_clear_screen(); + + vita2d_draw_rectangle(0, 0, 960, 112, RGBA8(51, 51, 51, 255)); + + vita2d_draw_texture(icon_back, 25, 54); + vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Metadata Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Metadata Settings"); + + int printed = 0; + + for (int i = 0; i < max_items + 1; i++) { + if (printed == FILES_PER_PAGE) + break; + + if (selection < FILES_PER_PAGE || i >(selection - FILES_PER_PAGE)) { + if (i == selection) + vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); + + vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); + + printed++; + } + } + + vita2d_draw_texture(config.meta_flac == SCE_TRUE ? toggle_on : toggle_off, 850, 118); + vita2d_draw_texture(config.meta_mp3 == SCE_TRUE ? toggle_on : toggle_off, 850, 190); + vita2d_draw_texture(config.meta_opus == SCE_TRUE ? toggle_on : toggle_off, 850, 262); + } + else {} + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_end_shfb(); + + Utils_ReadControls(); + + if (pressed & SCE_CTRL_CANCEL) + break; + + if (pressed & SCE_CTRL_UP) + selection--; + else if (pressed & SCE_CTRL_DOWN) + selection++; + + Utils_SetMax(&selection, 0, max_items); + Utils_SetMin(&selection, max_items, 0); + + if (pressed & SCE_CTRL_ENTER) { + switch (selection) { + case 0: + config.meta_flac = !config.meta_flac; + Config_Save(config); + break; + + case 1: + config.meta_mp3 = !config.meta_mp3; + Config_Save(config); + break; + + case 2: + config.meta_opus = !config.meta_opus; + Config_Save(config); + break; + } + } + + if (Utils_AppStatusIsRunning()) + break; + } +} + +static void Menu_DisplayALCModeSettings(void) { + int selection = 0, max_items = 1; + + const char *menu_items[] = { + "ALC off", + "ALC mode 1" + //"ALC mode max" // Max doesn't seem to work ? + }; + + while (SCE_TRUE) { + vita2d_start_drawing(); + if (isFG) { + vita2d_clear_screen(); + + vita2d_draw_rectangle(0, 0, 960, 112, RGBA8(51, 51, 51, 255)); + + vita2d_draw_texture(icon_back, 25, 54); + vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Dynamic Normalizer")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Dynamic Normalizer"); + + int printed = 0; + + for (int i = 0; i < max_items + 1; i++) { + if (printed == FILES_PER_PAGE) + break; + + if (selection < FILES_PER_PAGE || i >(selection - FILES_PER_PAGE)) { + if (i == selection) + vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); + + vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); + + printed++; + } + } + + vita2d_draw_texture(config.alc_mode == 0 ? radio_on : radio_off, 850, 126); + vita2d_draw_texture(config.alc_mode == 1 ? radio_on : radio_off, 850, 198); + } + else {} + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_end_shfb(); + + Utils_ReadControls(); + + if (pressed & SCE_CTRL_CANCEL) + break; + + if (pressed & SCE_CTRL_UP) + selection--; + else if (pressed & SCE_CTRL_DOWN) + selection++; + + Utils_SetMax(&selection, 0, max_items); + Utils_SetMin(&selection, max_items, 0); + + if (pressed & SCE_CTRL_ENTER) { + config.alc_mode = selection; + Config_Save(config); + Dirbrowse_PopulateFiles(SCE_TRUE); + } + + if (Utils_AppStatusIsRunning()) + break; + } +} + +void Menu_DisplaySettings(void) { + int selection = 0, max_items = 3; + + const char *menu_items[] = { + "Device settings", + "Sort settings", + "Metadata settings", + "Dynamic normalizer modes" + }; + + while (SCE_TRUE) { + vita2d_start_drawing(); + if (isFG) { + vita2d_clear_screen(); + + vita2d_draw_rectangle(0, 0, 960, 112, RGBA8(51, 51, 51, 255)); + + vita2d_draw_texture(icon_back, 25, 54); + vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, "Settings")) / 2) + 20, RGBA8(255, 255, 255, 255), 25, "Settings"); + + int printed = 0; + + for (int i = 0; i < max_items + 1; i++) { + if (printed == FILES_PER_PAGE) + break; + + if (selection < FILES_PER_PAGE || i >(selection - FILES_PER_PAGE)) { + if (i == selection) + vita2d_draw_rectangle(0, 112 + (72 * printed), 960, 72, RGBA8(230, 230, 230, 255)); + + vita2d_font_draw_text(font, 30, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, menu_items[i]); + + printed++; + } + } + } + else {} + vita2d_end_drawing(); + vita2d_wait_rendering_done(); + vita2d_end_shfb(); + + Utils_ReadControls(); + + if (pressed & SCE_CTRL_CANCEL) + break; + + if (pressed & SCE_CTRL_UP) + selection--; + else if (pressed & SCE_CTRL_DOWN) + selection++; + + Utils_SetMax(&selection, 0, max_items); + Utils_SetMin(&selection, max_items, 0); + + if (pressed & SCE_CTRL_ENTER) { + switch (selection) { + case 0: + Menu_DisplayDeviceSettings(); + break; + case 1: + Menu_DisplaySortSettings(); + break; + case 2: + Menu_DisplayMetadataSettings(); + break; + case 3: + Menu_DisplayALCModeSettings(); + break; + } + } + + if (Utils_AppStatusIsRunning()) + break; + } +} diff --git a/source/textures.c b/source/textures.c index b2ca43f..481163a 100644 --- a/source/textures.c +++ b/source/textures.c @@ -2,25 +2,6 @@ #include "textures.h" -extern SceUChar8 _binary_res_battery_20_png_start; -extern SceUChar8 _binary_res_battery_30_png_start; -extern SceUChar8 _binary_res_battery_50_png_start; -extern SceUChar8 _binary_res_battery_60_png_start; -extern SceUChar8 _binary_res_battery_80_png_start; -extern SceUChar8 _binary_res_battery_90_png_start; -extern SceUChar8 _binary_res_battery_full_png_start; - -extern SceUChar8 _binary_res_battery_20_charging_png_start; -extern SceUChar8 _binary_res_battery_30_charging_png_start; -extern SceUChar8 _binary_res_battery_50_charging_png_start; -extern SceUChar8 _binary_res_battery_60_charging_png_start; -extern SceUChar8 _binary_res_battery_80_charging_png_start; -extern SceUChar8 _binary_res_battery_90_charging_png_start; -extern SceUChar8 _binary_res_battery_full_charging_png_start; - -extern SceUChar8 _binary_res_battery_low_png_start; -extern SceUChar8 _binary_res_battery_unknown_png_start; - extern SceUChar8 _binary_res_icon_audio_png_start; extern SceUChar8 _binary_res_icon_file_png_start; extern SceUChar8 _binary_res_icon_folder_png_start; @@ -34,8 +15,6 @@ extern SceUChar8 _binary_res_btn_playback_repeat_overlay_png_start; extern SceUChar8 _binary_res_btn_playback_rewind_png_start; extern SceUChar8 _binary_res_btn_playback_shuffle_png_start; extern SceUChar8 _binary_res_btn_playback_shuffle_overlay_png_start; -extern SceUChar8 _binary_res_default_artwork_png_start; -extern SceUChar8 _binary_res_default_artwork_blur_png_start; extern SceUChar8 _binary_res_toggle_off_png_start; extern SceUChar8 _binary_res_toggle_on_png_start; @@ -49,24 +28,6 @@ static vita2d_texture *Texture_LoadImageBilinear(SceUChar8 *buffer) { } void Textures_Load(void) { - battery_20 = Texture_LoadImageBilinear(&_binary_res_battery_20_png_start); - battery_30 = Texture_LoadImageBilinear(&_binary_res_battery_30_png_start); - battery_50 = Texture_LoadImageBilinear(&_binary_res_battery_50_png_start); - battery_60 = Texture_LoadImageBilinear(&_binary_res_battery_60_png_start); - battery_80 = Texture_LoadImageBilinear(&_binary_res_battery_80_png_start); - battery_90 = Texture_LoadImageBilinear(&_binary_res_battery_90_png_start); - battery_full = Texture_LoadImageBilinear(&_binary_res_battery_full_png_start); - - battery_20_charging = Texture_LoadImageBilinear(&_binary_res_battery_20_charging_png_start); - battery_30_charging = Texture_LoadImageBilinear(&_binary_res_battery_30_charging_png_start); - battery_50_charging = Texture_LoadImageBilinear(&_binary_res_battery_50_charging_png_start); - battery_60_charging = Texture_LoadImageBilinear(&_binary_res_battery_60_charging_png_start); - battery_80_charging = Texture_LoadImageBilinear(&_binary_res_battery_80_charging_png_start); - battery_90_charging = Texture_LoadImageBilinear(&_binary_res_battery_90_charging_png_start); - battery_full_charging = Texture_LoadImageBilinear(&_binary_res_battery_full_charging_png_start); - - battery_low = Texture_LoadImageBilinear(&_binary_res_battery_low_png_start); - battery_unknown = Texture_LoadImageBilinear(&_binary_res_battery_unknown_png_start); icon_audio = Texture_LoadImageBilinear(&_binary_res_icon_audio_png_start); icon_file = Texture_LoadImageBilinear(&_binary_res_icon_file_png_start); @@ -81,8 +42,6 @@ void Textures_Load(void) { btn_rewind = Texture_LoadImageBilinear(&_binary_res_btn_playback_rewind_png_start); btn_shuffle = Texture_LoadImageBilinear(&_binary_res_btn_playback_shuffle_png_start); btn_shuffle_overlay = Texture_LoadImageBilinear(&_binary_res_btn_playback_shuffle_overlay_png_start); - default_artwork = Texture_LoadImageBilinear(&_binary_res_default_artwork_png_start); - default_artwork_blur = Texture_LoadImageBilinear(&_binary_res_default_artwork_blur_png_start); toggle_on = Texture_LoadImageBilinear(&_binary_res_toggle_on_png_start); toggle_off = Texture_LoadImageBilinear(&_binary_res_toggle_off_png_start); @@ -96,8 +55,6 @@ void Textures_Free(void) { vita2d_free_texture(toggle_off); vita2d_free_texture(toggle_on); - vita2d_free_texture(default_artwork_blur); - vita2d_free_texture(default_artwork); vita2d_free_texture(btn_shuffle_overlay); vita2d_free_texture(btn_shuffle); vita2d_free_texture(btn_rewind); @@ -111,23 +68,4 @@ void Textures_Free(void) { vita2d_free_texture(icon_dir); vita2d_free_texture(icon_file); vita2d_free_texture(icon_audio); - - vita2d_free_texture(battery_unknown); - vita2d_free_texture(battery_low); - - vita2d_free_texture(battery_full_charging); - vita2d_free_texture(battery_90_charging); - vita2d_free_texture(battery_80_charging); - vita2d_free_texture(battery_60_charging); - vita2d_free_texture(battery_50_charging); - vita2d_free_texture(battery_30_charging); - vita2d_free_texture(battery_20_charging); - - vita2d_free_texture(battery_full); - vita2d_free_texture(battery_90); - vita2d_free_texture(battery_80); - vita2d_free_texture(battery_60); - vita2d_free_texture(battery_50); - vita2d_free_texture(battery_30); - vita2d_free_texture(battery_20); } diff --git a/source/utils.c b/source/utils.c index dd97483..0c40146 100644 --- a/source/utils.c +++ b/source/utils.c @@ -2,14 +2,40 @@ #include #include #include +#include #include #include #include #include "common.h" +typedef struct SceAppMgrAppStatus { // size is 0x40 on FW 0.990 + SceUInt32 unk_0; // 0x0 + SceUInt32 launchMode; // 0x4 + SceUInt32 bgm_priority_or_status; // 0x8 + char appName[32]; // 0xC + SceUInt32 unk_2C; // 0x2C + SceUID appId; // 0x30 - Application ID + SceUID processId; // 0x34 - Process ID + SceUInt32 isForeground; // 0x38 + SceUInt32 status_related_2; // 0x3C +} SceAppMgrAppStatus; + +typedef struct SceAppMgrEvent { // size is 0x64 + int event; /* Event ID */ + SceUID appId; /* Application ID. Added when required by the event */ + char param[56]; /* Parameters to pass with the event */ +} SceAppMgrEvent; + +int _sceAppMgrReceiveEvent(SceAppMgrEvent *appEvent); +int sceAppMgrQuitForNonSuspendableApp(void); + +int isFG = SCE_TRUE; + +static SceAppMgrEvent appEvent; static SceCtrlData pad, old_pad; static int lock_power = 0; +static int finish_flag = SCE_FALSE; void Utils_SetMax(int *set, int value, int max) { if (*set > max) @@ -31,7 +57,38 @@ int Utils_ReadControls(void) { return 0; } +int Utils_AppStatusIsRunning(void) +{ + return finish_flag; +} + +int Utils_AppStatusWatchdog(SceSize argc, void* argv) +{ + while (SCE_TRUE) { + _sceAppMgrReceiveEvent(&appEvent); + switch (appEvent.event) { + case 268435457: // resume + isFG = SCE_TRUE; + break; + case 268435458: // exit + isFG = SCE_FALSE; + break; + case 536870913: // destroy + /* sceAppMgrQuitForNonSuspendableApp(); */ //Doesn't work due to ksceSblACMgrIsNonGameProgram() + finish_flag = SCE_TRUE; + break; + } + sceKernelDelayThread(1000); + } + + return 0; +} + int Utils_InitAppUtil(void) { + + SceUID watchdog = sceKernelCreateThread("appStatusWatchdog", Utils_AppStatusWatchdog, 192, 0x1000, 0, 0, NULL); + sceKernelStartThread(watchdog, 0, NULL); + SceAppUtilInitParam init; SceAppUtilBootParam boot; memset(&init, 0, sizeof(SceAppUtilInitParam)); @@ -112,20 +169,16 @@ static int power_tick_thread(SceSize args, void *argp) { void Utils_InitPowerTick(void) { SceUID thid = 0; - if (R_SUCCEEDED(thid = sceKernelCreateThread("power_tick_thread", power_tick_thread, 0x10000100, 0x40000, 0, 0, NULL))) + if (R_SUCCEEDED(thid = sceKernelCreateThread("power_tick_thread", power_tick_thread, 192, 0x1000, 0, 0, NULL))) sceKernelStartThread(thid, 0, NULL); } void Utils_LockPower(void) { - if (!lock_power) - sceShellUtilLock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN); lock_power++; } void Utils_UnlockPower(void) { - if (lock_power) - sceShellUtilUnlock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN); lock_power--; if (lock_power < 0)