From 40a41608ca04b2890317061a6453ba375a349855 Mon Sep 17 00:00:00 2001 From: proconsule <34319995+proconsule@users.noreply.github.com> Date: Sun, 31 Oct 2021 11:47:58 +0100 Subject: [PATCH] v 0.3.0 - Track selection (video/audio/sub) - Custom Seek Values (in config.ini or via Settings Menu) - Aspect Ratio Control (with custom ratio) - Fix (disable Sleep Mode/Dimming on media playback) - Small fiexs --- Makefile | 8 +- README.md | 3 + include/apppopups.h | 21 ++ include/appwindows.h | 14 -- include/config.h | 17 ++ include/fileInfo.h | 56 +++++ include/gui.h | 24 +++ include/libmpv.h | 29 ++- include/playerwindows.h | 35 ++++ include/utils.h | 3 +- source/UI/apppopups.cpp | 37 ++++ source/UI/enigmaui.cpp | 154 +++++++------- source/UI/infoMenu.cpp | 33 ++- source/UI/mainMenu.cpp | 2 + source/UI/playerWindows.cpp | 267 ++++++++++++++++++++++++ source/UI/settingsMenu.cpp | 57 ++++- source/config.cpp | 39 ++++ source/gui.cpp | 165 +++++++++++---- source/libmpv.cpp | 257 ++++++++++++++++++++++- source/{ => localfs/usb}/usbfs.cpp | 0 {include => source/localfs/usb}/usbfs.h | 0 source/playerOverlay.cpp | 22 -- source/utils.cpp | 4 +- 23 files changed, 1064 insertions(+), 183 deletions(-) create mode 100644 include/apppopups.h create mode 100644 include/fileInfo.h create mode 100644 include/playerwindows.h create mode 100644 source/UI/apppopups.cpp create mode 100644 source/UI/playerWindows.cpp rename source/{ => localfs/usb}/usbfs.cpp (100%) rename {include => source/localfs/usb}/usbfs.h (100%) delete mode 100644 source/playerOverlay.cpp diff --git a/Makefile b/Makefile index 664b5cc..067dee3 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/UI source/remotefs/Enigma2 source/remotefs/ftplib source/remotefs/HTTPDir +SOURCES := libs/imgui libs/imgui/misc/freetype source source/UI source/remotefs/Enigma2 source/localfs/usb source/remotefs/ftplib source/remotefs/HTTPDir DATA := data -INCLUDES := libs/simpleini libs/imgui include source/remotefs/Enigma2 source/remotefs/ftplib source/remotefs/HTTPDir +INCLUDES := libs/simpleini libs/imgui include source/remotefs/Enigma2 source/localfs/usb source/remotefs/ftplib source/remotefs/HTTPDir ROMFS := romfs VERSION_MAJOR := 0 -VERSION_MINOR := 2 -VERSION_MICRO := 1 +VERSION_MINOR := 3 +VERSION_MICRO := 0 APP_TITLE := NXMP APP_AUTHOR := proconsule diff --git a/README.md b/README.md index d053cb4..ba7ce49 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ Buttons Mapping - R L ZR ZL (seek +/- during playback) - \+ Exit NXMP - R Stick Button Toggle Masterlock (during playback, only A button will work) +- Dpad Right (during playback show right menu) +- Dpad Left (during playback close right menu) FAQ @@ -58,6 +60,7 @@ FAQ Thanks to ----- - Cpasjuste for pPlay https://github.com/Cpasjuste/pplay some code was taken here (mpv part) +- DarkMatterCore for libusbhsfs https://github.com/DarkMatterCore/libusbhsfs (this gives NXMP USB support) - bodyXY @ GBATemp forum for banner and icons - docgold @ GBATemp forum for Enigma2 samples and support on decoders - tataniko @ GBATemp forum for suggestions and bug hunting diff --git a/include/apppopups.h b/include/apppopups.h new file mode 100644 index 0000000..85fa34a --- /dev/null +++ b/include/apppopups.h @@ -0,0 +1,21 @@ +#ifndef NXMP_APPPOPUPS_H +#define NXMP_APPPOPUPS_H + +#include "imgui.h" + +namespace Popups { + inline void SetupPopup(const char *id) { + ImGui::OpenPopup(id); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + ImGui::SetNextWindowPos(ImVec2(640.0f, 360.0f), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + }; + + inline void ExitPopup(void) { + ImGui::EndPopup(); + ImGui::PopStyleVar(); + }; + + void SaveSettingsPopup(void); +} + +#endif \ No newline at end of file diff --git a/include/appwindows.h b/include/appwindows.h index 510628b..f61f153 100644 --- a/include/appwindows.h +++ b/include/appwindows.h @@ -26,19 +26,5 @@ namespace Windows { } -namespace PlayerWindows { - inline void SetupWindow(void) { - ImGui::SetNextWindowPos(ImVec2(0.0f, 600.0f), ImGuiCond_Once); - ImGui::SetNextWindowSize(ImVec2(1280.0f, 120.0f), ImGuiCond_Once); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - }; - inline void ExitWindow(void) { - ImGui::End(); - ImGui::PopStyleVar(); - }; - - void PlayerControls(); - -} #endif \ No newline at end of file diff --git a/include/config.h b/include/config.h index d994c25..2943e3d 100644 --- a/include/config.h +++ b/include/config.h @@ -17,8 +17,25 @@ class Config{ std::string getEnigma(); std::string getStartPath(); + int getLongSeek(bool tmpvalue); + int getShortSeek(bool tmpvalue); + + void setLongSeek(int seektime); + void setShortSeek(int seektime); + + void saveSettings(); + std::vector topmenu; CSimpleIniA *ini; + +private: + int shortseek; + int longseek; + + int tmpshortseek; + int tmplongseek; + + std::string inifilePath; }; diff --git a/include/fileInfo.h b/include/fileInfo.h new file mode 100644 index 0000000..e29748d --- /dev/null +++ b/include/fileInfo.h @@ -0,0 +1,56 @@ +#ifndef NXMP_FILEINFO_H +#define NXMP_FILEINFO_H + +#include +#include + +class fileInfo { + +public: + + class Track { + public: + int id; + std::string type; + std::string title = "Unknown"; + std::string language = "N/A"; + std::string codec; + int channels; + int bit_rate; + int sample_rate; + int width; + int height; + bool selected = false; + }; + + class Chapter{ + public: + std::string title; + double time; + }; + + class Playback { + public: + int vid_id = -1; + int aud_id = -1; + int sub_id = -1; + int position = 0; + }; + + + std::string title = "Unknown"; + std::string path; + long duration = 0; + int bit_rate = 0; + std::vector videos; + std::vector audios; + std::vector subtitles; + + std::vector chapters; + + Playback playbackInfo; + + +}; + +#endif \ No newline at end of file diff --git a/include/gui.h b/include/gui.h index 26d3965..eaa029f 100644 --- a/include/gui.h +++ b/include/gui.h @@ -9,6 +9,8 @@ #endif #include #include "appwindows.h" +#include "apppopups.h" +#include "playerwindows.h" #include "libmpv.h" #include "config.h" #include "remotefs.h" @@ -33,10 +35,29 @@ enum MENU_STATES { MENU_STATE_PLAYER }; +enum APP_POPUP_STATES { + POPUP_STATE_NONE, + POPUP_STATE_SAVE_SETTINGS +}; + +enum PLAYER_RIGHT_MENU_STATES { + PLAYER_RIGHT_MENU_PLAYER, + PLAYER_RIGHT_MENU_HOME, + PLAYER_RIGHT_MENU_TRACKS, + PLAYER_RIGHT_MENU_TRACKS_VIDEO, + PLAYER_RIGHT_MENU_TRACKS_AUDIO, + PLAYER_RIGHT_MENU_TRACKS_SUB, + PLAYER_RIGHT_MENU_CHAPTERS, + PLAYER_RIGHT_MENU_ARATIO, + PLAYER_RIGHT_MENU_CUSTOMARATIO +}; + typedef struct { MENU_STATES state = MENU_STATE_HOME; MENU_STATES laststate = MENU_STATE_FILEBROWSER; + PLAYER_RIGHT_MENU_STATES rightmenustate = PLAYER_RIGHT_MENU_PLAYER; + APP_POPUP_STATES popupstate = POPUP_STATE_NONE; int selected = 0; std::string localpath = "/switch/nxmp"; std::vector localfileentries; @@ -56,6 +77,9 @@ typedef struct { bool first_item; bool focus; + bool rightmenu_first_item; + bool rightmenu_focus; + } MenuItem; diff --git a/include/libmpv.h b/include/libmpv.h index d681376..25a12ac 100644 --- a/include/libmpv.h +++ b/include/libmpv.h @@ -2,10 +2,16 @@ #define NXMP_LIBMPVMPV_H #include +#include "fileInfo.h" #include #include +struct decoderlist_struct{ + std::string codecname; + std::string codecdesc; +}; + class libMpv{ public: @@ -19,9 +25,7 @@ class libMpv{ void Stop(); - void seekSilent(double position); - - void seekOSD(double position); + void seek(double position,bool osd); bool Stopped(); @@ -29,17 +33,34 @@ class libMpv{ int64_t getPosition(); + int64_t getVideoWidth(); + int64_t getVideoHeight(); + + fileInfo *getFileInfo(); + + void setVid(int id, bool osd); + void setAid(int id, bool osd); + void setSid(int id, bool osd); + + void setAspectRatio(double ratio,bool osd); + + void getfileInfo(); + + mpv_handle *getHandle(); mpv_render_context *getContext(); + std::vector getDecoderList(); std::string mpv_version; std::string ffmpeg_version; - + private: mpv_handle *handle = nullptr; mpv_render_context *context = nullptr; + std::vector decoderlist; + fileInfo * fileinfo = nullptr; }; diff --git a/include/playerwindows.h b/include/playerwindows.h new file mode 100644 index 0000000..07696d7 --- /dev/null +++ b/include/playerwindows.h @@ -0,0 +1,35 @@ +#ifndef NXMP_PLAYERWINDOWS_H +#define NXMP_PLAYERWINDOWS_H + +#include "imgui.h" + + +namespace playerWindows{ + inline void SetupRightWindow(void) { + ImGui::SetNextWindowPos(ImVec2(1080.0f, 0.0f), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(200.0f, 720.0f), ImGuiCond_Once); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); + + }; + + inline void ExitWindow(void) { + ImGui::End(); + ImGui::PopStyleVar(); + ImGui::PopStyleColor(); + }; + + + + void RightHomeWindow(bool *focus, bool *first_item); + void RightTrackWindow(bool *focus, bool *first_item); + void RightChapterWindow(bool *focus, bool *first_item); + void RightTrackVideoWindow(bool *focus, bool *first_item); + void RightTrackAudioWindow(bool *focus, bool *first_item); + void RightTrackSubWindow(bool *focus, bool *first_item); + void RightHomeARatio(bool *focus, bool *first_item); + void RightHomeCustomARatio(bool *focus, bool *first_item); + +} + +#endif \ No newline at end of file diff --git a/include/utils.h b/include/utils.h index 9f9b939..ea1247e 100644 --- a/include/utils.h +++ b/include/utils.h @@ -41,7 +41,8 @@ namespace Utility{ std::string toUpper(const std::string &str); bool endsWith(const std::string &value, const std::string &ending, bool sensitive); std::vector getMediaExtensions(); - std::string humanSize(uint64_t bytes); + std::string humanSize(size_t bytes); + std::string str_tolower(std::string s); } #endif \ No newline at end of file diff --git a/source/UI/apppopups.cpp b/source/UI/apppopups.cpp new file mode 100644 index 0000000..cde4f33 --- /dev/null +++ b/source/UI/apppopups.cpp @@ -0,0 +1,37 @@ +#include "apppopups.h" +#include "gui.h" +#include "imgui.h" +#include "imgui_internal.h" +#include "utils.h" + +namespace Popups{ + + void SaveSettingsPopup(void) { + Popups::SetupPopup("Save Settings"); + + if (ImGui::BeginPopupModal("Save Settings", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + + ImGui::Text("Save Settings?"); + + ImVec2 button_size(ImGui::GetFontSize() * 7.0f, 0.0f); + if (ImGui::Button("Yes", button_size)) + { + item.state = MENU_STATE_HOME; + item.popupstate = POPUP_STATE_NONE; + configini->saveSettings(); + + } + ImGui::SameLine(); + if (ImGui::Button("No", button_size)) + { + + item.state = MENU_STATE_HOME; + item.popupstate = POPUP_STATE_NONE; + ImGui::CloseCurrentPopup(); + } + + } + Popups::ExitPopup(); + } + +} \ No newline at end of file diff --git a/source/UI/enigmaui.cpp b/source/UI/enigmaui.cpp index d2ffb7b..707b091 100644 --- a/source/UI/enigmaui.cpp +++ b/source/UI/enigmaui.cpp @@ -1,78 +1,78 @@ -#include "gui.h" -#include "imgui.h" -#include "imgui_internal.h" -#include "appwindows.h" -#include "utils.h" -#include "localfiles.h" -#include "Enigma2.h" - - -namespace Windows { - void EnigmaWindow(bool *focus, bool *first_item) { - Windows::SetupWindow(); - std::vector topmenu = {"Local Files","Network","Enigma2"}; - - if (ImGui::Begin("Enigma2", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_MenuBar)) { - ImGui::SetNextWindowFocus(); - if (ImGui::BeginMenuBar()) { - ImGui::Text("%s",enigma2->getCurrBouquet().name.c_str()); - ImGui::EndMenuBar(); - } - if (ImGui::BeginListBox("Enigma2 Browser Menu",ImVec2(1280.0f, 720.0f))){ - if(enigma2->getCurrBouquet().bouquetref == ""){ - for (unsigned int n = 0; n < enigma2->e2services.size(); n++){ - static int selected = -1; - - if (ImGui::Selectable(enigma2->e2services[n].name.c_str(), selected == n)){ - - enigma2->m3uParser((char *)enigma2->e2services[n].bouquetref.c_str()); - enigma2->setCurrBouquet(enigma2->e2services[n]); - } - if (selected) - ImGui::SetItemDefaultFocus(); - - } - if (*first_item) { - ImGui::SetFocusID(ImGui::GetID(enigma2->e2services[0].name.c_str()), ImGui::GetCurrentWindow()); - *first_item = false; - } - }else if(enigma2->getCurrBouquet().bouquetref != ""){ - for (unsigned int n = 0; n < enigma2->e2currbouqet.size(); n++){ - static int selected = -1; - std::string itemid = "##" + std::to_string(n); - float currstartpos = ImGui::GetCursorPosX(); - if (ImGui::Selectable(itemid.c_str(), selected == n, 0, ImVec2(0, 70))){ - - const char *cmd[] = {"loadfile", enigma2->e2currbouqet[n].url.c_str(), NULL}; - mpv_command_async(libmpv->getHandle(), 0, cmd); - } - ImGui::SameLine(); - ImGui::SetCursorPosX(currstartpos); - ImGui::Text("%s",enigma2->e2currbouqet[n].name.c_str()); - ImGui::SetCursorPosY(ImGui::GetCursorPosY()-40.0f); - ImGui::PushFont(fontSmall); - ImGui::Text(u8"%s",enigma2->e2currbouqet[n].epg.title.c_str()); - ImGui::PopFont(); - float progressval = (float)(enigma2->e2currbouqet[n].epg.currTime-enigma2->e2currbouqet[n].epg.startTime)/(float)enigma2->e2currbouqet[n].epg.duration; - std::string progressid = std::string("progress") + itemid; - if(enigma2->e2currbouqet[n].epg.title == "")progressval=0.0f; - ImGui::PushStyleColor(ImGuiCol_PlotHistogram,ImVec4(1.0f,1.0f,1.0f,0.6f)); - ImGui::ProgressBar(progressval,ImVec2(-1.0f,15),""); - ImGui::PopStyleColor(1); - ImGui::Separator(); - if (selected) - ImGui::SetItemDefaultFocus(); - - } - if (*first_item) { - std::string itemid = "##" + std::to_string(0); - ImGui::SetFocusID(ImGui::GetID(itemid.c_str()), ImGui::GetCurrentWindow()); - *first_item = false; - } - } - } - ImGui::EndListBox(); - } - Windows::ExitWindow(); - } +#include "gui.h" +#include "imgui.h" +#include "imgui_internal.h" +#include "appwindows.h" +#include "utils.h" +#include "localfiles.h" +#include "Enigma2.h" + + +namespace Windows { + void EnigmaWindow(bool *focus, bool *first_item) { + Windows::SetupWindow(); + std::vector topmenu = {"Local Files","Network","Enigma2"}; + + if (ImGui::Begin("Enigma2", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_MenuBar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginMenuBar()) { + ImGui::Text("%s",enigma2->getCurrBouquet().name.c_str()); + ImGui::EndMenuBar(); + } + if (ImGui::BeginListBox("Enigma2 Browser Menu",ImVec2(1280.0f, 720.0f))){ + if(enigma2->getCurrBouquet().bouquetref == ""){ + for (unsigned int n = 0; n < enigma2->e2services.size(); n++){ + static int selected = -1; + + if (ImGui::Selectable(enigma2->e2services[n].name.c_str(), selected == n)){ + + enigma2->m3uParser((char *)enigma2->e2services[n].bouquetref.c_str()); + enigma2->setCurrBouquet(enigma2->e2services[n]); + } + if (selected) + ImGui::SetItemDefaultFocus(); + + } + if (*first_item) { + ImGui::SetFocusID(ImGui::GetID(enigma2->e2services[0].name.c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + }else if(enigma2->getCurrBouquet().bouquetref != ""){ + for (unsigned int n = 0; n < enigma2->e2currbouqet.size(); n++){ + static int selected = -1; + std::string itemid = "##" + std::to_string(n); + float currstartpos = ImGui::GetCursorPosX(); + if (ImGui::Selectable(itemid.c_str(), selected == n, 0, ImVec2(0, 70))){ + + const char *cmd[] = {"loadfile", enigma2->e2currbouqet[n].url.c_str(), NULL}; + mpv_command_async(libmpv->getHandle(), 0, cmd); + } + ImGui::SameLine(); + ImGui::SetCursorPosX(currstartpos); + ImGui::Text("%s",enigma2->e2currbouqet[n].name.c_str()); + ImGui::SetCursorPosY(ImGui::GetCursorPosY()-40.0f); + ImGui::PushFont(fontSmall); + ImGui::Text(u8"%s",enigma2->e2currbouqet[n].epg.title.c_str()); + ImGui::PopFont(); + float progressval = (float)(enigma2->e2currbouqet[n].epg.currTime-enigma2->e2currbouqet[n].epg.startTime)/(float)enigma2->e2currbouqet[n].epg.duration; + std::string progressid = std::string("progress") + itemid; + if(enigma2->e2currbouqet[n].epg.title == "")progressval=0.0f; + ImGui::PushStyleColor(ImGuiCol_PlotHistogram,ImVec4(1.0f,1.0f,1.0f,0.6f)); + ImGui::ProgressBar(progressval,ImVec2(-1.0f,15),""); + ImGui::PopStyleColor(1); + ImGui::Separator(); + if (selected) + ImGui::SetItemDefaultFocus(); + + } + if (*first_item) { + std::string itemid = "##" + std::to_string(0); + ImGui::SetFocusID(ImGui::GetID(itemid.c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + } + } + ImGui::EndListBox(); + } + Windows::ExitWindow(); + } } \ No newline at end of file diff --git a/source/UI/infoMenu.cpp b/source/UI/infoMenu.cpp index 91c835d..80b18ed 100644 --- a/source/UI/infoMenu.cpp +++ b/source/UI/infoMenu.cpp @@ -11,11 +11,7 @@ namespace Windows { void InfoMenuWindow(bool *focus, bool *first_item) { Windows::SetupWindow(); if (ImGui::Begin("Info Menu Window", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse)) { - if (!*focus) { - ImGui::SetNextWindowFocus(); - *focus = true; - } - char nxmptext[32]; + char nxmptext[32]; char ffmpegtext[32]; char mpvtext[32]; sprintf(nxmptext,"NXMP v%d.%d.%d",VERSION_MAJOR,VERSION_MINOR,VERSION_MICRO); @@ -36,6 +32,33 @@ namespace Windows { ImGui::Image((void*)(intptr_t)MPVTexture.id, ImVec2(MPVTexture.width,MPVTexture.height)); ImGui::SetCursorPosX((windowWidth - ImGui::CalcTextSize(mpvtext, NULL, true).x) * 0.5f); ImGui::Text(mpvtext); + ImGui::Separator(); + ImGui::Text("Decoders List:"); + static int column_count = 2; + if (ImGui::BeginTable("decoderTable", column_count, ImGuiTableFlags_ScrollY|ImGuiTableFlags_SizingFixedFit)) + { + ImGui::TableSetupColumn("codec", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("codecdesc", ImGuiTableColumnFlags_WidthStretch); + std::vector mydecoderlist = libmpv->getDecoderList(); + for (int cell = 0; cell < mydecoderlist.size() * column_count; cell++) + { + ImGui::TableNextColumn(); + int column = ImGui::TableGetColumnIndex(); + int row = ImGui::TableGetRowIndex(); + + ImGui::PushID(cell); + if(column == 0){ + ImGui::Text("%s",mydecoderlist[row].codecname.c_str()); + } + if(column == 1){ + ImGui::Text("%s",mydecoderlist[row].codecdesc.c_str()); + } + + ImGui::PopID(); + } + ImGui::EndTable(); + } + } Windows::ExitWindow(); diff --git a/source/UI/mainMenu.cpp b/source/UI/mainMenu.cpp index f7622c7..906579a 100644 --- a/source/UI/mainMenu.cpp +++ b/source/UI/mainMenu.cpp @@ -82,6 +82,8 @@ namespace Windows { } } if(topmenu[n] == "Settings"){ + configini->setLongSeek(configini->getLongSeek(false)); + configini->setShortSeek(configini->getShortSeek(false)); item.state = MENU_STATE_SETTINGS; } if(topmenu[n] == "Info"){ diff --git a/source/UI/playerWindows.cpp b/source/UI/playerWindows.cpp new file mode 100644 index 0000000..3dedade --- /dev/null +++ b/source/UI/playerWindows.cpp @@ -0,0 +1,267 @@ +#include "gui.h" +#include "playerwindows.h" +#include "imgui.h" +#include "utils.h" +#include "imgui_internal.h" + + +namespace playerWindows{ + + static int drag_wmax = 0; + static int drag_hmax = 0; + static int drag_w = 0; + static int drag_h = 0; + + + void RightHomeWindow(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + std::vector topmenu = {"Tracks","Chapters","Aspect Ratio"}; + 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))){ + for (unsigned int n = 0; n < topmenu.size(); n++){ + static int selected = -1; + if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){ + if(topmenu[n] == "Tracks"){ + item.rightmenustate = PLAYER_RIGHT_MENU_TRACKS; + } + if(topmenu[n] == "Chapters"){ + item.rightmenustate = PLAYER_RIGHT_MENU_CHAPTERS; + } + if(topmenu[n] == "Aspect Ratio"){ + item.rightmenustate = PLAYER_RIGHT_MENU_ARATIO; + } + } + } + if (*first_item) { + ImGui::SetFocusID(ImGui::GetID(topmenu[0].c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + } + ImGui::EndListBox(); + } + playerWindows::ExitWindow(); + } + void RightTrackWindow(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + std::vector topmenu = {"Video","Audio","Sub"}; + if (ImGui::Begin("Right Menu Tracks", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginListBox("Tracks Menu",ImVec2(1280.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(topmenu[n] == "Video"){ + item.rightmenustate = PLAYER_RIGHT_MENU_TRACKS_VIDEO; + } + if(topmenu[n] == "Audio"){ + item.rightmenustate = PLAYER_RIGHT_MENU_TRACKS_AUDIO; + } + if(topmenu[n] == "Sub"){ + item.rightmenustate = PLAYER_RIGHT_MENU_TRACKS_SUB; + } + } + } + if (*first_item) { + ImGui::SetFocusID(ImGui::GetID(topmenu[0].c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + } + ImGui::EndListBox(); + } + playerWindows::ExitWindow(); + } + + void RightTrackVideoWindow(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + if (ImGui::Begin("Right Menu Tracks Video", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginListBox("Video Tracks Menu",ImVec2(1280.0f, 720.0f))){ + if(libmpv->getFileInfo() != nullptr){ + for (unsigned int n = 0; n < libmpv->getFileInfo()->videos.size(); n++){ + static int selected = -1; + std::string itemid = "##" + std::to_string(n); + float currstartpos = ImGui::GetCursorPosX(); + if (ImGui::Selectable(itemid.c_str(), selected == n,0,ImVec2(0, 50))){ + + } + ImGui::SetCursorPosX(currstartpos); + ImGui::SetCursorPosY(ImGui::GetCursorPosY()-50.0f); + ImGui::PushFont(fontSmall); + ImGui::Text("#%d %s",libmpv->getFileInfo()->videos[n].id,libmpv->getFileInfo()->videos[n].title.c_str()); + ImGui::Text("%dx%d",libmpv->getFileInfo()->videos[n].width,libmpv->getFileInfo()->videos[n].height); + ImGui::PopFont(); + } + } + } + ImGui::EndListBox(); + } + + playerWindows::ExitWindow(); + } + + void RightTrackAudioWindow(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + if (ImGui::Begin("Right Menu Tracks Audio", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginListBox("Audio Tracks Menu",ImVec2(200.0f, 720.0f))){ + if(libmpv->getFileInfo() != nullptr){ + for (unsigned int n = 0; n < libmpv->getFileInfo()->audios.size(); n++){ + //static int selected = libmpv->getFileInfo()->audios[n].selected ? n : -1; + std::string itemid = "##" + std::to_string(n); + float currstartpos = ImGui::GetCursorPosX(); + if (ImGui::Selectable(itemid.c_str(), libmpv->getFileInfo()->audios[n].selected,0,ImVec2(0, 70))){ + libmpv->setAid(libmpv->getFileInfo()->audios[n].id,item.playershowcontrols); + } + ImGui::SameLine(); + ImGui::SetCursorPosX(currstartpos); + ImGui::Text("#%d %s",libmpv->getFileInfo()->audios[n].id,libmpv->getFileInfo()->audios[n].title.c_str()); + ImGui::SetCursorPosY(ImGui::GetCursorPosY()-40.0f); + ImGui::PushFont(fontSmall); + ImGui::Text("%s",libmpv->getFileInfo()->audios[n].codec.c_str()); + ImGui::SameLine(); + ImGui::Text("%dch",libmpv->getFileInfo()->audios[n].channels); + ImGui::Text("%s",libmpv->getFileInfo()->audios[n].language.c_str()); + ImGui::PopFont(); + } + if (*first_item) { + std::string itemid = "##" + std::to_string(0); + ImGui::SetFocusID(ImGui::GetID(itemid.c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + } + } + ImGui::EndListBox(); + } + playerWindows::ExitWindow(); + } + + void RightTrackSubWindow(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + if (ImGui::Begin("Right Menu Tracks Subs", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginListBox("Sub Tracks Menu",ImVec2(200.0f, 720.0f))){ + if(libmpv->getFileInfo() != nullptr){ + for (unsigned int n = 0; n < libmpv->getFileInfo()->subtitles.size(); n++){ + static int selected = -1; + std::string itemid = "##" + std::to_string(n); + float currstartpos = ImGui::GetCursorPosX(); + if (ImGui::Selectable(itemid.c_str(), selected == n,0,ImVec2(0, 50))){ + libmpv->setSid(libmpv->getFileInfo()->subtitles[n].id,item.playershowcontrols); + } + ImGui::SameLine(); + ImGui::SetCursorPosX(currstartpos); + ImGui::Text("#%d %s",libmpv->getFileInfo()->subtitles[n].id,libmpv->getFileInfo()->subtitles[n].title.c_str()); + ImGui::SetCursorPosY(ImGui::GetCursorPosY()-20.0f); + ImGui::PushFont(fontSmall); + ImGui::Text("%s",libmpv->getFileInfo()->subtitles[n].language.c_str()); + ImGui::PopFont(); + } + if (*first_item) { + std::string itemid = "##" + std::to_string(0); + ImGui::SetFocusID(ImGui::GetID(itemid.c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + } + } + ImGui::EndListBox(); + } + playerWindows::ExitWindow(); + } + + void RightChapterWindow(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + std::vector topmenu = {"Video","Audio","Sub"}; + if (ImGui::Begin("Right Menu Chapters", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + ImGui::SetNextWindowFocus(); + if (ImGui::BeginListBox("Chapter Menu",ImVec2(200.0f, 720.0f))){ + if(libmpv->getFileInfo() != nullptr){ + for (unsigned int n = 0; n < libmpv->getFileInfo()->chapters.size(); n++){ + static int selected = -1; + std::string itemid = "##" + std::to_string(n); + float currstartpos = ImGui::GetCursorPosX(); + if (ImGui::Selectable(itemid.c_str(), selected == n,0,ImVec2(0, 50))){ + libmpv->seek(libmpv->getFileInfo()->chapters[n].time,item.playershowcontrols); + + } + ImGui::SameLine(); + ImGui::SetCursorPosX(currstartpos); + ImGui::PushFont(fontSmall); + ImGui::Text("%s",libmpv->getFileInfo()->chapters[n].title.c_str()); + ImGui::PopFont(); + + } + if (*first_item) { + std::string itemid = "##" + std::to_string(0); + ImGui::SetFocusID(ImGui::GetID(itemid.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"}; + 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){ + libmpv->setAspectRatio(-1,item.playershowcontrols); + } + if(n==1){ + libmpv->setAspectRatio(1.777,item.playershowcontrols); + } + if(n==2){ + libmpv->setAspectRatio(1.6,item.playershowcontrols); + } + if(n==3){ + libmpv->setAspectRatio(1.333,item.playershowcontrols); + } + if(n==4){ + drag_wmax = libmpv->getVideoWidth(); + drag_hmax = libmpv->getVideoHeight(); + drag_w = libmpv->getVideoWidth(); + drag_h = libmpv->getVideoHeight(); + item.rightmenustate = PLAYER_RIGHT_MENU_CUSTOMARATIO; + } + } + } + if (*first_item) { + ImGui::SetFocusID(ImGui::GetID(topmenu[0].c_str()), ImGui::GetCurrentWindow()); + *first_item = false; + } + ImGui::EndListBox(); + } + } + playerWindows::ExitWindow(); + } + + void RightHomeCustomARatio(bool *focus, bool *first_item){ + playerWindows::SetupRightWindow(); + std::vector topmenu = {"Default","16:9","16:10","4:3","Custom Ratio"}; + if (ImGui::Begin("Right Menu CustomAratio", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { + //ImGui::SetNextWindowFocus(); + ImGui::PushItemWidth(200-10); + ImGui::Text("Width"); + if(ImGui::DragInt("Width", &drag_w, 0.5f, 0, drag_wmax, "%d", ImGuiSliderFlags_NoInput)){ + double aratio = (double)drag_w/(double)drag_h; + libmpv->setAspectRatio(aratio,item.playershowcontrols); + } + ImGui::Text("Height"); + if(ImGui::DragInt("Height", &drag_h, 0.5f, 0, drag_hmax, "%d", ImGuiSliderFlags_NoInput)){ + double aratio = (double)drag_w/(double)drag_h; + libmpv->setAspectRatio(aratio,item.playershowcontrols); + } + ImGui::Text("Ratio: %.3f",(double)drag_w/(double)drag_h); + } + + playerWindows::ExitWindow(); + } +} diff --git a/source/UI/settingsMenu.cpp b/source/UI/settingsMenu.cpp index 2fba945..183532a 100644 --- a/source/UI/settingsMenu.cpp +++ b/source/UI/settingsMenu.cpp @@ -15,10 +15,61 @@ namespace Windows { ImGui::SetNextWindowFocus(); *focus = true; } - auto windowWidth = ImGui::GetWindowSize().x; - ImGui::SetCursorPosX((windowWidth - ImGui::CalcTextSize("No Settings right now", NULL, true).x) * 0.5f); - ImGui::Text("No Settings right now"); + //auto windowWidth = ImGui::GetWindowSize().x; + //ImGui::SetCursorPosX((windowWidth - ImGui::CalcTextSize("No Settings right now", NULL, true).x) * 0.5f); + //static int counter = configini->getShortSeek(); + float spacing = ImGui::GetStyle().ItemInnerSpacing.x; + ImGui::Text("Short Seek Time"); + ImGui::SameLine(220,spacing); + ImGui::PushButtonRepeat(true); + if (ImGui::ArrowButton("##shortleft", ImGuiDir_Left)) { + if(configini->getShortSeek(true)-1 >0){ + configini->setShortSeek(configini->getShortSeek(true)-1); + } + } + ImGui::SameLine(0.0f, spacing); + if (ImGui::ArrowButton("##shortright", ImGuiDir_Right)) { + configini->setShortSeek(configini->getShortSeek(true)+1); + } + ImGui::PopButtonRepeat(); + ImGui::SameLine(); + ImGui::Text("%d sec", configini->getShortSeek(true)); + ImGui::Text("Long Seek Time"); + ImGui::SameLine(220,spacing); + ImGui::PushButtonRepeat(true); + if (ImGui::ArrowButton("##longleft", ImGuiDir_Left)) { + if(configini->getLongSeek(true)-1 >0){ + configini->setLongSeek(configini->getLongSeek(true)-1); + } + } + ImGui::SameLine(0.0f, spacing); + if (ImGui::ArrowButton("##longright", ImGuiDir_Right)) { + configini->setLongSeek(configini->getLongSeek(true)+1); + } + ImGui::PopButtonRepeat(); + ImGui::SameLine(); + ImGui::Text("%d sec", configini->getLongSeek(true)); + + + + ImGui::SetCursorPosX(ImGui::GetWindowSize().x/2); + ImGui::SetCursorPosY(ImGui::GetWindowSize().y -50); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(0.0f, 0.6f, 0.6f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(0.0f, 0.7f, 0.7f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(0.0f, 0.8f, 0.8f)); + if (ImGui::Button("Save")){ + item.popupstate = POPUP_STATE_SAVE_SETTINGS; + } + ImGui::PopStyleColor(3); + ImGui::SameLine(0,50); + if (ImGui::Button("Cancel")){ + item.state = MENU_STATE_HOME; + } + + + } Windows::ExitWindow(); } diff --git a/source/config.cpp b/source/config.cpp index 7b1c2cd..c666a54 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -16,12 +16,18 @@ std::vector char_split (const std::string &s, char delim) { } Config::Config(std::string inifile){ + inifilePath = inifile; ini = new CSimpleIniA(true,true); ini->SetUnicode(); ini->LoadFile(inifile.c_str()); CSimpleIniA::TNamesDepend values; + longseek = ini->GetLongValue("Main", "longseek"); + shortseek = ini->GetLongValue("Main", "shortseek"); + tmplongseek = longseek; + tmpshortseek = shortseek; + topmenu.push_back("Local Files"); topmenu.push_back("USB"); @@ -82,3 +88,36 @@ std::string Config::getEnigma(){ } +int Config::getLongSeek(bool tmpvalue){ + if(tmpvalue){ + return tmplongseek; + } + return longseek; +} + +int Config::getShortSeek(bool tmpvalue){ + if(tmpvalue){ + return tmpshortseek; + } + return shortseek; +} + +void Config::setLongSeek(int seektime){ + tmplongseek = seektime; +} +void Config::setShortSeek(int seektime){ + tmpshortseek = seektime; +} + +void Config::saveSettings(){ + longseek = tmplongseek; + shortseek = tmpshortseek; + ini->Delete("Main", "shortseek"); + ini->SetLongValue("Main", "shortseek", shortseek, NULL, false); + ini->Delete("Main", "longseek"); + ini->SetLongValue("Main", "longseek", longseek, NULL, false); + std::string data; + int rc = ini->Save(data); + rc = ini->SaveFile(inifilePath.c_str()); +} + diff --git a/source/gui.cpp b/source/gui.cpp index 0d9ed46..f69c58f 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -34,9 +34,7 @@ namespace GUI { libmpv = new libMpv("mpv"); wakeup_on_mpv_render_update = SDL_RegisterEvents(1); wakeup_on_mpv_events = SDL_RegisterEvents(1); - //mpv_set_wakeup_callback(libmpv->getHandle(), [](void *) -> void {SDL_Event event = {.type = wakeup_on_mpv_events}; SDL_PushEvent(&event);}, NULL); mpv_set_wakeup_callback(libmpv->getHandle(), on_mpv_events, NULL); - mpv_render_context_set_update_callback(libmpv->getContext(), [](void *) -> void { SDL_Event event = {.type = wakeup_on_mpv_render_update}; SDL_PushEvent(&event); }, NULL); } @@ -72,6 +70,18 @@ namespace GUI { sdlevent.jbutton.button = SDL_KEY_PLUS; SDL_PushEvent(&sdlevent); } + if(keycode == SDLK_m){ + SDL_Event sdlevent; + sdlevent.type = SDL_JOYBUTTONDOWN; + sdlevent.jbutton.button = SDL_KEY_DRIGHT; + SDL_PushEvent(&sdlevent); + } + if(keycode == SDLK_n){ + SDL_Event sdlevent; + sdlevent.type = SDL_JOYBUTTONDOWN; + sdlevent.jbutton.button = SDL_KEY_DLEFT; + SDL_PushEvent(&sdlevent); + } if(keycode == SDLK_y){ SDL_Event sdlevent; sdlevent.type = SDL_JOYBUTTONDOWN; @@ -114,9 +124,30 @@ namespace GUI { if (event.type == SDL_JOYBUTTONDOWN) { Uint8 button = event.jbutton.button; - if (button == SDL_KEY_PLUS) + if (button == SDL_KEY_PLUS && !item.masterlock) renderloopdone = true; + if (button == SDL_KEY_DRIGHT){ + if(item.state == MENU_STATE_PLAYER && !item.masterlock){ + if(item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER){ + if(item.rightmenustate != PLAYER_RIGHT_MENU_CUSTOMARATIO){ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } + } + } + } + + if (button == SDL_KEY_DLEFT){ + if(item.state == MENU_STATE_PLAYER && !item.masterlock){ + if(item.rightmenustate != PLAYER_RIGHT_MENU_PLAYER){ + if(item.rightmenustate != PLAYER_RIGHT_MENU_CUSTOMARATIO){ + item.rightmenustate = PLAYER_RIGHT_MENU_PLAYER; + } + + } + } + } + if (button == SDL_KEY_RSTICK){ if(item.state == MENU_STATE_PLAYER){ toggleMasterLock(); @@ -130,41 +161,28 @@ namespace GUI { if (button == SDL_KEY_ZR){ if(item.state == MENU_STATE_PLAYER && !item.masterlock){ - if(item.playershowcontrols){ - libmpv->seekOSD(libmpv->getPosition() + 60.0); - }else{ - libmpv->seekSilent(libmpv->getPosition() + 60.0); - } + libmpv->seek(libmpv->getPosition() + configini->getLongSeek(false),item.playershowcontrols); } } if (button == SDL_KEY_ZL){ if(item.state == MENU_STATE_PLAYER && !item.masterlock){ - if(item.playershowcontrols){ - libmpv->seekOSD(libmpv->getPosition() - 60.0); - }else{ - libmpv->seekSilent(libmpv->getPosition() - 60.0); - } + libmpv->seek(libmpv->getPosition() - configini->getLongSeek(false),item.playershowcontrols); + } } if (button == SDL_KEY_R){ if(item.state == MENU_STATE_PLAYER && !item.masterlock){ - if(item.playershowcontrols){ - libmpv->seekOSD(libmpv->getPosition() + 10.0); - }else{ - libmpv->seekSilent(libmpv->getPosition() + 10.0); - } + libmpv->seek(libmpv->getPosition() + configini->getShortSeek(false),item.playershowcontrols); + } } if (button == SDL_KEY_L){ if(item.state == MENU_STATE_PLAYER && !item.masterlock){ - if(item.playershowcontrols){ - libmpv->seekOSD(libmpv->getPosition() - 10.0); - }else{ - libmpv->seekSilent(libmpv->getPosition() - 10.0); - } + libmpv->seek(libmpv->getPosition() - configini->getShortSeek(false),item.playershowcontrols); + } } @@ -182,15 +200,17 @@ namespace GUI { } if (button == SDL_KEY_A){ if(item.state == MENU_STATE_PLAYER){ - if(libmpv->Paused()){ - libmpv->Resume(); - }else{ - libmpv->Pause(); + if(item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER){ + if(libmpv->Paused()){ + libmpv->Resume(); + }else{ + libmpv->Pause(); + } } } } if (button == SDL_KEY_Y && !item.masterlock){ - if(item.state != MENU_STATE_HOME && item.state != MENU_STATE_PLAYER){ + if(item.state != MENU_STATE_HOME && item.state != MENU_STATE_PLAYER && item.popupstate == POPUP_STATE_NONE){ #ifdef __SWITCH__ if(usbmounter != nullptr){ delete usbmounter; @@ -257,9 +277,29 @@ namespace GUI { } - if(!libmpv->Stopped() && !item.masterlock){ - item.state = item.laststate; - libmpv->Stop(); + if(item.state == MENU_STATE_PLAYER){ + if(item.rightmenustate == PLAYER_RIGHT_MENU_PLAYER){ + if(!libmpv->Stopped() && !item.masterlock){ + item.state = item.laststate; + libmpv->Stop(); + } + }else if(item.rightmenustate == PLAYER_RIGHT_MENU_TRACKS){ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } + else if(item.rightmenustate == PLAYER_RIGHT_MENU_TRACKS_VIDEO||item.rightmenustate == PLAYER_RIGHT_MENU_TRACKS_AUDIO||item.rightmenustate == PLAYER_RIGHT_MENU_TRACKS_SUB){ + item.rightmenustate = PLAYER_RIGHT_MENU_TRACKS; + } + else if(item.rightmenustate == PLAYER_RIGHT_MENU_CHAPTERS){ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } + else if(item.rightmenustate == PLAYER_RIGHT_MENU_ARATIO){ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } + else if(item.rightmenustate == PLAYER_RIGHT_MENU_CUSTOMARATIO){ + item.rightmenustate = PLAYER_RIGHT_MENU_ARATIO; + } + + } } } @@ -279,19 +319,29 @@ namespace GUI { if (strstr(msg->text, "DR image")) printf("log: %s", msg->text); continue; - }if (mp_event->event_id == MPV_EVENT_START_FILE) { + } + if (mp_event->event_id == MPV_EVENT_FILE_LOADED) { + libmpv->getfileInfo(); + } + if (mp_event->event_id == MPV_EVENT_START_FILE) { +#ifdef __SWITCH__ + appletSetMediaPlaybackState(true); +#endif printf("START FILE\n"); item.laststate = item.state; item.state = MENU_STATE_PLAYER; } - printf("Event id: %d\n",mp_event->event_id); + //printf("Event id: %d\n",mp_event->event_id); if (mp_event->event_id == MPV_EVENT_END_FILE) { +#ifdef __SWITCH__ + appletSetMediaPlaybackState(false); +#endif printf("END FILE\n"); item.state = item.laststate; item.masterlock = false; printf("MENU STATE: %d\n",item.state ); } - + count --; printf("event: %s\n", mpv_event_name(mp_event->event_id)); } @@ -321,27 +371,57 @@ namespace GUI { break; case MENU_STATE_SETTINGS: Windows::SettingsMenuWindow(&item.focus, &item.first_item); + if(item.popupstate == POPUP_STATE_SAVE_SETTINGS){ + Popups::SaveSettingsPopup(); + } break; case MENU_STATE_INFO: Windows::InfoMenuWindow(&item.focus, &item.first_item); break; case MENU_STATE_PLAYER: - if(item.playershowcontrols){ - //PlayerWindows::PlayerControls(); - } break; } + + switch (item.rightmenustate) { + case PLAYER_RIGHT_MENU_PLAYER: + break; + case PLAYER_RIGHT_MENU_HOME: + playerWindows::RightHomeWindow(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_TRACKS: + playerWindows::RightTrackWindow(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_TRACKS_VIDEO: + playerWindows::RightTrackVideoWindow(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_TRACKS_AUDIO: + playerWindows::RightTrackAudioWindow(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_TRACKS_SUB: + playerWindows::RightTrackSubWindow(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_CHAPTERS: + playerWindows::RightChapterWindow(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_ARATIO: + playerWindows::RightHomeARatio(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + case PLAYER_RIGHT_MENU_CUSTOMARATIO: + playerWindows::RightHomeCustomARatio(&item.rightmenu_focus,&item.rightmenu_first_item); + break; + + } } void HandleRender(){ - ImGui::Render(); - ImGuiIO &io = ImGui::GetIO(); - glViewport(0, 0, static_cast(io.DisplaySize.x), static_cast(io.DisplaySize.y)); - glClearColor(0.00f, 0.00f, 0.00f, 1.00f); - glClear(GL_COLOR_BUFFER_BIT); + ImGui::Render(); + ImGuiIO &io = ImGui::GetIO(); + glViewport(0, 0, static_cast(io.DisplaySize.x), static_cast(io.DisplaySize.y)); + glClearColor(0.00f, 0.00f, 0.00f, 1.00f); + glClear(GL_COLOR_BUFFER_BIT); SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow(); SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext(); @@ -361,7 +441,6 @@ namespace GUI { mpv_render_context_render(libmpv->getContext(), params); } ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - SDL_GL_SwapWindow(window); } diff --git a/source/libmpv.cpp b/source/libmpv.cpp index e5ef118..8e72f3c 100644 --- a/source/libmpv.cpp +++ b/source/libmpv.cpp @@ -1,5 +1,14 @@ #include +#include +#include #include "libmpv.h" +#include "utils.h" + + +bool codecSort(const decoderlist_struct &a, const decoderlist_struct &b) { + + return Utility::str_tolower(a.codecname) < Utility::str_tolower(b.codecname); +} libMpv::libMpv(const std::string &configDir) { @@ -53,6 +62,31 @@ libMpv::libMpv(const std::string &configDir) { mpv_version = mpv_get_property_string(handle, "mpv-version"); ffmpeg_version = mpv_get_property_string(handle, "ffmpeg-version"); + + mpv_node node; + mpv_get_property(handle, "decoder-list", MPV_FORMAT_NODE, &node); + if (node.format == MPV_FORMAT_NODE_ARRAY) { + for (int i = 0; i < node.u.list->num; i++) { + if (node.u.list->values[i].format == MPV_FORMAT_NODE_MAP) { + decoderlist_struct decoderentry{}; + for (int n = 0; n < node.u.list->values[i].u.list->num; n++) { + std::string key = node.u.list->values[i].u.list->keys[n]; + if (key == "codec") { + decoderentry.codecname = node.u.list->values[i].u.list->values[n].u.string; + } + if (key == "description") { + decoderentry.codecdesc = node.u.list->values[i].u.list->values[n].u.string; + } + } + decoderlist.push_back(decoderentry); + + } + + } + + } + + std::sort(decoderlist.begin(),decoderlist.end(),codecSort); printf("MPV Init Completed\n"); } @@ -76,14 +110,14 @@ void libMpv::Stop() { mpv_command_async(handle, 0, cmd); } -void libMpv::seekSilent(double position) { - std::string cmd = "no-osd seek " + std::to_string(position) + " absolute"; - mpv_command_string(handle, cmd.c_str()); -} - -void libMpv::seekOSD(double position) { - std::string cmd = "osd-bar seek " + std::to_string(position) + " absolute"; - mpv_command_string(handle, cmd.c_str()); +void libMpv::seek(double position,bool osd) { + if(osd){ + std::string cmd = "seek " + std::to_string(position) + " absolute"; + mpv_command_string(handle, cmd.c_str()); + }else{ + std::string cmd = "no-osd seek " + std::to_string(position) + " absolute"; + mpv_command_string(handle, cmd.c_str()); + } } bool libMpv::Stopped(){ @@ -98,6 +132,10 @@ bool libMpv::Paused(){ return ret == 1; } +std::vector libMpv::getDecoderList(){ + return decoderlist; +} + mpv_handle *libMpv::getHandle() { return handle; } @@ -106,6 +144,209 @@ mpv_render_context *libMpv::getContext() { return context; } +fileInfo *libMpv::getFileInfo(){ + return fileinfo; +} + +int64_t libMpv::getVideoWidth(){ + int64_t ret = 0; + mpv_get_property(handle, "width", MPV_FORMAT_INT64, &ret); + return ret; +} + +int64_t libMpv::getVideoHeight(){ + int64_t ret = 0; + mpv_get_property(handle, "height", MPV_FORMAT_INT64, &ret); + return ret; +} + +void libMpv::getfileInfo() { + + + std::vector streams; + mpv_node node; + mpv_get_property(handle, "track-list", MPV_FORMAT_NODE, &node); + if (node.format == MPV_FORMAT_NODE_ARRAY) { + for (int i = 0; i < node.u.list->num; i++) { + if (node.u.list->values[i].format == MPV_FORMAT_NODE_MAP) { + fileInfo::Track stream{}; + for (int n = 0; n < node.u.list->values[i].u.list->num; n++) { + std::string key = node.u.list->values[i].u.list->keys[n]; + if (key == "type") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING) { + stream.type = node.u.list->values[i].u.list->values[n].u.string; + } + } else if (key == "id") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_INT64) { + stream.id = (int) node.u.list->values[i].u.list->values[n].u.int64; + } + } else if (key == "title") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING) { + stream.title = node.u.list->values[i].u.list->values[n].u.string; + } + } else if (key == "lang") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING) { + stream.language = node.u.list->values[i].u.list->values[n].u.string; + } + } else if (key == "codec") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING) { + stream.codec = node.u.list->values[i].u.list->values[n].u.string; + } + } else if (key == "demux-w") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_INT64) { + stream.width = (int) node.u.list->values[i].u.list->values[n].u.int64; + } + } else if (key == "demux-h") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_INT64) { + stream.height = (int) node.u.list->values[i].u.list->values[n].u.int64; + } + } else if (key == "demux-samplerate") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_INT64) { + stream.sample_rate = (int) node.u.list->values[i].u.list->values[n].u.int64; + } + } else if (key == "demux-channel-count") { + if (node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_INT64) { + stream.channels = (int) node.u.list->values[i].u.list->values[n].u.int64; + } + } else if (key == "selected") { + stream.selected = (bool)node.u.list->values[i].u.list->values[n].u.flag; + } + } + streams.push_back(stream); + } + } + } + + std::vector chapters; + mpv_node chapternode; + mpv_get_property(handle, "chapter-list", MPV_FORMAT_NODE, &chapternode); + if (chapternode.format == MPV_FORMAT_NODE_ARRAY) { + for (int i = 0; i < chapternode.u.list->num; i++) { + if (chapternode.u.list->values[i].format == MPV_FORMAT_NODE_MAP) { + fileInfo::Chapter chapter{}; + for (int n = 0; n < chapternode.u.list->values[i].u.list->num; n++) { + std::string key = chapternode.u.list->values[i].u.list->keys[n]; + if (key == "title") { + if (chapternode.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING) { + chapter.title = chapternode.u.list->values[i].u.list->values[n].u.string; + } + + } + else if (key == "time") { + if (chapternode.u.list->values[i].u.list->values[n].format == MPV_FORMAT_DOUBLE) { + chapter.time = (double) chapternode.u.list->values[i].u.list->values[n].u.double_; + } + + } + + } + chapters.push_back(chapter); + + } + + } + + } + + + + if(fileinfo != nullptr){ + delete fileinfo; + } + fileinfo = new fileInfo(); + + fileInfo::Track dummysubstream{}; + dummysubstream.id = -1; + dummysubstream.title = "None"; + fileinfo->subtitles.push_back(dummysubstream); + + + for (auto &stream: streams) { + if (stream.type == "video") { + fileinfo->videos.push_back(stream); + if(stream.selected){ + fileinfo->playbackInfo.vid_id = stream.id; + } + } else if (stream.type == "audio") { + fileinfo->audios.push_back(stream); + if(stream.selected){ + fileinfo->playbackInfo.aud_id = stream.id; + } + } else if (stream.type == "sub") { + fileinfo->subtitles.push_back(stream); + if(stream.selected){ + fileinfo->playbackInfo.sub_id = stream.id; + } + } + } + + for (auto &chapter: chapters) { + fileinfo->chapters.push_back(chapter); + } + + +} + +void libMpv::setVid(int id, bool osd) { + if (id > -1) { + for(int i=0;ivideos.size();i++){ + if(fileinfo->videos[i].selected)fileinfo->videos[i].selected=false; + if(fileinfo->videos[i].id == id)fileinfo->videos[i].selected=true; + } + if(osd){ + std::string cmd = "set vid " + std::to_string(id); + mpv_command_string(handle, cmd.c_str()); + }else{ + std::string cmd = "no-osd set vid " + std::to_string(id); + mpv_command_string(handle, cmd.c_str()); + } + } +} + +void libMpv::setAid(int id, bool osd) { + if (id > -1) { + for(int i=0;iaudios.size();i++){ + if(fileinfo->audios[i].selected)fileinfo->audios[i].selected=false; + if(fileinfo->audios[i].id == id)fileinfo->audios[i].selected=true; + } + if(osd){ + std::string cmd = "set aid " + std::to_string(id); + mpv_command_string(handle, cmd.c_str()); + }else{ + std::string cmd = "no-osd set aid " + std::to_string(id); + mpv_command_string(handle, cmd.c_str()); + } + } +} + +void libMpv::setSid(int id, bool osd) { + for(int i=0;isubtitles.size();i++){ + if(fileinfo->subtitles[i].selected)fileinfo->subtitles[i].selected=false; + if(fileinfo->subtitles[i].id == id)fileinfo->subtitles[i].selected=true; + } + if(id == -1){ + if(osd){ + std::string cmd = "set sid no"; + mpv_command_string(handle, cmd.c_str()); + }else{ + std::string cmd = "no-osd set sid no"; + mpv_command_string(handle, cmd.c_str()); + } + }else{ + if(osd){ + std::string cmd = "set sid " + std::to_string(id); + mpv_command_string(handle, cmd.c_str()); + }else{ + std::string cmd = "no-osd set sid " + std::to_string(id); + mpv_command_string(handle, cmd.c_str()); + } + } +} + +void libMpv::setAspectRatio(double ratio,bool osd){ + mpv_set_property_async(handle, 0,"video-aspect-override", MPV_FORMAT_DOUBLE, &ratio); +} + libMpv::~libMpv(){ if (context) { mpv_render_context_free(context); diff --git a/source/usbfs.cpp b/source/localfs/usb/usbfs.cpp similarity index 100% rename from source/usbfs.cpp rename to source/localfs/usb/usbfs.cpp diff --git a/include/usbfs.h b/source/localfs/usb/usbfs.h similarity index 100% rename from include/usbfs.h rename to source/localfs/usb/usbfs.h diff --git a/source/playerOverlay.cpp b/source/playerOverlay.cpp deleted file mode 100644 index 93a1457..0000000 --- a/source/playerOverlay.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "gui.h" -#include "appwindows.h" -#include "imgui.h" -#include "utils.h" -#include "imgui_internal.h" - - -namespace PlayerWindows{ - - void PlayerControls(){ - PlayerWindows::SetupWindow(); - if (ImGui::Begin("Player Controls", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoSavedSettings)) { - - } - - - Windows::ExitWindow(); - } - - - -} \ No newline at end of file diff --git a/source/utils.cpp b/source/utils.cpp index cd3501f..5b0a759 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -81,12 +81,12 @@ namespace Utility{ return true; } - std::string humanSize(uint64_t bytes) + std::string humanSize(size_t bytes) { std::vectorsuffix = {"B", "KB", "MB", "GB", "TB"}; int i = 0; - double dblBytes = bytes; + double dblBytes = bytes; if (bytes > 1024) { for (i = 0; (bytes / 1024) > 0 && i<(int)suffix.size()-1; i++, bytes /= 1024)