mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-07 00:56:00 -05:00
Most files: Move files into subdirectories
Almost all the files have been moved into folders and subfolders to keep everything organized and clean.
This commit is contained in:
175
src/headers/advanced-scene-switcher.hpp
Normal file
175
src/headers/advanced-scene-switcher.hpp
Normal file
@@ -0,0 +1,175 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "../forms/ui_advanced-scene-switcher.h"
|
||||
#include "switcher-data-structs.hpp"
|
||||
|
||||
class QCloseEvent;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Advanced Scene Switcher window
|
||||
*******************************************************************************/
|
||||
class SceneSwitcher : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
std::unique_ptr<Ui_SceneSwitcher> ui;
|
||||
bool loading = true;
|
||||
|
||||
SceneSwitcher(QWidget *parent);
|
||||
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
void SetStarted();
|
||||
void SetStopped();
|
||||
|
||||
int FindByData(const QString &window);
|
||||
int ScreenRegionFindByData(const QString ®ion);
|
||||
int PauseScenesFindByData(const QString &scene);
|
||||
int PauseWindowsFindByData(const QString &window);
|
||||
int IgnoreWindowsFindByData(const QString &window);
|
||||
int SceneRoundTripFindByData(const QString &scene1);
|
||||
int SceneTransitionsFindByData(const QString &scene1, const QString &scene2);
|
||||
int DefaultTransitionsFindByData(const QString &scene);
|
||||
int executableFindByData(const QString &exe);
|
||||
int IgnoreIdleWindowsFindByData(const QString& window);
|
||||
int randomFindByData(const QString& scene);
|
||||
|
||||
void UpdateNonMatchingScene(const QString &name);
|
||||
void UpdateAutoStopScene(const QString &name);
|
||||
void UpdateIdleDataTransition(const QString& name);
|
||||
void UpdateIdleDataScene(const QString& name);
|
||||
|
||||
public slots:
|
||||
void on_switches_currentRowChanged(int idx);
|
||||
void on_add_clicked();
|
||||
void on_remove_clicked();
|
||||
void on_noMatchDontSwitch_clicked();
|
||||
void on_noMatchSwitch_clicked();
|
||||
void on_noMatchRandomSwitch_clicked();
|
||||
void on_startAtLaunch_toggled(bool value);
|
||||
void on_noMatchSwitchScene_currentTextChanged(const QString &text);
|
||||
void on_checkInterval_valueChanged(int value);
|
||||
void on_toggleStartButton_clicked();
|
||||
|
||||
void on_screenRegions_currentRowChanged(int idx);
|
||||
void on_screenRegionAdd_clicked();
|
||||
void on_screenRegionRemove_clicked();
|
||||
|
||||
void on_pauseScenes_currentRowChanged(int idx);
|
||||
void on_pauseScenesAdd_clicked();
|
||||
void on_pauseScenesRemove_clicked();
|
||||
|
||||
void on_pauseWindows_currentRowChanged(int idx);
|
||||
void on_pauseWindowsAdd_clicked();
|
||||
void on_pauseWindowsRemove_clicked();
|
||||
|
||||
void on_ignoreWindows_currentRowChanged(int idx);
|
||||
void on_ignoreWindowsAdd_clicked();
|
||||
void on_ignoreWindowsRemove_clicked();
|
||||
|
||||
void on_sceneRoundTrips_currentRowChanged(int idx);
|
||||
void on_sceneRoundTripAdd_clicked();
|
||||
void on_sceneRoundTripRemove_clicked();
|
||||
void on_sceneRoundTripSave_clicked();
|
||||
void on_sceneRoundTripLoad_clicked();
|
||||
|
||||
void on_autoStopSceneCheckBox_stateChanged(int state);
|
||||
void on_autoStopScenes_currentTextChanged(const QString &text);
|
||||
|
||||
void on_sceneTransitions_currentRowChanged(int idx);
|
||||
void on_transitionsAdd_clicked();
|
||||
void on_transitionsRemove_clicked();
|
||||
void on_defaultTransitions_currentRowChanged(int idx);
|
||||
void on_defaultTransitionsAdd_clicked();
|
||||
void on_defaultTransitionsRemove_clicked();
|
||||
|
||||
void on_browseButton_clicked();
|
||||
void on_readFileCheckBox_stateChanged(int state);
|
||||
void on_readPathLineEdit_textChanged(const QString & text);
|
||||
void on_writePathLineEdit_textChanged(const QString & text);
|
||||
void on_browseButton_2_clicked();
|
||||
|
||||
void on_executableAdd_clicked();
|
||||
void on_executableRemove_clicked();
|
||||
void on_executables_currentRowChanged(int idx);
|
||||
|
||||
void on_idleCheckBox_stateChanged(int state);
|
||||
void on_idleTransitions_currentTextChanged(const QString& text);
|
||||
void on_idleScenes_currentTextChanged(const QString& text);
|
||||
void on_idleSpinBox_valueChanged(int i);
|
||||
void on_ignoreIdleWindows_currentRowChanged(int idx);
|
||||
void on_ignoreIdleAdd_clicked();
|
||||
void on_ignoreIdleRemove_clicked();
|
||||
|
||||
void on_randomAdd_clicked();
|
||||
void on_randomRemove_clicked();
|
||||
void on_randomScenesList_currentRowChanged(int idx);
|
||||
|
||||
void on_fileAdd_clicked();
|
||||
void on_fileRemove_clicked();
|
||||
void on_fileScenesList_currentRowChanged(int idx);
|
||||
void on_browseButton_3_clicked();
|
||||
|
||||
void on_priorityUp_clicked();
|
||||
void on_priorityDown_clicked();
|
||||
|
||||
void updateScreenRegionCursorPos();
|
||||
|
||||
void on_close_clicked();
|
||||
};
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Windowtitle helper
|
||||
********************************************************************************/
|
||||
void GetWindowList(std::vector<std::string> &windows);
|
||||
void GetCurrentWindowTitle(std::string &title);
|
||||
bool isFullscreen();
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Screenregion helper
|
||||
********************************************************************************/
|
||||
pair<int, int> getCursorPos();
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Idle detection helper
|
||||
********************************************************************************/
|
||||
int secondsSinceLastInput();
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Executable helper
|
||||
********************************************************************************/
|
||||
void GetProcessList(QStringList &processes);
|
||||
bool isInFocus(const QString &exeToCheck);
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Sceneswitch helper
|
||||
********************************************************************************/
|
||||
struct obs_weak_source;
|
||||
typedef struct obs_weak_source obs_weak_source_t;
|
||||
|
||||
obs_weak_source_t* getNextTransition(obs_weak_source_t* scene1, obs_weak_source_t* scene2);
|
||||
void switchScene(OBSWeakSource& scene, OBSWeakSource& transition);
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Hotkey helper
|
||||
********************************************************************************/
|
||||
void startStopHotkeyFunc(void* data, obs_hotkey_id id, obs_hotkey_t* hotkey, bool pressed);
|
||||
void loadKeybinding(obs_hotkey_id hotkeyId);
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Main SwitcherData
|
||||
********************************************************************************/
|
||||
struct SwitcherData;
|
||||
extern SwitcherData* switcher;
|
||||
378
src/headers/switcher-data-structs.hpp
Normal file
378
src/headers/switcher-data-structs.hpp
Normal file
@@ -0,0 +1,378 @@
|
||||
#pragma once
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <regex>
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
#include <QDateTime>
|
||||
#include "utility.hpp"
|
||||
|
||||
#define DEFAULT_INTERVAL 300
|
||||
|
||||
#define DEFAULT_IDLE_TIME 60
|
||||
|
||||
#define PREVIOUS_SCENE_NAME "Previous Scene"
|
||||
|
||||
#define READ_FILE_FUNC 0
|
||||
#define ROUND_TRIP_FUNC 1
|
||||
#define IDLE_FUNC 2
|
||||
#define EXE_FUNC 3
|
||||
#define SCREEN_REGION_FUNC 4
|
||||
#define WINDOW_TITLE_FUNC 5
|
||||
|
||||
#define DEFAULT_PRIORITY_0 READ_FILE_FUNC
|
||||
#define DEFAULT_PRIORITY_1 ROUND_TRIP_FUNC
|
||||
#define DEFAULT_PRIORITY_2 IDLE_FUNC
|
||||
#define DEFAULT_PRIORITY_3 EXE_FUNC
|
||||
#define DEFAULT_PRIORITY_4 SCREEN_REGION_FUNC
|
||||
#define DEFAULT_PRIORITY_5 WINDOW_TITLE_FUNC
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Data structs for each scene switching method
|
||||
********************************************************************************/
|
||||
struct WindowSceneSwitch
|
||||
{
|
||||
OBSWeakSource scene;
|
||||
string window;
|
||||
OBSWeakSource transition;
|
||||
bool fullscreen;
|
||||
|
||||
inline WindowSceneSwitch(
|
||||
OBSWeakSource scene_, const char* window_, OBSWeakSource transition_, bool fullscreen_)
|
||||
: scene(scene_)
|
||||
, window(window_)
|
||||
, transition(transition_)
|
||||
, fullscreen(fullscreen_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct ExecutableSceneSwitch
|
||||
{
|
||||
OBSWeakSource mScene;
|
||||
OBSWeakSource mTransition;
|
||||
QString mExe;
|
||||
bool mInFocus;
|
||||
|
||||
inline ExecutableSceneSwitch(
|
||||
OBSWeakSource scene, OBSWeakSource transition, const QString& exe, bool inFocus)
|
||||
: mScene(scene)
|
||||
, mTransition(transition)
|
||||
, mExe(exe)
|
||||
, mInFocus(inFocus)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct ScreenRegionSwitch
|
||||
{
|
||||
OBSWeakSource scene;
|
||||
OBSWeakSource transition;
|
||||
int minX, minY, maxX, maxY;
|
||||
string regionStr;
|
||||
|
||||
inline ScreenRegionSwitch(OBSWeakSource scene_, OBSWeakSource transition_, int minX_, int minY_,
|
||||
int maxX_, int maxY_, string regionStr_)
|
||||
: scene(scene_)
|
||||
, transition(transition_)
|
||||
, minX(minX_)
|
||||
, minY(minY_)
|
||||
, maxX(maxX_)
|
||||
, maxY(maxY_)
|
||||
, regionStr(regionStr_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct SceneRoundTripSwitch
|
||||
{
|
||||
OBSWeakSource scene1;
|
||||
OBSWeakSource scene2;
|
||||
OBSWeakSource transition;
|
||||
int delay;
|
||||
bool usePreviousScene;
|
||||
string sceneRoundTripStr;
|
||||
|
||||
inline SceneRoundTripSwitch(OBSWeakSource scene1_, OBSWeakSource scene2_,
|
||||
OBSWeakSource transition_, int delay_, bool usePreviousScene_, string str)
|
||||
: scene1(scene1_)
|
||||
, scene2(scene2_)
|
||||
, transition(transition_)
|
||||
, delay(delay_)
|
||||
, usePreviousScene(usePreviousScene_)
|
||||
, sceneRoundTripStr(str)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct RandomSwitch
|
||||
{
|
||||
OBSWeakSource scene;
|
||||
OBSWeakSource transition;
|
||||
double delay;
|
||||
string randomSwitchStr;
|
||||
|
||||
inline RandomSwitch(OBSWeakSource scene_, OBSWeakSource transition_
|
||||
, double delay_, string str)
|
||||
: scene(scene_)
|
||||
, transition(transition_)
|
||||
, delay(delay_)
|
||||
, randomSwitchStr(str)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct SceneTransition
|
||||
{
|
||||
OBSWeakSource scene1;
|
||||
OBSWeakSource scene2;
|
||||
OBSWeakSource transition;
|
||||
string sceneTransitionStr;
|
||||
|
||||
inline SceneTransition(OBSWeakSource scene1_, OBSWeakSource scene2_, OBSWeakSource transition_,
|
||||
string sceneTransitionStr_)
|
||||
: scene1(scene1_)
|
||||
, scene2(scene2_)
|
||||
, transition(transition_)
|
||||
, sceneTransitionStr(sceneTransitionStr_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct DefaultSceneTransition
|
||||
{
|
||||
OBSWeakSource scene;
|
||||
OBSWeakSource transition;
|
||||
string sceneTransitionStr;
|
||||
|
||||
inline DefaultSceneTransition(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||
string sceneTransitionStr_)
|
||||
: scene(scene_)
|
||||
, transition(transition_)
|
||||
, sceneTransitionStr(sceneTransitionStr_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct FileSwitch
|
||||
{
|
||||
OBSWeakSource scene;
|
||||
OBSWeakSource transition;
|
||||
string file;
|
||||
string text;
|
||||
bool useRegex = false;
|
||||
bool useTime = false;
|
||||
QDateTime lastMod;
|
||||
|
||||
inline FileSwitch(
|
||||
OBSWeakSource scene_, OBSWeakSource transition_, const char* file_, const char* text_, bool useRegex_, bool useTime_)
|
||||
: scene(scene_)
|
||||
, transition(transition_)
|
||||
, file(file_)
|
||||
, text(text_)
|
||||
, useRegex(useRegex_)
|
||||
, useTime(useTime_)
|
||||
, lastMod()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct FileIOData
|
||||
{
|
||||
bool readEnabled = false;
|
||||
string readPath;
|
||||
bool writeEnabled = false;
|
||||
string writePath;
|
||||
};
|
||||
|
||||
struct IdleData
|
||||
{
|
||||
bool idleEnable = false;
|
||||
int time = DEFAULT_IDLE_TIME;
|
||||
OBSWeakSource scene;
|
||||
OBSWeakSource transition;
|
||||
bool usePreviousScene;
|
||||
bool alreadySwitched = false;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NO_SWITCH = 0,
|
||||
SWITCH = 1,
|
||||
RANDOM_SWITCH = 2
|
||||
} NoMatch;
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* SwitcherData
|
||||
********************************************************************************/
|
||||
struct SwitcherData
|
||||
{
|
||||
thread th;
|
||||
condition_variable cv;
|
||||
mutex m;
|
||||
bool transitionActive = false;
|
||||
bool waitForTransition = false;
|
||||
condition_variable transitionCv;
|
||||
bool startAtLaunch = false;
|
||||
bool stop = false;
|
||||
|
||||
int interval = DEFAULT_INTERVAL;
|
||||
|
||||
obs_source_t* waitScene = NULL; //scene during which wait started
|
||||
OBSWeakSource previousScene = NULL;
|
||||
OBSWeakSource PreviousScene2 = NULL;
|
||||
OBSWeakSource lastRandomScene;
|
||||
OBSWeakSource nonMatchingScene;
|
||||
NoMatch switchIfNotMatching = NO_SWITCH;
|
||||
|
||||
vector<WindowSceneSwitch> windowSwitches;
|
||||
vector<string> ignoreIdleWindows;
|
||||
string lastTitle;
|
||||
|
||||
vector<ScreenRegionSwitch> screenRegionSwitches;
|
||||
|
||||
vector<OBSWeakSource> pauseScenesSwitches;
|
||||
|
||||
vector<string> pauseWindowsSwitches;
|
||||
|
||||
vector<string> ignoreWindowsSwitches;
|
||||
|
||||
vector<SceneRoundTripSwitch> sceneRoundTripSwitches;
|
||||
|
||||
vector<RandomSwitch> randomSwitches;
|
||||
|
||||
FileIOData fileIO;
|
||||
IdleData idleData;
|
||||
vector<FileSwitch> fileSwitches;
|
||||
|
||||
vector<ExecutableSceneSwitch> executableSwitches;
|
||||
|
||||
bool autoStopEnable = false;
|
||||
OBSWeakSource autoStopScene;
|
||||
|
||||
vector<SceneTransition> sceneTransitions;
|
||||
vector<DefaultSceneTransition> defaultSceneTransitions;
|
||||
|
||||
vector<int> functionNamesByPriority = vector<int>{
|
||||
DEFAULT_PRIORITY_0,
|
||||
DEFAULT_PRIORITY_1,
|
||||
DEFAULT_PRIORITY_2,
|
||||
DEFAULT_PRIORITY_3,
|
||||
DEFAULT_PRIORITY_4,
|
||||
DEFAULT_PRIORITY_5,
|
||||
};
|
||||
|
||||
void Thread();
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
bool sceneChangedDuringWait();
|
||||
bool prioFuncsValid();
|
||||
void writeSceneInfoToFile();
|
||||
void setDefaultSceneTransitions(unique_lock<mutex>& lock);
|
||||
void autoStopStreamAndRecording();
|
||||
bool checkPause();
|
||||
void checkSceneRoundTrip(bool& match, OBSWeakSource& scene, OBSWeakSource& transition, unique_lock<mutex>& lock);
|
||||
void checkIdleSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition);
|
||||
void checkWindowTitleSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition);
|
||||
void checkExeSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition);
|
||||
void checkScreenRegionSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition);
|
||||
void checkSwitchInfoFromFile(bool& match, OBSWeakSource& scene, OBSWeakSource& transition);
|
||||
void checkFileContent(bool& match, OBSWeakSource& scene, OBSWeakSource& transition);
|
||||
void checkRandom(bool& match, OBSWeakSource& scene, OBSWeakSource& transition, int& delay);
|
||||
|
||||
void Prune()
|
||||
{
|
||||
for (size_t i = 0; i < windowSwitches.size(); i++)
|
||||
{
|
||||
WindowSceneSwitch& s = windowSwitches[i];
|
||||
if (!WeakSourceValid(s.scene) || !WeakSourceValid(s.transition))
|
||||
windowSwitches.erase(windowSwitches.begin() + i--);
|
||||
}
|
||||
|
||||
if (nonMatchingScene && !WeakSourceValid(nonMatchingScene))
|
||||
{
|
||||
switchIfNotMatching = NO_SWITCH;
|
||||
nonMatchingScene = nullptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < randomSwitches.size(); i++)
|
||||
{
|
||||
RandomSwitch& s = randomSwitches[i];
|
||||
if (!WeakSourceValid(s.scene) || !WeakSourceValid(s.transition))
|
||||
randomSwitches.erase(randomSwitches.begin() + i--);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < screenRegionSwitches.size(); i++)
|
||||
{
|
||||
ScreenRegionSwitch& s = screenRegionSwitches[i];
|
||||
if (!WeakSourceValid(s.scene) || !WeakSourceValid(s.transition))
|
||||
screenRegionSwitches.erase(screenRegionSwitches.begin() + i--);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < pauseScenesSwitches.size(); i++)
|
||||
{
|
||||
OBSWeakSource& scene = pauseScenesSwitches[i];
|
||||
if (!WeakSourceValid(scene))
|
||||
pauseScenesSwitches.erase(pauseScenesSwitches.begin() + i--);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sceneRoundTripSwitches.size(); i++)
|
||||
{
|
||||
SceneRoundTripSwitch& s = sceneRoundTripSwitches[i];
|
||||
if (!WeakSourceValid(s.scene1) || (!s.usePreviousScene && !WeakSourceValid(s.scene2))
|
||||
|| !WeakSourceValid(s.transition))
|
||||
sceneRoundTripSwitches.erase(sceneRoundTripSwitches.begin() + i--);
|
||||
}
|
||||
|
||||
if (!WeakSourceValid(autoStopScene))
|
||||
{
|
||||
autoStopScene = nullptr;
|
||||
autoStopEnable = false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sceneTransitions.size(); i++)
|
||||
{
|
||||
SceneTransition& s = sceneTransitions[i];
|
||||
if (!WeakSourceValid(s.scene1) || !WeakSourceValid(s.scene2)
|
||||
|| !WeakSourceValid(s.transition))
|
||||
sceneTransitions.erase(sceneTransitions.begin() + i--);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < defaultSceneTransitions.size(); i++)
|
||||
{
|
||||
DefaultSceneTransition& s = defaultSceneTransitions[i];
|
||||
if (!WeakSourceValid(s.scene) || !WeakSourceValid(s.transition))
|
||||
defaultSceneTransitions.erase(defaultSceneTransitions.begin() + i--);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < executableSwitches.size(); i++)
|
||||
{
|
||||
ExecutableSceneSwitch& s = executableSwitches[i];
|
||||
if (!WeakSourceValid(s.mScene) || !WeakSourceValid(s.mTransition))
|
||||
executableSwitches.erase(executableSwitches.begin() + i--);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < fileSwitches.size(); i++)
|
||||
{
|
||||
FileSwitch& s = fileSwitches[i];
|
||||
if (!WeakSourceValid(s.scene) || !WeakSourceValid(s.transition))
|
||||
fileSwitches.erase(fileSwitches.begin() + i--);
|
||||
}
|
||||
|
||||
if (!idleData.usePreviousScene && !WeakSourceValid(idleData.scene) || !WeakSourceValid(idleData.transition))
|
||||
{
|
||||
idleData.idleEnable = false;
|
||||
}
|
||||
}
|
||||
inline ~SwitcherData()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
};
|
||||
166
src/headers/utility.hpp
Normal file
166
src/headers/utility.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#pragma once
|
||||
#include <obs.hpp>
|
||||
#include <QString>
|
||||
#include <obs-frontend-api.h>
|
||||
#include "switcher-data-structs.hpp"
|
||||
using namespace std;
|
||||
|
||||
static inline bool WeakSourceValid(obs_weak_source_t* ws)
|
||||
{
|
||||
obs_source_t* source = obs_weak_source_get_source(ws);
|
||||
if (source)
|
||||
obs_source_release(source);
|
||||
return !!source;
|
||||
}
|
||||
|
||||
static inline QString MakeSwitchName(
|
||||
const QString& scene, const QString& value, const QString& transition, bool fullscreen)
|
||||
{
|
||||
if (!fullscreen)
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition
|
||||
+ QStringLiteral("]: ") + value;
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition + QStringLiteral("]: ")
|
||||
+ value + QStringLiteral(" (only if window is fullscreen)");
|
||||
}
|
||||
|
||||
static inline QString MakeSwitchNameExecutable(
|
||||
const QString& scene, const QString& value, const QString& transition, bool inFocus)
|
||||
{
|
||||
if (!inFocus)
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition
|
||||
+ QStringLiteral("]: ") + value;
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition + QStringLiteral("]: ")
|
||||
+ value + QStringLiteral(" (only if window is focused)");
|
||||
}
|
||||
|
||||
static inline QString MakeScreenRegionSwitchName(
|
||||
const QString& scene, const QString& transition, int minX, int minY, int maxX, int maxY)
|
||||
{
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition + QStringLiteral("]: ")
|
||||
+ QString::number(minX) + QStringLiteral(", ") + QString::number(minY)
|
||||
+ QStringLiteral(" x ") + QString::number(maxX) + QStringLiteral(", ")
|
||||
+ QString::number(maxY);
|
||||
}
|
||||
|
||||
static inline QString MakeSceneRoundTripSwitchName(
|
||||
const QString& scene1, const QString& scene2, const QString& transition, double delay)
|
||||
{
|
||||
return scene1 + QStringLiteral(" -> wait for ") + QString::number(delay)
|
||||
+ QStringLiteral(" seconds -> ") + scene2 + QStringLiteral(" (using ") + transition
|
||||
+ QStringLiteral(" transition)");
|
||||
}
|
||||
|
||||
static inline QString MakeSceneTransitionName(
|
||||
const QString& scene1, const QString& scene2, const QString& transition)
|
||||
{
|
||||
return scene1 + QStringLiteral(" --- ") + transition + QStringLiteral(" --> ") + scene2;
|
||||
}
|
||||
|
||||
static inline QString MakeDefaultSceneTransitionName(
|
||||
const QString& scene, const QString& transition)
|
||||
{
|
||||
return scene + QStringLiteral(" --> ") + transition;
|
||||
}
|
||||
|
||||
static inline QString MakeRandomSwitchName(
|
||||
const QString& scene, const QString& transition, double& delay)
|
||||
{
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition + QStringLiteral("]: ")
|
||||
+ QString::number(delay) + QStringLiteral(" seconds");
|
||||
}
|
||||
|
||||
static inline QString MakeFileSwitchName(
|
||||
const QString& scene, const QString& transition, const QString& fileName, const QString& text, bool useRegex, bool useTime)
|
||||
{
|
||||
QString switchName = QStringLiteral("Switch to ") + scene + QStringLiteral(" using ") + transition + QStringLiteral(" if ")
|
||||
+ fileName;
|
||||
if (useTime)
|
||||
switchName += QStringLiteral(" was modified and");
|
||||
switchName += QStringLiteral(" contains");
|
||||
if (useRegex)
|
||||
switchName += QStringLiteral(" (RegEx): \n\"");
|
||||
else
|
||||
switchName += QStringLiteral(": \n\"");
|
||||
if (text.length() > 30)
|
||||
switchName += text.left(27) + QStringLiteral("...\"");
|
||||
else
|
||||
switchName += text + QStringLiteral("\"");
|
||||
|
||||
return switchName;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
static inline OBSWeakSource GetWeakTransitionByName(const char* transitionName)
|
||||
{
|
||||
OBSWeakSource weak;
|
||||
obs_source_t* source = nullptr;
|
||||
|
||||
if (strcmp(transitionName, "Default") == 0)
|
||||
{
|
||||
source = obs_frontend_get_current_transition();
|
||||
weak = obs_source_get_weak_source(source);
|
||||
obs_source_release(source);
|
||||
obs_weak_source_release(weak);
|
||||
return weak;
|
||||
}
|
||||
|
||||
obs_frontend_source_list* transitions = new obs_frontend_source_list();
|
||||
obs_frontend_get_transitions(transitions);
|
||||
bool match = false;
|
||||
|
||||
for (size_t i = 0; i < transitions->sources.num; i++)
|
||||
{
|
||||
const char* name = obs_source_get_name(transitions->sources.array[i]);
|
||||
if (strcmp(transitionName, name) == 0)
|
||||
{
|
||||
match = true;
|
||||
source = transitions->sources.array[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (match){
|
||||
weak = obs_source_get_weak_source(source);
|
||||
obs_weak_source_release(weak);
|
||||
}
|
||||
obs_frontend_source_list_free(transitions);
|
||||
|
||||
return weak;
|
||||
}
|
||||
|
||||
static inline OBSWeakSource GetWeakTransitionByQString(const QString& name)
|
||||
{
|
||||
return GetWeakTransitionByName(name.toUtf8().constData());
|
||||
}
|
||||
Reference in New Issue
Block a user