further reduced chance of scene dupe

This commit is contained in:
WarmUpTill 2016-08-21 00:52:56 +02:00 committed by GitHub
parent 794a508e7b
commit b8f94cd1d3
2 changed files with 74 additions and 3 deletions

66
Testing.cpp Normal file
View File

@ -0,0 +1,66 @@
/*
* SceneSwitcher.cpp
* SceneSwitcher
*
* Created by Till Wickenheiser on 25.06.16.
* Copyright © 2016 WarmUpTill. All rights reserved.
*
*/
#include <iostream>
#include "SceneSwitcher.hpp"
#ifdef __APPLE__ //&& __MACH__
//do stuff for mac
#endif
#ifdef __WINDOWS__
//do stuff for windows
//this is so cool ! :D
string GetActiveWindowTitle()
{
char wnd_title[256];
//get handle of currently active window
HWND hwnd = GetForegroundWindow();
GetWindowTextA(hwnd, wnd_title, sizeof(wnd_title));
return wnd_title;
}
#endif
void HelloWorldPriv(const char * s)
{
std::string cmd = "osascript -e 'tell application \"System Events\"' -e 'set frontApp to name of first application process whose frontmost is true' -e 'end tell'";
system(cmd.c_str());
std::cout << s << std::endl;
};
//OSErr err;
//CGSValue titleValue;
//char *title;
//CGSConnection connection = _CGSDefaultConnection();
//int windowCount, *windows, i;
//
//NSCountWindows(&windowCount);
//windows = malloc(windowCount * sizeof(*windows));
//if (windows) {
// NSWindowList(windowCount, windows);
// for (i=0; i < windowCount; ++i) {
// err = CGSGetWindowProperty(connection, windows[i],
// CGSCreateCStringNoCopy("kCGSWindowTitle"),
// &titleValue);
// title = CGSCStringValue(titleValue);
// }
// free(windows);
//}
//
//Int getActiveWindowOSX(){
// NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
// NSApplication *myApp;
//
//
// myApp=[NSApplication sharedApplication];
//
// NSWindow *myWindow = [myApp keyWindow];
//
// [pool release];
// return NWSindow;
//};

View File

@ -31,6 +31,8 @@ void Switcher::switcherThreadFunc() {
obs_source_t * transitionUsed = obs_get_output_source(0);
obs_source_t * sceneUsed = obs_transition_get_active_source(transitionUsed);
const char *sceneUsedName = obs_source_get_name(sceneUsed);
obs_source_release(sceneUsed);
obs_source_release(transitionUsed);
//check if scene switching should be paused
if ((sceneUsedName) && find(pauseScenes.begin(), pauseScenes.end(), string(sceneUsedName)) != pauseScenes.end()) {
pauseSwitching = true;
@ -142,15 +144,20 @@ void Switcher::switcherThreadFunc() {
sceneName = sceneRoundTrip.first[roundTripPos];
}
//check if current scene is already the desired scene
transitionUsed = obs_get_output_source(0);
sceneUsed = obs_transition_get_active_source(transitionUsed);
const char *sceneUsedName = obs_source_get_name(sceneUsed);
obs_source_release(sceneUsed);
if ((sceneUsedName) && strcmp(sceneUsedName, sceneName.c_str()) != 0) {
//switch scene
obs_source_t *source = obs_get_source_by_name(sceneName.c_str());
obs_source_t *source = obs_get_source_by_name(sceneName.c_str()); //<--- do some more testing here regarding scene duplication
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(transitionUsed);
}
///////////////////////////////////////////////
//Scene Round Trip
@ -175,8 +182,6 @@ void Switcher::switcherThreadFunc() {
}
}
}
obs_source_release(sceneUsed);
obs_source_release(transitionUsed);
//sleep for a bit
this_thread::sleep_for(chrono::milliseconds(sleepTime));
sleepTime = 1000;