diff --git a/settings.cpp b/settings.cpp index 99f4282a..7edac7f7 100644 --- a/settings.cpp +++ b/settings.cpp @@ -23,6 +23,7 @@ void Settings::load() { settings = map(); sceneRoundTrip = vector(); pauseScenes = vector(); + ignoreNames = vector(); //read the settings file vector settingsElements; ifstream infile(settingsFilePath); @@ -65,10 +66,12 @@ void Settings::load() { if (sceneRoundTrip.size() > 0) { sceneRoundTrip.back().pop_back(); } + //add missing values if (sceneRoundTrip.size() == 0 || sceneRoundTrip.size() % 2 != 0) { sceneRoundTrip.push_back(""); } } + //find Pause Scene Names if (temp.find("Pause Scene Names") != temp.npos) { //discard the first value ("Pause Scene Names") getline(lineStream, value, ','); @@ -82,8 +85,22 @@ void Settings::load() { pauseScenes.back().pop_back(); } } + //find window names to ignroe + if (temp.find("Ignore Window Names") != temp.npos) { + //discard the first value "Ignore Window Names" + getline(lineStream, value, ','); + while (lineStream.good()) { + //Ignore Window Names,windowName1,windowName2,... + getline(lineStream, value, ','); + ignoreNames.push_back(value); + } + //remove trailing /" of last value + if (ignoreNames.size() > 0) { + ignoreNames.back().pop_back(); + } + } //find values for Scene switching - if (temp.find("Pause Scene Names") == temp.npos && temp.find("Scene Round Trip") == temp.npos) + if (temp.find("Pause Scene Names") == temp.npos && temp.find("Scene Round Trip") == temp.npos && temp.find("Ignore Window Names") == temp.npos) { //windowTitle,sceneName,isFullscreenValue while (lineStream.good()) { @@ -138,3 +155,8 @@ vector Settings::getPauseScenes() { return pauseScenes; } +vector Settings::getIgnoreNames() +{ + return ignoreNames; +} + diff --git a/settings.h b/settings.h index 0ffd8dfe..90ed1914 100644 --- a/settings.h +++ b/settings.h @@ -17,12 +17,14 @@ public: map getMap(); vector getSceneRoundTrip(); vector getPauseScenes(); + vector getIgnoreNames(); string getSettingsFilePath(); void setSettingsFilePath(string path); private: string settingsFilePath = ""; map settings; vector sceneRoundTrip; - vectorpauseScenes; + vector pauseScenes; + vector ignoreNames; bool startMessageDisable = false; }; diff --git a/switcher.cpp b/switcher.cpp index 09a8ddce..2e84f112 100644 --- a/switcher.cpp +++ b/switcher.cpp @@ -78,51 +78,55 @@ void Switcher::switcherThreadFunc() { else { //get active window title and reset values windowname = GetActiveWindowTitle(); - match = false; - sceneName = ""; - checkFullscreen = false; - //first check if there is a direct match - map::iterator it = settingsMap.find(windowname); - if (it != settingsMap.end()) { - sceneName = it->second.sceneName; - checkFullscreen = it->second.isFullscreen; - match = true; - } - else { - //maybe there is a regular expression match - for (map::iterator iter = settingsMap.begin(); iter != settingsMap.end(); ++iter) - { - try { - regex e = regex(iter->first); - match = regex_match(windowname, e); - if (match) { - sceneName = iter->second.sceneName; - checkFullscreen = iter->second.isFullscreen; - break; - } - } - catch (...) {} + //should we ignore this window name? + if (find(ignoreNames.begin(), ignoreNames.end(), windowname) == ignoreNames.end()) { + //reset values + match = false; + sceneName = ""; + checkFullscreen = false; + //first check if there is a direct match + map::iterator it = settingsMap.find(windowname); + if (it != settingsMap.end()) { + sceneName = it->second.sceneName; + checkFullscreen = it->second.isFullscreen; + match = true; } - } - //do we only switch if window is also fullscreen? - if (!checkFullscreen || (checkFullscreen && isWindowFullscreen())) { - //do we know the window title or is a fullscreen/backup Scene set? - if (!(settingsMap.find("Backup Scene Name") == settingsMap.end()) || match) { - if (!match && !(settingsMap.find("Backup Scene Name") == settingsMap.end())) { - 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 + else { + //maybe there is a regular expression match + for (map::iterator iter = settingsMap.begin(); iter != settingsMap.end(); ++iter) + { + try { + regex e = regex(iter->first); + match = regex_match(windowname, e); + if (match) { + sceneName = iter->second.sceneName; + checkFullscreen = iter->second.isFullscreen; + break; + } } - obs_source_release(source); + catch (...) {} + } + } + //do we only switch if window is also fullscreen? + if (!checkFullscreen || (checkFullscreen && isWindowFullscreen())) { + //do we know the window title or is a fullscreen/backup Scene set? + if (!(settingsMap.find("Backup Scene Name") == settingsMap.end()) || match) { + if (!match && !(settingsMap.find("Backup Scene Name") == settingsMap.end())) { + 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); + } + obs_source_release(sceneUsed); + obs_source_release(transitionUsed); } - obs_source_release(sceneUsed); - obs_source_release(transitionUsed); } } } @@ -138,6 +142,7 @@ void Switcher::firstLoad() { settingsMap = settings.getMap(); sceneRoundTrip = settings.getSceneRoundTrip(); pauseScenes = settings.getPauseScenes(); + ignoreNames = settings.getIgnoreNames(); if (!settings.getStartMessageDisable()) { string message = "The following settings were found for Scene Switcher:\n"; for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); ++it) @@ -156,6 +161,7 @@ void Switcher::firstLoad() { settingsMap = settings.getMap(); sceneRoundTrip = settings.getSceneRoundTrip(); pauseScenes = settings.getPauseScenes(); + ignoreNames = settings.getIgnoreNames(); if (!settings.getStartMessageDisable()) { string message = "The following settings were found for Scene Switcher:\n"; for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); ++it) @@ -191,6 +197,7 @@ void Switcher::load() { settingsMap = settings.getMap(); sceneRoundTrip = settings.getSceneRoundTrip(); pauseScenes = settings.getPauseScenes(); + ignoreNames = settings.getIgnoreNames(); } //start thread diff --git a/switcher.h b/switcher.h index 8004b94f..1470b1a4 100644 --- a/switcher.h +++ b/switcher.h @@ -23,6 +23,7 @@ private: map settingsMap; vector sceneRoundTrip; vector pauseScenes; + vector ignoreNames; void switcherThreadFunc(); bool isWindowFullscreen(); string GetActiveWindowTitle();