From 1dfce58b54526205c0a69b59e8d9b094f408d18d Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Fri, 19 Aug 2016 03:07:27 +0200 Subject: [PATCH] removed additional delay from SceneRoundTrip, no more duplicate scenes(hopefully) --- settings.cpp | 23 ++++++---- settings.h | 4 +- switcher.cpp | 125 ++++++++++++++++++++++++++++----------------------- switcher.h | 2 +- 4 files changed, 85 insertions(+), 69 deletions(-) diff --git a/settings.cpp b/settings.cpp index 7edac7f7..7559126b 100644 --- a/settings.cpp +++ b/settings.cpp @@ -21,7 +21,8 @@ void Settings::setSettingsFilePath(string path) void Settings::load() { //reset the settings settings = map(); - sceneRoundTrip = vector(); + sceneRoundTrip = pair, vector>(); + vector sceneRoundTripTemp; pauseScenes = vector(); ignoreNames = vector(); //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 Settings::getMap() { return settings; } -vector Settings::getSceneRoundTrip() { +pair, vector> Settings::getSceneRoundTrip() { return sceneRoundTrip; } diff --git a/settings.h b/settings.h index 90ed1914..5d277b3b 100644 --- a/settings.h +++ b/settings.h @@ -15,7 +15,7 @@ public: void load(); bool getStartMessageDisable(); map getMap(); - vector getSceneRoundTrip(); + pair, vector> getSceneRoundTrip(); vector getPauseScenes(); vector getIgnoreNames(); string getSettingsFilePath(); @@ -23,7 +23,7 @@ public: private: string settingsFilePath = ""; map settings; - vector sceneRoundTrip; + pair, vector> sceneRoundTrip; vector pauseScenes; vector ignoreNames; bool startMessageDisable = false; diff --git a/switcher.cpp b/switcher.cpp index bcac2813..20612bfa 100644 --- a/switcher.cpp +++ b/switcher.cpp @@ -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 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; } } diff --git a/switcher.h b/switcher.h index 8cd4223a..1a1741b8 100644 --- a/switcher.h +++ b/switcher.h @@ -22,7 +22,7 @@ private: bool isRunning = true; Settings settings; map settingsMap; - vector sceneRoundTrip; + pair, vector> sceneRoundTrip; vector pauseScenes; vector ignoreNames; void switcherThreadFunc();