Add a show compiler so QLC+ workspaces can be described and tested.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fee1985e1a
commit
4374ffb430
14 files changed
+3739
No files matched your search
+300
@@ -0,0 +1,300 @@
|
||||
"""Virtual console widgets."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from .model import INVALID_FUNCTION, MidiBinding
|
||||
from .xmlutil import appearance, attr
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .model import Show
|
||||
|
||||
|
||||
@dataclass
|
||||
class Slider:
|
||||
id: int
|
||||
caption: str
|
||||
channels: list[tuple[int, int]]
|
||||
x: int
|
||||
y: int
|
||||
w: int
|
||||
h: int
|
||||
value: int = 0
|
||||
fg: Any = "Default"
|
||||
cng: str = "None"
|
||||
inverted: bool = False
|
||||
binding: MidiBinding | None = None
|
||||
type_name: str = "Slider"
|
||||
|
||||
def render(self, indent: str = " ") -> str:
|
||||
inner = indent + " "
|
||||
inv = "true" if self.inverted else "false"
|
||||
channels = "\n".join(
|
||||
f'{inner} <Channel Fixture="{fid}">{ch}</Channel>' for fid, ch in self.channels
|
||||
)
|
||||
extra = _input_xml(self.binding, inner)
|
||||
return (
|
||||
f"{indent}<Slider Caption={attr(self.caption)} ID=\"{self.id}\" "
|
||||
f'WidgetStyle="Slider" InvertedAppearance="{inv}">\n'
|
||||
f'{inner}<WindowState Visible="True" X="{self.x}" Y="{self.y}" '
|
||||
f'Width="{self.w}" Height="{self.h}"/>\n'
|
||||
f"{appearance(fg=self.fg, indent=inner)}\n"
|
||||
f'{inner}<SliderMode ValueDisplayStyle="Exact" ClickAndGoType={attr(self.cng)} '
|
||||
f'Monitor="true">Level</SliderMode>\n'
|
||||
f"{inner}<Reset/>\n"
|
||||
f'{inner}<Level LowLimit="0" HighLimit="255" Value="{self.value}">\n'
|
||||
f"{channels}\n"
|
||||
f"{inner}</Level>\n"
|
||||
f"{inner}<Playback>\n"
|
||||
f"{inner} <Function>{INVALID_FUNCTION}</Function>\n"
|
||||
f"{inner}</Playback>{extra}\n"
|
||||
f"{indent}</Slider>"
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Button:
|
||||
id: int
|
||||
caption: str
|
||||
function_id: int
|
||||
x: int
|
||||
y: int
|
||||
w: int
|
||||
h: int
|
||||
fg: Any = "4294967295"
|
||||
bg: Any = "Default"
|
||||
action: str = "Toggle"
|
||||
binding: MidiBinding | None = None
|
||||
type_name: str = "Button"
|
||||
|
||||
def render(self, indent: str = " ") -> str:
|
||||
inner = indent + " "
|
||||
extra = _input_xml(self.binding, inner)
|
||||
return (
|
||||
f"{indent}<Button Caption={attr(self.caption)} ID=\"{self.id}\" Icon=\"\">\n"
|
||||
f'{inner}<WindowState Visible="True" X="{self.x}" Y="{self.y}" '
|
||||
f'Width="{self.w}" Height="{self.h}"/>\n'
|
||||
f"{appearance(fg=self.fg, bg=self.bg, frame='None', indent=inner)}\n"
|
||||
f'{inner}<Function ID="{self.function_id}"/>\n'
|
||||
f"{inner}<Action>{self.action}</Action>\n"
|
||||
f'{inner}<Intensity Adjust="False">100</Intensity>{extra}\n'
|
||||
f"{indent}</Button>"
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class XYPad:
|
||||
id: int
|
||||
caption: str
|
||||
fixture_id: int
|
||||
x: int
|
||||
y: int
|
||||
w: int
|
||||
h: int
|
||||
reverse_pan: bool = False
|
||||
reverse_tilt: bool = False
|
||||
pan: int = 128
|
||||
tilt: int = 128
|
||||
binding: MidiBinding | None = None
|
||||
type_name: str = "XYPad"
|
||||
|
||||
def render(self, indent: str = " ") -> str:
|
||||
inner = indent + " "
|
||||
pan_rev = "True" if self.reverse_pan else "False"
|
||||
tilt_rev = "True" if self.reverse_tilt else "False"
|
||||
extra = _input_xml(self.binding, inner)
|
||||
return (
|
||||
f"{indent}<XYPad Caption={attr(self.caption)} ID=\"{self.id}\" InvertedAppearance=\"0\">\n"
|
||||
f'{inner}<WindowState Visible="True" X="{self.x}" Y="{self.y}" '
|
||||
f'Width="{self.w}" Height="{self.h}"/>\n'
|
||||
f"{appearance(indent=inner)}\n"
|
||||
f'{inner}<Fixture ID="{self.fixture_id}" Head="0">\n'
|
||||
f'{inner} <Axis ID="X" LowLimit="0" HighLimit="1" Reverse="{pan_rev}"/>\n'
|
||||
f'{inner} <Axis ID="Y" LowLimit="0" HighLimit="1" Reverse="{tilt_rev}"/>\n'
|
||||
f"{inner}</Fixture>\n"
|
||||
f'{inner}<Window hMin="0" hMax="255" vMin="0" vMax="255"/>\n'
|
||||
f'{inner}<Pan Position="{self.pan}"/>\n'
|
||||
f'{inner}<Tilt Position="{self.tilt}"/>{extra}\n'
|
||||
f"{indent}</XYPad>"
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Frame:
|
||||
show: Show
|
||||
caption: str
|
||||
x: int = 0
|
||||
y: int = 0
|
||||
w: int = 0
|
||||
h: int = 0
|
||||
solo: bool = False
|
||||
root: bool = False
|
||||
show_header: bool = True
|
||||
children: list[Any] = field(default_factory=list)
|
||||
id: int | None = None
|
||||
type_name: str = "Frame"
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
self.type_name = "SoloFrame" if self.solo else "Frame"
|
||||
if not self.root and self.id is None:
|
||||
self.id = self.show.alloc_widget()
|
||||
|
||||
def slider(
|
||||
self,
|
||||
caption: str,
|
||||
channels: list[tuple[Any, int]],
|
||||
*,
|
||||
x: int,
|
||||
y: int,
|
||||
w: int,
|
||||
h: int,
|
||||
value: int = 0,
|
||||
fg: Any = "Default",
|
||||
cng: str = "None",
|
||||
inverted: bool = False,
|
||||
input: MidiBinding | None = None,
|
||||
) -> Slider:
|
||||
widget = Slider(
|
||||
id=self.show.alloc_widget(),
|
||||
caption=caption,
|
||||
channels=[(self.show.fixture_id(fx), int(ch)) for fx, ch in channels],
|
||||
x=x,
|
||||
y=y,
|
||||
w=w,
|
||||
h=h,
|
||||
value=int(value),
|
||||
fg=fg,
|
||||
cng=cng,
|
||||
inverted=inverted,
|
||||
binding=input,
|
||||
)
|
||||
self.children.append(widget)
|
||||
return widget
|
||||
|
||||
def button(
|
||||
self,
|
||||
caption: str,
|
||||
function: Any,
|
||||
*,
|
||||
x: int,
|
||||
y: int,
|
||||
w: int,
|
||||
h: int,
|
||||
fg: Any = "4294967295",
|
||||
bg: Any = "Default",
|
||||
action: str = "Toggle",
|
||||
input: MidiBinding | None = None,
|
||||
) -> Button:
|
||||
if isinstance(function, int):
|
||||
fid = function
|
||||
elif isinstance(function, str):
|
||||
fid = self.show.functions_by_key[function].id
|
||||
else:
|
||||
fid = function.id
|
||||
widget = Button(
|
||||
id=self.show.alloc_widget(),
|
||||
caption=caption,
|
||||
function_id=fid,
|
||||
x=x,
|
||||
y=y,
|
||||
w=w,
|
||||
h=h,
|
||||
fg=fg,
|
||||
bg=bg,
|
||||
action=action,
|
||||
binding=input,
|
||||
)
|
||||
self.children.append(widget)
|
||||
return widget
|
||||
|
||||
def xypad(
|
||||
self,
|
||||
caption: str,
|
||||
fixture: Any,
|
||||
*,
|
||||
x: int,
|
||||
y: int,
|
||||
w: int,
|
||||
h: int,
|
||||
reverse_pan: bool = False,
|
||||
reverse_tilt: bool = False,
|
||||
pan: int = 128,
|
||||
tilt: int = 128,
|
||||
input: MidiBinding | None = None,
|
||||
) -> XYPad:
|
||||
widget = XYPad(
|
||||
id=self.show.alloc_widget(),
|
||||
caption=caption,
|
||||
fixture_id=self.show.fixture_id(fixture),
|
||||
x=x,
|
||||
y=y,
|
||||
w=w,
|
||||
h=h,
|
||||
reverse_pan=reverse_pan,
|
||||
reverse_tilt=reverse_tilt,
|
||||
pan=int(pan),
|
||||
tilt=int(tilt),
|
||||
binding=input,
|
||||
)
|
||||
self.children.append(widget)
|
||||
return widget
|
||||
|
||||
def frame(
|
||||
self,
|
||||
caption: str,
|
||||
*,
|
||||
x: int,
|
||||
y: int,
|
||||
w: int,
|
||||
h: int,
|
||||
solo: bool = False,
|
||||
header: bool = True,
|
||||
) -> Frame:
|
||||
child = Frame(self.show, caption, x, y, w, h, solo=solo, show_header=header)
|
||||
self.children.append(child)
|
||||
return child
|
||||
|
||||
def solo_frame(self, caption: str, *, x: int, y: int, w: int, h: int) -> Frame:
|
||||
return self.frame(caption, x=x, y=y, w=w, h=h, solo=True)
|
||||
|
||||
def render(self, indent: str = " ") -> str:
|
||||
inner = indent + " "
|
||||
if self.root:
|
||||
body = "\n".join(child.render(inner) for child in self.children)
|
||||
parts = [
|
||||
f"{indent}<Frame Caption=\"\">",
|
||||
appearance(frame="None", indent=inner),
|
||||
]
|
||||
if body:
|
||||
parts.append(body)
|
||||
parts.append(f"{indent}</Frame>")
|
||||
return "\n".join(parts)
|
||||
tag = "SoloFrame" if self.solo else "Frame"
|
||||
flags = [
|
||||
f"{inner}<AllowChildren>True</AllowChildren>",
|
||||
f"{inner}<AllowResize>True</AllowResize>",
|
||||
f"{inner}<ShowHeader>{'True' if self.show_header else 'False'}</ShowHeader>",
|
||||
f"{inner}<ShowEnableButton>False</ShowEnableButton>",
|
||||
]
|
||||
if not self.solo:
|
||||
flags.append(f"{inner}<ShowIntensityButton>False</ShowIntensityButton>")
|
||||
flags.append(f"{inner}<Mixing>False</Mixing>")
|
||||
nested = "\n".join(child.render(inner) for child in self.children)
|
||||
parts = [
|
||||
f"{indent}<{tag} Caption={attr(self.caption)} ID=\"{self.id}\">",
|
||||
appearance(indent=inner),
|
||||
f'{inner}<WindowState Visible="True" X="{self.x}" Y="{self.y}" Width="{self.w}" Height="{self.h}"/>',
|
||||
*flags,
|
||||
]
|
||||
if nested:
|
||||
parts.append(nested)
|
||||
parts.append(f"{indent}</{tag}>")
|
||||
return "\n".join(parts)
|
||||
|
||||
|
||||
def _input_xml(binding: MidiBinding | None, indent: str) -> str:
|
||||
if binding is None:
|
||||
return ""
|
||||
return f'\n{indent}<Input Universe="{binding.universe}" Channel="{binding.channel}"/>'
|
||||
Reference in new issue
Block a user