From bd987d1c4997c3a7b81b6242ee2bf78f96e82ce9 Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Sat, 5 Feb 2022 10:48:11 -0300 Subject: [PATCH 1/5] nothing important --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8523ef8..d77bc3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ build-win32/ nxmp.* +compile.bat From c83414b04d1564e184329a6ef3e300b78026e74b Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Sat, 5 Feb 2022 11:06:20 -0300 Subject: [PATCH 2/5] Language Subtitle --- include/config.h | 15 +++++++++++ source/UI/settingsMenu.cpp | 35 +++++++++++++++++++++++++ source/config.cpp | 52 ++++++++++++++++++++++++++++++++++++++ source/libmpv.cpp | 7 +++++ 4 files changed, 109 insertions(+) diff --git a/include/config.h b/include/config.h index 3b21376..2d20b90 100644 --- a/include/config.h +++ b/include/config.h @@ -39,6 +39,13 @@ class Config{ void setUseAlang(bool _val); int getAlang(bool tmpvalue); void setAlang(int lang); + + //Slang + bool getUseSlang(bool tmpvalue); + void setUseSlang(bool _val); + int getSlang(bool tmpvalue); + void setSlang(int lang); + //End Slang int getSubFontSize(bool tmpvalue); void setSubFontSize(int val); @@ -86,6 +93,14 @@ class Config{ int tmpalang; int alang; + //Slang + bool tmpuseslang; + bool useslang; + + int tmpslang; + int slang; + //End Slang + int tmpsubfontsize; int subfontsize; diff --git a/source/UI/settingsMenu.cpp b/source/UI/settingsMenu.cpp index 851e1ff..8e3c2f9 100644 --- a/source/UI/settingsMenu.cpp +++ b/source/UI/settingsMenu.cpp @@ -113,6 +113,38 @@ namespace Windows { if(!alangbool){ ImGui::EndDisabled(); } + + //Slang + ImGui::Dummy(ImVec2(0.0f,10.0f)); + bool slangbool = configini->getUseSlang(true); + if(ImGui::Checkbox("Use Auto Subtitles Language", &slangbool)){ + configini->setUseSlang(slangbool); + } + + if(!slangbool){ + ImGui::BeginDisabled(); + } + + + const char* combo_preview_value_2 = Utility::getLanguages()[configini->getSlang(true)].lang3.c_str(); // Pass in the preview value visible before opening the combo (it could be anything) + ImGui::PushItemWidth(300); + if (ImGui::BeginCombo("Subtitles Language", combo_preview_value_2, 0)) + { + for (int n = 0; n < Utility::getLanguages().size(); n++) + { + const bool is_selected = (configini->getSlang(true) == n); + if (ImGui::Selectable(Utility::getLanguages()[n].lang3.c_str(), is_selected)) + configini->setSlang(n); + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + if(!slangbool){ + ImGui::EndDisabled(); + } + //End Slang ImGui::Dummy(ImVec2(0.0f,30.0f)); ImGui::Text("Subtitle"); ImGui::Separator(); @@ -261,6 +293,9 @@ namespace Windows { configini->setLongSeek(configini->getLongSeek(false)); configini->setShortSeek(configini->getShortSeek(false)); configini->setAlang(configini->getAlang(false)); + //Slang + configini->setSlang(configini->getSlang(false)); + //end Slang configini->setSubFontSize(configini->getSubFontSize(false)); configini->setSubFontColor(configini->getSubFontColor(false)); configini->setDbActive(configini->getDeinterlace(false)); diff --git a/source/config.cpp b/source/config.cpp index 9b19629..c7b429f 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -58,6 +58,23 @@ Config::Config(std::string inifile){ alang = Utility::getLanguagesIdx(alangstring); tmpalang = alang; + + //Slang + useslang = ini->GetBoolValue("Main", "useslang"); + tmpuseslang = useslang; + const char* slangpv; + slangpv = ini->GetValue("Main", "slang"); + std::string slangstring = "eng"; + if(slangpv!= nullptr){ + slangstring = slangpv; + } + if(slangstring == ""){ + slangstring = "eng"; + } + + slang = Utility::getLanguagesIdx(slangstring); + tmpslang = slang; + //endSlang subfontsize = ini->GetLongValue("Main", "subfontsize"); if(subfontsize == 0)subfontsize = 55; @@ -254,6 +271,30 @@ void Config::setAlang(int lang){ tmpalang = lang; } +//Slang +bool Config::getUseSlang(bool tmpvalue){ + if(tmpvalue){ + return tmpuseslang; + } + return useslang; +} +void Config::setUseSlang(bool _val){ + tmpuseslang = _val; +} + +int Config::getSlang(bool tmpvalue){ + if(tmpvalue){ + return tmpslang; + } + return slang; +} + +void Config::setSlang(int lang){ + tmpslang = lang; +} +//end Slang + + int Config::getSubFontSize(bool tmpvalue){ if(tmpvalue){ return tmpsubfontsize; @@ -339,6 +380,9 @@ void Config::saveSettings(){ longseek = tmplongseek; shortseek = tmpshortseek; usealang = tmpusealang; + //slang + useslang = tmpuseslang; + //end slang subfontsize = tmpsubfontsize; deint = tmpdeint; dbactive = tmpdbactive; @@ -372,6 +416,14 @@ void Config::saveSettings(){ ini->Delete("Main", "alang"); ini->SetValue("Main", "alang", Utility::getLanguages()[tmpalang].lang3.c_str()); + //slang + ini->Delete("Main", "useslang"); + ini->SetBoolValue("Main", "useslang", useslang, NULL, false); + + ini->Delete("Main", "slang"); + ini->SetValue("Main", "slang", Utility::getLanguages()[tmpslang].lang3.c_str()); + //end slang + ini->Delete("Main", "subfontsize"); ini->SetLongValue("Main", "subfontsize", subfontsize, NULL, false); diff --git a/source/libmpv.cpp b/source/libmpv.cpp index f5f55ae..717faa4 100644 --- a/source/libmpv.cpp +++ b/source/libmpv.cpp @@ -38,6 +38,13 @@ libMpv::libMpv(const std::string &configDir) { std::string alangstring = Utility::getLanguages()[configini->getAlang(false)].lang3 + std::string(",") + Utility::getLanguages()[configini->getAlang(false)].lang2 + std::string(",eng,en"); mpv_set_option_string(handle, "alang", alangstring.c_str()); } + + //Slang + if(configini->getUseSlang(false)){ + std::string slangstring = Utility::getLanguages()[configini->getSlang(false)].lang3 + std::string(",") + Utility::getLanguages()[configini->getSlang(false)].lang2 + std::string(",eng,en"); + mpv_set_option_string(handle, "slang", slangstring.c_str()); + } + //End Slang #ifdef _WIN32 mpv_set_option_string(handle, "hwdec", "auto-copy"); #endif From 720e85d1c3d517cdd993754853f4ecf89064e020 Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Sat, 5 Feb 2022 11:17:58 -0300 Subject: [PATCH 3/5] Overclock First Part --- include/SwitchSys.h | 151 ++++++++++++++++++++++++++++++++++++++++++++ source/main.cpp | 36 +++++++++++ 2 files changed, 187 insertions(+) create mode 100644 include/SwitchSys.h diff --git a/include/SwitchSys.h b/include/SwitchSys.h new file mode 100644 index 0000000..16c7c72 --- /dev/null +++ b/include/SwitchSys.h @@ -0,0 +1,151 @@ +#include +class SwitchSys { + + public: + + enum class CPUClock { + Stock = 0, // default clock when application is launched + Min = 1020000000, // minimal clock + Med = 1224000000, // medium clock + Max = 1785000000 // maximal clock + }; + + enum class GPUClock { + Stock = 0, // default clock when application is launched + Min = 307200000, // minimal clock + Med = 460000000, // medium clock + Max = 921000000 // maximal clock + }; + + enum class EMCClock { + Stock = 0, // default clock when application is launched + Min = 1331200000, // minimal clock + Med = 1331200000, // medium clock + Max = 1600000000 // maximal clock + }; + + enum class Module { + Cpu = PcvModule_CpuBus, + Gpu = PcvModule_GPU, + Emc = PcvModule_EMC + }; + + static int getClock(const Module &module, bool stockClocks = false); + + static bool setClock(const Module &module, int hz); + + static int stock_cpu_clock; + static int stock_gpu_clock; + static int stock_emc_clock; + }; + +int SwitchSys::stock_cpu_clock = 0; +int SwitchSys::stock_gpu_clock = 0; +int SwitchSys::stock_emc_clock = 0; + +int stock_cpu_clock_temp = 0; +int stock_gpu_clock_temp = 0; +int stock_emc_clock_temp = 0; + + + +bool SwitchSys::setClock(const SwitchSys::Module &module, int hz) { + + int new_hz = hz; + int bus_id = (int) module; + bool is_old = hosversionBefore(8, 0, 0); + + switch (module) { + case SwitchSys::Module::Cpu: + new_hz = new_hz <= 0 ? stock_cpu_clock : new_hz; + bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus; + break; + case SwitchSys::Module::Gpu: + new_hz = new_hz <= 0 ? stock_gpu_clock : new_hz; + bus_id = is_old ? (int) module : (int) PcvModuleId_GPU; + break; + case SwitchSys::Module::Emc: + new_hz = new_hz <= 0 ? stock_emc_clock : new_hz; + bus_id = is_old ? (int) module : (int) PcvModuleId_EMC; + break; + default: + break; + } + + if (is_old) { + if (R_SUCCEEDED(pcvSetClockRate((PcvModule) bus_id, (u32) new_hz))) { + return true; + } + } else { + ClkrstSession session = {0}; + clkrstOpenSession(&session, (PcvModuleId) bus_id, 3); + clkrstSetClockRate(&session, hz); + clkrstCloseSession(&session); + } + + + return false; +} +int SwitchSys::getClock(const SwitchSys::Module &module, bool stockClocks) { + + u32 hz = 0; + int bus_id = 0; + bool is_old = hosversionBefore(8, 0, 0); + + if (stockClocks) { + switch (module) { + case SwitchSys::Module::Cpu: + return stock_cpu_clock; + case SwitchSys::Module::Gpu: + return stock_gpu_clock; + case SwitchSys::Module::Emc: + return stock_emc_clock; + default: + return 0; + } + } + + switch (module) { + case SwitchSys::Module::Cpu: + bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus; + break; + case SwitchSys::Module::Gpu: + bus_id = is_old ? (int) module : (int) PcvModuleId_GPU; + break; + case SwitchSys::Module::Emc: + bus_id = is_old ? (int) module : (int) PcvModuleId_EMC; + break; + default: + break; + } + + if (hosversionBefore(8, 0, 0)) { + pcvGetClockRate((PcvModule) bus_id, &hz); + } else { + ClkrstSession session = {0}; + clkrstOpenSession(&session, (PcvModuleId) bus_id, 3); + clkrstGetClockRate(&session, &hz); + clkrstCloseSession(&session); + } + + + return (int) hz; +} + +void maxClock() +{ int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu); + SwitchSys::setClock(SwitchSys::Module::Cpu, (int) SwitchSys::CPUClock::Max); + SwitchSys::setClock(SwitchSys::Module::Gpu, (int) SwitchSys::GPUClock::Max); + SwitchSys::setClock(SwitchSys::Module::Emc, (int) SwitchSys::EMCClock::Max); + printf("setting max cpu speed (old: %i, new: %i)\n", + clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu));} + +void defaultClock(int stock_cpu_clock_temp,int stock_gpu_clock_temp,int stock_emc_clock_temp) +{ + int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu); + SwitchSys::setClock(SwitchSys::Module::Cpu, (int) stock_cpu_clock_temp); + SwitchSys::setClock(SwitchSys::Module::Gpu, (int) stock_gpu_clock_temp); + SwitchSys::setClock(SwitchSys::Module::Emc, (int) stock_emc_clock_temp); + printf("restoring cpu speed (old: %i, new: %i)\n", + clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu)); +} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 213adbf..e689f75 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -3,6 +3,7 @@ #ifdef NXMP_SWITCH #include +#include "SwitchSys.h" #endif @@ -412,10 +413,40 @@ int main(int argc,char *argv[]){ #endif +#ifdef __SWITCH__ + +if (hosversionBefore(8, 0, 0)) { + if (R_SUCCEEDED(pcvInitialize())) { + SwitchSys::stock_cpu_clock = SwitchSys::getClock(SwitchSys::Module::Cpu); + SwitchSys::stock_gpu_clock = SwitchSys::getClock(SwitchSys::Module::Gpu); + SwitchSys::stock_emc_clock = SwitchSys::getClock(SwitchSys::Module::Emc); + } + } else { + if (R_SUCCEEDED(clkrstInitialize())) { + SwitchSys::stock_cpu_clock = SwitchSys::getClock(SwitchSys::Module::Cpu); + SwitchSys::stock_gpu_clock = SwitchSys::getClock(SwitchSys::Module::Gpu); + SwitchSys::stock_emc_clock = SwitchSys::getClock(SwitchSys::Module::Emc); + } + } + + printf("SWITCHRenderer(): clocks: cpu=%i, gpu=%i, emc=%i\n", + SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock); + stock_cpu_clock_temp = SwitchSys::stock_cpu_clock; + stock_gpu_clock_temp = SwitchSys::stock_gpu_clock; + stock_emc_clock_temp = SwitchSys::stock_emc_clock; + + maxClock(); +#endif + GUI::initMpv(); GUI::RenderLoop(); printf("Ending Render Loop\n"); + +#ifdef __SWITCH__ + defaultClock(stock_cpu_clock_temp, stock_gpu_clock_temp, stock_emc_clock_temp); +#endif + delete libmpv; libmpv = nullptr; printf("Ending MPV\n"); @@ -474,6 +505,11 @@ int main(int argc,char *argv[]){ printf("Exit Services\n"); #ifdef NXMP_SWITCH + if (hosversionBefore(8, 0, 0)) { + pcvExit(); + } else { + clkrstExit(); + } ncmExit(); plExit(); romfsExit(); From 86f41f7480f627e5c3ffd1a352a0bc4c21f0d20c Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Sat, 5 Feb 2022 11:35:06 -0300 Subject: [PATCH 4/5] Interpolation and Anime4K Upscaler a folder called anime4k in the MPV directory is necessary. like the example I showed you. --- include/gui.h | 2 + include/playerwindows.h | 2 + source/UI/playerWindows.cpp | 100 +++++++++++++++++++++++++++++++++++- source/gui.cpp | 12 +++++ 4 files changed, 115 insertions(+), 1 deletion(-) diff --git a/include/gui.h b/include/gui.h index d182258..1c01866 100644 --- a/include/gui.h +++ b/include/gui.h @@ -93,12 +93,14 @@ enum PLAYER_RIGHT_MENU_STATES { PLAYER_RIGHT_MENU_TRACKS_AUDIO, PLAYER_RIGHT_MENU_TRACKS_SUB, PLAYER_RIGHT_MENU_CHAPTERS, + PLAYER_RIGHT_MENU_INTERPOLATION, PLAYER_RIGHT_MENU_ARATIO, PLAYER_RIGHT_MENU_CUSTOMARATIO, PLAYER_RIGHT_MENU_IMAGE, PLAYER_RIGHT_MENU_AUDIO, PLAYER_RIGHT_MENU_SUB, PLAYER_RIGHT_MENU_SHADERMANIA, + PLAYER_RIGHT_MENU_ANIME4K, PLAYER_AUDIOEQ, PLAYER_SUPERAUDIOEQ }; diff --git a/include/playerwindows.h b/include/playerwindows.h index c4a74fa..926409e 100644 --- a/include/playerwindows.h +++ b/include/playerwindows.h @@ -78,6 +78,8 @@ namespace playerWindows{ void RightTrackVideoWindow(bool *focus, bool *first_item); void RightTrackAudioWindow(bool *focus, bool *first_item); void RightTrackSubWindow(bool *focus, bool *first_item); + void RightHomeInterpolation(bool *focus, bool *first_item); + void RightHomeAnime4K(bool *focus, bool *first_item); void RightHomeARatio(bool *focus, bool *first_item); void RightHomeCustomARatio(bool *focus, bool *first_item); void RightHomeImage(bool *focus, bool *first_item); diff --git a/source/UI/playerWindows.cpp b/source/UI/playerWindows.cpp index 5b81bcc..63f36f6 100644 --- a/source/UI/playerWindows.cpp +++ b/source/UI/playerWindows.cpp @@ -41,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","ShaderMania"}; + std::vector topmenu = {"Tracks","Chapters","Interpolation","Aspect Ratio","Image","Audio","Subtitle","ShaderMania","Anime4K v4.0.1"}; 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))){ @@ -54,6 +54,9 @@ namespace playerWindows{ if(topmenu[n] == "Chapters"){ item.rightmenustate = PLAYER_RIGHT_MENU_CHAPTERS; } + if(topmenu[n] == "Interpolation"){ + item.rightmenustate = PLAYER_RIGHT_MENU_INTERPOLATION; + } if(topmenu[n] == "Aspect Ratio"){ item.rightmenustate = PLAYER_RIGHT_MENU_ARATIO; } @@ -69,6 +72,9 @@ namespace playerWindows{ if(topmenu[n] == "ShaderMania"){ item.rightmenustate = PLAYER_RIGHT_MENU_SHADERMANIA; } + if(topmenu[n] == "Anime4K v4.0.1"){ + item.rightmenustate = PLAYER_RIGHT_MENU_ANIME4K; + } } } if (*first_item) { @@ -243,6 +249,98 @@ namespace playerWindows{ playerWindows::ExitWindow(); } + //Used For 1080p screens with less powerful GPUs: + //https://github.com/bloc97/Anime4K/blob/815b122284304e6e1e244a8cf6a160eeaa07040c/GLSL_Instructions.md + void RightHomeAnime4K(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + std::vector topmenu = {"Mode A (Fast)","Mode B (Fast)","Mode C (Fast)","Mode A+A (Fast)","Mode B+B (Fast)","Mode C+A (Fast)","Show Info","Disabled"}; + if (ImGui::Begin("Right Menu ARatio", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginListBox("Aspect Ratio",ImVec2(200.0f, 720.0f))){ + for (unsigned int n = 0; n < topmenu.size(); n++){ + static int selected = -1; + if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){ + if(n==0){ + mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode A (Fast)\""); + } + if(n==1){ + mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode B (Fast)\""); + + } + if(n==2){ + mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Upscale_Denoise_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode C (Fast)\""); + + } + if(n==3){ + mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_Restore_CNN_S.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode A+A (Fast)\""); + + } + if(n==4){ + mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_S.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode B+B (Fast)\""); + + } + if(n==5){ + mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Upscale_Denoise_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Restore_CNN_S.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode C+A (Fast)\""); + + } + if(n==6){ + mpv_command_string(libmpv->getHandle(), "show-text \"Shaders: ${glsl-shaders}\""); + } + if(n==7){ + mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders clr \"\"; show-text \"Anime4K Disabled\""); + } + } + } + if (*first_item) { + ImGui::SetFocusID(ImGui::GetID(topmenu[0].c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + ImGui::EndListBox(); + } + } + playerWindows::ExitWindow(); + } + + void RightHomeInterpolation(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + std::vector topmenu = {"Enable/Disable","Catmull-Rom","Mitchell","Bicubic","OverSample"}; + if (ImGui::Begin("Right Menu ARatio", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginListBox("Aspect Ratio",ImVec2(200.0f, 720.0f))){ + for (unsigned int n = 0; n < topmenu.size(); n++){ + static int selected = -1; + if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){ + if(n==0){ + mpv_command_string(libmpv->getHandle(), "cycle-values video-sync display-resample audio ; cycle-values interpolation yes no ; show-text \"Interpolation: ${interpolation} (${tscale})\""); + + } + if(n==1){ + mpv_command_string(libmpv->getHandle(), "set tscale \"catmull_rom\" ; show-text \"Interpolation: ${interpolation} (${tscale})\""); + + } + if(n==2){ + mpv_command_string(libmpv->getHandle(), "set tscale \"mitchell\" ; show-text \"Interpolation: ${interpolation} (${tscale})\""); + + } + if(n==3){ + mpv_command_string(libmpv->getHandle(), "set tscale \"bicubic\" ; show-text \"Interpolation: ${interpolation} (${tscale})\""); + + } + if(n==4){ + mpv_command_string(libmpv->getHandle(), "set tscale \"oversample\" ; show-text \"Interpolation: ${interpolation} (${tscale})\""); + + } + } + } + if (*first_item) { + ImGui::SetFocusID(ImGui::GetID(topmenu[0].c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + ImGui::EndListBox(); + } + } + playerWindows::ExitWindow(); + } void RightHomeARatio(bool *focus, bool *first_item){ playerWindows::SetupRightWindow(); std::vector topmenu = {"Default","16:9","16:10","4:3","Custom Ratio"}; diff --git a/source/gui.cpp b/source/gui.cpp index 5cc7a29..f4b9a6e 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -558,6 +558,12 @@ namespace GUI { else if(item.rightmenustate == PLAYER_RIGHT_MENU_CHAPTERS){ item.rightmenustate = PLAYER_RIGHT_MENU_HOME; } + else if(item.rightmenustate == PLAYER_RIGHT_MENU_INTERPOLATION){ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } + else if(item.rightmenustate == PLAYER_RIGHT_MENU_ANIME4K){ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } else if(item.rightmenustate == PLAYER_RIGHT_MENU_ARATIO){ item.rightmenustate = PLAYER_RIGHT_MENU_HOME; } @@ -864,6 +870,12 @@ namespace GUI { case PLAYER_RIGHT_MENU_CHAPTERS: playerWindows::RightChapterWindow(&item.rightmenu_focus,&item.rightmenu_first_item); break; + case PLAYER_RIGHT_MENU_INTERPOLATION: + playerWindows::RightHomeInterpolation(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_ANIME4K: + playerWindows::RightHomeAnime4K(&item.rightmenu_focus,&item.rightmenu_first_item); + break; case PLAYER_RIGHT_MENU_ARATIO: playerWindows::RightHomeARatio(&item.rightmenu_focus,&item.rightmenu_first_item); break; From c8154926c3ad6f4f19396464e40e61992d332498 Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Sat, 5 Feb 2022 13:46:46 -0300 Subject: [PATCH 5/5] finished Overclock --- .gitignore | 1 + include/SwitchSys.h | 126 +++++------------------------------- include/gui.h | 2 +- source/SwitchSys.cpp | 119 ++++++++++++++++++++++++++++++++++ source/UI/playerWindows.cpp | 14 ++-- source/gui.cpp | 23 ++++++- source/main.cpp | 15 ++--- 7 files changed, 173 insertions(+), 127 deletions(-) create mode 100644 source/SwitchSys.cpp diff --git a/.gitignore b/.gitignore index d77bc3a..bf84f65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ build-win32/ +nxmp/ nxmp.* compile.bat diff --git a/include/SwitchSys.h b/include/SwitchSys.h index 16c7c72..d519934 100644 --- a/include/SwitchSys.h +++ b/include/SwitchSys.h @@ -1,5 +1,16 @@ + +// +// Created by cpasjuste on 26/11/18. +// + +#ifndef CROSS2D_SWITCH_CLOCKS_H +#define CROSS2D_SWITCH_CLOCKS_H #include -class SwitchSys { +#include + +namespace c2d { + + class SwitchSys { public: @@ -29,7 +40,8 @@ class SwitchSys { Gpu = PcvModule_GPU, Emc = PcvModule_EMC }; - + static void maxClock(); + static void defaultClock(int stock_cpu_clock_temp,int stock_gpu_clock_temp,int stock_emc_clock_temp); static int getClock(const Module &module, bool stockClocks = false); static bool setClock(const Module &module, int hz); @@ -38,114 +50,6 @@ class SwitchSys { static int stock_gpu_clock; static int stock_emc_clock; }; - -int SwitchSys::stock_cpu_clock = 0; -int SwitchSys::stock_gpu_clock = 0; -int SwitchSys::stock_emc_clock = 0; - -int stock_cpu_clock_temp = 0; -int stock_gpu_clock_temp = 0; -int stock_emc_clock_temp = 0; - - - -bool SwitchSys::setClock(const SwitchSys::Module &module, int hz) { - - int new_hz = hz; - int bus_id = (int) module; - bool is_old = hosversionBefore(8, 0, 0); - - switch (module) { - case SwitchSys::Module::Cpu: - new_hz = new_hz <= 0 ? stock_cpu_clock : new_hz; - bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus; - break; - case SwitchSys::Module::Gpu: - new_hz = new_hz <= 0 ? stock_gpu_clock : new_hz; - bus_id = is_old ? (int) module : (int) PcvModuleId_GPU; - break; - case SwitchSys::Module::Emc: - new_hz = new_hz <= 0 ? stock_emc_clock : new_hz; - bus_id = is_old ? (int) module : (int) PcvModuleId_EMC; - break; - default: - break; - } - - if (is_old) { - if (R_SUCCEEDED(pcvSetClockRate((PcvModule) bus_id, (u32) new_hz))) { - return true; - } - } else { - ClkrstSession session = {0}; - clkrstOpenSession(&session, (PcvModuleId) bus_id, 3); - clkrstSetClockRate(&session, hz); - clkrstCloseSession(&session); - } - - - return false; } -int SwitchSys::getClock(const SwitchSys::Module &module, bool stockClocks) { - - u32 hz = 0; - int bus_id = 0; - bool is_old = hosversionBefore(8, 0, 0); - - if (stockClocks) { - switch (module) { - case SwitchSys::Module::Cpu: - return stock_cpu_clock; - case SwitchSys::Module::Gpu: - return stock_gpu_clock; - case SwitchSys::Module::Emc: - return stock_emc_clock; - default: - return 0; - } - } - - switch (module) { - case SwitchSys::Module::Cpu: - bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus; - break; - case SwitchSys::Module::Gpu: - bus_id = is_old ? (int) module : (int) PcvModuleId_GPU; - break; - case SwitchSys::Module::Emc: - bus_id = is_old ? (int) module : (int) PcvModuleId_EMC; - break; - default: - break; - } - - if (hosversionBefore(8, 0, 0)) { - pcvGetClockRate((PcvModule) bus_id, &hz); - } else { - ClkrstSession session = {0}; - clkrstOpenSession(&session, (PcvModuleId) bus_id, 3); - clkrstGetClockRate(&session, &hz); - clkrstCloseSession(&session); - } - - - return (int) hz; -} - -void maxClock() -{ int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu); - SwitchSys::setClock(SwitchSys::Module::Cpu, (int) SwitchSys::CPUClock::Max); - SwitchSys::setClock(SwitchSys::Module::Gpu, (int) SwitchSys::GPUClock::Max); - SwitchSys::setClock(SwitchSys::Module::Emc, (int) SwitchSys::EMCClock::Max); - printf("setting max cpu speed (old: %i, new: %i)\n", - clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu));} -void defaultClock(int stock_cpu_clock_temp,int stock_gpu_clock_temp,int stock_emc_clock_temp) -{ - int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu); - SwitchSys::setClock(SwitchSys::Module::Cpu, (int) stock_cpu_clock_temp); - SwitchSys::setClock(SwitchSys::Module::Gpu, (int) stock_gpu_clock_temp); - SwitchSys::setClock(SwitchSys::Module::Emc, (int) stock_emc_clock_temp); - printf("restoring cpu speed (old: %i, new: %i)\n", - clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu)); -} \ No newline at end of file +#endif //CROSS2D_SWITCH_CLOCKS_H \ No newline at end of file diff --git a/include/gui.h b/include/gui.h index 1c01866..307c452 100644 --- a/include/gui.h +++ b/include/gui.h @@ -132,7 +132,7 @@ typedef struct { int playershowcontrols = false; int playershowstats = false; bool masterlock = false; - + bool clockoc = false; bool first_item; bool focus; int fileHoveredidx = 0; diff --git a/source/SwitchSys.cpp b/source/SwitchSys.cpp new file mode 100644 index 0000000..5aa043c --- /dev/null +++ b/source/SwitchSys.cpp @@ -0,0 +1,119 @@ +// +// Created by cpasjuste on 26/11/18. +// + +#include "SwitchSys.h" + +using namespace c2d; + +int SwitchSys::stock_cpu_clock = 0; +int SwitchSys::stock_gpu_clock = 0; +int SwitchSys::stock_emc_clock = 0; + +int SwitchSys::getClock(const SwitchSys::Module &module, bool stockClocks) { + + u32 hz = 0; + + + int bus_id = 0; + bool is_old = hosversionBefore(8, 0, 0); + + if (stockClocks) { + switch (module) { + case SwitchSys::Module::Cpu: + return stock_cpu_clock; + case SwitchSys::Module::Gpu: + return stock_gpu_clock; + case SwitchSys::Module::Emc: + return stock_emc_clock; + default: + return 0; + } + } + + switch (module) { + case SwitchSys::Module::Cpu: + bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus; + break; + case SwitchSys::Module::Gpu: + bus_id = is_old ? (int) module : (int) PcvModuleId_GPU; + break; + case SwitchSys::Module::Emc: + bus_id = is_old ? (int) module : (int) PcvModuleId_EMC; + break; + default: + break; + } + + if (hosversionBefore(8, 0, 0)) { + pcvGetClockRate((PcvModule) bus_id, &hz); + } else { + ClkrstSession session = {0}; + clkrstOpenSession(&session, (PcvModuleId) bus_id, 3); + clkrstGetClockRate(&session, &hz); + clkrstCloseSession(&session); + } + + + return (int) hz; +} + + + + +bool SwitchSys::setClock(const SwitchSys::Module &module, int hz) { + + + int new_hz = hz; + int bus_id = (int) module; + bool is_old = hosversionBefore(8, 0, 0); + + switch (module) { + case SwitchSys::Module::Cpu: + new_hz = new_hz <= 0 ? stock_cpu_clock : new_hz; + bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus; + break; + case SwitchSys::Module::Gpu: + new_hz = new_hz <= 0 ? stock_gpu_clock : new_hz; + bus_id = is_old ? (int) module : (int) PcvModuleId_GPU; + break; + case SwitchSys::Module::Emc: + new_hz = new_hz <= 0 ? stock_emc_clock : new_hz; + bus_id = is_old ? (int) module : (int) PcvModuleId_EMC; + break; + default: + break; + } + + if (is_old) { + if (R_SUCCEEDED(pcvSetClockRate((PcvModule) bus_id, (u32) new_hz))) { + return true; + } + } else { + ClkrstSession session = {0}; + clkrstOpenSession(&session, (PcvModuleId) bus_id, 3); + clkrstSetClockRate(&session, hz); + clkrstCloseSession(&session); + } + + + return false; +} + +void SwitchSys::maxClock() +{ int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu); + SwitchSys::setClock(SwitchSys::Module::Cpu, (int) SwitchSys::CPUClock::Max); + SwitchSys::setClock(SwitchSys::Module::Gpu, (int) SwitchSys::GPUClock::Max); + SwitchSys::setClock(SwitchSys::Module::Emc, (int) SwitchSys::EMCClock::Max); + printf("setting max cpu speed (old: %i, new: %i)\n", + clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu));} + +void SwitchSys::defaultClock(int stock_cpu_clock_temp,int stock_gpu_clock_temp,int stock_emc_clock_temp) +{ + int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu); + SwitchSys::setClock(SwitchSys::Module::Cpu, (int) stock_cpu_clock_temp); + SwitchSys::setClock(SwitchSys::Module::Gpu, (int) stock_gpu_clock_temp); + SwitchSys::setClock(SwitchSys::Module::Emc, (int) stock_emc_clock_temp); + printf("restoring cpu speed (old: %i, new: %i)\n", + clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu)); +} \ No newline at end of file diff --git a/source/UI/playerWindows.cpp b/source/UI/playerWindows.cpp index 63f36f6..473a903 100644 --- a/source/UI/playerWindows.cpp +++ b/source/UI/playerWindows.cpp @@ -3,7 +3,9 @@ #include "imgui.h" #include "utils.h" #include "imgui_internal.h" +#include "SwitchSys.h" +using namespace c2d; namespace playerWindows{ @@ -262,32 +264,34 @@ namespace playerWindows{ if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){ if(n==0){ mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode A (Fast)\""); + SwitchSys::maxClock(); } if(n==1){ mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode B (Fast)\""); - + SwitchSys::maxClock(); } if(n==2){ mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Upscale_Denoise_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode C (Fast)\""); - + SwitchSys::maxClock(); } if(n==3){ mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_Restore_CNN_S.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode A+A (Fast)\""); - + SwitchSys::maxClock(); } if(n==4){ mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_S.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode B+B (Fast)\""); - + SwitchSys::maxClock(); } if(n==5){ mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Upscale_Denoise_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Restore_CNN_S.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode C+A (Fast)\""); - + SwitchSys::maxClock(); } if(n==6){ mpv_command_string(libmpv->getHandle(), "show-text \"Shaders: ${glsl-shaders}\""); } if(n==7){ mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders clr \"\"; show-text \"Anime4K Disabled\""); + SwitchSys::defaultClock(SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock); } } } diff --git a/source/gui.cpp b/source/gui.cpp index f4b9a6e..56d83fd 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -5,11 +5,13 @@ #include "gui.h" #include "localfiles.h" - #include "imgui.h" #include "imgui_internal.h" #include "imgui_impl_sdl.h" #include "imgui_impl_opengl3.h" +#include "SwitchSys.h" + +using namespace c2d; MenuItem item; @@ -47,6 +49,20 @@ namespace GUI { } } + + void toggleOC(){ + item.clockoc = !item.clockoc; + if(item.clockoc){ + const char *cmd[] = {"show-text", "Overclock Enabled","2000", NULL}; + mpv_command_async(libmpv->getHandle(), 0, cmd); + SwitchSys::maxClock(); + }else{ + const char *cmd[] = {"show-text", "Overclock Disabled","2000", NULL}; + mpv_command_async(libmpv->getHandle(), 0, cmd); + SwitchSys::defaultClock(SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock); + } + + } void HandleEvents(){ @@ -345,6 +361,11 @@ namespace GUI { toggleMasterLock(); } } + if (button == SDL_KEY_LSTICK){ + if(item.state == MENU_STATE_PLAYER && !item.masterlock){ + toggleOC(); + } + } if (button == SDL_KEY_MINUS){ if(item.state == MENU_STATE_PLAYER && !item.masterlock){ item.state = item.laststate; diff --git a/source/main.cpp b/source/main.cpp index e689f75..24574b4 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -3,7 +3,6 @@ #ifdef NXMP_SWITCH #include -#include "SwitchSys.h" #endif @@ -39,10 +38,12 @@ #include "playlist.h" #include "shaderMania.h" - +#include "SwitchSys.h" #define NDEBUG 1 +using namespace c2d; + static bool init(); SDL_Window *window; @@ -430,12 +431,8 @@ if (hosversionBefore(8, 0, 0)) { } printf("SWITCHRenderer(): clocks: cpu=%i, gpu=%i, emc=%i\n", - SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock); - stock_cpu_clock_temp = SwitchSys::stock_cpu_clock; - stock_gpu_clock_temp = SwitchSys::stock_gpu_clock; - stock_emc_clock_temp = SwitchSys::stock_emc_clock; - - maxClock(); + SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock); + //SwitchSys::maxClock(); #endif GUI::initMpv(); @@ -444,7 +441,7 @@ if (hosversionBefore(8, 0, 0)) { printf("Ending Render Loop\n"); #ifdef __SWITCH__ - defaultClock(stock_cpu_clock_temp, stock_gpu_clock_temp, stock_emc_clock_temp); + SwitchSys::defaultClock(SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock); #endif delete libmpv;