#!/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 smoother daemon is running.""" try: out = subprocess.check_output(["aconnect", "-l"], text=True) except (FileNotFoundError, subprocess.CalledProcessError): out = "" for name in ( "SMC-PAD Smooth", "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""" """ 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""" Sunken {fg} Default None Default """ 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 ' fids = list(fixture_ids() if fixtures is None else fixtures) channels = "\n".join( f' {dmx_ch}' for fid in fids ) return f""" {appearance(fg)} Level {channels} 4294967295 {inp} """ 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' {v}' for fx in fixture_ids() for ch, v in vals ) return f""" 1 Forward Loop {fv} """ def fixtures_xml() -> str: blocks = [] for i in fixture_ids(): addr = BCC_START_ADDRESS + i * BCC_CHANNELS blocks.append( f""" beamZ BCC145 8 Channel {i} BCC145 #{i + 1} 0
{addr}
{BCC_CHANNELS}
""" ) 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""" """ 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""" Q Light Controller Plus 4.12.7 Jimmy {dmx_out} {fixtures} {funcs} None Default Default None Default {vc_widgets} """ 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()