mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-08 09:36:07 -05:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba38b8bf27 | ||
|
|
38513735dd |
@@ -167,24 +167,6 @@ bool MacroSegment::IsTempVarInUse(const std::string &id) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroSegment::CopyTempVarValuesFrom(const MacroSegment &other)
|
|
||||||
{
|
|
||||||
for (const auto &src : other._tempVariables) {
|
|
||||||
for (auto &dst : _tempVariables) {
|
|
||||||
if (dst.ID() != src.ID()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto value = src.Value();
|
|
||||||
if (value) {
|
|
||||||
dst.SetValue(*value);
|
|
||||||
} else {
|
|
||||||
dst.InvalidateValue();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroSegment::SetTempVarValue(const std::string &id,
|
void MacroSegment::SetTempVarValue(const std::string &id,
|
||||||
const std::string &value)
|
const std::string &value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ protected:
|
|||||||
|
|
||||||
bool IsTempVarInUse(const std::string &id) const;
|
bool IsTempVarInUse(const std::string &id) const;
|
||||||
void SetTempVarValue(const std::string &id, const std::string &value);
|
void SetTempVarValue(const std::string &id, const std::string &value);
|
||||||
void CopyTempVarValuesFrom(const MacroSegment &other);
|
|
||||||
|
|
||||||
template<typename T, typename = std::enable_if_t<
|
template<typename T, typename = std::enable_if_t<
|
||||||
std::is_same<std::decay_t<T>, bool>::value>>
|
std::is_same<std::decay_t<T>, bool>::value>>
|
||||||
|
|||||||
@@ -428,13 +428,9 @@ bool Macro::RunActionsHelper(
|
|||||||
}
|
}
|
||||||
if (action->Enabled()) {
|
if (action->Enabled()) {
|
||||||
action->LogAction();
|
action->LogAction();
|
||||||
std::shared_ptr<MacroAction> actionCopy;
|
bool actionResult = false;
|
||||||
action->WithLock([&action, &actionCopy]() {
|
action->WithLock([&action, &actionResult]() {
|
||||||
actionCopy = action->Copy();
|
actionResult = action->PerformAction();
|
||||||
});
|
|
||||||
bool actionResult = actionCopy->PerformAction();
|
|
||||||
action->WithLock([&action, &actionCopy]() {
|
|
||||||
action->CopyTempVarValuesFrom(*actionCopy);
|
|
||||||
});
|
});
|
||||||
actionsExecutedSuccessfully =
|
actionsExecutedSuccessfully =
|
||||||
actionsExecutedSuccessfully && actionResult;
|
actionsExecutedSuccessfully && actionResult;
|
||||||
|
|||||||
@@ -66,4 +66,15 @@ void Lockable::WithLock(const std::function<void()> &func)
|
|||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SuspendLock::SuspendLock(Lockable &lockable)
|
||||||
|
: _mtx(static_cast<std::mutex &>(lockable._mtx))
|
||||||
|
{
|
||||||
|
_mtx.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
SuspendLock::~SuspendLock()
|
||||||
|
{
|
||||||
|
_mtx.lock();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace advss
|
} // namespace advss
|
||||||
|
|||||||
@@ -51,6 +51,24 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PerInstanceMutex _mtx;
|
PerInstanceMutex _mtx;
|
||||||
|
|
||||||
|
friend class SuspendLock;
|
||||||
|
};
|
||||||
|
|
||||||
|
// RAII guard that temporarily releases a Lockable's per-segment lock.
|
||||||
|
// Use this inside PerformAction() / CheckCondition() to unblock the UI
|
||||||
|
// during long-running operations while still running on the original segment.
|
||||||
|
// The caller MUST be holding the lock (i.e. be inside WithLock) when
|
||||||
|
// constructing this object; the lock is re-acquired on destruction.
|
||||||
|
class EXPORT SuspendLock {
|
||||||
|
public:
|
||||||
|
SuspendLock(Lockable &lockable);
|
||||||
|
~SuspendLock();
|
||||||
|
SuspendLock(const SuspendLock &) = delete;
|
||||||
|
SuspendLock &operator=(const SuspendLock &) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::mutex &_mtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace advss
|
} // namespace advss
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ static void waitHelper(std::unique_lock<std::mutex> *lock, Macro *macro,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroActionMedia::PerformActionHelper(obs_source_t *source) const
|
void MacroActionMedia::PerformActionHelper(obs_source_t *source)
|
||||||
{
|
{
|
||||||
obs_media_state state = obs_source_media_get_state(source);
|
obs_media_state state = obs_source_media_get_state(source);
|
||||||
|
|
||||||
@@ -130,6 +130,7 @@ void MacroActionMedia::PerformActionHelper(obs_source_t *source) const
|
|||||||
SeekToPercentage(source);
|
SeekToPercentage(source);
|
||||||
break;
|
break;
|
||||||
case Action::WAIT_FOR_PLAYBACK_STOP: {
|
case Action::WAIT_FOR_PLAYBACK_STOP: {
|
||||||
|
SuspendLock suspendLock(*this);
|
||||||
std::unique_lock<std::mutex> lock(*GetMutex());
|
std::unique_lock<std::mutex> lock(*GetMutex());
|
||||||
waitHelper(&lock, GetMacro(), source);
|
waitHelper(&lock, GetMacro(), source);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
SceneSelection _scene;
|
SceneSelection _scene;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PerformActionHelper(obs_source_t *) const;
|
void PerformActionHelper(obs_source_t *);
|
||||||
void SeekToPercentage(obs_source_t *source) const;
|
void SeekToPercentage(obs_source_t *source) const;
|
||||||
|
|
||||||
static bool _registered;
|
static bool _registered;
|
||||||
|
|||||||
@@ -159,7 +159,10 @@ bool MacroActionPlayAudio::PerformAction()
|
|||||||
|
|
||||||
if (_waitForCompletion) {
|
if (_waitForCompletion) {
|
||||||
SetMacroAbortWait(false);
|
SetMacroAbortWait(false);
|
||||||
waitForPlaybackToEnd(GetMacro(), source, maxMs);
|
{
|
||||||
|
SuspendLock suspendLock(*this);
|
||||||
|
waitForPlaybackToEnd(GetMacro(), source, maxMs);
|
||||||
|
}
|
||||||
deactivatePlayback(source, wantsOutput);
|
deactivatePlayback(source, wantsOutput);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,20 @@ bool MacroActionRun::_registered = MacroActionFactory::Register(
|
|||||||
bool MacroActionRun::PerformAction()
|
bool MacroActionRun::PerformAction()
|
||||||
{
|
{
|
||||||
if (_wait) {
|
if (_wait) {
|
||||||
_procConfig.StartProcessAndWait(_timeout.Milliseconds());
|
// Snapshot config before releasing the lock for the blocking wait
|
||||||
SetTempVarValues();
|
auto procConfig = _procConfig;
|
||||||
|
const auto timeout = _timeout.Milliseconds();
|
||||||
|
{
|
||||||
|
SuspendLock suspendLock(*this);
|
||||||
|
procConfig.StartProcessAndWait(timeout);
|
||||||
|
}
|
||||||
|
SetTempVarValue("process.id", procConfig.GetProcessId());
|
||||||
|
SetTempVarValue("process.exitCode",
|
||||||
|
procConfig.GetProcessExitCode());
|
||||||
|
SetTempVarValue("process.stream.output",
|
||||||
|
procConfig.GetProcessOutputStream());
|
||||||
|
SetTempVarValue("process.stream.error",
|
||||||
|
procConfig.GetProcessErrorStream());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -259,6 +259,12 @@ void MacroActionSourceInteractionEdit::AcceptRecorded(
|
|||||||
_stepList->SetSteps(_entryData->_steps);
|
_stepList->SetSteps(_entryData->_steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MacroActionSourceInteractionEdit::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
const QSignalBlocker b(this);
|
||||||
|
UpdateEntryData();
|
||||||
|
}
|
||||||
|
|
||||||
void MacroActionSourceInteractionEdit::SetCurrentStepEditor(int row)
|
void MacroActionSourceInteractionEdit::SetCurrentStepEditor(int row)
|
||||||
{
|
{
|
||||||
if (_stepEditor) {
|
if (_stepEditor) {
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ private slots:
|
|||||||
signals:
|
signals:
|
||||||
void HeaderInfoChanged(const QString &);
|
void HeaderInfoChanged(const QString &);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetCurrentStepEditor(int row);
|
void SetCurrentStepEditor(int row);
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,11 @@ bool MacroActionWait::PerformAction()
|
|||||||
std::chrono::milliseconds((int)(sleepDuration * 1000));
|
std::chrono::milliseconds((int)(sleepDuration * 1000));
|
||||||
|
|
||||||
SetMacroAbortWait(false);
|
SetMacroAbortWait(false);
|
||||||
std::unique_lock<std::mutex> lock(*GetMutex());
|
{
|
||||||
waitHelper(&lock, GetMacro(), time);
|
SuspendLock suspendLock(*this);
|
||||||
|
std::unique_lock<std::mutex> lock(*GetMutex());
|
||||||
|
waitHelper(&lock, GetMacro(), time);
|
||||||
|
}
|
||||||
|
|
||||||
return !MacroWaitShouldAbort();
|
return !MacroWaitShouldAbort();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,48 +112,56 @@ static URLInfo getURLInfo(const std::string &input, bool keepParams)
|
|||||||
|
|
||||||
bool MacroActionHttp::PerformAction()
|
bool MacroActionHttp::PerformAction()
|
||||||
{
|
{
|
||||||
|
// Capture all config while holding the segment lock
|
||||||
const auto [host, path] = getURLInfo(_url, !_setParams);
|
const auto [host, path] = getURLInfo(_url, !_setParams);
|
||||||
|
|
||||||
httplib::Client cli(host);
|
httplib::Client cli(host);
|
||||||
setTimeout(cli, _timeout);
|
setTimeout(cli, _timeout);
|
||||||
const auto params = _setParams ? getParams(_params) : httplib::Params();
|
const auto params = _setParams ? getParams(_params) : httplib::Params();
|
||||||
const auto headers = _setHeaders ? getHeaders(_headers)
|
const auto headers = _setHeaders ? getHeaders(_headers)
|
||||||
: httplib::Headers();
|
: httplib::Headers();
|
||||||
|
const auto method = _method;
|
||||||
|
const std::string body = _body;
|
||||||
|
const std::string contentType = _contentType;
|
||||||
|
|
||||||
|
// Release the segment lock for the blocking network call
|
||||||
httplib::Result response;
|
httplib::Result response;
|
||||||
switch (_method) {
|
{
|
||||||
case MacroActionHttp::Method::GET:
|
SuspendLock suspendLock(*this);
|
||||||
response = cli.Get(path, params, headers);
|
switch (method) {
|
||||||
break;
|
case MacroActionHttp::Method::GET:
|
||||||
case MacroActionHttp::Method::POST: {
|
response = cli.Get(path, params, headers);
|
||||||
const auto pathWithParam =
|
break;
|
||||||
httplib::append_query_params(path, params);
|
case MacroActionHttp::Method::POST: {
|
||||||
response =
|
const auto pathWithParam =
|
||||||
cli.Post(pathWithParam, headers, _body, _contentType);
|
httplib::append_query_params(path, params);
|
||||||
break;
|
response = cli.Post(pathWithParam, headers, body,
|
||||||
}
|
contentType);
|
||||||
case MacroActionHttp::Method::PUT: {
|
break;
|
||||||
const auto pathWithParam =
|
}
|
||||||
httplib::append_query_params(path, params);
|
case MacroActionHttp::Method::PUT: {
|
||||||
response = cli.Put(pathWithParam, headers, _body, _contentType);
|
const auto pathWithParam =
|
||||||
break;
|
httplib::append_query_params(path, params);
|
||||||
}
|
response = cli.Put(pathWithParam, headers, body,
|
||||||
case MacroActionHttp::Method::PATCH: {
|
contentType);
|
||||||
const auto pathWithParam =
|
break;
|
||||||
httplib::append_query_params(path, params);
|
}
|
||||||
response =
|
case MacroActionHttp::Method::PATCH: {
|
||||||
cli.Patch(pathWithParam, headers, _body, _contentType);
|
const auto pathWithParam =
|
||||||
break;
|
httplib::append_query_params(path, params);
|
||||||
}
|
response = cli.Patch(pathWithParam, headers, body,
|
||||||
case MacroActionHttp::Method::DELETE: {
|
contentType);
|
||||||
const auto pathWithParam =
|
break;
|
||||||
httplib::append_query_params(path, params);
|
}
|
||||||
response =
|
case MacroActionHttp::Method::DELETE: {
|
||||||
cli.Delete(pathWithParam, headers, _body, _contentType);
|
const auto pathWithParam =
|
||||||
break;
|
httplib::append_query_params(path, params);
|
||||||
}
|
response = cli.Delete(pathWithParam, headers, body,
|
||||||
default:
|
contentType);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VerboseLoggingEnabled() && !response) {
|
if (VerboseLoggingEnabled() && !response) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ bool MacroActionScript::PerformAction()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SuspendLock suspendLock(static_cast<MacroAction &>(*this));
|
||||||
(void)SendTriggerSignal();
|
(void)SendTriggerSignal();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ bool MacroConditionScript::CheckCondition()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SuspendLock suspendLock(static_cast<MacroCondition &>(*this));
|
||||||
return SendTriggerSignal();
|
return SendTriggerSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user