diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index d5054f5e..be79946a 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -15,9 +15,9 @@ SwitcherData *switcher = nullptr; -/******************************************************************************** +/****************************************************************************** * Create the Advanced Scene Switcher settings window - ********************************************************************************/ + ******************************************************************************/ AdvSceneSwitcher::AdvSceneSwitcher(QWidget *parent) : QDialog(parent), ui(new Ui_AdvSceneSwitcher) { @@ -67,9 +67,9 @@ void AdvSceneSwitcher::loadUI() loading = false; } -/******************************************************************************** +/****************************************************************************** * UI helpers - ********************************************************************************/ + ******************************************************************************/ bool AdvSceneSwitcher::DisplayMessage(QString msg, bool question) { if (question) { @@ -137,9 +137,10 @@ void AdvSceneSwitcher::populateSceneSelection(QComboBox *sel, bool addPrevious, temp++; } - if (addPrevious) + if (addPrevious) { sel->addItem(obs_module_text( "AdvSceneSwitcher.selectPreviousScene")); + } if (addSceneGroup) { for (auto &sg : switcher->sceneGroups) { @@ -151,10 +152,11 @@ void AdvSceneSwitcher::populateSceneSelection(QComboBox *sel, bool addPrevious, void AdvSceneSwitcher::populateTransitionSelection(QComboBox *sel, bool addSelect) { - if (addSelect) + if (addSelect) { addSelectionEntry( sel, obs_module_text("AdvSceneSwitcher.selectTransition")); + } obs_frontend_source_list *transitions = new obs_frontend_source_list(); obs_frontend_get_transitions(transitions); @@ -170,9 +172,10 @@ void AdvSceneSwitcher::populateTransitionSelection(QComboBox *sel, void AdvSceneSwitcher::populateWindowSelection(QComboBox *sel, bool addSelect) { - if (addSelect) + if (addSelect) { addSelectionEntry( sel, obs_module_text("AdvSceneSwitcher.selectWindow")); + } std::vector windows; GetWindowList(windows); @@ -190,12 +193,13 @@ void AdvSceneSwitcher::populateWindowSelection(QComboBox *sel, bool addSelect) void AdvSceneSwitcher::populateAudioSelection(QComboBox *sel, bool addSelect) { - if (addSelect) + if (addSelect) { addSelectionEntry( sel, obs_module_text("AdvSceneSwitcher.selectAudioSource"), obs_module_text( "AdvSceneSwitcher.invaildEntriesWillNotBeSaved")); + } auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */ { @@ -219,12 +223,13 @@ void AdvSceneSwitcher::populateAudioSelection(QComboBox *sel, bool addSelect) void AdvSceneSwitcher::populateMediaSelection(QComboBox *sel, bool addSelect) { - if (addSelect) + if (addSelect) { addSelectionEntry( sel, obs_module_text("AdvSceneSwitcher.selectMediaSource"), obs_module_text( "AdvSceneSwitcher.invaildEntriesWillNotBeSaved")); + } auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */ { @@ -248,9 +253,10 @@ void AdvSceneSwitcher::populateMediaSelection(QComboBox *sel, bool addSelect) void AdvSceneSwitcher::populateProcessSelection(QComboBox *sel, bool addSelect) { - if (addSelect) + if (addSelect) { addSelectionEntry( sel, obs_module_text("AdvSceneSwitcher.selectProcess")); + } QStringList processes; GetProcessList(processes); @@ -270,8 +276,9 @@ void AdvSceneSwitcher::listAddClicked(QListWidget *list, return; } - if (addButton && addHighlight) + if (addButton && addHighlight) { addButton->disconnect(*addHighlight); + } QListWidgetItem *item; item = new QListWidgetItem(list); @@ -285,8 +292,9 @@ void AdvSceneSwitcher::listAddClicked(QListWidget *list, bool AdvSceneSwitcher::listMoveUp(QListWidget *list) { int index = list->currentRow(); - if (index == -1 || index == 0) + if (index == -1 || index == 0) { return false; + } QWidget *row = list->itemWidget(list->currentItem()); QListWidgetItem *itemN = list->currentItem()->clone(); @@ -302,8 +310,9 @@ bool AdvSceneSwitcher::listMoveUp(QListWidget *list) bool AdvSceneSwitcher::listMoveDown(QListWidget *list) { int index = list->currentRow(); - if (index == -1 || index == list->count() - 1) + if (index == -1 || index == list->count() - 1) { return false; + } QWidget *row = list->itemWidget(list->currentItem()); QListWidgetItem *itemN = list->currentItem()->clone(); @@ -321,8 +330,9 @@ QMetaObject::Connection AdvSceneSwitcher::PulseWidget(QWidget *widget, QColor startColor, QString specifier) { - if (switcher->disableHints) + if (switcher->disableHints) { return QMetaObject::Connection(); + } widget->setStyleSheet(specifier + "{ \ border-style: outset; \ @@ -338,7 +348,7 @@ QMetaObject::Connection AdvSceneSwitcher::PulseWidget(QWidget *widget, paAnimation->setStartValue(startColor); paAnimation->setEndValue(endColor); paAnimation->setDuration(1000); - // play backward to return to original state on timer end + // Play backwards to return to original state on timer end paAnimation->setDirection(QAbstractAnimation::Backward); auto con = QWidget::connect( @@ -353,9 +363,9 @@ QMetaObject::Connection AdvSceneSwitcher::PulseWidget(QWidget *widget, return con; } -/******************************************************************************** +/****************************************************************************** * Saving and loading - ********************************************************************************/ + ******************************************************************************/ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *) { if (saving) { @@ -376,10 +386,12 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *) obs_data_t *obj = obs_data_get_obj(save_data, "advanced-scene-switcher"); - if (!obj) + if (!obj) { obj = obs_data_create(); - if (switcher->versionChanged(obj, g_GIT_SHA1)) + } + if (switcher->versionChanged(obj, g_GIT_SHA1)) { AdvSceneSwitcher::AskBackup(obj); + } switcher->loadSettings(obj); @@ -387,18 +399,19 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *) switcher->m.unlock(); - // stop the scene switcher at least once - // to avoid issues with scene collection changes + // Stop the scene switcher at least once to + // avoid scene duplication issues with scene collection changes bool start = !switcher->stop; switcher->Stop(); - if (start) + if (start) { switcher->Start(); + } } } -/******************************************************************************** +/****************************************************************************** * Main switcher thread - ********************************************************************************/ + ******************************************************************************/ void SwitcherData::Thread() { blog(LOG_INFO, "started"); @@ -436,9 +449,7 @@ void SwitcherData::Thread() } } - //sleep for a bit - if (verbose) - blog(LOG_INFO, "sleep for %ld", duration.count()); + vblog(LOG_INFO, "sleep for %ld", duration.count()); cv.wait_for(lock, duration); startTime = std::chrono::high_resolution_clock::now(); @@ -507,10 +518,8 @@ void SwitcherData::Thread() if (linger) { duration = std::chrono::milliseconds(linger); - if (verbose) - blog(LOG_INFO, - "sleep for %ld before switching scene", - duration.count()); + vblog(LOG_INFO, "sleep for %ld before switching scene", + duration.count()); cv.wait_for(lock, duration); @@ -519,9 +528,9 @@ void SwitcherData::Thread() } if (sceneChangedDuringWait()) { - if (verbose) - blog(LOG_INFO, - "scene was changed manually - ignoring match"); + vblog(LOG_INFO, + "scene was changed manually - ignoring match"); + match = false; linger = 0; } @@ -566,11 +575,13 @@ void switchScene(OBSWeakSource &scene, OBSWeakSource &transition, setNextTransition(scene, currentSource, transition, transitionOverrideOverride, td); obs_frontend_set_current_scene(source); - if (transitionOverrideOverride) + if (transitionOverrideOverride) { restoreTransitionOverride(source, td); + } - if (switcher->verbose) + if (switcher->verbose) { blog(LOG_INFO, "switched scene"); + } } obs_source_release(currentSource); obs_source_release(source); @@ -606,20 +617,22 @@ void SwitcherData::Stop() bool SwitcherData::sceneChangedDuringWait() { obs_source_t *currentSource = obs_frontend_get_current_scene(); - if (!currentSource) + if (!currentSource) { return true; + } obs_source_release(currentSource); return (waitScene && currentSource != waitScene); } -/******************************************************************************** +/****************************************************************************** * OBS module setup - ********************************************************************************/ + ******************************************************************************/ extern "C" void FreeSceneSwitcher() { if (loaded_curl_lib) { - if (switcher->curl && f_curl_cleanup) + if (switcher->curl && f_curl_cleanup) { f_curl_cleanup(switcher->curl); + } delete loaded_curl_lib; loaded_curl_lib = nullptr; } @@ -630,11 +643,12 @@ extern "C" void FreeSceneSwitcher() void handleSceneChange(SwitcherData *s) { - //stop waiting if scene was manually changed - if (s->sceneChangedDuringWait()) + // Stop waiting if scene was manually changed + if (s->sceneChangedDuringWait()) { s->cv.notify_one(); + } - //set previous scene + // Set previous scene obs_source_t *source = obs_frontend_get_current_scene(); obs_weak_source_t *ws = obs_source_get_weak_source(source); obs_source_release(source); diff --git a/src/curl-helper.cpp b/src/curl-helper.cpp index 30f16977..4039246f 100644 --- a/src/curl-helper.cpp +++ b/src/curl-helper.cpp @@ -54,9 +54,9 @@ bool loadCurl() libFilePath.toUtf8().constData()); loaded_curl_lib = new QLibrary(libFilePath, nullptr); - if (resolveCurl()) + if (resolveCurl()) { return true; - else { + } else { delete loaded_curl_lib; loaded_curl_lib = nullptr; } diff --git a/src/general.cpp b/src/general.cpp index f6cc1c77..162fabc6 100644 --- a/src/general.cpp +++ b/src/general.cpp @@ -26,8 +26,9 @@ void AdvSceneSwitcher::UpdateNonMatchingScene(const QString &name) void AdvSceneSwitcher::on_noMatchDontSwitch_clicked() { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); switcher->switchIfNotMatching = NO_SWITCH; @@ -37,8 +38,9 @@ void AdvSceneSwitcher::on_noMatchDontSwitch_clicked() void AdvSceneSwitcher::on_noMatchSwitch_clicked() { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); switcher->switchIfNotMatching = SWITCH; @@ -49,8 +51,9 @@ void AdvSceneSwitcher::on_noMatchSwitch_clicked() void AdvSceneSwitcher::on_noMatchRandomSwitch_clicked() { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); switcher->switchIfNotMatching = RANDOM_SWITCH; @@ -60,16 +63,19 @@ void AdvSceneSwitcher::on_noMatchRandomSwitch_clicked() void AdvSceneSwitcher::on_noMatchDelay_valueChanged(double i) { - if (loading) + if (loading) { return; + } + std::lock_guard lock(switcher->m); switcher->noMatchDelay = i; } void AdvSceneSwitcher::on_startupBehavior_currentIndexChanged(int index) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); switcher->startupBehavior = (StartupBehavior)index; @@ -77,8 +83,9 @@ void AdvSceneSwitcher::on_startupBehavior_currentIndexChanged(int index) void AdvSceneSwitcher::on_autoStartEvent_currentIndexChanged(int index) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); switcher->autoStartEvent = static_cast(index); @@ -87,8 +94,9 @@ void AdvSceneSwitcher::on_autoStartEvent_currentIndexChanged(int index) void AdvSceneSwitcher::on_noMatchSwitchScene_currentTextChanged( const QString &text) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); UpdateNonMatchingScene(text); @@ -96,16 +104,19 @@ void AdvSceneSwitcher::on_noMatchSwitchScene_currentTextChanged( void AdvSceneSwitcher::on_cooldownTime_valueChanged(double i) { - if (loading) + if (loading) { return; + } + std::lock_guard lock(switcher->m); switcher->cooldown = i; } void AdvSceneSwitcher::on_checkInterval_valueChanged(int value) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); switcher->interval = value; @@ -148,15 +159,19 @@ void AdvSceneSwitcher::closeEvent(QCloseEvent *) void AdvSceneSwitcher::on_verboseLogging_stateChanged(int state) { - if (loading) + if (loading) { return; + } + switcher->verbose = state; } void AdvSceneSwitcher::on_uiHintsDisable_stateChanged(int state) { - if (loading) + if (loading) { return; + } + switcher->disableHints = state; } @@ -165,8 +180,9 @@ void AdvSceneSwitcher::AskBackup(obs_data_t *obj) bool backupSettings = DisplayMessage( obs_module_text("AdvSceneSwitcher.askBackup"), true); - if (!backupSettings) + if (!backupSettings) { return; + } QString directory = QFileDialog::getSaveFileName( nullptr, @@ -175,12 +191,14 @@ void AdvSceneSwitcher::AskBackup(obs_data_t *obj) QDir::currentPath(), obs_module_text( "AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType")); - if (directory.isEmpty()) + if (directory.isEmpty()) { return; + } QFile file(directory); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { return; + } obs_data_save_json(obj, file.fileName().toUtf8().constData()); } @@ -194,12 +212,14 @@ void AdvSceneSwitcher::on_exportSettings_clicked() QDir::currentPath(), tr(obs_module_text( "AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType"))); - if (directory.isEmpty()) + if (directory.isEmpty()) { return; + } QFile file(directory); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { return; + } obs_data_t *obj = obs_data_create(); @@ -212,7 +232,7 @@ void AdvSceneSwitcher::on_exportSettings_clicked() void AdvSceneSwitcher::on_importSettings_clicked() { - // scene switcher could be stuck in a sequence + // Scene switcher could be stuck in a sequence // so it needs to be stopped before importing new settings bool start = !switcher->stop; switcher->Stop(); @@ -226,12 +246,14 @@ void AdvSceneSwitcher::on_importSettings_clicked() QDir::currentPath(), tr(obs_module_text( "AdvSceneSwitcher.generalTab.saveOrLoadsettings.textType"))); - if (directory.isEmpty()) + if (directory.isEmpty()) { return; + } QFile file(directory); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return; + } obs_data_t *obj = obs_data_create_from_json_file( file.fileName().toUtf8().constData()); @@ -250,9 +272,10 @@ void AdvSceneSwitcher::on_importSettings_clicked() "AdvSceneSwitcher.generalTab.saveOrLoadsettings.loadSuccess")); close(); - // restart scene switcher if it was active - if (start) + // Restart scene switcher if it was active + if (start) { switcher->Start(); + } } int findTabIndex(QTabWidget *tabWidget, int pos) @@ -312,9 +335,10 @@ int findTabIndex(QTabWidget *tabWidget, int pos) if (page) { at = tabWidget->indexOf(page); } - if (at == -1) + if (at == -1) { blog(LOG_INFO, "failed to find tab %s", tabName.toUtf8().constData()); + } return at; } @@ -325,8 +349,9 @@ void AdvSceneSwitcher::setTabOrder() for (int i = 0; i < bar->count(); ++i) { int curPos = findTabIndex(ui->tabWidget, switcher->tabOrder[i]); - if (i != curPos && curPos != -1) + if (i != curPos && curPos != -1) { bar->moveTab(curPos, i); + } } connect(bar, &QTabBar::tabMoved, this, &AdvSceneSwitcher::on_tabMoved); @@ -334,8 +359,10 @@ void AdvSceneSwitcher::setTabOrder() void AdvSceneSwitcher::on_tabMoved(int from, int to) { - if (loading) + if (loading) { return; + } + std::swap(switcher->tabOrder[from], switcher->tabOrder[to]); } @@ -350,8 +377,9 @@ void AdvSceneSwitcher::on_tabWidget_currentChanged(int index) void SwitcherData::loadSettings(obs_data_t *obj) { - if (!obj) + if (!obj) { return; + } switcher->loadSceneGroups(obj); switcher->loadWindowTitleSwitches(obj); @@ -373,8 +401,9 @@ void SwitcherData::loadSettings(obs_data_t *obj) void SwitcherData::saveSettings(obs_data_t *obj) { - if (!obj) + if (!obj) { return; + } saveSceneGroups(obj); saveWindowTitleSwitches(obj); @@ -483,10 +512,12 @@ void SwitcherData::loadGeneralSettings(obs_data_t *obj) switcher->stop = !obs_data_get_bool(obj, "active"); switcher->startupBehavior = (StartupBehavior)obs_data_get_int(obj, "startup_behavior"); - if (switcher->startupBehavior == START) + if (switcher->startupBehavior == START) { switcher->stop = false; - if (switcher->startupBehavior == STOP) + } + if (switcher->startupBehavior == STOP) { switcher->stop = true; + } switcher->autoStartEvent = static_cast( obs_data_get_int(obj, "autoStartEvent")); @@ -625,8 +656,7 @@ void SwitcherData::checkSwitchCooldown(bool &match) } match = false; - if (verbose) - blog(LOG_INFO, "cooldown active - ignoring match"); + vblog(LOG_INFO, "cooldown active - ignoring match"); } void populateStartupBehavior(QComboBox *cb) @@ -745,8 +775,9 @@ void AdvSceneSwitcher::setupGeneralTab() ui->autoStartEvent->setCurrentIndex( static_cast(switcher->autoStartEvent)); - if (switcher->th && switcher->th->isRunning()) + if (switcher->th && switcher->th->isRunning()) { SetStarted(); - else + } else { SetStopped(); + } } diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index d03b3544..d818c0a0 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -7,6 +7,10 @@ #include "switcher-data-structs.hpp" #define blog(level, msg, ...) blog(level, "[adv-ss] " msg, ##__VA_ARGS__) +#define vblog(level, msg, ...) \ + if (verbose) { \ + blog(level, "[adv-ss] " msg, ##__VA_ARGS__); \ + } class QCloseEvent; @@ -215,34 +219,34 @@ public slots: private: }; -/******************************************************************************** +/****************************************************************************** * Windowtitle helper - ********************************************************************************/ + ******************************************************************************/ void GetWindowList(std::vector &windows); -void GetWindowList(QStringList &windows); // Overloaded +void GetWindowList(QStringList &windows); void GetCurrentWindowTitle(std::string &title); bool isFullscreen(std::string &title); bool isMaximized(std::string &title); -/******************************************************************************** +/****************************************************************************** * Screenregion helper - ********************************************************************************/ + ******************************************************************************/ std::pair getCursorPos(); -/******************************************************************************** +/****************************************************************************** * Idle detection helper - ********************************************************************************/ + ******************************************************************************/ int secondsSinceLastInput(); -/******************************************************************************** +/****************************************************************************** * Executable helper - ********************************************************************************/ + ******************************************************************************/ void GetProcessList(QStringList &processes); bool isInFocus(const QString &executable); -/******************************************************************************** +/****************************************************************************** * Sceneswitch helper - ********************************************************************************/ + ******************************************************************************/ void setNextTransition(OBSWeakSource &targetScene, obs_source_t *currentSource, OBSWeakSource &transition, @@ -253,8 +257,8 @@ void restoreTransitionOverride(obs_source_t *scene, transitionData td); void switchScene(OBSWeakSource &scene, OBSWeakSource &transition, bool &transitionOverrideOverride); -/******************************************************************************** +/****************************************************************************** * Main SwitcherData - ********************************************************************************/ + ******************************************************************************/ struct SwitcherData; extern SwitcherData *switcher; diff --git a/src/headers/scene-group.hpp b/src/headers/scene-group.hpp index a8794831..8aa879c4 100644 --- a/src/headers/scene-group.hpp +++ b/src/headers/scene-group.hpp @@ -19,6 +19,7 @@ enum class AdvanceCondition { }; struct SceneGroup { + OBSWeakSource getCurrentScene(); OBSWeakSource getNextScene(); OBSWeakSource getNextSceneCount(); OBSWeakSource getNextSceneTime(); diff --git a/src/headers/switch-generic.hpp b/src/headers/switch-generic.hpp index 993f5242..071e31d7 100644 --- a/src/headers/switch-generic.hpp +++ b/src/headers/switch-generic.hpp @@ -67,6 +67,7 @@ public: bool usePreviousScene = true, bool addSceneGroup = false); virtual SceneSwitcherEntry *getSwitchData(); virtual void setSwitchData(SceneSwitcherEntry *s); + void showSwitchData(); static void swapSwitchData(SwitchWidget *s1, SwitchWidget *s2); diff --git a/src/headers/switch-media.hpp b/src/headers/switch-media.hpp index 4cdb5749..e5049461 100644 --- a/src/headers/switch-media.hpp +++ b/src/headers/switch-media.hpp @@ -20,13 +20,13 @@ struct MediaSwitch : SceneSwitcherEntry { time_restriction restriction = TIME_RESTRICTION_NONE; int64_t time = 0; - // trigger scene change only once even if media state might trigger repeatedly + // Trigger scene change only once even if media state might trigger repeatedly bool matched = false; std::atomic_bool stopped = {false}; std::atomic_bool ended = {false}; - // workaround to enable use of "ended" to specify end of VLC playlist + // Workaround to enable use of "ended" to specify end of VLC playlist bool previousStateEnded = false; bool playedToEnd = false; diff --git a/src/headers/utility.hpp b/src/headers/utility.hpp index 5c7a8777..fcc1525e 100644 --- a/src/headers/utility.hpp +++ b/src/headers/utility.hpp @@ -11,16 +11,18 @@ static inline bool SceneGroupValid(SceneGroup *group) { - if (group) + if (group) { return group->name != invalid_scene_group_name; + } return false; } static inline bool WeakSourceValid(obs_weak_source_t *ws) { obs_source_t *source = obs_weak_source_get_source(ws); - if (source) + if (source) { obs_source_release(source); + } return !!source; } @@ -39,8 +41,9 @@ static inline std::string GetWeakSourceName(obs_weak_source_t *weak_source) static inline SceneGroup *GetSceneGroupByName(const char *name) { - if (!switcher) + if (!switcher) { return nullptr; + } for (SceneGroup &sg : switcher->sceneGroups) { if (sg.name == name) { @@ -130,8 +133,9 @@ getNextDelim(std::string text, } } - if (pos == std::string::npos) + if (pos == std::string::npos) { return ""; + } return res; } @@ -167,11 +171,14 @@ placeWidgets(std::string text, QBoxLayout *layout, } for (auto &lw : labelsWidgetsPairs) { - if (lw.first != "") + if (lw.first != "") { layout->addWidget(new QLabel(lw.first.c_str())); - if (lw.second) + } + if (lw.second) { layout->addWidget(lw.second); + } } - if (addStretch) + if (addStretch) { layout->addStretch(); + } } diff --git a/src/hotkey.cpp b/src/hotkey.cpp index 8b1e94a1..e785f4b8 100644 --- a/src/hotkey.cpp +++ b/src/hotkey.cpp @@ -11,8 +11,9 @@ void startHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, UNUSED_PARAMETER(hotkey); if (pressed) { - if (!(switcher->th && switcher->th->isRunning())) + if (!(switcher->th && switcher->th->isRunning())) { switcher->Start(); + } } } @@ -24,8 +25,9 @@ void stopHotkeyFunc(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, UNUSED_PARAMETER(hotkey); if (pressed) { - if (switcher->th && switcher->th->isRunning()) + if (switcher->th && switcher->th->isRunning()) { switcher->Stop(); + } } } @@ -37,10 +39,11 @@ void startStopToggleHotkeyFunc(void *data, obs_hotkey_id id, UNUSED_PARAMETER(hotkey); if (pressed) { - if (switcher->th && switcher->th->isRunning()) + if (switcher->th && switcher->th->isRunning()) { switcher->Stop(); - else + } else { switcher->Start(); + } } } @@ -84,8 +87,9 @@ void SwitcherData::saveHotkeys(obs_data_t *obj) void SwitcherData::loadHotkeys(obs_data_t *obj) { - if (!switcher->hotkeysRegistered) + if (!switcher->hotkeysRegistered) { registerHotkeys(); + } obs_data_array_t *startHotkeyArrray = obs_data_get_array(obj, "startHotkey"); diff --git a/src/scene-group.cpp b/src/scene-group.cpp index b4806d0b..22e32625 100644 --- a/src/scene-group.cpp +++ b/src/scene-group.cpp @@ -12,10 +12,11 @@ void SceneGroup::advanceIdx() currentIdx++; if (currentIdx >= scenes.size()) { - if (repeat) + if (repeat) { currentIdx = 0; - else + } else { currentIdx = scenes.size() - 1; + } } } @@ -31,8 +32,9 @@ OBSWeakSource SceneGroup::getNextSceneCount() OBSWeakSource SceneGroup::getNextSceneTime() { - if (lastAdvTime.time_since_epoch().count() == 0) + if (lastAdvTime.time_since_epoch().count() == 0) { lastAdvTime = std::chrono::high_resolution_clock::now(); + } auto now = std::chrono::high_resolution_clock::now(); auto passedTime = std::chrono::duration_cast( @@ -48,16 +50,19 @@ OBSWeakSource SceneGroup::getNextSceneTime() OBSWeakSource SceneGroup::getNextSceneRandom() { - if (scenes.size() == 1) + if (scenes.size() == 1) { return *scenes.begin(); + } std::vector rs(scenes); std::random_device rng; std::mt19937 urng(rng()); std::shuffle(rs.begin(), rs.end(), urng); for (OBSWeakSource &s : rs) { - if (s == lastRandomScene) + if (s == lastRandomScene) { continue; + } + lastRandomScene = s; return s; @@ -65,10 +70,16 @@ OBSWeakSource SceneGroup::getNextSceneRandom() return nullptr; } +OBSWeakSource SceneGroup::getCurrentScene() +{ + return scenes[currentIdx]; +} + OBSWeakSource SceneGroup::getNextScene() { - if (scenes.empty()) + if (scenes.empty()) { return nullptr; + } switch (type) { case AdvanceCondition::Count: @@ -95,8 +106,9 @@ bool sceneGroupNameExists(std::string name) } for (SceneGroup &sg : switcher->sceneGroups) { - if (sg.name == name) + if (sg.name == name) { return true; + } } return (name == obs_module_text( @@ -154,8 +166,9 @@ void AdvSceneSwitcher::on_sceneGroupAdd_clicked() void AdvSceneSwitcher::on_sceneGroupRemove_clicked() { QListWidgetItem *item = ui->sceneGroups->currentItem(); - if (!item) + if (!item) { return; + } QString name; { @@ -206,8 +219,9 @@ SceneGroup *getSelectedSG(Ui_AdvSceneSwitcher *ui) SceneGroup *currentSG = nullptr; QListWidgetItem *sgItem = ui->sceneGroups->currentItem(); - if (!sgItem) + if (!sgItem) { return currentSG; + } QString sgName = sgItem->data(Qt::UserRole).toString(); for (auto &sg : switcher->sceneGroups) { @@ -225,8 +239,9 @@ void AdvSceneSwitcher::on_sceneGroupName_editingFinished() bool nameValid = true; SceneGroup *currentSG = getSelectedSG(ui.get()); - if (!currentSG) + if (!currentSG) { return; + } QString newName = ui->sceneGroupName->text(); QString oldName = QString::fromStdString(currentSG->name); @@ -282,8 +297,10 @@ void AdvSceneSwitcher::SetEditSceneGroup(SceneGroup &sg) void AdvSceneSwitcher::on_sceneGroups_currentRowChanged(int idx) { - if (loading) + if (loading) { return; + } + if (idx == -1) { ui->sceneGroupEdit->setDisabled(true); return; @@ -304,17 +321,20 @@ void AdvSceneSwitcher::on_sceneGroupSceneAdd_clicked() { std::lock_guard lock(switcher->m); SceneGroup *currentSG = getSelectedSG(ui.get()); - if (!currentSG) + if (!currentSG) { return; + } QString sceneName = ui->sceneGroupSceneSelection->currentText(); - if (sceneName.isEmpty()) + if (sceneName.isEmpty()) { return; + } OBSWeakSource source = GetWeakSourceByQString(sceneName); - if (!source) + if (!source) { return; + } QVariant v = QVariant::fromValue(sceneName); QListWidgetItem *item = @@ -330,12 +350,14 @@ void AdvSceneSwitcher::on_sceneGroupSceneRemove_clicked() { std::lock_guard lock(switcher->m); SceneGroup *currentSG = getSelectedSG(ui.get()); - if (!currentSG) + if (!currentSG) { return; + } int idx = ui->sceneGroupScenes->currentRow(); - if (idx == -1) + if (idx == -1) { return; + } auto &scenes = currentSG->scenes; scenes.erase(scenes.begin() + idx); @@ -348,8 +370,9 @@ void AdvSceneSwitcher::on_sceneGroupSceneUp_clicked() { std::lock_guard lock(switcher->m); SceneGroup *currentSG = getSelectedSG(ui.get()); - if (!currentSG) + if (!currentSG) { return; + } int index = ui->sceneGroupScenes->currentRow(); if (index != -1 && index != 0) { @@ -366,8 +389,9 @@ void AdvSceneSwitcher::on_sceneGroupSceneDown_clicked() { std::lock_guard lock(switcher->m); SceneGroup *currentSG = getSelectedSG(ui.get()); - if (!currentSG) + if (!currentSG) { return; + } int index = ui->sceneGroupScenes->currentRow(); if (index != -1 && index != ui->sceneGroupScenes->count() - 1) { @@ -528,8 +552,9 @@ bool SGNameDialog::AskForName(QWidget *parent, const QString &title, const QString &text, std::string &userTextInput, const QString &placeHolder, int maxSize) { - if (maxSize <= 0 || maxSize > 32767) + if (maxSize <= 0 || maxSize > 32767) { maxSize = 170; + } SGNameDialog dialog(parent); dialog.setWindowTitle(title); @@ -559,7 +584,6 @@ void populateTypeSelection(QComboBox *list) SceneGroupEditWidget::SceneGroupEditWidget() { - //w->setContentsMargins(0, 0, 0, 0); type = new QComboBox(); populateTypeSelection(type); @@ -639,8 +663,9 @@ SceneGroupEditWidget::SceneGroupEditWidget() void SceneGroupEditWidget::ShowCurrentTypeEdit() { - if (!sceneGroup) + if (!sceneGroup) { return; + } countEdit->setVisible(false); timeEdit->setVisible(false); @@ -664,8 +689,10 @@ void SceneGroupEditWidget::ShowCurrentTypeEdit() void SceneGroupEditWidget::SetEditSceneGroup(SceneGroup *sg) { - if (!sg) + if (!sg) { return; + } + sceneGroup = sg; type->setCurrentIndex(static_cast(sg->type)); count->setValue(sg->count); @@ -676,8 +703,9 @@ void SceneGroupEditWidget::SetEditSceneGroup(SceneGroup *sg) void SceneGroupEditWidget::TypeChanged(int type) { - if (!sceneGroup) + if (!sceneGroup) { return; + } std::lock_guard lock(switcher->m); sceneGroup->type = static_cast(type); @@ -687,24 +715,30 @@ void SceneGroupEditWidget::TypeChanged(int type) void SceneGroupEditWidget::CountChanged(int count) { - if (!sceneGroup) + if (!sceneGroup) { return; + } + std::lock_guard lock(switcher->m); sceneGroup->count = count; } void SceneGroupEditWidget::TimeChanged(double time) { - if (!sceneGroup) + if (!sceneGroup) { return; + } + std::lock_guard lock(switcher->m); sceneGroup->time = time; } void SceneGroupEditWidget::RepeatChanged(int state) { - if (!sceneGroup) + if (!sceneGroup) { return; + } + std::lock_guard lock(switcher->m); sceneGroup->repeat = state; } diff --git a/src/scene-trigger.cpp b/src/scene-trigger.cpp index 1d3840fc..5b8cd5b3 100644 --- a/src/scene-trigger.cpp +++ b/src/scene-trigger.cpp @@ -22,8 +22,9 @@ void AdvSceneSwitcher::on_triggerAdd_clicked() void AdvSceneSwitcher::on_triggerRemove_clicked() { QListWidgetItem *item = ui->sceneTriggers->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -38,8 +39,9 @@ void AdvSceneSwitcher::on_triggerRemove_clicked() void AdvSceneSwitcher::on_triggerUp_clicked() { int index = ui->sceneTriggers->currentRow(); - if (!listMoveUp(ui->sceneTriggers)) + if (!listMoveUp(ui->sceneTriggers)) { return; + } SceneTriggerWidget *s1 = (SceneTriggerWidget *)ui->sceneTriggers->itemWidget( @@ -59,8 +61,9 @@ void AdvSceneSwitcher::on_triggerDown_clicked() { int index = ui->sceneTriggers->currentRow(); - if (!listMoveDown(ui->sceneTriggers)) + if (!listMoveDown(ui->sceneTriggers)) { return; + } SceneTriggerWidget *s1 = (SceneTriggerWidget *)ui->sceneTriggers->itemWidget( @@ -205,15 +208,18 @@ bool isFrontendAction(sceneTriggerAction triggerAction) void SceneTrigger::performAction() { - if (triggerAction == sceneTriggerAction::NONE) + if (triggerAction == sceneTriggerAction::NONE) { return; + } std::thread t; - if (isFrontendAction(triggerAction)) + if (isFrontendAction(triggerAction)) { t = std::thread(frontEndActionThread, triggerAction, duration); - else + } else { t = std::thread(muteThread, audioSource, duration); + } + t.detach(); } @@ -488,10 +494,12 @@ SceneTriggerWidget::SceneTriggerWidget(QWidget *parent, SceneTrigger *s) audioSources->setCurrentText( GetWeakSourceName(s->audioSource).c_str()); - if (s->triggerAction == sceneTriggerAction::MUTE_SOURCE) + + if (s->triggerAction == sceneTriggerAction::MUTE_SOURCE) { audioSources->show(); - else + } else { audioSources->hide(); + } } QHBoxLayout *mainLayout = new QHBoxLayout; @@ -532,40 +540,50 @@ void SceneTriggerWidget::swapSwitchData(SceneTriggerWidget *s1, void SceneTriggerWidget::TriggerTypeChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->triggerType = static_cast(index); } void SceneTriggerWidget::TriggerActionChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + { std::lock_guard lock(switcher->m); switchData->triggerAction = static_cast(index); } - if (switchData->triggerAction == sceneTriggerAction::MUTE_SOURCE) + if (switchData->triggerAction == sceneTriggerAction::MUTE_SOURCE) { audioSources->show(); - else + } else { audioSources->hide(); + } } void SceneTriggerWidget::DurationChanged(double dur) { - if (loading || !switchData) + + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->duration = dur; } void SceneTriggerWidget::AudioSourceChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->audioSource = GetWeakSourceByQString(text); } diff --git a/src/switch-audio.cpp b/src/switch-audio.cpp index f6fd7510..fc3eef50 100644 --- a/src/switch-audio.cpp +++ b/src/switch-audio.cpp @@ -23,8 +23,9 @@ void AdvSceneSwitcher::on_audioAdd_clicked() void AdvSceneSwitcher::on_audioRemove_clicked() { QListWidgetItem *item = ui->audioSwitches->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -39,8 +40,9 @@ void AdvSceneSwitcher::on_audioRemove_clicked() void AdvSceneSwitcher::on_audioUp_clicked() { int index = ui->audioSwitches->currentRow(); - if (!listMoveUp(ui->audioSwitches)) + if (!listMoveUp(ui->audioSwitches)) { return; + } AudioSwitchWidget *s1 = (AudioSwitchWidget *)ui->audioSwitches->itemWidget( @@ -60,8 +62,9 @@ void AdvSceneSwitcher::on_audioDown_clicked() { int index = ui->audioSwitches->currentRow(); - if (!listMoveDown(ui->audioSwitches)) + if (!listMoveDown(ui->audioSwitches)) { return; + } AudioSwitchWidget *s1 = (AudioSwitchWidget *)ui->audioSwitches->itemWidget( @@ -79,8 +82,10 @@ void AdvSceneSwitcher::on_audioDown_clicked() void AdvSceneSwitcher::on_audioFallback_toggled(bool on) { - if (loading || !switcher) + if (loading || !switcher) { return; + } + std::lock_guard lock(switcher->m); switcher->audioFallback.enable = on; } @@ -98,8 +103,9 @@ void SwitcherData::checkAudioSwitchFallback(OBSWeakSource &scene, scene = audioFallback.getScene(); transition = audioFallback.transition; - if (verbose) + if (verbose) { audioFallback.logMatch(); + } } audioFallback.matchCount++; @@ -108,14 +114,16 @@ void SwitcherData::checkAudioSwitchFallback(OBSWeakSource &scene, void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (AudioSwitch::pause) + if (AudioSwitch::pause) { return; + } - bool fallbackChecked = false; // false if one or no match + bool fallbackChecked = false; // false if only one or no match for (AudioSwitch &s : audioSwitches) { - if (!s.initialized()) + if (!s.initialized()) { continue; + } obs_source_t *as = obs_weak_source_get_source(s.audioSource); bool audioActive = obs_source_active(as); @@ -124,14 +132,15 @@ void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene, // peak will have a value from -60 db to 0 db bool volumeThresholdreached = false; - if (s.condition == ABOVE) + if (s.condition == ABOVE) { volumeThresholdreached = ((double)s.peak + 60) * 1.7 > s.volumeThreshold; - else + } else { volumeThresholdreached = ((double)s.peak + 60) * 1.7 < s.volumeThreshold; + } - // reset for next check + // Reset for next check s.peak = -FLT_MAX; if (volumeThresholdreached) { @@ -156,16 +165,19 @@ void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene, transition = s.transition; match = true; - if (verbose) + if (verbose) { s.logMatch(); + } - if (!audioFallback.enable) + if (!audioFallback.enable) { break; + } } } - if (!fallbackChecked) + if (!fallbackChecked) { audioFallback.matchCount = 0; + } } void SwitcherData::saveAudioSwitches(obs_data_t *obj) @@ -238,9 +250,11 @@ void AudioSwitch::setVolumeLevel(void *data, UNUSED_PARAMETER(inputPeak); AudioSwitch *s = static_cast(data); - for (int i = 1; i < MAX_AUDIO_CHANNELS; i++) - if (peak[i] > s->peak) + for (int i = 1; i < MAX_AUDIO_CHANNELS; i++) { + if (peak[i] > s->peak) { s->peak = peak[i]; + } + } } obs_volmeter_t *AddVolmeterToSource(AudioSwitch *entry, obs_weak_source *source) @@ -281,10 +295,8 @@ void AudioSwitch::save(obs_data_t *obj) { SceneSwitcherEntry::save(obj); - obs_source_t *source = obs_weak_source_get_source(audioSource); - const char *audioSourceName = obs_source_get_name(source); - obs_data_set_string(obj, "audioSource", audioSourceName); - obs_source_release(source); + obs_data_set_string(obj, "audioSource", + GetWeakSourceName(audioSource).c_str()); obs_data_set_int(obj, "volume", volumeThreshold); obs_data_set_int(obj, "condition", condition); @@ -294,13 +306,15 @@ void AudioSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldAudio(obs_data_t *obj, AudioSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene = obs_data_get_string(obj, "scene"); - if (strcmp(scene, "") == 0) + if (strcmp(scene, "") == 0) { return false; + } s->scene = GetWeakSourceByName(scene); @@ -320,8 +334,9 @@ bool loadOldAudio(obs_data_t *obj, AudioSwitch *s) void AudioSwitch::load(obs_data_t *obj) { - if (loadOldAudio(obj, this)) + if (loadOldAudio(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -439,11 +454,12 @@ AudioSwitchWidget::AudioSwitchWidget(QWidget *parent, AudioSwitch *s) audioVolumeThreshold = new QSpinBox(); duration = new QDoubleSpinBox(); - obs_source_t *soruce = nullptr; - if (s) - soruce = obs_weak_source_get_source(s->audioSource); - volMeter = new VolControl(soruce); - obs_source_release(soruce); + obs_source_t *source = nullptr; + if (s) { + source = obs_weak_source_get_source(s->audioSource); + } + volMeter = new VolControl(source); + obs_source_release(source); audioVolumeThreshold->setSuffix("%"); audioVolumeThreshold->setMaximum(100); @@ -543,8 +559,10 @@ void AudioSwitchWidget::UpdateVolmeterSource() void AudioSwitchWidget::SourceChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->audioSource = GetWeakSourceByQString(text); switchData->resetVolmeter(); @@ -553,24 +571,30 @@ void AudioSwitchWidget::SourceChanged(const QString &text) void AudioSwitchWidget::VolumeThresholdChanged(int vol) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->volumeThreshold = vol; } void AudioSwitchWidget::ConditionChanged(int cond) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->condition = (audioCondition)cond; } void AudioSwitchWidget::DurationChanged(double dur) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->duration = dur; } @@ -609,8 +633,10 @@ AudioSwitchFallbackWidget::AudioSwitchFallbackWidget(QWidget *parent, void AudioSwitchFallbackWidget::DurationChanged(double dur) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->duration = dur; } diff --git a/src/switch-executable.cpp b/src/switch-executable.cpp index 88166ee1..c67ced0e 100644 --- a/src/switch-executable.cpp +++ b/src/switch-executable.cpp @@ -20,8 +20,9 @@ void AdvSceneSwitcher::on_executableAdd_clicked() void AdvSceneSwitcher::on_executableRemove_clicked() { QListWidgetItem *item = ui->executables->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -36,8 +37,9 @@ void AdvSceneSwitcher::on_executableRemove_clicked() void AdvSceneSwitcher::on_executableUp_clicked() { int index = ui->executables->currentRow(); - if (!listMoveUp(ui->executables)) + if (!listMoveUp(ui->executables)) { return; + } ExecutableSwitchWidget *s1 = (ExecutableSwitchWidget *)ui->executables->itemWidget( @@ -57,8 +59,9 @@ void AdvSceneSwitcher::on_executableDown_clicked() { int index = ui->executables->currentRow(); - if (!listMoveDown(ui->executables)) + if (!listMoveDown(ui->executables)) { return; + } ExecutableSwitchWidget *s1 = (ExecutableSwitchWidget *)ui->executables->itemWidget( @@ -77,8 +80,9 @@ void AdvSceneSwitcher::on_executableDown_clicked() void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (executableSwitches.size() == 0 || ExecutableSwitch::pause) + if (executableSwitches.size() == 0 || ExecutableSwitch::pause) { return; + } std::string title; QStringList runningProcesses; @@ -105,15 +109,15 @@ void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene, // Check for match GetProcessList(runningProcesses); for (ExecutableSwitch &s : executableSwitches) { - if (!s.initialized()) + if (!s.initialized()) { continue; - // True if executable switch is running (direct) + } + bool equals = runningProcesses.contains(s.exe); - // True if executable switch is running (regex) bool matches = (runningProcesses.indexOf( QRegularExpression(s.exe)) != -1); - // True if focus is disabled OR switch is focused bool focus = (!s.inFocus || isInFocus(s.exe)); + // True if current window is ignored AND switch equals OR matches last window bool ignore = (ignored && (title == s.exe.toStdString() || @@ -125,8 +129,9 @@ void SwitcherData::checkExeSwitch(bool &match, OBSWeakSource &scene, scene = s.getScene(); transition = s.transition; - if (verbose) + if (verbose) { s.logMatch(); + } break; } } @@ -197,13 +202,15 @@ void ExecutableSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldExe(obs_data_t *obj, ExecutableSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene = obs_data_get_string(obj, "scene"); - if (strcmp(scene, "") == 0) + if (strcmp(scene, "") == 0) { return false; + } s->scene = GetWeakSourceByName(scene); @@ -219,8 +226,9 @@ bool loadOldExe(obs_data_t *obj, ExecutableSwitch *s) void ExecutableSwitch::load(obs_data_t *obj) { - if (loadOldExe(obj, this)) + if (loadOldExe(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -288,16 +296,20 @@ void ExecutableSwitchWidget::swapSwitchData(ExecutableSwitchWidget *s1, void ExecutableSwitchWidget::ProcessChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->exe = text; } void ExecutableSwitchWidget::FocusChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->inFocus = state; } diff --git a/src/switch-file.cpp b/src/switch-file.cpp index 6344a698..007e01c8 100644 --- a/src/switch-file.cpp +++ b/src/switch-file.cpp @@ -19,14 +19,16 @@ void AdvSceneSwitcher::on_browseButton_clicked() tr(obs_module_text("AdvSceneSwitcher.fileTab.selectWrite")), QDir::currentPath(), tr(obs_module_text("AdvSceneSwitcher.fileTab.textFileType"))); - if (!path.isEmpty()) + if (!path.isEmpty()) { ui->writePathLineEdit->setText(path); + } } void AdvSceneSwitcher::on_readFileCheckBox_stateChanged(int state) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); if (!state) { @@ -42,8 +44,9 @@ void AdvSceneSwitcher::on_readFileCheckBox_stateChanged(int state) void AdvSceneSwitcher::on_readPathLineEdit_textChanged(const QString &text) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); if (text.isEmpty()) { @@ -56,8 +59,9 @@ void AdvSceneSwitcher::on_readPathLineEdit_textChanged(const QString &text) void AdvSceneSwitcher::on_writePathLineEdit_textChanged(const QString &text) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); if (text.isEmpty()) { @@ -75,14 +79,16 @@ void AdvSceneSwitcher::on_browseButton_2_clicked() tr(obs_module_text("AdvSceneSwitcher.fileTab.selectRead")), QDir::currentPath(), tr(obs_module_text("AdvSceneSwitcher.fileTab.anyFileType"))); - if (!path.isEmpty()) + if (!path.isEmpty()) { ui->readPathLineEdit->setText(path); + } } void SwitcherData::writeSceneInfoToFile() { - if (!fileIO.writeEnabled || fileIO.writePath.empty()) + if (!fileIO.writeEnabled || fileIO.writePath.empty()) { return; + } obs_source_t *currentSource = obs_frontend_get_current_scene(); @@ -97,8 +103,9 @@ void SwitcherData::writeSceneInfoToFile() void SwitcherData::writeToStatusFile(QString msg) { - if (!fileIO.writeEnabled || fileIO.writePath.empty()) + if (!fileIO.writeEnabled || fileIO.writePath.empty()) { return; + } QFile file(QString::fromStdString(fileIO.writePath)); if (file.open(QIODevice::ReadWrite)) { @@ -111,8 +118,9 @@ void SwitcherData::writeToStatusFile(QString msg) void SwitcherData::checkSwitchInfoFromFile(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (!fileIO.readEnabled || fileIO.readPath.empty()) + if (!fileIO.readEnabled || fileIO.readPath.empty()) { return; + } QFile file(QString::fromStdString(fileIO.readPath)); if (file.open(QIODevice::ReadOnly)) { @@ -175,8 +183,9 @@ bool compareIgnoringLineEnding(QString &s1, QString &s2) } } - if (!s1stream.atEnd() && !s2stream.atEnd()) + if (!s1stream.atEnd() && !s2stream.atEnd()) { return false; + } return true; } @@ -185,8 +194,9 @@ bool matchFileContent(QString &filedata, FileSwitch &s) { if (s.onlyMatchIfChanged) { size_t newHash = strHash(filedata.toUtf8().constData()); - if (newHash == s.lastHash) + if (newHash == s.lastHash) { return false; + } s.lastHash = newHash; } @@ -210,13 +220,15 @@ bool checkLocalFileContent(FileSwitch &s) { QString t = QString::fromStdString(s.text); QFile file(QString::fromStdString(s.file)); - if (s.file.empty() || !file.open(QIODevice::ReadOnly)) + if (s.file.empty() || !file.open(QIODevice::ReadOnly)) { return false; + } if (s.useTime) { QDateTime newLastMod = QFileInfo(file).lastModified(); - if (s.lastMod == newLastMod) + if (s.lastMod == newLastMod) { return false; + } s.lastMod = newLastMod; } @@ -230,12 +242,14 @@ bool checkLocalFileContent(FileSwitch &s) void SwitcherData::checkFileContent(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (FileSwitch::pause) + if (FileSwitch::pause) { return; + } for (FileSwitch &s : fileSwitches) { - if (!s.initialized()) + if (!s.initialized()) { continue; + } bool equal = false; if (s.remote) { @@ -249,8 +263,9 @@ void SwitcherData::checkFileContent(bool &match, OBSWeakSource &scene, transition = s.transition; match = true; - if (verbose) + if (verbose) { s.logMatch(); + } break; } } @@ -272,8 +287,9 @@ void AdvSceneSwitcher::on_fileAdd_clicked() void AdvSceneSwitcher::on_fileRemove_clicked() { QListWidgetItem *item = ui->fileSwitches->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -287,27 +303,32 @@ void AdvSceneSwitcher::on_fileRemove_clicked() void AdvSceneSwitcher::on_fileSwitches_currentRowChanged(int idx) { - if (loading) + if (loading) { return; - if (idx == -1) + } + if (idx == -1) { return; + } std::lock_guard lock(switcher->m); - if ((int)switcher->fileSwitches.size() <= idx) + if ((int)switcher->fileSwitches.size() <= idx) { return; + } FileSwitch s = switcher->fileSwitches[idx]; - if (s.remote) + if (s.remote) { ui->remoteFileWarningLabel->show(); - else + } else { ui->remoteFileWarningLabel->hide(); + } } void AdvSceneSwitcher::on_fileUp_clicked() { int index = ui->fileSwitches->currentRow(); - if (!listMoveUp(ui->fileSwitches)) + if (!listMoveUp(ui->fileSwitches)) { return; + } FileSwitchWidget *s1 = (FileSwitchWidget *)ui->fileSwitches->itemWidget( ui->fileSwitches->item(index)); @@ -325,8 +346,9 @@ void AdvSceneSwitcher::on_fileDown_clicked() { int index = ui->fileSwitches->currentRow(); - if (!listMoveDown(ui->fileSwitches)) + if (!listMoveDown(ui->fileSwitches)) { return; + } FileSwitchWidget *s1 = (FileSwitchWidget *)ui->fileSwitches->itemWidget( ui->fileSwitches->item(index)); @@ -393,8 +415,9 @@ void AdvSceneSwitcher::setupFileTab() obs_module_text("AdvSceneSwitcher.fileTab.remoteFileWarning2")); ui->remoteFileWarningLabel->hide(); - if (switcher->curl) + if (switcher->curl) { ui->libcurlWarning->setVisible(false); + } for (auto &s : switcher->fileSwitches) { QListWidgetItem *item; @@ -442,13 +465,15 @@ void FileSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldFile(obs_data_t *obj, FileSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene = obs_data_get_string(obj, "scene"); - if (strcmp(scene, "") == 0) + if (strcmp(scene, "") == 0) { return false; + } s->scene = GetWeakSourceByName(scene); @@ -468,8 +493,9 @@ bool loadOldFile(obs_data_t *obj, FileSwitch *s) void FileSwitch::load(obs_data_t *obj) { - if (loadOldFile(obj, this)) + if (loadOldFile(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -516,10 +542,11 @@ FileSwitchWidget::FileSwitchWidget(QWidget *parent, FileSwitch *s) fileType->addItem(obs_module_text("AdvSceneSwitcher.fileTab.remote")); if (s) { - if (s->remote) + if (s->remote) { fileType->setCurrentIndex(1); - else + } else { fileType->setCurrentIndex(0); + } filePath->setText(QString::fromStdString(s->file)); matchText->setPlainText(QString::fromStdString(s->text)); useRegex->setChecked(s->useRegex); @@ -581,8 +608,9 @@ void FileSwitchWidget::swapSwitchData(FileSwitchWidget *s1, void FileSwitchWidget::FileTypeChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } if ((file_type)index == LOCAL) { browseButton->setDisabled(false); @@ -598,24 +626,28 @@ void FileSwitchWidget::FileTypeChanged(int index) void FileSwitchWidget::FilePathChanged() { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->file = filePath->text().toUtf8().constData(); } void FileSwitchWidget::BrowseButtonClicked() { - if (loading || !switchData) + if (loading || !switchData) { return; + } QString path = QFileDialog::getOpenFileName( this, tr(obs_module_text("AdvSceneSwitcher.fileTab.selectRead")), QDir::currentPath(), tr(obs_module_text("AdvSceneSwitcher.fileTab.anyFileType"))); - if (path.isEmpty()) + if (path.isEmpty()) { return; + } filePath->setText(path); FilePathChanged(); @@ -623,32 +655,40 @@ void FileSwitchWidget::BrowseButtonClicked() void FileSwitchWidget::MatchTextChanged() { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->text = matchText->toPlainText().toUtf8().constData(); } void FileSwitchWidget::UseRegexChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->useRegex = state; } void FileSwitchWidget::CheckModificationDateChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->useTime = state; } void FileSwitchWidget::CheckFileContentChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->onlyMatchIfChanged = state; } diff --git a/src/switch-generic.cpp b/src/switch-generic.cpp index faa9fc88..87f58278 100644 --- a/src/switch-generic.cpp +++ b/src/switch-generic.cpp @@ -17,14 +17,12 @@ bool SceneSwitcherEntry::valid() void SceneSwitcherEntry::logMatchScene() { - const char *sceneName = previous_scene_name; + std::string sceneName = previous_scene_name; if (!usePreviousScene) { - obs_source_t *s = obs_weak_source_get_source(scene); - sceneName = obs_source_get_name(s); - obs_source_release(s); + sceneName = GetWeakSourceName(scene); } blog(LOG_INFO, "match for '%s' - switch to scene '%s'", getType(), - sceneName); + sceneName.c_str()); } void SceneSwitcherEntry::logMatchSceneGroup() @@ -36,14 +34,10 @@ void SceneSwitcherEntry::logMatchSceneGroup() return; } - const char *sceneName = previous_scene_name; - obs_source_t *s = - obs_weak_source_get_source(group->scenes[group->currentIdx]); - sceneName = obs_source_get_name(s); - obs_source_release(s); + std::string sceneName = GetWeakSourceName(group->getCurrentScene()); blog(LOG_INFO, "match for '%s' - switch to scene '%s' using '%s'", - getType(), sceneName, group->name.c_str()); + getType(), sceneName.c_str(), group->name.c_str()); } void SceneSwitcherEntry::logMatch() @@ -58,8 +52,9 @@ void SceneSwitcherEntry::logMatch() OBSWeakSource SceneSwitcherEntry::getScene() { if (targetType == SwitchTargetType::Scene) { - if (usePreviousScene && switcher) + if (usePreviousScene && switcher) { return switcher->previousScene; + } return scene; } else if (targetType == SwitchTargetType::SceneGroup) { return group->getNextScene(); @@ -73,28 +68,22 @@ void SceneSwitcherEntry::save(obs_data_t *obj, const char *targetTypeSaveName, { obs_data_set_int(obj, targetTypeSaveName, static_cast(targetType)); - const char *targetName = ""; + std::string targetName = ""; if (targetType == SwitchTargetType::Scene) { if (usePreviousScene) { targetName = previous_scene_name; } else { - obs_source_t *sceneSource = - obs_weak_source_get_source(scene); - targetName = obs_source_get_name(sceneSource); - obs_source_release(sceneSource); + targetName = GetWeakSourceName(scene); } } else if (targetType == SwitchTargetType::SceneGroup) { targetName = group->name.c_str(); } - obs_data_set_string(obj, targetSaveName, targetName); + obs_data_set_string(obj, targetSaveName, targetName.c_str()); - obs_source_t *transitionSource = obs_weak_source_get_source(transition); - const char *transitionName = obs_source_get_name(transitionSource); - obs_source_release(transitionSource); - - obs_data_set_string(obj, transitionSaveName, transitionName); + obs_data_set_string(obj, transitionSaveName, + GetWeakSourceName(transition).c_str()); } void SceneSwitcherEntry::load(obs_data_t *obj, const char *targetTypeLoadName, @@ -108,8 +97,9 @@ void SceneSwitcherEntry::load(obs_data_t *obj, const char *targetTypeLoadName, if (targetType == SwitchTargetType::Scene) { usePreviousScene = strcmp(targetName, previous_scene_name) == 0; - if (!usePreviousScene) + if (!usePreviousScene) { scene = GetWeakSourceByName(targetName); + } } else if (targetType == SwitchTargetType::SceneGroup) { group = GetSceneGroupByName(targetName); } @@ -123,16 +113,18 @@ void SceneSwitcherEntry::load(obs_data_t *obj, const char *targetTypeLoadName, void SwitchWidget::SceneGroupAdd(const QString &name) { - if (!scenes) + if (!scenes) { return; + } scenes->addItem(name); } void SwitchWidget::SceneGroupRemove(const QString &name) { - if (!scenes) + if (!scenes) { return; + } int idx = scenes->findText(name); @@ -154,8 +146,9 @@ void SwitchWidget::SceneGroupRemove(const QString &name) void SwitchWidget::SceneGroupRename(const QString &oldName, const QString &newName) { - if (!scenes) + if (!scenes) { return; + } bool renameSelected = scenes->currentText() == oldName; int idx = scenes->findText(oldName); @@ -167,8 +160,9 @@ void SwitchWidget::SceneGroupRename(const QString &oldName, scenes->removeItem(idx); scenes->insertItem(idx, newName); - if (renameSelected) + if (renameSelected) { scenes->setCurrentIndex(scenes->findText(newName)); + } } SwitchWidget::SwitchWidget(QWidget *parent, SceneSwitcherEntry *s, @@ -202,23 +196,8 @@ SwitchWidget::SwitchWidget(QWidget *parent, SceneSwitcherEntry *s, addSceneGroup); AdvSceneSwitcher::populateTransitionSelection(transitions); - if (s) { - if (s->usePreviousScene) { - scenes->setCurrentText(obs_module_text( - "AdvSceneSwitcher.selectPreviousScene")); - } else { - scenes->setCurrentText( - GetWeakSourceName(s->scene).c_str()); - if (s->targetType == SwitchTargetType::SceneGroup && - s->group) - scenes->setCurrentText( - QString::fromStdString(s->group->name)); - } - transitions->setCurrentText( - GetWeakSourceName(s->transition).c_str()); - } - switchData = s; + showSwitchData(); } SceneSwitcherEntry *SwitchWidget::getSwitchData() @@ -231,6 +210,30 @@ void SwitchWidget::setSwitchData(SceneSwitcherEntry *s) switchData = s; } +void SwitchWidget::showSwitchData() +{ + if (!switchData) { + return; + } + + transitions->setCurrentText( + GetWeakSourceName(switchData->transition).c_str()); + + if (switchData->usePreviousScene) { + scenes->setCurrentText(obs_module_text( + "AdvSceneSwitcher.selectPreviousScene")); + return; + } + + scenes->setCurrentText(GetWeakSourceName(switchData->scene).c_str()); + + if (switchData->group && + switchData->targetType == SwitchTargetType::SceneGroup) { + scenes->setCurrentText( + QString::fromStdString(switchData->group->name)); + } +} + void SwitchWidget::swapSwitchData(SwitchWidget *s1, SwitchWidget *s2) { SceneSwitcherEntry *t = s1->getSwitchData(); @@ -246,8 +249,10 @@ bool isPreviousScene(const QString &text) void SwitchWidget::SceneChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->usePreviousScene = isPreviousScene(text); @@ -267,8 +272,10 @@ void SwitchWidget::SceneChanged(const QString &text) void SwitchWidget::TransitionChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->transition = GetWeakTransitionByQString(text); } diff --git a/src/switch-idle.cpp b/src/switch-idle.cpp index 2a02c16d..beee0947 100644 --- a/src/switch-idle.cpp +++ b/src/switch-idle.cpp @@ -9,8 +9,9 @@ IdleWidget *idleWidget = nullptr; void SwitcherData::checkIdleSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (!idleData.idleEnable || IdleData::pause) + if (!idleData.idleEnable || IdleData::pause) { return; + } std::string title; bool ignoreIdle = false; @@ -38,23 +39,26 @@ void SwitcherData::checkIdleSwitch(bool &match, OBSWeakSource &scene, } if (!ignoreIdle && secondsSinceLastInput() > idleData.time) { - if (idleData.alreadySwitched) + if (idleData.alreadySwitched) { return; + } scene = idleData.getScene(); transition = idleData.transition; match = true; idleData.alreadySwitched = true; - if (verbose) + if (verbose) { idleData.logMatch(); + } } else idleData.alreadySwitched = false; } void AdvSceneSwitcher::on_idleCheckBox_stateChanged(int state) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); if (!state) { @@ -68,10 +72,12 @@ void AdvSceneSwitcher::on_idleCheckBox_stateChanged(int state) void AdvSceneSwitcher::on_ignoreIdleWindows_currentRowChanged(int idx) { - if (loading) + if (loading) { return; - if (idx == -1) + } + if (idx == -1) { return; + } QListWidgetItem *item = ui->ignoreIdleWindows->item(idx); @@ -90,8 +96,9 @@ void AdvSceneSwitcher::on_ignoreIdleAdd_clicked() { QString windowName = ui->ignoreIdleWindowsWindows->currentText(); - if (windowName.isEmpty()) + if (windowName.isEmpty()) { return; + } QVariant v = QVariant::fromValue(windowName); @@ -113,8 +120,9 @@ void AdvSceneSwitcher::on_ignoreIdleAdd_clicked() void AdvSceneSwitcher::on_ignoreIdleRemove_clicked() { QListWidgetItem *item = ui->ignoreIdleWindows->currentItem(); - if (!item) + if (!item) { return; + } QString windowName = item->data(Qt::UserRole).toString(); @@ -267,8 +275,10 @@ IdleWidget::IdleWidget(QWidget *parent, IdleData *s) void IdleWidget::DurationChanged(int dur) { - if (loading) + if (loading) { return; + } + std::lock_guard lock(switcher->m); switcher->idleData.time = dur; } diff --git a/src/switch-media.cpp b/src/switch-media.cpp index 64ae8840..c05335ab 100644 --- a/src/switch-media.cpp +++ b/src/switch-media.cpp @@ -23,8 +23,9 @@ void AdvSceneSwitcher::on_mediaAdd_clicked() void AdvSceneSwitcher::on_mediaRemove_clicked() { QListWidgetItem *item = ui->mediaSwitches->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -39,8 +40,9 @@ void AdvSceneSwitcher::on_mediaRemove_clicked() void AdvSceneSwitcher::on_mediaUp_clicked() { int index = ui->mediaSwitches->currentRow(); - if (!listMoveUp(ui->mediaSwitches)) + if (!listMoveUp(ui->mediaSwitches)) { return; + } MediaSwitchWidget *s1 = (MediaSwitchWidget *)ui->mediaSwitches->itemWidget( @@ -60,8 +62,9 @@ void AdvSceneSwitcher::on_mediaDown_clicked() { int index = ui->mediaSwitches->currentRow(); - if (!listMoveDown(ui->mediaSwitches)) + if (!listMoveDown(ui->mediaSwitches)) { return; + } MediaSwitchWidget *s1 = (MediaSwitchWidget *)ui->mediaSwitches->itemWidget( @@ -80,12 +83,14 @@ void AdvSceneSwitcher::on_mediaDown_clicked() void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (MediaSwitch::pause) + if (MediaSwitch::pause) { return; + } for (MediaSwitch &mediaSwitch : mediaSwitches) { - if (!mediaSwitch.initialized()) + if (!mediaSwitch.initialized()) { continue; + } obs_source_t *source = obs_weak_source_get_source(mediaSwitch.source); @@ -138,8 +143,9 @@ void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene, (duration - time <= interval * 2); // reset - if (ended) + if (ended) { mediaSwitch.playedToEnd = false; + } // reset for next check mediaSwitch.stopped = false; @@ -179,14 +185,16 @@ void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene, scene = mediaSwitch.getScene(); transition = mediaSwitch.transition; - if (verbose) + if (verbose) { mediaSwitch.logMatch(); + } } mediaSwitch.matched = matched; - if (match) + if (match) { break; + } } } @@ -256,10 +264,7 @@ void MediaSwitch::save(obs_data_t *obj) { SceneSwitcherEntry::save(obj); - obs_source_t *s = obs_weak_source_get_source(source); - const char *sourceName = obs_source_get_name(s); - obs_data_set_string(obj, "source", sourceName); - obs_source_release(s); + obs_data_set_string(obj, "source", GetWeakSourceName(source).c_str()); obs_data_set_int(obj, "state", state); obs_data_set_int(obj, "restriction", restriction); @@ -269,13 +274,15 @@ void MediaSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldMedia(obs_data_t *obj, MediaSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene = obs_data_get_string(obj, "scene"); - if (strcmp(scene, "") == 0) + if (strcmp(scene, "") == 0) { return false; + } s->scene = GetWeakSourceByName(scene); @@ -296,8 +303,9 @@ bool loadOldMedia(obs_data_t *obj, MediaSwitch *s) void MediaSwitch::load(obs_data_t *obj) { - if (loadOldMedia(obj, this)) + if (loadOldMedia(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -492,8 +500,9 @@ MediaSwitchWidget::MediaSwitchWidget(QWidget *parent, MediaSwitch *s) states->setCurrentIndex(s->state); timeRestrictions->setCurrentIndex(s->restriction); time->setValue(s->time); - if (s->restriction == TIME_RESTRICTION_NONE) + if (s->restriction == TIME_RESTRICTION_NONE) { time->setDisabled(true); + } } QHBoxLayout *mainLayout = new QHBoxLayout; @@ -535,8 +544,10 @@ void MediaSwitchWidget::swapSwitchData(MediaSwitchWidget *s1, void MediaSwitchWidget::SourceChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->clearSignalHandler(); switchData->source = GetWeakSourceByQString(text); @@ -545,8 +556,10 @@ void MediaSwitchWidget::SourceChanged(const QString &text) void MediaSwitchWidget::StateChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->state = (obs_media_state)index; switchData->anyState = switchData->state == media_any_idx; @@ -554,13 +567,15 @@ void MediaSwitchWidget::StateChanged(int index) void MediaSwitchWidget::TimeRestrictionChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } - if ((time_restriction)index == TIME_RESTRICTION_NONE) + if ((time_restriction)index == TIME_RESTRICTION_NONE) { time->setDisabled(true); - else + } else { time->setDisabled(false); + } std::lock_guard lock(switcher->m); switchData->restriction = (time_restriction)index; @@ -568,8 +583,10 @@ void MediaSwitchWidget::TimeRestrictionChanged(int index) void MediaSwitchWidget::TimeChanged(int time) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->time = time; } diff --git a/src/switch-pause.cpp b/src/switch-pause.cpp index 223d6693..ee141a58 100644 --- a/src/switch-pause.cpp +++ b/src/switch-pause.cpp @@ -21,8 +21,9 @@ void AdvSceneSwitcher::on_pauseAdd_clicked() void AdvSceneSwitcher::on_pauseRemove_clicked() { QListWidgetItem *item = ui->pauseEntries->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -37,8 +38,9 @@ void AdvSceneSwitcher::on_pauseRemove_clicked() void AdvSceneSwitcher::on_pauseUp_clicked() { int index = ui->pauseEntries->currentRow(); - if (!listMoveUp(ui->pauseEntries)) + if (!listMoveUp(ui->pauseEntries)) { return; + } PauseEntryWidget *s1 = (PauseEntryWidget *)ui->pauseEntries->itemWidget( ui->pauseEntries->item(index)); @@ -56,8 +58,9 @@ void AdvSceneSwitcher::on_pauseDown_clicked() { int index = ui->pauseEntries->currentRow(); - if (!listMoveDown(ui->pauseEntries)) + if (!listMoveDown(ui->pauseEntries)) { return; + } PauseEntryWidget *s1 = (PauseEntryWidget *)ui->pauseEntries->itemWidget( ui->pauseEntries->item(index)); @@ -90,62 +93,50 @@ void setPauseTarget(PauseTarget &target, bool &verbose) { switch (target) { case PauseTarget::All: - if (verbose) - blog(LOG_INFO, "pause all switching"); + vblog(LOG_INFO, "pause all switching"); break; case PauseTarget::Transition: - if (verbose) - blog(LOG_INFO, "pause def_transition switching"); + vblog(LOG_INFO, "pause def_transition switching"); DefaultSceneTransition::pause = true; break; case PauseTarget::Window: - if (verbose) - blog(LOG_INFO, "pause window switching"); + vblog(LOG_INFO, "pause window switching"); WindowSwitch::pause = true; break; case PauseTarget::Executable: - if (verbose) - blog(LOG_INFO, "pause exec switching"); + vblog(LOG_INFO, "pause exec switching"); ExecutableSwitch::pause = true; break; case PauseTarget::Region: - if (verbose) - blog(LOG_INFO, "pause region switching"); + vblog(LOG_INFO, "pause region switching"); ScreenRegionSwitch::pause = true; break; case PauseTarget::Media: - if (verbose) - blog(LOG_INFO, "pause media switching"); + vblog(LOG_INFO, "pause media switching"); MediaSwitch::pause = true; break; case PauseTarget::File: - if (verbose) - blog(LOG_INFO, "pause file switching"); + vblog(LOG_INFO, "pause file switching"); FileSwitch::pause = true; break; case PauseTarget::Random: - if (verbose) - blog(LOG_INFO, "pause random switching"); + vblog(LOG_INFO, "pause random switching"); RandomSwitch::pause = true; break; case PauseTarget::Time: - if (verbose) - blog(LOG_INFO, "pause time switching"); + vblog(LOG_INFO, "pause time switching"); TimeSwitch::pause = true; break; case PauseTarget::Idle: - if (verbose) - blog(LOG_INFO, "pause idle switching"); + vblog(LOG_INFO, "pause idle switching"); IdleData::pause = true; break; case PauseTarget::Sequence: - if (verbose) - blog(LOG_INFO, "pause sequence switching"); + vblog(LOG_INFO, "pause sequence switching"); SceneSequenceSwitch::pause = true; break; case PauseTarget::Audio: - if (verbose) - blog(LOG_INFO, "pause audio switching"); + vblog(LOG_INFO, "pause audio switching"); AudioSwitch::pause = true; break; } @@ -154,24 +145,22 @@ void setPauseTarget(PauseTarget &target, bool &verbose) bool checkPauseScene(obs_weak_source_t *currentScene, obs_weak_source_t *scene, PauseTarget &target, bool &verbose) { - if (currentScene != scene) + if (currentScene != scene) { return false; + } setPauseTarget(target, verbose); - if (target == PauseTarget::All) - return true; - return false; + return (target == PauseTarget::All); } bool checkPauseWindow(std::string ¤tTitle, std::string &title, PauseTarget &target, bool &verbose) { - if (currentTitle != title) + if (currentTitle != title) { return false; + } setPauseTarget(target, verbose); - if (target == PauseTarget::All) - return true; - return false; + return (target == PauseTarget::All); } bool SwitcherData::checkPause() @@ -187,14 +176,16 @@ bool SwitcherData::checkPause() obs_weak_source_t *ws = obs_source_get_weak_source(currentSource); for (PauseEntry &s : pauseEntries) { - if (s.pauseType == PauseType::Scene) + if (s.pauseType == PauseType::Scene) { pauseAll = checkPauseScene(ws, s.scene, s.pauseTarget, verbose); - else + } else { pauseAll = checkPauseWindow(title, s.window, s.pauseTarget, verbose); - if (pauseAll) + } + if (pauseAll) { break; + } } obs_source_release(currentSource); @@ -263,8 +254,9 @@ void SwitcherData::loadPauseSwitches(obs_data_t *obj) void SwitcherData::loadOldPauseSwitches(obs_data_t *obj) { - if (obs_data_get_int(obj, "oldPauseValuesImported")) + if (obs_data_get_int(obj, "oldPauseValuesImported")) { return; + } obs_data_array_t *pauseScenesArray = obs_data_get_array(obj, "pauseScenes"); @@ -423,8 +415,10 @@ void PauseEntryWidget::swapSwitchData(PauseEntryWidget *s1, void PauseEntryWidget::PauseTypeChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->pauseType = static_cast(index); @@ -443,16 +437,20 @@ void PauseEntryWidget::PauseTypeChanged(int index) void PauseEntryWidget::PauseTargetChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->pauseTarget = static_cast(index); } void PauseEntryWidget::WindowChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->window = text.toStdString(); } diff --git a/src/switch-priority.cpp b/src/switch-priority.cpp index 0ec770c4..8fbdd188 100644 --- a/src/switch-priority.cpp +++ b/src/switch-priority.cpp @@ -58,12 +58,14 @@ bool SwitcherData::prioFuncsValid() auto it = std::unique(functionNamesByPriority.begin(), functionNamesByPriority.end()); bool wasUnique = (it == functionNamesByPriority.end()); - if (!wasUnique) + if (!wasUnique) { return false; + } for (int p : functionNamesByPriority) { - if (p < 0 || p > 8) + if (p < 0 || p > 8) { return false; + } } return true; } diff --git a/src/switch-random.cpp b/src/switch-random.cpp index 7bcd0c32..171ed6cd 100644 --- a/src/switch-random.cpp +++ b/src/switch-random.cpp @@ -22,8 +22,9 @@ void AdvSceneSwitcher::on_randomAdd_clicked() void AdvSceneSwitcher::on_randomRemove_clicked() { QListWidgetItem *item = ui->randomSwitches->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -38,27 +39,32 @@ void AdvSceneSwitcher::on_randomRemove_clicked() void SwitcherData::checkRandom(bool &match, OBSWeakSource &scene, OBSWeakSource &transition, int &delay) { - if (randomSwitches.size() == 0 || RandomSwitch::pause) + if (randomSwitches.size() == 0 || RandomSwitch::pause) { return; + } std::deque rs(randomSwitches); std::random_device rng; std::mt19937 urng(rng()); std::shuffle(rs.begin(), rs.end(), urng); for (RandomSwitch &r : rs) { - if (!r.initialized()) + if (!r.initialized()) { continue; + } - if (r.scene == lastRandomScene && randomSwitches.size() != 1) + if (r.scene == lastRandomScene && randomSwitches.size() != 1) { continue; + } + scene = r.getScene(); transition = r.transition; delay = (int)r.delay * 1000; match = true; lastRandomScene = r.scene; - if (verbose) + if (verbose) { r.logMatch(); + } break; } } @@ -115,11 +121,12 @@ void AdvSceneSwitcher::setupRandomTab() ui->randomHelp->setVisible(false); } - if (switcher->switchIfNotMatching != RANDOM_SWITCH) + if (switcher->switchIfNotMatching != RANDOM_SWITCH) { PulseWidget(ui->randomDisabledWarning, QColor(Qt::red), QColor(0, 0, 0, 0), "QLabel "); - else + } else { ui->randomDisabledWarning->setVisible(false); + } } void RandomSwitch::save(obs_data_t *obj) @@ -185,8 +192,10 @@ void RandomSwitchWidget::swapSwitchData(RandomSwitchWidget *s1, void RandomSwitchWidget::DelayChanged(double d) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->delay = d; } diff --git a/src/switch-screen-region.cpp b/src/switch-screen-region.cpp index 0cf6b2c0..5bb6cd05 100644 --- a/src/switch-screen-region.cpp +++ b/src/switch-screen-region.cpp @@ -19,8 +19,9 @@ void showCurrentFrame(QListWidget *list) { QListWidgetItem *item = list->currentItem(); - if (!item) + if (!item) { return; + } ScreenRegionWidget *sw = (ScreenRegionWidget *)list->itemWidget(item); sw->showFrame(); @@ -53,8 +54,9 @@ void AdvSceneSwitcher::on_showFrame_clicked() void AdvSceneSwitcher::on_screenRegionSwitches_currentRowChanged(int idx) { - if (loading || idx == -1) + if (loading || idx == -1) { return; + } if (switcher->showFrame) { clearFrames(ui->screenRegionSwitches); @@ -78,8 +80,9 @@ void AdvSceneSwitcher::on_screenRegionAdd_clicked() void AdvSceneSwitcher::on_screenRegionRemove_clicked() { QListWidgetItem *item = ui->screenRegionSwitches->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -94,8 +97,9 @@ void AdvSceneSwitcher::on_screenRegionRemove_clicked() void AdvSceneSwitcher::on_screenRegionUp_clicked() { int index = ui->screenRegionSwitches->currentRow(); - if (!listMoveUp(ui->screenRegionSwitches)) + if (!listMoveUp(ui->screenRegionSwitches)) { return; + } ScreenRegionWidget *s1 = (ScreenRegionWidget *)ui->screenRegionSwitches->itemWidget( @@ -115,8 +119,9 @@ void AdvSceneSwitcher::on_screenRegionDown_clicked() { int index = ui->screenRegionSwitches->currentRow(); - if (!listMoveDown(ui->screenRegionSwitches)) + if (!listMoveDown(ui->screenRegionSwitches)) { return; + } ScreenRegionWidget *s1 = (ScreenRegionWidget *)ui->screenRegionSwitches->itemWidget( @@ -134,8 +139,9 @@ void AdvSceneSwitcher::on_screenRegionDown_clicked() bool shouldIgnoreSceneSwitch(ScreenRegionSwitch &matchingRegion) { - if (!matchingRegion.excludeScene) + if (!matchingRegion.excludeScene) { return false; + } obs_source_t *currentScene = obs_frontend_get_current_scene(); OBSWeakSource ws = obs_source_get_weak_source(currentScene); @@ -148,15 +154,17 @@ bool shouldIgnoreSceneSwitch(ScreenRegionSwitch &matchingRegion) void SwitcherData::checkScreenRegionSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (ScreenRegionSwitch::pause) + if (ScreenRegionSwitch::pause) { return; + } std::pair cursorPos = getCursorPos(); int minRegionSize = 99999; for (auto &s : screenRegionSwitches) { - if (!s.initialized()) + if (!s.initialized()) { continue; + } if (cursorPos.first >= s.minX && cursorPos.second >= s.minY && cursorPos.first <= s.maxX && cursorPos.second <= s.maxY) { @@ -172,8 +180,9 @@ void SwitcherData::checkScreenRegionSwitch(bool &match, OBSWeakSource &scene, transition = s.transition; minRegionSize = regionSize; - if (verbose) + if (verbose) { s.logMatch(); + } break; } } @@ -251,12 +260,8 @@ void ScreenRegionSwitch::save(obs_data_t *obj) { SceneSwitcherEntry::save(obj); - const char *excludeSceneName = ""; - obs_source_t *excludeSceneSource = - obs_weak_source_get_source(excludeScene); - excludeSceneName = obs_source_get_name(excludeSceneSource); - obs_source_release(excludeSceneSource); - obs_data_set_string(obj, "excludeScene", excludeSceneName); + obs_data_set_string(obj, "excludeScene", + GetWeakSourceName(excludeScene).c_str()); obs_data_set_int(obj, "minX", minX); obs_data_set_int(obj, "minY", minY); @@ -267,13 +272,15 @@ void ScreenRegionSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldRegion(obs_data_t *obj, ScreenRegionSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene = obs_data_get_string(obj, "screenRegionScene"); - if (strcmp(scene, "") == 0) + if (strcmp(scene, "") == 0) { return false; + } s->scene = GetWeakSourceByName(scene); @@ -292,8 +299,9 @@ bool loadOldRegion(obs_data_t *obj, ScreenRegionSwitch *s) void ScreenRegionSwitch::load(obs_data_t *obj) { - if (loadOldRegion(obj, this)) + if (loadOldRegion(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -407,17 +415,20 @@ void ScreenRegionWidget::hideFrame() void ScreenRegionWidget::ExcludeSceneChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; - std::lock_guard lock(switcher->m); + } + std::lock_guard lock(switcher->m); switchData->excludeScene = GetWeakSourceByQString(text); } void ScreenRegionWidget::MinXChanged(int pos) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->minX = pos; @@ -426,8 +437,10 @@ void ScreenRegionWidget::MinXChanged(int pos) void ScreenRegionWidget::MinYChanged(int pos) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->minY = pos; @@ -436,8 +449,10 @@ void ScreenRegionWidget::MinYChanged(int pos) void ScreenRegionWidget::MaxXChanged(int pos) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->maxX = pos; @@ -446,8 +461,10 @@ void ScreenRegionWidget::MaxXChanged(int pos) void ScreenRegionWidget::MaxYChanged(int pos) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->maxY = pos; @@ -463,8 +480,9 @@ void ScreenRegionWidget::drawFrame() Qt::WindowStaysOnTopHint); helperFrame.setAttribute(Qt::WA_TranslucentBackground, true); - if (switchData) + if (switchData) { helperFrame.setGeometry(switchData->minX, switchData->minY, switchData->maxX - switchData->minX, switchData->maxY - switchData->minY); + } } diff --git a/src/switch-sequence.cpp b/src/switch-sequence.cpp index b617682e..1a2bccf3 100644 --- a/src/switch-sequence.cpp +++ b/src/switch-sequence.cpp @@ -23,11 +23,12 @@ void AdvSceneSwitcher::on_sceneSequenceAdd_clicked() void AdvSceneSwitcher::on_sceneSequenceRemove_clicked() { QListWidgetItem *item = ui->sceneSequenceSwitches->currentItem(); - if (!item) + if (!item) { return; + } { - // might be in waiting state of sequence + // Might be in waiting state of sequence // causing invalid access after wakeup // thus we need to stop the main thread before delete bool wasRunning = !switcher->stop; @@ -38,8 +39,9 @@ void AdvSceneSwitcher::on_sceneSequenceRemove_clicked() auto &switches = switcher->sceneSequenceSwitches; switches.erase(switches.begin() + idx); - if (wasRunning) + if (wasRunning) { switcher->Start(); + } } delete item; @@ -48,8 +50,9 @@ void AdvSceneSwitcher::on_sceneSequenceRemove_clicked() void AdvSceneSwitcher::on_sceneSequenceUp_clicked() { int index = ui->sceneSequenceSwitches->currentRow(); - if (!listMoveUp(ui->sceneSequenceSwitches)) + if (!listMoveUp(ui->sceneSequenceSwitches)) { return; + } SequenceWidget *s1 = (SequenceWidget *)ui->sceneSequenceSwitches->itemWidget( @@ -69,8 +72,9 @@ void AdvSceneSwitcher::on_sceneSequenceDown_clicked() { int index = ui->sceneSequenceSwitches->currentRow(); - if (!listMoveDown(ui->sceneSequenceSwitches)) + if (!listMoveDown(ui->sceneSequenceSwitches)) { return; + } SequenceWidget *s1 = (SequenceWidget *)ui->sceneSequenceSwitches->itemWidget( @@ -95,11 +99,13 @@ void AdvSceneSwitcher::on_sceneSequenceSave_clicked() QDir::currentPath(), tr(obs_module_text( "AdvSceneSwitcher.sceneSequenceTab.fileType"))); - if (directory.isEmpty()) + if (directory.isEmpty()) { return; + } QFile file(directory); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { return; + } obs_data_t *obj = obs_data_create(); switcher->saveSceneSequenceSwitches(obj); @@ -116,12 +122,14 @@ void AdvSceneSwitcher::on_sceneSequenceLoad_clicked() QDir::currentPath(), tr(obs_module_text( "AdvSceneSwitcher.sceneSequenceTab.fileType"))); - if (directory.isEmpty()) + if (directory.isEmpty()) { return; + } QFile file(directory); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return; + } obs_data_t *obj = obs_data_create_from_json_file( file.fileName().toUtf8().constData()); @@ -132,7 +140,7 @@ void AdvSceneSwitcher::on_sceneSequenceLoad_clicked() return; } - // might be in waiting state of sequence + // Might be in waiting state of sequence // causing invalid access after wakeup // thus we need to stop the main thread before delete bool wasRunning = !switcher->stop; @@ -140,8 +148,9 @@ void AdvSceneSwitcher::on_sceneSequenceLoad_clicked() switcher->loadSceneSequenceSwitches(obj); - if (wasRunning) + if (wasRunning) { switcher->Start(); + } obs_data_release(obj); @@ -179,15 +188,17 @@ bool matchUninterruptible(SwitcherData *switcher, SceneSequenceSwitch &s, void SwitcherData::checkSceneSequence(bool &match, OBSWeakSource &scene, OBSWeakSource &transition, int &linger) { - if (SceneSequenceSwitch::pause) + if (SceneSequenceSwitch::pause) { return; + } obs_source_t *currentSource = obs_frontend_get_current_scene(); obs_weak_source_t *ws = obs_source_get_weak_source(currentSource); for (SceneSequenceSwitch &s : sceneSequenceSwitches) { - if (!s.initialized()) + if (!s.initialized()) { continue; + } if (s.startScene == ws) { if (!match) { @@ -202,8 +213,9 @@ void SwitcherData::checkSceneSequence(bool &match, OBSWeakSource &scene, if (match) { scene = s.getScene(); transition = s.transition; - if (switcher->verbose) + if (switcher->verbose) { s.logMatch(); + } } } } else { @@ -283,10 +295,8 @@ void SceneSequenceSwitch::save(obs_data_t *obj) { SceneSwitcherEntry::save(obj); - obs_source_t *source = obs_weak_source_get_source(startScene); - const char *startSceneName = obs_source_get_name(source); - obs_data_set_string(obj, "startScene", startSceneName); - obs_source_release(source); + obs_data_set_string(obj, "startScene", + GetWeakSourceName(startScene).c_str()); obs_data_set_double(obj, "delay", delay); @@ -298,13 +308,15 @@ void SceneSequenceSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldScequence(obs_data_t *obj, SceneSequenceSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene1 = obs_data_get_string(obj, "sceneRoundTripScene1"); - if (strcmp(scene1, "") == 0) + if (strcmp(scene1, "") == 0) { return false; + } s->startScene = GetWeakSourceByName(scene1); @@ -331,8 +343,9 @@ bool loadOldScequence(obs_data_t *obj, SceneSequenceSwitch *s) void SceneSequenceSwitch::load(obs_data_t *obj) { - if (loadOldScequence(obj, this)) + if (loadOldScequence(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -440,22 +453,26 @@ void SequenceWidget::swapSwitchData(SequenceWidget *s1, SequenceWidget *s2) void SequenceWidget::UpdateDelay() { - if (switchData) + if (switchData) { delay->setValue(switchData->delay / switchData->delayMultiplier); + } } void SequenceWidget::DelayChanged(double delay) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + switchData->delay = delay * switchData->delayMultiplier; } void SequenceWidget::DelayUnitsChanged(int idx) { - if (loading || !switchData) + if (loading || !switchData) { return; + } delay_units unit = (delay_units)idx; @@ -478,16 +495,20 @@ void SequenceWidget::DelayUnitsChanged(int idx) void SequenceWidget::StartSceneChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->startScene = GetWeakSourceByQString(text); } void SequenceWidget::InterruptibleChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->interruptible = state; } diff --git a/src/switch-time.cpp b/src/switch-time.cpp index 46d20708..89c66072 100644 --- a/src/switch-time.cpp +++ b/src/switch-time.cpp @@ -20,8 +20,9 @@ void AdvSceneSwitcher::on_timeAdd_clicked() void AdvSceneSwitcher::on_timeRemove_clicked() { QListWidgetItem *item = ui->timeSwitches->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -36,8 +37,9 @@ void AdvSceneSwitcher::on_timeRemove_clicked() void AdvSceneSwitcher::on_timeUp_clicked() { int index = ui->timeSwitches->currentRow(); - if (!listMoveUp(ui->timeSwitches)) + if (!listMoveUp(ui->timeSwitches)) { return; + } TimeSwitchWidget *s1 = (TimeSwitchWidget *)ui->timeSwitches->itemWidget( ui->timeSwitches->item(index)); @@ -55,8 +57,9 @@ void AdvSceneSwitcher::on_timeDown_clicked() { int index = ui->timeSwitches->currentRow(); - if (!listMoveDown(ui->timeSwitches)) + if (!listMoveDown(ui->timeSwitches)) { return; + } TimeSwitchWidget *s1 = (TimeSwitchWidget *)ui->timeSwitches->itemWidget( ui->timeSwitches->item(index)); @@ -72,14 +75,15 @@ void AdvSceneSwitcher::on_timeDown_clicked() bool timesAreInInterval(QTime &time1, QTime &time2, int &interval) { - if (time1.isNull() || time2.isNull()) + if (time1.isNull() || time2.isNull()) { return false; + } bool ret = false; QTime validSwitchTimeWindow = time1.addMSecs(interval); ret = time1 <= time2 && time2 <= validSwitchTimeWindow; - // check for overflow + // Check for overflow if (!ret && validSwitchTimeWindow.msecsSinceStartOfDay() < interval) { ret = time2 >= time1 || time2 <= validSwitchTimeWindow; } @@ -88,8 +92,9 @@ bool timesAreInInterval(QTime &time1, QTime &time2, int &interval) bool checkLiveTime(TimeSwitch &s, QDateTime &start, int &interval) { - if (start.isNull()) + if (start.isNull()) { return false; + } QDateTime now = QDateTime::currentDateTime(); QTime timePassed = QTime(0, 0).addMSecs(start.msecsTo(now)); @@ -111,25 +116,29 @@ bool checkRegularTime(TimeSwitch &s, int &interval) void SwitcherData::checkTimeSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (TimeSwitch::pause) + if (TimeSwitch::pause) { return; + } for (TimeSwitch &s : timeSwitches) { - if (!s.initialized()) + if (!s.initialized()) { continue; + } - if (s.trigger == LIVE) + if (s.trigger == LIVE) { match = checkLiveTime(s, liveTime, interval); - else + } else { match = checkRegularTime(s, interval); + } if (match) { scene = s.getScene(); transition = s.transition; match = true; - if (verbose) + if (verbose) { s.logMatch(); + } break; } } @@ -198,13 +207,15 @@ void TimeSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldTime(obs_data_t *obj, TimeSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene = obs_data_get_string(obj, "scene"); - if (strcmp(scene, "") == 0) + if (strcmp(scene, "") == 0) { return false; + } s->scene = GetWeakSourceByName(scene); @@ -220,8 +231,9 @@ bool loadOldTime(obs_data_t *obj, TimeSwitch *s) void TimeSwitch::load(obs_data_t *obj) { - if (loadOldTime(obj, this)) + if (loadOldTime(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -302,16 +314,20 @@ void TimeSwitchWidget::swapSwitchData(TimeSwitchWidget *s1, void TimeSwitchWidget::TriggerChanged(int index) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->trigger = (timeTrigger)index; } void TimeSwitchWidget::TimeChanged(const QTime &time) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->time = time; } diff --git a/src/switch-transitions.cpp b/src/switch-transitions.cpp index 37474dda..cb4b2fb7 100644 --- a/src/switch-transitions.cpp +++ b/src/switch-transitions.cpp @@ -18,8 +18,9 @@ void AdvSceneSwitcher::on_transitionsAdd_clicked() void AdvSceneSwitcher::on_transitionsRemove_clicked() { QListWidgetItem *item = ui->sceneTransitions->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -34,8 +35,9 @@ void AdvSceneSwitcher::on_transitionsRemove_clicked() void AdvSceneSwitcher::on_transitionsUp_clicked() { int index = ui->sceneTransitions->currentRow(); - if (!listMoveUp(ui->sceneTransitions)) + if (!listMoveUp(ui->sceneTransitions)) { return; + } TransitionSwitchWidget *s1 = (TransitionSwitchWidget *)ui->sceneTransitions->itemWidget( @@ -55,8 +57,9 @@ void AdvSceneSwitcher::on_transitionsDown_clicked() { int index = ui->sceneTransitions->currentRow(); - if (!listMoveDown(ui->sceneTransitions)) + if (!listMoveDown(ui->sceneTransitions)) { return; + } TransitionSwitchWidget *s1 = (TransitionSwitchWidget *)ui->sceneTransitions->itemWidget( @@ -88,8 +91,9 @@ void AdvSceneSwitcher::on_defaultTransitionsAdd_clicked() void AdvSceneSwitcher::on_defaultTransitionsRemove_clicked() { QListWidgetItem *item = ui->defaultTransitions->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -104,8 +108,9 @@ void AdvSceneSwitcher::on_defaultTransitionsRemove_clicked() void AdvSceneSwitcher::on_defaultTransitionsUp_clicked() { int index = ui->defaultTransitions->currentRow(); - if (!listMoveUp(ui->defaultTransitions)) + if (!listMoveUp(ui->defaultTransitions)) { return; + } TransitionSwitchWidget *s1 = (TransitionSwitchWidget *)ui->defaultTransitions->itemWidget( @@ -125,8 +130,9 @@ void AdvSceneSwitcher::on_defaultTransitionsDown_clicked() { int index = ui->defaultTransitions->currentRow(); - if (!listMoveDown(ui->defaultTransitions)) + if (!listMoveDown(ui->defaultTransitions)) { return; + } DefTransitionSwitchWidget *s1 = (DefTransitionSwitchWidget *)ui->defaultTransitions->itemWidget( @@ -145,22 +151,25 @@ void AdvSceneSwitcher::on_defaultTransitionsDown_clicked() void SwitcherData::checkDefaultSceneTransitions(bool &match, OBSWeakSource &transition) { - if (checkedDefTransition || DefaultSceneTransition::pause) + if (checkedDefTransition || DefaultSceneTransition::pause) { return; + } obs_source_t *currentSource = obs_frontend_get_current_scene(); obs_weak_source_t *ws = obs_source_get_weak_source(currentSource); for (DefaultSceneTransition &s : defaultSceneTransitions) { if (s.scene == ws) { - if (!s.initialized()) + if (!s.initialized()) { continue; + } match = true; transition = s.transition; - if (verbose) + if (verbose) { s.logMatch(); + } break; } } @@ -179,8 +188,9 @@ void SwitcherData::setCurrentDefTransition(OBSWeakSource &transition) void AdvSceneSwitcher::on_transitionOverridecheckBox_stateChanged(int state) { - if (loading) + if (loading) { return; + } std::lock_guard lock(switcher->m); if (!state) { @@ -196,8 +206,9 @@ obs_weak_source_t *getNextTransition(obs_weak_source_t *scene1, obs_weak_source_t *ws = nullptr; if (scene1 && scene2) { for (SceneTransition &t : switcher->sceneTransitions) { - if (!t.initialized()) + if (!t.initialized()) { continue; + } if (t.scene == scene1 && t.scene2 == scene2) { ws = t.transition; @@ -259,8 +270,9 @@ void setNextTransition(OBSWeakSource &targetScene, obs_source_t *currentSource, obs_frontend_set_current_transition(nextTransition); } - if (transitionOverrideOverride) + if (transitionOverrideOverride) { overwriteTransitionOverride(targetScene, nextTransition, td); + } obs_weak_source_release(nextTransitionWs); obs_source_release(nextTransition); @@ -476,8 +488,10 @@ void TransitionSwitchWidget::swapSwitchData(TransitionSwitchWidget *s1, void TransitionSwitchWidget::Scene2Changed(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->scene2 = GetWeakSourceByQString(text); } diff --git a/src/switch-window.cpp b/src/switch-window.cpp index d07c1f1f..444f03a2 100644 --- a/src/switch-window.cpp +++ b/src/switch-window.cpp @@ -20,8 +20,9 @@ void AdvSceneSwitcher::on_windowAdd_clicked() void AdvSceneSwitcher::on_windowRemove_clicked() { QListWidgetItem *item = ui->windowSwitches->currentItem(); - if (!item) + if (!item) { return; + } { std::lock_guard lock(switcher->m); @@ -36,8 +37,9 @@ void AdvSceneSwitcher::on_windowRemove_clicked() void AdvSceneSwitcher::on_windowUp_clicked() { int index = ui->windowSwitches->currentRow(); - if (!listMoveUp(ui->windowSwitches)) + if (!listMoveUp(ui->windowSwitches)) { return; + } WindowSwitchWidget *s1 = (WindowSwitchWidget *)ui->windowSwitches->itemWidget( @@ -57,8 +59,9 @@ void AdvSceneSwitcher::on_windowDown_clicked() { int index = ui->windowSwitches->currentRow(); - if (!listMoveDown(ui->windowSwitches)) + if (!listMoveDown(ui->windowSwitches)) { return; + } WindowSwitchWidget *s1 = (WindowSwitchWidget *)ui->windowSwitches->itemWidget( @@ -78,8 +81,9 @@ void AdvSceneSwitcher::on_ignoreWindowsAdd_clicked() { QString windowName = ui->ignoreWindowsWindows->currentText(); - if (windowName.isEmpty()) + if (windowName.isEmpty()) { return; + } QVariant v = QVariant::fromValue(windowName); @@ -102,8 +106,9 @@ void AdvSceneSwitcher::on_ignoreWindowsAdd_clicked() void AdvSceneSwitcher::on_ignoreWindowsRemove_clicked() { QListWidgetItem *item = ui->ignoreWindows->currentItem(); - if (!item) + if (!item) { return; + } QString windowName = item->data(Qt::UserRole).toString(); @@ -144,10 +149,12 @@ int AdvSceneSwitcher::IgnoreWindowsFindByData(const QString &window) void AdvSceneSwitcher::on_ignoreWindows_currentRowChanged(int idx) { - if (loading) + if (loading) { return; - if (idx == -1) + } + if (idx == -1) { return; + } QListWidgetItem *item = ui->ignoreWindows->item(idx); @@ -167,9 +174,7 @@ bool isRunning(std::string &title) QStringList windows; GetWindowList(windows); - // True if switch is running (direct) bool equals = windows.contains(QString::fromStdString(title)); - // True if switch is running (regex) bool matches = (windows.indexOf(QRegularExpression( QString::fromStdString(title))) != -1); @@ -181,9 +186,7 @@ bool isFocused(std::string &title) std::string current; GetCurrentWindowTitle(current); - // True if switch equals current window bool equals = (title == current); - // True if switch matches current window bool matches = QString::fromStdString(current).contains( QRegularExpression(QString::fromStdString(title))); @@ -193,8 +196,9 @@ bool isFocused(std::string &title) void SwitcherData::checkWindowTitleSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition) { - if (WindowSwitch::pause) + if (WindowSwitch::pause) { return; + } std::string title; bool ignored = false; @@ -202,9 +206,7 @@ void SwitcherData::checkWindowTitleSwitch(bool &match, OBSWeakSource &scene, // Check if current window is ignored GetCurrentWindowTitle(title); for (auto &window : ignoreWindowsSwitches) { - // True if ignored switch equals current window bool equals = (title == window); - // True if ignored switch matches current window bool matches = QString::fromStdString(title).contains( QRegularExpression(QString::fromStdString(window))); @@ -219,14 +221,12 @@ void SwitcherData::checkWindowTitleSwitch(bool &match, OBSWeakSource &scene, // Check for match for (WindowSwitch &s : windowSwitches) { - if (!s.initialized()) + if (!s.initialized()) { continue; + } - // True if fullscreen is disabled OR current window is fullscreen bool fullscreen = (!s.fullscreen || isFullscreen(s.window)); - // True if maximized is disabled OR current window is maximized bool max = (!s.maximized || isMaximized(s.window)); - // True if focus is disabled OR switch is focused bool focus = (!s.focus || isFocused(s.window)); // True if current window is ignored AND switch equals OR matches last window bool ignore = @@ -242,8 +242,9 @@ void SwitcherData::checkWindowTitleSwitch(bool &match, OBSWeakSource &scene, scene = s.getScene(); transition = s.transition; - if (verbose) + if (verbose) { s.logMatch(); + } break; } } @@ -361,13 +362,15 @@ void WindowSwitch::save(obs_data_t *obj) // To be removed in future version bool loadOldWindow(obs_data_t *obj, WindowSwitch *s) { - if (!s) + if (!s) { return false; + } const char *scene = obs_data_get_string(obj, "scene"); - if (strcmp(scene, "") == 0) + if (strcmp(scene, "") == 0) { return false; + } s->scene = GetWeakSourceByName(scene); @@ -392,8 +395,9 @@ bool loadOldWindow(obs_data_t *obj, WindowSwitch *s) void WindowSwitch::load(obs_data_t *obj) { - if (loadOldWindow(obj, this)) + if (loadOldWindow(obj, this)) { return; + } SceneSwitcherEntry::load(obj); @@ -487,32 +491,40 @@ void WindowSwitchWidget::swapSwitchData(WindowSwitchWidget *s1, void WindowSwitchWidget::WindowChanged(const QString &text) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->window = text.toStdString(); } void WindowSwitchWidget::FullscreenChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->fullscreen = state; } void WindowSwitchWidget::MaximizedChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->maximized = state; } void WindowSwitchWidget::FocusChanged(int state) { - if (loading || !switchData) + if (loading || !switchData) { return; + } + std::lock_guard lock(switcher->m); switchData->focus = state; } diff --git a/src/switcher-data-structs.cpp b/src/switcher-data-structs.cpp index 282fdc0e..e1e257ca 100644 --- a/src/switcher-data-structs.cpp +++ b/src/switcher-data-structs.cpp @@ -5,8 +5,9 @@ void SwitcherData::Prune() { for (size_t i = 0; i < windowSwitches.size(); i++) { WindowSwitch &s = windowSwitches[i]; - if (!s.valid()) + if (!s.valid()) { windowSwitches.erase(windowSwitches.begin() + i--); + } } if (nonMatchingScene && !WeakSourceValid(nonMatchingScene)) { @@ -16,60 +17,69 @@ void SwitcherData::Prune() for (size_t i = 0; i < randomSwitches.size(); i++) { RandomSwitch &s = randomSwitches[i]; - if (!s.valid()) + if (!s.valid()) { randomSwitches.erase(randomSwitches.begin() + i--); + } } for (size_t i = 0; i < screenRegionSwitches.size(); i++) { ScreenRegionSwitch &s = screenRegionSwitches[i]; - if (!s.valid()) + if (!s.valid()) { screenRegionSwitches.erase( screenRegionSwitches.begin() + i--); + } } for (size_t i = 0; i < pauseEntries.size(); i++) { PauseEntry &s = pauseEntries[i]; - if (!s.valid()) + if (!s.valid()) { pauseEntries.erase(pauseEntries.begin() + i--); + } } for (size_t i = 0; i < sceneSequenceSwitches.size(); i++) { SceneSequenceSwitch &s = sceneSequenceSwitches[i]; - if (!s.valid()) + if (!s.valid()) { sceneSequenceSwitches.erase( sceneSequenceSwitches.begin() + i--); + } } for (size_t i = 0; i < sceneTransitions.size(); i++) { SceneTransition &s = sceneTransitions[i]; - if (!s.valid()) + if (!s.valid()) { sceneTransitions.erase(sceneTransitions.begin() + i--); + } } for (size_t i = 0; i < defaultSceneTransitions.size(); i++) { DefaultSceneTransition &s = defaultSceneTransitions[i]; - if (!s.valid()) + if (!s.valid()) { defaultSceneTransitions.erase( defaultSceneTransitions.begin() + i--); + } } for (size_t i = 0; i < executableSwitches.size(); i++) { ExecutableSwitch &s = executableSwitches[i]; - if (!s.valid()) + if (!s.valid()) { executableSwitches.erase(executableSwitches.begin() + i--); + } } for (size_t i = 0; i < fileSwitches.size(); i++) { FileSwitch &s = fileSwitches[i]; - if (!s.valid()) + if (!s.valid()) { fileSwitches.erase(fileSwitches.begin() + i--); + } } for (size_t i = 0; i < timeSwitches.size(); i++) { TimeSwitch &s = timeSwitches[i]; - if (!s.valid()) + if (!s.valid()) { timeSwitches.erase(timeSwitches.begin() + i--); + } } if (!idleData.valid()) { @@ -78,20 +88,23 @@ void SwitcherData::Prune() for (size_t i = 0; i < mediaSwitches.size(); i++) { MediaSwitch &s = mediaSwitches[i]; - if (!s.valid()) + if (!s.valid()) { mediaSwitches.erase(mediaSwitches.begin() + i--); + } } for (size_t i = 0; i < audioSwitches.size(); i++) { AudioSwitch &s = audioSwitches[i]; - if (!s.valid()) + if (!s.valid()) { audioSwitches.erase(audioSwitches.begin() + i--); + } } for (auto &sg : sceneGroups) { for (size_t i = 0; i < sg.scenes.size(); i++) - if (!WeakSourceValid(sg.scenes[i])) + if (!WeakSourceValid(sg.scenes[i])) { sg.scenes.erase(sg.scenes.begin() + i--); + } } } diff --git a/src/volume-control.cpp b/src/volume-control.cpp index 842bbb74..df1bcfd8 100644 --- a/src/volume-control.cpp +++ b/src/volume-control.cpp @@ -82,7 +82,10 @@ VolControl::VolControl(OBSSource source_, bool vertical) nameLabel = new QLabel(); volLabel = new QLabel(); - QString sourceName = obs_source_get_name(source); + QString sourceName = ""; + if (source) { + obs_source_get_name(source); + } setObjectName(sourceName); QVBoxLayout *mainLayout = new QVBoxLayout; diff --git a/src/win/advanced-scene-switcher-win.cpp b/src/win/advanced-scene-switcher-win.cpp index 23b845cf..02c18dee 100644 --- a/src/win/advanced-scene-switcher-win.cpp +++ b/src/win/advanced-scene-switcher-win.cpp @@ -15,8 +15,9 @@ static bool GetWindowTitle(HWND window, std::string &title) std::wstring wtitle; wtitle.resize(len); - if (!GetWindowTextW(window, &wtitle[0], (int)len + 1)) + if (!GetWindowTextW(window, &wtitle[0], (int)len + 1)) { return false; + } len = os_wcs_to_utf8(wtitle.c_str(), 0, nullptr, 0); title.resize(len); @@ -29,16 +30,19 @@ static bool WindowValid(HWND window) LONG_PTR styles; DWORD id; - if (!IsWindowVisible(window)) + if (!IsWindowVisible(window)) { return false; + } GetWindowThreadProcessId(window, &id); - if (id == GetCurrentProcessId()) + if (id == GetCurrentProcessId()) { return false; + } styles = GetWindowLongPtr(window, GWL_STYLE); - if (styles & WS_CHILD) + if (styles & WS_CHILD) { return false; + } return true; } @@ -51,8 +55,9 @@ BOOL CALLBACK GetTitleCB(HWND hwnd, LPARAM lParam) std::string title; GetWindowTitle(hwnd, title); - if (title.empty()) + if (title.empty()) { return TRUE; + } std::vector &titles = *reinterpret_cast *>(lParam); @@ -68,8 +73,9 @@ VOID EnumWindowsWithMetro(__in WNDENUMPROC lpEnumFunc, __in LPARAM lParam) while (i < MAX_SEARCH && (childWindow = FindWindowEx(NULL, childWindow, NULL, NULL))) { - if (!lpEnumFunc(childWindow, lParam)) + if (!lpEnumFunc(childWindow, lParam)) { return; + } i++; } } @@ -140,8 +146,9 @@ bool isMaximized(std::string &title) HWND hwnd = NULL; hwnd = getHWNDfromTitle(title); - if (!hwnd) + if (!hwnd) { return false; + } monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), @@ -170,8 +177,9 @@ bool isFullscreen(std::string &title) HWND hwnd = NULL; hwnd = getHWNDfromTitle(title); - if (!hwnd) + if (!hwnd) { return false; + } monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), @@ -197,8 +205,9 @@ void GetProcessList(QStringList &processes) PROCESSENTRY32 procEntry; procSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); - if (procSnapshot == INVALID_HANDLE_VALUE) + if (procSnapshot == INVALID_HANDLE_VALUE) { return; + } procEntry.dwSize = sizeof(PROCESSENTRY32); @@ -209,12 +218,15 @@ void GetProcessList(QStringList &processes) do { QString tempexe = QString::fromWCharArray(procEntry.szExeFile); - if (tempexe == "System") + if (tempexe == "System") { continue; - if (tempexe == "[System Process]") + } + if (tempexe == "[System Process]") { continue; - if (processes.contains(tempexe)) + } + if (processes.contains(tempexe)) { continue; + } processes.append(tempexe); } while (Process32Next(procSnapshot, &procEntry)); @@ -231,8 +243,9 @@ bool isInFocus(const QString &executable) HANDLE process = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId); - if (process == NULL) + if (process == NULL) { return false; + } WCHAR executablePath[600]; GetModuleFileNameEx(process, 0, executablePath, 600); @@ -254,8 +267,9 @@ int getLastInputTime() { LASTINPUTINFO lastInputInfo; lastInputInfo.cbSize = sizeof(LASTINPUTINFO); - if (GetLastInputInfo(&lastInputInfo)) + if (GetLastInputInfo(&lastInputInfo)) { return lastInputInfo.dwTime; + } return 0; }