From 786c9592a169a989b1699b96190a89e4217e9988 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Thu, 4 Aug 2022 23:18:28 +0200 Subject: [PATCH] Fix depecrations and clean up backwards compatibility checks --- src/advanced-scene-switcher.cpp | 2 -- .../opencv/macro-condition-video.cpp | 23 +++++++++-------- src/headers/macro-action-replay-buffer.hpp | 4 --- src/headers/macro-action-virtual-cam.hpp | 4 --- src/headers/macro-condition-replay-buffer.hpp | 4 --- src/headers/macro-condition-virtual-cam.hpp | 4 --- src/headers/switch-network.hpp | 3 +-- src/macro-action-replay-buffer.cpp | 4 --- src/macro-action-transition.cpp | 15 +++-------- src/macro-action-virtual-cam.cpp | 4 --- src/macro-condition-file.cpp | 9 +++++-- src/macro-condition-replay-buffer.cpp | 4 --- src/macro-condition-virtual-cam.cpp | 4 --- src/macro-segment-list.cpp | 10 +++++--- src/scene-trigger.cpp | 4 --- src/switch-file.cpp | 11 +++++--- src/switch-network.cpp | 25 ++++++++++--------- src/volume-control.cpp | 5 ++-- src/win/advanced-scene-switcher-win.cpp | 8 +++--- 19 files changed, 56 insertions(+), 91 deletions(-) diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index 79088345..773dbbb8 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -628,11 +628,9 @@ static void OBSEvent(enum obs_frontend_event event, void *switcher) case OBS_FRONTEND_EVENT_STREAMING_STOPPED: resetLiveTime(); break; -#ifdef REPLAYBUFFER_SUPPORTED case OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED: setReplayBufferSaved(); break; -#endif case OBS_FRONTEND_EVENT_TRANSITION_STOPPED: setTranstionEnd(); break; diff --git a/src/external-macro-modules/opencv/macro-condition-video.cpp b/src/external-macro-modules/opencv/macro-condition-video.cpp index 7f5508f3..7602e300 100644 --- a/src/external-macro-modules/opencv/macro-condition-video.cpp +++ b/src/external-macro-modules/opencv/macro-condition-video.cpp @@ -540,18 +540,21 @@ void MacroConditionVideoEdit::ImageBrowseButtonClicked() obs_module_text("AdvSceneSwitcher.windowTitle"), obs_module_text( "AdvSceneSwitcher.condition.video.askFileAction"), - QMessageBox::Yes | QMessageBox::No); + QMessageBox::Yes | QMessageBox::No | + QMessageBox::Cancel); + auto yes = msgBox.button(QMessageBox::StandardButton::Yes); + yes->setText(obs_module_text( + "AdvSceneSwitcher.condition.video.askFileAction.file")); + auto no = msgBox.button(QMessageBox::StandardButton::No); + no->setText(obs_module_text( + "AdvSceneSwitcher.condition.video.askFileAction.screenshot")); msgBox.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); - msgBox.setButtonText( - QMessageBox::Yes, - obs_module_text( - "AdvSceneSwitcher.condition.video.askFileAction.file")); - msgBox.setButtonText( - QMessageBox::No, - obs_module_text( - "AdvSceneSwitcher.condition.video.askFileAction.screenshot")); - useExistingFile = msgBox.exec() == QMessageBox::Yes; + const auto result = msgBox.exec(); + if (result == QMessageBox::Cancel) { + return; + } + useExistingFile = result == QMessageBox::Yes; } if (useExistingFile) { diff --git a/src/headers/macro-action-replay-buffer.hpp b/src/headers/macro-action-replay-buffer.hpp index 9d59c37c..842a089c 100644 --- a/src/headers/macro-action-replay-buffer.hpp +++ b/src/headers/macro-action-replay-buffer.hpp @@ -1,5 +1,3 @@ -#ifdef REPLAYBUFFER_SUPPORTED - #pragma once #include "macro-action-edit.hpp" #include "duration-control.hpp" @@ -60,5 +58,3 @@ protected: private: bool _loading = true; }; - -#endif diff --git a/src/headers/macro-action-virtual-cam.hpp b/src/headers/macro-action-virtual-cam.hpp index ff1f128e..b3819786 100644 --- a/src/headers/macro-action-virtual-cam.hpp +++ b/src/headers/macro-action-virtual-cam.hpp @@ -1,5 +1,3 @@ -#ifdef VCAM_SUPPORTED - #pragma once #include "macro-action-edit.hpp" @@ -58,5 +56,3 @@ private: QHBoxLayout *_mainLayout; bool _loading = true; }; - -#endif diff --git a/src/headers/macro-condition-replay-buffer.hpp b/src/headers/macro-condition-replay-buffer.hpp index 1d9bb9f2..e759bba9 100644 --- a/src/headers/macro-condition-replay-buffer.hpp +++ b/src/headers/macro-condition-replay-buffer.hpp @@ -1,5 +1,3 @@ -#ifdef REPLAYBUFFER_SUPPORTED - #pragma once #include "macro.hpp" #include @@ -57,5 +55,3 @@ protected: private: bool _loading = true; }; - -#endif diff --git a/src/headers/macro-condition-virtual-cam.hpp b/src/headers/macro-condition-virtual-cam.hpp index f84ca860..30c68c76 100644 --- a/src/headers/macro-condition-virtual-cam.hpp +++ b/src/headers/macro-condition-virtual-cam.hpp @@ -1,5 +1,3 @@ -#ifdef VCAM_SUPPORTED - #pragma once #include "macro.hpp" #include @@ -55,5 +53,3 @@ protected: private: bool _loading = true; }; - -#endif diff --git a/src/headers/switch-network.hpp b/src/headers/switch-network.hpp index 5f519457..6c63d9cd 100644 --- a/src/headers/switch-network.hpp +++ b/src/headers/switch-network.hpp @@ -6,7 +6,6 @@ Most of this code is based on https://github.com/Palakis/obs-websocket #include #include -#include #include #include #include @@ -75,7 +74,7 @@ private: quint16 _serverPort = 55555; bool _lockToIPv4 = false; std::set> _connections; - QMutex _clMutex; + std::recursive_mutex _clMutex; QThreadPool _threadPool; }; diff --git a/src/macro-action-replay-buffer.cpp b/src/macro-action-replay-buffer.cpp index 263a48be..0c76a9a1 100644 --- a/src/macro-action-replay-buffer.cpp +++ b/src/macro-action-replay-buffer.cpp @@ -1,5 +1,3 @@ -#ifdef REPLAYBUFFER_SUPPORTED - #include "headers/macro-action-replay-buffer.hpp" #include "headers/advanced-scene-switcher.hpp" #include "headers/utility.hpp" @@ -125,5 +123,3 @@ void MacroActionReplayBufferEdit::ActionChanged(int value) ReplayBufferAction::SAVE); adjustSize(); } - -#endif diff --git a/src/macro-action-transition.cpp b/src/macro-action-transition.cpp index 000640b7..f07fd2f2 100644 --- a/src/macro-action-transition.cpp +++ b/src/macro-action-transition.cpp @@ -51,13 +51,6 @@ void MacroActionTransition::SetTransitionOverride() void MacroActionTransition::SetSourceTransition(bool show) { -#ifdef VISIBILITY_TRANSITIONS_SUPPORTED - const auto setTransitionFunc = show ? obs_sceneitem_set_show_transition - : obs_sceneitem_set_hide_transition; - const auto setDurationFunc = - show ? obs_sceneitem_set_show_transition_duration - : obs_sceneitem_set_hide_transition_duration; - auto transition = obs_weak_source_get_source(_transition.GetTransition()); obs_data_t *settings = obs_source_get_settings(transition); @@ -70,18 +63,16 @@ void MacroActionTransition::SetSourceTransition(bool show) const auto items = _source.GetSceneItems(_scene); for (auto &item : items) { if (_setTransitionType) { - setTransitionFunc(item, t); + obs_sceneitem_set_transition(item, show, t); } if (_setDuration) { - setDurationFunc(item, _duration.seconds * 1000); + obs_sceneitem_set_transition_duration( + item, show, _duration.seconds * 1000); } obs_sceneitem_release(item); } obs_source_release(t); -#else - blog(LOG_WARNING, "Setting hide / show transition not supported!"); -#endif } bool MacroActionTransition::PerformAction() diff --git a/src/macro-action-virtual-cam.cpp b/src/macro-action-virtual-cam.cpp index d5480c85..28bd7a5c 100644 --- a/src/macro-action-virtual-cam.cpp +++ b/src/macro-action-virtual-cam.cpp @@ -1,5 +1,3 @@ -#ifdef VCAM_SUPPORTED - #include "headers/macro-action-virtual-cam.hpp" #include "headers/advanced-scene-switcher.hpp" #include "headers/utility.hpp" @@ -109,5 +107,3 @@ void MacroActionVCamEdit::ActionChanged(int value) std::lock_guard lock(switcher->m); _entryData->_action = static_cast(value); } - -#endif diff --git a/src/macro-condition-file.cpp b/src/macro-condition-file.cpp index 547b32d3..8db98d62 100644 --- a/src/macro-condition-file.cpp +++ b/src/macro-condition-file.cpp @@ -6,6 +6,7 @@ #include #include +#include const std::string MacroConditionFile::id = "file"; @@ -56,8 +57,12 @@ bool MacroConditionFile::matchFileContent(QString &filedata) } if (_useRegex) { - QRegExp rx(QString::fromStdString(_text)); - return rx.exactMatch(filedata); + try { + std::regex expr(_text); + return std::regex_match(filedata.toStdString(), expr); + } catch (const std::regex_error &) { + return false; + } } QString text = QString::fromStdString(_text); diff --git a/src/macro-condition-replay-buffer.cpp b/src/macro-condition-replay-buffer.cpp index b1f29f1c..e5d39806 100644 --- a/src/macro-condition-replay-buffer.cpp +++ b/src/macro-condition-replay-buffer.cpp @@ -1,5 +1,3 @@ -#ifdef REPLAYBUFFER_SUPPORTED - #include "headers/macro-condition-edit.hpp" #include "headers/macro-condition-replay-buffer.hpp" #include "headers/utility.hpp" @@ -108,5 +106,3 @@ void MacroConditionReplayBufferEdit::UpdateEntryData() _state->setCurrentIndex(static_cast(_entryData->_state)); } - -#endif diff --git a/src/macro-condition-virtual-cam.cpp b/src/macro-condition-virtual-cam.cpp index 6f1a1de2..8b8a75f9 100644 --- a/src/macro-condition-virtual-cam.cpp +++ b/src/macro-condition-virtual-cam.cpp @@ -1,5 +1,3 @@ -#ifdef VCAM_SUPPORTED - #include "headers/macro-condition-edit.hpp" #include "headers/macro-condition-virtual-cam.hpp" #include "headers/utility.hpp" @@ -101,5 +99,3 @@ void MacroConditionVCamEdit::UpdateEntryData() _states->setCurrentIndex(static_cast(_entryData->_state)); } - -#endif diff --git a/src/macro-segment-list.cpp b/src/macro-segment-list.cpp index 13b24d43..ba9099bb 100644 --- a/src/macro-segment-list.cpp +++ b/src/macro-segment-list.cpp @@ -155,7 +155,7 @@ bool MacroSegmentList::eventFilter(QObject *object, QEvent *event) void MacroSegmentList::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { - _dragPosition = GetDragIndex(event->globalPos()); + _dragPosition = GetDragIndex(event->globalPosition().toPoint()); emit SelectionChagned(_dragPosition); } else { _dragPosition = -1; @@ -263,7 +263,7 @@ void MacroSegmentList::dragMoveEvent(QDragMoveEvent *event) return; } - _dragCursorPos = (mapToGlobal(event->pos())); + _dragCursorPos = (mapToGlobal(event->position().toPoint())); CheckDropLine(_dragCursorPos); } @@ -409,9 +409,11 @@ void MacroSegmentList::dropEvent(QDropEvent *event) { HideLastDropLine(); auto widget = qobject_cast(event->source()); - if (widget && !widget->geometry().contains(event->pos()) && + if (widget && + !widget->geometry().contains(event->position().toPoint()) && widgetIsInLayout(widget, _contentLayout)) { - int dropPosition = GetDropIndex(mapToGlobal(event->pos())); + int dropPosition = + GetDropIndex(mapToGlobal(event->position().toPoint())); if (dropPosition == -1) { return; } diff --git a/src/scene-trigger.cpp b/src/scene-trigger.cpp index 6ef630f5..bbffd7c1 100644 --- a/src/scene-trigger.cpp +++ b/src/scene-trigger.cpp @@ -185,22 +185,18 @@ void frontEndActionThread(sceneTriggerAction action, double delay) case sceneTriggerAction::STOP_STREAMING: obs_frontend_streaming_stop(); break; -#ifdef REPLAYBUFFER_SUPPORTED case sceneTriggerAction::START_REPLAY_BUFFER: obs_frontend_replay_buffer_start(); break; case sceneTriggerAction::STOP_REPLAY_BUFFER: obs_frontend_replay_buffer_stop(); break; -#endif -#ifdef VCAM_SUPPORTED case sceneTriggerAction::START_VCAM: obs_frontend_start_virtualcam(); break; case sceneTriggerAction::STOP_VCAM: obs_frontend_stop_virtualcam(); break; -#endif default: blog(LOG_WARNING, "ignoring unexpected frontend action '%d'", static_cast(action)); diff --git a/src/switch-file.cpp b/src/switch-file.cpp index 9e6950e5..f6a42d40 100644 --- a/src/switch-file.cpp +++ b/src/switch-file.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "headers/advanced-scene-switcher.hpp" @@ -113,7 +114,7 @@ void SwitcherData::writeToStatusFile(const QString &msg) QFile file(QString::fromStdString(fileIO.writePath)); if (file.open(QIODevice::ReadWrite)) { QTextStream stream(&file); - stream << msg << endl; + stream << msg << Qt::endl; } file.close(); } @@ -197,8 +198,12 @@ bool matchFileContent(QString &filedata, FileSwitch &s) } if (s.useRegex) { - QRegExp rx(QString::fromStdString(s.text)); - return rx.exactMatch(filedata); + try { + std::regex expr(s.text); + return std::regex_match(filedata.toStdString(), expr); + } catch (const std::regex_error &) { + return false; + } } QString text = QString::fromStdString(s.text); diff --git a/src/switch-network.cpp b/src/switch-network.cpp index 1abd6910..b132eabf 100644 --- a/src/switch-network.cpp +++ b/src/switch-network.cpp @@ -113,8 +113,7 @@ bool NetworkConfig::ShouldSendPrviewSceneChange() return ServerEnabled && SendPreview; } -WSServer::WSServer() - : QObject(nullptr), _connections(), _clMutex(QMutex::Recursive) +WSServer::WSServer() : QObject(nullptr), _connections(), _clMutex() { _server.get_alog().clear_channels( websocketpp::log::alevel::frame_header | @@ -169,13 +168,13 @@ void WSServer::start(quint16 port, bool lockToIPv4) blog(LOG_INFO, "server: listen failed: %s", errorCodeMessage.c_str()); - obs_frontend_push_ui_translation(obs_module_get_string); - QString errorTitle = tr("AdvSceneSwitcher.windowTitle"); + QString errorTitle = + obs_module_text("AdvSceneSwitcher.windowTitle"); QString errorMessage = - tr("AdvSceneSwitcher.networkTab.startFailed.message") + QString(obs_module_text( + "AdvSceneSwitcher.networkTab.startFailed.message")) .arg(_serverPort) .arg(errorCodeMessage.c_str()); - obs_frontend_pop_ui_translation(); QMainWindow *mainWindow = reinterpret_cast( obs_frontend_get_main_window()); @@ -256,9 +255,10 @@ void WSServer::sendMessage(sceneSwitchInfo sceneSwitch, bool preview) void WSServer::onOpen(connection_hdl hdl) { - QMutexLocker locker(&_clMutex); - _connections.insert(hdl); - locker.unlock(); + { + std::lock_guard lock(_clMutex); + _connections.insert(hdl); + } QString clientIp = getRemoteEndpoint(hdl); blog(LOG_INFO, "new client connection from %s", @@ -329,9 +329,10 @@ void WSServer::onMessage(connection_hdl, server::message_ptr message) void WSServer::onClose(connection_hdl hdl) { - QMutexLocker locker(&_clMutex); - _connections.erase(hdl); - locker.unlock(); + { + std::lock_guard lock(_clMutex); + _connections.erase(hdl); + } auto conn = _server.get_con_from_hdl(hdl); auto localCloseCode = conn->get_local_close_code(); diff --git a/src/volume-control.cpp b/src/volume-control.cpp index df1bcfd8..9f145567 100644 --- a/src/volume-control.cpp +++ b/src/volume-control.cpp @@ -590,9 +590,8 @@ VolumeMeter::calculateBallisticsForChannel(int channelNr, uint64_t ts, } else { // The peak and hold falls back to peak after 1 second. qreal timeSinceLastPeak = - (uint64_t)( - ts - - displayInputPeakHoldLastUpdateTime[channelNr]) * + (uint64_t)(ts - + displayInputPeakHoldLastUpdateTime[channelNr]) * 0.000000001; if (timeSinceLastPeak > inputPeakHoldDuration) { displayInputPeakHold[channelNr] = diff --git a/src/win/advanced-scene-switcher-win.cpp b/src/win/advanced-scene-switcher-win.cpp index 262b3aaf..58e0d91c 100644 --- a/src/win/advanced-scene-switcher-win.cpp +++ b/src/win/advanced-scene-switcher-win.cpp @@ -139,11 +139,9 @@ std::pair getCursorPos() HWND getHWNDfromTitle(std::string title) { HWND hwnd = NULL; - - std::wstring_convert> converter; - std::wstring wTitle = converter.from_bytes(title); - - hwnd = FindWindowEx(NULL, NULL, NULL, wTitle.c_str()); + wchar_t wTitle[512]; + os_utf8_to_wcs(title.c_str(), 0, wTitle, 512); + hwnd = FindWindowEx(NULL, NULL, NULL, wTitle); return hwnd; }