How I control QLC+ with a Stream Deck using websockets and Python

Поділитися
Вставка
  • Опубліковано 29 лют 2024
  • Controlling QLC+ with a Stream Deck using websockets and Python involves creating an interactive lighting control setup that bridges sophisticated software control with a user-friendly hardware interface. This setup allows for real-time manipulation of lighting scenes and effects directly from a Stream Deck, a customizable control surface commonly used for live streaming and video production. Here's a concise overview of the process:
    QLC+ Configuration: Begin by setting up your lighting scenes, fixtures, and cues within QLC+, a versatile lighting control software. Ensure that QLC+ is configured to accept websocket connections, which will allow external commands to trigger actions within the software.
    Websockets Server in Python: Develop a Python script that functions as a bridge between the Stream Deck and QLC+. This script uses websockets to communicate with QLC+, sending commands based on button presses detected from the Stream Deck. Python's websockets library can be used to establish this connection, listening for commands from the Stream Deck and forwarding them to QLC+.
    Stream Deck Configuration: Configure your Stream Deck with buttons representing various lighting scenes or commands you wish to execute in QLC+. Each button can be assigned a specific command that correlates with an action or scene in QLC+.
    Python Script for Stream Deck Integration: Utilize Python to detect button presses on the Stream Deck. This can be achieved through libraries that interface with the Stream Deck SDK, allowing your script to know when a button is pressed and which command to send over websockets.
    Command Mapping and Execution: Map each Stream Deck button to a specific command within your Python script. When a button is pressed, the script translates this into a websocket message, which is sent to QLC+, triggering the corresponding action or scene change.
    Run and Test: With everything set up, run your Python script, and test the integration by pressing buttons on your Stream Deck. Each button press should result in an immediate response from QLC+, changing lighting scenes or triggering effects as configured.
    This method provides a tactile, quick-response interface for controlling lighting setups, making it ideal for live performances, events, or any application where direct and immediate control over lighting is desired. By leveraging websockets for communication, this setup ensures that commands are relayed in real-time, allowing for seamless interaction between the Stream Deck and QLC+.
    Heres the code
    import asyncio
    from StreamDeck.DeviceManager import DeviceManager
    from websocket import create_connection, WebSocketException
    Target WebSocket server URL (to send a message upon button press)
    TARGET_WS_URL = "ws://127.0.0.1:9999/qlcplusWS" # Change this to your Qlc+ URL
    ws = create_connection(TARGET_WS_URL)
    Function to send a message over WebSocket with error handling
    def send_message(TARGET_WS_URL,key):
    try:
    #ws = create_connection(TARGET_WS_URL)
    ws.send(f"{key}|255")
    print(f"{key}|255")
    except WebSocketException as e:
    print(f"WebSocket Handshake: {e}")
    except Exception as e:
    print(f"Unexpected error: {e}")
    Callback function for button presses with improved error handling
    def key_change_callback(deck, key, state):
    try:
    if state: # Button is pressed
    print(f"Button {key} pressed")
    Now also send a message to the target WebSocket server
    send_message(TARGET_WS_URL,key)#need to format the messahge to give the button number here
    else: # Button is released
    print(f"Button {key} released")
    except Exception as e:
    print(f"Error handling button {key} press/release: {e}")
    Main function remains the same
    def main():
    stream_decks = DeviceManager().enumerate()
    if not stream_decks:
    print("No Stream Deck found.")
    return
    deck = stream_decks[0]
    print("Found Stream Deck")
    deck.open()
    deck.reset()
    deck.set_key_callback(key_change_callback)
    print("Press buttons on your Stream Deck. Press Ctrl+C to quit.")
    try:
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_forever()
    except KeyboardInterrupt:
    print("Exiting...")
    finally:
    deck.close()
    ws.close()
    if _name_ == "__main__":
    main()
  • Навчання та стиль

КОМЕНТАРІ •