mod generated;
pub use generated::{
BANNER_COUNT, Banner, PANEL_CONTROL_COUNT, PANEL_PRESS_COUNT, PANEL_ROWS, SECTION_COUNT,
};
use generated::{BANNERS, SECTIONS};
use core::fmt;
use crate::effect::Colour;
use crate::param::{Controller, Group, ParamId};
use crate::pixels::Glyph;
#[must_use]
pub fn sections() -> &'static [Section; SECTION_COUNT] {
&SECTIONS
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct Section {
name: &'static str,
row: u8,
group: Group,
banner: Banner,
clusters: u8,
note: Option<&'static str>,
controls: &'static [PanelControl],
presses: &'static [PanelPress],
}
impl Section {
#[must_use]
pub const fn name(&self) -> &'static str {
self.name
}
#[must_use]
pub const fn row(&self) -> u8 {
self.row
}
#[must_use]
pub const fn group(&self) -> Group {
self.group
}
#[must_use]
pub const fn controls(&self) -> &'static [PanelControl] {
self.controls
}
#[must_use]
pub const fn presses(&self) -> &'static [PanelPress] {
self.presses
}
#[must_use]
pub const fn banner(&self) -> Banner {
self.banner
}
#[must_use]
pub const fn clusters(&self) -> u8 {
self.clusters
}
#[must_use]
pub const fn note(&self) -> Option<&'static str> {
self.note
}
}
impl fmt::Display for Section {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct PanelControl {
parameter: ParamId,
legend: &'static str,
drawing: Option<Glyph>,
shape: PanelShape,
cluster: u8,
lamp: Option<Lamp>,
}
impl PanelControl {
#[must_use]
pub const fn parameter(&self) -> ParamId {
self.parameter
}
#[must_use]
pub const fn legend(&self) -> &'static str {
self.legend
}
#[must_use]
pub const fn silkscreen(&self) -> Silkscreen {
match self.drawing {
Some(glyph) => Silkscreen::Drawing(glyph),
None => Silkscreen::Word(self.legend),
}
}
#[must_use]
pub const fn shape(&self) -> PanelShape {
self.shape
}
#[must_use]
pub const fn cluster(&self) -> u8 {
self.cluster
}
#[must_use]
pub const fn lamp(&self) -> Option<Lamp> {
self.lamp
}
}
impl fmt::Display for PanelControl {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.legend)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct PanelPress {
legend: &'static str,
shape: PanelShape,
lamp: Lamp,
sends: Sends,
cluster: u8,
note: Option<&'static str>,
}
impl PanelPress {
#[must_use]
pub const fn legend(&self) -> &'static str {
self.legend
}
#[must_use]
pub const fn shape(&self) -> PanelShape {
self.shape
}
#[must_use]
pub const fn lamp(&self) -> Lamp {
self.lamp
}
#[must_use]
pub const fn sends(&self) -> Sends {
self.sends
}
#[must_use]
pub const fn cluster(&self) -> u8 {
self.cluster
}
#[must_use]
pub const fn note(&self) -> Option<&'static str> {
self.note
}
}
impl fmt::Display for PanelPress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.legend)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub enum Sends {
Nothing,
Controller(u8),
}
impl Sends {
#[must_use]
pub fn controller(self) -> Option<&'static Controller> {
match self {
Self::Nothing => None,
Self::Controller(cc) => Controller::for_cc(cc),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Lamp {
Amber,
Cyan,
White,
}
impl fmt::Display for Lamp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Amber => "amber",
Self::Cyan => "cyan",
Self::White => "white",
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub enum Silkscreen {
Word(&'static str),
Drawing(Glyph),
}
impl Banner {
#[must_use]
pub fn plate(self) -> Colour {
self.colours().0
}
#[must_use]
pub fn ink(self) -> Colour {
self.colours().1
}
fn colours(self) -> (Colour, Colour) {
BANNERS
.get(self as usize)
.copied()
.unwrap_or((Colour::new(0, 0, 0), Colour::new(0, 0, 0)))
}
}
impl fmt::Display for Banner {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.plate())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum PanelShape {
Fader,
Button,
Lamps,
}
#[cfg(test)]
#[expect(
clippy::expect_used,
reason = "a failed expectation is the test failure"
)]
mod tests {
use super::{
BANNER_COUNT, Banner, Lamp, PANEL_CONTROL_COUNT, PANEL_PRESS_COUNT, PANEL_ROWS, PanelShape,
Sends, Silkscreen, sections,
};
use crate::param::{Group, Kind, PARAMETER_COUNT, ParamId};
#[test]
fn a_parameter_has_at_most_one_control_on_the_panel() {
let mut seen = [false; PARAMETER_COUNT];
let mut counted = 0;
for section in sections() {
for control in section.controls() {
let parameter = control.parameter();
let slot = seen
.get_mut(usize::from(parameter.offset()))
.expect("a parameter is inside the table");
assert!(!*slot, "{parameter} is on the panel twice");
*slot = true;
counted += 1;
}
}
assert_eq!(counted, PANEL_CONTROL_COUNT);
}
#[test]
fn every_plate_holds_parameters_of_one_group() {
for section in sections() {
assert!(!section.controls().is_empty(), "{section} has no controls");
assert!(section.row() < PANEL_ROWS, "{section} is in no row");
for control in section.controls() {
assert_eq!(
control.parameter().group(),
section.group(),
"{} is on the {section} plate and in another section",
control.parameter()
);
}
}
}
#[test]
fn a_legend_is_printed_the_way_a_panel_prints_one() {
for section in sections() {
for control in section.controls() {
let legend = control.legend();
assert!(!legend.is_empty(), "{} has no legend", control.parameter());
assert!(
legend.chars().all(|c| !c.is_ascii_lowercase()),
"{legend} is not printed in caps"
);
assert!(
legend.split(' ').all(|word| word.len() <= 6),
"{legend} is too long a word to print over a fader"
);
}
}
}
#[test]
fn a_strip_of_lamps_has_names_to_light() {
for section in sections() {
for control in section.controls() {
if control.shape() != PanelShape::Lamps {
continue;
}
assert!(
matches!(control.parameter().kind(), Kind::Enumerated(_)),
"{} is drawn as lamps and has no names",
control.parameter()
);
assert!(control.parameter().choices().is_some());
}
}
}
#[test]
fn the_panel_is_the_handful_a_player_reaches_for() {
let panelled = sections()
.iter()
.map(|section| section.controls().len())
.sum::<usize>();
assert_eq!(panelled, PANEL_CONTROL_COUNT);
assert!(panelled * 4 < PARAMETER_COUNT, "a second rack, not a panel");
assert!(panelled > 20, "a front panel with nothing on it");
}
#[test]
fn the_rows_are_the_instruments_own() {
let row = |wanted: u8| {
sections()
.iter()
.filter(move |section| section.row() == wanted)
.map(super::Section::name)
};
assert!(row(0).eq(["ARP / SEQ", "LFO 1", "LFO 2", "POLY"]));
assert!(row(1).eq(["DCO 1 & 2", "VCF", "VCA", "HPF", "ENVELOPES"]));
}
#[test]
fn a_clusters_numbering_is_the_runs_a_rule_divides() {
for section in sections() {
let mut current = 0;
let clusters = section
.controls()
.iter()
.map(super::PanelControl::cluster)
.chain(section.presses().iter().map(super::PanelPress::cluster));
for cluster in clusters {
assert!(
cluster == current || cluster == current + 1,
"{section} rules a cluster {cluster} after {current}"
);
current = cluster;
}
assert_eq!(
section.clusters(),
current + 1,
"{section} counts its clusters differently from its controls"
);
}
}
#[test]
fn only_a_press_carries_a_lamp() {
let mut lit = 0;
for section in sections() {
for control in section.controls() {
match control.shape() {
PanelShape::Button => {
assert!(control.lamp().is_some(), "{} is unlit", control.parameter());
lit += 1;
}
PanelShape::Fader | PanelShape::Lamps => assert_eq!(
control.lamp(),
None,
"{} is not a press and carries a lamp",
control.parameter()
),
}
}
}
assert!(lit > 0, "a front panel with nothing to press");
let cyan = sections()
.iter()
.flat_map(super::Section::controls)
.filter(|control| control.lamp() == Some(Lamp::Cyan))
.map(super::PanelControl::parameter);
assert!(cyan.eq([ParamId::ArpHold]));
}
#[test]
fn a_press_says_what_it_sends() {
let presses: usize = sections()
.iter()
.map(|section| section.presses().len())
.sum();
assert_eq!(presses, PANEL_PRESS_COUNT);
for section in sections() {
for press in section.presses() {
assert_eq!(press.shape(), PanelShape::Button);
assert!(press.cluster() < section.clusters());
match press.sends() {
Sends::Nothing => assert!(
press.note().is_some(),
"{press} sends nothing and says nothing about why"
),
Sends::Controller(cc) => {
assert!(
press.sends().controller().is_some(),
"{press} sends CC {cc}"
);
}
}
}
}
let legends = sections()
.iter()
.flat_map(super::Section::presses)
.map(super::PanelPress::legend);
assert!(legends.eq(["CHORD", "POLY CHORD"]));
}
#[test]
fn a_drawn_silkscreen_is_a_wave_and_a_word() {
let mut drawn = 0;
for section in sections() {
for control in section.controls() {
match control.silkscreen() {
Silkscreen::Word(word) => assert_eq!(word, control.legend()),
Silkscreen::Drawing(glyph) => {
drawn += 1;
assert!(!control.legend().is_empty());
assert_eq!(control.parameter().glyph(), Some(glyph));
}
}
}
}
assert_eq!(drawn, 2, "the two waveform presses on OSC 1");
}
#[test]
fn every_plate_is_printed_on_a_measured_banner() {
assert_eq!(BANNER_COUNT, 3);
for section in sections() {
let banner = section.banner();
assert_ne!(
banner.plate(),
banner.ink(),
"{section} prints its name in the colour of the strip"
);
}
let red = sections()
.iter()
.filter(|section| section.banner() == Banner::Red)
.count();
assert!(
red * 2 > sections().len(),
"a panel without its red stripes"
);
assert_eq!(Banner::Red.plate().to_rgb(), [0xc8, 0x17, 0x2e]);
}
#[test]
fn every_control_names_a_parameter_the_table_has() {
for section in sections() {
for control in section.controls() {
let parameter = control.parameter();
assert_eq!(ParamId::from_offset(parameter.offset()), Ok(parameter));
assert!(parameter.max() > parameter.min());
}
}
assert!(
sections()
.iter()
.filter(|section| section.group() == Group::Vcf)
.map(super::Section::name)
.eq(["VCF", "HPF"])
);
}
}