mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-11 11:06:03 -05:00
Compare commits
6 Commits
mac-proc-f
...
undo-redo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
953a05054d | ||
|
|
bb9e3efa90 | ||
|
|
71a2a83c3b | ||
|
|
d946ed485c | ||
|
|
33ee7ac6cb | ||
|
|
3bcc041487 |
@@ -173,6 +173,8 @@ target_sources(
|
|||||||
lib/macro/macro-signals.hpp
|
lib/macro/macro-signals.hpp
|
||||||
lib/macro/macro-tab.cpp
|
lib/macro/macro-tab.cpp
|
||||||
lib/macro/macro-tree.cpp
|
lib/macro/macro-tree.cpp
|
||||||
|
lib/macro/macro-undo-redo.cpp
|
||||||
|
lib/macro/macro-undo-redo.hpp
|
||||||
lib/macro/macro-tree.hpp
|
lib/macro/macro-tree.hpp
|
||||||
lib/macro/macro-websocket-trigger.cpp
|
lib/macro/macro-websocket-trigger.cpp
|
||||||
lib/macro/macro.cpp
|
lib/macro/macro.cpp
|
||||||
|
|||||||
@@ -198,6 +198,20 @@ AdvSceneSwitcher.macroTab.groupNameExists="The name \"%1\" is already used by a
|
|||||||
AdvSceneSwitcher.macroTab.removeSingleMacroPopup.text="Are you sure you want to remove \"%1\"?"
|
AdvSceneSwitcher.macroTab.removeSingleMacroPopup.text="Are you sure you want to remove \"%1\"?"
|
||||||
AdvSceneSwitcher.macroTab.removeMultipleMacrosPopup.text="Are you sure you want to remove %1 macros/groups?"
|
AdvSceneSwitcher.macroTab.removeMultipleMacrosPopup.text="Are you sure you want to remove %1 macros/groups?"
|
||||||
AdvSceneSwitcher.macroTab.removeGroupPopup.text="Are you sure you want to remove \"%1\" group and all its elements?"
|
AdvSceneSwitcher.macroTab.removeGroupPopup.text="Are you sure you want to remove \"%1\" group and all its elements?"
|
||||||
|
AdvSceneSwitcher.undo.renameMacro="Rename Macro '%1'"
|
||||||
|
AdvSceneSwitcher.undo.modifyMacro="Modify Macro '%1'"
|
||||||
|
AdvSceneSwitcher.undo.addMacro="Add Macro '%1'"
|
||||||
|
AdvSceneSwitcher.undo.removeMacro="Remove Macro '%1'"
|
||||||
|
AdvSceneSwitcher.undo.importMacros="Import Macros"
|
||||||
|
AdvSceneSwitcher.undo.addSegment="Add %1 in '%2'"
|
||||||
|
AdvSceneSwitcher.undo.removeSegment="Remove %1 in '%2'"
|
||||||
|
AdvSceneSwitcher.undo.changeSegmentType="Change %1 Type in '%2'"
|
||||||
|
AdvSceneSwitcher.undo.groupMacros="Group Macros '%1'"
|
||||||
|
AdvSceneSwitcher.undo.ungroupMacros="Ungroup Macros '%1'"
|
||||||
|
AdvSceneSwitcher.undo.removeMacroGroup="Remove Macro Group '%1'"
|
||||||
|
AdvSceneSwitcher.undo.segment.action="Action"
|
||||||
|
AdvSceneSwitcher.undo.segment.elseAction="Else Action"
|
||||||
|
AdvSceneSwitcher.undo.segment.condition="Condition"
|
||||||
AdvSceneSwitcher.macroTab.contextMenuAdd="Add"
|
AdvSceneSwitcher.macroTab.contextMenuAdd="Add"
|
||||||
AdvSceneSwitcher.macroTab.copy="Duplicate Macro"
|
AdvSceneSwitcher.macroTab.copy="Duplicate Macro"
|
||||||
AdvSceneSwitcher.macroTab.group="Group Selected Macros"
|
AdvSceneSwitcher.macroTab.group="Group Selected Macros"
|
||||||
@@ -267,7 +281,6 @@ AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.unpause="Unpaused"
|
|||||||
AdvSceneSwitcher.macroTab.currentRegisterDock="Register dock widget to control the pause state of selected macro or run it manually"
|
AdvSceneSwitcher.macroTab.currentRegisterDock="Register dock widget to control the pause state of selected macro or run it manually"
|
||||||
AdvSceneSwitcher.macroTab.currentIsStandaloneDock="Is standalone dock"
|
AdvSceneSwitcher.macroTab.currentIsStandaloneDock="Is standalone dock"
|
||||||
AdvSceneSwitcher.macroTab.currentDockWindowName="Add to macro dock with name:"
|
AdvSceneSwitcher.macroTab.currentDockWindowName="Add to macro dock with name:"
|
||||||
AdvSceneSwitcher.macroTab.currentDockWindowName.addNew="Add new dock..."
|
|
||||||
AdvSceneSwitcher.macroTab.currentDockAddRunButton="Add button to run the macro"
|
AdvSceneSwitcher.macroTab.currentDockAddRunButton="Add button to run the macro"
|
||||||
AdvSceneSwitcher.macroTab.currentDockAddPauseButton="Add button to pause or unpause the macro"
|
AdvSceneSwitcher.macroTab.currentDockAddPauseButton="Add button to pause or unpause the macro"
|
||||||
AdvSceneSwitcher.macroTab.currentDockAddStatusLabel="Add status label"
|
AdvSceneSwitcher.macroTab.currentDockAddStatusLabel="Add status label"
|
||||||
@@ -986,7 +999,6 @@ AdvSceneSwitcher.action.playAudio.monitorUnavailable="Audio monitoring not avail
|
|||||||
AdvSceneSwitcher.action.playAudio.tracks="Tracks"
|
AdvSceneSwitcher.action.playAudio.tracks="Tracks"
|
||||||
AdvSceneSwitcher.action.playAudio.layout.startOffset="{{useStartOffset}}Start at{{startOffset}}"
|
AdvSceneSwitcher.action.playAudio.layout.startOffset="{{useStartOffset}}Start at{{startOffset}}"
|
||||||
AdvSceneSwitcher.action.playAudio.layout.playbackDuration="{{useDuration}}Play for{{playbackDuration}}(0 = until end)"
|
AdvSceneSwitcher.action.playAudio.layout.playbackDuration="{{useDuration}}Play for{{playbackDuration}}(0 = until end)"
|
||||||
AdvSceneSwitcher.action.playAudio.mono="Mono"
|
|
||||||
AdvSceneSwitcher.action.recording="Recording"
|
AdvSceneSwitcher.action.recording="Recording"
|
||||||
AdvSceneSwitcher.action.recording.type.stop="Stop recording"
|
AdvSceneSwitcher.action.recording.type.stop="Stop recording"
|
||||||
AdvSceneSwitcher.action.recording.type.start="Start recording"
|
AdvSceneSwitcher.action.recording.type.start="Start recording"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "macro-action-edit.hpp"
|
#include "macro-action-edit.hpp"
|
||||||
|
#include "macro-undo-redo.hpp"
|
||||||
#include "advanced-scene-switcher.hpp"
|
#include "advanced-scene-switcher.hpp"
|
||||||
#include "macro-helpers.hpp"
|
#include "macro-helpers.hpp"
|
||||||
#include "macro-settings.hpp"
|
#include "macro-settings.hpp"
|
||||||
@@ -111,9 +112,32 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro =
|
||||||
|
(*_entryData)->GetMacro()->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string oldId = (*_entryData)->GetId();
|
||||||
|
OBSDataAutoRelease oldData = obs_data_create();
|
||||||
|
(*_entryData)->Save(oldData);
|
||||||
|
|
||||||
HeaderInfoChanged("");
|
HeaderInfoChanged("");
|
||||||
auto idx = _entryData->get()->GetIndex();
|
auto idx = _entryData->get()->GetIndex();
|
||||||
auto macro = _entryData->get()->GetMacro();
|
auto macro = _entryData->get()->GetMacro();
|
||||||
|
|
||||||
|
// Determine whether this is an action or else-action before resetting.
|
||||||
|
const auto *rawPtr = (*_entryData).get();
|
||||||
|
const auto &elseActions = macro->ElseActions();
|
||||||
|
const bool isElse = std::any_of(elseActions.begin(), elseActions.end(),
|
||||||
|
[rawPtr](const auto &a) {
|
||||||
|
return a.get() == rawPtr;
|
||||||
|
});
|
||||||
|
const auto segmentType = isElse ? MacroEdit::SegmentType::ELSE_ACTION
|
||||||
|
: MacroEdit::SegmentType::ACTION;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
_entryData->reset();
|
_entryData->reset();
|
||||||
@@ -122,6 +146,16 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text)
|
|||||||
(*_entryData)->PostLoad();
|
(*_entryData)->PostLoad();
|
||||||
RunAndClearPostLoadSteps();
|
RunAndClearPostLoadSteps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease newData = obs_data_create();
|
||||||
|
(*_entryData)->Save(newData);
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
} else {
|
||||||
|
RegisterSegmentTypeChangeUndoRedo(macro, segmentType, idx,
|
||||||
|
oldId, oldData, 0, id,
|
||||||
|
newData, 0);
|
||||||
|
}
|
||||||
auto widget = MacroActionFactory::CreateWidget(id, this, *_entryData);
|
auto widget = MacroActionFactory::CreateWidget(id, this, *_entryData);
|
||||||
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
|
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
|
||||||
this, SLOT(HeaderInfoChanged(const QString &)));
|
this, SLOT(HeaderInfoChanged(const QString &)));
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ bool MacroActionLoop::PostLoad()
|
|||||||
MacroAction::PostLoad();
|
MacroAction::PostLoad();
|
||||||
_loopMacro->PostLoad();
|
_loopMacro->PostLoad();
|
||||||
_loopMacro->SetActionTriggerMode(Macro::ActionTriggerMode::ALWAYS);
|
_loopMacro->SetActionTriggerMode(Macro::ActionTriggerMode::ALWAYS);
|
||||||
|
_loopMacro->SetNestedParentMacro(GetMacro());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ bool MacroActionMacro::PostLoad()
|
|||||||
MacroAction::PostLoad();
|
MacroAction::PostLoad();
|
||||||
_runOptions.macro.PostLoad();
|
_runOptions.macro.PostLoad();
|
||||||
_nestedMacro->PostLoad();
|
_nestedMacro->PostLoad();
|
||||||
|
_nestedMacro->SetNestedParentMacro(GetMacro());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "macro-condition-edit.hpp"
|
#include "macro-condition-edit.hpp"
|
||||||
|
#include "macro-undo-redo.hpp"
|
||||||
|
|
||||||
#include "advanced-scene-switcher.hpp"
|
#include "advanced-scene-switcher.hpp"
|
||||||
#include "condition-logic.hpp"
|
#include "condition-logic.hpp"
|
||||||
@@ -250,6 +251,19 @@ void MacroConditionEdit::ConditionSelectionChanged(const QString &text)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro =
|
||||||
|
(*_entryData)->GetMacro()->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string oldId = (*_entryData)->GetId();
|
||||||
|
const int oldLogic = (int)(*_entryData)->GetLogicType();
|
||||||
|
OBSDataAutoRelease oldData = obs_data_create();
|
||||||
|
(*_entryData)->Save(oldData);
|
||||||
|
|
||||||
auto temp = DurationModifier();
|
auto temp = DurationModifier();
|
||||||
_dur->SetValue(temp);
|
_dur->SetValue(temp);
|
||||||
HeaderInfoChanged("");
|
HeaderInfoChanged("");
|
||||||
@@ -267,6 +281,17 @@ void MacroConditionEdit::ConditionSelectionChanged(const QString &text)
|
|||||||
(*_entryData)->PostLoad();
|
(*_entryData)->PostLoad();
|
||||||
RunAndClearPostLoadSteps();
|
RunAndClearPostLoadSteps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease newData = obs_data_create();
|
||||||
|
(*_entryData)->Save(newData);
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
} else {
|
||||||
|
RegisterSegmentTypeChangeUndoRedo(
|
||||||
|
macro, MacroEdit::SegmentType::CONDITION, idx, oldId,
|
||||||
|
oldData, oldLogic, id, newData,
|
||||||
|
(int)(*_entryData)->GetLogicType());
|
||||||
|
}
|
||||||
auto widget =
|
auto widget =
|
||||||
MacroConditionFactory::CreateWidget(id, this, *_entryData);
|
MacroConditionFactory::CreateWidget(id, this, *_entryData);
|
||||||
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
|
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "macro-edit.hpp"
|
#include "macro-edit.hpp"
|
||||||
|
|
||||||
#include "condition-logic.hpp"
|
#include "condition-logic.hpp"
|
||||||
|
#include "macro-undo-redo.hpp"
|
||||||
#include "cursor-shape-changer.hpp"
|
#include "cursor-shape-changer.hpp"
|
||||||
#include "macro-action-edit.hpp"
|
#include "macro-action-edit.hpp"
|
||||||
#include "macro-action-macro.hpp"
|
#include "macro-action-macro.hpp"
|
||||||
@@ -257,6 +258,92 @@ std::shared_ptr<Macro> MacroEdit::GetMacro() const
|
|||||||
return _currentMacro;
|
return _currentMacro;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MacroEdit::InsertSegmentWidget(SegmentType type, int idx)
|
||||||
|
{
|
||||||
|
auto macro = _currentMacro;
|
||||||
|
if (!macro) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SegmentType::ACTION: {
|
||||||
|
if (idx < 0 || idx > (int)macro->Actions().size()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ui->actionsList->Insert(
|
||||||
|
idx, new MacroActionEdit(this, ¯o->Actions()[idx]));
|
||||||
|
SetActionData(*macro);
|
||||||
|
ui->actionsList->SetHelpMsgVisible(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SegmentType::ELSE_ACTION: {
|
||||||
|
if (idx < 0 || idx > (int)macro->ElseActions().size()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ui->elseActionsList->Insert(
|
||||||
|
idx,
|
||||||
|
new MacroActionEdit(this, ¯o->ElseActions()[idx]));
|
||||||
|
SetElseActionData(*macro);
|
||||||
|
ui->elseActionsList->SetHelpMsgVisible(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SegmentType::CONDITION: {
|
||||||
|
if (idx < 0 || idx > (int)macro->Conditions().size()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ui->conditionsList->Insert(
|
||||||
|
idx,
|
||||||
|
new MacroConditionEdit(this, ¯o->Conditions()[idx],
|
||||||
|
idx == 0));
|
||||||
|
if (idx == 0 && macro->Conditions().size() > 1) {
|
||||||
|
static_cast<MacroConditionEdit *>(
|
||||||
|
ui->conditionsList->WidgetAt(1))
|
||||||
|
->SetRootNode(false);
|
||||||
|
}
|
||||||
|
SetConditionData(*macro);
|
||||||
|
ui->conditionsList->SetHelpMsgVisible(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MacroEdit::RemoveSegmentWidget(SegmentType type, int idx)
|
||||||
|
{
|
||||||
|
auto macro = _currentMacro;
|
||||||
|
if (!macro) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SegmentType::ACTION:
|
||||||
|
if (idx >= 0 &&
|
||||||
|
idx < ui->actionsList->ContentLayout()->count()) {
|
||||||
|
ui->actionsList->Remove(idx);
|
||||||
|
SetActionData(*macro);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SegmentType::ELSE_ACTION:
|
||||||
|
if (idx >= 0 &&
|
||||||
|
idx < ui->elseActionsList->ContentLayout()->count()) {
|
||||||
|
ui->elseActionsList->Remove(idx);
|
||||||
|
SetElseActionData(*macro);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SegmentType::CONDITION:
|
||||||
|
if (idx >= 0 &&
|
||||||
|
idx < ui->conditionsList->ContentLayout()->count()) {
|
||||||
|
ui->conditionsList->Remove(idx);
|
||||||
|
if (idx == 0 && !macro->Conditions().empty()) {
|
||||||
|
static_cast<MacroConditionEdit *>(
|
||||||
|
ui->conditionsList->WidgetAt(0))
|
||||||
|
->SetRootNode(true);
|
||||||
|
}
|
||||||
|
SetConditionData(*macro);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MacroEdit::ClearSegmentWidgetCacheFor(Macro *macro) const
|
void MacroEdit::ClearSegmentWidgetCacheFor(Macro *macro) const
|
||||||
{
|
{
|
||||||
ui->conditionsList->ClearWidgetsFromCacheFor(macro);
|
ui->conditionsList->ClearWidgetsFromCacheFor(macro);
|
||||||
@@ -295,7 +382,7 @@ isValidMacroSegmentIdx(const std::deque<std::shared_ptr<MacroSegment>> &list,
|
|||||||
return (idx > 0 || (unsigned)idx < list.size());
|
return (idx > 0 || (unsigned)idx < list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
void MacroEdit::SetupMacroSegmentSelection(SegmentType type, int idx)
|
||||||
{
|
{
|
||||||
auto macro = _currentMacro;
|
auto macro = _currentMacro;
|
||||||
if (!macro) {
|
if (!macro) {
|
||||||
@@ -308,7 +395,7 @@ void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
|||||||
std::deque<std::shared_ptr<MacroSegment>> segments;
|
std::deque<std::shared_ptr<MacroSegment>> segments;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MacroEdit::MacroSection::CONDITIONS:
|
case MacroEdit::SegmentType::CONDITION:
|
||||||
setList = ui->conditionsList;
|
setList = ui->conditionsList;
|
||||||
setIdx = ¤tConditionIdx;
|
setIdx = ¤tConditionIdx;
|
||||||
segments = {macro->Conditions().begin(),
|
segments = {macro->Conditions().begin(),
|
||||||
@@ -319,7 +406,7 @@ void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
|||||||
resetIdx1 = ¤tActionIdx;
|
resetIdx1 = ¤tActionIdx;
|
||||||
resetIdx2 = ¤tElseActionIdx;
|
resetIdx2 = ¤tElseActionIdx;
|
||||||
break;
|
break;
|
||||||
case MacroEdit::MacroSection::ACTIONS:
|
case MacroEdit::SegmentType::ACTION:
|
||||||
setList = ui->actionsList;
|
setList = ui->actionsList;
|
||||||
setIdx = ¤tActionIdx;
|
setIdx = ¤tActionIdx;
|
||||||
segments = {macro->Actions().begin(), macro->Actions().end()};
|
segments = {macro->Actions().begin(), macro->Actions().end()};
|
||||||
@@ -329,7 +416,7 @@ void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
|||||||
resetIdx1 = ¤tConditionIdx;
|
resetIdx1 = ¤tConditionIdx;
|
||||||
resetIdx2 = ¤tElseActionIdx;
|
resetIdx2 = ¤tElseActionIdx;
|
||||||
break;
|
break;
|
||||||
case MacroEdit::MacroSection::ELSE_ACTIONS:
|
case MacroEdit::SegmentType::ELSE_ACTION:
|
||||||
setList = ui->elseActionsList;
|
setList = ui->elseActionsList;
|
||||||
setIdx = ¤tElseActionIdx;
|
setIdx = ¤tElseActionIdx;
|
||||||
segments = {macro->ElseActions().begin(),
|
segments = {macro->ElseActions().begin(),
|
||||||
@@ -965,7 +1052,7 @@ void MacroEdit::UpMacroSegmentHotkey()
|
|||||||
int conditionSize = macro->Conditions().size();
|
int conditionSize = macro->Conditions().size();
|
||||||
|
|
||||||
if (currentActionIdx == -1 && currentConditionIdx == -1) {
|
if (currentActionIdx == -1 && currentConditionIdx == -1) {
|
||||||
if (lastInteracted == MacroSection::CONDITIONS) {
|
if (lastInteracted == SegmentType::CONDITION) {
|
||||||
if (conditionSize == 0) {
|
if (conditionSize == 0) {
|
||||||
MacroActionSelectionChanged(0);
|
MacroActionSelectionChanged(0);
|
||||||
} else {
|
} else {
|
||||||
@@ -1021,7 +1108,7 @@ void MacroEdit::DownMacroSegmentHotkey()
|
|||||||
int conditionSize = macro->Conditions().size();
|
int conditionSize = macro->Conditions().size();
|
||||||
|
|
||||||
if (currentActionIdx == -1 && currentConditionIdx == -1) {
|
if (currentActionIdx == -1 && currentConditionIdx == -1) {
|
||||||
if (lastInteracted == MacroSection::CONDITIONS) {
|
if (lastInteracted == SegmentType::CONDITION) {
|
||||||
if (conditionSize == 0) {
|
if (conditionSize == 0) {
|
||||||
MacroActionSelectionChanged(0);
|
MacroActionSelectionChanged(0);
|
||||||
} else {
|
} else {
|
||||||
@@ -1084,6 +1171,13 @@ void MacroEdit::AddMacroAction(Macro *macro, int idx, const std::string &id,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
macro->Actions().emplace(macro->Actions().begin() + idx,
|
macro->Actions().emplace(macro->Actions().begin() + idx,
|
||||||
@@ -1098,6 +1192,11 @@ void MacroEdit::AddMacroAction(Macro *macro, int idx, const std::string &id,
|
|||||||
idx, new MacroActionEdit(this, ¯o->Actions()[idx]));
|
idx, new MacroActionEdit(this, ¯o->Actions()[idx]));
|
||||||
SetActionData(*macro);
|
SetActionData(*macro);
|
||||||
}
|
}
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
} else {
|
||||||
|
RegisterSegmentAddUndoRedo(macro, SegmentType::ACTION, idx);
|
||||||
|
}
|
||||||
HighlightAction(idx);
|
HighlightAction(idx);
|
||||||
ui->actionsList->SetHelpMsgVisible(false);
|
ui->actionsList->SetHelpMsgVisible(false);
|
||||||
emit(MacroSegmentOrderChanged());
|
emit(MacroSegmentOrderChanged());
|
||||||
@@ -1163,6 +1262,24 @@ void MacroEdit::RemoveMacroAction(int idx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
} else {
|
||||||
|
OBSDataAutoRelease segData = obs_data_create();
|
||||||
|
std::string segId;
|
||||||
|
{
|
||||||
|
auto lock = LockContext();
|
||||||
|
macro->Actions().at(idx)->Save(segData);
|
||||||
|
segId = macro->Actions().at(idx)->GetId();
|
||||||
|
}
|
||||||
|
RegisterSegmentRemoveUndoRedo(macro.get(), SegmentType::ACTION,
|
||||||
|
idx, segId, segData,
|
||||||
|
(int)Logic::Type::ROOT_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
ui->actionsList->Remove(idx);
|
ui->actionsList->Remove(idx);
|
||||||
@@ -1172,8 +1289,11 @@ void MacroEdit::RemoveMacroAction(int idx)
|
|||||||
macro->UpdateActionIndices();
|
macro->UpdateActionIndices();
|
||||||
SetActionData(*macro);
|
SetActionData(*macro);
|
||||||
}
|
}
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
}
|
||||||
MacroActionSelectionChanged(-1);
|
MacroActionSelectionChanged(-1);
|
||||||
lastInteracted = MacroSection::ACTIONS;
|
lastInteracted = SegmentType::ACTION;
|
||||||
emit(MacroSegmentOrderChanged());
|
emit(MacroSegmentOrderChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1353,7 +1473,7 @@ void MacroEdit::MoveMacroActionDown(int idx)
|
|||||||
|
|
||||||
void MacroEdit::MacroElseActionSelectionChanged(int idx)
|
void MacroEdit::MacroElseActionSelectionChanged(int idx)
|
||||||
{
|
{
|
||||||
SetupMacroSegmentSelection(MacroSection::ELSE_ACTIONS, idx);
|
SetupMacroSegmentSelection(SegmentType::ELSE_ACTION, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroEdit::MacroElseActionReorder(int to, int from)
|
void MacroEdit::MacroElseActionReorder(int to, int from)
|
||||||
@@ -1390,6 +1510,13 @@ void MacroEdit::AddMacroElseAction(Macro *macro, int idx, const std::string &id,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
macro->ElseActions().emplace(macro->ElseActions().begin() + idx,
|
macro->ElseActions().emplace(macro->ElseActions().begin() + idx,
|
||||||
@@ -1406,6 +1533,12 @@ void MacroEdit::AddMacroElseAction(Macro *macro, int idx, const std::string &id,
|
|||||||
new MacroActionEdit(this, ¯o->ElseActions()[idx]));
|
new MacroActionEdit(this, ¯o->ElseActions()[idx]));
|
||||||
SetElseActionData(*macro);
|
SetElseActionData(*macro);
|
||||||
}
|
}
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
} else {
|
||||||
|
RegisterSegmentAddUndoRedo(macro, SegmentType::ELSE_ACTION,
|
||||||
|
idx);
|
||||||
|
}
|
||||||
HighlightElseAction(idx);
|
HighlightElseAction(idx);
|
||||||
ui->elseActionsList->SetHelpMsgVisible(false);
|
ui->elseActionsList->SetHelpMsgVisible(false);
|
||||||
emit(MacroSegmentOrderChanged());
|
emit(MacroSegmentOrderChanged());
|
||||||
@@ -1455,6 +1588,25 @@ void MacroEdit::RemoveMacroElseAction(int idx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
} else {
|
||||||
|
OBSDataAutoRelease segData = obs_data_create();
|
||||||
|
std::string segId;
|
||||||
|
{
|
||||||
|
auto lock = LockContext();
|
||||||
|
macro->ElseActions().at(idx)->Save(segData);
|
||||||
|
segId = macro->ElseActions().at(idx)->GetId();
|
||||||
|
}
|
||||||
|
RegisterSegmentRemoveUndoRedo(macro.get(),
|
||||||
|
SegmentType::ELSE_ACTION, idx,
|
||||||
|
segId, segData,
|
||||||
|
(int)Logic::Type::ROOT_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
ui->elseActionsList->Remove(idx);
|
ui->elseActionsList->Remove(idx);
|
||||||
@@ -1464,8 +1616,11 @@ void MacroEdit::RemoveMacroElseAction(int idx)
|
|||||||
macro->UpdateElseActionIndices();
|
macro->UpdateElseActionIndices();
|
||||||
SetElseActionData(*macro);
|
SetElseActionData(*macro);
|
||||||
}
|
}
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
}
|
||||||
MacroElseActionSelectionChanged(-1);
|
MacroElseActionSelectionChanged(-1);
|
||||||
lastInteracted = MacroSection::ELSE_ACTIONS;
|
lastInteracted = SegmentType::ELSE_ACTION;
|
||||||
emit(MacroSegmentOrderChanged());
|
emit(MacroSegmentOrderChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1526,7 +1681,7 @@ void MacroEdit::MoveMacroElseActionDown(int idx)
|
|||||||
|
|
||||||
void MacroEdit::MacroActionSelectionChanged(int idx)
|
void MacroEdit::MacroActionSelectionChanged(int idx)
|
||||||
{
|
{
|
||||||
SetupMacroSegmentSelection(MacroSection::ACTIONS, idx);
|
SetupMacroSegmentSelection(SegmentType::ACTION, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroEdit::MacroActionReorder(int to, int from)
|
void MacroEdit::MacroActionReorder(int to, int from)
|
||||||
@@ -1599,6 +1754,13 @@ void MacroEdit::AddMacroCondition(Macro *macro, int idx, const std::string &id,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
auto cond = macro->Conditions().emplace(
|
auto cond = macro->Conditions().emplace(
|
||||||
@@ -1617,6 +1779,11 @@ void MacroEdit::AddMacroCondition(Macro *macro, int idx, const std::string &id,
|
|||||||
idx == 0));
|
idx == 0));
|
||||||
SetConditionData(*macro);
|
SetConditionData(*macro);
|
||||||
}
|
}
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
} else {
|
||||||
|
RegisterSegmentAddUndoRedo(macro, SegmentType::CONDITION, idx);
|
||||||
|
}
|
||||||
HighlightCondition(idx);
|
HighlightCondition(idx);
|
||||||
ui->conditionsList->SetHelpMsgVisible(false);
|
ui->conditionsList->SetHelpMsgVisible(false);
|
||||||
emit(MacroSegmentOrderChanged());
|
emit(MacroSegmentOrderChanged());
|
||||||
@@ -1652,6 +1819,26 @@ void MacroEdit::RemoveMacroCondition(int idx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||||
|
OBSDataAutoRelease parentBeforeData;
|
||||||
|
if (parentMacro) {
|
||||||
|
parentBeforeData = obs_data_create();
|
||||||
|
parentMacro->Save(parentBeforeData);
|
||||||
|
} else {
|
||||||
|
OBSDataAutoRelease segData = obs_data_create();
|
||||||
|
std::string segId;
|
||||||
|
int logic;
|
||||||
|
{
|
||||||
|
auto lock = LockContext();
|
||||||
|
macro->Conditions().at(idx)->Save(segData);
|
||||||
|
segId = macro->Conditions().at(idx)->GetId();
|
||||||
|
logic = (int)macro->Conditions().at(idx)->GetLogicType();
|
||||||
|
}
|
||||||
|
RegisterSegmentRemoveUndoRedo(macro.get(),
|
||||||
|
SegmentType::CONDITION, idx,
|
||||||
|
segId, segData, logic);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
ui->conditionsList->Remove(idx);
|
ui->conditionsList->Remove(idx);
|
||||||
@@ -1666,8 +1853,11 @@ void MacroEdit::RemoveMacroCondition(int idx)
|
|||||||
}
|
}
|
||||||
SetConditionData(*macro);
|
SetConditionData(*macro);
|
||||||
}
|
}
|
||||||
|
if (parentMacro) {
|
||||||
|
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||||
|
}
|
||||||
MacroConditionSelectionChanged(-1);
|
MacroConditionSelectionChanged(-1);
|
||||||
lastInteracted = MacroSection::CONDITIONS;
|
lastInteracted = SegmentType::CONDITION;
|
||||||
emit(MacroSegmentOrderChanged());
|
emit(MacroSegmentOrderChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1792,7 +1982,7 @@ void MacroEdit::MoveMacroConditionDown(int idx)
|
|||||||
|
|
||||||
void MacroEdit::MacroConditionSelectionChanged(int idx)
|
void MacroEdit::MacroConditionSelectionChanged(int idx)
|
||||||
{
|
{
|
||||||
SetupMacroSegmentSelection(MacroSection::CONDITIONS, idx);
|
SetupMacroSegmentSelection(SegmentType::CONDITION, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroEdit::MacroConditionReorder(int to, int from)
|
void MacroEdit::MacroConditionReorder(int to, int from)
|
||||||
|
|||||||
@@ -12,11 +12,15 @@ class MacroEdit : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum class SegmentType { CONDITION, ACTION, ELSE_ACTION };
|
||||||
|
|
||||||
MacroEdit(QWidget *parent, QStringList helpMsg = {});
|
MacroEdit(QWidget *parent, QStringList helpMsg = {});
|
||||||
void SetMacro(const std::shared_ptr<Macro> &);
|
void SetMacro(const std::shared_ptr<Macro> &);
|
||||||
std::shared_ptr<Macro> GetMacro() const;
|
std::shared_ptr<Macro> GetMacro() const;
|
||||||
void ClearSegmentWidgetCacheFor(Macro *) const;
|
void ClearSegmentWidgetCacheFor(Macro *) const;
|
||||||
void SetControlsDisabled(bool disable) const;
|
void SetControlsDisabled(bool disable) const;
|
||||||
|
void InsertSegmentWidget(SegmentType type, int idx);
|
||||||
|
void RemoveSegmentWidget(SegmentType type, int idx);
|
||||||
void HighlightAction(int idx, QColor color = QColor(Qt::green)) const;
|
void HighlightAction(int idx, QColor color = QColor(Qt::green)) const;
|
||||||
void HighlightElseAction(int idx,
|
void HighlightElseAction(int idx,
|
||||||
QColor color = QColor(Qt::green)) const;
|
QColor color = QColor(Qt::green)) const;
|
||||||
@@ -112,14 +116,12 @@ protected:
|
|||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class MacroSection { CONDITIONS, ACTIONS, ELSE_ACTIONS };
|
|
||||||
|
|
||||||
void PopulateMacroActions(Macro &m, uint32_t afterIdx = 0);
|
void PopulateMacroActions(Macro &m, uint32_t afterIdx = 0);
|
||||||
void PopulateMacroElseActions(Macro &m, uint32_t afterIdx = 0);
|
void PopulateMacroElseActions(Macro &m, uint32_t afterIdx = 0);
|
||||||
void PopulateMacroConditions(Macro &m, uint32_t afterIdx = 0);
|
void PopulateMacroConditions(Macro &m, uint32_t afterIdx = 0);
|
||||||
void ScrollAndFocusNewSegment(MacroSegmentList *list, int newIdx,
|
void ScrollAndFocusNewSegment(MacroSegmentList *list, int newIdx,
|
||||||
int *currentIdx);
|
int *currentIdx);
|
||||||
void SetupMacroSegmentSelection(MacroSection type, int idx);
|
void SetupMacroSegmentSelection(SegmentType type, int idx);
|
||||||
void
|
void
|
||||||
SetupContextMenu(const QPoint &pos,
|
SetupContextMenu(const QPoint &pos,
|
||||||
const std::function<void(MacroEdit *, int)> &remove,
|
const std::function<void(MacroEdit *, int)> &remove,
|
||||||
@@ -131,7 +133,7 @@ private:
|
|||||||
void RunSegmentHighlightChecks();
|
void RunSegmentHighlightChecks();
|
||||||
bool ElseSectionIsVisible() const;
|
bool ElseSectionIsVisible() const;
|
||||||
|
|
||||||
MacroSection lastInteracted = MacroSection::CONDITIONS;
|
SegmentType lastInteracted = SegmentType::CONDITION;
|
||||||
int currentConditionIdx = -1;
|
int currentConditionIdx = -1;
|
||||||
int currentActionIdx = -1;
|
int currentActionIdx = -1;
|
||||||
int currentElseActionIdx = -1;
|
int currentElseActionIdx = -1;
|
||||||
|
|||||||
@@ -201,6 +201,8 @@ bool MacroSegmentList::PopulateWidgetsFromCache(const Macro *macro)
|
|||||||
_contentLayout->addWidget(widget);
|
_contentLayout->addWidget(widget);
|
||||||
widget->show();
|
widget->show();
|
||||||
}
|
}
|
||||||
|
// Widgets are now owned by the layout again, so the cache entry is stale.
|
||||||
|
_widgetCache.erase(it);
|
||||||
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
@@ -463,7 +465,17 @@ void MacroSegmentList::SetupVisibleMacroSegmentWidgets()
|
|||||||
|
|
||||||
const auto viewportRect = viewport()->rect();
|
const auto viewportRect = viewport()->rect();
|
||||||
|
|
||||||
for (auto segment : widget()->findChildren<MacroSegmentEdit *>()) {
|
for (int i = 0; i < _contentLayout->count(); ++i) {
|
||||||
|
auto item = _contentLayout->itemAt(i);
|
||||||
|
if (!item) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto segment = dynamic_cast<MacroSegmentEdit *>(item->widget());
|
||||||
|
if (!segment) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const auto pos = segment->mapTo(viewport(), QPoint(0, 0));
|
const auto pos = segment->mapTo(viewport(), QPoint(0, 0));
|
||||||
const QRect rect(pos, segment->size());
|
const QRect rect(pos, segment->size());
|
||||||
if (!viewportRect.intersects(rect)) {
|
if (!viewportRect.intersects(rect)) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "macro-settings.hpp"
|
#include "macro-settings.hpp"
|
||||||
#include "layout-helpers.hpp"
|
#include "layout-helpers.hpp"
|
||||||
#include "macro-helpers.hpp"
|
|
||||||
#include "macro.hpp"
|
#include "macro.hpp"
|
||||||
#include "obs-module-helper.hpp"
|
#include "obs-module-helper.hpp"
|
||||||
#include "plugin-state-helpers.hpp"
|
#include "plugin-state-helpers.hpp"
|
||||||
@@ -9,48 +8,11 @@
|
|||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
namespace advss {
|
namespace advss {
|
||||||
|
|
||||||
static GlobalMacroSettings macroSettings;
|
static GlobalMacroSettings macroSettings;
|
||||||
|
|
||||||
static constexpr int addNewDockWindowRole = Qt::UserRole + 1;
|
|
||||||
|
|
||||||
static QStringList GetExistingDockWindowNames()
|
|
||||||
{
|
|
||||||
std::set<std::string> names;
|
|
||||||
for (const auto ¯o : GetAllMacros()) {
|
|
||||||
if (!macro) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto &dockSettings = macro->GetDockSettings();
|
|
||||||
if (dockSettings.IsStandaloneDock()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
names.insert(dockSettings.DockWindowName());
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList result;
|
|
||||||
for (const auto &name : names) {
|
|
||||||
result << QString::fromStdString(name);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void populateDockWindowNameCombo(QComboBox *combo)
|
|
||||||
{
|
|
||||||
combo->clear();
|
|
||||||
auto names = GetExistingDockWindowNames();
|
|
||||||
combo->addItems(names);
|
|
||||||
if (!names.isEmpty()) {
|
|
||||||
combo->insertSeparator(combo->count());
|
|
||||||
}
|
|
||||||
combo->addItem(obs_module_text(
|
|
||||||
"AdvSceneSwitcher.macroTab.currentDockWindowName.addNew"));
|
|
||||||
combo->setItemData(combo->count() - 1, true, addNewDockWindowRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalMacroSettings::Save(obs_data_t *obj) const
|
void GlobalMacroSettings::Save(obs_data_t *obj) const
|
||||||
{
|
{
|
||||||
auto data = obs_data_create();
|
auto data = obs_data_create();
|
||||||
@@ -134,7 +96,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
|||||||
"AdvSceneSwitcher.macroTab.currentRegisterDock"))),
|
"AdvSceneSwitcher.macroTab.currentRegisterDock"))),
|
||||||
_currentMacroIsStandaloneDock(new QCheckBox(obs_module_text(
|
_currentMacroIsStandaloneDock(new QCheckBox(obs_module_text(
|
||||||
"AdvSceneSwitcher.macroTab.currentIsStandaloneDock"))),
|
"AdvSceneSwitcher.macroTab.currentIsStandaloneDock"))),
|
||||||
_currentMacroDockWindowName(new QComboBox(this)),
|
_currentMacroDockWindowName(new QLineEdit(this)),
|
||||||
_currentMacroDockAddRunButton(new QCheckBox(obs_module_text(
|
_currentMacroDockAddRunButton(new QCheckBox(obs_module_text(
|
||||||
"AdvSceneSwitcher.macroTab.currentDockAddRunButton"))),
|
"AdvSceneSwitcher.macroTab.currentDockAddRunButton"))),
|
||||||
_currentMacroDockAddPauseButton(new QCheckBox(obs_module_text(
|
_currentMacroDockAddPauseButton(new QCheckBox(obs_module_text(
|
||||||
@@ -181,17 +143,6 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
|||||||
"AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.unpause"),
|
"AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.unpause"),
|
||||||
static_cast<int>(Macro::PauseStateSaveBehavior::UNPAUSE));
|
static_cast<int>(Macro::PauseStateSaveBehavior::UNPAUSE));
|
||||||
|
|
||||||
_currentMacroDockWindowName->setEditable(true);
|
|
||||||
populateDockWindowNameCombo(_currentMacroDockWindowName);
|
|
||||||
connect(_currentMacroDockWindowName,
|
|
||||||
qOverload<int>(&QComboBox::activated), this, [this](int index) {
|
|
||||||
if (_currentMacroDockWindowName
|
|
||||||
->itemData(index, addNewDockWindowRole)
|
|
||||||
.toBool()) {
|
|
||||||
_currentMacroDockWindowName->setCurrentText("");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
auto highlightOptions = new QGroupBox(
|
auto highlightOptions = new QGroupBox(
|
||||||
obs_module_text("AdvSceneSwitcher.macroTab.highlightSettings"));
|
obs_module_text("AdvSceneSwitcher.macroTab.highlightSettings"));
|
||||||
auto highlightLayout = new QVBoxLayout;
|
auto highlightLayout = new QVBoxLayout;
|
||||||
@@ -397,7 +348,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
|||||||
_currentMacroRegisterDock->setChecked(dockEnabled);
|
_currentMacroRegisterDock->setChecked(dockEnabled);
|
||||||
_currentMacroIsStandaloneDock->setChecked(
|
_currentMacroIsStandaloneDock->setChecked(
|
||||||
dockSettings.IsStandaloneDock());
|
dockSettings.IsStandaloneDock());
|
||||||
_currentMacroDockWindowName->setCurrentText(
|
_currentMacroDockWindowName->setText(
|
||||||
QString::fromStdString(dockSettings.DockWindowName()));
|
QString::fromStdString(dockSettings.DockWindowName()));
|
||||||
_currentMacroDockAddRunButton->setChecked(dockSettings.HasRunButton());
|
_currentMacroDockAddRunButton->setChecked(dockSettings.HasRunButton());
|
||||||
_currentMacroDockAddPauseButton->setChecked(
|
_currentMacroDockAddPauseButton->setChecked(
|
||||||
@@ -535,7 +486,7 @@ bool MacroSettingsDialog::AskForSettings(QWidget *parent,
|
|||||||
dockSettings.SetIsStandaloneDock(
|
dockSettings.SetIsStandaloneDock(
|
||||||
dialog._currentMacroIsStandaloneDock->isChecked());
|
dialog._currentMacroIsStandaloneDock->isChecked());
|
||||||
dockSettings.SetDockWindowName(
|
dockSettings.SetDockWindowName(
|
||||||
dialog._currentMacroDockWindowName->currentText().toStdString());
|
dialog._currentMacroDockWindowName->text().toStdString());
|
||||||
dockSettings.SetHasRunButton(
|
dockSettings.SetHasRunButton(
|
||||||
dialog._currentMacroDockAddRunButton->isChecked());
|
dialog._currentMacroDockAddRunButton->isChecked());
|
||||||
dockSettings.SetHasPauseButton(
|
dockSettings.SetHasPauseButton(
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
@@ -72,7 +71,7 @@ private:
|
|||||||
MacroInputSelection *_currentInputs;
|
MacroInputSelection *_currentInputs;
|
||||||
QCheckBox *_currentMacroRegisterDock;
|
QCheckBox *_currentMacroRegisterDock;
|
||||||
QCheckBox *_currentMacroIsStandaloneDock;
|
QCheckBox *_currentMacroIsStandaloneDock;
|
||||||
QComboBox *_currentMacroDockWindowName;
|
QLineEdit *_currentMacroDockWindowName;
|
||||||
QCheckBox *_currentMacroDockAddRunButton;
|
QCheckBox *_currentMacroDockAddRunButton;
|
||||||
QCheckBox *_currentMacroDockAddPauseButton;
|
QCheckBox *_currentMacroDockAddPauseButton;
|
||||||
QCheckBox *_currentMacroDockAddStatusLabel;
|
QCheckBox *_currentMacroDockAddStatusLabel;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "macro-settings.hpp"
|
#include "macro-settings.hpp"
|
||||||
#include "macro-signals.hpp"
|
#include "macro-signals.hpp"
|
||||||
#include "macro-tree.hpp"
|
#include "macro-tree.hpp"
|
||||||
|
#include "macro-undo-redo.hpp"
|
||||||
#include "macro.hpp"
|
#include "macro.hpp"
|
||||||
#include "math-helpers.hpp"
|
#include "math-helpers.hpp"
|
||||||
#include "name-dialog.hpp"
|
#include "name-dialog.hpp"
|
||||||
@@ -122,6 +123,7 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
|
|||||||
ui->macros->Add(newMacro);
|
ui->macros->Add(newMacro);
|
||||||
MacroSignalManager::Instance()->Add(
|
MacroSignalManager::Instance()->Add(
|
||||||
QString::fromStdString(name));
|
QString::fromStdString(name));
|
||||||
|
RegisterMacroAddUndoRedo(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +133,7 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
|
|||||||
ui->macros->AddToGroup(newMacro, selectedMacro);
|
ui->macros->AddToGroup(newMacro, selectedMacro);
|
||||||
MacroSignalManager::Instance()->Add(
|
MacroSignalManager::Instance()->Add(
|
||||||
QString::fromStdString(name));
|
QString::fromStdString(name));
|
||||||
|
RegisterMacroAddUndoRedo(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,12 +142,14 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
|
|||||||
ui->macros->Add(newMacro, selectedMacro);
|
ui->macros->Add(newMacro, selectedMacro);
|
||||||
MacroSignalManager::Instance()->Add(
|
MacroSignalManager::Instance()->Add(
|
||||||
QString::fromStdString(name));
|
QString::fromStdString(name));
|
||||||
|
RegisterMacroAddUndoRedo(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Macro::PrepareMoveToGroup(selectedMacroGroup, newMacro);
|
Macro::PrepareMoveToGroup(selectedMacroGroup, newMacro);
|
||||||
ui->macros->Add(newMacro, selectedMacro);
|
ui->macros->Add(newMacro, selectedMacro);
|
||||||
MacroSignalManager::Instance()->Add(QString::fromStdString(name));
|
MacroSignalManager::Instance()->Add(QString::fromStdString(name));
|
||||||
|
RegisterMacroAddUndoRedo(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addGroupSubitems(std::vector<std::shared_ptr<Macro>> ¯os,
|
static void addGroupSubitems(std::vector<std::shared_ptr<Macro>> ¯os,
|
||||||
@@ -185,6 +190,12 @@ void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> ¯o)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (macro->IsGroup()) {
|
||||||
|
RegisterGroupDeleteUndoRedo(macro.get());
|
||||||
|
} else {
|
||||||
|
RegisterMacroRemoveUndoRedo(macro.get());
|
||||||
|
}
|
||||||
|
|
||||||
if (macro->IsGroup()) {
|
if (macro->IsGroup()) {
|
||||||
std::vector<std::shared_ptr<Macro>> macros = {macro};
|
std::vector<std::shared_ptr<Macro>> macros = {macro};
|
||||||
addGroupSubitems(macros, macro);
|
addGroupSubitems(macros, macro);
|
||||||
@@ -241,13 +252,16 @@ void AdvSceneSwitcher::RemoveSelectedMacros()
|
|||||||
void AdvSceneSwitcher::RenameMacro(std::shared_ptr<Macro> ¯o,
|
void AdvSceneSwitcher::RenameMacro(std::shared_ptr<Macro> ¯o,
|
||||||
const QString &name)
|
const QString &name)
|
||||||
{
|
{
|
||||||
auto oldName = QString::fromStdString(macro->Name());
|
const std::string oldName = macro->Name();
|
||||||
|
const std::string newName = name.toStdString();
|
||||||
{
|
{
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
macro->SetName(name.toStdString());
|
macro->SetName(newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroSignalManager::Instance()->Rename(oldName, name);
|
RegisterMacroRenameUndoRedo(oldName, newName);
|
||||||
|
MacroSignalManager::Instance()->Rename(QString::fromStdString(oldName),
|
||||||
|
name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdvSceneSwitcher::on_macroRemove_clicked()
|
void AdvSceneSwitcher::on_macroRemove_clicked()
|
||||||
@@ -443,6 +457,7 @@ void AdvSceneSwitcher::ImportMacros()
|
|||||||
ui->macros->Reset(GetTopLevelMacros(),
|
ui->macros->Reset(GetTopLevelMacros(),
|
||||||
GetGlobalMacroSettings()._highlightExecuted);
|
GetGlobalMacroSettings()._highlightExecuted);
|
||||||
disableAddButtonHighlight();
|
disableAddButtonHighlight();
|
||||||
|
RegisterMacrosImportUndoRedo(importedMacros);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdvSceneSwitcher::on_macroName_editingFinished()
|
void AdvSceneSwitcher::on_macroName_editingFinished()
|
||||||
@@ -814,6 +829,7 @@ void AdvSceneSwitcher::CopyMacro()
|
|||||||
ui->macros->Add(newMacro, macro);
|
ui->macros->Add(newMacro, macro);
|
||||||
disableAddButtonHighlight();
|
disableAddButtonHighlight();
|
||||||
MacroSignalManager::Instance()->Add(QString::fromStdString(name));
|
MacroSignalManager::Instance()->Add(QString::fromStdString(name));
|
||||||
|
RegisterMacroAddUndoRedo(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdvSceneSwitcher::PauseSelectedMacros()
|
void AdvSceneSwitcher::PauseSelectedMacros()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "macro-tree.hpp"
|
#include "macro-tree.hpp"
|
||||||
|
#include "macro-undo-redo.hpp"
|
||||||
|
|
||||||
#include "macro-helpers.hpp"
|
#include "macro-helpers.hpp"
|
||||||
#include "macro-search.hpp"
|
#include "macro-search.hpp"
|
||||||
@@ -824,6 +825,8 @@ void MacroTreeModel::GroupSelectedItems(QModelIndexList &indices)
|
|||||||
|
|
||||||
Reset(_macros);
|
Reset(_macros);
|
||||||
assert(IsInValidState());
|
assert(IsInValidState());
|
||||||
|
|
||||||
|
RegisterGroupCreateUndoRedo(name.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
||||||
@@ -837,6 +840,7 @@ void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
|||||||
std::shared_ptr<Macro> item = _macros[ModelIndexToMacroIndex(
|
std::shared_ptr<Macro> item = _macros[ModelIndexToMacroIndex(
|
||||||
indices[i].row(), _macros)];
|
indices[i].row(), _macros)];
|
||||||
if (item->IsGroup()) {
|
if (item->IsGroup()) {
|
||||||
|
RegisterGroupRemoveUndoRedo(item->Name());
|
||||||
Macro::RemoveGroup(item);
|
Macro::RemoveGroup(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1338
lib/macro/macro-undo-redo.cpp
Normal file
1338
lib/macro/macro-undo-redo.cpp
Normal file
File diff suppressed because it is too large
Load Diff
35
lib/macro/macro-undo-redo.hpp
Normal file
35
lib/macro/macro-undo-redo.hpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "macro-edit.hpp"
|
||||||
|
|
||||||
|
#include <obs-data.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace advss {
|
||||||
|
|
||||||
|
class Macro;
|
||||||
|
|
||||||
|
void RegisterMacroAddUndoRedo(const std::string ¯oName);
|
||||||
|
bool RegisterMacroRemoveUndoRedo(Macro *macro);
|
||||||
|
void RegisterSegmentAddUndoRedo(Macro *macro, MacroEdit::SegmentType type,
|
||||||
|
int index);
|
||||||
|
void RegisterSegmentTypeChangeUndoRedo(Macro *macro,
|
||||||
|
MacroEdit::SegmentType type, int index,
|
||||||
|
const std::string &oldId,
|
||||||
|
obs_data_t *oldData, int oldLogic,
|
||||||
|
const std::string &newId,
|
||||||
|
obs_data_t *newData, int newLogic);
|
||||||
|
void RegisterSegmentRemoveUndoRedo(Macro *macro, MacroEdit::SegmentType type,
|
||||||
|
int index, const std::string &segmentId,
|
||||||
|
obs_data_t *segmentData, int logic);
|
||||||
|
void RegisterMacroRenameUndoRedo(const std::string &oldName,
|
||||||
|
const std::string &newName);
|
||||||
|
void RegisterGroupCreateUndoRedo(const std::string &groupName);
|
||||||
|
void RegisterGroupRemoveUndoRedo(const std::string &groupName);
|
||||||
|
void RegisterGroupDeleteUndoRedo(Macro *macro);
|
||||||
|
void RegisterMacroModifyUndoRedo(Macro *parentMacro, obs_data_t *beforeData);
|
||||||
|
void RegisterMacrosImportUndoRedo(
|
||||||
|
const std::vector<std::shared_ptr<Macro>> &importedMacros);
|
||||||
|
|
||||||
|
} // namespace advss
|
||||||
@@ -130,6 +130,13 @@ public:
|
|||||||
void SetParent(std::shared_ptr<Macro> m) { _parent = m; }
|
void SetParent(std::shared_ptr<Macro> m) { _parent = m; }
|
||||||
std::shared_ptr<Macro> Parent() const;
|
std::shared_ptr<Macro> Parent() const;
|
||||||
|
|
||||||
|
// For nested macros embedded in actions (e.g. loop, nested-macro action)
|
||||||
|
void SetNestedParentMacro(Macro *parent)
|
||||||
|
{
|
||||||
|
_nestedParentMacro = parent;
|
||||||
|
}
|
||||||
|
Macro *GetNestedParentMacro() const { return _nestedParentMacro; }
|
||||||
|
|
||||||
// Saving and loading
|
// Saving and loading
|
||||||
bool Save(obs_data_t *obj, bool saveForCopy = false) const;
|
bool Save(obs_data_t *obj, bool saveForCopy = false) const;
|
||||||
bool Load(obs_data_t *obj);
|
bool Load(obs_data_t *obj);
|
||||||
@@ -187,6 +194,7 @@ private:
|
|||||||
std::deque<std::shared_ptr<MacroAction>> _elseActions;
|
std::deque<std::shared_ptr<MacroAction>> _elseActions;
|
||||||
|
|
||||||
std::weak_ptr<Macro> _parent;
|
std::weak_ptr<Macro> _parent;
|
||||||
|
Macro *_nestedParentMacro = nullptr;
|
||||||
uint32_t _groupSize = 0;
|
uint32_t _groupSize = 0;
|
||||||
bool _isGroup = false;
|
bool _isGroup = false;
|
||||||
bool _isCollapsed = false;
|
bool _isCollapsed = false;
|
||||||
|
|||||||
@@ -420,10 +420,11 @@ static bool queueWithNameExists(const std::string &name)
|
|||||||
return !GetWeakActionQueueByName(name).expired();
|
return !GetWeakActionQueueByName(name).expired();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void signalImportedQueues(void *varsPtr)
|
||||||
signalImportedQueues(const std::vector<std::shared_ptr<Item>> &queues)
|
|
||||||
{
|
{
|
||||||
for (const auto &queue : queues) {
|
auto queues = std::unique_ptr<std::vector<std::shared_ptr<Item>>>(
|
||||||
|
static_cast<std::vector<std::shared_ptr<Item>> *>(varsPtr));
|
||||||
|
for (const auto &queue : *queues) {
|
||||||
ActionQueueSignalManager::Instance()->Add(
|
ActionQueueSignalManager::Instance()->Add(
|
||||||
QString::fromStdString(queue->Name()));
|
QString::fromStdString(queue->Name()));
|
||||||
}
|
}
|
||||||
@@ -435,7 +436,7 @@ void ImportQueues(obs_data_t *data)
|
|||||||
obs_data_get_array(data, "actionQueues");
|
obs_data_get_array(data, "actionQueues");
|
||||||
size_t count = obs_data_array_count(array);
|
size_t count = obs_data_array_count(array);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Item>> importedQueues;
|
auto importedQueues = new std::vector<std::shared_ptr<Item>>;
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||||
@@ -445,11 +446,10 @@ void ImportQueues(obs_data_t *data)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
queues.emplace_back(queue);
|
queues.emplace_back(queue);
|
||||||
importedQueues.emplace_back(queue);
|
importedQueues->emplace_back(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueUITask(
|
QueueUITask(signalImportedQueues, importedQueues);
|
||||||
[importedQueues]() { signalImportedQueues(importedQueues); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<ActionQueue> GetWeakActionQueueByName(const std::string &name)
|
std::weak_ptr<ActionQueue> GetWeakActionQueueByName(const std::string &name)
|
||||||
|
|||||||
@@ -734,10 +734,12 @@ TempVarSignalManager *TempVarSignalManager::Instance()
|
|||||||
void NotifyUIAboutTempVarChange(MacroSegment *segment)
|
void NotifyUIAboutTempVarChange(MacroSegment *segment)
|
||||||
{
|
{
|
||||||
IncrementTempVarInUseGeneration();
|
IncrementTempVarInUseGeneration();
|
||||||
QueueUITask([segment]() {
|
QueueUITask(
|
||||||
|
[](void *segment) {
|
||||||
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
||||||
|
(MacroSegment *)segment);
|
||||||
|
},
|
||||||
segment);
|
segment);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TempVarOutputMappingsWidget::TempVarOutputMappingsWidget(QWidget *parent)
|
TempVarOutputMappingsWidget::TempVarOutputMappingsWidget(QWidget *parent)
|
||||||
|
|||||||
@@ -184,9 +184,9 @@ std::string GetThemeTypeName()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueueUITaskRaw(void (*task)(void *param), void *param, bool wait)
|
void QueueUITask(void (*task)(void *param), void *param)
|
||||||
{
|
{
|
||||||
obs_queue_task(OBS_TASK_UI, task, param, wait);
|
obs_queue_task(OBS_TASK_UI, task, param, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCursorInWidgetArea(QWidget *widget)
|
bool IsCursorInWidgetArea(QWidget *widget)
|
||||||
|
|||||||
@@ -6,10 +6,7 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
class QAbstractButton;
|
class QAbstractButton;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
@@ -41,23 +38,7 @@ EXPORT void DisplayTrayMessage(const QString &title, const QString &msg,
|
|||||||
EXPORT std::string GetThemeTypeName();
|
EXPORT std::string GetThemeTypeName();
|
||||||
EXPORT QWidget *GetSettingsWindow();
|
EXPORT QWidget *GetSettingsWindow();
|
||||||
|
|
||||||
EXPORT void QueueUITaskRaw(void (*task)(void *param), void *param,
|
EXPORT void QueueUITask(void (*task)(void *param), void *param);
|
||||||
bool wait = false);
|
|
||||||
|
|
||||||
// Runs func on the main/UI thread; blocks if wait is true.
|
|
||||||
template<typename F> void QueueUITask(F &&func, bool wait = false)
|
|
||||||
{
|
|
||||||
using FnType = std::decay_t<F>;
|
|
||||||
auto *heapFunc = new FnType(std::forward<F>(func));
|
|
||||||
|
|
||||||
QueueUITaskRaw(
|
|
||||||
[](void *param) {
|
|
||||||
std::unique_ptr<FnType> fn(
|
|
||||||
static_cast<FnType *>(param));
|
|
||||||
(*fn)();
|
|
||||||
},
|
|
||||||
heapFunc, wait);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsCursorInWidgetArea(QWidget *widget);
|
bool IsCursorInWidgetArea(QWidget *widget);
|
||||||
|
|
||||||
|
|||||||
@@ -504,10 +504,11 @@ void LoadVariables(obs_data_t *obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void signalImportedVariables(void *varsPtr)
|
||||||
signalImportedVariables(const std::vector<std::shared_ptr<Item>> &vars)
|
|
||||||
{
|
{
|
||||||
for (const auto &var : vars) {
|
auto vars = std::unique_ptr<std::vector<std::shared_ptr<Item>>>(
|
||||||
|
static_cast<std::vector<std::shared_ptr<Item>> *>(varsPtr));
|
||||||
|
for (const auto &var : *vars) {
|
||||||
VariableSignalManager::Instance()->Add(
|
VariableSignalManager::Instance()->Add(
|
||||||
QString::fromStdString(var->Name()));
|
QString::fromStdString(var->Name()));
|
||||||
}
|
}
|
||||||
@@ -518,7 +519,7 @@ void ImportVariables(obs_data_t *data)
|
|||||||
OBSDataArrayAutoRelease array = obs_data_get_array(data, "variables");
|
OBSDataArrayAutoRelease array = obs_data_get_array(data, "variables");
|
||||||
size_t count = obs_data_array_count(array);
|
size_t count = obs_data_array_count(array);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Item>> importedVars;
|
auto importedVars = new std::vector<std::shared_ptr<Item>>;
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||||
@@ -530,11 +531,10 @@ void ImportVariables(obs_data_t *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetVariables().emplace_back(var);
|
GetVariables().emplace_back(var);
|
||||||
importedVars.emplace_back(var);
|
importedVars->emplace_back(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueUITask(
|
QueueUITask(signalImportedVariables, importedVars);
|
||||||
[importedVars]() { signalImportedVariables(importedVars); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime()
|
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime()
|
||||||
|
|||||||
@@ -2,64 +2,18 @@
|
|||||||
#include "audio-helpers.hpp"
|
#include "audio-helpers.hpp"
|
||||||
#include "layout-helpers.hpp"
|
#include "layout-helpers.hpp"
|
||||||
#include "macro-helpers.hpp"
|
#include "macro-helpers.hpp"
|
||||||
#include "plugin-state-helpers.hpp"
|
|
||||||
#include "sync-helpers.hpp"
|
#include "sync-helpers.hpp"
|
||||||
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <mutex>
|
|
||||||
#include <set>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
namespace advss {
|
namespace advss {
|
||||||
|
|
||||||
|
// Use a high output channel index that is unlikely to be claimed by OBS or
|
||||||
|
// other plugins. OBS supports channels 0-63; channel 0 is the main scene.
|
||||||
static constexpr uint32_t kPlaybackOutputChannel = 63;
|
static constexpr uint32_t kPlaybackOutputChannel = 63;
|
||||||
|
|
||||||
// Tracks rawSource handles held by background cleanup threads so they can be
|
|
||||||
// stopped early when OBS begins shutdown, before audio is freed.
|
|
||||||
static std::mutex g_activeSourcesMutex;
|
|
||||||
static std::set<obs_source_t *> g_activeSources;
|
|
||||||
|
|
||||||
static void registerActiveSource(obs_source_t *source)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_activeSourcesMutex);
|
|
||||||
g_activeSources.insert(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unregisterActiveSource(obs_source_t *source)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_activeSourcesMutex);
|
|
||||||
g_activeSources.erase(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void stopAllActiveSources()
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_activeSourcesMutex);
|
|
||||||
for (auto *source : g_activeSources) {
|
|
||||||
obs_source_media_stop(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handleObsEvent(enum obs_frontend_event event, void *)
|
|
||||||
{
|
|
||||||
if (event == OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN ||
|
|
||||||
event == OBS_FRONTEND_EVENT_EXIT) {
|
|
||||||
stopAllActiveSources();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool setup()
|
|
||||||
{
|
|
||||||
AddPluginPostLoadStep([]() {
|
|
||||||
obs_frontend_add_event_callback(handleObsEvent, nullptr);
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool setupDone = setup();
|
|
||||||
|
|
||||||
const std::string MacroActionPlayAudio::id = "play_audio";
|
const std::string MacroActionPlayAudio::id = "play_audio";
|
||||||
|
|
||||||
bool MacroActionPlayAudio::_registered = MacroActionFactory::Register(
|
bool MacroActionPlayAudio::_registered = MacroActionFactory::Register(
|
||||||
@@ -69,7 +23,6 @@ bool MacroActionPlayAudio::_registered = MacroActionFactory::Register(
|
|||||||
|
|
||||||
static void deactivatePlayback(obs_source_t *source, bool wantsOutput)
|
static void deactivatePlayback(obs_source_t *source, bool wantsOutput)
|
||||||
{
|
{
|
||||||
obs_source_media_stop(source);
|
|
||||||
if (wantsOutput) {
|
if (wantsOutput) {
|
||||||
obs_set_output_source(kPlaybackOutputChannel, nullptr);
|
obs_set_output_source(kPlaybackOutputChannel, nullptr);
|
||||||
} else {
|
} else {
|
||||||
@@ -85,7 +38,8 @@ static void waitForPlaybackToEnd(Macro *macro, obs_source_t *source,
|
|||||||
std::unique_lock<std::mutex> lock(*GetMutex());
|
std::unique_lock<std::mutex> lock(*GetMutex());
|
||||||
SetMacroAbortWait(false);
|
SetMacroAbortWait(false);
|
||||||
|
|
||||||
// Poll until the source starts playing or the macro is stopped.
|
// The media source needs time to open and decode before reaching
|
||||||
|
// PLAYING state. Poll until it starts (or the macro is stopped).
|
||||||
while (!MacroWaitShouldAbort() && !MacroIsStopped(macro)) {
|
while (!MacroWaitShouldAbort() && !MacroIsStopped(macro)) {
|
||||||
if (obs_source_media_get_state(source) ==
|
if (obs_source_media_get_state(source) ==
|
||||||
OBS_MEDIA_STATE_PLAYING) {
|
OBS_MEDIA_STATE_PLAYING) {
|
||||||
@@ -94,8 +48,9 @@ static void waitForPlaybackToEnd(Macro *macro, obs_source_t *source,
|
|||||||
GetMacroWaitCV().wait_for(lock, 10ms);
|
GetMacroWaitCV().wait_for(lock, 10ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for playback to end. Two consecutive non-playing samples are
|
// Now wait for playback to end. Require two consecutive non-playing
|
||||||
// required to avoid false positives on brief state transitions.
|
// samples to avoid false positives on brief state transitions.
|
||||||
|
// If maxMs > 0, also stop once that many milliseconds have elapsed.
|
||||||
const auto playbackStart = std::chrono::steady_clock::now();
|
const auto playbackStart = std::chrono::steady_clock::now();
|
||||||
static const int kStopThreshold = 2;
|
static const int kStopThreshold = 2;
|
||||||
int stoppedCount = 0;
|
int stoppedCount = 0;
|
||||||
@@ -140,6 +95,7 @@ bool MacroActionPlayAudio::PerformAction()
|
|||||||
obs_data_set_string(settings, "local_file", path.c_str());
|
obs_data_set_string(settings, "local_file", path.c_str());
|
||||||
obs_data_set_bool(settings, "is_local_file", true);
|
obs_data_set_bool(settings, "is_local_file", true);
|
||||||
obs_data_set_bool(settings, "looping", false);
|
obs_data_set_bool(settings, "looping", false);
|
||||||
|
// Disable automatic restart on activate so we control start explicitly.
|
||||||
obs_data_set_bool(settings, "restart_on_activate", false);
|
obs_data_set_bool(settings, "restart_on_activate", false);
|
||||||
obs_data_set_bool(settings, "close_when_inactive", true);
|
obs_data_set_bool(settings, "close_when_inactive", true);
|
||||||
|
|
||||||
@@ -157,11 +113,10 @@ bool MacroActionPlayAudio::PerformAction()
|
|||||||
DecibelToPercent(static_cast<float>(_volumeDB.GetValue()));
|
DecibelToPercent(static_cast<float>(_volumeDB.GetValue()));
|
||||||
obs_source_set_volume(source, vol);
|
obs_source_set_volume(source, vol);
|
||||||
obs_source_set_monitoring_type(source, _monitorType);
|
obs_source_set_monitoring_type(source, _monitorType);
|
||||||
if (_mono) {
|
|
||||||
obs_source_set_flags(source, OBS_SOURCE_FLAG_FORCE_MONO);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back to monitor-only if all output tracks are deselected.
|
// Fall back to monitor-only if all output tracks are deselected —
|
||||||
|
// there is no point routing through the output channel if the mixer
|
||||||
|
// mask would silence every track.
|
||||||
const bool wantsOutput =
|
const bool wantsOutput =
|
||||||
(_monitorType != OBS_MONITORING_TYPE_MONITOR_ONLY) &&
|
(_monitorType != OBS_MONITORING_TYPE_MONITOR_ONLY) &&
|
||||||
(_audioMixers != 0);
|
(_audioMixers != 0);
|
||||||
@@ -173,8 +128,10 @@ bool MacroActionPlayAudio::PerformAction()
|
|||||||
|
|
||||||
if (wantsOutput) {
|
if (wantsOutput) {
|
||||||
obs_source_set_audio_mixers(source, _audioMixers);
|
obs_source_set_audio_mixers(source, _audioMixers);
|
||||||
// Route through a private scene positioned off-screen so the
|
// Route through a private scene so we can position the scene
|
||||||
// audio mixes into the output without video appearing on screen.
|
// item far off-screen. This keeps the item "visible" (so audio
|
||||||
|
// is still mixed) while ensuring its video never intersects the
|
||||||
|
// output frame.
|
||||||
OBSSceneAutoRelease audioScene =
|
OBSSceneAutoRelease audioScene =
|
||||||
obs_scene_create_private("advss_audio_scene");
|
obs_scene_create_private("advss_audio_scene");
|
||||||
obs_sceneitem_t *item = obs_scene_add(audioScene, source);
|
obs_sceneitem_t *item = obs_scene_add(audioScene, source);
|
||||||
@@ -184,7 +141,8 @@ bool MacroActionPlayAudio::PerformAction()
|
|||||||
}
|
}
|
||||||
obs_set_output_source(kPlaybackOutputChannel,
|
obs_set_output_source(kPlaybackOutputChannel,
|
||||||
obs_scene_get_source(audioScene));
|
obs_scene_get_source(audioScene));
|
||||||
// audioScene is released here; the output channel keeps the scene alive.
|
// audioScene released here; the output channel holds the
|
||||||
|
// remaining reference and keeps the scene alive.
|
||||||
} else {
|
} else {
|
||||||
obs_source_set_audio_mixers(source, 0);
|
obs_source_set_audio_mixers(source, 0);
|
||||||
obs_source_inc_active(source);
|
obs_source_inc_active(source);
|
||||||
@@ -209,15 +167,15 @@ bool MacroActionPlayAudio::PerformAction()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep the source alive until playback ends via a background thread.
|
// Keep the source alive in a background thread that cleans up
|
||||||
|
// once playback finishes. Grab an extra strong reference so the
|
||||||
|
// source survives beyond this stack frame.
|
||||||
auto rawSource = obs_source_get_ref(source);
|
auto rawSource = obs_source_get_ref(source);
|
||||||
registerActiveSource(rawSource);
|
|
||||||
auto macro = GetMacro();
|
auto macro = GetMacro();
|
||||||
|
|
||||||
std::thread cleanupThread([rawSource, wantsOutput, macro, maxMs]() {
|
std::thread cleanupThread([rawSource, wantsOutput, macro, maxMs]() {
|
||||||
waitForPlaybackToEnd(macro, rawSource, maxMs);
|
waitForPlaybackToEnd(macro, rawSource, maxMs);
|
||||||
deactivatePlayback(rawSource, wantsOutput);
|
deactivatePlayback(rawSource, wantsOutput);
|
||||||
unregisterActiveSource(rawSource);
|
|
||||||
obs_source_release(rawSource);
|
obs_source_release(rawSource);
|
||||||
});
|
});
|
||||||
AddMacroHelperThread(macro, std::move(cleanupThread));
|
AddMacroHelperThread(macro, std::move(cleanupThread));
|
||||||
@@ -246,7 +204,6 @@ bool MacroActionPlayAudio::Save(obs_data_t *obj) const
|
|||||||
obs_data_set_bool(obj, "useDuration", _useDuration);
|
obs_data_set_bool(obj, "useDuration", _useDuration);
|
||||||
_playbackDuration.Save(obj, "playbackDuration");
|
_playbackDuration.Save(obj, "playbackDuration");
|
||||||
obs_data_set_bool(obj, "waitForCompletion", _waitForCompletion);
|
obs_data_set_bool(obj, "waitForCompletion", _waitForCompletion);
|
||||||
obs_data_set_bool(obj, "mono", _mono);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +221,6 @@ bool MacroActionPlayAudio::Load(obs_data_t *obj)
|
|||||||
_useDuration = obs_data_get_bool(obj, "useDuration");
|
_useDuration = obs_data_get_bool(obj, "useDuration");
|
||||||
_playbackDuration.Load(obj, "playbackDuration");
|
_playbackDuration.Load(obj, "playbackDuration");
|
||||||
_waitForCompletion = obs_data_get_bool(obj, "waitForCompletion");
|
_waitForCompletion = obs_data_get_bool(obj, "waitForCompletion");
|
||||||
_mono = obs_data_get_bool(obj, "mono");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,9 +262,7 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
|||||||
_useDuration(new QCheckBox(this)),
|
_useDuration(new QCheckBox(this)),
|
||||||
_playbackDuration(new DurationSelection(this, true, 0.0)),
|
_playbackDuration(new DurationSelection(this, true, 0.0)),
|
||||||
_waitForCompletion(new QCheckBox(
|
_waitForCompletion(new QCheckBox(
|
||||||
obs_module_text("AdvSceneSwitcher.action.playAudio.wait"))),
|
obs_module_text("AdvSceneSwitcher.action.playAudio.wait")))
|
||||||
_mono(new QCheckBox(
|
|
||||||
obs_module_text("AdvSceneSwitcher.action.playAudio.mono")))
|
|
||||||
{
|
{
|
||||||
_volumeDB->setMinimum(-100.0);
|
_volumeDB->setMinimum(-100.0);
|
||||||
_volumeDB->setMaximum(0.0);
|
_volumeDB->setMaximum(0.0);
|
||||||
@@ -349,8 +303,6 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
|||||||
SLOT(PlaybackDurationChanged(const Duration &)));
|
SLOT(PlaybackDurationChanged(const Duration &)));
|
||||||
QWidget::connect(_waitForCompletion, SIGNAL(stateChanged(int)), this,
|
QWidget::connect(_waitForCompletion, SIGNAL(stateChanged(int)), this,
|
||||||
SLOT(WaitChanged(int)));
|
SLOT(WaitChanged(int)));
|
||||||
QWidget::connect(_mono, SIGNAL(stateChanged(int)), this,
|
|
||||||
SLOT(MonoChanged(int)));
|
|
||||||
|
|
||||||
auto tracksLayout = new QHBoxLayout;
|
auto tracksLayout = new QHBoxLayout;
|
||||||
tracksLayout->setContentsMargins(0, 0, 0, 0);
|
tracksLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
@@ -394,7 +346,6 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
|||||||
mainLayout->addLayout(startOffsetLayout);
|
mainLayout->addLayout(startOffsetLayout);
|
||||||
mainLayout->addLayout(playbackDurationLayout);
|
mainLayout->addLayout(playbackDurationLayout);
|
||||||
mainLayout->addWidget(_waitForCompletion);
|
mainLayout->addWidget(_waitForCompletion);
|
||||||
mainLayout->addWidget(_mono);
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
_entryData = entryData;
|
_entryData = entryData;
|
||||||
@@ -424,7 +375,6 @@ void MacroActionPlayAudioEdit::UpdateEntryData()
|
|||||||
_playbackDuration->SetDuration(_entryData->_playbackDuration);
|
_playbackDuration->SetDuration(_entryData->_playbackDuration);
|
||||||
_playbackDuration->setEnabled(_entryData->_useDuration);
|
_playbackDuration->setEnabled(_entryData->_useDuration);
|
||||||
_waitForCompletion->setChecked(_entryData->_waitForCompletion);
|
_waitForCompletion->setChecked(_entryData->_waitForCompletion);
|
||||||
_mono->setChecked(_entryData->_mono);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroActionPlayAudioEdit::FilePathChanged(const QString &path)
|
void MacroActionPlayAudioEdit::FilePathChanged(const QString &path)
|
||||||
@@ -493,10 +443,4 @@ void MacroActionPlayAudioEdit::WaitChanged(int value)
|
|||||||
_entryData->_waitForCompletion = value;
|
_entryData->_waitForCompletion = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroActionPlayAudioEdit::MonoChanged(int value)
|
|
||||||
{
|
|
||||||
GUARD_LOADING_AND_LOCK();
|
|
||||||
_entryData->_mono = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace advss
|
} // namespace advss
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ public:
|
|||||||
bool _useDuration = false;
|
bool _useDuration = false;
|
||||||
Duration _playbackDuration;
|
Duration _playbackDuration;
|
||||||
bool _waitForCompletion = false;
|
bool _waitForCompletion = false;
|
||||||
bool _mono = false;
|
|
||||||
|
|
||||||
static bool _registered;
|
static bool _registered;
|
||||||
static const std::string id;
|
static const std::string id;
|
||||||
@@ -69,7 +68,6 @@ private slots:
|
|||||||
void UseDurationChanged(int);
|
void UseDurationChanged(int);
|
||||||
void PlaybackDurationChanged(const Duration &);
|
void PlaybackDurationChanged(const Duration &);
|
||||||
void WaitChanged(int value);
|
void WaitChanged(int value);
|
||||||
void MonoChanged(int value);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void HeaderInfoChanged(const QString &);
|
void HeaderInfoChanged(const QString &);
|
||||||
@@ -85,7 +83,6 @@ private:
|
|||||||
QCheckBox *_useDuration;
|
QCheckBox *_useDuration;
|
||||||
DurationSelection *_playbackDuration;
|
DurationSelection *_playbackDuration;
|
||||||
QCheckBox *_waitForCompletion;
|
QCheckBox *_waitForCompletion;
|
||||||
QCheckBox *_mono;
|
|
||||||
|
|
||||||
std::shared_ptr<MacroActionPlayAudio> _entryData;
|
std::shared_ptr<MacroActionPlayAudio> _entryData;
|
||||||
bool _loading = true;
|
bool _loading = true;
|
||||||
|
|||||||
@@ -17,6 +17,20 @@ bool MacroActionSceneCollection::_registered = MacroActionFactory::Register(
|
|||||||
MacroActionSceneCollectionEdit::Create,
|
MacroActionSceneCollectionEdit::Create,
|
||||||
"AdvSceneSwitcher.action.sceneCollection"});
|
"AdvSceneSwitcher.action.sceneCollection"});
|
||||||
|
|
||||||
|
template<typename F> void QueueUITaskLambda(F &&func)
|
||||||
|
{
|
||||||
|
using FnType = std::decay_t<F>;
|
||||||
|
auto *heapFunc = new FnType(std::forward<F>(func));
|
||||||
|
|
||||||
|
QueueUITask(
|
||||||
|
[](void *param) {
|
||||||
|
std::unique_ptr<FnType> fn(
|
||||||
|
static_cast<FnType *>(param));
|
||||||
|
(*fn)();
|
||||||
|
},
|
||||||
|
heapFunc);
|
||||||
|
}
|
||||||
|
|
||||||
bool MacroActionSceneCollection::PerformAction()
|
bool MacroActionSceneCollection::PerformAction()
|
||||||
{
|
{
|
||||||
// Changing the scene collection will also reload the settings of the
|
// Changing the scene collection will also reload the settings of the
|
||||||
@@ -27,7 +41,7 @@ bool MacroActionSceneCollection::PerformAction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto collectionName = _sceneCollection;
|
const auto collectionName = _sceneCollection;
|
||||||
QueueUITask([collectionName]() {
|
QueueUITaskLambda([collectionName]() {
|
||||||
obs_frontend_set_current_scene_collection(
|
obs_frontend_set_current_scene_collection(
|
||||||
collectionName.c_str());
|
collectionName.c_str());
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -185,6 +185,20 @@ static void closeSourceDialog(obs_source_t *source, bool accept,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F> void QueueUITaskLambda(F &&func)
|
||||||
|
{
|
||||||
|
using FnType = std::decay_t<F>;
|
||||||
|
auto *heapFunc = new FnType(std::forward<F>(func));
|
||||||
|
|
||||||
|
QueueUITask(
|
||||||
|
[](void *param) {
|
||||||
|
std::unique_ptr<FnType> fn(
|
||||||
|
static_cast<FnType *>(param));
|
||||||
|
(*fn)();
|
||||||
|
},
|
||||||
|
heapFunc);
|
||||||
|
}
|
||||||
|
|
||||||
bool MacroActionSource::PerformAction()
|
bool MacroActionSource::PerformAction()
|
||||||
{
|
{
|
||||||
OBSSource s = obs_weak_source_get_source(_source.GetSource());
|
OBSSource s = obs_weak_source_get_source(_source.GetSource());
|
||||||
@@ -257,17 +271,17 @@ bool MacroActionSource::PerformAction()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueUITask([&]() {
|
QueueUITaskLambda([&]() {
|
||||||
closeSourceDialog(s, true, "OBSBasicInteraction");
|
closeSourceDialog(s, true, "OBSBasicInteraction");
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case Action::CLOSE_FILTER_DIALOG:
|
case Action::CLOSE_FILTER_DIALOG:
|
||||||
QueueUITask([&]() {
|
QueueUITaskLambda([&]() {
|
||||||
closeSourceDialog(s, _acceptDialog, "OBSBasicFilters");
|
closeSourceDialog(s, _acceptDialog, "OBSBasicFilters");
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case Action::CLOSE_PROPERTIES_DIALOG:
|
case Action::CLOSE_PROPERTIES_DIALOG:
|
||||||
QueueUITask([&]() {
|
QueueUITaskLambda([&]() {
|
||||||
closeSourceDialog(s, _acceptDialog,
|
closeSourceDialog(s, _acceptDialog,
|
||||||
"OBSBasicProperties");
|
"OBSBasicProperties");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,74 +5,8 @@
|
|||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <spawn.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <poll.h>
|
|
||||||
#include <csignal>
|
|
||||||
#include <cerrno>
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
extern char **environ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace advss {
|
namespace advss {
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
// QProcess uses fork(), which is unsafe to call in OBS's multi-threaded,
|
|
||||||
// CEF/XPC-using process (see fork(2)). posix_spawn() avoids fork() entirely.
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
std::vector<char *> BuildArgv(const std::string &path, const QStringList &args,
|
|
||||||
std::vector<std::string> &storage)
|
|
||||||
{
|
|
||||||
storage.push_back(path);
|
|
||||||
for (auto &arg : args) {
|
|
||||||
storage.push_back(arg.toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<char *> argv;
|
|
||||||
argv.reserve(storage.size() + 1);
|
|
||||||
for (auto &arg : storage) {
|
|
||||||
argv.push_back(const_cast<char *>(arg.c_str()));
|
|
||||||
}
|
|
||||||
argv.push_back(nullptr);
|
|
||||||
return argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DrainPipe(int fd, std::string &buffer)
|
|
||||||
{
|
|
||||||
char chunk[4096];
|
|
||||||
while (true) {
|
|
||||||
ssize_t n = read(fd, chunk, sizeof(chunk));
|
|
||||||
if (n > 0) {
|
|
||||||
buffer.append(chunk, static_cast<size_t>(n));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (n == 0) {
|
|
||||||
return false; // EOF
|
|
||||||
}
|
|
||||||
if (errno == EINTR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return true; // EAGAIN/EWOULDBLOCK
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string TrimTrailingNewline(const std::string &s)
|
|
||||||
{
|
|
||||||
static const QRegularExpression regex("(\\r\\n|\\r|\\n)$");
|
|
||||||
return QString::fromStdString(s).remove(regex).toStdString();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool ProcessConfig::Save(obs_data_t *obj) const
|
bool ProcessConfig::Save(obs_data_t *obj) const
|
||||||
{
|
{
|
||||||
auto data = obs_data_create();
|
auto data = obs_data_create();
|
||||||
@@ -116,44 +50,11 @@ QStringList ProcessConfig::Args() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
bool ProcessConfig::StartProcessDetached() const
|
|
||||||
{
|
|
||||||
auto path = Path();
|
|
||||||
auto workDir = WorkingDir();
|
|
||||||
std::vector<std::string> argStorage;
|
|
||||||
auto argv = BuildArgv(path, Args(), argStorage);
|
|
||||||
|
|
||||||
posix_spawn_file_actions_t actions;
|
|
||||||
posix_spawn_file_actions_init(&actions);
|
|
||||||
if (!workDir.empty()) {
|
|
||||||
posix_spawn_file_actions_addchdir_np(&actions, workDir.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_t pid = 0;
|
|
||||||
int rc = posix_spawn(&pid, path.c_str(), &actions, nullptr, argv.data(),
|
|
||||||
environ);
|
|
||||||
posix_spawn_file_actions_destroy(&actions);
|
|
||||||
|
|
||||||
if (rc != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::thread([pid]() {
|
|
||||||
int status = 0;
|
|
||||||
while (waitpid(pid, &status, 0) == -1 && errno == EINTR) {
|
|
||||||
}
|
|
||||||
}).detach();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
bool ProcessConfig::StartProcessDetached() const
|
bool ProcessConfig::StartProcessDetached() const
|
||||||
{
|
{
|
||||||
return QProcess::startDetached(QString::fromStdString(Path()), Args(),
|
return QProcess::startDetached(QString::fromStdString(Path()), Args(),
|
||||||
QString::fromStdString(WorkingDir()));
|
QString::fromStdString(WorkingDir()));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void ProcessConfig::ResolveVariables()
|
void ProcessConfig::ResolveVariables()
|
||||||
{
|
{
|
||||||
@@ -162,139 +63,6 @@ void ProcessConfig::ResolveVariables()
|
|||||||
_args.ResolveVariables();
|
_args.ResolveVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
std::variant<int, ProcessConfig::ProcStartError>
|
|
||||||
ProcessConfig::StartProcessAndWait(int timeout)
|
|
||||||
{
|
|
||||||
ResetFinishedProcessData();
|
|
||||||
|
|
||||||
vblog(LOG_INFO, "run \"%s\" with a timeout of %d ms", Path().c_str(),
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
int outPipe[2];
|
|
||||||
int errPipe[2];
|
|
||||||
if (pipe(outPipe) != 0 || pipe(errPipe) != 0) {
|
|
||||||
vblog(LOG_INFO, "failed to start \"%s\"!", Path().c_str());
|
|
||||||
return ProcStartError::FAILED_TO_START;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto path = Path();
|
|
||||||
auto workDir = WorkingDir();
|
|
||||||
std::vector<std::string> argStorage;
|
|
||||||
auto argv = BuildArgv(path, Args(), argStorage);
|
|
||||||
|
|
||||||
posix_spawn_file_actions_t actions;
|
|
||||||
posix_spawn_file_actions_init(&actions);
|
|
||||||
posix_spawn_file_actions_addclose(&actions, outPipe[0]);
|
|
||||||
posix_spawn_file_actions_addclose(&actions, errPipe[0]);
|
|
||||||
posix_spawn_file_actions_adddup2(&actions, outPipe[1], STDOUT_FILENO);
|
|
||||||
posix_spawn_file_actions_adddup2(&actions, errPipe[1], STDERR_FILENO);
|
|
||||||
posix_spawn_file_actions_addclose(&actions, outPipe[1]);
|
|
||||||
posix_spawn_file_actions_addclose(&actions, errPipe[1]);
|
|
||||||
if (!workDir.empty()) {
|
|
||||||
posix_spawn_file_actions_addchdir_np(&actions, workDir.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_t pid = 0;
|
|
||||||
int rc = posix_spawn(&pid, path.c_str(), &actions, nullptr, argv.data(),
|
|
||||||
environ);
|
|
||||||
posix_spawn_file_actions_destroy(&actions);
|
|
||||||
close(outPipe[1]);
|
|
||||||
close(errPipe[1]);
|
|
||||||
|
|
||||||
if (rc != 0) {
|
|
||||||
close(outPipe[0]);
|
|
||||||
close(errPipe[0]);
|
|
||||||
vblog(LOG_INFO, "failed to start \"%s\"!", Path().c_str());
|
|
||||||
return ProcStartError::FAILED_TO_START;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetProcessId(std::to_string(pid));
|
|
||||||
fcntl(outPipe[0], F_SETFL, O_NONBLOCK);
|
|
||||||
fcntl(errPipe[0], F_SETFL, O_NONBLOCK);
|
|
||||||
|
|
||||||
std::string outBuf;
|
|
||||||
std::string errBuf;
|
|
||||||
bool outDone = false;
|
|
||||||
bool errDone = false;
|
|
||||||
auto deadline = std::chrono::steady_clock::now() +
|
|
||||||
std::chrono::milliseconds(timeout);
|
|
||||||
|
|
||||||
while (!outDone || !errDone) {
|
|
||||||
auto remaining =
|
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
deadline - std::chrono::steady_clock::now())
|
|
||||||
.count();
|
|
||||||
if (remaining <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct pollfd fds[2];
|
|
||||||
int n = 0;
|
|
||||||
int outIdx = -1;
|
|
||||||
int errIdx = -1;
|
|
||||||
if (!outDone) {
|
|
||||||
fds[n] = {outPipe[0], POLLIN, 0};
|
|
||||||
outIdx = n++;
|
|
||||||
}
|
|
||||||
if (!errDone) {
|
|
||||||
fds[n] = {errPipe[0], POLLIN, 0};
|
|
||||||
errIdx = n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pr = poll(fds, n, static_cast<int>(remaining));
|
|
||||||
if (pr < 0) {
|
|
||||||
if (errno == EINTR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outIdx >= 0 && fds[outIdx].revents != 0) {
|
|
||||||
if (!DrainPipe(outPipe[0], outBuf)) {
|
|
||||||
outDone = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (errIdx >= 0 && fds[errIdx].revents != 0) {
|
|
||||||
if (!DrainPipe(errPipe[0], errBuf)) {
|
|
||||||
errDone = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(outPipe[0]);
|
|
||||||
close(errPipe[0]);
|
|
||||||
|
|
||||||
if (!outDone || !errDone) {
|
|
||||||
vblog(LOG_INFO,
|
|
||||||
"timeout while running \"%s\"\nAttempting to kill process!",
|
|
||||||
Path().c_str());
|
|
||||||
kill(pid, SIGKILL);
|
|
||||||
int status = 0;
|
|
||||||
while (waitpid(pid, &status, 0) == -1 && errno == EINTR) {
|
|
||||||
}
|
|
||||||
_processOutputStream = TrimTrailingNewline(outBuf);
|
|
||||||
_processErrorStream = TrimTrailingNewline(errBuf);
|
|
||||||
return ProcStartError::TIMEOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = 0;
|
|
||||||
while (waitpid(pid, &status, 0) == -1 && errno == EINTR) {
|
|
||||||
}
|
|
||||||
|
|
||||||
_processOutputStream = TrimTrailingNewline(outBuf);
|
|
||||||
_processErrorStream = TrimTrailingNewline(errBuf);
|
|
||||||
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
int exitCode = WEXITSTATUS(status);
|
|
||||||
_processExitCode = std::to_string(exitCode);
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
vblog(LOG_INFO, "process \"%s\" crashed!", Path().c_str());
|
|
||||||
return ProcStartError::CRASH;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
std::variant<int, ProcessConfig::ProcStartError>
|
std::variant<int, ProcessConfig::ProcStartError>
|
||||||
ProcessConfig::StartProcessAndWait(int timeout)
|
ProcessConfig::StartProcessAndWait(int timeout)
|
||||||
{
|
{
|
||||||
@@ -333,7 +101,6 @@ ProcessConfig::StartProcessAndWait(int timeout)
|
|||||||
vblog(LOG_INFO, "process \"%s\" crashed!", Path().c_str());
|
vblog(LOG_INFO, "process \"%s\" crashed!", Path().c_str());
|
||||||
return ProcStartError::CRASH;
|
return ProcStartError::CRASH;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void ProcessConfig::SetFinishedProcessData(QProcess &process)
|
void ProcessConfig::SetFinishedProcessData(QProcess &process)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,9 +31,14 @@ static bool setup()
|
|||||||
static const auto showInvalidWarnings = [](void *) {
|
static const auto showInvalidWarnings = [](void *) {
|
||||||
const auto invalidTokens = getInvalidTokens();
|
const auto invalidTokens = getInvalidTokens();
|
||||||
for (const auto &token : invalidTokens) {
|
for (const auto &token : invalidTokens) {
|
||||||
QueueUITask([token]() {
|
QueueUITask(
|
||||||
InvalidTokenDialog::ShowWarning(token);
|
[](void *tokenPtr) {
|
||||||
});
|
auto tokenName = static_cast<QString *>(
|
||||||
|
tokenPtr);
|
||||||
|
InvalidTokenDialog::ShowWarning(
|
||||||
|
*tokenName);
|
||||||
|
},
|
||||||
|
(void *)&token);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,9 @@ void MacroEdit::HighlightControls() const {}
|
|||||||
void MacroEdit::PopulateMacroActions(Macro &, uint32_t) {}
|
void MacroEdit::PopulateMacroActions(Macro &, uint32_t) {}
|
||||||
void MacroEdit::PopulateMacroElseActions(Macro &, uint32_t) {}
|
void MacroEdit::PopulateMacroElseActions(Macro &, uint32_t) {}
|
||||||
void MacroEdit::PopulateMacroConditions(Macro &, uint32_t) {}
|
void MacroEdit::PopulateMacroConditions(Macro &, uint32_t) {}
|
||||||
void MacroEdit::SetupMacroSegmentSelection(MacroSection, int) {}
|
void MacroEdit::InsertSegmentWidget(SegmentType, int) {}
|
||||||
|
void MacroEdit::RemoveSegmentWidget(SegmentType, int) {}
|
||||||
|
void MacroEdit::SetupMacroSegmentSelection(SegmentType, int) {}
|
||||||
void MacroEdit::SetupContextMenu(const QPoint &,
|
void MacroEdit::SetupContextMenu(const QPoint &,
|
||||||
const std::function<void(MacroEdit *, int)> &,
|
const std::function<void(MacroEdit *, int)> &,
|
||||||
const std::function<void(MacroEdit *)> &,
|
const std::function<void(MacroEdit *)> &,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ std::string GetThemeTypeName()
|
|||||||
return "Dark";
|
return "Dark";
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueueUITaskRaw(void (*task)(void *param), void *, bool) {}
|
void QueueUITask(void (*task)(void *param), void *) {}
|
||||||
|
|
||||||
QWidget *GetSettingsWindow()
|
QWidget *GetSettingsWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user