#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum PresetKind {
Env,
Vib,
Detune,
Arp,
}
impl PresetKind {
pub const fn command(self) -> &'static str {
match self {
PresetKind::Env => "@env",
PresetKind::Vib => "@vib",
PresetKind::Detune => "@detune",
PresetKind::Arp => "@arp",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct Preset {
pub kind: PresetKind,
pub name: &'static str,
pub body: &'static str,
}
impl Preset {
pub fn definition(&self) -> String {
format!("{} {} = {}", self.kind.command(), self.name, self.body)
}
pub fn select(&self) -> String {
format!("{} {}", self.kind.command(), self.name)
}
}
const fn p(kind: PresetKind, name: &'static str, body: &'static str) -> Preset {
Preset { kind, name, body }
}
pub const PRESETS: &[Preset] = &[
p(PresetKind::Env, "pluck", "15 13 11 9 7 5 4 3 2 1 0"),
p(PresetKind::Env, "piano", "15 14 13 12 * 11:4 / 8:2 5:2 2:2"),
p(PresetKind::Env, "organ", "15 / 12 6"),
p(
PresetKind::Env,
"pad",
"3 6 9 12 15 * 14:6 13:6 14:6 / 10:4 6:4 3:4",
),
p(
PresetKind::Env,
"bell",
"15 12 10 9:2 8:3 7:4 6:6 5:8 4:10 3:12",
),
p(PresetKind::Env, "swell", "2:3 4:3 6:3 8:3 10:3 12:3 15"),
p(PresetKind::Env, "echo", "15 10 6 3 0:4 8 5 3 1 0:4 4 2 1 0"),
p(PresetKind::Vib, "light", "20 55 15"),
p(PresetKind::Vib, "wide", "12 50 40"),
p(PresetKind::Vib, "fast", "0 80 20"),
p(PresetKind::Detune, "chorus", "8"),
p(PresetKind::Detune, "bend", "-100:2 -60:2 -30:2 -10:2 0"),
p(
PresetKind::Detune,
"drop",
"0:6 / -50:2 -150:2 -300:2 -600:2",
),
p(PresetKind::Arp, "major", "* 0:2 4:2 7:2"),
p(PresetKind::Arp, "minor", "* 0:2 3:2 7:2"),
p(PresetKind::Arp, "octave", "* 0:2 12:2"),
p(PresetKind::Arp, "kick", "12 7 3 0"),
];
pub fn of_kind(kind: PresetKind) -> impl Iterator<Item = &'static Preset> {
PRESETS.iter().filter(move |p| p.kind == kind)
}
pub fn find(kind: PresetKind, name: &str) -> Option<&'static Preset> {
PRESETS.iter().find(|p| p.kind == kind && p.name == name)
}