Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Script to forward OSC messages from Resolume to QLab using Python.
- This script listens for OSC messages indicating clip activations in Resolume
- and sends corresponding OSC messages to QLab to start cues.
- # Requirements:
- 1. Install Python (https://www.python.org/downloads/)
- 2. Install the `python-osc` library:
- Run: `pip install python-osc`
- # How to Run:
- 1. Save this script as `resolume_to_qlab.py`.
- 2. Run the script in Terminal: `python3 resolume_to_qlab.py`.
- 3. Ensure Resolume and QLab are configured to use the correct OSC ports.
- - Resolume: Configure outgoing OSC to `127.0.0.1` and port `7001`.
- - QLab: Ensure OSC input is enabled and listening on port `53000`.
- # Notes:
- - Cue names in QLab should match the format "LayerX_ClipY" (e.g., "Layer1_Clip1").
- - Only activation messages (state == 1.0) are processed.
- """
- from pythonosc import dispatcher, osc_server
- from pythonosc import udp_client
- # QLab OSC Client Setup
- # QLab's IP and port for receiving OSC messages
- # Default IP is localhost (127.0.0.1) and default port is 53000
- qlab_client = udp_client.SimpleUDPClient("127.0.0.1", 53000) # Change IP/port as needed
- # Function to handle messages from Resolume
- def handle_dynamic_connect(address, *args):
- """
- This function processes OSC messages from Resolume and forwards them to QLab.
- Args:
- - address (str): The OSC address of the message (e.g., "/composition/layers/1/clips/1/connect").
- - args (list): Arguments of the OSC message (e.g., [1.0] for activation).
- Functionality:
- 1. Extracts the layer and clip numbers from the OSC address.
- 2. Constructs a QLab cue name in the format "LayerX_ClipY".
- 3. If the message indicates activation (state == 1.0), sends an OSC message to QLab.
- """
- # Split the OSC address into parts (e.g., '/composition/layers/1/clips/1/connect')
- parts = address.split("/")
- # Extract layer and clip numbers from the OSC address
- layer = parts[3] # '1' from '/composition/layers/1/...'
- clip = parts[5] # '1' from '/composition/.../clips/1/...'
- # Generate QLab cue name based on layer and clip numbers
- cue_name = f"Layer{layer}_Clip{clip}"
- # Check the message arguments to determine the connection state
- if args:
- state = args[0] # The first argument represents the state
- if state == 1.0: # Only process activation messages
- print(f"Layer {layer}, Clip {clip}: Activated") # Log the activation
- # Construct the OSC message to start the corresponding QLab cue
- osc_message = f"/cue/{cue_name}/start"
- print(f"Sending OSC message to QLab: {osc_message}") # Log the OSC message
- qlab_client.send_message(osc_message, None) # Send the OSC message to QLab
- # Dispatcher to map OSC addresses to handler functions
- osc_dispatcher = dispatcher.Dispatcher()
- # Map Resolume's connect messages to the handler function
- # The wildcard (*) allows dynamic mapping for all layers and clips
- osc_dispatcher.map("/composition/layers/*/clips/*/connect", handle_dynamic_connect)
- # Start the OSC server to listen for messages from Resolume
- server = osc_server.ThreadingOSCUDPServer(("127.0.0.1", 7001), osc_dispatcher)
- print("Listening for OSC messages from Resolume on port 7001...")
- # Keep the server running indefinitely
- server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment