add previous scene as option for scene round trip

This commit is contained in:
WarmUpTill 2018-07-13 23:54:05 +02:00
parent d41868c660
commit 70c0a8ed57
3 changed files with 37 additions and 15 deletions

View File

@ -63,6 +63,8 @@ SceneSwitcher::SceneSwitcher(QWidget* parent)
temp++;
}
ui->sceneRoundTripScenes2->addItem(PREVIOUS_SCENE_NAME);
obs_frontend_source_list* transitions = new obs_frontend_source_list();
obs_frontend_get_transitions(transitions);
@ -82,8 +84,6 @@ SceneSwitcher::SceneSwitcher(QWidget* parent)
obs_frontend_source_list_free(transitions);
if (switcher->switchIfNotMatching == SWITCH)
{
ui->noMatchSwitch->setChecked(true);
@ -191,8 +191,8 @@ SceneSwitcher::SceneSwitcher(QWidget* parent)
int smallestDelay = switcher->interval;
for (auto& s : switcher->sceneRoundTripSwitches)
{
string sceneName1 = GetWeakSourceName(s.scene1);
string sceneName2 = GetWeakSourceName(s.scene2);
string sceneName1 = GetWeakSourceName(s.scene1);
string sceneName2 = (s.usePreviousScene) ? PREVIOUS_SCENE_NAME : GetWeakSourceName(s.scene2);
string transitionName = GetWeakSourceName(s.transition);
QString text = MakeSceneRoundTripSwitchName(
sceneName1.c_str(), sceneName2.c_str(), transitionName.c_str(), (double)s.delay / 1000);
@ -444,13 +444,13 @@ static void SaveSceneSwitcher(obs_data_t* save_data, bool saving, void*)
obs_source_t* source1 = obs_weak_source_get_source(s.scene1);
obs_source_t* source2 = obs_weak_source_get_source(s.scene2);
obs_source_t* transition = obs_weak_source_get_source(s.transition);
if (source1 && source2 && transition)
if (source1 && (s.usePreviousScene || source2) && transition)
{
const char* sceneName1 = obs_source_get_name(source1);
const char* sceneName2 = obs_source_get_name(source2);
const char* transitionName = obs_source_get_name(transition);
obs_data_set_string(array_obj, "sceneRoundTripScene1", sceneName1);
obs_data_set_string(array_obj, "sceneRoundTripScene2", sceneName2);
obs_data_set_string(array_obj, "sceneRoundTripScene2", s.usePreviousScene ? PREVIOUS_SCENE_NAME : sceneName2);
obs_data_set_string(array_obj, "transition", transitionName);
obs_data_set_int(array_obj, "sceneRoundTripDelay", s.delay / 1000); //delay stored in two separate values
obs_data_set_int(array_obj, "sceneRoundTripDelayMs", s.delay % 1000); //to be compatible with older versions
@ -781,7 +781,7 @@ static void SaveSceneSwitcher(obs_data_t* save_data, bool saving, void*)
switcher->sceneRoundTripSwitches.emplace_back(GetWeakSourceByName(scene1),
GetWeakSourceByName(scene2), GetWeakTransitionByName(transition), delay,
sceneRoundTripStr);
(strcmp(scene2, PREVIOUS_SCENE_NAME) == 0), sceneRoundTripStr);
obs_data_release(array_obj);
}
@ -1053,6 +1053,7 @@ void SwitcherData::Thread()
{
switchScene(scene, transition);
}
setPreviousScene();
}
endLoop:
;
@ -1094,6 +1095,19 @@ void switchScene(OBSWeakSource scene, OBSWeakSource transition)
obs_source_release(source);
}
void SwitcherData::setPreviousScene()
{
obs_source_t* source = obs_frontend_get_current_scene();
obs_weak_source_t* ws = obs_source_get_weak_source(source);
obs_source_release(source);
obs_weak_source_release(ws);
if (!source)
return;
if (previousScene == ws)
return;
previousScene = ws;
}
bool SwitcherData::sceneChangedDuringWait() {
bool r = false;
obs_source_t* currentSource = obs_frontend_get_current_scene();

View File

@ -34,7 +34,9 @@ void SceneSwitcher::on_sceneRoundTripAdd_clicked()
lock_guard<mutex> lock(switcher->m);
switcher->sceneRoundTripSwitches.emplace_back(
source1, source2, transition, int(delay * 1000), text.toUtf8().constData());
source1, source2, transition, int(delay * 1000),
(scene2Name == QString(PREVIOUS_SCENE_NAME)),
text.toUtf8().constData());
}
else
{
@ -50,6 +52,7 @@ void SceneSwitcher::on_sceneRoundTripAdd_clicked()
s.scene2 = source2;
s.delay = int(delay * 1000);
s.transition = transition;
s.usePreviousScene = (scene2Name == QString(PREVIOUS_SCENE_NAME));
s.sceneRoundTripStr = text.toUtf8().constData();
break;
}
@ -181,6 +184,7 @@ void SceneSwitcher::on_sceneRoundTripLoad_clicked()
GetWeakSourceByQString(lines[1]),
GetWeakTransitionByQString(lines[4]),
lines[2].toInt(),
(lines[1].toUtf8().constData() == QString(PREVIOUS_SCENE_NAME)),
lines[3].toStdString()));
}
lines.clear();
@ -225,7 +229,7 @@ void SwitcherData::checkSceneRoundTrip(bool& match, OBSWeakSource& scene, OBSWea
if (currentSource == currentSource2)
{
match = true;
scene = s.scene2;
scene = (s.usePreviousScene) ? previousScene : s.scene2;
transition = s.transition;
}
obs_source_release(currentSource2);

View File

@ -14,6 +14,8 @@
#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
@ -94,14 +96,16 @@ struct SceneRoundTripSwitch
OBSWeakSource scene2;
OBSWeakSource transition;
int delay;
bool usePreviousScene;
string sceneRoundTripStr;
inline SceneRoundTripSwitch(OBSWeakSource scene1_, OBSWeakSource scene2_,
OBSWeakSource transition_, int delay_, string str)
OBSWeakSource transition_, int delay_, bool usePreviousScene_, string str)
: scene1(scene1_)
, scene2(scene2_)
, transition(transition_)
, delay(delay_)
, usePreviousScene(usePreviousScene_)
, sceneRoundTripStr(str)
{
}
@ -215,14 +219,13 @@ struct SwitcherData
condition_variable transitionCv;
bool startAtLaunch = false;
bool stop = false;
obs_source_t* waitScene = NULL; //scene during which wait started
int interval = DEFAULT_INTERVAL;
OBSWeakSource nonMatchingScene;
obs_source_t* waitScene = NULL; //scene during which wait started
OBSWeakSource previousScene = NULL;
OBSWeakSource lastRandomScene;
OBSWeakSource nonMatchingScene;
NoMatch switchIfNotMatching = NO_SWITCH;
vector<WindowSceneSwitch> windowSwitches;
@ -266,6 +269,7 @@ struct SwitcherData
void Start();
void Stop();
void setPreviousScene();
bool sceneChangedDuringWait();
bool prioFuncsValid();
void writeSceneInfoToFile();
@ -320,7 +324,7 @@ struct SwitcherData
for (size_t i = 0; i < sceneRoundTripSwitches.size(); i++)
{
SceneRoundTripSwitch& s = sceneRoundTripSwitches[i];
if (!WeakSourceValid(s.scene1) || !WeakSourceValid(s.scene2)
if (!WeakSourceValid(s.scene1) || (!s.usePreviousScene && !WeakSourceValid(s.scene2))
|| !WeakSourceValid(s.transition))
sceneRoundTripSwitches.erase(sceneRoundTripSwitches.begin() + i--);
}