Skip to content

Commit

Permalink
fix quickview property sync
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Dec 3, 2023
1 parent 0f58225 commit 913e59b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
4 changes: 3 additions & 1 deletion include/mpv.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class Mpv {
std::vector<BindingItem> bindings;
std::vector<std::string> profiles;
std::string aid, vid, sid, sid2, audioDevice, cursorAutohide;
int64_t chapter = 0, volume = 100, playlistPos = -1, playlistPlayingPos = -1, timePos = 0;
int64_t chapter, volume, playlistPos, playlistPlayingPos, timePos;
int64_t brightness, contrast, saturation, gamma, hue;
double audioDelay, subDelay, subScale;
bool pause, mute, fullscreen, sidv, sidv2, forceWindow;
bool keepaspect, keepaspectWindow, windowDragging, autoResize;

Expand Down
10 changes: 10 additions & 0 deletions source/mpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ void Mpv::observeProperties() {
observeProperty<int64_t, MPV_FORMAT_INT64>("playlist-pos", [this](int64_t val) { playlistPos = val; });
observeProperty<int64_t, MPV_FORMAT_INT64>("playlist-playing-pos", [this](int64_t val) { playlistPlayingPos = val; });
observeProperty<int64_t, MPV_FORMAT_INT64>("time-pos", [this](int64_t val) { timePos = val; });

observeProperty<int64_t, MPV_FORMAT_INT64>("brightness", [this](int64_t val) { brightness = val; });
observeProperty<int64_t, MPV_FORMAT_INT64>("contrast", [this](int64_t val) { contrast = val; });
observeProperty<int64_t, MPV_FORMAT_INT64>("saturation", [this](int64_t val) { saturation = val; });
observeProperty<int64_t, MPV_FORMAT_INT64>("gamma", [this](int64_t val) { gamma = val; });
observeProperty<int64_t, MPV_FORMAT_INT64>("hue", [this](int64_t val) { hue = val; });

observeProperty<double, MPV_FORMAT_DOUBLE>("audio-delay", [this](double val) { audioDelay = val; });
observeProperty<double, MPV_FORMAT_DOUBLE>("sub-delay", [this](double val) { subDelay = val; });
observeProperty<double, MPV_FORMAT_DOUBLE>("sub-scale", [this](double val) { subScale = val; });
}

void Mpv::initPlaylist(mpv_node &node) {
Expand Down
27 changes: 10 additions & 17 deletions source/views/quickview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,13 @@ void Quickview::drawVideoTabContent() {
"views.quickview.video.equalizer.saturation", "views.quickview.video.equalizer.gamma",
"views.quickview.video.equalizer.hue",
};
static int equalizer[IM_ARRAYSIZE(eq)] = {
(int)mpv->property<int64_t, MPV_FORMAT_INT64>("brightness"),
(int)mpv->property<int64_t, MPV_FORMAT_INT64>("contrast"),
(int)mpv->property<int64_t, MPV_FORMAT_INT64>("saturation"),
(int)mpv->property<int64_t, MPV_FORMAT_INT64>("gamma"),
(int)mpv->property<int64_t, MPV_FORMAT_INT64>("hue"),
int equalizer[IM_ARRAYSIZE(eq)] = {
(int)mpv->brightness, (int)mpv->contrast, (int)mpv->saturation, (int)mpv->gamma, (int)mpv->hue,
};
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + scaled(1));
ImGui::BeginGroup();
for (int i = 0; i < IM_ARRAYSIZE(equalizer); i++) {
if (ImGui::Button(fmt::format("{}##{}", ICON_FA_UNDO, eq[i]).c_str())) {
equalizer[i] = 0;
mpv->commandv("set", eq[i], "0", nullptr);
}
if (ImGui::Button(fmt::format("{}##{}", ICON_FA_UNDO, eq[i]).c_str())) mpv->commandv("set", eq[i], "0", nullptr);
ImGui::SameLine();
if (ImGui::SliderInt(i18n(eq_labels[i]).c_str(), &equalizer[i], -100, 100))
mpv->commandv("set", eq[i], std::to_string(equalizer[i]).c_str(), nullptr);
Expand All @@ -389,18 +382,18 @@ void Quickview::drawAudioTabContent() {
ImGui::NewLine();

ImGui::TextUnformatted("views.quickview.audio.volume"_i18n);
static int volume = (int)mpv->volume;
int volume = (int)mpv->volume;
if (ImGui::SliderInt("##Volume", &volume, 0, 200, "%d%%"))
mpv->commandv("set", "volume", std::to_string(volume).c_str(), nullptr);
ImGui::SameLine();
if (toggleButton(ICON_FA_VOLUME_MUTE, mpv->mute, "views.quickview.audio.mute"_i18n)) mpv->command("cycle mute");
ImGui::NewLine();

ImGui::TextUnformatted("views.quickview.audio.delay"_i18n);
static float delay = (float)mpv->property<double, MPV_FORMAT_DOUBLE>("audio-delay");
float delay = (float)mpv->audioDelay;
if (ImGui::SliderFloat("##Delay", &delay, -10, 10, "%.1fs"))
mpv->commandv("set", "audio-delay", fmt::format("{:.1f}", delay).c_str(), nullptr);
if (iconButton(ICON_FA_UNDO, "set audio-delay 0", "views.quickview.audio.delay.reset"_i18n)) delay = 0;
iconButton(ICON_FA_UNDO, "set audio-delay 0", "views.quickview.audio.delay.reset"_i18n);
ImGui::NewLine();
ImGui::Separator();
ImGui::NewLine();
Expand All @@ -423,17 +416,17 @@ void Quickview::drawSubtitleTabContent() {
ImGui::NewLine();

ImGui::TextUnformatted("views.quickview.subtitle.scale"_i18n);
static float scale = (float)mpv->property<double, MPV_FORMAT_DOUBLE>("sub-scale");
float scale = (float)mpv->subScale;
if (ImGui::SliderFloat("##Scale", &scale, 0, 4, "%.1f"))
mpv->commandv("set", "sub-scale", fmt::format("{:.1f}", scale).c_str(), nullptr);
if (iconButton(ICON_FA_UNDO, "set sub-scale 1", "views.quickview.subtitle.scale.reset"_i18n)) scale = 1;
iconButton(ICON_FA_UNDO, "set sub-scale 1", "views.quickview.subtitle.scale.reset"_i18n);
ImGui::NewLine();

ImGui::TextUnformatted("views.quickview.subtitle.delay"_i18n);
static float delay = (float)mpv->property<double, MPV_FORMAT_DOUBLE>("sub-delay");
float delay = (float)mpv->subDelay;
if (ImGui::SliderFloat("##Delay", &delay, -10, 10, "%.1fs"))
mpv->commandv("set", "sub-delay", fmt::format("{:.1f}", delay).c_str(), nullptr);
if (iconButton(ICON_FA_UNDO, "set sub-delay 0", "views.quickview.subtitle.delay.reset"_i18n)) delay = 0;
iconButton(ICON_FA_UNDO, "set sub-delay 0", "views.quickview.subtitle.delay.reset"_i18n);
}

void Quickview::drawAudioEq() {
Expand Down
2 changes: 1 addition & 1 deletion source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool Window::init(OptionParser& parser) {
borderless = !static_cast<bool>(flag);
if (borderless) {
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
::SetWindowLongA(hwnd, GWL_STYLE, style | WS_CAPTION | WS_MAXIMIZEBOX | WS_THICKFRAME);
::SetWindowLong(hwnd, GWL_STYLE, style | WS_CAPTION | WS_MAXIMIZEBOX | WS_THICKFRAME);
}
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
});
Expand Down

0 comments on commit 913e59b

Please sign in to comment.