From 7f141651829bae7dfb77cc90842fb12a524f0427 Mon Sep 17 00:00:00 2001 From: proconsule <34319995+proconsule@users.noreply.github.com> Date: Sun, 21 Nov 2021 10:06:12 +0100 Subject: [PATCH] v 0.5.1 - Fix for db not saved on hard exit the app - ShaderMania useless but fun with shaders - Custom Sub Font Size - Show File selection during playback with - button - Volume Up/Down with rstick --- Makefile | 6 +- README.md | 8 +- include/config.h | 8 ++ include/gui.h | 8 ++ include/libmpv.h | 5 ++ include/playerwindows.h | 24 ++++++ source/UI/enigmaui.cpp | 2 +- source/UI/filebrowser.cpp | 1 + source/UI/networkBrowser.cpp | 2 + source/UI/playerWindows.cpp | 77 +++++++++++++++-- source/UI/settingsMenu.cpp | 18 ++++ source/UI/usbBrowser.cpp | 2 +- source/config.cpp | 23 +++++ source/gui.cpp | 130 ++++++++++++++++++++++++----- source/libmpv.cpp | 72 ++++++++++++++-- source/main.cpp | 8 ++ source/shadermania/shaderMania.cpp | 71 ++++++++++++++++ source/shadermania/shaderMania.h | 22 +++++ 18 files changed, 446 insertions(+), 41 deletions(-) create mode 100644 source/shadermania/shaderMania.cpp create mode 100644 source/shadermania/shaderMania.h diff --git a/Makefile b/Makefile index f1648ab..4290b2a 100644 --- a/Makefile +++ b/Makefile @@ -39,14 +39,14 @@ include $(DEVKITPRO)/libnx/switch_rules #--------------------------------------------------------------------------------- TARGET := $(notdir $(CURDIR)) BUILD := build -SOURCES := libs/imgui libs/imgui/misc/freetype source source/eqpreset source/database source/UI source/remotefs/Enigma2 source/localfs source/localfs/usb source/remotefs/ftplib source/remotefs/HTTPDir +SOURCES := libs/imgui libs/imgui/misc/freetype source source/shadermania source/eqpreset source/database source/UI source/remotefs/Enigma2 source/localfs source/localfs/usb source/remotefs/ftplib source/remotefs/HTTPDir DATA := data -INCLUDES := libs/simpleini libs/imgui include source/eqpreset source/database source/remotefs/Enigma2 source/localfs source/localfs/usb source/remotefs/ftplib source/remotefs/HTTPDir +INCLUDES := libs/simpleini libs/imgui include source/shadermania source/eqpreset source/database source/remotefs/Enigma2 source/localfs source/localfs/usb source/remotefs/ftplib source/remotefs/HTTPDir ROMFS := romfs VERSION_MAJOR := 0 VERSION_MINOR := 5 -VERSION_MICRO := 0 +VERSION_MICRO := 1 APP_TITLE := NXMP APP_AUTHOR := proconsule diff --git a/README.md b/README.md index 1a398fd..fc5861b 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ Buttons Mapping - R Stick Button Toggle Masterlock (during playback, only A button will work) - Dpad Right (during playback show/hide right menu) - Dpad Down (during playback show/hide player UI) -- R Stick Up/Down Fast Scroll on file list +- R Stick Up/Down Fast Scroll on file list (Volume Control During Playback) +- \- Show file selection during playback + FAQ ----- @@ -57,6 +59,10 @@ FAQ **A:** Enigma2 is an application used in Linux-based Digital Video Broadcasting (DVB-S, DVB-C, DVB-T) receivers or TV set-top boxes and Internet Protocol television receivers. +**Q:** What is ShaderMania? + +**A:** ShaderMania is an useless but fun feature of NXMP, it uses the ability of MPV to load custom shader into the video output chain. I adopt some shaders from https://www.shadertoy.com/ to make shaders effects to the video. Some like grayscale may be usefull for someone others (like the sea shaders) is only for fun. Users can also make their custom shaders and place in mpv/shaders directory. + Thanks to ----- - Cpasjuste for pPlay https://github.com/Cpasjuste/pplay some code was taken here (mpv part) diff --git a/include/config.h b/include/config.h index 62c1b17..4df3701 100644 --- a/include/config.h +++ b/include/config.h @@ -28,6 +28,9 @@ class Config{ int getAlang(bool tmpvalue); void setAlang(int lang); + int getSubFontSize(bool tmpvalue); + void setSubFontSize(int val); + int getDeinterlace(bool tmpvalue); void setDeinterlace(int value); @@ -57,10 +60,15 @@ class Config{ int tmpalang; int alang; + int tmpsubfontsize; + int subfontsize; + int tmpdeint; int deint; + + int tmpstartresumeperc; int tmpstopresumeperc; int startresumeperc; diff --git a/include/gui.h b/include/gui.h index d253d12..f8a998b 100644 --- a/include/gui.h +++ b/include/gui.h @@ -26,6 +26,8 @@ #include "HTTPDir.h" #include "FTPDir.h" +#include "shaderMania.h" + enum MENU_STATES { MENU_STATE_HOME, @@ -66,6 +68,7 @@ enum PLAYER_RIGHT_MENU_STATES { PLAYER_RIGHT_MENU_IMAGE, PLAYER_RIGHT_MENU_AUDIO, PLAYER_RIGHT_MENU_SUB, + PLAYER_RIGHT_MENU_SHADERMANIA, PLAYER_AUDIOEQ, PLAYER_SUPERAUDIOEQ }; @@ -103,6 +106,9 @@ typedef struct { bool rightmenu_first_item; bool rightmenu_focus; + bool showVolume = false; + float VolumeHide = 0.0; + } MenuItem; @@ -167,6 +173,8 @@ extern Tex NoLoopIcon; extern ImFont* fontSmall; +extern shaderMania* shadermania; + namespace GUI { diff --git a/include/libmpv.h b/include/libmpv.h index 3a15792..0555666 100644 --- a/include/libmpv.h +++ b/include/libmpv.h @@ -63,6 +63,7 @@ class libMpv{ void setRotate(int value, bool osd); void setVolume(int value,bool osd); + int getVolume(); bool getMute(); void toggleMute(); @@ -84,6 +85,8 @@ class libMpv{ void getfileInfo(); + void setShader(std::string _filename); + void clearShader(); mpv_handle *getHandle(); @@ -96,6 +99,8 @@ class libMpv{ private: + + void resetFileInfo(); mpv_handle *handle = nullptr; mpv_render_context *context = nullptr; std::vector decoderlist; diff --git a/include/playerwindows.h b/include/playerwindows.h index 86c097c..c4a74fa 100644 --- a/include/playerwindows.h +++ b/include/playerwindows.h @@ -14,6 +14,14 @@ namespace playerWindows{ ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); } + inline void SetupVolumeWindow(void){ + ImGui::SetNextWindowPos(ImVec2(10.0f, 10.0f), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(200.0f, 50.0f), ImGuiCond_Once); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); + } + static float rightmenuposX = 1280.0f; inline void SetupRightWindow(void) { ImGui::SetNextWindowPos(ImVec2(rightmenuposX, 0.0f), ImGuiCond_Always); @@ -42,6 +50,7 @@ namespace playerWindows{ ImGui::SetNextWindowPos(ImVec2(0.0f, 620.0f), ImGuiCond_Once); ImGui::SetNextWindowSize(ImVec2(1280.0f, 720.0f), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); }; @@ -51,6 +60,18 @@ namespace playerWindows{ ImGui::PopStyleColor(); }; + inline void ExitVolumeWindow(void) { + ImGui::End(); + ImGui::PopStyleVar(2); + ImGui::PopStyleColor(); + }; + + inline void ExitControlsWindow(void) { + ImGui::End(); + ImGui::PopStyleVar(2); + ImGui::PopStyleColor(); + }; + void RightHomeWindow(bool *focus, bool *first_item); void RightTrackWindow(bool *focus, bool *first_item); void RightChapterWindow(bool *focus, bool *first_item); @@ -72,6 +93,9 @@ namespace playerWindows{ void playerControls(); + void RightHomeShaderMania(); + void VolumeWindow(); + } #endif \ No newline at end of file diff --git a/source/UI/enigmaui.cpp b/source/UI/enigmaui.cpp index 6be2203..18026fd 100644 --- a/source/UI/enigmaui.cpp +++ b/source/UI/enigmaui.cpp @@ -44,7 +44,7 @@ namespace Windows { std::string itemid = "##" + std::to_string(n); float currstartpos = ImGui::GetCursorPosX(); if (ImGui::Selectable(itemid.c_str(), selected == n, 0, ImVec2(0, 70))){ - + item.laststate = item.state; libmpv->loadFileLive(enigma2->e2currbouqet[n].url,enigma2->e2currbouqet[n].name); diff --git a/source/UI/filebrowser.cpp b/source/UI/filebrowser.cpp index 75a40ab..1a788db 100644 --- a/source/UI/filebrowser.cpp +++ b/source/UI/filebrowser.cpp @@ -44,6 +44,7 @@ namespace Windows { localdir->DirList(thislist[n].path,true,Utility::getMediaExtensions()); } else{ + item.laststate = item.state; libmpv->loadFile(thislist[n].path); if(configini->getDbActive(true)){ libmpv->getFileInfo()->resume = sqlitedb->getResume(thislist[n].path); diff --git a/source/UI/networkBrowser.cpp b/source/UI/networkBrowser.cpp index 7a80d6d..0238b9a 100644 --- a/source/UI/networkBrowser.cpp +++ b/source/UI/networkBrowser.cpp @@ -48,6 +48,7 @@ namespace Windows { }else if (thislist[n].type == FS::FileEntryType::File){ std::string openurl = thisurl.scheme + std::string("://") + thisurl.user + std::string(":") + thisurl.pass + std::string("@") + thisurl.server + std::string("/") + thislist[n].path + thislist[n].name; + item.laststate = item.state; libmpv->loadFile(openurl); if(configini->getDbActive(true)){ libmpv->getFileInfo()->resume = sqlitedb->getResume(openurl); @@ -118,6 +119,7 @@ namespace Windows { urlschema thisurl = Utility::parseUrl(httpdir->getUrl()); std::string openurl = thisurl.scheme + std::string("://") + thisurl.server + std::string("/") + httpdir->getCurrPath() + thislist[n].name; + item.laststate = item.state; libmpv->loadFile(openurl); libmpv->getFileInfo()->resume = sqlitedb->getResume(openurl); if(libmpv->getFileInfo()->resume>0){ diff --git a/source/UI/playerWindows.cpp b/source/UI/playerWindows.cpp index f238209..37a06f6 100644 --- a/source/UI/playerWindows.cpp +++ b/source/UI/playerWindows.cpp @@ -18,6 +18,7 @@ namespace playerWindows{ static int drag_gamma = 0; static int drag_hue = 0; static int rotateidx = 0; + static int shaderidx = 0; @@ -40,7 +41,7 @@ namespace playerWindows{ rightmenuposX = item.rightmenu_startpos; if(item.rightmenu_startpos>1080)item.rightmenu_startpos-=10; playerWindows::SetupRightWindow(); - std::vector topmenu = {"Tracks","Chapters","Aspect Ratio","Image","Audio","Subtitle"}; + std::vector topmenu = {"Tracks","Chapters","Aspect Ratio","Image","Audio","Subtitle","ShaderMania"}; if (ImGui::Begin("Right Menu Home", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); if (ImGui::BeginListBox("Right Menu Home List",ImVec2(1280.0f, 720.0f))){ @@ -65,6 +66,9 @@ namespace playerWindows{ if(topmenu[n] == "Subtitle"){ item.rightmenustate = PLAYER_RIGHT_MENU_SUB; } + if(topmenu[n] == "ShaderMania"){ + item.rightmenustate = PLAYER_RIGHT_MENU_SHADERMANIA; + } } } if (*first_item) { @@ -419,6 +423,7 @@ namespace playerWindows{ auto windowWidth = ImGui::GetWindowSize().x; ImGui::SetCursorPosX((windowWidth - ImGui::CalcTextSize("Volume", NULL, true).x) * 0.5f); ImGui::Text("Volume"); + drag_volume = libmpv->getVolume(); if(ImGui::DragInt("Volume", &drag_volume, 0.5f, 0, 200, "%d", ImGuiSliderFlags_NoInput)){ libmpv->setVolume(drag_volume,item.playershowcontrols); } @@ -460,21 +465,21 @@ namespace playerWindows{ if(ImGui::DragInt("Sub Position", &drag_subpos, 0.5f, 0, 100, "%d", ImGuiSliderFlags_NoInput)){ libmpv->setSubPos(drag_subpos,item.playershowcontrols); } - ImGui::BeginDisabled(); + //ImGui::BeginDisabled(); ImGui::SetCursorPosX((windowWidth - ImGui::CalcTextSize("Sub Font Size", NULL, true).x) * 0.5f); ImGui::Text("Sub Font Size"); - if(ImGui::DragInt("Sub Font Size", &drag_subfontsize, 0.5f, 1, 70, "%d", ImGuiSliderFlags_NoInput)){ + if(ImGui::DragInt("Sub Font Size", &drag_subfontsize, 0.5f, 1, 120, "%d", ImGuiSliderFlags_NoInput)){ libmpv->setSubFontSize(drag_subfontsize,item.playershowcontrols); } - ImGui::EndDisabled(); + //ImGui::EndDisabled(); ImGui::SetCursorPosY(ImGui::GetWindowSize().y -50); if(ImGui::Button("Reset to Default")){ drag_subpos = 100; drag_subdelay = 0.0f; - drag_subfontsize = 55; + drag_subfontsize = configini->getSubFontSize(false); libmpv->setSubPos(drag_subpos,false); libmpv->setSubDelay(drag_subdelay,false); - libmpv->setSubFontSize(drag_subdelay,false); + libmpv->setSubFontSize(drag_subfontsize,false); } } playerWindows::ExitWindow(); @@ -713,7 +718,67 @@ namespace playerWindows{ } + playerWindows::ExitControlsWindow(); + } + + void RightHomeShaderMania(){ + playerWindows::SetupRightWindow(); + std::vector topmenu = {"Default","16:9","16:10","4:3","Custom Ratio"}; + if (ImGui::Begin("Shader Mania", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::PushItemWidth(200-10); + ImGui::Text("Shaders"); + if (ImGui::BeginCombo("Shaders Combo", shadermania->getCurrList()[shaderidx].name.c_str(), 0)) + { + for (int n = 0; n < shadermania->getCurrList().size(); n++) + { + const bool is_selected = (shaderidx == n); + std::string itemid = "##" + std::to_string(n); + if (ImGui::Selectable(itemid.c_str(), is_selected)){ + + if(n == 0){ + libmpv->clearShader(); + }else{ + printf("PATH: %s\n",shadermania->getCurrList()[n].path.c_str()); + libmpv->setShader(shadermania->getCurrList()[n].path); + } + shaderidx = n; + } + ImGui::SameLine(); + ImGui::Text("%s",shadermania->getCurrList()[n].name.c_str()); + + + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + ImGui::PopItemWidth(); + } + } + playerWindows::ExitWindow(); } + + void VolumeWindow(){ + playerWindows::SetupVolumeWindow(); + if (ImGui::Begin("Volume Window", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(1.0,1.0,1.0,0.2)); + ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(1.0,1.0,1.0,1.0)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 12.0f); + ImGui::ProgressBar(libmpv->getVolume()/100.0, ImVec2(150.0, 25.0f),""); + ImGui::PopStyleColor(2); + ImGui::PopStyleVar(); + ImGui::SameLine(); + ImGui::Image((void*)(intptr_t)VolumeIcon.id, ImVec2(25,25)); + ImGuiContext& g = *GImGui; + if(item.VolumeHide +2 < g.Time){ + item.showVolume = false; + } + + } + + playerWindows::ExitVolumeWindow(); + } } diff --git a/source/UI/settingsMenu.cpp b/source/UI/settingsMenu.cpp index e09cd45..9690198 100644 --- a/source/UI/settingsMenu.cpp +++ b/source/UI/settingsMenu.cpp @@ -83,6 +83,24 @@ namespace Windows { ImGui::EndDisabled(); } + ImGui::Text("Sub Font Size"); + ImGui::SameLine(220,spacing); + ImGui::PushButtonRepeat(true); + if (ImGui::ArrowButton("##subsizeleft", ImGuiDir_Left)) { + if(configini->getSubFontSize(true)-1 >0){ + configini->setSubFontSize(configini->getSubFontSize(true)-1); + } + } + ImGui::SameLine(0.0f, spacing); + if (ImGui::ArrowButton("##subsizeright", ImGuiDir_Right)) { + if(configini->getSubFontSize(true)+1 <120){ + configini->setSubFontSize(configini->getSubFontSize(true)+1); + } + } + ImGui::PopButtonRepeat(); + ImGui::SameLine(); + ImGui::Text("%d", configini->getSubFontSize(true)); + std::vector deintmenu = {"No","Yes","Auto"}; const char* combo_deintpreview_value = deintmenu[configini->getDeinterlace(true)].c_str(); ImGui::PushItemWidth(300); diff --git a/source/UI/usbBrowser.cpp b/source/UI/usbBrowser.cpp index e72c37a..8a40445 100644 --- a/source/UI/usbBrowser.cpp +++ b/source/UI/usbBrowser.cpp @@ -81,7 +81,7 @@ namespace Windows { item.usbfileentries = FS::getDirList(item.usbpath.c_str(),true,Utility::getMediaExtensions()); triggerselect = true; }else if(thislist[n].type == FS::FileEntryType::File){ - + item.laststate = item.state; libmpv->loadFile(thislist[n].path); if(configini->getDbActive(true)){ libmpv->getFileInfo()->resume = sqlitedb->getResume(thislist[n].path); diff --git a/source/config.cpp b/source/config.cpp index c972c4e..aecfb14 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -48,6 +48,12 @@ Config::Config(std::string inifile){ alang = Utility::getLanguagesIdx(alangstring); tmpalang = alang; + subfontsize = ini->GetLongValue("Main", "subfontsize"); + if(subfontsize == 0)subfontsize = 55; + tmpsubfontsize = subfontsize; + + + const char* deintpv; deintpv = ini->GetValue("Main", "deinterlace"); std::string deintstring; @@ -183,6 +189,17 @@ void Config::setAlang(int lang){ tmpalang = lang; } +int Config::getSubFontSize(bool tmpvalue){ + if(tmpvalue){ + return tmpsubfontsize; + } + return subfontsize; +} + +void Config::setSubFontSize(int val){ + tmpsubfontsize = val; +} + void Config::setDeinterlace(int value){ tmpdeint = value; } @@ -230,6 +247,7 @@ void Config::saveSettings(){ longseek = tmplongseek; shortseek = tmpshortseek; usealang = tmpusealang; + subfontsize = tmpsubfontsize; deint = tmpdeint; dbactive = tmpdbactive; @@ -246,6 +264,11 @@ void Config::saveSettings(){ ini->Delete("Main", "alang"); ini->SetValue("Main", "alang", Utility::getLanguages()[tmpalang].lang3.c_str()); + + ini->Delete("Main", "subfontsize"); + ini->SetLongValue("Main", "subfontsize", subfontsize, NULL, false); + + std::vector deintopts = {"no","yes","auto"}; ini->Delete("Main", "deinterlace"); ini->SetValue("Main", "deinterlace", deintopts[deint].c_str()); diff --git a/source/gui.cpp b/source/gui.cpp index fba81ab..71f6d20 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -12,6 +12,11 @@ MenuItem item; namespace GUI { + + const int JOYSTICK_DEAD_ZONE = 8000; + const int JOYSTICK_EXTENDED_DEAD_ZONE = 32726; + + enum SDL_KEYS { SDL_KEY_A, SDL_KEY_B, SDL_KEY_X, SDL_KEY_Y, SDL_KEY_LSTICK, SDL_KEY_RSTICK, @@ -39,11 +44,6 @@ namespace GUI { } - void toggleStats(){ - const char *cmd[] = {"script-binding","stats/display-stats-toggle" ,NULL}; - mpv_command_async(libmpv->getHandle(), 0, cmd); - } - void toggleMasterLock(){ item.masterlock = !item.masterlock; if(item.masterlock){ @@ -137,27 +137,97 @@ namespace GUI { sdlevent.jbutton.button = SDL_KEY_L; SDL_PushEvent(&sdlevent); } - if(keycode == SDLK_t){ - //mpv_set_option_string(libmpv->getHandle(), "gpu-nxmp-deint", "0"); - //mpv_set_option_string(libmpv->getHandle(), "glsl-shader", "C:\\Users\\Ceco\\C-Dev\\imgui-test\\mpv\\shaders\\test.hook"); - mpv_command_string(libmpv->getHandle(),"no-osd change-list glsl-shaders set C:\\Users\\Ceco\\C-Dev\\imgui-test\\mpv\\shaders\\scale.glsl"); + if(keycode == SDLK_i){ + SDL_Event sdlevent; + sdlevent.type = SDL_JOYBUTTONDOWN; + sdlevent.jbutton.button = SDL_KEY_RSTICK_UP; + SDL_PushEvent(&sdlevent); + } + if(keycode == SDLK_k){ + SDL_Event sdlevent; + sdlevent.type = SDL_JOYBUTTONDOWN; + sdlevent.jbutton.button = SDL_KEY_RSTICK_DOWN; + SDL_PushEvent(&sdlevent); + } + + + if(keycode == 45){ + SDL_Event sdlevent; + sdlevent.type = SDL_JOYBUTTONDOWN; + sdlevent.jbutton.button = SDL_KEY_MINUS; + SDL_PushEvent(&sdlevent); } if(keycode == SDLK_e){ - mpv_command_string(libmpv->getHandle(),"no-osd change-list glsl-shaders clr \"\""); - //mpv_set_option_string(libmpv->getHandle(), "gpu-nxmp-deint", "1"); + } } #endif + if(event.type == SDL_JOYAXISMOTION){ + if( event.jaxis.axis == 3 ) { + if( event.jaxis.value > JOYSTICK_DEAD_ZONE ) { + if(item.state == MENU_STATE_PLAYER && !item.masterlock && item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER){ + item.showVolume = true; + ImGuiContext& g = *GImGui; + item.VolumeHide = g.Time; + if(libmpv->getVolume()-1>=0){ + libmpv->setVolume(libmpv->getVolume()-1,false); + } + } + } + else if( event.jaxis.value < -JOYSTICK_DEAD_ZONE ) { + if(item.state == MENU_STATE_PLAYER && !item.masterlock && item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER){ + item.showVolume = true; + ImGuiContext& g = *GImGui; + item.VolumeHide = g.Time; + if(libmpv->getVolume()+1<=100){ + libmpv->setVolume(libmpv->getVolume()+1,false); + } + } + } + + } + + //Uint8 axis = event.axis; + + + } + if (event.type == SDL_JOYBUTTONDOWN) { Uint8 button = event.jbutton.button; if (button == SDL_KEY_PLUS && !item.masterlock) renderloopdone = true; + + + + if (button == SDL_KEY_RSTICK_UP){ + if(item.state == MENU_STATE_PLAYER && !item.masterlock && item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER){ + item.showVolume = true; + ImGuiContext& g = *GImGui; + item.VolumeHide = g.Time; + if(libmpv->getVolume()+1<=100){ + libmpv->setVolume(libmpv->getVolume()+1,false); + } + } + } + + if (button == SDL_KEY_RSTICK_DOWN){ + if(item.state == MENU_STATE_PLAYER && !item.masterlock && item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER){ + item.showVolume = true; + ImGuiContext& g = *GImGui; + item.VolumeHide = g.Time; + if(libmpv->getVolume()-1>=0){ + libmpv->setVolume(libmpv->getVolume()-1,false); + } + } + } + + if (button == SDL_KEY_DUP){ if(item.state == MENU_STATE_PLAYER && !item.masterlock && item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER && item.popupstate == POPUP_STATE_NONE){ - + } } @@ -165,6 +235,7 @@ namespace GUI { if(item.state == MENU_STATE_PLAYER && !item.masterlock && item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER && item.popupstate == POPUP_STATE_NONE){ if(item.playercontrolstate == PLAYER_CONTROL_STATE_NONE){ item.playercontrolstate = PLAYER_CONTROL_STATE_CONTROLS; + }else{ item.playercontrolstate = PLAYER_CONTROL_STATE_NONE; } @@ -197,7 +268,9 @@ namespace GUI { } if (button == SDL_KEY_MINUS){ if(item.state == MENU_STATE_PLAYER && !item.masterlock){ - toggleStats(); + item.state = item.laststate; + }else if(item.state != MENU_STATE_PLAYER && !libmpv->Stopped()){ + item.state = MENU_STATE_PLAYER; } } @@ -258,7 +331,7 @@ namespace GUI { localdir = nullptr; } #ifdef __SWITCH__ - if(usbmounter != nullptr){ + if(usbmounter != nullptr && libmpv->Stopped()){ delete usbmounter; usbmounter = nullptr; } @@ -284,25 +357,25 @@ namespace GUI { } if (button == SDL_KEY_B){ - if(item.state == MENU_STATE_ENIGMABROWSER && libmpv->Stopped()){ + if(item.state == MENU_STATE_ENIGMABROWSER){ item.first_item = true; enigma2->backToTop(); } - if(item.state == MENU_STATE_FTPBROWSER && libmpv->Stopped()){ + if(item.state == MENU_STATE_FTPBROWSER){ item.first_item = true; ftpdir->backDir(); ftpdir->DirList(ftpdir->getCurrPath(),Utility::getMediaExtensions()); } - if(item.state == MENU_STATE_HTTPBROWSER && libmpv->Stopped()){ + if(item.state == MENU_STATE_HTTPBROWSER){ item.first_item = true; httpdir->backDir(); httpdir->DirList(httpdir->getCurrPath(),Utility::getMediaExtensions()); } - if(item.state == MENU_STATE_USB && libmpv->Stopped()){ + if(item.state == MENU_STATE_USB){ if(item.usbbasepath != ""){ item.first_item = true; if(item.usbpath != item.usbbasepath){ @@ -314,7 +387,7 @@ namespace GUI { } } - if(item.state == MENU_STATE_FILEBROWSER && libmpv->Stopped()){ + if(item.state == MENU_STATE_FILEBROWSER){ item.first_item = true; localdir->backPath(); localdir->DirList(localdir->getCurrentPath(),true,Utility::getMediaExtensions()); @@ -325,7 +398,6 @@ namespace GUI { if(item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER && item.playercontrolstate == PLAYER_CONTROL_STATE_NONE){ if(!libmpv->Stopped() && !item.masterlock){ item.state = item.laststate; - libmpv->Stop(); } }else if(item.rightmenustate == PLAYER_RIGHT_MENU_TRACKS){ @@ -358,6 +430,9 @@ namespace GUI { else if(item.rightmenustate == PLAYER_SUPERAUDIOEQ){ item.rightmenustate = PLAYER_RIGHT_MENU_AUDIO; } + else if(item.rightmenustate == PLAYER_RIGHT_MENU_SHADERMANIA){ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } } @@ -434,6 +509,7 @@ namespace GUI { mpv_event_property *prop = (mpv_event_property*)mp_event->data; if(std::string(prop->name) == "metadata" && !libmpv->Stopped()) { + if(prop->data == nullptr)continue; mpv_node node = *(mpv_node *)prop->data; printf("Node format %d\n",node.format); if (node.format == MPV_FORMAT_NODE_MAP) { @@ -513,6 +589,9 @@ namespace GUI { playerWindows::CacheWindow(); break; case MENU_STATE_PLAYER: + if(item.showVolume){ + playerWindows::VolumeWindow(); + } if(item.popupstate == POPUP_STATE_RESUME){ Popups::ResumePopup(); } @@ -567,7 +646,10 @@ namespace GUI { break; case PLAYER_RIGHT_MENU_SUB: playerWindows::RightHomeSub(&item.rightmenu_focus,&item.rightmenu_first_item); - break; + break; + case PLAYER_RIGHT_MENU_SHADERMANIA: + playerWindows::RightHomeShaderMania(); + break; case PLAYER_AUDIOEQ: playerWindows::AudioEqualizer(&item.rightmenu_focus,&item.rightmenu_first_item); break; @@ -609,8 +691,12 @@ namespace GUI { } int RenderLoop(void) { - +#ifdef __SWITCH__ + while (!renderloopdone && appletMainLoop()) +#endif +#ifdef _WIN32 while (!renderloopdone) +#endif { HandleEvents(); HandleLayers(); diff --git a/source/libmpv.cpp b/source/libmpv.cpp index bbc1700..a0be564 100644 --- a/source/libmpv.cpp +++ b/source/libmpv.cpp @@ -21,7 +21,7 @@ libMpv::libMpv(const std::string &configDir) { mpv_set_option_string(handle, "config", "yes"); mpv_set_option_string(handle, "config-dir", configDir.c_str()); mpv_set_option_string(handle, "terminal", "yes"); - mpv_set_option_string(handle, "msg-level", "all=errors"); + mpv_set_option_string(handle, "msg-level", "all=v"); mpv_set_option_string(handle, "vd-lavc-threads", "4"); mpv_set_option_string(handle, "vd-lavc-skiploopfilter", "all"); mpv_set_option_string(handle, "audio-channels", "stereo"); @@ -30,6 +30,8 @@ libMpv::libMpv(const std::string &configDir) { mpv_set_option_string(handle, "fbo-format", "rgba8"); mpv_set_option_string(handle, "gpu-nxmp-deint", std::to_string(configini->getDeinterlace(false)).c_str()); mpv_set_option_string(handle, "volume-max", "200"); + mpv_set_option_string(handle, "opengl-pbo", "yes"); + if(configini->getUseAlang(false)){ @@ -100,21 +102,34 @@ libMpv::libMpv(const std::string &configDir) { } void libMpv::loadFile(std::string _path){ - if(fileinfo != nullptr){ - delete fileinfo; + + if(!Stopped()){ + resetFileInfo(); + }else{ + if(fileinfo != nullptr){ + delete fileinfo; + fileinfo = nullptr; + } + fileinfo = new fileInfo(); } - fileinfo = new fileInfo(); fileinfo->path = _path; const char *cmd[] = {"loadfile", _path.c_str(), NULL}; mpv_command_async(handle, 0, cmd); setLoop(false); + setSubFontSize(configini->getSubFontSize(false),false); } void libMpv::loadFileLive(std::string _path,std::string _changename){ - if(fileinfo != nullptr){ - delete fileinfo; + if(!Stopped()){ + resetFileInfo(); + }else{ + if(fileinfo != nullptr){ + delete fileinfo; + fileinfo = nullptr; + } + fileinfo = new fileInfo(); } fileinfo = new fileInfo(); fileinfo->path = _path; @@ -123,6 +138,7 @@ void libMpv::loadFileLive(std::string _path,std::string _changename){ const char *cmd[] = {"loadfile", _path.c_str(), NULL}; mpv_command_async(handle, 0, cmd); setLoop(false); + setSubFontSize(configini->getSubFontSize(false),false); } int64_t libMpv::getPosition() { @@ -153,6 +169,7 @@ void libMpv::Resume() { } void libMpv::Stop() { + clearShader(); const char *cmd[] = {"stop", NULL}; mpv_command_async(handle, 0, cmd); } @@ -484,6 +501,10 @@ void libMpv::setVolume(int value,bool osd){ volume = value; } +int libMpv::getVolume(){ + return volume; +} + bool libMpv::getMute(){ if(volume == 0)return true; return false; @@ -518,7 +539,13 @@ void libMpv::setSubPos(int value,bool osd){ } void libMpv::setSubFontSize(int value,bool osd){ - mpv_set_property_async(handle, 0,"sub-font-size", MPV_FORMAT_INT64, &value); + if(osd){ + std::string cmd = "set sub-font-size " + std::to_string(value); + mpv_command_string(handle, cmd.c_str()); + }else{ + std::string cmd = "no-osd set sub-font-size " + std::to_string(value); + mpv_command_string(handle, cmd.c_str()); + } } void libMpv::setAudioEQ(int *eqval,bool osd){ @@ -572,6 +599,37 @@ bool libMpv::getLoop(){ return loop; } +void libMpv::setShader(std::string _filename){ + std::string command = std::string("no-osd change-list glsl-shaders set ") + _filename; + mpv_command_string(handle,command.c_str()); +} +void libMpv::clearShader(){ + mpv_command_string(handle,"no-osd change-list glsl-shaders clr \"\""); +} + +void libMpv::resetFileInfo(){ + fileinfo->title = "Unknown"; + fileinfo->path = ""; + fileinfo->duration = 0; + fileinfo->resume = 0; + fileinfo->bit_rate = 0; + fileinfo->videos.clear(); + fileinfo->audios.clear(); + fileinfo->subtitles.clear(); + + fileinfo->chapters.clear(); + + fileinfo->playbackInfo.vid_id = -1; + fileinfo->playbackInfo.aud_id = -1; + fileinfo->playbackInfo.sub_id = -1; + fileinfo->playbackInfo.position = 0; + fileinfo->playbackInfo.duration = 0; + fileinfo->playbackInfo.title = ""; + fileinfo->playbackInfo.artist = ""; + fileinfo->playbackInfo.islive = false; +} + + libMpv::~libMpv(){ if (context) { mpv_render_context_free(context); diff --git a/source/main.cpp b/source/main.cpp index 8bdf254..30bbeaa 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -25,6 +25,8 @@ #include "SQLiteDB.h" #include "eqpreset.h" +#include "shaderMania.h" + //#define NDEBUG 1 static bool init(); @@ -81,6 +83,8 @@ Tex NoLoopIcon; ImFont* fontSmall; +shaderMania* shadermania = nullptr; + const GLuint WIDTH = 1280, HEIGHT = 720; std::string nxmpTitle = std::string("NXMP v") + std::to_string(VERSION_MAJOR) + std::string(".") + std::to_string(VERSION_MINOR) + std::string(".") + std::to_string(VERSION_MICRO); @@ -128,6 +132,7 @@ static bool init() { #ifdef __SWITCH__ int main() { + appletLockExit(); #else int main(int argc,char *argv[]){ #endif @@ -149,6 +154,7 @@ int main(int argc,char *argv[]){ sqlitedb = new SQLiteDB("nxmp.db"); } + shadermania = new shaderMania(); #ifdef __SWITCH__ Result ret; @@ -308,6 +314,7 @@ int main(int argc,char *argv[]){ printf("Init Enigma2\n"); + GUI::RenderLoop(); printf("Ending Render Loop\n"); delete libmpv; @@ -361,6 +368,7 @@ int main(int argc,char *argv[]){ plExit(); romfsExit(); socketExit(); + appletUnlockExit(); #endif return 0; } diff --git a/source/shadermania/shaderMania.cpp b/source/shadermania/shaderMania.cpp new file mode 100644 index 0000000..654d993 --- /dev/null +++ b/source/shadermania/shaderMania.cpp @@ -0,0 +1,71 @@ +#include "shaderMania.h" + + +shaderMania::shaderMania(){ + + std::vector shadersext = {"glsl","hook"}; + DirList("./mpv/shaders",true,shadersext); + +} + + +std::vector shaderMania::getCurrList(){ + return currentlist; +} + +void shaderMania::DirList(const std::string &path,bool showHidden,const std::vector &extensions) { + + currentlist.clear(); + struct dirent *ent; + DIR *dir; + + if (!path.empty()) { + if ((dir = opendir(path.c_str())) != nullptr) { + while ((ent = readdir(dir)) != nullptr) { + if ((path == "/" || strlen(ent->d_name) == 1) && ent->d_name[0] == '.') { + continue; + } + if ((path == "/" || strlen(ent->d_name) == 2) && ent->d_name[0] == '.' && ent->d_name[1] == '.') { + continue; + } + if (!showHidden && ent->d_name[0] == '.') { + if (strlen(ent->d_name) != 2 && ent->d_name[1] != '.') { + continue; + } + } + + FS::FileEntry file; + file.name = ent->d_name; + file.path = FS::removeLastSlash(path) + "/" + file.name; + + struct stat st{}; + if (stat(file.path.c_str(), &st) == 0) { + file.size = (size_t) st.st_size; + file.type = S_ISDIR(st.st_mode) ? FS::FileEntryType::Directory : FS::FileEntryType::File; + } + if(file.type == FS::FileEntryType::File){ + bool isMediafile = false; + for (auto &ext : extensions) { + if (Utility::endsWith(file.name, ext, false)) { + isMediafile = true; + } + } + if(isMediafile){ + currentlist.push_back(file); + } + }else if(file.type == FS::FileEntryType::Directory){ + currentlist.push_back(file); + } + + } + + closedir(dir); + std::sort(currentlist.begin(), currentlist.end(), FS::Sort); + FS::FileEntry dummyfile; + dummyfile.name = "None"; + dummyfile.path = ""; + currentlist.insert(currentlist.begin(), dummyfile); + } + } + + } \ No newline at end of file diff --git a/source/shadermania/shaderMania.h b/source/shadermania/shaderMania.h new file mode 100644 index 0000000..255c2c2 --- /dev/null +++ b/source/shadermania/shaderMania.h @@ -0,0 +1,22 @@ +#ifndef NXMP_SHADERMANIA_H +#define NXMP_SHADERMANIA_H + +#include "localfiles.h" + + + +class shaderMania{ +public: + shaderMania(); + ~shaderMania(); + + std::vector getCurrList(); + void DirList(const std::string &path,bool showHidden,const std::vector &extensions); + +private: + std::vector currentlist; + +}; + + +#endif \ No newline at end of file