def SwitchScene(Action, ws): #Here we check whether StudioMode is on StudioState = CheckStudioState(ws) if StudioState == True: #Here we set the preview scene try: ws.call(requests.SetPreviewScene(Action["DestinationScene"])) except: print("Couldn't set " + Action["DestinationScene"] + " to program") else: PrintWithTime("Set " + Action["DestinationScene"] + " to program") else: #Here we set the configured transition mode if "Transition" in Action: Transition_old = GetTransition(ws) SetTransition(Action, ws) #Here we set the scene being viewed try: ws.call(requests.SetCurrentScene(Action["DestinationScene"])) except: print("Couldn't set " + Action["DestinationScene"] + " to program") else: PrintWithTime("Set " + Action["DestinationScene"] + " to program") #Here we set the transition mode back if "Transition" in Action: try: Duration = ws.call(requests.GetTransitionDuration()) Duration = Duration.getTransitionDuration() except: print("Couldn't get transition duration") else: time.sleep(Duration / 1000 + 0.1) finally: SetTransition(Transition_old, ws)
def switch_to(self, scene: str): res = self.ws.call(obsws_requests.GetStudioModeStatus()) if not res.getStudioMode(): self.ws.call(obsws_requests.EnableStudioMode()) self.ws.call(obsws_requests.SetPreviewScene(scene)) self.ws.call(obsws_requests.TransitionToProgram('Stinger')) self.ws.call(obsws_requests.DisableStudioMode())
def press_button(Button): if Button == 8: try: print("Connecting to Camera1") ws.call(requests.SetPreviewScene("Camera1")) except: print("Exception happened") elif Button == 9: try: print("Connecting to Camera2") ws.call(requests.SetPreviewScene("Camera2")) except: print("Exception happened") elif Button == 15: try: print("Send to stream") CurrentsceneObject = ws.call(requests.GetPreviewScene()) # print(CurrentsceneObject) Currentscene = CurrentsceneObject.getName() # print(Currentscene) ws.call(requests.SetCurrentTransition("Fade")) ws.call(requests.SetCurrentScene(Currentscene)) except: print("Exception happened")
def change_scene(self, amount): """ Jump to the next / previous scene. The web socket will only give us the current scene name and an orderd list of scenes; we therefore need to work out the index of the current scene and then the name of the desired scene to jump to. """ if self.connection.call( requests.GetStudioModeStatus()).getStudioMode() == False: print('Studio mode must be on for scene switching') return scenes = self.connection.call(requests.GetSceneList()).getScenes() current_scene = self.connection.call( requests.GetPreviewScene()).getName() current_scene_index = [ i for i, s in enumerate(scenes) if s['name'] == current_scene ][0] new_scene_index = (current_scene_index + amount) % len(scenes) new_scene = scenes[new_scene_index]['name'] self.connection.call(requests.SetPreviewScene(new_scene))
def SwitchScene(BUTTONCONF): #Here we check whether StudioMode is on StudioState = CheckStudioState() if StudioState == True: #Here we set the preview scene try: ws.call(requests.SetPreviewScene(BUTTONCONF["DestinationScene"])) print("Set Target to preview") except: print("Couldn't set Target to preview") #These lines are here to change the transition mode when pressing scene button. They produce lag and are commented out # if "Transition" in BUTTONCONF: # if "TransitionDuration" in BUTTONCONF: # SetTransitionMode(BUTTONCONF["Transition"], BUTTONCONF["TransitionDuration"]) # else: # SetTransitionMode(BUTTONCONF["Transition"], None) # # if "Transition" not in BUTTONCONF: # SetTransitionMode(DefaultTransition, DefaultTransitionDuration) else: #Here we set the transition specified in config if "Transition" in BUTTONCONF: if "TransitionDuration" in BUTTONCONF: SetTransitionMode(BUTTONCONF["Transition"], BUTTONCONF["TransitionDuration"]) else: SetTransitionMode(BUTTONCONF["Transition"], None) #Here we set the scene being viewed try: ws.call(requests.SetCurrentScene(BUTTONCONF["DestinationScene"])) print("Set " + BUTTONCONF["DestinationScene"] + " to program") except: print("Couldn't set " + BUTTONCONF["DestinationScene"] + " to program") #Here we set back the transition to the defaults if "Transition" in BUTTONCONF: time.sleep(BUTTONCONF["TransitionDuration"] / 1000 + 0.1) SetTransitionMode(DefaultTransition, DefaultTransitionDuration)
def SetPreviewScene(self, SceneName): try: self.ws.call(requests.SetPreviewScene(SceneName)) except Exception as e: print(e)
for s in scenes.getScenes(): if not ":" in s['name']: continue i = s['name'].split(":")[0] if not i.isnumeric(): continue i = int(i) if i>=10: p = i//10 i = i%10 if not p in pages: pages[p] = {} if p>max_pages: max_pages=p pages[p]["KEY_NUMERIC_%d" % (i)] = requests.SetPreviewScene(s['name']) else: keys["KEY_NUMERIC_%d" % (i)] = requests.SetPreviewScene(s['name']) if not keys: print("No prefixes in scenes, fallback to scenes order.") next_key = 0 for s in scenes.getScenes(): p = next_key//10 i = next_key%10 if not p in pages: pages[p] = {} if p>max_pages: max_pages=p pages[p]["KEY_NUMERIC_%d" % (i)] = requests.SetPreviewScene(s['name']) next_key += 1
def set_preview_scene(self, name): res = self._call(requests.SetPreviewScene(name)) return res.status
def StudioMode_SetPreview(self, SceneName="", *args, **kwargs): try: self.ws.call(requests.SetPreviewScene(SceneName)) PrintWithTime(f"Set preview to {SceneName}") except Exception as e: PrintWithTime(f"Couldn't set preview to {SceneName}. Error : {e}")