mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-20 00:05:41 -05:00
Add option to automatically start scene switcher on recording / streaming start (#112)
This commit is contained in:
@@ -662,6 +662,20 @@ void resetLiveTime(SwitcherData *s)
|
||||
s->liveTime = QDateTime();
|
||||
}
|
||||
|
||||
void checkAutoStartRecording(SwitcherData *s)
|
||||
{
|
||||
if (s->autoStartEvent == AutoStartEvent::RECORDING ||
|
||||
s->autoStartEvent == AutoStartEvent::RECORINDG_OR_STREAMING)
|
||||
s->Start();
|
||||
}
|
||||
|
||||
void checkAutoStartStreaming(SwitcherData *s)
|
||||
{
|
||||
if (s->autoStartEvent == AutoStartEvent::STREAMING ||
|
||||
s->autoStartEvent == AutoStartEvent::RECORINDG_OR_STREAMING)
|
||||
s->Start();
|
||||
}
|
||||
|
||||
// Note to future self:
|
||||
// be careful using switcher->m here as there is potential for deadlocks when using
|
||||
// frontend functions such as obs_frontend_set_current_scene()
|
||||
@@ -678,8 +692,12 @@ static void OBSEvent(enum obs_frontend_event event, void *switcher)
|
||||
handleTransitionStop((SwitcherData *)switcher);
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_RECORDING_STARTED:
|
||||
setLiveTime((SwitcherData *)switcher);
|
||||
checkAutoStartRecording((SwitcherData *)switcher);
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_STREAMING_STARTED:
|
||||
setLiveTime((SwitcherData *)switcher);
|
||||
checkAutoStartStreaming((SwitcherData *)switcher);
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_RECORDING_STOPPED:
|
||||
case OBS_FRONTEND_EVENT_STREAMING_STOPPED:
|
||||
|
||||
@@ -75,6 +75,15 @@ void AdvSceneSwitcher::on_startupBehavior_currentIndexChanged(int index)
|
||||
switcher->startupBehavior = (StartupBehavior)index;
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_autoStartEvent_currentIndexChanged(int index)
|
||||
{
|
||||
if (loading)
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->autoStartEvent = static_cast<AutoStartEvent>(index);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_noMatchSwitchScene_currentTextChanged(
|
||||
const QString &text)
|
||||
{
|
||||
@@ -403,6 +412,9 @@ void SwitcherData::saveGeneralSettings(obs_data_t *obj)
|
||||
obs_data_set_bool(obj, "active", !switcher->stop);
|
||||
obs_data_set_int(obj, "startup_behavior", switcher->startupBehavior);
|
||||
|
||||
obs_data_set_int(obj, "autoStartEvent",
|
||||
static_cast<int>(switcher->autoStartEvent));
|
||||
|
||||
obs_data_set_bool(obj, "verbose", switcher->verbose);
|
||||
obs_data_set_bool(obj, "disableHints", switcher->disableHints);
|
||||
|
||||
@@ -476,6 +488,9 @@ void SwitcherData::loadGeneralSettings(obs_data_t *obj)
|
||||
if (switcher->startupBehavior == STOP)
|
||||
switcher->stop = true;
|
||||
|
||||
switcher->autoStartEvent = static_cast<AutoStartEvent>(
|
||||
obs_data_get_int(obj, "autoStartEvent"));
|
||||
|
||||
switcher->verbose = obs_data_get_bool(obj, "verbose");
|
||||
switcher->disableHints = obs_data_get_bool(obj, "disableHints");
|
||||
|
||||
@@ -614,6 +629,28 @@ void SwitcherData::checkSwitchCooldown(bool &match)
|
||||
blog(LOG_INFO, "cooldown active - ignoring match");
|
||||
}
|
||||
|
||||
void populateStartupBehavior(QComboBox *cb)
|
||||
{
|
||||
cb->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.onStartup.asLastRun"));
|
||||
cb->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.onStartup.alwaysStart"));
|
||||
cb->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.onStartup.doNotStart"));
|
||||
}
|
||||
|
||||
void populateAutoStartEventSelection(QComboBox *cb)
|
||||
{
|
||||
cb->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.autoStart.never"));
|
||||
cb->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.autoStart.recording"));
|
||||
cb->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.autoStart.streaming"));
|
||||
cb->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.autoStart.recordingAndStreaming"));
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::setupGeneralTab()
|
||||
{
|
||||
populateSceneSelection(ui->noMatchSwitchScene, false);
|
||||
@@ -701,15 +738,13 @@ void AdvSceneSwitcher::setupGeneralTab()
|
||||
}
|
||||
}
|
||||
|
||||
ui->startupBehavior->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.onStartup.asLastRun"));
|
||||
ui->startupBehavior->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.onStartup.alwaysStart"));
|
||||
ui->startupBehavior->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.generalTab.status.onStartup.doNotStart"));
|
||||
|
||||
populateStartupBehavior(ui->startupBehavior);
|
||||
ui->startupBehavior->setCurrentIndex(switcher->startupBehavior);
|
||||
|
||||
populateAutoStartEventSelection(ui->autoStartEvent);
|
||||
ui->autoStartEvent->setCurrentIndex(
|
||||
static_cast<int>(switcher->autoStartEvent));
|
||||
|
||||
if (switcher->th && switcher->th->isRunning())
|
||||
SetStarted();
|
||||
else
|
||||
|
||||
@@ -100,6 +100,7 @@ public slots:
|
||||
void on_noMatchDelay_valueChanged(double i);
|
||||
void on_cooldownTime_valueChanged(double i);
|
||||
void on_startupBehavior_currentIndexChanged(int index);
|
||||
void on_autoStartEvent_currentIndexChanged(int index);
|
||||
void on_noMatchSwitchScene_currentTextChanged(const QString &text);
|
||||
void on_checkInterval_valueChanged(int value);
|
||||
void on_toggleStartButton_clicked();
|
||||
|
||||
@@ -28,6 +28,13 @@ constexpr auto previous_scene_name = "Previous Scene";
|
||||
typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch;
|
||||
typedef enum { PERSIST = 0, START = 1, STOP = 2 } StartupBehavior;
|
||||
|
||||
enum class AutoStartEvent {
|
||||
NEVER,
|
||||
RECORDING,
|
||||
STREAMING,
|
||||
RECORINDG_OR_STREAMING,
|
||||
};
|
||||
|
||||
typedef struct transitionData {
|
||||
std::string name = "";
|
||||
int duration = 0;
|
||||
@@ -64,6 +71,7 @@ struct SwitcherData {
|
||||
double noMatchDelay;
|
||||
double noMatchCount = 0;
|
||||
StartupBehavior startupBehavior = PERSIST;
|
||||
AutoStartEvent autoStartEvent = AutoStartEvent::NEVER;
|
||||
|
||||
double cooldown = 0.;
|
||||
std::chrono::high_resolution_clock::time_point lastMatchTime;
|
||||
|
||||
Reference in New Issue
Block a user