removed additional delay from SceneRoundTrip, no more duplicate scenes(hopefully)

This commit is contained in:
WarmUpTill 2016-08-19 03:07:27 +02:00 committed by GitHub
parent 23208fe8f7
commit 1dfce58b54
4 changed files with 85 additions and 69 deletions

View File

@ -21,7 +21,8 @@ void Settings::setSettingsFilePath(string path)
void Settings::load() {
//reset the settings
settings = map<string, Data>();
sceneRoundTrip = vector<string>();
sceneRoundTrip = pair<vector<string>, vector<string>>();
vector<string> sceneRoundTripTemp;
pauseScenes = vector<string>();
ignoreNames = vector<string>();
//read the settings file
@ -60,15 +61,15 @@ void Settings::load() {
while (lineStream.good()) {
//Scene Round Trip,TriggerSceneHere,DelayHere,NextSceneHere,DelayHere,AnotherSceneHere,DelayHere,...
getline(lineStream, value, ',');
sceneRoundTrip.push_back(value);
sceneRoundTripTemp.push_back(value);
}
//remove trailing /" of last value
if (sceneRoundTrip.size() > 0) {
sceneRoundTrip.back().pop_back();
if (sceneRoundTripTemp.size() > 0) {
sceneRoundTripTemp.back().pop_back();
}
//add missing values
if (sceneRoundTrip.size() == 0 || sceneRoundTrip.size() % 2 != 0) {
sceneRoundTrip.push_back("");
if (sceneRoundTripTemp.size() == 0 || sceneRoundTripTemp.size() % 2 != 0) {
sceneRoundTripTemp.push_back("");
}
}
//find Pause Scene Names
@ -76,7 +77,7 @@ void Settings::load() {
//discard the first value ("Pause Scene Names")
getline(lineStream, value, ',');
while (lineStream.good()) {
//Scene Round Trip,TriggerSceneHere,DelayHere,NextSceneHere,DelayHere,AnotherSceneHere,DelayHere,...
//Pause Scene Names,Scene Name,Scene Name,Scene Name,...
getline(lineStream, value, ',');
pauseScenes.push_back(value);
}
@ -121,7 +122,6 @@ void Settings::load() {
for (; numValues > 3; numValues--) {
settingsElements.pop_back();
}
//assing to data
Data d = Data();
string isFullscreen = settingsElements.back();
@ -137,6 +137,11 @@ void Settings::load() {
}
}
infile.close();
//create sceneRoundTrip from sceneRoundTripTemp
for (int i = 0; i < sceneRoundTripTemp.size(); i += 2) {
sceneRoundTrip.first.push_back(sceneRoundTripTemp[i]);
sceneRoundTrip.second.push_back(sceneRoundTripTemp[i + 1]);
}
}
bool Settings::getStartMessageDisable() {
@ -147,7 +152,7 @@ map<string, Data> Settings::getMap() {
return settings;
}
vector<string> Settings::getSceneRoundTrip() {
pair<vector<string>, vector<string>> Settings::getSceneRoundTrip() {
return sceneRoundTrip;
}

View File

@ -15,7 +15,7 @@ public:
void load();
bool getStartMessageDisable();
map<string, Data> getMap();
vector<string> getSceneRoundTrip();
pair<vector<string>, vector<string>> getSceneRoundTrip();
vector<string> getPauseScenes();
vector<string> getIgnoreNames();
string getSettingsFilePath();
@ -23,7 +23,7 @@ public:
private:
string settingsFilePath = "";
map<string, Data> settings;
vector<string> sceneRoundTrip;
pair<vector<string>, vector<string>> sceneRoundTrip;
vector<string> pauseScenes;
vector<string> ignoreNames;
bool startMessageDisable = false;

View File

@ -25,6 +25,7 @@ void Switcher::switcherThreadFunc() {
string sceneName = "";
bool checkFullscreen = false;
bool pauseSwitching = false;
size_t sleepTime = 1000;
while (isRunning) {
//get Scene Name
obs_source_t * transitionUsed = obs_get_output_source(0);
@ -33,49 +34,28 @@ void Switcher::switcherThreadFunc() {
//check if scene switching should be paused
if ((sceneUsedName) && find(pauseScenes.begin(), pauseScenes.end(), string(sceneUsedName)) != pauseScenes.end()) {
pauseSwitching = true;
//cancel Scene Round trip
sceneRoundTripActive = false;
roundTripPos = 0;
}
else {
pauseSwitching = false;
}
if (sceneRoundTripActive) {
//did the user switch to another scene during scene round trip ?
if ((sceneUsedName) && find(sceneRoundTrip.first.begin(), sceneRoundTrip.first.end(), string(sceneUsedName)) == sceneRoundTrip.first.end()) {
sceneRoundTripActive = false;
roundTripPos = 0;
}
}
//check if a Scene Round Trip should be started
else if ((sceneUsedName) && sceneRoundTrip.first.size() > 0 && strcmp(sceneUsedName, sceneRoundTrip.first.front().c_str()) == 0) {
sceneRoundTripActive = true;
roundTripPos = 0;
}
//are we in pause mode?
if (!pauseSwitching) {
//check if a Scene Round Trip should be started
if ((sceneUsedName) && sceneRoundTrip.size() > 0 && strcmp(sceneUsedName, sceneRoundTrip.front().c_str()) == 0) {
sceneRoundTripActive = true;
roundTripPos = 1;
}
if (sceneRoundTripActive) {
//get delay and wait
try {
this_thread::sleep_for(chrono::milliseconds(1000 * stoi(sceneRoundTrip.at(roundTripPos), nullptr, 10)));
}
catch (...) {
//just wait for 3 seconds if value was not set properly
this_thread::sleep_for(chrono::milliseconds(3000));
}
//are we done with the Scene Round trip?
if (roundTripPos + 1 >= sceneRoundTrip.size()) {
sceneRoundTripActive = false;
roundTripPos = 0;
}
else {
//switch scene
sceneName = sceneRoundTrip.at(roundTripPos + 1);
obs_source_t *source = obs_get_source_by_name(sceneName.c_str());
if (source != NULL) {
//create transition to new scene
obs_transition_start(transitionUsed, OBS_TRANSITION_MODE_AUTO, 300, source); //OBS_TRANSITION_MODE_AUTO uses the obs user settings for transitions
}
obs_source_release(source);
//prepare for next sceneName,Delay pair
roundTripPos += 2;
}
}
//normal scene switching here
else {
///////////////////////////////////////////////
//finding the scene to switch to
///////////////////////////////////////////////
if (!sceneRoundTripActive) {
//get active window title
windowname = GetActiveWindowTitle();
//should we ignore this window name?
@ -106,7 +86,9 @@ void Switcher::switcherThreadFunc() {
catch (...) {}
}
}
//check cursor regions
///////////////////////////////////////////////
//cursor regions check
///////////////////////////////////////////////
if (!match)
{
pair<int, int> cursorPos = getCursorXY();
@ -143,32 +125,61 @@ void Switcher::switcherThreadFunc() {
catch (...) {}
}
}
//do we only switch if window is also fullscreen?
match = match && (!checkFullscreen || (checkFullscreen && isWindowFullscreen()));
//match or backup scene set
if (settingsMap.find("Backup Scene Name") != settingsMap.end() || match) {
//no match -> backup scene
if (!match) {
sceneName = settingsMap.find("Backup Scene Name")->second.sceneName;
}
//check if current scene is already the desired scene
if ((sceneUsedName) && strcmp(sceneUsedName, sceneName.c_str()) != 0) {
//switch scene
obs_source_t *source = obs_get_source_by_name(sceneName.c_str());
if (source != NULL) {
//create transition to new scene (otherwise UI wont work anymore)
obs_transition_start(transitionUsed, OBS_TRANSITION_MODE_AUTO, 300, source); //OBS_TRANSITION_MODE_AUTO uses the obs user settings for transitions
}
obs_source_release(source);
}
}
}
///////////////////////////////////////////////
//switch the scene
///////////////////////////////////////////////
//do we only switch if window is also fullscreen? || are we in sceneRoundTripActive?
match = (match && (!checkFullscreen || (checkFullscreen && isWindowFullscreen()))) || sceneRoundTripActive;
//match or backup scene set
if (settingsMap.find("Backup Scene Name") != settingsMap.end() || match) {
//no match -> backup scene
if (!match) {
sceneName = settingsMap.find("Backup Scene Name")->second.sceneName;
}
if (sceneRoundTripActive) {
sceneName = sceneRoundTrip.first[roundTripPos];
}
//check if current scene is already the desired scene
if ((sceneUsedName) && strcmp(sceneUsedName, sceneName.c_str()) != 0) {
//switch scene
obs_source_t *source = obs_get_source_by_name(sceneName.c_str());
if (source != NULL) {
//create transition to new scene (otherwise UI wont work anymore)
obs_transition_start(transitionUsed, OBS_TRANSITION_MODE_AUTO, 300, source); //OBS_TRANSITION_MODE_AUTO uses the obs user settings for transitions
}
obs_source_release(source);
}
}
///////////////////////////////////////////////
//Scene Round Trip
///////////////////////////////////////////////
if (sceneRoundTripActive) {
//get delay and wait
try {
sleepTime = stoi(sceneRoundTrip.second[roundTripPos]) * 1000;
}
catch (...) {
//just wait for 3 seconds if value was not set properly
sleepTime = 3000;
}
//are we done with the Scene Round trip?
if (roundTripPos + 1 == sceneRoundTrip.first.size()) {
sceneRoundTripActive = false;
roundTripPos = 0;
}
else {
//prepare for next sceneName,Delay pair
roundTripPos++;
}
}
}
obs_source_release(sceneUsed);
obs_source_release(transitionUsed);
//sleep for a bit
this_thread::sleep_for(chrono::milliseconds(1000));
this_thread::sleep_for(chrono::milliseconds(sleepTime));
sleepTime = 1000;
}
}

View File

@ -22,7 +22,7 @@ private:
bool isRunning = true;
Settings settings;
map<string, Data> settingsMap;
vector<string> sceneRoundTrip;
pair<vector<string>, vector<string>> sceneRoundTrip;
vector<string> pauseScenes;
vector<string> ignoreNames;
void switcherThreadFunc();