def run(self, event: obs.ObsEvent) -> None: if isinstance(event, ObsConnected): scene = self.obsws.call(requests.GetCurrentScene()) try: sources = scene.getSources() except KeyError: sources = [] for s in sources: if s['name'] in self.mutable_scene_items: self.mutable_items_visible[s['name']] = s['render'] # Any item not in the current scene, we'll consider not visible. for i in self.mutable_scene_items: self.mutable_items_visible.setdefault(i, False) mute_status = self.obsws.call(requests.GetMute(self.mic_source)) self.muted = mute_status.getMuted() logger.info( f'Starting: {self.muted}, {self.mutable_items_visible}') return if isinstance(event, obs.ObsDisconnected): self.cancel_timer() return event = cast(ObsMessage, event) msg = event.obs_message if isinstance(msg, events.SourceMuteStateChanged): self.muted = msg.getMuted() if self.accidentally_muted(): self.start_timer() else: self.cancel_timer() self.has_announced = False elif isinstance(msg, events.SceneItemVisibilityChanged): self.mutable_items_visible[ msg.getItemName()] = msg.getItemVisible() if self.accidentally_muted(): self.start_timer() else: self.cancel_timer() elif isinstance(msg, events.StreamStopping): self.cancel_timer()
def ToggleMuteSource(Action, ws, midi_out): if "SourceName" in Action: try: MuteState = ws.call(requests.GetMute(Action["SourceName"])) MuteState = MuteState.getMuted() except: print("Couldn't get mute state") else: try: ws.call(requests.SetMute(Action["SourceName"], not MuteState)) except: print("Couldn't toggle mute state of " + Action["SourceName"]) else: if MuteState == True: MidiLed(Action, "off", midi_out) else: MidiLed(Action, "on", midi_out) PrintWithTime("Toggled the mute state of " + Action["SourceName"]) else: print("No SourceName argument in action config")
def mute(bh, msg, mute=True): ws.connect() # Request everything be muted for mic in MICROPHONES: ws.call(requests.SetMute(mic, mute=mute)) # Go through again, verify that all the muting worked mute_status = [] for mic in MICROPHONES: ret = ws.call(requests.GetMute(mic)) print(ret) mute_status.append(ret.getMuted()) ws.disconnect() # React based on if everything was muted or not. React based on current # status (currently muted or not), not based on if it was successful or # not. if all(mute_status): bh.react(msg, 'mute_notifications') elif not any(mute_status): bh.react(msg, 'notifications') else: return "Mute statuses: %s" % ' '.join(str(x) for x in mute_status)
def GetSourceMute(self, SourceName): try: return self.ws.call( requests.GetMute(SourceName)).__dict__["datain"]["muted"] except Exception as e: print(e)