mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-29 12:45:28 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1020a1909 | ||
|
|
8b0bd4193b | ||
|
|
d55bb6bc86 | ||
|
|
0583331bfd |
@@ -459,7 +459,7 @@ void SwitcherData::LoadSettings(obs_data_t *obj)
|
||||
LoadHotkeys(obj);
|
||||
LoadUISettings(obj);
|
||||
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
|
||||
// Reset on startup and scene collection change
|
||||
ResetLastOpenedTab();
|
||||
|
||||
@@ -117,7 +117,7 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text)
|
||||
*_entryData = MacroActionFactory::Create(id, macro);
|
||||
(*_entryData)->SetIndex(idx);
|
||||
(*_entryData)->PostLoad();
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
}
|
||||
auto widget = MacroActionFactory::CreateWidget(id, this, *_entryData);
|
||||
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
|
||||
|
||||
@@ -239,7 +239,7 @@ void MacroConditionEdit::ConditionSelectionChanged(const QString &text)
|
||||
(*_entryData)->SetIndex(idx);
|
||||
(*_entryData)->SetLogicType(logic);
|
||||
(*_entryData)->PostLoad();
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
}
|
||||
auto widget =
|
||||
MacroConditionFactory::CreateWidget(id, this, *_entryData);
|
||||
|
||||
@@ -1080,7 +1080,7 @@ void MacroEdit::AddMacroAction(Macro *macro, int idx, const std::string &id,
|
||||
macro->Actions().at(idx)->Load(data);
|
||||
}
|
||||
macro->Actions().at(idx)->PostLoad();
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
macro->UpdateActionIndices();
|
||||
ui->actionsList->Insert(
|
||||
idx,
|
||||
@@ -1383,7 +1383,7 @@ void MacroEdit::AddMacroElseAction(Macro *macro, int idx, const std::string &id,
|
||||
macro->ElseActions().at(idx)->Load(data);
|
||||
}
|
||||
macro->ElseActions().at(idx)->PostLoad();
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
macro->UpdateElseActionIndices();
|
||||
ui->elseActionsList->Insert(
|
||||
idx, new MacroActionEdit(
|
||||
@@ -1583,7 +1583,7 @@ void MacroEdit::AddMacroCondition(Macro *macro, int idx, const std::string &id,
|
||||
macro->Conditions().at(idx)->Load(data);
|
||||
}
|
||||
macro->Conditions().at(idx)->PostLoad();
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
(*cond)->SetLogicType(logic);
|
||||
macro->UpdateConditionIndices();
|
||||
ui->conditionsList->Insert(
|
||||
|
||||
@@ -416,7 +416,7 @@ void AdvSceneSwitcher::ImportMacros()
|
||||
OBSDataAutoRelease array_obj = obs_data_array_item(array, i);
|
||||
auto macro = std::make_shared<Macro>();
|
||||
macro->Load(array_obj);
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
|
||||
if (macroNameExists(macro->Name()) &&
|
||||
!ResolveMacroImportNameConflict(macro)) {
|
||||
@@ -444,7 +444,7 @@ void AdvSceneSwitcher::ImportMacros()
|
||||
for (const auto ¯o : importedMacros) {
|
||||
macro->PostLoad();
|
||||
}
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
|
||||
ui->macros->Reset(GetMacros(),
|
||||
GetGlobalMacroSettings()._highlightExecuted);
|
||||
@@ -752,7 +752,7 @@ void AdvSceneSwitcher::CopyMacro()
|
||||
newMacro->Load(data);
|
||||
newMacro->PostLoad();
|
||||
newMacro->SetName(name);
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
Macro::PrepareMoveToGroup(macro->Parent(), newMacro);
|
||||
|
||||
ui->macros->Add(newMacro, macro);
|
||||
|
||||
@@ -113,7 +113,7 @@ void ActionQueue::Add(const std::shared_ptr<MacroAction> &action)
|
||||
action->Save(data);
|
||||
copy->Load(data);
|
||||
copy->PostLoad();
|
||||
RunPostLoadSteps();
|
||||
RunAndClearPostLoadSteps();
|
||||
copy->ResolveVariablesToFixedValues();
|
||||
_actions.emplace_back(copy);
|
||||
} else {
|
||||
|
||||
@@ -113,12 +113,13 @@ void RunLoadSteps(obs_data_t *obj)
|
||||
}
|
||||
}
|
||||
|
||||
void RunPostLoadSteps()
|
||||
void RunAndClearPostLoadSteps()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(postLoadMutex);
|
||||
for (const auto &func : getPostLoadSteps()) {
|
||||
func();
|
||||
}
|
||||
getPostLoadSteps().clear();
|
||||
}
|
||||
|
||||
void ClearPostLoadSteps()
|
||||
|
||||
@@ -14,7 +14,7 @@ EXPORT void AddPostLoadStep(std::function<void()>);
|
||||
EXPORT void AddIntervalResetStep(std::function<void()>);
|
||||
void RunSaveSteps(obs_data_t *);
|
||||
void RunLoadSteps(obs_data_t *);
|
||||
EXPORT void RunPostLoadSteps();
|
||||
EXPORT void RunAndClearPostLoadSteps();
|
||||
void ClearPostLoadSteps();
|
||||
|
||||
EXPORT void AddPluginInitStep(std::function<void()>);
|
||||
|
||||
@@ -239,22 +239,26 @@ void SceneSelection::ResolveVariables()
|
||||
_type = Type::SCENE;
|
||||
}
|
||||
|
||||
SceneSelection SceneSelectionWidget::CurrentSelection()
|
||||
static obs_weak_canvas_t *getWeakRefToMainCanvas()
|
||||
{
|
||||
SceneSelection s;
|
||||
|
||||
static auto mainCanvas = obs_get_main_canvas();
|
||||
static auto mainCanvasWeak = obs_canvas_get_weak_canvas(mainCanvas);
|
||||
static auto canvas = obs_get_main_canvas();
|
||||
static auto weakCanvas = obs_canvas_get_weak_canvas(canvas);
|
||||
[[maybe_unused]] static const bool _ = []() {
|
||||
// Let's just hope we don't have to deal with selecting scenes
|
||||
// when the OBS main canvas gets deleted and release the
|
||||
// references here already to avoid reporting leaks on shutdown
|
||||
obs_canvas_release(mainCanvas);
|
||||
obs_weak_canvas_release(mainCanvasWeak);
|
||||
obs_canvas_release(canvas);
|
||||
obs_weak_canvas_release(weakCanvas);
|
||||
return true;
|
||||
}();
|
||||
return weakCanvas;
|
||||
}
|
||||
|
||||
s._canvas = _forceMainCanvas ? OBSWeakCanvas(mainCanvasWeak)
|
||||
SceneSelection SceneSelectionWidget::CurrentSelection()
|
||||
{
|
||||
SceneSelection s;
|
||||
|
||||
s._canvas = _forceMainCanvas ? OBSWeakCanvas(getWeakRefToMainCanvas())
|
||||
: _canvas->GetCanvas();
|
||||
|
||||
const int idx = _scenes->currentIndex();
|
||||
@@ -342,6 +346,10 @@ void SceneSelectionWidget::Reset()
|
||||
|
||||
void SceneSelectionWidget::PopulateSceneSelection(obs_weak_canvas_t *canvas)
|
||||
{
|
||||
if (_forceMainCanvas) {
|
||||
canvas = getWeakRefToMainCanvas();
|
||||
}
|
||||
|
||||
_scenes->clear();
|
||||
if ((_current || _previous)) {
|
||||
const bool isMain = IsMainCanvas(canvas);
|
||||
@@ -418,7 +426,7 @@ SceneSelectionWidget::SceneSelectionWidget(QWidget *parent, bool variables,
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
if (GetCanvasCount() <= 1) {
|
||||
_canvas->hide();
|
||||
LockToMainCanvas();
|
||||
}
|
||||
|
||||
Resize();
|
||||
|
||||
@@ -199,7 +199,17 @@ std::chrono::high_resolution_clock::time_point GetLastSceneChangeTime()
|
||||
|
||||
OBSWeakSource GetCurrentScene()
|
||||
{
|
||||
return switcher->currentScene;
|
||||
if (switcher->currentScene) {
|
||||
return switcher->currentScene;
|
||||
}
|
||||
|
||||
// If there wasn't any scene switch yet switcher->currentScene will be
|
||||
// null and we must use obs_frontend_get_current_scene() instead
|
||||
OBSSourceAutoRelease currentSceneSource =
|
||||
obs_frontend_get_current_scene();
|
||||
OBSWeakSourceAutoRelease currentSceneWeakSource =
|
||||
obs_source_get_weak_source(currentSceneSource);
|
||||
return currentSceneWeakSource.Get();
|
||||
}
|
||||
|
||||
OBSWeakSource GetPreviousScene()
|
||||
|
||||
@@ -202,6 +202,8 @@ static void appendNestedMacros(std::deque<std::shared_ptr<Macro>> ¯os,
|
||||
dynamic_cast<MacroActionMacro *>(action.get());
|
||||
if (nestedMacroAction) {
|
||||
macros.push_back(nestedMacroAction->_nestedMacro);
|
||||
appendNestedMacros(
|
||||
macros, nestedMacroAction->_nestedMacro.get());
|
||||
}
|
||||
}
|
||||
for (const auto &action : macro->ElseActions()) {
|
||||
@@ -209,6 +211,8 @@ static void appendNestedMacros(std::deque<std::shared_ptr<Macro>> ¯os,
|
||||
dynamic_cast<MacroActionMacro *>(action.get());
|
||||
if (nestedMacroAction) {
|
||||
macros.push_back(nestedMacroAction->_nestedMacro);
|
||||
appendNestedMacros(
|
||||
macros, nestedMacroAction->_nestedMacro.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,8 +305,13 @@ void TempVariableRef::Save(obs_data_t *obj, Macro *macro,
|
||||
|
||||
void TempVariableRef::Load(obs_data_t *obj, Macro *macroPtr, const char *name)
|
||||
{
|
||||
std::deque<std::shared_ptr<Macro>> allMacros = GetMacros();
|
||||
for (const auto &topLevelMacro : GetMacros()) {
|
||||
appendNestedMacros(allMacros, topLevelMacro.get());
|
||||
}
|
||||
|
||||
std::weak_ptr<Macro> macro;
|
||||
for (const auto ¯oShared : GetMacros()) {
|
||||
for (const auto ¯oShared : allMacros) {
|
||||
if (macroShared.get() == macroPtr) {
|
||||
macro = macroShared;
|
||||
break;
|
||||
@@ -340,7 +349,7 @@ void TempVariableRef::PostLoad(int idx, SegmentType type,
|
||||
return;
|
||||
}
|
||||
|
||||
Macro *macro = nullptr;
|
||||
auto macro = childMacro.get();
|
||||
for (int i = 0; i < _depth; i++) {
|
||||
macro = getParentMacro(childMacro.get());
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
void PostLoad(int idx, SegmentType, const std::weak_ptr<Macro> &);
|
||||
|
||||
std::string _id = "";
|
||||
std::weak_ptr<MacroSegment> _segment;
|
||||
std::weak_ptr<MacroSegment> _segment = {};
|
||||
int _depth = 0;
|
||||
|
||||
friend TempVariable;
|
||||
|
||||
Reference in New Issue
Block a user