diff --git a/CMakeLists.txt b/CMakeLists.txt index 34c17860..03ab9557 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,9 @@ if(BUILD_OUT_OF_TREE) src/switch-random.cpp src/switch-time.cpp src/switch-audio.cpp + src/switch-generic.cpp src/curl-helper.cpp + src/volume-control.cpp ) set(advanced-scene-switcher_UI @@ -218,6 +220,7 @@ else () src/switch-random.cpp src/switch-time.cpp src/switch-audio.cpp + src/switch-generic.cpp src/curl-helper.cpp src/volume-control.cpp ) diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index df04cc5a..c0d11a2c 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -1499,89 +1499,6 @@ Executable - - - - - - - - - <html><head/><body><p>WARNING! Simultaneously running multiple applications from the same executable may result in undesired behavior</p></body></html> - - - Qt::AutoText - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - true - - - 20 - - - - - - - - 100 - 0 - - - - - - - - - - - only if focused - - - 100 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index a5f274f9..6e03c028 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -163,6 +163,17 @@ void SceneSwitcher::populateMediaSelection(QComboBox *sel, bool addSelect) obs_enum_sources(sourceEnum, sel); } +void SceneSwitcher::populateProcessSelection(QComboBox *sel, bool addSelect) +{ + if (addSelect) + addSelectionEntry(sel, "--select process--"); + + QStringList processes; + GetProcessList(processes); + for (QString &process : processes) + sel->addItem(process); +} + bool SceneSwitcher::listMoveUp(QListWidget *list) { int index = list->currentRow(); diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index 33d6c3a1..2c4bd60e 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -80,6 +80,8 @@ public: bool addSelect = true); static void populateMediaSelection(QComboBox *sel, bool addSelect = true); + static void populateProcessSelection(QComboBox *sel, + bool addSelect = true); bool listMoveUp(QListWidget *list); bool listMoveDown(QListWidget *list); @@ -159,7 +161,6 @@ public slots: void on_executableDown_clicked(); void on_executableAdd_clicked(); void on_executableRemove_clicked(); - void on_executables_currentRowChanged(int idx); void on_idleCheckBox_stateChanged(int state); void on_idleTransitions_currentTextChanged(const QString &text); diff --git a/src/headers/switch-audio.hpp b/src/headers/switch-audio.hpp index 48a58dac..e8194754 100644 --- a/src/headers/switch-audio.hpp +++ b/src/headers/switch-audio.hpp @@ -2,7 +2,6 @@ #include #include #include -#include #include "utility.hpp" #include "switch-generic.hpp" @@ -38,7 +37,7 @@ struct AudioSwitch : virtual SceneSwitcherEntry { friend void swap(AudioSwitch &first, AudioSwitch &second); }; -class AudioSwitchWidget : public QWidget { +class AudioSwitchWidget : public SwitchWidget { Q_OBJECT public: @@ -51,16 +50,10 @@ public: AudioSwitchWidget *as2); private slots: - void SceneChanged(const QString &text); - void TransitionChanged(const QString &text); void SourceChanged(const QString &text); void VolumeThresholdChanged(int vol); private: - bool loading = true; - - QComboBox *audioScenes; - QComboBox *audioTransitions; QComboBox *audioSources; QSpinBox *audioVolumeThreshold; diff --git a/src/headers/switch-executable.hpp b/src/headers/switch-executable.hpp index 05400534..9126a9b2 100644 --- a/src/headers/switch-executable.hpp +++ b/src/headers/switch-executable.hpp @@ -1,20 +1,23 @@ #pragma once -#include +#include +#include +#include + #include "utility.hpp" #include "switch-generic.hpp" constexpr auto exe_func = 3; constexpr auto default_priority_3 = exe_func; -struct ExecutableSceneSwitch : SceneSwitcherEntry { - QString exe; - bool inFocus; +struct ExecutableSwitch : SceneSwitcherEntry { + QString exe = ""; + bool inFocus = false; const char *getType() { return "exec"; } - inline ExecutableSceneSwitch(OBSWeakSource scene_, - OBSWeakSource transition_, - const QString &exe_, bool inFocus_) + inline ExecutableSwitch(){}; + inline ExecutableSwitch(OBSWeakSource scene_, OBSWeakSource transition_, + const QString &exe_, bool inFocus_) : SceneSwitcherEntry(scene_, transition_), exe(exe_), inFocus(inFocus_) @@ -22,7 +25,28 @@ struct ExecutableSceneSwitch : SceneSwitcherEntry { } }; -static inline QString MakeSwitchNameExecutable(const QString &scene, - const QString &value, - const QString &transition, - bool inFocus); +class ExecutableSwitchWidget : public SwitchWidget { + Q_OBJECT + +public: + ExecutableSwitchWidget(ExecutableSwitch *s); + ExecutableSwitch *getSwitchData(); + void setSwitchData(ExecutableSwitch *s); + + static void swapSwitchData(ExecutableSwitchWidget *s1, + ExecutableSwitchWidget *s2); + +private slots: + void ProcessChanged(const QString &text); + void FocusChanged(int state); + +private: + QComboBox *processes; + QCheckBox *requiresFocus; + + QLabel *whenLabel; + QLabel *switchLabel; + QLabel *usingLabel; + + ExecutableSwitch *switchData; +}; diff --git a/src/headers/switch-generic.hpp b/src/headers/switch-generic.hpp index f2e1adcb..5504d5e0 100644 --- a/src/headers/switch-generic.hpp +++ b/src/headers/switch-generic.hpp @@ -8,41 +8,41 @@ struct SceneSwitcherEntry { bool usePreviousScene = false; virtual const char *getType() = 0; - virtual bool initialized() { return scene && transition; } - virtual bool valid() - { - return (usePreviousScene || WeakSourceValid(scene)) && - WeakSourceValid(transition); - } - - // TODO - //virtual bool checkMatch() = 0; - - virtual void logMatch() - { - obs_source_t *s = obs_weak_source_get_source(scene); - const char *sceneName = obs_source_get_name(s); - obs_source_release(s); - blog(LOG_INFO, - "[adv-ss] match for '%s' - switch to scene '%s'", - getType(), sceneName); - } + virtual bool initialized(); + virtual bool valid(); + virtual void logMatch(); inline SceneSwitcherEntry() {} inline SceneSwitcherEntry(OBSWeakSource scene_, OBSWeakSource transition_, - bool usePreviousScene_) + bool usePreviousScene_ = true) : scene(scene_), transition(transition_), usePreviousScene(usePreviousScene_) { } - inline SceneSwitcherEntry(OBSWeakSource scene_, - OBSWeakSource transition_) - : scene(scene_), - transition(transition_), - usePreviousScene(false) - { - } +}; + +class SwitchWidget : public QWidget { + Q_OBJECT + +public: + SwitchWidget(SceneSwitcherEntry *s, bool usePreviousScene = true); + virtual SceneSwitcherEntry *getSwitchData(); + virtual void setSwitchData(SceneSwitcherEntry *s); + + static void swapSwitchData(SwitchWidget *s1, SwitchWidget *s2); + +private slots: + void SceneChanged(const QString &text); + void TransitionChanged(const QString &text); + +protected: + bool loading = true; + + QComboBox *scenes; + QComboBox *transitions; + + SceneSwitcherEntry *switchData; }; diff --git a/src/headers/switcher-data-structs.hpp b/src/headers/switcher-data-structs.hpp index b61cc92d..53688c6e 100644 --- a/src/headers/switcher-data-structs.hpp +++ b/src/headers/switcher-data-structs.hpp @@ -81,7 +81,7 @@ struct SwitcherData { std::vector fileSwitches; CURL *curl = nullptr; - std::vector executableSwitches; + std::deque executableSwitches; bool autoStopEnable = false; OBSWeakSource autoStopScene; diff --git a/src/switch-audio.cpp b/src/switch-audio.cpp index 94671f58..859c6989 100644 --- a/src/switch-audio.cpp +++ b/src/switch-audio.cpp @@ -40,13 +40,13 @@ void SceneSwitcher::on_audioUp_clicked() if (!listMoveUp(ui->audioSwitches)) return; - AudioSwitchWidget *as1 = + AudioSwitchWidget *s1 = (AudioSwitchWidget *)ui->audioSwitches->itemWidget( ui->audioSwitches->item(index)); - AudioSwitchWidget *as2 = + AudioSwitchWidget *s2 = (AudioSwitchWidget *)ui->audioSwitches->itemWidget( ui->audioSwitches->item(index - 1)); - AudioSwitchWidget::swapSwitchData(as1, as2); + AudioSwitchWidget::swapSwitchData(s1, s2); std::lock_guard lock(switcher->m); @@ -61,13 +61,13 @@ void SceneSwitcher::on_audioDown_clicked() if (!listMoveDown(ui->audioSwitches)) return; - AudioSwitchWidget *as1 = + AudioSwitchWidget *s1 = (AudioSwitchWidget *)ui->audioSwitches->itemWidget( ui->audioSwitches->item(index)); - AudioSwitchWidget *as2 = + AudioSwitchWidget *s2 = (AudioSwitchWidget *)ui->audioSwitches->itemWidget( ui->audioSwitches->item(index + 1)); - AudioSwitchWidget::swapSwitchData(as1, as2); + AudioSwitchWidget::swapSwitchData(s1, s2); std::lock_guard lock(switcher->m); @@ -224,14 +224,12 @@ void AudioSwitch::resetVolmeter() bool AudioSwitch::initialized() { - return audioSource && SceneSwitcherEntry::initialized(); + return SceneSwitcherEntry::initialized() && audioSource; } bool AudioSwitch::valid() { - return !initialized() || - ((usePreviousScene || WeakSourceValid(scene)) && - WeakSourceValid(audioSource) && WeakSourceValid(transition)); + return SceneSwitcherEntry::valid() && WeakSourceValid(audioSource); } inline AudioSwitch::AudioSwitch(OBSWeakSource scene_, OBSWeakSource transition_, @@ -320,10 +318,8 @@ void swap(AudioSwitch &first, AudioSwitch &second) second.resetVolmeter(); } -AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) +AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) : SwitchWidget(s) { - audioScenes = new QComboBox(); - audioTransitions = new QComboBox(); audioSources = new QComboBox(); audioVolumeThreshold = new QSpinBox(); @@ -348,24 +344,15 @@ AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) volMeter->GetSlider(), SLOT(setValue(int))); QWidget::connect(audioVolumeThreshold, SIGNAL(valueChanged(int)), this, SLOT(VolumeThresholdChanged(int))); - QWidget::connect(audioScenes, - SIGNAL(currentTextChanged(const QString &)), this, - SLOT(SceneChanged(const QString &))); - QWidget::connect(audioTransitions, - SIGNAL(currentTextChanged(const QString &)), this, - SLOT(TransitionChanged(const QString &))); QWidget::connect(audioSources, SIGNAL(currentTextChanged(const QString &)), this, SLOT(SourceChanged(const QString &))); - SceneSwitcher::populateSceneSelection(audioScenes, true); - SceneSwitcher::populateTransitionSelection(audioTransitions); SceneSwitcher::populateAudioSelection(audioSources); if (s) { - audioScenes->setCurrentText( - GetWeakSourceName(s->scene).c_str()); - audioTransitions->setCurrentText( + scenes->setCurrentText(GetWeakSourceName(s->scene).c_str()); + transitions->setCurrentText( GetWeakSourceName(s->transition).c_str()); audioSources->setCurrentText( GetWeakSourceName(s->audioSource).c_str()); @@ -381,9 +368,9 @@ AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s) switchLayout->addWidget(aboveLabel); switchLayout->addWidget(audioVolumeThreshold); switchLayout->addWidget(switchLabel); - switchLayout->addWidget(audioScenes); + switchLayout->addWidget(scenes); switchLayout->addWidget(usingLabel); - switchLayout->addWidget(audioTransitions); + switchLayout->addWidget(transitions); switchLayout->addStretch(); QVBoxLayout *mainLayout = new QVBoxLayout; @@ -408,20 +395,14 @@ void AudioSwitchWidget::setSwitchData(AudioSwitch *s) switchData = s; } -void AudioSwitchWidget::swapSwitchData(AudioSwitchWidget *as1, - AudioSwitchWidget *as2) +void AudioSwitchWidget::swapSwitchData(AudioSwitchWidget *s1, + AudioSwitchWidget *s2) { - AudioSwitch *t = as1->getSwitchData(); - as1->setSwitchData(as2->getSwitchData()); - as2->setSwitchData(t); -} + SwitchWidget::swapSwitchData(s1, s2); -void AudioSwitchWidget::SceneChanged(const QString &text) -{ - if (loading || !switchData) - return; - std::lock_guard lock(switcher->m); - switchData->scene = GetWeakSourceByQString(text); + AudioSwitch *t = s1->getSwitchData(); + s1->setSwitchData(s2->getSwitchData()); + s2->setSwitchData(t); } void AudioSwitchWidget::UpdateVolmeterSource() @@ -444,14 +425,6 @@ void AudioSwitchWidget::UpdateVolmeterSource() volMeter->GetSlider()->setValue(switchData->volumeThreshold); } -void AudioSwitchWidget::TransitionChanged(const QString &text) -{ - if (loading || !switchData) - return; - std::lock_guard lock(switcher->m); - switchData->transition = GetWeakTransitionByQString(text); -} - void AudioSwitchWidget::SourceChanged(const QString &text) { if (loading || !switchData) diff --git a/src/switch-executable.cpp b/src/switch-executable.cpp index 4445727c..0d2296c6 100644 --- a/src/switch-executable.cpp +++ b/src/switch-executable.cpp @@ -1,121 +1,17 @@ #include "headers/advanced-scene-switcher.hpp" -int SceneSwitcher::executableFindByData(const QString &exe) -{ - int count = ui->executables->count(); - - for (int i = 0; i < count; i++) { - QListWidgetItem *item = ui->executables->item(i); - QString itemExe = item->data(Qt::UserRole).toString(); - - if (itemExe == exe) - return i; - } - - return -1; -} - -void SceneSwitcher::on_executables_currentRowChanged(int idx) -{ - if (loading) - return; - if (idx == -1) - return; - - QListWidgetItem *item = ui->executables->item(idx); - - QString exec = item->data(Qt::UserRole).toString(); - - std::lock_guard lock(switcher->m); - for (auto &s : switcher->executableSwitches) { - if (exec.compare(s.exe) == 0) { - QString sceneName = GetWeakSourceName(s.scene).c_str(); - QString transitionName = - GetWeakSourceName(s.transition).c_str(); - ui->executableScenes->setCurrentText(sceneName); - ui->executable->setCurrentText(exec); - ui->executableTransitions->setCurrentText( - transitionName); - ui->requiresFocusCheckBox->setChecked(s.inFocus); - break; - } - } -} - -void SceneSwitcher::on_executableUp_clicked() -{ - int index = ui->executables->currentRow(); - if (index != -1 && index != 0) { - ui->executables->insertItem(index - 1, - ui->executables->takeItem(index)); - ui->executables->setCurrentRow(index - 1); - - std::lock_guard lock(switcher->m); - - iter_swap(switcher->executableSwitches.begin() + index, - switcher->executableSwitches.begin() + index - 1); - } -} - -void SceneSwitcher::on_executableDown_clicked() -{ - int index = ui->executables->currentRow(); - if (index != -1 && index != ui->executables->count() - 1) { - ui->executables->insertItem(index + 1, - ui->executables->takeItem(index)); - ui->executables->setCurrentRow(index + 1); - - std::lock_guard lock(switcher->m); - - iter_swap(switcher->executableSwitches.begin() + index, - switcher->executableSwitches.begin() + index + 1); - } -} - void SceneSwitcher::on_executableAdd_clicked() { - QString sceneName = ui->executableScenes->currentText(); - QString exeName = ui->executable->currentText(); - QString transitionName = ui->executableTransitions->currentText(); - bool inFocus = ui->requiresFocusCheckBox->isChecked(); + std::lock_guard lock(switcher->m); + switcher->executableSwitches.emplace_back(); - if (exeName.isEmpty() || sceneName.isEmpty()) - return; - - OBSWeakSource source = GetWeakSourceByQString(sceneName); - OBSWeakSource transition = GetWeakTransitionByQString(transitionName); - QVariant v = QVariant::fromValue(exeName); - - QString text = MakeSwitchNameExecutable(sceneName, exeName, - transitionName, inFocus); - - int idx = executableFindByData(exeName); - - if (idx == -1) { - std::lock_guard lock(switcher->m); - switcher->executableSwitches.emplace_back( - source, transition, exeName.toUtf8().constData(), - inFocus); - - QListWidgetItem *item = - new QListWidgetItem(text, ui->executables); - item->setData(Qt::UserRole, v); - } else { - QListWidgetItem *item = ui->executables->item(idx); - item->setText(text); - - { - std::lock_guard lock(switcher->m); - for (auto &s : switcher->executableSwitches) { - if (s.exe == exeName) { - s.scene = source; - s.transition = transition; - s.inFocus = inFocus; - break; - } - } - } - } + QListWidgetItem *item; + item = new QListWidgetItem(ui->executables); + ui->executables->addItem(item); + ExecutableSwitchWidget *sw = new ExecutableSwitchWidget( + &switcher->executableSwitches.back()); + item->setSizeHint(sw->minimumSizeHint()); + ui->executables->setItemWidget(item, sw); } void SceneSwitcher::on_executableRemove_clicked() @@ -124,25 +20,57 @@ void SceneSwitcher::on_executableRemove_clicked() if (!item) return; - QString exe = item->data(Qt::UserRole).toString(); - { std::lock_guard lock(switcher->m); + int idx = ui->executables->currentRow(); auto &switches = switcher->executableSwitches; - - for (auto it = switches.begin(); it != switches.end(); ++it) { - auto &s = *it; - - if (s.exe == exe) { - switches.erase(it); - break; - } - } + switches.erase(switches.begin() + idx); } delete item; } +void SceneSwitcher::on_executableUp_clicked() +{ + int index = ui->executables->currentRow(); + if (!listMoveUp(ui->executables)) + return; + + ExecutableSwitchWidget *s1 = + (ExecutableSwitchWidget *)ui->executables->itemWidget( + ui->executables->item(index)); + ExecutableSwitchWidget *s2 = + (ExecutableSwitchWidget *)ui->executables->itemWidget( + ui->executables->item(index - 1)); + ExecutableSwitchWidget::swapSwitchData(s1, s2); + + std::lock_guard lock(switcher->m); + + std::swap(switcher->executableSwitches[index], + switcher->executableSwitches[index - 1]); +} + +void SceneSwitcher::on_executableDown_clicked() +{ + int index = ui->executables->currentRow(); + + if (!listMoveDown(ui->executables)) + return; + + ExecutableSwitchWidget *s1 = + (ExecutableSwitchWidget *)ui->executables->itemWidget( + ui->executables->item(index)); + ExecutableSwitchWidget *s2 = + (ExecutableSwitchWidget *)ui->executables->itemWidget( + ui->executables->item(index + 1)); + ExecutableSwitchWidget::swapSwitchData(s1, s2); + + std::lock_guard lock(switcher->m); + + std::swap(switcher->executableSwitches[index], + switcher->executableSwitches[index + 1]); +} + void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { @@ -170,7 +98,7 @@ void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene, // Check for match GetProcessList(runningProcesses); - for (ExecutableSceneSwitch &s : executableSwitches) { + for (ExecutableSwitch &s : executableSwitches) { // True if executable switch is running (direct) bool equals = runningProcesses.contains(s.exe); // True if executable switch is running (regex) @@ -199,7 +127,7 @@ void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene, void SwitcherData::saveExecutableSwitches(obs_data_t *obj) { obs_data_array_t *executableArray = obs_data_array_create(); - for (ExecutableSceneSwitch &s : switcher->executableSwitches) { + for (ExecutableSwitch &s : switcher->executableSwitches) { obs_data_t *array_obj = obs_data_create(); obs_source_t *source = obs_weak_source_get_source(s.scene); @@ -255,37 +183,96 @@ void SwitcherData::loadExecutableSwitches(obs_data_t *obj) void SceneSwitcher::setupExecutableTab() { - populateSceneSelection(ui->executableScenes, false); - populateTransitionSelection(ui->executableTransitions); - - QStringList processes; - GetProcessList(processes); - for (QString &process : processes) - ui->executable->addItem(process); - for (auto &s : switcher->executableSwitches) { std::string sceneName = GetWeakSourceName(s.scene); std::string transitionName = GetWeakSourceName(s.transition); - QString text = MakeSwitchNameExecutable(sceneName.c_str(), - s.exe, - transitionName.c_str(), - s.inFocus); - QListWidgetItem *item = - new QListWidgetItem(text, ui->executables); - item->setData(Qt::UserRole, s.exe); + QListWidgetItem *item; + item = new QListWidgetItem(ui->executables); + ui->executables->addItem(item); + ExecutableSwitchWidget *sw = new ExecutableSwitchWidget(&s); + item->setSizeHint(sw->minimumSizeHint()); + ui->executables->setItemWidget(item, sw); } } -static inline QString MakeSwitchNameExecutable(const QString &scene, - const QString &value, - const QString &transition, - bool inFocus) +ExecutableSwitchWidget::ExecutableSwitchWidget(ExecutableSwitch *s) + : SwitchWidget(s, false) { - if (!inFocus) - return QStringLiteral("[") + scene + QStringLiteral(", ") + - transition + QStringLiteral("]: ") + value; - return QStringLiteral("[") + scene + QStringLiteral(", ") + transition + - QStringLiteral("]: ") + value + - QStringLiteral(" (only if focused)"); + processes = new QComboBox(); + requiresFocus = new QCheckBox("only if focused"); + + whenLabel = new QLabel("When"); + switchLabel = new QLabel("is running switch to"); + usingLabel = new QLabel("using"); + + QWidget::connect(processes, SIGNAL(currentTextChanged(const QString &)), + this, SLOT(ProcessChanged(const QString &))); + QWidget::connect(requiresFocus, SIGNAL(stateChanged(int)), this, + SLOT(FocusChanged(int))); + + SceneSwitcher::populateProcessSelection(processes); + + if (s) { + scenes->setCurrentText(GetWeakSourceName(s->scene).c_str()); + transitions->setCurrentText( + GetWeakSourceName(s->transition).c_str()); + processes->setCurrentText(s->exe); + requiresFocus->setChecked(s->inFocus); + } + + setStyleSheet("* { background-color: transparent; }"); + + QHBoxLayout *mainLayout = new QHBoxLayout; + + mainLayout->addWidget(whenLabel); + mainLayout->addWidget(processes); + mainLayout->addWidget(switchLabel); + mainLayout->addWidget(scenes); + mainLayout->addWidget(usingLabel); + mainLayout->addWidget(transitions); + mainLayout->addWidget(requiresFocus); + mainLayout->addStretch(); + + setLayout(mainLayout); + + switchData = s; + + loading = false; +} + +ExecutableSwitch *ExecutableSwitchWidget::getSwitchData() +{ + return switchData; +} + +void ExecutableSwitchWidget::setSwitchData(ExecutableSwitch *s) +{ + switchData = s; +} + +void ExecutableSwitchWidget::swapSwitchData(ExecutableSwitchWidget *s1, + ExecutableSwitchWidget *s2) +{ + SwitchWidget::swapSwitchData(s1, s2); + + ExecutableSwitch *t = s1->getSwitchData(); + s1->setSwitchData(s2->getSwitchData()); + s2->setSwitchData(t); +} + +void ExecutableSwitchWidget::ProcessChanged(const QString &text) +{ + if (loading || !switchData) + return; + std::lock_guard lock(switcher->m); + switchData->exe = text; +} + +void ExecutableSwitchWidget::FocusChanged(int state) +{ + if (loading || !switchData) + return; + std::lock_guard lock(switcher->m); + switchData->inFocus = state; } diff --git a/src/switch-generic.cpp b/src/switch-generic.cpp new file mode 100644 index 00000000..05b16369 --- /dev/null +++ b/src/switch-generic.cpp @@ -0,0 +1,81 @@ +#include +#include + +#include "headers/advanced-scene-switcher.hpp" + +bool SceneSwitcherEntry::initialized() +{ + return scene && transition; +} + +bool SceneSwitcherEntry::valid() +{ + return !initialized() || + ((usePreviousScene || WeakSourceValid(scene)) && + WeakSourceValid(transition)); +} + +void SceneSwitcherEntry::logMatch() +{ + obs_source_t *s = obs_weak_source_get_source(scene); + const char *sceneName = obs_source_get_name(s); + obs_source_release(s); + blog(LOG_INFO, "[adv-ss] match for '%s' - switch to scene '%s'", + getType(), sceneName); +} + +SwitchWidget::SwitchWidget(SceneSwitcherEntry *s, bool usePreviousScene) +{ + scenes = new QComboBox(); + transitions = new QComboBox(); + + QWidget::connect(scenes, SIGNAL(currentTextChanged(const QString &)), + this, SLOT(SceneChanged(const QString &))); + QWidget::connect(transitions, + SIGNAL(currentTextChanged(const QString &)), this, + SLOT(TransitionChanged(const QString &))); + + SceneSwitcher::populateSceneSelection(scenes, usePreviousScene); + SceneSwitcher::populateTransitionSelection(transitions); + + if (s) { + scenes->setCurrentText(GetWeakSourceName(s->scene).c_str()); + transitions->setCurrentText( + GetWeakSourceName(s->transition).c_str()); + } + + switchData = s; +} + +SceneSwitcherEntry *SwitchWidget::getSwitchData() +{ + return switchData; +} + +void SwitchWidget::setSwitchData(SceneSwitcherEntry *s) +{ + switchData = s; +} + +void SwitchWidget::swapSwitchData(SwitchWidget *s1, SwitchWidget *s2) +{ + SceneSwitcherEntry *t = s1->getSwitchData(); + s1->setSwitchData(s2->getSwitchData()); + s2->setSwitchData(t); +} + +void SwitchWidget::SceneChanged(const QString &text) +{ + if (loading || !switchData) + return; + std::lock_guard lock(switcher->m); + switchData->scene = GetWeakSourceByQString(text); +} + +void SwitchWidget::TransitionChanged(const QString &text) +{ + if (loading || !switchData) + return; + std::lock_guard lock(switcher->m); + switchData->transition = GetWeakTransitionByQString(text); +} diff --git a/src/switcher-data-structs.cpp b/src/switcher-data-structs.cpp index 83217636..95b2ed8f 100644 --- a/src/switcher-data-structs.cpp +++ b/src/switcher-data-structs.cpp @@ -60,7 +60,7 @@ void SwitcherData::Prune() } for (size_t i = 0; i < executableSwitches.size(); i++) { - ExecutableSceneSwitch &s = executableSwitches[i]; + ExecutableSwitch &s = executableSwitches[i]; if (!s.valid()) executableSwitches.erase(executableSwitches.begin() + i--);