From 5aa642f2ff83a26161d74385fc4fd78137a6fe78 Mon Sep 17 00:00:00 2001 From: mrdude2478 Date: Tue, 3 Oct 2023 07:39:00 +0100 Subject: [PATCH] add mod tracker audio support to themes --- Makefile | 2 +- source/ui/mainPage.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8b55499..7edca85 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -std=gnu++20 -Wall ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) -LIBS := -lpu -lcurl -lz -lssh2 -lusbhsfs -lntfs-3g -llwext4 -lmbedtls -lmbedcrypto -lmbedx509 -lminizip -lnx -lstdc++fs -lzzip -lpu -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -lSDL2 -lc -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lzstd +LIBS := -lpu -lcurl -lz -lssh2 -lusbhsfs -lntfs-3g -llwext4 -lmbedtls -lmbedcrypto -lmbedx509 -lminizip -lnx -lstdc++fs -lzzip -lpu -lfreetype -lSDL2main -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -lSDL2 -lc -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lzstd #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing diff --git a/source/ui/mainPage.cpp b/source/ui/mainPage.cpp index 29c3944..43dd930 100644 --- a/source/ui/mainPage.cpp +++ b/source/ui/mainPage.cpp @@ -15,6 +15,11 @@ #include "util/theme.hpp" #include +// Include sdl2 headers +#include +#include +Mix_Music* audio = NULL; + #define COLOR(hex) pu::ui::Color::FromHex(hex) int statvfs(const char* path, struct statvfs* buf); @@ -134,6 +139,19 @@ namespace inst::ui { inst::ui::mainApp->CreateShowDialog("usage.space_info"_lang, Info, { "common.ok"_lang }, true, "romfs:/images/icons/drive.png"); } + void playmusic() { + SDL_Init(SDL_INIT_AUDIO); + Mix_Init(MIX_INIT_MP3); //enable mp3 support + Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096); + std::string loadsound = "romfs:/bluesong.mod"; + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(inst::config::appDir + "audio.music"_theme)) { + loadsound = inst::config::appDir + "audio.music"_theme; + } + const char* x = loadsound.c_str(); + audio = Mix_LoadMUS(x); + Mix_PlayMusic(audio, 100); //Play the audio file 100 loops + } + void mainMenuThread() { bool menuLoaded = mainApp->IsShown(); if (!appletFinished && appletGetAppletType() == AppletType_LibraryApplet) { @@ -263,6 +281,7 @@ namespace inst::ui { } this->Add(this->optionMenu); this->AddRenderCallback(mainMenuThread); + playmusic(); } void MainPage::installMenuItem_Click() { @@ -380,10 +399,14 @@ namespace inst::ui { if (Down & HidNpadButton_ZR) { } - if (Down & HidNpadButton_L) { + if (Down & Held & HidNpadButton_L) { + playmusic(); } - if (Down & HidNpadButton_R) { + if (Down & Held & HidNpadButton_R) { + Mix_FreeMusic(audio); + audio = NULL; + Mix_Quit(); } } } \ No newline at end of file