393 lines
12 KiB
Python
393 lines
12 KiB
Python
#!/usr/bin/env python3
|
||
"""Build shows/midi.qxw — M-VAVE SMC-PAD controlling 20× BCC145 (Dim + RGBW)."""
|
||
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
import shutil
|
||
import subprocess
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parents[2]
|
||
OUT = ROOT / "shows" / "midi.qxw"
|
||
PROFILE_SRC = ROOT / "inputprofiles" / "M-VAVE-SMC-PAD.qxi"
|
||
PROFILE_DST = Path.home() / ".qlcplus" / "inputprofiles" / "M-VAVE-SMC-PAD.qxi"
|
||
|
||
PROFILE_NAME = "M-VAVE SMC-PAD"
|
||
MIDI_UNIVERSE_ID = 1 # Universe 2
|
||
OMNI_MIDICHANNEL = 16 # pads ch10 + knobs ch1
|
||
PAD_MIDI_CH = 9
|
||
|
||
# 20× BCC145, 8ch mode, physical/UI start channel 88
|
||
# QLC XML Address is 0-based: Address 87 → DMX/UI channel 88 (same as xchc.qxw).
|
||
BCC_COUNT = 20
|
||
BCC_START_ADDRESS = 87
|
||
BCC_CHANNELS = 8
|
||
UNIVERSE_CHANNELS = BCC_START_ADDRESS + BCC_COUNT * BCC_CHANNELS # 247
|
||
# 8ch map: 0 Dim, 1 Strobe, 2–5 RGBW, 6 Macro, 7 Speed
|
||
STROBE_CH, MACRO_CH, SPEED_CH = 1, 6, 7
|
||
|
||
# Knob bank 1 (CC 30–37): knobs 1–8 — master Dim/RGBW/Strobe/Macro/Speed
|
||
# Knob bank 2 (CC 38–44): knobs 9–15 — Dim boost for #9–#15 (HTP vs master)
|
||
KNOB_BANK1 = [
|
||
# (cc, caption, widget_id, dmx_ch, fg, cng, value, fixtures|None)
|
||
(32, "Dim", 0, 0, "4294967295", "None", 200, None),
|
||
(36, "R", 1, 2, "4294901760", "Red", 0, None),
|
||
(37, "G", 2, 3, "4278255360", "Green", 0, None),
|
||
(34, "B", 3, 4, "4278190335", "Blue", 0, None),
|
||
(35, "W", 4, 5, "4294967295", "None", 0, None),
|
||
(33, "Strobe", 5, STROBE_CH, "4294922844", "None", 0, None),
|
||
(30, "Macro", 6, MACRO_CH, "4288256409", "None", 0, None),
|
||
(31, "Speed", 7, SPEED_CH, "4286611584", "None", 0, None),
|
||
]
|
||
KNOB_BANK2 = [
|
||
# (cc, caption, widget_id, fixture_id)
|
||
(38, "F9", 20, 8),
|
||
(39, "F10", 21, 9),
|
||
(40, "F11", 22, 10),
|
||
(41, "F12", 23, 11),
|
||
(42, "F13", 24, 12),
|
||
(43, "F14", 25, 13),
|
||
(44, "F15", 26, 14),
|
||
]
|
||
|
||
# 4×4 pads → colour flashes / utility (scenes built below)
|
||
# note 36..51 with OMNI encoding
|
||
PAD_COLORS = [
|
||
# (name, r, g, b, w) — bottom row left→right, then up
|
||
("Red", 255, 0, 0, 0),
|
||
("Green", 0, 255, 0, 0),
|
||
("Blue", 0, 0, 255, 0),
|
||
("White", 0, 0, 0, 255),
|
||
("Yellow", 255, 255, 0, 0),
|
||
("Cyan", 0, 255, 255, 0),
|
||
("Magenta", 255, 0, 255, 0),
|
||
("Orange", 255, 80, 0, 0),
|
||
("Warm", 255, 120, 40, 80),
|
||
("Cool", 80, 120, 255, 40),
|
||
("Pink", 255, 40, 120, 0),
|
||
("Lime", 120, 255, 0, 0),
|
||
("Full", 255, 255, 255, 255),
|
||
("Half", 128, 128, 128, 128),
|
||
("Dim50", 0, 0, 0, 0), # blackout colour; dim stays
|
||
("Black", 0, 0, 0, 0),
|
||
]
|
||
|
||
|
||
def detect_midi_uid() -> str:
|
||
"""Prefer smoothed virtual port when the pad controller (padcontroller.midi) is running."""
|
||
try:
|
||
out = subprocess.check_output(["aconnect", "-l"], text=True)
|
||
except (FileNotFoundError, subprocess.CalledProcessError):
|
||
out = ""
|
||
for name in (
|
||
"padcontroller",
|
||
"SMC-PAD Bluetooth",
|
||
"SINCO SMC-PAD-Private",
|
||
"SINCO SMC-PAD-Master",
|
||
"SINCO",
|
||
):
|
||
if name in out:
|
||
return name
|
||
return "SMC-PAD Bluetooth"
|
||
|
||
|
||
ARTNET_OUTPUT_IP = "192.168.1.175"
|
||
# Device Art-Net universe (IceRay SwOut); keep in sync with the box
|
||
ARTNET_OUTPUT_UNI = "0"
|
||
ARTNET_LINE = "0"
|
||
|
||
|
||
def detect_artnet_uid() -> str:
|
||
"""Local IPv4 on the same /24 as the Art-Net node (prefer wlan/eth)."""
|
||
try:
|
||
out = subprocess.check_output(["ip", "-4", "-o", "addr", "show"], text=True)
|
||
except (FileNotFoundError, subprocess.CalledProcessError):
|
||
return "192.168.1.90"
|
||
prefix = ".".join(ARTNET_OUTPUT_IP.split(".")[:3]) + "."
|
||
candidates: list[str] = []
|
||
for line in out.splitlines():
|
||
# 2: wlo1 inet 192.168.1.90/24 ...
|
||
parts = line.split()
|
||
if len(parts) < 4 or parts[2] != "inet":
|
||
continue
|
||
ip = parts[3].split("/", 1)[0]
|
||
iface = parts[1]
|
||
if ip.startswith(prefix) and not iface.startswith(("lo", "vir", "docker", "br-", "mpq")):
|
||
candidates.append(ip)
|
||
return candidates[0] if candidates else "192.168.1.90"
|
||
|
||
|
||
def output_xml() -> str:
|
||
uid = detect_artnet_uid()
|
||
return f""" <Output Plugin="ArtNet" UID="{uid}" Line="{ARTNET_LINE}">
|
||
<PluginParameters outputIP="{ARTNET_OUTPUT_IP}" outputUni="{ARTNET_OUTPUT_UNI}" UniverseChannels="{UNIVERSE_CHANNELS}"/>
|
||
</Output>"""
|
||
|
||
|
||
def install_profile() -> None:
|
||
PROFILE_DST.parent.mkdir(parents=True, exist_ok=True)
|
||
shutil.copy2(PROFILE_SRC, PROFILE_DST)
|
||
|
||
|
||
def appearance(fg: str = "Default") -> str:
|
||
return f""" <Appearance>
|
||
<FrameStyle>Sunken</FrameStyle>
|
||
<ForegroundColor>{fg}</ForegroundColor>
|
||
<BackgroundColor>Default</BackgroundColor>
|
||
<BackgroundImage>None</BackgroundImage>
|
||
<Font>Default</Font>
|
||
</Appearance>"""
|
||
|
||
|
||
def fixture_ids() -> range:
|
||
return range(BCC_COUNT)
|
||
|
||
|
||
def slider(
|
||
wid: int,
|
||
caption: str,
|
||
x: int,
|
||
y: int,
|
||
dmx_ch: int,
|
||
*,
|
||
fg: str,
|
||
cng: str,
|
||
value: int,
|
||
midi_cc: int | None,
|
||
fixtures: range | list[int] | None = None,
|
||
width: int = 60,
|
||
height: int = 280,
|
||
) -> str:
|
||
inp = ""
|
||
if midi_cc is not None:
|
||
inp = f'\n <Input Universe="{MIDI_UNIVERSE_ID}" Channel="{midi_cc}"/>'
|
||
fids = list(fixture_ids() if fixtures is None else fixtures)
|
||
channels = "\n".join(
|
||
f' <Channel Fixture="{fid}">{dmx_ch}</Channel>' for fid in fids
|
||
)
|
||
return f""" <Slider Caption="{caption}" ID="{wid}" WidgetStyle="Slider" InvertedAppearance="false">
|
||
<WindowState Visible="True" X="{x}" Y="{y}" Width="{width}" Height="{height}"/>
|
||
{appearance(fg)}
|
||
<SliderMode ValueDisplayStyle="Exact" ClickAndGoType="{cng}" Monitor="true">Level</SliderMode>
|
||
<Level LowLimit="0" HighLimit="255" Value="{value}">
|
||
{channels}
|
||
</Level>
|
||
<Playback>
|
||
<Function>4294967295</Function>
|
||
</Playback>{inp}
|
||
</Slider>"""
|
||
|
||
|
||
def scene_xml(fid: int, name: str, r: int, g: int, b: int, w: int) -> str:
|
||
# BCC145 8ch: Dim left to slider; force Strobe/Macro/Speed off; set RGBW.
|
||
vals = [
|
||
(STROBE_CH, 0),
|
||
(2, r),
|
||
(3, g),
|
||
(4, b),
|
||
(5, w),
|
||
(MACRO_CH, 0),
|
||
(SPEED_CH, 0),
|
||
]
|
||
fv = "\n".join(
|
||
f' <FixtureVal ID="{fx}" Channel="{ch}">{v}</FixtureVal>'
|
||
for fx in fixture_ids()
|
||
for ch, v in vals
|
||
)
|
||
return f""" <Function ID="{fid}" Type="Scene" Name="{name}">
|
||
<Bus Role="Fade">1</Bus>
|
||
<Speed FadeIn="0" FadeOut="0" Duration="0"/>
|
||
<Direction>Forward</Direction>
|
||
<RunOrder>Loop</RunOrder>
|
||
{fv}
|
||
</Function>"""
|
||
|
||
|
||
def fixtures_xml() -> str:
|
||
blocks = []
|
||
for i in fixture_ids():
|
||
addr = BCC_START_ADDRESS + i * BCC_CHANNELS
|
||
blocks.append(
|
||
f""" <Fixture>
|
||
<Manufacturer>beamZ</Manufacturer>
|
||
<Model>BCC145</Model>
|
||
<Mode>8 Channel</Mode>
|
||
<ID>{i}</ID>
|
||
<Name>BCC145 #{i + 1}</Name>
|
||
<Universe>0</Universe>
|
||
<Address>{addr}</Address>
|
||
<Channels>{BCC_CHANNELS}</Channels>
|
||
</Fixture>"""
|
||
)
|
||
return "\n".join(blocks)
|
||
|
||
|
||
def button_xml(wid: int, caption: str, x: int, y: int, func_id: int, midi_ch: int, bg: str) -> str:
|
||
return f""" <Button Caption="{caption}" ID="{wid}" Icon="">
|
||
<WindowState Visible="True" X="{x}" Y="{y}" Width="70" Height="56"/>
|
||
<Appearance>
|
||
<FrameStyle>None</FrameStyle>
|
||
<ForegroundColor>4294967295</ForegroundColor>
|
||
<BackgroundColor>{bg}</BackgroundColor>
|
||
<BackgroundImage>None</BackgroundImage>
|
||
<Font>Default</Font>
|
||
</Appearance>
|
||
<Function ID="{func_id}"/>
|
||
<Action>Toggle</Action>
|
||
<Intensity Adjust="False">100</Intensity>
|
||
<Input Universe="{MIDI_UNIVERSE_ID}" Channel="{midi_ch}"/>
|
||
</Button>"""
|
||
|
||
|
||
def bg_color(r: int, g: int, b: int) -> str:
|
||
# QLC packed ARGB as decimal
|
||
return str((0xFF << 24) | (r << 16) | (g << 8) | b)
|
||
|
||
|
||
def build(uid: str) -> str:
|
||
functions = []
|
||
buttons = []
|
||
for i, (name, r, g, b, w) in enumerate(PAD_COLORS):
|
||
fid = 10 + i
|
||
note = 36 + i
|
||
midi_ch = (PAD_MIDI_CH << 12) | (128 + note)
|
||
functions.append(scene_xml(fid, name, r, g, b, w))
|
||
row, col = divmod(i, 4)
|
||
# pad grid: bottom row is notes 36-39 → visual row 3
|
||
vx = 20 + col * 80
|
||
vy = 20 + (3 - row) * 66
|
||
buttons.append(
|
||
button_xml(10 + i, name, vx, vy, fid, midi_ch, bg_color(r, g, b))
|
||
)
|
||
|
||
sliders = []
|
||
for i, (cc, cap, wid, dmx, fg, cng, val, fxs) in enumerate(KNOB_BANK1):
|
||
sliders.append(
|
||
slider(
|
||
wid,
|
||
cap,
|
||
360 + i * 58,
|
||
20,
|
||
dmx,
|
||
fg=fg,
|
||
cng=cng,
|
||
value=val,
|
||
midi_cc=cc,
|
||
fixtures=fxs,
|
||
)
|
||
)
|
||
for i, (cc, cap, wid, fx) in enumerate(KNOB_BANK2):
|
||
sliders.append(
|
||
slider(
|
||
wid,
|
||
cap,
|
||
360 + i * 58,
|
||
310,
|
||
0, # Dim
|
||
fg="4294967295",
|
||
cng="None",
|
||
value=200,
|
||
midi_cc=cc,
|
||
fixtures=[fx],
|
||
height=120,
|
||
)
|
||
)
|
||
|
||
vc_widgets = "\n".join(buttons + sliders)
|
||
funcs = "\n".join(functions)
|
||
fixtures = fixtures_xml()
|
||
dmx_out = output_xml()
|
||
|
||
return f"""<?xml version="1.0" encoding="UTF-8"?>
|
||
<!DOCTYPE Workspace>
|
||
<Workspace xmlns="http://www.qlcplus.org/Workspace" CurrentWindow="VirtualConsole">
|
||
<Creator>
|
||
<Name>Q Light Controller Plus</Name>
|
||
<Version>4.12.7</Version>
|
||
<Author>Jimmy</Author>
|
||
</Creator>
|
||
<Engine>
|
||
<InputOutputMap>
|
||
<Universe Name="Universe 1" ID="0">
|
||
{dmx_out}
|
||
</Universe>
|
||
<Universe Name="Universe 2" ID="1">
|
||
<Input Plugin="MIDI" UID="{uid}" Line="0" Profile="{PROFILE_NAME}">
|
||
<PluginParameters midichannel="{OMNI_MIDICHANNEL}"/>
|
||
</Input>
|
||
</Universe>
|
||
<Universe Name="Universe 3" ID="2"/>
|
||
<Universe Name="Universe 4" ID="3"/>
|
||
</InputOutputMap>
|
||
{fixtures}
|
||
{funcs}
|
||
</Engine>
|
||
<VirtualConsole>
|
||
<Frame Caption="">
|
||
<Appearance>
|
||
<FrameStyle>None</FrameStyle>
|
||
<ForegroundColor>Default</ForegroundColor>
|
||
<BackgroundColor>Default</BackgroundColor>
|
||
<BackgroundImage>None</BackgroundImage>
|
||
<Font>Default</Font>
|
||
</Appearance>
|
||
{vc_widgets}
|
||
</Frame>
|
||
<Properties>
|
||
<Size Width="900" Height="460"/>
|
||
<GrandMaster ChannelMode="Intensity" ValueMode="Reduce" SliderMode="Normal"/>
|
||
</Properties>
|
||
</VirtualConsole>
|
||
<SimpleDesk>
|
||
<Engine/>
|
||
</SimpleDesk>
|
||
</Workspace>
|
||
"""
|
||
|
||
|
||
def patch_qsettings(uid: str) -> None:
|
||
conf = Path.home() / ".config" / "qlcplus" / "Q Light Controller Plus.conf"
|
||
if not conf.exists():
|
||
return
|
||
text = conf.read_text()
|
||
key = uid.replace(" ", "%20")
|
||
pattern = rf"(Input\\{re.escape(key)}\\midichannel=)\d+"
|
||
if re.search(pattern, text):
|
||
text = re.sub(pattern, rf"\g<1>{OMNI_MIDICHANNEL}", text)
|
||
elif "[midiplugin]" in text and f"Input\\{key}\\midichannel=" not in text:
|
||
text = text.replace(
|
||
"[midiplugin]\n",
|
||
f"[midiplugin]\nInput\\{key}\\midichannel={OMNI_MIDICHANNEL}\n"
|
||
f"Input\\{key}\\mode=Control Change\n"
|
||
f"Input\\{key}\\initmessage=\n",
|
||
1,
|
||
)
|
||
conf.write_text(text)
|
||
|
||
|
||
def main() -> None:
|
||
uid = detect_midi_uid()
|
||
install_profile()
|
||
patch_qsettings(uid)
|
||
OUT.write_text(build(uid))
|
||
ui_start = BCC_START_ADDRESS + 1
|
||
ui_last = BCC_START_ADDRESS + BCC_COUNT * BCC_CHANNELS
|
||
print(f"Wrote {OUT}")
|
||
print(f" MIDI: {uid} OMNI on Universe 2")
|
||
print(
|
||
f" Art-Net → {ARTNET_OUTPUT_IP} uni {ARTNET_OUTPUT_UNI} "
|
||
f"(local {detect_artnet_uid()})"
|
||
)
|
||
print(
|
||
f" {BCC_COUNT}× BCC145 8ch @ UI {ui_start}–{ui_last} "
|
||
f"(XML Address {BCC_START_ADDRESS}–{BCC_START_ADDRESS + (BCC_COUNT - 1) * BCC_CHANNELS})"
|
||
)
|
||
print(" Bank1 knobs 1–8: Dim/RGBW/Strobe/Macro/Speed (all)")
|
||
print(" Bank2 knobs 9–15: Dim for #9–#15")
|
||
print(" 16 pads → colour scenes (all fixtures; strobe/macro forced off)")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|