• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

    OBS: OSC Scene Switcher - My Version

    Hardware, Interfacing, and Third-Party Software
    1
    1
    1150
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mark
      mark last edited by mark

      Dear All,

      In preparing for today's guru session I wanted to make use of this python script hosted on GitHub to allow me to switch scenes in OBS using OSC. Kudos to Carlo Cattano for creating it.

      However, I discovered two issues:

      1) macOS does not support python scripts :-( The workaround is to run the script in a terminal window.

      2) The script itself does not seem to work as one might expect. The description indicates that the single numeric parameter sent after the /Scenes address should select the scene at that index, i.e., 0 selects the first scene, 1 selects the second, etc. But it doesn't seem to work that way. So I made some improvement and fixes to the script as given below. This code below should be replace the code in the ObSC.py file.

      ObSC.py.zip

      Best Wishes,
      Mark

      import sys,time,argparse,math
      from pythonosc import dispatcher
      from pythonosc import osc_server
      import logging
      logging.basicConfig(level=logging.INFO)
      sys.path.append('../')
      from obswebsocket import obsws, requests  # noqa: E402
      host = "localhost"
      port = 4444
      password = "put_your_password_here"
      ws = obsws(host, port, password)
      ws.connect()
      ScenesNames = []
      SceneSources = []
      def sourceSwitch(source_name,scene,switch):
          ws.call(requests.SetSceneItemProperties(source_name,scene,visible=switch)) 
      def is_integer(v):
          try:
              int(v)
              return True;
          except ValueError:
              return False;
      def scene_switch(unused_addr, args, oscValue):
      

      try:
              if (is_integer(oscValue)):
                  print("CMD = '{0}' INDEX = {1} OBS SCENE NAME = '{2}'".format(args[0], oscValue, ScenesNames[int(oscValue)]))
                  ws.call(requests.SetCurrentScene(ScenesNames[int(oscValue)]))
                  # control sources by using sourceSwitch("source_Name","Scene_name", bool)
                  # sourceSwitch("screen1","Scene1",False)
              else:
                  print("OSC Value '{0}' cannot be converted to an integer.".format(oscValue))
          except:
              pass
      if name == "main":
          try:
              scenes = ws.call(requests.GetSceneList())
              for s in scenes.getScenes():
                  name = s['name']
                  print("Adding Scene = '{0}".format(name))
                  ScenesNames.append(name)                        # Add every scene to a list of scenes
              print("CURRENT SCENES IN OBS:\n", ScenesNames)
             
              ### OSC SETTINGS
              parser = argparse.ArgumentParser()
              parser.add_argument("--ip", default="127.0.0.1", help="The ip to listen on")
              parser.add_argument("--port", type=int, default=5005, help="The port to listen on")
              args = parser.parse_args()                           # parser for --ip --port arguments
              dispatcher = dispatcher.Dispatcher()
              dispatcher.map("/Scene", scene_switch, "Scene")      # OSC LISTENER
              server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatcher)  
              print("Serving on {}".format(server.server_address))
              
              server.serve_forever()
          except KeyboardInterrupt:
              pass
          ws.disconnect()
        

      Media Artist & Creator of Isadora
      Macintosh SE-30, 32 Mb RAM, MacOS 7.6, Dual Floppy Drives

      1 Reply Last reply Reply Quote 3
      • First post
        Last post