Guest User

Resolume to Qlab

a guest
Nov 18th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.34 KB | Software | 0 0
  1. """
  2. Script to forward OSC messages from Resolume to QLab using Python.
  3. This script listens for OSC messages indicating clip activations in Resolume
  4. and sends corresponding OSC messages to QLab to start cues.
  5.  
  6. # Requirements:
  7. 1. Install Python (https://www.python.org/downloads/)
  8. 2. Install the `python-osc` library:
  9.   Run: `pip install python-osc`
  10.  
  11. # How to Run:
  12. 1. Save this script as `resolume_to_qlab.py`.
  13. 2. Run the script in Terminal: `python3 resolume_to_qlab.py`.
  14. 3. Ensure Resolume and QLab are configured to use the correct OSC ports.
  15.   - Resolume: Configure outgoing OSC to `127.0.0.1` and port `7001`.
  16.   - QLab: Ensure OSC input is enabled and listening on port `53000`.
  17.  
  18. # Notes:
  19. - Cue names in QLab should match the format "LayerX_ClipY" (e.g., "Layer1_Clip1").
  20. - Only activation messages (state == 1.0) are processed.
  21. """
  22.  
  23. from pythonosc import dispatcher, osc_server
  24. from pythonosc import udp_client
  25.  
  26. # QLab OSC Client Setup
  27. # QLab's IP and port for receiving OSC messages
  28. # Default IP is localhost (127.0.0.1) and default port is 53000
  29.  
  30. qlab_client = udp_client.SimpleUDPClient("127.0.0.1", 53000)  # Change IP/port as needed
  31.  
  32. # Function to handle messages from Resolume
  33. def handle_dynamic_connect(address, *args):
  34.     """
  35.    This function processes OSC messages from Resolume and forwards them to QLab.
  36.    
  37.    Args:
  38.    - address (str): The OSC address of the message (e.g., "/composition/layers/1/clips/1/connect").
  39.    - args (list): Arguments of the OSC message (e.g., [1.0] for activation).
  40.  
  41.    Functionality:
  42.    1. Extracts the layer and clip numbers from the OSC address.
  43.    2. Constructs a QLab cue name in the format "LayerX_ClipY".
  44.    3. If the message indicates activation (state == 1.0), sends an OSC message to QLab.
  45.    """
  46.     # Split the OSC address into parts (e.g., '/composition/layers/1/clips/1/connect')
  47.     parts = address.split("/")
  48.    
  49.     # Extract layer and clip numbers from the OSC address
  50.     layer = parts[3]  # '1' from '/composition/layers/1/...'
  51.     clip = parts[5]   # '1' from '/composition/.../clips/1/...'
  52.  
  53.     # Generate QLab cue name based on layer and clip numbers
  54.     cue_name = f"Layer{layer}_Clip{clip}"
  55.  
  56.     # Check the message arguments to determine the connection state
  57.     if args:
  58.         state = args[0]  # The first argument represents the state
  59.         if state == 1.0:  # Only process activation messages
  60.             print(f"Layer {layer}, Clip {clip}: Activated")  # Log the activation
  61.             # Construct the OSC message to start the corresponding QLab cue
  62.             osc_message = f"/cue/{cue_name}/start"
  63.             print(f"Sending OSC message to QLab: {osc_message}")  # Log the OSC message
  64.             qlab_client.send_message(osc_message, None)  # Send the OSC message to QLab
  65.  
  66. # Dispatcher to map OSC addresses to handler functions
  67. osc_dispatcher = dispatcher.Dispatcher()
  68.  
  69. # Map Resolume's connect messages to the handler function
  70. # The wildcard (*) allows dynamic mapping for all layers and clips
  71. osc_dispatcher.map("/composition/layers/*/clips/*/connect", handle_dynamic_connect)
  72.  
  73. # Start the OSC server to listen for messages from Resolume
  74. server = osc_server.ThreadingOSCUDPServer(("127.0.0.1", 7001), osc_dispatcher)
  75. print("Listening for OSC messages from Resolume on port 7001...")
  76.  
  77. # Keep the server running indefinitely
  78. server.serve_forever()
  79.  
Advertisement
Add Comment
Please, Sign In to add comment