Skip to content

Commit

Permalink
Merge pull request #11 from darkxex/master
Browse files Browse the repository at this point in the history
All functions implemented.
  • Loading branch information
darkxex authored Feb 5, 2022
2 parents 91e393a + c815492 commit 0710dc8
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/
build-win32/
nxmp/
nxmp.*
compile.bat
55 changes: 55 additions & 0 deletions include/SwitchSys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

//
// Created by cpasjuste on 26/11/18.
//

#ifndef CROSS2D_SWITCH_CLOCKS_H
#define CROSS2D_SWITCH_CLOCKS_H
#include <stdio.h>
#include <switch.h>

namespace c2d {

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 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);

static int stock_cpu_clock;
static int stock_gpu_clock;
static int stock_emc_clock;
};
}

#endif //CROSS2D_SWITCH_CLOCKS_H
15 changes: 15 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -130,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;
Expand Down
2 changes: 2 additions & 0 deletions include/playerwindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
119 changes: 119 additions & 0 deletions source/SwitchSys.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
104 changes: 103 additions & 1 deletion source/UI/playerWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "imgui.h"
#include "utils.h"
#include "imgui_internal.h"
#include "SwitchSys.h"

using namespace c2d;

namespace playerWindows{

Expand Down Expand Up @@ -41,7 +43,7 @@ namespace playerWindows{
rightmenuposX = item.rightmenu_startpos;
if(item.rightmenu_startpos>1080)item.rightmenu_startpos-=10;
playerWindows::SetupRightWindow();
std::vector<std::string> topmenu = {"Tracks","Chapters","Aspect Ratio","Image","Audio","Subtitle","ShaderMania"};
std::vector<std::string> 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))){
Expand All @@ -54,6 +56,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;
}
Expand All @@ -69,6 +74,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) {
Expand Down Expand Up @@ -243,6 +251,100 @@ 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<std::string> 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)\"");
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);
}
}
}
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<std::string> 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<std::string> topmenu = {"Default","16:9","16:10","4:3","Custom Ratio"};
Expand Down
Loading

0 comments on commit 0710dc8

Please sign in to comment.