Fix depecrations and clean up backwards compatibility checks

This commit is contained in:
WarmUpTill
2022-08-04 23:18:28 +02:00
committed by WarmUpTill
parent 5cb50821e0
commit 786c9592a1
19 changed files with 56 additions and 91 deletions

View File

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

View File

@@ -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) {

View File

@@ -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

View File

@@ -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

View File

@@ -1,5 +1,3 @@
#ifdef REPLAYBUFFER_SUPPORTED
#pragma once
#include "macro.hpp"
#include <QWidget>
@@ -57,5 +55,3 @@ protected:
private:
bool _loading = true;
};
#endif

View File

@@ -1,5 +1,3 @@
#ifdef VCAM_SUPPORTED
#pragma once
#include "macro.hpp"
#include <QWidget>
@@ -55,5 +53,3 @@ protected:
private:
bool _loading = true;
};
#endif

View File

@@ -6,7 +6,6 @@ Most of this code is based on https://github.com/Palakis/obs-websocket
#include <set>
#include <QtCore/QObject>
#include <QtCore/QMutex>
#include <QtCore/QSharedPointer>
#include <QtCore/QVariantHash>
#include <QtCore/QThreadPool>
@@ -75,7 +74,7 @@ private:
quint16 _serverPort = 55555;
bool _lockToIPv4 = false;
std::set<connection_hdl, std::owner_less<connection_hdl>> _connections;
QMutex _clMutex;
std::recursive_mutex _clMutex;
QThreadPool _threadPool;
};

View File

@@ -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

View File

@@ -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()

View File

@@ -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<std::mutex> lock(switcher->m);
_entryData->_action = static_cast<VCamAction>(value);
}
#endif

View File

@@ -6,6 +6,7 @@
#include <QTextStream>
#include <QFileDialog>
#include <regex>
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);

View File

@@ -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<int>(_entryData->_state));
}
#endif

View File

@@ -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<int>(_entryData->_state));
}
#endif

View File

@@ -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<QWidget *>(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;
}

View File

@@ -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<int>(action));

View File

@@ -2,6 +2,7 @@
#include <QTextStream>
#include <QDateTime>
#include <functional>
#include <regex>
#include <curl/curl.h>
#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);

View File

@@ -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<QMainWindow *>(
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<std::recursive_mutex> 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<std::recursive_mutex> lock(_clMutex);
_connections.erase(hdl);
}
auto conn = _server.get_con_from_hdl(hdl);
auto localCloseCode = conn->get_local_close_code();

View File

@@ -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] =

View File

@@ -139,11 +139,9 @@ std::pair<int, int> getCursorPos()
HWND getHWNDfromTitle(std::string title)
{
HWND hwnd = NULL;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> 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;
}