mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Rework MacroRef
This should resolve issues of macro names / selections not properly updating after renaming / grouping / un-grouping macros
This commit is contained in:
parent
9a4abd78ed
commit
e66d0bc6b8
|
|
@ -21,27 +21,28 @@ const static std::map<PerformMacroAction, std::string> actionTypes = {
|
|||
|
||||
bool MacroActionMacro::PerformAction()
|
||||
{
|
||||
if (!_macro.get()) {
|
||||
auto macro = _macro.GetMacro();
|
||||
if (!macro) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (_action) {
|
||||
case PerformMacroAction::PAUSE:
|
||||
_macro->SetPaused();
|
||||
macro->SetPaused();
|
||||
break;
|
||||
case PerformMacroAction::UNPAUSE:
|
||||
_macro->SetPaused(false);
|
||||
macro->SetPaused(false);
|
||||
break;
|
||||
case PerformMacroAction::RESET_COUNTER:
|
||||
_macro->ResetRunCount();
|
||||
macro->ResetRunCount();
|
||||
break;
|
||||
case PerformMacroAction::RUN:
|
||||
if (!_macro->Paused()) {
|
||||
_macro->PerformActions();
|
||||
if (!macro->Paused()) {
|
||||
macro->PerformActions();
|
||||
}
|
||||
break;
|
||||
case PerformMacroAction::STOP:
|
||||
_macro->Stop();
|
||||
macro->Stop();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -51,26 +52,27 @@ bool MacroActionMacro::PerformAction()
|
|||
|
||||
void MacroActionMacro::LogAction() const
|
||||
{
|
||||
if (!_macro.get()) {
|
||||
auto macro = _macro.GetMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
switch (_action) {
|
||||
case PerformMacroAction::PAUSE:
|
||||
vblog(LOG_INFO, "paused \"%s\"", _macro->Name().c_str());
|
||||
vblog(LOG_INFO, "paused \"%s\"", macro->Name().c_str());
|
||||
break;
|
||||
case PerformMacroAction::UNPAUSE:
|
||||
vblog(LOG_INFO, "unpaused \"%s\"", _macro->Name().c_str());
|
||||
vblog(LOG_INFO, "unpaused \"%s\"", macro->Name().c_str());
|
||||
break;
|
||||
case PerformMacroAction::RESET_COUNTER:
|
||||
vblog(LOG_INFO, "reset counter for \"%s\"",
|
||||
_macro->Name().c_str());
|
||||
macro->Name().c_str());
|
||||
break;
|
||||
case PerformMacroAction::RUN:
|
||||
vblog(LOG_INFO, "run nested macro \"%s\"",
|
||||
_macro->Name().c_str());
|
||||
macro->Name().c_str());
|
||||
break;
|
||||
case PerformMacroAction::STOP:
|
||||
vblog(LOG_INFO, "stopped macro \"%s\"", _macro->Name().c_str());
|
||||
vblog(LOG_INFO, "stopped macro \"%s\"", macro->Name().c_str());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -96,10 +98,7 @@ bool MacroActionMacro::Load(obs_data_t *obj)
|
|||
|
||||
std::string MacroActionMacro::GetShortDesc() const
|
||||
{
|
||||
if (_macro.get()) {
|
||||
return _macro->Name();
|
||||
}
|
||||
return "";
|
||||
return _macro.Name();
|
||||
}
|
||||
|
||||
static inline void populateActionSelection(QComboBox *list)
|
||||
|
|
@ -120,8 +119,6 @@ MacroActionMacroEdit::MacroActionMacroEdit(
|
|||
|
||||
QWidget::connect(_macros, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(MacroChanged(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SLOT(MacroRemove(const QString &)));
|
||||
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(ActionChanged(int)));
|
||||
|
||||
|
|
@ -145,7 +142,7 @@ void MacroActionMacroEdit::UpdateEntryData()
|
|||
return;
|
||||
}
|
||||
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
|
||||
_macros->SetCurrentMacro(_entryData->_macro.get());
|
||||
_macros->SetCurrentMacro(_entryData->_macro);
|
||||
if (_entryData->_action == PerformMacroAction::RUN ||
|
||||
_entryData->_action == PerformMacroAction::STOP) {
|
||||
_macros->HideSelectedMacro();
|
||||
|
|
@ -159,7 +156,7 @@ void MacroActionMacroEdit::MacroChanged(const QString &text)
|
|||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_macro.UpdateRef(text);
|
||||
_entryData->_macro = text;
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
|
|
@ -180,10 +177,3 @@ void MacroActionMacroEdit::ActionChanged(int value)
|
|||
_macros->ShowAllMacros();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionMacroEdit::MacroRemove(const QString &)
|
||||
{
|
||||
if (_entryData) {
|
||||
_entryData->_macro.UpdateRef();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ public:
|
|||
|
||||
private slots:
|
||||
void MacroChanged(const QString &text);
|
||||
void MacroRemove(const QString &name);
|
||||
void ActionChanged(int value);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
|
|
|||
|
|
@ -11,22 +11,30 @@ bool MacroActionRandom::_registered = MacroActionFactory::Register(
|
|||
{MacroActionRandom::Create, MacroActionRandomEdit::Create,
|
||||
"AdvSceneSwitcher.action.random"});
|
||||
|
||||
std::vector<MacroRef> getNextMacros(std::vector<MacroRef> ¯os,
|
||||
MacroRef &lastRandomMacro, bool allowRepeat)
|
||||
static bool validNextMacro(const std::shared_ptr<Macro> ¯o)
|
||||
{
|
||||
std::vector<MacroRef> res;
|
||||
return macro && !macro->Paused();
|
||||
}
|
||||
|
||||
static std::vector<std::shared_ptr<Macro>>
|
||||
getNextMacros(std::vector<MacroRef> ¯os, MacroRef &lastRandomMacroRef,
|
||||
bool allowRepeat)
|
||||
{
|
||||
std::vector<std::shared_ptr<Macro>> res;
|
||||
if (macros.size() == 1) {
|
||||
if (!macros[0].get() || macros[0]->Paused()) {
|
||||
return res;
|
||||
} else {
|
||||
return macros;
|
||||
auto macro = macros[0].GetMacro();
|
||||
if (validNextMacro(macro)) {
|
||||
res.push_back(macro);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
auto lastRandomMacro = lastRandomMacroRef.GetMacro();
|
||||
for (auto &m : macros) {
|
||||
if (m.get() && !m->Paused() &&
|
||||
(allowRepeat || (lastRandomMacro.get() != m.get()))) {
|
||||
res.push_back(m);
|
||||
auto macro = m.GetMacro();
|
||||
if (validNextMacro(macro) &&
|
||||
(allowRepeat || (lastRandomMacro != macro))) {
|
||||
res.push_back(macro);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
|
@ -42,7 +50,7 @@ bool MacroActionRandom::PerformAction()
|
|||
if (macros.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
if (macros.size() == 1 && macros[0].get()) {
|
||||
if (macros.size() == 1) {
|
||||
lastRandomMacro = macros[0];
|
||||
return macros[0]->PerformActions();
|
||||
}
|
||||
|
|
@ -126,8 +134,7 @@ void MacroActionRandomEdit::MacroRemove(const QString &)
|
|||
|
||||
auto it = _entryData->_macros.begin();
|
||||
while (it != _entryData->_macros.end()) {
|
||||
it->UpdateRef();
|
||||
if (it->get() == nullptr) {
|
||||
if (!it->GetMacro()) {
|
||||
it = _entryData->_macros.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
|
|
@ -188,9 +195,9 @@ bool MacroActionRandomEdit::ShouldShowAllowRepeat()
|
|||
if (_entryData->_macros.size() <= 1) {
|
||||
return false;
|
||||
}
|
||||
const auto macro = _entryData->_macros[0];
|
||||
const auto macro = _entryData->_macros[0].GetMacro();
|
||||
for (const auto &m : _entryData->_macros) {
|
||||
if (macro.get() != m.get()) {
|
||||
if (macro != m.GetMacro()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ bool MacroActionSequence::_registered = MacroActionFactory::Register(
|
|||
int getNextUnpausedMacroIdx(std::vector<MacroRef> ¯os, int startIdx)
|
||||
{
|
||||
for (; (int)macros.size() > startIdx; ++startIdx) {
|
||||
if (macros[startIdx].get() && !macros[startIdx]->Paused()) {
|
||||
auto macro = macros[startIdx].GetMacro();
|
||||
if (macro && !macro->Paused()) {
|
||||
return startIdx;
|
||||
}
|
||||
}
|
||||
|
|
@ -58,7 +59,7 @@ bool MacroActionSequence::PerformAction()
|
|||
return true;
|
||||
}
|
||||
|
||||
auto macro = GetNextMacro();
|
||||
auto macro = GetNextMacro().GetMacro();
|
||||
if (!macro.get()) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -158,8 +159,8 @@ void MacroActionSequenceEdit::MacroRemove(const QString &)
|
|||
|
||||
auto it = _entryData->_macros.begin();
|
||||
while (it != _entryData->_macros.end()) {
|
||||
it->UpdateRef();
|
||||
if (it->get() == nullptr) {
|
||||
|
||||
if (!it->GetMacro()) {
|
||||
it = _entryData->_macros.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
|
|
@ -250,12 +251,11 @@ void MacroActionSequenceEdit::UpdateStatusLine()
|
|||
QString nextMacroName =
|
||||
obs_module_text("AdvSceneSwitcher.action.sequence.status.none");
|
||||
if (_entryData) {
|
||||
if (_entryData->_lastSequenceMacro.get()) {
|
||||
lastMacroName = QString::fromStdString(
|
||||
_entryData->_lastSequenceMacro->Name());
|
||||
if (auto macro = _entryData->_lastSequenceMacro.GetMacro()) {
|
||||
lastMacroName = QString::fromStdString(macro->Name());
|
||||
}
|
||||
auto next = _entryData->GetNextMacro(false);
|
||||
if (next.get()) {
|
||||
auto next = _entryData->GetNextMacro(false).GetMacro();
|
||||
if (next) {
|
||||
nextMacroName = QString::fromStdString(next->Name());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,11 @@ static std::map<TimerAction, std::string> timerActions = {
|
|||
|
||||
bool MacroActionTimer::PerformAction()
|
||||
{
|
||||
if (!_macro.get()) {
|
||||
auto macro = _macro.GetMacro();
|
||||
if (!macro) {
|
||||
return true;
|
||||
}
|
||||
for (auto c : _macro->Conditions()) {
|
||||
for (auto c : macro->Conditions()) {
|
||||
if (c->GetId() != "timer") {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -58,26 +59,27 @@ bool MacroActionTimer::PerformAction()
|
|||
|
||||
void MacroActionTimer::LogAction() const
|
||||
{
|
||||
if (!_macro.get()) {
|
||||
auto macro = _macro.GetMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
switch (_actionType) {
|
||||
case TimerAction::PAUSE:
|
||||
vblog(LOG_INFO, "paused timers on \"%s\"",
|
||||
_macro->Name().c_str());
|
||||
macro->Name().c_str());
|
||||
break;
|
||||
case TimerAction::CONTINUE:
|
||||
vblog(LOG_INFO, "continued timers on \"%s\"",
|
||||
_macro->Name().c_str());
|
||||
macro->Name().c_str());
|
||||
break;
|
||||
case TimerAction::RESET:
|
||||
vblog(LOG_INFO, "reset timers on \"%s\"",
|
||||
_macro->Name().c_str());
|
||||
macro->Name().c_str());
|
||||
break;
|
||||
case TimerAction::SET_TIME_REMAINING:
|
||||
vblog(LOG_INFO,
|
||||
"set time remaining of timers on \"%s\" to \"%s\"",
|
||||
_macro->Name().c_str(), _duration.ToString().c_str());
|
||||
macro->Name().c_str(), _duration.ToString().c_str());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -105,10 +107,7 @@ bool MacroActionTimer::Load(obs_data_t *obj)
|
|||
|
||||
std::string MacroActionTimer::GetShortDesc() const
|
||||
{
|
||||
if (_macro.get()) {
|
||||
return _macro->Name();
|
||||
}
|
||||
return "";
|
||||
return _macro.Name();
|
||||
}
|
||||
|
||||
static inline void populateTypeSelection(QComboBox *list)
|
||||
|
|
@ -130,8 +129,6 @@ MacroActionTimerEdit::MacroActionTimerEdit(
|
|||
|
||||
QWidget::connect(_macros, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(MacroChanged(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SLOT(MacroRemove(const QString &)));
|
||||
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
|
||||
SLOT(DurationChanged(double)));
|
||||
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
|
||||
|
|
@ -160,7 +157,7 @@ void MacroActionTimerEdit::UpdateEntryData()
|
|||
return;
|
||||
}
|
||||
|
||||
_macros->SetCurrentMacro(_entryData->_macro.get());
|
||||
_macros->SetCurrentMacro(_entryData->_macro);
|
||||
_duration->SetDuration(_entryData->_duration);
|
||||
_timerAction->setCurrentIndex(
|
||||
static_cast<int>(_entryData->_actionType));
|
||||
|
|
@ -215,14 +212,7 @@ void MacroActionTimerEdit::MacroChanged(const QString &text)
|
|||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_macro.UpdateRef(text);
|
||||
_entryData->_macro = text;
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
|
||||
void MacroActionTimerEdit::MacroRemove(const QString &)
|
||||
{
|
||||
if (_entryData) {
|
||||
_entryData->_macro.UpdateRef();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ public:
|
|||
|
||||
private slots:
|
||||
void MacroChanged(const QString &text);
|
||||
void MacroRemove(const QString &name);
|
||||
void DurationChanged(double value);
|
||||
void DurationUnitChanged(DurationUnit unit);
|
||||
void ActionTypeChanged(int value);
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ MacroRefAction::MacroRefAction(Macro *m, bool supportsVariableValue)
|
|||
{
|
||||
}
|
||||
|
||||
void MacroRefAction::ResolveMacroRef()
|
||||
bool MacroRefAction::PostLoad()
|
||||
{
|
||||
_macro.UpdateRef();
|
||||
_macro.PostLoad();
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiMacroRefAction::MultiMacroRefAction(Macro *m, bool supportsVariableValue)
|
||||
|
|
@ -39,9 +40,10 @@ MultiMacroRefAction::MultiMacroRefAction(Macro *m, bool supportsVariableValue)
|
|||
{
|
||||
}
|
||||
|
||||
void MultiMacroRefAction::ResolveMacroRef()
|
||||
bool MultiMacroRefAction::PostLoad()
|
||||
{
|
||||
for (auto &m : _macros) {
|
||||
m.UpdateRef();
|
||||
for (auto ¯o : _macros) {
|
||||
macro.PostLoad();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,15 @@ public:
|
|||
class MacroRefAction : virtual public MacroAction {
|
||||
public:
|
||||
MacroRefAction(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
bool PostLoad() override;
|
||||
|
||||
MacroRef _macro;
|
||||
};
|
||||
|
||||
class MultiMacroRefAction : virtual public MacroAction {
|
||||
public:
|
||||
MultiMacroRefAction(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
bool PostLoad() override;
|
||||
|
||||
std::vector<MacroRef> _macros;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -44,11 +44,12 @@ bool MacroConditionMacro::CheckStateCondition()
|
|||
// Note:
|
||||
// Depending on the order the macro conditions are checked Matched() might
|
||||
// still return the state of the previous interval
|
||||
if (!_macro.get()) {
|
||||
auto macro = _macro.GetMacro();
|
||||
if (!macro) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _macro->Matched();
|
||||
return macro->Matched();
|
||||
}
|
||||
|
||||
bool MacroConditionMacro::CheckMultiStateCondition()
|
||||
|
|
@ -57,8 +58,9 @@ bool MacroConditionMacro::CheckMultiStateCondition()
|
|||
// Depending on the order the macro conditions are checked Matched() might
|
||||
// still return the state of the previous interval
|
||||
int matchedCount = 0;
|
||||
for (const auto ¯o : _macros) {
|
||||
if (!macro.get()) {
|
||||
for (const auto &m : _macros) {
|
||||
auto macro = m.GetMacro();
|
||||
if (!macro) {
|
||||
continue;
|
||||
}
|
||||
if (macro->Matched()) {
|
||||
|
|
@ -82,17 +84,18 @@ bool MacroConditionMacro::CheckMultiStateCondition()
|
|||
|
||||
bool MacroConditionMacro::CheckCountCondition()
|
||||
{
|
||||
if (!_macro.get()) {
|
||||
auto macro = _macro.GetMacro();
|
||||
if (!macro) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (_counterCondition) {
|
||||
case CounterCondition::BELOW:
|
||||
return _macro->RunCount() < _count;
|
||||
return macro->RunCount() < _count;
|
||||
case CounterCondition::ABOVE:
|
||||
return _macro->RunCount() > _count;
|
||||
return macro->RunCount() > _count;
|
||||
case CounterCondition::EQUAL:
|
||||
return _macro->RunCount() == _count;
|
||||
return macro->RunCount() == _count;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -150,12 +153,15 @@ bool MacroConditionMacro::Load(obs_data_t *obj)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MacroConditionMacro::PostLoad()
|
||||
{
|
||||
return MacroRefCondition::PostLoad() &&
|
||||
MultiMacroRefCondtition::PostLoad();
|
||||
}
|
||||
|
||||
std::string MacroConditionMacro::GetShortDesc() const
|
||||
{
|
||||
if (_macro.get()) {
|
||||
return _macro->Name();
|
||||
}
|
||||
return "";
|
||||
return _macro.Name();
|
||||
}
|
||||
|
||||
static inline void populateTypeSelection(QComboBox *list)
|
||||
|
|
@ -383,7 +389,7 @@ void MacroConditionMacroEdit::UpdateEntryData()
|
|||
break;
|
||||
}
|
||||
|
||||
_macros->SetCurrentMacro(_entryData->_macro.get());
|
||||
_macros->SetCurrentMacro(_entryData->_macro);
|
||||
_types->setCurrentIndex(static_cast<int>(_entryData->_type));
|
||||
_counterConditions->setCurrentIndex(
|
||||
static_cast<int>(_entryData->_counterCondition));
|
||||
|
|
@ -401,7 +407,7 @@ void MacroConditionMacroEdit::MacroChanged(const QString &text)
|
|||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_macro.UpdateRef(text);
|
||||
_entryData->_macro = text;
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
|
|
@ -433,12 +439,9 @@ void MacroConditionMacroEdit::MacroRemove(const QString &)
|
|||
return;
|
||||
}
|
||||
|
||||
_entryData->_macro.UpdateRef();
|
||||
|
||||
auto it = _entryData->_macros.begin();
|
||||
while (it != _entryData->_macros.end()) {
|
||||
it->UpdateRef();
|
||||
if (it->get() == nullptr) {
|
||||
if (!it->GetMacro()) {
|
||||
it = _entryData->_macros.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
|
|
@ -473,18 +476,26 @@ void MacroConditionMacroEdit::TypeChanged(int type)
|
|||
|
||||
void MacroConditionMacroEdit::ResetClicked()
|
||||
{
|
||||
if (_loading || !_entryData || !_entryData->_macro.get()) {
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
_entryData->_macro->ResetRunCount();
|
||||
auto macro = _entryData->_macro.GetMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
macro->ResetRunCount();
|
||||
}
|
||||
|
||||
void MacroConditionMacroEdit::UpdateCount()
|
||||
{
|
||||
if (_entryData && _entryData->_macro.get()) {
|
||||
_currentCount->setText(
|
||||
QString::number(_entryData->_macro->RunCount()));
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto macro = _entryData->_macro.GetMacro();
|
||||
if (macro) {
|
||||
_currentCount->setText(QString::number(macro->RunCount()));
|
||||
} else {
|
||||
_currentCount->setText("-");
|
||||
}
|
||||
|
|
@ -492,10 +503,11 @@ void MacroConditionMacroEdit::UpdateCount()
|
|||
|
||||
void MacroConditionMacroEdit::UpdatePaused()
|
||||
{
|
||||
auto macro = _entryData->_macro.GetMacro();
|
||||
_pausedWarning->setVisible(
|
||||
_entryData &&
|
||||
_entryData->_type != MacroConditionMacro::Type::MULTI_STATE &&
|
||||
_entryData->_macro.get() && _entryData->_macro->Paused());
|
||||
macro && macro->Paused());
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
bool CheckCondition();
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
bool PostLoad() override;
|
||||
std::string GetShortDesc() const;
|
||||
std::string GetId() const { return id; };
|
||||
static std::shared_ptr<MacroCondition> Create(Macro *m)
|
||||
|
|
|
|||
|
|
@ -156,9 +156,10 @@ MacroRefCondition::MacroRefCondition(Macro *m, bool supportsVariableValue)
|
|||
{
|
||||
}
|
||||
|
||||
void MacroRefCondition::ResolveMacroRef()
|
||||
bool MacroRefCondition::PostLoad()
|
||||
{
|
||||
_macro.UpdateRef();
|
||||
_macro.PostLoad();
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiMacroRefCondtition::MultiMacroRefCondtition(Macro *m,
|
||||
|
|
@ -167,9 +168,10 @@ MultiMacroRefCondtition::MultiMacroRefCondtition(Macro *m,
|
|||
{
|
||||
}
|
||||
|
||||
void MultiMacroRefCondtition::ResolveMacroRef()
|
||||
bool MultiMacroRefCondtition::PostLoad()
|
||||
{
|
||||
for (auto &m : _macros) {
|
||||
m.UpdateRef();
|
||||
for (auto ¯o : _macros) {
|
||||
macro.PostLoad();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,13 +84,15 @@ private:
|
|||
class MacroRefCondition : virtual public MacroCondition {
|
||||
public:
|
||||
MacroRefCondition(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
bool PostLoad() override;
|
||||
|
||||
MacroRef _macro;
|
||||
};
|
||||
|
||||
class MultiMacroRefCondtition : virtual public MacroCondition {
|
||||
public:
|
||||
MultiMacroRefCondtition(Macro *m, bool supportsVariableValue = false);
|
||||
void ResolveMacroRef();
|
||||
bool PostLoad() override;
|
||||
|
||||
std::vector<MacroRef> _macros;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,50 +1,50 @@
|
|||
#include "macro-ref.hpp"
|
||||
#include "macro.hpp"
|
||||
|
||||
MacroRef::MacroRef(std::string name) : _name(name)
|
||||
MacroRef::MacroRef(std::string name)
|
||||
{
|
||||
UpdateRef();
|
||||
}
|
||||
void MacroRef::UpdateRef()
|
||||
{
|
||||
_ref = GetMacroByName(_name.c_str());
|
||||
}
|
||||
void MacroRef::UpdateRef(std::string newName)
|
||||
{
|
||||
_name = newName;
|
||||
UpdateRef();
|
||||
}
|
||||
void MacroRef::UpdateRef(QString newName)
|
||||
{
|
||||
_name = newName.toStdString();
|
||||
UpdateRef();
|
||||
_macro = GetWeakMacroByName(name.c_str());
|
||||
}
|
||||
|
||||
void MacroRef::Save(obs_data_t *obj) const
|
||||
{
|
||||
if (_ref) {
|
||||
obs_data_set_string(obj, "macro", _ref->Name().c_str());
|
||||
if (auto macro = _macro.lock()) {
|
||||
obs_data_set_string(obj, "macro", macro->Name().c_str());
|
||||
}
|
||||
}
|
||||
void MacroRef::Load(obs_data_t *obj)
|
||||
{
|
||||
_name = obs_data_get_string(obj, "macro");
|
||||
UpdateRef();
|
||||
auto name = obs_data_get_string(obj, "macro");
|
||||
_postLoadName = name;
|
||||
_macro = GetWeakMacroByName(name);
|
||||
}
|
||||
|
||||
Macro *MacroRef::get() const
|
||||
void MacroRef::PostLoad()
|
||||
{
|
||||
return _ref;
|
||||
_macro = GetWeakMacroByName(_postLoadName.c_str());
|
||||
}
|
||||
|
||||
Macro *MacroRef::operator->() const
|
||||
void MacroRef::operator=(const QString &name)
|
||||
{
|
||||
return _ref;
|
||||
_macro = GetWeakMacroByName(name.toStdString().c_str());
|
||||
}
|
||||
|
||||
std::string MacroRef::RefName() const
|
||||
void MacroRef::operator=(const std::shared_ptr<Macro> ¯o)
|
||||
{
|
||||
return _name;
|
||||
_macro = macro;
|
||||
}
|
||||
|
||||
std::shared_ptr<Macro> MacroRef::GetMacro() const
|
||||
{
|
||||
return _macro.lock();
|
||||
}
|
||||
|
||||
std::string MacroRef::Name() const
|
||||
{
|
||||
if (auto macro = GetMacro()) {
|
||||
return macro->Name();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void SaveMacroList(obs_data_t *obj, const std::vector<MacroRef> ¯os,
|
||||
|
|
@ -52,7 +52,7 @@ void SaveMacroList(obs_data_t *obj, const std::vector<MacroRef> ¯os,
|
|||
{
|
||||
obs_data_array_t *array = obs_data_array_create();
|
||||
for (auto &m : macros) {
|
||||
if (!m.get()) {
|
||||
if (!m.GetMacro()) {
|
||||
continue;
|
||||
}
|
||||
obs_data_t *array_obj = obs_data_create();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
|
|
@ -10,18 +11,17 @@ class MacroRef {
|
|||
public:
|
||||
MacroRef(){};
|
||||
MacroRef(std::string name);
|
||||
void UpdateRef();
|
||||
void UpdateRef(std::string name);
|
||||
void UpdateRef(QString name);
|
||||
void operator=(const QString &);
|
||||
void operator=(const std::shared_ptr<Macro> &);
|
||||
void Save(obs_data_t *obj) const;
|
||||
void Load(obs_data_t *obj);
|
||||
Macro *get() const;
|
||||
Macro *operator->() const;
|
||||
std::string RefName() const;
|
||||
void PostLoad();
|
||||
std::shared_ptr<Macro> GetMacro() const;
|
||||
std::string Name() const;
|
||||
|
||||
private:
|
||||
std::string _name = "";
|
||||
Macro *_ref = nullptr;
|
||||
std::string _postLoadName;
|
||||
std::weak_ptr<Macro> _macro;
|
||||
};
|
||||
|
||||
void SaveMacroList(obs_data_t *obj, const std::vector<MacroRef> ¯os,
|
||||
|
|
|
|||
|
|
@ -39,8 +39,9 @@ void MacroSelection::MacroAdd(const QString &name)
|
|||
addItem(name);
|
||||
}
|
||||
|
||||
void MacroSelection::SetCurrentMacro(Macro *m)
|
||||
void MacroSelection::SetCurrentMacro(const MacroRef ¯o)
|
||||
{
|
||||
auto m = macro.GetMacro();
|
||||
if (!m) {
|
||||
this->setCurrentIndex(0);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
#include <QDialog>
|
||||
|
||||
class Macro;
|
||||
class MacroRef;
|
||||
|
||||
class MacroSelection : public QComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroSelection(QWidget *parent);
|
||||
void SetCurrentMacro(Macro *);
|
||||
void SetCurrentMacro(const MacroRef &);
|
||||
void HideSelectedMacro(); // Macro currently being edited
|
||||
void ShowAllMacros();
|
||||
|
||||
|
|
|
|||
|
|
@ -292,10 +292,6 @@ void MacroTreeModel::MoveItemBefore(const std::shared_ptr<Macro> &item,
|
|||
_macros.insert(std::next(_macros.begin(), macroTo + i), tmp);
|
||||
}
|
||||
endMoveRows();
|
||||
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroTreeModel::MoveItemAfter(const std::shared_ptr<Macro> &item,
|
||||
|
|
@ -340,10 +336,6 @@ void MacroTreeModel::MoveItemAfter(const std::shared_ptr<Macro> &item,
|
|||
_macros.insert(std::next(_macros.begin(), macroTo), tmp);
|
||||
}
|
||||
endMoveRows();
|
||||
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
|
|
@ -368,9 +360,6 @@ void MacroTreeModel::Add(std::shared_ptr<Macro> item)
|
|||
_mt->selectionModel()->clear();
|
||||
_mt->selectionModel()->select(createIndex(idx, 0, nullptr),
|
||||
QItemSelectionModel::Select);
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroTreeModel::Remove(std::shared_ptr<Macro> item)
|
||||
|
|
@ -404,10 +393,6 @@ void MacroTreeModel::Remove(std::shared_ptr<Macro> item)
|
|||
if (isGroup) {
|
||||
UpdateGroupState(true);
|
||||
}
|
||||
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Macro> MacroTreeModel::Neighbor(const std::shared_ptr<Macro> &m,
|
||||
|
|
@ -619,9 +604,6 @@ void MacroTreeModel::GroupSelectedItems(QModelIndexList &indices)
|
|||
_mt->selectionModel()->clear();
|
||||
|
||||
Reset(_macros);
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
||||
|
|
@ -641,15 +623,7 @@ void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
|||
|
||||
_mt->selectionModel()->clear();
|
||||
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
|
||||
Reset(_macros);
|
||||
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroTreeModel::ExpandGroup(std::shared_ptr<Macro> item)
|
||||
|
|
@ -664,10 +638,6 @@ void MacroTreeModel::ExpandGroup(std::shared_ptr<Macro> item)
|
|||
Reset(_macros);
|
||||
|
||||
_mt->selectionModel()->clear();
|
||||
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroTreeModel::CollapseGroup(std::shared_ptr<Macro> item)
|
||||
|
|
@ -682,10 +652,6 @@ void MacroTreeModel::CollapseGroup(std::shared_ptr<Macro> item)
|
|||
Reset(_macros);
|
||||
|
||||
_mt->selectionModel()->clear();
|
||||
|
||||
for (auto &m : _macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroTreeModel::UpdateGroupState(bool update)
|
||||
|
|
@ -1043,10 +1009,6 @@ void MacroTree::dropEvent(QDropEvent *event)
|
|||
items.insert(std::next(it, 1), i);
|
||||
}
|
||||
|
||||
for (auto &m : items) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
|
||||
// Update widgets and accept event
|
||||
UpdateWidgets(true);
|
||||
event->accept();
|
||||
|
|
|
|||
|
|
@ -498,7 +498,6 @@ bool Macro::Load(obs_data_t *obj)
|
|||
|
||||
bool Macro::PostLoad()
|
||||
{
|
||||
ResolveMacroRef();
|
||||
for (auto &c : _conditions) {
|
||||
c->PostLoad();
|
||||
}
|
||||
|
|
@ -508,33 +507,6 @@ bool Macro::PostLoad()
|
|||
return true;
|
||||
}
|
||||
|
||||
void Macro::ResolveMacroRef()
|
||||
{
|
||||
for (auto &c : _conditions) {
|
||||
MacroRefCondition *ref =
|
||||
dynamic_cast<MacroRefCondition *>(c.get());
|
||||
if (ref) {
|
||||
ref->ResolveMacroRef();
|
||||
}
|
||||
MultiMacroRefCondtition *ref2 =
|
||||
dynamic_cast<MultiMacroRefCondtition *>(c.get());
|
||||
if (ref2) {
|
||||
ref2->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
for (auto &a : _actions) {
|
||||
MacroRefAction *ref = dynamic_cast<MacroRefAction *>(a.get());
|
||||
if (ref) {
|
||||
ref->ResolveMacroRef();
|
||||
}
|
||||
MultiMacroRefAction *ref2 =
|
||||
dynamic_cast<MultiMacroRefAction *>(a.get());
|
||||
if (ref2) {
|
||||
ref2->ResolveMacroRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Macro::SwitchesScene()
|
||||
{
|
||||
MacroActionSwitchScene temp(nullptr);
|
||||
|
|
@ -821,3 +793,14 @@ Macro *GetMacroByQString(const QString &name)
|
|||
{
|
||||
return GetMacroByName(name.toUtf8().constData());
|
||||
}
|
||||
|
||||
std::weak_ptr<Macro> GetWeakMacroByName(const char *name)
|
||||
{
|
||||
for (auto &m : switcher->macros) {
|
||||
if (m->Name() == name) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,10 +63,9 @@ public:
|
|||
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
bool PostLoad();
|
||||
// Some macros can refer to other macros, which are not yet loaded.
|
||||
// Use this function to set these references after loading is complete.
|
||||
void ResolveMacroRef();
|
||||
bool PostLoad();
|
||||
|
||||
// Helper function for plugin state condition regarding scene change
|
||||
bool SwitchesScene();
|
||||
|
|
@ -124,3 +123,4 @@ private:
|
|||
|
||||
Macro *GetMacroByName(const char *name);
|
||||
Macro *GetMacroByQString(const QString &name);
|
||||
std::weak_ptr<Macro> GetWeakMacroByName(const char *name);
|
||||
|
|
|
|||
|
|
@ -69,17 +69,20 @@ MacroList::MacroList(QWidget *parent, bool allowDuplicates, bool reorder)
|
|||
void MacroList::SetContent(const std::vector<MacroRef> ¯os)
|
||||
{
|
||||
for (auto &m : macros) {
|
||||
QString name;
|
||||
if (!m.get()) {
|
||||
name = QString::fromStdString(m.RefName()) + "<" +
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.macroList.deleted") +
|
||||
">";
|
||||
QString listEntryName;
|
||||
auto macroName = m.Name();
|
||||
if (macroName.empty()) {
|
||||
listEntryName = QString::fromStdString(
|
||||
std::string("<") +
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.macroList.deleted") +
|
||||
">");
|
||||
} else {
|
||||
name = QString::fromStdString(m->Name());
|
||||
listEntryName = QString::fromStdString(macroName);
|
||||
}
|
||||
QListWidgetItem *item = new QListWidgetItem(name, _list);
|
||||
item->setData(Qt::UserRole, name);
|
||||
QListWidgetItem *item =
|
||||
new QListWidgetItem(listEntryName, _list);
|
||||
item->setData(Qt::UserRole, listEntryName);
|
||||
}
|
||||
SetMacroListSize();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user