From 2cbb3c2505298de75a35c8b4e84b26f1e7dcf108 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 17 Nov 2016 05:29:30 -0800 Subject: [PATCH] frontend-tools: Move source helper functions to a header --- .../frontend-tools/CMakeLists.txt | 1 + .../frontend-tools/auto-scene-switcher.cpp | 32 +---------------- .../frontend-tools/tool-helpers.hpp | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 UI/frontend-plugins/frontend-tools/tool-helpers.hpp diff --git a/UI/frontend-plugins/frontend-tools/CMakeLists.txt b/UI/frontend-plugins/frontend-tools/CMakeLists.txt index f186de642..7b340e119 100644 --- a/UI/frontend-plugins/frontend-tools/CMakeLists.txt +++ b/UI/frontend-plugins/frontend-tools/CMakeLists.txt @@ -20,6 +20,7 @@ endif() set(frontend-tools_HEADERS ${frontend-tools_HEADERS} output-timer.hpp + tool-helpers.hpp ) set(frontend-tools_SOURCES ${frontend-tools_SOURCES} diff --git a/UI/frontend-plugins/frontend-tools/auto-scene-switcher.cpp b/UI/frontend-plugins/frontend-tools/auto-scene-switcher.cpp index 999d3525c..06c030702 100644 --- a/UI/frontend-plugins/frontend-tools/auto-scene-switcher.cpp +++ b/UI/frontend-plugins/frontend-tools/auto-scene-switcher.cpp @@ -6,6 +6,7 @@ #include #include #include "auto-scene-switcher.hpp" +#include "tool-helpers.hpp" #include #include @@ -82,37 +83,6 @@ static inline QString MakeSwitchName(const QString &scene, return QStringLiteral("[") + scene + QStringLiteral("]: ") + window; } -static inline string GetWeakSourceName(obs_weak_source_t *weak_source) -{ - string name; - - obs_source_t *source = obs_weak_source_get_source(weak_source); - if (source) { - name = obs_source_get_name(source); - obs_source_release(source); - } - - return name; -} - -static inline OBSWeakSource GetWeakSourceByName(const char *name) -{ - OBSWeakSource weak; - obs_source_t *source = obs_get_source_by_name(name); - if (source) { - weak = obs_source_get_weak_source(source); - obs_weak_source_release(weak); - obs_source_release(source); - } - - return weak; -} - -static inline OBSWeakSource GetWeakSourceByQString(const QString &name) -{ - return GetWeakSourceByName(name.toUtf8().constData()); -} - SceneSwitcher::SceneSwitcher(QWidget *parent) : QDialog(parent), ui(new Ui_SceneSwitcher) diff --git a/UI/frontend-plugins/frontend-tools/tool-helpers.hpp b/UI/frontend-plugins/frontend-tools/tool-helpers.hpp new file mode 100644 index 000000000..840e746ff --- /dev/null +++ b/UI/frontend-plugins/frontend-tools/tool-helpers.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include + +static inline OBSWeakSource GetWeakSourceByName(const char *name) +{ + OBSWeakSource weak; + obs_source_t *source = obs_get_source_by_name(name); + if (source) { + weak = obs_source_get_weak_source(source); + obs_weak_source_release(weak); + obs_source_release(source); + } + + return weak; +} + +static inline OBSWeakSource GetWeakSourceByQString(const QString &name) +{ + return GetWeakSourceByName(name.toUtf8().constData()); +} + +static inline std::string GetWeakSourceName(obs_weak_source_t *weak_source) +{ + std::string name; + + obs_source_t *source = obs_weak_source_get_source(weak_source); + if (source) { + name = obs_source_get_name(source); + obs_source_release(source); + } + + return name; +}