Feat: refactoring by breaking words in multiple files
This commit is contained in:
413
crates/forth/src/words/sequencing.rs
Normal file
413
crates/forth/src/words/sequencing.rs
Normal file
@@ -0,0 +1,413 @@
|
||||
use super::{Word, WordCompile::*};
|
||||
|
||||
// Time, Context, Probability, Generator, Desktop
|
||||
pub(super) const WORDS: &[Word] = &[
|
||||
// Probability
|
||||
Word {
|
||||
name: "rand",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(min max -- n|f)",
|
||||
desc: "Random in range. Int if both args are int, float otherwise",
|
||||
example: "1 6 rand => 4 | 0.0 1.0 rand => 0.42",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "exprand",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(lo hi -- f)",
|
||||
desc: "Exponential random biased toward lo. Both args must be positive",
|
||||
example: "1.0 100.0 exprand => 3.7",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "logrand",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(lo hi -- f)",
|
||||
desc: "Exponential random biased toward hi. Both args must be positive",
|
||||
example: "1.0 100.0 logrand => 87.2",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "seed",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(n --)",
|
||||
desc: "Set random seed",
|
||||
example: "12345 seed",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "coin",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(-- bool)",
|
||||
desc: "50/50 random boolean",
|
||||
example: "coin => 0 or 1",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "chance",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot prob --)",
|
||||
desc: "Execute quotation with probability (0.0-1.0)",
|
||||
example: "{ 2 distort } 0.75 chance",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "prob",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot pct --)",
|
||||
desc: "Execute quotation with probability (0-100)",
|
||||
example: "{ 2 distort } 75 prob",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "choose",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(..n n -- val)",
|
||||
desc: "Random pick from n items",
|
||||
example: "1 2 3 3 choose",
|
||||
compile: Simple,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "cycle",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(v1..vn n -- selected)",
|
||||
desc: "Cycle through n items by step runs",
|
||||
example: "60 64 67 3 cycle",
|
||||
compile: Simple,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "pcycle",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(v1..vn n -- selected)",
|
||||
desc: "Cycle through n items by pattern iteration",
|
||||
example: "60 64 67 3 pcycle",
|
||||
compile: Simple,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "always",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Always execute quotation",
|
||||
example: "{ 2 distort } always",
|
||||
compile: Probability(1.0),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "never",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Never execute quotation",
|
||||
example: "{ 2 distort } never",
|
||||
compile: Probability(0.0),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "often",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 75% of the time",
|
||||
example: "{ 2 distort } often",
|
||||
compile: Probability(0.75),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "sometimes",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 50% of the time",
|
||||
example: "{ 2 distort } sometimes",
|
||||
compile: Probability(0.5),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "rarely",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 25% of the time",
|
||||
example: "{ 2 distort } rarely",
|
||||
compile: Probability(0.25),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "almostNever",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 10% of the time",
|
||||
example: "{ 2 distort } almostNever",
|
||||
compile: Probability(0.1),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "almostAlways",
|
||||
aliases: &[],
|
||||
category: "Probability",
|
||||
stack: "(quot --)",
|
||||
desc: "Execute quotation 90% of the time",
|
||||
example: "{ 2 distort } almostAlways",
|
||||
compile: Probability(0.9),
|
||||
varargs: false,
|
||||
},
|
||||
// Time
|
||||
Word {
|
||||
name: "every",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(n -- bool)",
|
||||
desc: "True every nth iteration",
|
||||
example: "4 every",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "loop",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(n --)",
|
||||
desc: "Fit sample to n beats",
|
||||
example: "\"break\" s 4 loop @",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "tempo!",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(bpm --)",
|
||||
desc: "Set global tempo",
|
||||
example: "140 tempo!",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "speed!",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(multiplier --)",
|
||||
desc: "Set pattern speed multiplier",
|
||||
example: "2.0 speed!",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "chain",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(bank pattern --)",
|
||||
desc: "Chain to bank/pattern (1-indexed) when current pattern ends",
|
||||
example: "1 4 chain",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "at",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(v1..vn --)",
|
||||
desc: "Set delta context for emit timing",
|
||||
example: "0 0.5 at kick s . => emits at 0 and 0.5 of step",
|
||||
compile: Simple,
|
||||
varargs: true,
|
||||
},
|
||||
// Context
|
||||
Word {
|
||||
name: "step",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- n)",
|
||||
desc: "Current step index",
|
||||
example: "step => 0",
|
||||
compile: Context("step"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "beat",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- f)",
|
||||
desc: "Current beat position",
|
||||
example: "beat => 4.5",
|
||||
compile: Context("beat"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "pattern",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- n)",
|
||||
desc: "Current pattern index",
|
||||
example: "pattern => 0",
|
||||
compile: Context("pattern"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "pbank",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- n)",
|
||||
desc: "Current pattern's bank index",
|
||||
example: "pbank => 0",
|
||||
compile: Context("bank"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "tempo",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- f)",
|
||||
desc: "Current BPM",
|
||||
example: "tempo => 120.0",
|
||||
compile: Context("tempo"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "phase",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- f)",
|
||||
desc: "Phase in bar (0-1)",
|
||||
example: "phase => 0.25",
|
||||
compile: Context("phase"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "slot",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- n)",
|
||||
desc: "Current slot number",
|
||||
example: "slot => 0",
|
||||
compile: Context("slot"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "runs",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- n)",
|
||||
desc: "Times this step ran",
|
||||
example: "runs => 3",
|
||||
compile: Context("runs"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "iter",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- n)",
|
||||
desc: "Pattern iteration count",
|
||||
example: "iter => 2",
|
||||
compile: Context("iter"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "stepdur",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- f)",
|
||||
desc: "Step duration in seconds",
|
||||
example: "stepdur => 0.125",
|
||||
compile: Context("stepdur"),
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "fill",
|
||||
aliases: &[],
|
||||
category: "Context",
|
||||
stack: "(-- bool)",
|
||||
desc: "True when fill is on (f key)",
|
||||
example: "\"snare\" s . fill ?",
|
||||
compile: Context("fill"),
|
||||
varargs: false,
|
||||
},
|
||||
// Desktop
|
||||
#[cfg(feature = "desktop")]
|
||||
Word {
|
||||
name: "mx",
|
||||
aliases: &[],
|
||||
category: "Desktop",
|
||||
stack: "(-- x)",
|
||||
desc: "Normalized mouse X position (0-1)",
|
||||
example: "mx 440 880 range freq",
|
||||
compile: Context("mx"),
|
||||
varargs: false,
|
||||
},
|
||||
#[cfg(feature = "desktop")]
|
||||
Word {
|
||||
name: "my",
|
||||
aliases: &[],
|
||||
category: "Desktop",
|
||||
stack: "(-- y)",
|
||||
desc: "Normalized mouse Y position (0-1)",
|
||||
example: "my 0.1 0.9 range gain",
|
||||
compile: Context("my"),
|
||||
varargs: false,
|
||||
},
|
||||
#[cfg(feature = "desktop")]
|
||||
Word {
|
||||
name: "mdown",
|
||||
aliases: &[],
|
||||
category: "Desktop",
|
||||
stack: "(-- bool)",
|
||||
desc: "1 when mouse button held, 0 otherwise",
|
||||
example: "mdown { \"crash\" s . } ?",
|
||||
compile: Context("mdown"),
|
||||
varargs: false,
|
||||
},
|
||||
// Generator
|
||||
Word {
|
||||
name: "..",
|
||||
aliases: &[],
|
||||
category: "Generator",
|
||||
stack: "(start end -- start start+1 ... end)",
|
||||
desc: "Push arithmetic sequence from start to end",
|
||||
example: "1 4 .. => 1 2 3 4",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "gen",
|
||||
aliases: &[],
|
||||
category: "Generator",
|
||||
stack: "(quot n -- results...)",
|
||||
desc: "Execute quotation n times, push all results",
|
||||
example: "{ 1 6 rand } 4 gen => 4 random values",
|
||||
compile: Simple,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "geom..",
|
||||
aliases: &[],
|
||||
category: "Generator",
|
||||
stack: "(start ratio count -- start start*r start*r^2 ...)",
|
||||
desc: "Push geometric sequence",
|
||||
example: "1 2 4 geom.. => 1 2 4 8",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user