From db44f9b98ef1ccfeae59a0138ac4edb6716069c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Forment?=
Date: Sun, 1 Mar 2026 19:09:52 +0100
Subject: [PATCH] Feat: documentation, UI/UX
---
crates/forth/README.md | 22 ++
crates/forth/src/ops.rs | 1 +
crates/forth/src/vm.rs | 39 ++-
crates/forth/src/words/compile.rs | 1 +
crates/forth/src/words/core.rs | 10 +
crates/markdown/README.md | 15 ++
crates/project/README.md | 22 ++
crates/ratatui/README.md | 25 ++
docs/forth/about_forth.md | 24 +-
docs/forth/brackets.md | 108 ++++++++
docs/forth/control_flow.md | 185 +++++++-------
docs/forth/cycling.md | 92 +++++++
docs/forth/definitions.md | 3 +-
docs/forth/oddities.md | 39 +--
docs/forth/stack.md | 2 +-
docs/getting-started/banks_patterns.md | 10 +-
docs/getting-started/big_picture.md | 25 +-
docs/getting-started/editing.md | 35 +--
docs/getting-started/engine.md | 50 ++--
docs/getting-started/grid.md | 98 +++----
docs/getting-started/navigation.md | 64 ++---
docs/getting-started/options.md | 37 +--
docs/getting-started/samples.md | 14 +-
docs/getting-started/saving.md | 12 -
docs/getting-started/staging.md | 22 +-
docs/tutorials/periodic_script.md | 43 ++++
docs/tutorials/randomness.md | 45 +---
docs/welcome.md | 16 +-
src/README.md | 26 ++
src/app/dispatch.rs | 9 -
src/app/scripting.rs | 20 +-
src/commands.rs | 2 -
src/engine/audio.rs | 2 +-
src/engine/sequencer.rs | 54 +++-
src/input/help_page.rs | 14 +-
src/input/main_page.rs | 2 +-
src/input/mod.rs | 7 +-
src/input/modal.rs | 8 +-
src/input/script_page.rs | 3 -
src/main.rs | 13 +-
src/model/docs.rs | 6 +
src/model/script.rs | 6 +-
src/page.rs | 5 -
src/services/help_nav.rs | 2 +
src/services/mod.rs | 1 -
src/services/stack_preview.rs | 102 --------
src/state/editor.rs | 17 +-
src/state/mod.rs | 2 +-
src/state/ui.rs | 2 +
src/views/help_view.rs | 29 ++-
src/views/main_view.rs | 23 ++
src/views/render.rs | 35 +--
src/views/script_view.rs | 22 --
website/public/docs.css | 305 ++++++++++++++++++++++
website/public/docs.js | 27 ++
website/src/pages/docs.astro | 338 +++++++++++++++++++++++++
website/src/pages/index.astro | 5 +-
57 files changed, 1531 insertions(+), 615 deletions(-)
create mode 100644 crates/forth/README.md
create mode 100644 crates/markdown/README.md
create mode 100644 crates/project/README.md
create mode 100644 crates/ratatui/README.md
create mode 100644 docs/forth/brackets.md
create mode 100644 docs/forth/cycling.md
create mode 100644 docs/tutorials/periodic_script.md
create mode 100644 src/README.md
delete mode 100644 src/services/stack_preview.rs
create mode 100644 website/public/docs.css
create mode 100644 website/public/docs.js
create mode 100644 website/src/pages/docs.astro
diff --git a/crates/forth/README.md b/crates/forth/README.md
new file mode 100644
index 0000000..63ce6b8
--- /dev/null
+++ b/crates/forth/README.md
@@ -0,0 +1,22 @@
+# cagire-forth
+
+Stack-based Forth VM for the Cagire sequencer. Tokenizes, compiles, and executes step scripts to produce audio and MIDI commands.
+
+## Modules
+
+| Module | Description |
+|--------|-------------|
+| `vm` | Interpreter loop, `Forth::evaluate()` entry point |
+| `compiler` | Tokenization (with source spans) and single-pass compilation to ops |
+| `ops` | `Op` enum (~90 variants) |
+| `types` | `Value`, `StepContext`, shared state types |
+| `words/` | Built-in word definitions: `core`, `sound`, `music`, `midi`, `effects`, `sequencing`, `compile` |
+| `theory/` | Music theory lookups: `scales` (~200 patterns), `chords` (interval arrays) |
+
+## Key Types
+
+- **`Forth`** — VM instance, holds stacks and compilation state
+- **`Value`** — Stack value (int, float, string, list, quotation, ...)
+- **`StepContext`** — Per-step evaluation context (step index, tempo, variables, ...)
+- **`Op`** — Compiled operation; nondeterministic variants carry `Option` for tracing
+- **`ExecutionTrace`** — Records executed/selected spans and resolved values during evaluation
diff --git a/crates/forth/src/ops.rs b/crates/forth/src/ops.rs
index 7439dcf..b2e9ca5 100644
--- a/crates/forth/src/ops.rs
+++ b/crates/forth/src/ops.rs
@@ -65,6 +65,7 @@ pub enum Op {
NewCmd,
SetParam(&'static str),
Emit,
+ Print,
Get,
Set,
SetKeep,
diff --git a/crates/forth/src/vm.rs b/crates/forth/src/vm.rs
index 4a4ed02..2e5a0f1 100644
--- a/crates/forth/src/vm.rs
+++ b/crates/forth/src/vm.rs
@@ -328,6 +328,16 @@ impl Forth {
Op::Drop => {
pop(stack)?;
}
+ Op::Print => {
+ let val = pop(stack)?;
+ let text = match &val {
+ Value::Int(n, _) => n.to_string(),
+ Value::Float(f, _) => format!("{f}"),
+ Value::Str(s, _) => s.to_string(),
+ _ => format!("{val:?}"),
+ };
+ outputs.push(format!("print:{text}"));
+ }
Op::Swap => {
ensure(stack, 2)?;
let len = stack.len();
@@ -558,9 +568,12 @@ impl Forth {
Op::NewCmd => {
ensure(stack, 1)?;
- let values = std::mem::take(stack);
+ let values = drain_skip_quotations(stack);
+ if values.is_empty() {
+ return Err("expected sound name".into());
+ }
let val = if values.len() == 1 {
- values.into_iter().next().expect("single value after len check")
+ values.into_iter().next().unwrap()
} else {
Value::CycleList(Arc::from(values))
};
@@ -568,9 +581,12 @@ impl Forth {
}
Op::SetParam(param) => {
ensure(stack, 1)?;
- let values = std::mem::take(stack);
+ let values = drain_skip_quotations(stack);
+ if values.is_empty() {
+ return Err("expected parameter value".into());
+ }
let val = if values.len() == 1 {
- values.into_iter().next().expect("single value after len check")
+ values.into_iter().next().unwrap()
} else {
Value::CycleList(Arc::from(values))
};
@@ -1866,6 +1882,21 @@ fn pop_bool(stack: &mut Vec) -> Result {
Ok(pop(stack)?.is_truthy())
}
+/// Drain the stack, returning non-quotation values.
+/// Quotations are pushed back onto the stack (transparent).
+fn drain_skip_quotations(stack: &mut Vec) -> Vec {
+ let values = std::mem::take(stack);
+ let mut result = Vec::new();
+ for v in values {
+ if matches!(v, Value::Quotation(..)) {
+ stack.push(v);
+ } else {
+ result.push(v);
+ }
+ }
+ result
+}
+
fn ensure(stack: &[Value], n: usize) -> Result<(), String> {
if stack.len() < n {
return Err("stack underflow".into());
diff --git a/crates/forth/src/words/compile.rs b/crates/forth/src/words/compile.rs
index 8ee55fa..5289b46 100644
--- a/crates/forth/src/words/compile.rs
+++ b/crates/forth/src/words/compile.rs
@@ -13,6 +13,7 @@ pub(super) fn simple_op(name: &str) -> Option {
"dup" => Op::Dup,
"dupn" => Op::Dupn,
"drop" => Op::Drop,
+ "print" => Op::Print,
"swap" => Op::Swap,
"over" => Op::Over,
"rot" => Op::Rot,
diff --git a/crates/forth/src/words/core.rs b/crates/forth/src/words/core.rs
index 452230c..ecef63d 100644
--- a/crates/forth/src/words/core.rs
+++ b/crates/forth/src/words/core.rs
@@ -33,6 +33,16 @@ pub(super) const WORDS: &[Word] = &[
compile: Simple,
varargs: false,
},
+ Word {
+ name: "print",
+ aliases: &[],
+ category: "Stack",
+ stack: "(x --)",
+ desc: "Print top of stack to footer bar",
+ example: "42 print",
+ compile: Simple,
+ varargs: false,
+ },
Word {
name: "swap",
aliases: &[],
diff --git a/crates/markdown/README.md b/crates/markdown/README.md
new file mode 100644
index 0000000..17cb29f
--- /dev/null
+++ b/crates/markdown/README.md
@@ -0,0 +1,15 @@
+# cagire-markdown
+
+Markdown parser and renderer that produces ratatui-styled lines. Used for the built-in help/documentation views.
+
+## Modules
+
+| Module | Description |
+|--------|-------------|
+| `parser` | Markdown-to-styled-lines conversion |
+| `highlighter` | `CodeHighlighter` trait for syntax highlighting in fenced code blocks |
+| `theme` | Color mappings for markdown elements |
+
+## Key Trait
+
+- **`CodeHighlighter`** — Implement to provide language-specific syntax highlighting. Returns `Vec<(Style, String)>` per line.
diff --git a/crates/project/README.md b/crates/project/README.md
new file mode 100644
index 0000000..5ff8b55
--- /dev/null
+++ b/crates/project/README.md
@@ -0,0 +1,22 @@
+# cagire-project
+
+Project data model and persistence for Cagire.
+
+## Modules
+
+| Module | Description |
+|--------|-------------|
+| `project` | `Project`, `Bank`, `Pattern`, `Step` structs and constants |
+| `file` | File I/O (save/load) |
+| `share` | Project sharing/export |
+
+## Key Types
+
+- **`Project`** — Top-level container: banks of patterns
+- **`Bank`** — Collection of patterns
+- **`Pattern`** — Sequence of steps with metadata
+- **`Step`** — Single step holding a Forth script
+
+## Constants
+
+`MAX_BANKS=32`, `MAX_PATTERNS=32`, `MAX_STEPS=1024`
diff --git a/crates/ratatui/README.md b/crates/ratatui/README.md
new file mode 100644
index 0000000..da89145
--- /dev/null
+++ b/crates/ratatui/README.md
@@ -0,0 +1,25 @@
+# cagire-ratatui
+
+TUI widget library and theme system for Cagire.
+
+## Widgets
+
+`category_list`, `confirm`, `editor`, `file_browser`, `hint_bar`, `lissajous`, `list_select`, `modal`, `nav_minimap`, `props_form`, `sample_browser`, `scope`, `scroll_indicators`, `search_bar`, `section_header`, `sparkles`, `spectrum`, `text_input`, `vu_meter`, `waveform`
+
+## Theme System
+
+The `theme/` module provides a palette-based theming system using Oklab color space.
+
+| Module | Description |
+|--------|-------------|
+| `mod` | `THEMES` array, `CURRENT_THEME` thread-local, `get()`/`set()` |
+| `palette` | `Palette` (14 fields), color manipulation helpers (`shift`, `mix`, `tint_bg`, ...) |
+| `build` | Derives ~190 `ThemeColors` fields from a `Palette` |
+| `transform` | HSV-based hue rotation for generated palettes |
+
+25 built-in themes.
+
+## Key Types
+
+- **`Palette`** — 14-field color definition, input to theme generation
+- **`ThemeColors`** — ~190 derived semantic colors used throughout the UI
diff --git a/docs/forth/about_forth.md b/docs/forth/about_forth.md
index c42322b..53a1635 100644
--- a/docs/forth/about_forth.md
+++ b/docs/forth/about_forth.md
@@ -1,13 +1,15 @@
# About Forth
-Forth is a _stack-based_ programming language created by Charles H. Moore in the early 1970s. It was designed with simplicity, directness, and interactive exploration in mind. Forth has been used for scientific work and embedded systems: it controlled telescopes and even ran on hardware aboard space missions. It evolved into many implementations targeting various architectures, but none of them really caught on. Nonetheless, the ideas behind Forth continue to attract people from very different, often unrelated fields. Today, Forth languages are used by hackers and artists for their unconventional nature. Forth is simple, direct, and beautiful to implement. Forth is an elegant, minimal language, easy to understand, extend, and tailor to a specific task. The Forth we use in Cagire is specialized in making live music. It is used as a DSL: a _Domain Specific Language_.
+Forth is a _stack-based_ programming language created by Charles H. Moore in the early 1970s. It was designed with simplicity, directness, and interactive exploration in mind. Forth has been used for scientific work and embedded systems: it controlled telescopes and even ran on hardware aboard space missions. It evolved into many implementations targeting various architectures, but none of them really caught on. Nonetheless, the ideas behind Forth continue to attract people from very different, often unrelated fields. Today, Forth languages are used by hackers and artists for their unconventional nature. Forth is simple, direct, and beautiful to implement. Forth is an elegant, minimal language, easy to understand, extend, and tailor to a specific task. The Forth we use in Cagire is specialized in making live music. It is used as a DSL: a _Domain Specific Language_.
+
+**TLDR:** Forth is a really nice language to play music with.
## Why Forth?
Most programming languages rely on a complex syntax of `variables`, `expressions` and `statements` like `x = 3 + 4` or `do_something(()=>bob(4))`. Forth works differently. It has almost no syntax at all. Instead, you push values onto a `stack` and apply `words` that transform them:
```forth
-3 4 +
+3 4 + print
```
The program above leaves the number `7` on the stack. There are no variables, no parentheses, no syntax to remember. You just end up with words and numbers separated by spaces. For live coding music, this directness is quite exciting. All you do is think in terms of transformations and add things to the stack: take a note, shift it up, add reverb, play it.
@@ -20,6 +22,7 @@ The stack is where values live. When you type a number, it goes on the stack. Wh
3 ;; stack: 3
4 ;; stack: 3 4
+ ;; stack: 7
+print
```
The stack is `last-in, first-out`. The most recent value is always on top. This means that it's often better to read Forth programs from right to left, bottom to top.
@@ -38,7 +41,7 @@ Words compose naturally on the stack. To double a number:
```forth
;; 3 3 +
-3 dup +
+3 dup + print
```
Forth has a large vocabulary, so Cagire includes a `Dictionary` directly in the application. You can also create your own words. They will work just like existing words. The only difference is that these words will not be included in the dictionary. There are good reasons to create new words on-the-fly:
@@ -58,13 +61,22 @@ Four basic types of values can live on the stack:
Floats can omit the leading zero: `.25` is the same as `0.25`, and `-.5` is `-0.5`.
-Parentheses are ignored by the parser. You can use them freely for visual grouping without affecting execution:
+Parentheses are used to "quote" a section of a program. The code inside does not run immediately — it is pushed onto the stack as a value. A quotation only runs when a consuming word decides to execute it. This is how conditionals and loops work:
```forth
-(c4 note) (0.5 gain) "sine" s .
+( 60 note 0.3 verb ) 1 ?
```
-Quotations are special. They let you pass code around as a value. This is how conditionals and loops work. Don't worry about them for now — you'll learn how to use them later.
+Here `?` pops the quotation and the condition. The code inside runs only when the condition is truthy. Words like `?`, `!?`, `times`, `cycle`, `choose`, `ifelse`, `every`, `chance`, and `apply` all consume quotations this way.
+
+Because parentheses defer execution, wrapping code in `( ... )` without a consuming word means it never runs. Quotations are transparent to sound and parameter words — they stay on the stack untouched. This is a useful trick for temporarily disabling part of a step:
+
+```forth
+( 0.5 gain ) ;; this quotation is ignored
+"kick" sound
+0.3 decay
+.
+```
Any word that is not recognized as a built-in or a user definition becomes a string on the stack. This means `kick s` and `"kick" s` are equivalent. You only need quotes when the string contains spaces or when it conflicts with an existing word name.
diff --git a/docs/forth/brackets.md b/docs/forth/brackets.md
new file mode 100644
index 0000000..286a8d7
--- /dev/null
+++ b/docs/forth/brackets.md
@@ -0,0 +1,108 @@
+# Brackets
+
+Cagire uses three bracket forms. Each one behaves differently.
+
+## ( ... ) — Quotations
+
+Parentheses create quotations: deferred code. The contents are not executed immediately — they are pushed onto the stack as a single value.
+
+```forth
+( dup + )
+```
+
+This pushes a block of code. You can store it in a variable, pass it to other words, or execute it later. Quotations are what make Cagire's control flow work.
+
+### Words that consume quotations
+
+Many built-in words expect a quotation on the stack:
+
+| Word | Effect |
+|------|--------|
+| `?` | Execute if condition is truthy |
+| `!?` | Execute if condition is falsy |
+| `ifelse` | Choose between two quotations |
+| `select` | Pick the nth quotation from a list |
+| `apply` | Execute unconditionally |
+| `times` | Loop n times |
+| `cycle` / `pcycle` | Rotate through quotations |
+| `choose` | Pick one at random |
+| `every` | Execute on every nth iteration |
+| `chance` / `prob` | Execute with probability |
+| `bjork` / `pbjork` | Euclidean rhythm gate |
+
+When a word like `cycle` or `choose` selects a quotation, it executes it. When it selects a plain value, it pushes it.
+
+### Nesting
+
+Quotations nest freely:
+
+```forth
+( ( c4 note ) ( e4 note ) coin ifelse ) 4 every
+```
+
+The outer quotation runs every 4th iteration. Inside, a coin flip picks the note.
+
+### The mute trick
+
+Wrapping code in a quotation without consuming it is a quick way to disable it:
+
+```forth
+( kick s . )
+```
+
+Nothing will execute this quotation — it just sits on the stack and gets discarded. Useful for temporarily silencing a line while editing.
+
+## [ ... ] — Square Brackets
+
+Square brackets execute their contents immediately, then push a count of how many values were produced. The values themselves stay on the stack.
+
+```forth
+[ 60 64 67 ]
+```
+
+After this runs, the stack holds `60 64 67 3` — three values plus the count `3`. This is useful with words that need to know how many items precede them:
+
+```forth
+[ 60 64 67 ] cycle note sine s .
+```
+
+The `cycle` word reads the count to know how many values to rotate through. Without brackets you would write `60 64 67 3 cycle` — the brackets save you from counting manually.
+
+Square brackets work with any word that takes a count:
+
+```forth
+[ c4 e4 g4 ] choose note saw s . ;; random note from the list
+[ 60 64 67 ] note sine s . ;; 3-note chord (note consumes all)
+```
+
+### Nesting
+
+Square brackets can nest. Each pair produces its own count:
+
+```forth
+[ [ 60 64 67 ] cycle [ 0.3 0.5 0.8 ] cycle ] choose
+```
+
+### Expressions inside brackets
+
+The contents are compiled and executed normally, so you can use any Forth code:
+
+```forth
+[ c4 c4 3 + c4 7 + ] note sine s . ;; root, minor third, fifth
+```
+
+## { ... } — Curly Braces
+
+Curly braces are ignored by the compiler. They do nothing. Use them as a visual aid to group related code:
+
+```forth
+{ kick s } { 0.5 gain } { 0.3 verb } .
+```
+
+This compiles to exactly the same thing as:
+
+```forth
+kick s 0.5 gain 0.3 verb .
+```
+
+They can help readability in dense one-liners but have no semantic meaning.
diff --git a/docs/forth/control_flow.md b/docs/forth/control_flow.md
index 5733df9..c14c6bb 100644
--- a/docs/forth/control_flow.md
+++ b/docs/forth/control_flow.md
@@ -1,140 +1,143 @@
# Control Flow
-Sometimes a step should behave differently depending on context — a coin flip, a fill, which iteration of the pattern is playing. Control flow words let you branch, choose, and repeat inside a step's script. Control structures are essential for programming and allow you to create complex and dynamic patterns.
+Control flow in Cagire's Forth comes in two families. The first is compiled syntax — `if/then` and `case` — which the compiler handles directly as branch instructions. The second is quotation words — `?`, `!?`, `ifelse`, `select`, `apply` — which pop `( ... )` quotations from the stack and decide whether to run them. Probability and periodic execution (`chance`, `every`, `bjork`) are covered in the Randomness tutorial.
-## if / else / then
+## Branching with if / else / then
-The simplest branch. Push a condition, then `if`:
+Push a condition, then `if`. Everything between `if` and `then` runs only when the condition is truthy:
```forth
-coin if 0.8 gain then
-saw s c4 note .
+;; degrade sound if true
+coin if
+ 7 crush
+then
+sine sound
+c4 note
+1 decay
+.
```
-The gain is applied if the coin flip is true. The sound will always plays. Add `else` for a two-way split:
+The crush is applied on half the hits. The sound always plays. Add `else` for a two-way split:
```forth
coin if
- c4 note
+ c5 note
else
c3 note
then
-saw s 0.6 gain .
+saw sound
+0.3 verb
+0.5 decay
+0.6 gain
+.
```
-These are compiled directly into branch instructions. For that reason, these words will not appear in the dictionary.
+These are compiled directly into branch instructions — they will not appear in the dictionary. This is a "low level" way to use conditionals in Cagire.
-## ? and !?
-
-When you already have a quotation, `?` executes it if the condition is truthy:
-
-```forth
-( 0.4 verb ) coin ?
-saw s c4 note 0.5 gain . ;; reverb on half the hits
-```
-
-`!?` is the opposite — executes when falsy:
-
-```forth
-( 0.2 gain ) coin !?
-saw s c4 note . ;; quiet on half the hits
-```
-
-These pair well with `chance`, `prob`, and the other probability words:
-
-```forth
-( 0.5 verb ) 0.3 chance ? ;; occasional reverb wash
-( 12 + ) fill ? ;; octave up during fills
-```
-
-## ifelse
-
-Two quotations, one condition. The true branch comes first:
-
-```forth
-( c3 note ) ( c4 note ) coin ifelse
-saw s 0.6 gain . ;; bass or lead, coin flip
-```
-
-Reads naturally: "c3 or c4, depending on the coin."
-
-```forth
-( 0.8 gain ) ( 0.3 gain ) fill ifelse
-tri s c4 note 0.2 decay . ;; loud during fills, quiet otherwise
-```
-
-## select
-
-Choose the nth option from a list of quotations:
-
-```forth
-( c4 ) ( e4 ) ( g4 ) ( b4 ) iter 4 mod select
-note sine s 0.5 decay .
-```
-
-Four notes cycling through a major seventh chord, one per pattern iteration. The index is 0-based.
-
-## apply
-
-When you have a quotation and want to execute it unconditionally, use `apply`:
-
-```forth
-( dup + ) apply ;; doubles the top value
-```
-
-This is simpler than `?` when there is no condition to check. It pops the quotation and runs it.
-
-## case / of / endof / endcase
+## Matching with case
For matching a value against several options. Cleaner than a chain of `if`s when you have more than two branches:
```forth
-iter 4 mod case
+1 8 rand 4 mod case
0 of c3 note endof
1 of e3 note endof
2 of g3 note endof
3 of a3 note endof
endcase
-saw s 0.6 gain 800 lpf .
+tri s
+2 fm 0.99 fmh
+0.6 gain 0.2 chorus
+1 decay
+800 lpf
+.
```
-A different root note each time the pattern loops.
-
-The last line before `endcase` is the default — it runs when no `of` matched:
+A different root note each time the pattern loops. The last line before `endcase` is the default — it runs when no `of` matched:
```forth
iter 3 mod case
0 of 0.9 gain endof
- 0.4 gain ;; default: quieter
+ 0.4 gain
endcase
-saw s c4 note .
+saw s
+.5 decay
+c4 note
+.
```
-## times
+Like `if/then`, `case` is compiled syntax and does not appear in the dictionary.
-Repeat a quotation n times. The variable `@i` is automatically set to the current iteration index (starting from 0):
+## Quotation Words
+
+The remaining control flow words operate on quotations — `( ... )` blocks sitting on the stack. Each word pops one or more quotations and decides whether or how to execute them.
+
+### ? and !?
+
+`?` executes a quotation if the condition is truthy:
```forth
-3 ( c4 @i 4 * + note ) times
-sine s 0.4 gain 0.5 verb . ;; c4, e4, g#4 — a chord
+( 0.4 verb 6 crush ) coin ?
+tri sound 2 fm 0.5 fmh
+c3 note 0.5 gain 2 decay
+.
```
-Subdivide with `at`:
+Reverb on half the hits. `!?` is the opposite — executes when falsy:
```forth
-4 ( @i 4 / at sine s c4 note 0.3 gain . ) times
+( 0.5 delay 0.9 delayfeedback ) coin !?
+saw sound
+c4 note
+500 lpf
+0.5 decay
+0.5 gain
+.
```
-Four evenly spaced notes within the step.
+Quiet on half the hits. These pair well with `chance` and `fill` from the Randomness tutorial.
-Vary intensity per iteration:
+### ifelse
+
+Two quotations, one condition. The true branch comes first:
```forth
-8 (
- @i 8 / at
- @i 4 mod 0 = if 0.7 else 0.2 then gain
- tri s c5 note 0.1 decay .
-) times
+( c3 note ) ( c5 note ) coin ifelse
+saw sound 0.3 verb
+0.5 decay 0.6 gain
+.
```
-Eight notes per step. Every fourth one louder.
+Reads naturally: "c3 or c5, depending on the coin."
+
+```forth
+( 0.8 gain ) ( 0.3 gain ) fill ifelse
+tri s c4 note 0.2 decay .
+```
+
+Loud during fills, quiet otherwise.
+
+### select
+
+Choose the nth quotation from a list. The index is 0-based:
+
+```forth
+( c4 ) ( e4 ) ( g4 ) ( b4 ) 0 3 rand select
+note sine s 0.5 decay .
+```
+
+Four notes of a major seventh chord picked randomly. Note that this is unnecessarily complex :)
+
+### apply
+
+When you have a quotation and want to execute it unconditionally:
+
+```forth
+( dup + ) apply
+```
+
+Pops the quotation and runs it. Simpler than `?` when there is no condition to check.
+
+## More!
+
+For probability gates, periodic execution, and euclidean rhythms, see the Randomness tutorial. For generators and ranges, see the Generators tutorial.
diff --git a/docs/forth/cycling.md b/docs/forth/cycling.md
new file mode 100644
index 0000000..cb1278e
--- /dev/null
+++ b/docs/forth/cycling.md
@@ -0,0 +1,92 @@
+# Cycling & Selection
+
+These words all share a pattern: push values onto the stack, then select one. If the selected item is a quotation, it gets executed. If it is a plain value, it gets pushed. All of them support `[ ]` brackets for auto-counting.
+
+## cycle / pcycle
+
+Sequential rotation through values.
+
+`cycle` advances based on `runs` — how many times this particular step has played:
+
+```forth
+60 64 67 3 cycle note sine s . ;; 60, 64, 67, 60, 64, 67, ...
+```
+
+`pcycle` advances based on `iter` — the pattern iteration count:
+
+```forth
+kick snare 2 pcycle s . ;; kick on even iterations, snare on odd
+```
+
+The distinction matters when patterns have different lengths or when multiple steps share the same script. `cycle` gives each step its own independent counter. `pcycle` ties all steps to the same global pattern position.
+
+## bounce / pbounce
+
+Ping-pong instead of wrapping. With 4 values the sequence is 0, 1, 2, 3, 2, 1, 0, 1, 2, ...
+
+```forth
+60 64 67 72 4 bounce note sine s . ;; ping-pong by step runs
+60 64 67 72 4 pbounce note sine s . ;; ping-pong by pattern iteration
+```
+
+Same `runs` vs `iter` split as `cycle` / `pcycle`.
+
+## choose
+
+Uniform random selection:
+
+```forth
+kick snare hat 3 choose s . ;; random drum hit each time
+```
+
+Unlike the cycling words, `choose` is nondeterministic — every evaluation picks independently.
+
+## wchoose
+
+Weighted random. Push value/weight pairs, then the count:
+
+```forth
+kick 0.5 snare 0.3 hat 0.2 3 wchoose s .
+```
+
+Kick plays 50% of the time, snare 30%, hat 20%. Weights are normalized automatically — they don't need to sum to 1.
+
+## index
+
+Direct lookup by an explicit index. The index wraps with modulo, so it never goes out of bounds. Negative indices count from the end:
+
+```forth
+[ c4 e4 g4 ] step index note sine s . ;; step number picks the note
+[ c4 e4 g4 ] iter index note sine s . ;; pattern iteration picks the note
+```
+
+This is useful when you want full control over which value is selected, driven by any expression you like.
+
+## Using with brackets
+
+All these words take a count argument `n`. Square brackets compute that count for you:
+
+```forth
+[ 60 64 67 ] cycle note sine s . ;; no need to write "3"
+[ kick snare hat ] choose s .
+[ c4 e4 g4 b4 ] bounce note sine s .
+```
+
+Without brackets: `60 64 67 3 cycle`. With brackets: `[ 60 64 67 ] cycle`. Same result, less counting.
+
+## Quotations
+
+When any of these words selects a quotation, it executes it instead of pushing it:
+
+```forth
+[ ( c4 note ) ( e4 note ) ( g4 note ) ] cycle
+sine s .
+```
+
+On the first run the quotation `( c4 note )` executes, setting the note to C4. Next run, E4. Then G4. Then back to C4.
+
+This works with all selection words. Mix plain values and quotations freely:
+
+```forth
+[ ( hat s 0.3 gain . ) ( snare s . ) ( kick s . ) ] choose
+```
diff --git a/docs/forth/definitions.md b/docs/forth/definitions.md
index a9090e1..15a637e 100644
--- a/docs/forth/definitions.md
+++ b/docs/forth/definitions.md
@@ -13,8 +13,7 @@ Use `:` to start a definition and `;` to end it:
This creates a word called `double` that duplicates the top value and adds it to itself. Now you can use it:
```forth
-3 double ;; leaves 6 on the stack
-5 double ;; leaves 10 on the stack
+3 double print ;; leaves 6 on the stack
```
The definition is simple: everything between `:` and `;` becomes the body of the word.
diff --git a/docs/forth/oddities.md b/docs/forth/oddities.md
index 34f13d2..07ff45c 100644
--- a/docs/forth/oddities.md
+++ b/docs/forth/oddities.md
@@ -10,7 +10,7 @@ Classic Forth uses parentheses for comments:
( this is a comment )
```
-Cagire uses double semicolons:
+In Cagire, parentheses create quotations, so comments use double semicolons instead:
```forth
;; this is a comment
@@ -18,18 +18,6 @@ Cagire uses double semicolons:
Everything after `;;` until the end of the line is ignored.
-## Quotations
-
-Classic Forth has no quotations. Code is not a value you can pass around.
-
-Cagire has first-class quotations using parentheses:
-
-```forth
-( dup + )
-```
-
-This pushes a block of code onto the stack. You can store it, pass it to other words, and execute it later. Quotations enable conditionals, probability, and cycling.
-
## Conditionals
Classic Forth uses `IF ... ELSE ... THEN`:
@@ -190,31 +178,6 @@ Execute a quotation on specific iterations:
`bjork` and `pbjork` use Bjorklund's algorithm to distribute k hits as evenly as possible across n positions. `bjork` counts by step runs, `pbjork` counts by pattern iterations. Classic Euclidean rhythms: tresillo (3,8), cinquillo (5,8), son clave (5,16).
-## Cycling
-
-Cagire has built-in support for cycling through values. Push values onto the stack, then select one based on pattern state:
-
-```forth
-60 64 67 3 cycle note
-```
-
-Each time the step runs, a different note is selected. The `3` tells `cycle` how many values to pick from.
-
-You can also use quotations if you need to execute code:
-
-```forth
-( c4 note ) ( e4 note ) ( g4 note ) 3 cycle
-```
-
-When the selected value is a quotation, it gets executed. When it is a plain value, it gets pushed onto the stack.
-
-Two cycling words exist:
-
-- `cycle` - selects based on `runs` (how many times this step has played)
-- `pcycle` - selects based on `iter` (how many times the pattern has looped)
-
-The difference between `cycle` and `pcycle` matters when patterns have different lengths. `cycle` counts per-step, `pcycle` counts per-pattern.
-
## Polyphonic Parameters
Parameter words like `note`, `freq`, and `gain` consume the entire stack. If you push multiple values before a param word, you get polyphony:
diff --git a/docs/forth/stack.md b/docs/forth/stack.md
index 296d6aa..ee1dd4b 100644
--- a/docs/forth/stack.md
+++ b/docs/forth/stack.md
@@ -89,7 +89,7 @@ The fix is simple: make sure you push enough values before calling a word. Check
* **Leftover values** are the opposite problem: values remain on the stack after your script finishes. This is less critical but indicates sloppy code. If your script leaves unused values behind, you probably made a mistake somewhere.
```forth
-3 4 5 + . ;; plays a sound, but 3 is still on the stack
+3 4 5 + ;; 3 is still on the stack, unconsumed
```
The `3` was never used. Either it should not be there, or you forgot a word that consumes it.
diff --git a/docs/getting-started/banks_patterns.md b/docs/getting-started/banks_patterns.md
index 048a563..156358c 100644
--- a/docs/getting-started/banks_patterns.md
+++ b/docs/getting-started/banks_patterns.md
@@ -6,6 +6,8 @@ Cagire organizes all your patterns and data following a strict hierarchy:
- **Banks** contain **Patterns**.
- **Patterns** contain **Steps**.
+If strict organization isn't your style, don't worry, you can ignore banks entirely and just work in a single pattern. You can also escape the strict metric using sub-step timing and randomness.
+
## Structure
```
@@ -15,7 +17,7 @@ Project
└── 1024 Steps (per pattern)
```
-A single project gives you 32 banks, each holding 32 patterns. You get 1024 patterns in each project, ~1.048.000 steps. This means that you can create a staggering amount of things. Don't hesitate to create copies, variations, and explore the pattern system thoroughly.
+A single project gives you 32 banks, each holding 32 patterns. You get 1024 patterns in each project, ~1.048.000 steps. This means that you can create a staggering amount of music. Don't hesitate to create copies, variations, and explore the pattern system thoroughly. The more you add, the more surprising it becomes.
## Patterns
@@ -29,7 +31,7 @@ Each pattern is an independent sequence of steps with its own properties:
| Sync Mode | Reset or Phase-Lock on re-trigger | `Reset` |
| Follow Up | What happens when the pattern finishes an iteration | `Loop` |
-Press `e` in the patterns view to edit these settings.
+Press `e` in the patterns view to edit these settings. After editing properties, you will have to hit the `c` key to _commit_ these changes. More about that later!
### Follow Up
@@ -49,6 +51,8 @@ Access the patterns view with `F2` (or `Ctrl+Up` from the sequencer). The view s
- `M` Muted
- `S` Soloed
+It is quite essential for you to understand the stage / commit system in order to use patterns. Please read the next section carefully!
+
### Keybindings
| Key | Action |
@@ -63,3 +67,5 @@ Access the patterns view with `F2` (or `Ctrl+Up` from the sequencer). The view s
| `Ctrl+c` / `Ctrl+v` | Copy / Paste |
| `Delete` | Reset to empty pattern |
| `Esc` | Cancel staged changes |
+
+
diff --git a/docs/getting-started/big_picture.md b/docs/getting-started/big_picture.md
index f7dcb39..d6e3351 100644
--- a/docs/getting-started/big_picture.md
+++ b/docs/getting-started/big_picture.md
@@ -1,6 +1,8 @@
# Big Picture
-Let's answer some basic questions: what exactly is Cagire? What purpose does it serve? Cagire is a small and simple piece of software that allows you to create music live while playing with scripts. At heart, it is really nothing more than a classic step sequencer, the kind you can buy in a music store. It is deliberately kept small and simple. Adding the Forth language to program steps allows you to create patterns and behaviors of any complexity. Forth also makes it super easy to extend and to customize Cagire while keeping the core mechanisms and the logic simple.
+> **What exactly is Cagire? What purpose does it serve?**
+
+Cagire is a small and simple software that allows you to create music live while programming short scripts. At heart, it is really nothing more than a classic step sequencer, the kind you can buy in a music store. It is deliberately kept small and simple in form, but it goes rather deep if you take the time to discover the audio engine and all its capabilities. Adding the Forth language to program steps allows you to create patterns and behaviors of any complexity. Forth also makes it easy to extend and to customize Cagire while keeping the core mechanisms and the logic simple.
Cagire is not complex, it is just very peculiar. It has been created as a hybrid between a step sequencer and a programming environment. It allows you to create music live and to extend and customize it using the power of Forth. It has been designed to be fast and responsive, low-tech in the sense that you can run it on any decent computer. You can think of it as a musical instrument. You learn it by getting into the flow and practicing. What you ultimately do with it is up to you: improvisation, composition, etc. Cagire is also made to be autonomous, self-contained, and self-sustaining: it contains all the necessary components to make music without relying on external software or hardware.
@@ -8,29 +10,40 @@ Cagire is not complex, it is just very peculiar. It has been created as a hybrid
A traditional step sequencer would offer the musician a grid where each step represents a note or a single musical event. Cagire replaces notes and/or events in favour of **Forth scripts**. When the sequencer reaches a step to play, it runs the script associated with it. A script can do whatever it is programmed to do: play a note, trigger a sample, apply effects, generate randomness, or all of the above. Scripts can share code and data with each other. Everything else works like a regular step sequencer: you can toggle, copy, paste, and rearrange steps freely.
+```forth
+0.0 8.0 rand at
+sine sound
+200 2000 rand 100 4000 rand
+4 slide freq 0.6 verb 2 vib
+0.125 vibmod 0.2 chorus
+0.4 0.6 rand gain
+.
+```
+
## What Does a Script Look Like?
-A Forth script is generally kind of small, and it solves a simple problem: playing a chord, tweaking some parameters, etc. The more focused it is, the better. Using Forth doesn't feel like programming at all. It feels more like juggling with words and numbers or writing bad computer poetry. Here is a program that plays a middle C note using a sine wave:
+A Forth script is generally kind of small, and it solves a simple problem: playing a chord, tweaking some parameters, etc. The more focused it is, the better. Using Forth doesn't feel like programming at all. It feels more like juggling with words and numbers or writing bad computer poetry. Here is a program that plays a middle C note for two steps using a sine wave:
```forth
-c4 note sine sound .
+c4 note sine sound 2 decay .
```
Read it backwards and you will understand what it does:
- `.` — play a sound.
+- `2 decay` — the sound takes two steps to die.
- `sine sound` — the sound is a sine wave.
- `c4 note` — the pitch is C4 (middle C).
-Five tokens separated by spaces. There is pretty much no syntax to learn, just three rules:
+There is pretty much no syntax to learn, just three rules:
- There are `words` and `numbers`.
- - A `word` is anything that is not a space or a number.
+ - A `word` is anything that is not a space or a number (can include symbols).
- A `number` is anything that is not a space or a word.
- They are separated by spaces.
- Everything piles up on the **stack**.
-The stack is what makes Forth tick. Think of it as a pile of things. `c4` puts a pitch on the pile. `note` picks it up. `sine` chooses a waveform. `sound` assembles everything into a voice. `.` plays it. Each word picks up what the previous ones left behind and leaves something for the next. Scripts can be simple one-liners or complex programs with conditionals, loops, and randomness. You will need to understand the stack, but it will take five minutes. See the **Forth** section for details.
+The stack is what makes Forth tick. Think of it as a pile of things. `c4` puts a pitch on the pile. `note` picks it up. `sine` chooses a waveform. `sound` assembles everything into a voice. `.` plays it. Each word picks up what the previous ones left behind and leaves something for the next. Scripts can be simple one-liners or complex programs with conditionals, loops, and randomness. Cagire requires you to understand what the stack is. The good thing is that it will take five minutes for you to make sense of it. See the **Forth** section for details.
## The Audio Engine
diff --git a/docs/getting-started/editing.md b/docs/getting-started/editing.md
index 10bef37..adea7be 100644
--- a/docs/getting-started/editing.md
+++ b/docs/getting-started/editing.md
@@ -1,6 +1,6 @@
# Editing a Step
-Each step in Cagire contains a Forth script. When the sequencer reaches that step, it runs the script to produce sound. This is where you write your music. Press `Enter` when hovering over any step to open the code editor. The editor appears as a modal overlay with the step number in the title bar. If the step is a linked step (shown with an arrow like `→05`), pressing `Enter` navigates to the source step instead.
+Each step in Cagire contains a Forth script. When the sequencer reaches that step, it runs the script to produce sound. This is where you write your music. Press `Enter` when hovering over any step to open the code editor. The editor appears as a modal overlay with the step number in the title bar. If the step is a mirrored step (shown with an arrow like `→05`), pressing `Enter` navigates to the source step instead.
## Writing Scripts
@@ -18,7 +18,7 @@ Add parameters before words to modify them:
c4 note 0.75 decay sine sound .
```
-Writing long lines is not recommended because it can become quite unmanageable. Instead, break them into multiple lines for clarity:
+Writing long lines can become tedious. Instead, break your code into multiple lines for clarity:
```forth
;; the same sound on multiple lines
@@ -29,6 +29,12 @@ sine sound
.
```
+Forth has no special rule about what a line should look like and space has no meaning.
+
+## Adding comments to your code
+
+You can comment a line using `;;`. This is not very common for people that are used to Forth. There are no multiline comments.
+
## Saving
- `Esc` — Save, compile, and close the editor.
@@ -64,27 +70,6 @@ Press `Ctrl+F` to open the search bar. Type your query, then navigate matches:
- `Enter` — Confirm and close search.
- `Esc` — Cancel search.
-## Debugging
+## Script preview
-Press `Ctrl+S` to toggle the stack display. This shows the stack state evaluated up to the cursor line, useful for understanding how values flow through your script.
-
-Press `Ctrl+R` to execute the script immediately as a one-shot, without waiting for the sequencer to reach the step. A green flash indicates success, red indicates an error.
-
-## Keybindings
-
-| Key | Action |
-|-----|--------|
-| `Esc` | Save and close |
-| `Ctrl+E` | Evaluate (save + compile in place) |
-| `Ctrl+R` | Execute script once |
-| `Ctrl+S` | Toggle stack display |
-| `Ctrl+B` | Open sample finder |
-| `Ctrl+F` | Search |
-| `Ctrl+N` | Next match / next suggestion |
-| `Ctrl+P` | Previous match / previous suggestion |
-| `Ctrl+A` | Select all |
-| `Ctrl+C` | Copy |
-| `Ctrl+X` | Cut |
-| `Ctrl+V` | Paste |
-| `Shift+Arrows` | Extend selection |
-| `Tab` | Accept completion / sample |
+Press `Ctrl+R` to execute the script immediately as a one-shot, without waiting for the sequencer to reach the step. A green flash indicates success, red indicates an error. This is super useful for sound design. It also works when hovering on a step with the editor closed.
diff --git a/docs/getting-started/engine.md b/docs/getting-started/engine.md
index fae6f7c..cc0d905 100644
--- a/docs/getting-started/engine.md
+++ b/docs/getting-started/engine.md
@@ -1,6 +1,6 @@
# The Audio Engine
-The Engine page (`F6`) is where you configure audio hardware, adjust performance settings, and manage your sample library. The right side of the page shows a real-time oscilloscope and spectrum analyzer. The page is divided into three sections. Press `Tab` to move between them, `Shift+Tab` to go back.
+The Engine page (`F6`) is where you configure audio hardware, manage MIDI connections, set up Ableton Link, and manage your sample library. The left column holds six configuration sections — press `Tab` to move between them, `Shift+Tab` to go back. The right column is a read-only monitoring panel with VU meters, status metrics, and an oscilloscope.
## Devices
@@ -17,11 +17,29 @@ Four audio parameters are adjustable with `Left`/`Right`:
| Voices | 1–128 | Maximum polyphony (simultaneous sounds) |
| Nudge | -100 to +100 ms | Timing offset to compensate for latency |
-The last two rows — sample rate and audio host — are read-only values reported by your system. After changing the buffer size or channel count, press `Shift+r` to restart the audio engine for changes to take effect.
+After changing the buffer size or channel count, press `Shift+r` to restart the audio engine for changes to take effect.
+
+## Link
+
+Ableton Link synchronizes tempo across devices and applications on the same network. Three settings are adjustable with `Left`/`Right`:
+
+- **Enabled** — Turn Link on or off. A status badge next to the header shows DISABLED, LISTENING, or CONNECTED.
+- **Start/Stop Sync** — Whether play/stop commands are shared with other Link peers.
+- **Quantum** — Number of beats per phrase, used for phase alignment.
+
+Below the settings, three read-only session values update in real time: Tempo, Beat, and Phase.
+
+## MIDI Outputs
+
+Four output slots (0–3). Browse with `Up`/`Down`, cycle available devices with `Left`/`Right`. A slot shows "(not connected)" until you assign a device.
+
+## MIDI Inputs
+
+Same layout as outputs — four input slots (0–3) with the same navigation.
## Samples
-This section shows how many sample directories are registered and how many files have been indexed. Press `A` to open a file browser and add a new sample directory. Press `D` to remove the last one. Cagire indexes audio files (wav, mp3, ogg, flac, aac, m4a) from all registered paths.
+This section shows how many sample directories are registered and how many files have been indexed. Browse existing paths with `Up`/`Down`. Press `A` to open a file browser and add a new sample directory. Press `D` to remove the selected path. Cagire indexes audio files (wav, mp3, ogg, flac, aac, m4a) from all registered paths.
Sample directories must be added here before you can use the sample browser or reference samples in your scripts.
@@ -30,23 +48,17 @@ Sample directories must be added here before you can use the sample browser or r
A few keys work from anywhere on the Engine page:
- `h` — Hush. Silence all audio immediately.
-- `p` — Panic. Hard stop, clears all active voices.
+- `p` — Panic. Hard stop, clears all active voices, stop all patterns.
- `t` — Test tone. Plays a brief sine wave to verify audio output.
- `r` — Reset the peak voice counter.
+- `Shift+r` — Restart the audio engine.
-## Keybindings
+## Monitoring
-| Key | Action |
-|-----|--------|
-| `Tab` / `Shift+Tab` | Next / previous section |
-| `Up` / `Down` | Navigate within section |
-| `Left` / `Right` | Switch device column / adjust setting |
-| `PageUp` / `PageDown` | Scroll device list |
-| `Enter` | Select device |
-| `D` | Refresh devices / remove last sample path |
-| `A` | Add sample directory |
-| `Shift+r` | Restart audio engine |
-| `h` | Hush |
-| `p` | Panic |
-| `t` | Test tone |
-| `r` | Reset peak voices |
+The right column displays a live overview of the engine state. Everything here is read-only.
+
+- **VU Meters** — Left and right channel levels with horizontal bars and dB readouts. Green below -12 dB, yellow approaching 0 dB, red above.
+
+- **Status** — CPU load (with bar graph), active voices and peak count, scheduled events, schedule depth, nudge offset, sample rate, audio host, and Link peers (when connected).
+
+- **Scope** — An oscilloscope showing the current audio output waveform.
diff --git a/docs/getting-started/grid.md b/docs/getting-started/grid.md
index ae7633a..997322d 100644
--- a/docs/getting-started/grid.md
+++ b/docs/getting-started/grid.md
@@ -1,43 +1,48 @@
# The Sequencer Grid
-The sequencer grid is the main view of Cagire (`F5`). This is the one you see when you open the application. On this view, you can see the step sequencer grid and edit each step using the code editor. You can optionally display the following widgets:
-- **an oscilloscope**: visualize the current audio output.
-- **a spectrum analyzer**: 32 bands spectrum analyze (mostly cosmetic).
-- **a step preview**: visualize the content of the hovered script.
-
-You can press `o` to cycle through layouts. It will basically rotate the sequencer around. Use it to find the view that makes the more sense for you.
+The sequencer grid (`F5`) is where you spend most of your time in Cagire. It shows the step sequencer and lets you edit each step using the code editor. This is the first view you see when you open the application. Optional widgets — oscilloscope, spectrum analyzer, goniometer, prelude preview, and step preview — can be toggled on for visual feedback while you work.
## Navigation
-Use arrow keys to move between steps. The grid wraps around at pattern boundaries. Press `:` to jump directly to a step by number. This keybinding is useful for very long patterns.
+Use arrow keys to move between steps. `Shift+arrows` selects multiple steps, and `Esc` clears any selection. The grid wraps around at pattern boundaries. Press `:` to jump directly to a step by number.
-## Preview
-
-Press `p` to enter preview mode. A read-only code editor opens showing the script of the step under the cursor. You can still navigate the grid while previewing. Press `Esc` to exit preview mode.
-
-## Selection
-
-Hold `Shift` while pressing arrow keys to select multiple steps. Press `Esc` to clear the selection.
+- `Alt+Up` / `Alt+Down` — Previous / next pattern
+- `Alt+Left` / `Alt+Right` — Previous / next bank
## Editing Steps
- `Enter` — Open the script editor
-- `t` — Toggle step active/inactive
+- `t` — Make a step active / inactive
- `r` — Rename a step
- `Del` — Delete selected steps
+## Mirrored Steps
+
+Imagine a drum pattern where four steps play the same kick script. You tweak the sound on one of them — now you have to find and edit all four. Mirrored steps solve this: one step is the source, the others are mirrors that always reflect its script. Edit the source once, every mirror follows.
+
+On the grid, mirrors are easy to spot. They show an arrow prefix like `→05`, meaning "I mirror step 05." Steps that share a source also share a background color, so clusters of linked steps are visible at a glance.
+
+To create mirrors: copy a step with `Ctrl+C`, then paste with `Ctrl+B` instead of `Ctrl+V`. The pasted steps become mirrors of the original. Pressing `Enter` on a mirror jumps to its source and opens the editor there. If you want to break the link and make a mirror independent again, press `Ctrl+H` to harden it back into a regular copy.
+
## Copy & Paste
- `Ctrl+C` — Copy selected steps
-- `Ctrl+V` — Paste as copies
-- `Ctrl+B` — Paste as linked steps
+- `Ctrl+V` — Paste as independent copies
+- `Ctrl+B` — Paste as mirrored steps
- `Ctrl+D` — Duplicate selection
-- `Ctrl+H` — Harden links (convert to independent copies)
+- `Ctrl+H` — Harden mirrors (convert to independent copies)
-Linked steps share the same script as their source. When you edit the source, all linked steps update automatically. This is an extremely important and powerful feature. It allows you to create complex patterns with minimal effort. `Ctrl+H` converts linked steps back to independent copies.
+## Prelude
+
+The prelude is a Forth script that runs before every step, useful for defining shared variables and setup code.
+
+- `p` — Open the prelude editor
+- `d` — Evaluate the prelude
## Pattern Controls
+Each pattern has its own length and speed. Length sets how many steps it cycles through. Speed is a multiplier on the global tempo.
+
- `<` / `>` — Decrease / increase pattern length
- `[` / `]` — Decrease / increase pattern speed
- `L` — Set length directly
@@ -45,6 +50,8 @@ Linked steps share the same script as their source. When you edit the source, al
## Playback
+Playback starts and stops globally across all unmuted patterns. The highlighted cell on the grid marks the currently playing step.
+
- `Space` — Toggle play / stop
- `+` / `-` — Adjust tempo
- `T` — Set tempo directly
@@ -52,57 +59,24 @@ Linked steps share the same script as their source. When you edit the source, al
## Mute & Solo
+Mute silences a pattern; solo silences everything except it. Both work while playing.
+
- `m` — Mute current pattern
- `x` — Solo current pattern
- `Shift+m` — Clear all mutes
- `Shift+x` — Clear all solos
-## Prelude
+## Project
-The prelude is a Forth script that runs before every step, useful for defining shared variables and setup code.
-
-- `d` — Open the prelude editor
-- `Shift+d` — Evaluate the prelude
+- `s` — Save project
+- `l` — Load project
+- `q` — Quit
## Tools
+A few utilities accessible from the grid.
+
- `e` — Euclidean rhythm distribution
+- `?` — Show keybindings help
+- `o` — Cycle layout
- `Tab` — Toggle sample browser panel
-
-## Visual Indicators
-
-- **Highlighted cell** — Currently playing step
-- **Colored backgrounds** — Linked steps share colors by source
-- **Arrow prefix** (`→05`) — Step is linked to step 05
-
-## Keybindings
-
-| Key | Action |
-|-----|--------|
-| `Arrows` | Navigate grid |
-| `Shift+Arrows` | Extend selection |
-| `:` | Jump to step |
-| `Enter` | Open editor |
-| `p` | Preview step |
-| `t` | Toggle step active |
-| `r` | Rename step |
-| `Del` | Delete steps |
-| `Ctrl+C` / `Ctrl+V` | Copy / Paste |
-| `Ctrl+B` | Paste as links |
-| `Ctrl+D` | Duplicate |
-| `Ctrl+H` | Harden links |
-| `<` / `>` | Pattern length |
-| `[` / `]` | Pattern speed |
-| `L` / `S` | Set length / speed |
-| `Space` | Play / Stop |
-| `+` / `-` | Tempo up / down |
-| `T` | Set tempo |
-| `Ctrl+R` | Execute step once |
-| `m` / `x` | Mute / Solo |
-| `d` | Prelude editor |
-| `e` | Euclidean distribution |
-| `o` | Cycle layout |
-| `Tab` | Sample browser |
-| `Ctrl+Z` | Undo |
-| `Ctrl+Shift+Z` | Redo |
-| `?` | Show keybindings |
diff --git a/docs/getting-started/navigation.md b/docs/getting-started/navigation.md
index 7f4582e..b1be0a3 100644
--- a/docs/getting-started/navigation.md
+++ b/docs/getting-started/navigation.md
@@ -1,41 +1,6 @@
# Navigation
-Cagire's interface is organized as a 3x2 grid of six views:
-
-```
-Dict Patterns Options
-Help Sequencer Engine
-```
-
-- *Dict* : Forth dictionary — learn about the language.
-- *Help* : Help and tutorials — learn about the tool.
-- *Patterns* : Manage your current session / project.
-- *Sequencer* : The main view, where you edit sequences and play music.
-- *Options* : Configuration settings for the application.
-- *Engine* : Configuration settings for the audio engine.
-
-## Switching Views
-
-Use `Ctrl+Arrow` keys to move between views. A minimap will briefly appear to show your position in the grid. You can also click on the view name at the bottom left to open the switch view panel.
-
-- `Ctrl+Left` / `Ctrl+Right` — move horizontally (wraps around)
-- `Ctrl+Up` / `Ctrl+Down` — move vertically (does not wrap)
-- `Click` at bottom left — select a view
-
-You can also jump directly to any view with the F-keys:
-
-| Key | View |
-|------|------------|
-| `F1` | Dict |
-| `F2` | Patterns |
-| `F3` | Options |
-| `F4` | Help |
-| `F5` | Sequencer |
-| `F6` | Engine |
-
-## Common Keys
-
-These shortcuts work on every view:
+Press `?` on any view to see its keybindings. The most important shortcuts are always displayed in the footer bar. Press `Esc` to close the keybindings panel. These shortcuts work on every view:
| Key | Action |
|---------|---------------------------|
@@ -45,6 +10,29 @@ These shortcuts work on every view:
| `l` | Load project |
| `?` | Show keybindings for view |
-## Getting Help
+## Views
-Press `?` on any view to see the associated keybindings. This shows all available shortcuts for the current context. The most important keybindings are displayed in the footer bar. Press `Esc` to close the keybindings panel.
+Cagire's interface is organized as a 3x2 grid of six views. Jump to any view with its F-key or `Ctrl+Arrow` keys:
+
+```
+F1 Dict F2 Patterns F3 Options
+F4 Help F5 Sequencer F6 Engine
+```
+
+| Key | View | Description |
+|------|------------|-------------|
+| `F1` | Dict | Forth dictionary — learn about the language |
+| `F2` | Patterns | Manage your current session / project |
+| `F3` | Options | Configuration settings for the application |
+| `F4` | Help | Help and tutorials — learn about the tool |
+| `F5` | Sequencer | The main view, where you edit sequences and play music |
+| `F6` | Engine | Configuration settings for the audio engine |
+
+Use `Ctrl+Arrow` keys to move between adjacent views. A minimap will briefly appear to show your position in the grid. You can also click on the view name at the bottom left or in the top left corner of the header bar to open the switch view panel.
+
+- `Ctrl+Left` / `Ctrl+Right` — move horizontally (wraps around)
+- `Ctrl+Up` / `Ctrl+Down` — move vertically (does not wrap)
+
+## Secrets
+
+There is a hidden seventh view: the **Periodic Script**. Press `F11` to open it. The periodic script is a free-running Forth script evaluated at every step, independent of any pattern. It is useful for drones, global effects, control logic, and experimentation. See the **Periodic Script** tutorial for details.
diff --git a/docs/getting-started/options.md b/docs/getting-started/options.md
index 99d6c42..2fb52dc 100644
--- a/docs/getting-started/options.md
+++ b/docs/getting-started/options.md
@@ -1,45 +1,28 @@
# Options
-The Options page (`F3`) gathers all configuration settings in one place: display, synchronization and MIDI. Navigate options with `Up`/`Down` or `Tab`, change values with `Left`/`Right`. All changes are saved automatically.
+The Options page (`F3`) gathers display and onboarding settings in one place. Navigate with `Up`/`Down` or `Tab`, change values with `Left`/`Right`. All changes are saved automatically. A description line appears below the focused option to explain what it does.
## Display
| Option | Values | Description |
|--------|--------|-------------|
| Theme | (cycle) | Color scheme for the entire interface |
-| Hue rotation | 0–360° | Shift theme colors by a hue angle (±5° per step) |
+| Hue rotation | 0–360° | Shift all theme colors by a hue angle (±5° per step) |
| Refresh rate | 60 / 30 / 15 fps | Lower values reduce CPU usage |
| Runtime highlight | on / off | Highlight executed code spans during playback |
-| Show scope | on / off | Oscilloscope on the engine page |
-| Show spectrum | on / off | Spectrum analyzer on the engine page |
+| Show scope | on / off | Oscilloscope on the main view |
+| Show spectrum | on / off | Spectrum analyzer on the main view |
+| Show lissajous | on / off | XY stereo phase scope |
+| Gain boost | 1x – 16x | Amplify scope and lissajous waveforms |
+| Normalize | on / off | Auto-scale visualizations to fill the display |
| Completion | on / off | Word completion popup in the editor |
| Show preview | on / off | Step script preview on the sequencer grid |
| Performance mode | on / off | Hide header and footer bars |
| Font | 6x13 – 10x20 | Bitmap font size (plugin mode only) |
-| Zoom | 0.5x – 2.0x | Interface zoom factor (plugin mode only) |
+| Zoom | 50% – 200% | Interface zoom factor (plugin mode only) |
| Window | (presets) | Window size presets (plugin mode only) |
-## Ableton Link
-
-Cagire uses Ableton Link to synchronize tempo with other applications on the same network. Three settings control the connection:
-
-- **Enabled** — Turn Link on or off. When enabled, Cagire listens for peers and shares its tempo.
-- **Start/Stop sync** — When on, pressing play or stop in one app affects all peers.
-- **Quantum** — The beat subdivision used for phase alignment.
-
-Below these settings, a read-only session display shows the current tempo, beat position, and phase. The status line at the top shows the connection state: disabled, listening, or connected with peer count.
-
-## MIDI
-
-Four output slots and four input slots let you connect to MIDI devices. Cycle through available devices with `Left`/`Right`. Each slot can hold one device, and the same device cannot be assigned to multiple slots.
-
## Onboarding
-At the bottom, you can reset the onboarding guides if you dismissed them earlier and want to see them again.
-
-## Keybindings
-
-| Key | Action |
-|-----|--------|
-| `Up` / `Down` / `Tab` | Navigate options |
-| `Left` / `Right` | Change value |
+- **Reset guides** — Re-enable all dismissed guide popups.
+- **Demo on startup** — Load a rotating demo song on fresh startup.
diff --git a/docs/getting-started/samples.md b/docs/getting-started/samples.md
index e570522..e019f03 100644
--- a/docs/getting-started/samples.md
+++ b/docs/getting-started/samples.md
@@ -1,6 +1,6 @@
# The Sample Browser
-Press `Tab` on the sequencer grid to open the sample browser. It appears as a side panel showing a tree of all your sample directories and files. Press `Tab` again to close it. Before using the browser, you need to register at least one sample directory on the Engine page (`F6`). Cagire indexes audio files (wav, mp3, ogg, flac, aac, m4a) from all registered paths.
+Press `Tab` on the sequencer grid to open the sample browser. It appears as a side panel showing a tree of all your sample directories and files. Press `Tab` again to close it. Before using the browser, you need to register at least one sample directory on the Engine page (`F6`). Cagire indexes audio files (`.wav`, `.mp3`, `.ogg`, `.flac`, `.aac`, `.m4a`) from all registered paths.
## Browsing
@@ -28,15 +28,3 @@ kick sound .
See the **Samples** section in the Audio Engine documentation for details on how sample playback works.
-## Keybindings
-
-| Key | Action |
-|-----|--------|
-| `Tab` | Open / close browser |
-| `Up` / `Down` | Navigate |
-| `Right` | Expand folder / play file |
-| `Left` | Collapse folder |
-| `Enter` | Play file |
-| `PageUp` / `PageDown` | Fast scroll |
-| `/` | Search |
-| `Esc` | Clear search / close |
diff --git a/docs/getting-started/saving.md b/docs/getting-started/saving.md
index 41b8eab..a9ec1d1 100644
--- a/docs/getting-started/saving.md
+++ b/docs/getting-started/saving.md
@@ -23,15 +23,3 @@ When saving, type a filename and press `Enter`. Parent directories are created a
When loading, browse to a `.cagire` file and press `Enter`. The project replaces the current session entirely.
-## Keybindings
-
-| Key | Action |
-|-----|--------|
-| `s` | Save (from any view) |
-| `l` | Load (from any view) |
-| `Up` / `Down` | Browse entries |
-| `Right` | Enter directory |
-| `Left` | Parent directory |
-| `Tab` | Autocomplete path |
-| `Enter` | Confirm |
-| `Esc` | Cancel |
diff --git a/docs/getting-started/staging.md b/docs/getting-started/staging.md
index 6ab5bc0..400f451 100644
--- a/docs/getting-started/staging.md
+++ b/docs/getting-started/staging.md
@@ -1,18 +1,27 @@
# Stage / Commit
-Cagire requires you to `stage` changes you wish to make to the playback state and then `commit` it. It is way more simple than it seems. For instance, you mark pattern `04` and `05` to start playing, and _then_ you send the order to start the playback (`commit`). The same goes for stopping patterns. You mark which pattern to stop (`stage`) and then you give the order to stop them (`commit`). Why is staging useful? Here are some reasons why this design choice was made:
+In Cagire, changes to playback happen in two steps. First you **stage**: you mark what you want to happen. Then you **commit**: you apply all staged changes at once. Nothing changes until you commit. It is simpler than it sounds.
-- **To apply multiple changes**: Queue several patterns to start/stop, commit them together.
-- **To get clean timing**: All changes happen on beat/bar boundaries.
-- **To help with live performance**: Prepare the next section without affecting current playback.
+Say you want patterns `04` and `05` to start playing together. You stage both (`p` on each), then commit (`c`). Both start at the same time. Want to stop them later? Stage them again, commit again. That's it.
+
+This two-step process exists for good reasons:
+
+- **Multiple changes at once**: queue several patterns to start/stop, commit them together.
+- **Clean timing**: all changes land on beat or bar boundaries, never mid-step.
+- **Safe preparation**: set up the next section while the current one keeps playing.
+
+## Push changes, then apply
Staging is an essential feature to understand to be effective when doing live performances:
1. Open the **Patterns** view (`F2` or `Ctrl+Up` from sequencer)
2. Navigate to a pattern you wish to change/play
3. Press `p` to stage it. The pending change is going to be displayed:
- - `+` (staged to play)
+ - `+` (staged to play)
- `-` (staged to stop)
+ - `m` (staged to mute)
+ - `s` (staged to solo)
+ - etc.
4. Repeat for other patterns you want to change
5. Press `c` to commit all changes
6. Or press `Esc` to cancel
@@ -24,7 +33,8 @@ You can also stage mute/solo changes:
- Press `Shift+m` to clear all mutes
- Press `Shift+x` to clear all solos
-A pattern might not start immediately depending on the sync mode you have chosen. It might wait for the next beat/bar boundary.
+A pattern might not start immediately depending on the sync mode you have chosen.
+It might wait for the next beat/bar boundary.
## Status Indicators
diff --git a/docs/tutorials/periodic_script.md b/docs/tutorials/periodic_script.md
new file mode 100644
index 0000000..859e124
--- /dev/null
+++ b/docs/tutorials/periodic_script.md
@@ -0,0 +1,43 @@
+# The Periodic Script
+
+The periodic script is a hidden seventh view accessible with `F11`. It is a Forth script that runs continuously alongside your patterns, evaluated at every step like a pattern would be. Think of it as a free-running pattern with no grid — just code.
+
+## What is it for?
+
+The periodic script is useful for things that don't belong to any specific pattern:
+
+- **Global effects**: apply a filter sweep or reverb tail across everything.
+- **Drones**: run a sustained sound that keeps going regardless of which patterns are playing.
+- **Control logic**: update variables, send MIDI clock, or modulate global parameters.
+- **Experimentation**: sketch ideas without touching your pattern grid.
+
+## Opening the Script
+
+Press `F11` from any view. The script page appears with an editor on the left and visualizations on the right (scope, spectrum, prelude preview). The script is saved with your project.
+
+## Editing
+
+Press `Enter` to focus the editor. Write Forth code as you would in any step. Press `Esc` to unfocus and save. Press `Ctrl+E` to evaluate without unfocusing.
+
+```forth
+;; a simple drone
+saw s c2 note 0.3 gain 0.4 verb .
+```
+
+## Speed and Length
+
+The periodic script has its own speed and length settings, independent of any pattern. Press `S` (unfocused) to set the speed and `L` to set the length (1-256 steps). Speed and length are displayed in the editor title bar.
+
+The script loops over its length just like a pattern. Context words like `step`, `iter`, and `phase` work as expected, counting within the script's own cycle.
+
+## Keybindings
+
+| Key | Action |
+|-----|--------|
+| `F11` | Open periodic script view |
+| `Enter` | Focus editor |
+| `Esc` | Unfocus and save |
+| `Ctrl+E` | Evaluate |
+| `Ctrl+S` | Toggle stack display |
+| `S` | Set speed (unfocused) |
+| `L` | Set length (unfocused) |
diff --git a/docs/tutorials/randomness.md b/docs/tutorials/randomness.md
index 0bbd920..d0f1903 100644
--- a/docs/tutorials/randomness.md
+++ b/docs/tutorials/randomness.md
@@ -94,37 +94,6 @@ Kick plays 50% of the time, snare 30%, hat 20%. Weights don't need to sum to 1 -
Combined with `note`, this gives you a random permutation of a chord every time the step runs.
-## Cycling
-
-Cycling steps through values deterministically. No randomness -- pure rotation.
-
-`cycle` selects based on how many times this step has played (its `runs` count):
-
-```forth
-60 64 67 3 cycle note sine s . ;; 60, 64, 67, 60, 64, 67, ...
-```
-
-`pcycle` selects based on the pattern iteration count (`iter`):
-
-```forth
-kick snare 2 pcycle s . ;; kick on even iterations, snare on odd
-```
-
-The difference matters when patterns have different lengths. `cycle` counts per-step, `pcycle` counts per-pattern.
-
-Quotations work here too:
-
-```forth
-( c4 note ) ( e4 note ) ( g4 note ) 3 cycle
-sine s .
-```
-
-`bounce` ping-pongs instead of wrapping around:
-
-```forth
-60 64 67 72 4 bounce note sine s . ;; 60, 64, 67, 72, 67, 64, 60, 64, ...
-```
-
## Periodic Execution
`every` runs a quotation once every n pattern iterations:
@@ -139,6 +108,20 @@ sine s .
( 2 distort ) 4 except ;; distort on all iterations except every 4th
```
+`every+` and `except+` take an extra offset argument to shift the phase:
+
+```forth
+( snare s . ) 4 2 every+ ;; fires at iter 2, 6, 10, 14...
+( snare s . ) 4 2 except+ ;; skips at iter 2, 6, 10, 14...
+```
+
+Without the offset, `every` fires at 0, 4, 8... The offset shifts that by 2, so it fires at 2, 6, 10... This lets you interleave patterns that share the same period:
+
+```forth
+( kick s . ) 4 every ;; kick at 0, 4, 8...
+( snare s . ) 4 2 every+ ;; snare at 2, 6, 10...
+```
+
`bjork` and `pbjork` use Bjorklund's algorithm to distribute k hits across n positions as evenly as possible. Classic Euclidean rhythms:
```forth
diff --git a/docs/welcome.md b/docs/welcome.md
index 2e5ab66..74d0af3 100644
--- a/docs/welcome.md
+++ b/docs/welcome.md
@@ -1,25 +1,25 @@
# Welcome to Cagire
-Cagire is a live-codable step sequencer. Each sequencer step is defined by a **Forth** script that gets evaluated at the right time. **Forth** is a minimal, fun and rewarding programming language. It has almost no syntax but provides infinite fun. It rewards exploration, creativity and curiosity. This documentation is both a _tutorial_ and a _reference_. All the code examples in the documentation are interactive. **You can run them!** Use `n` and `p` (next/previous) to navigate through the examples. Press `Enter` to evaluate an example! Try to evaluate the following example using `n`, `p` and `Enter`:
+Cagire is a live-codable step sequencer. Each sequencer step is defined by a **Forth** script that gets evaluated at the right time. **Forth** is a minimal, fun and rewarding programming language. It has almost no syntax but provides infinite fun. It rewards exploration, creativity and curiosity.
+
+This documentation is both a _tutorial_ and a _reference_. All the code examples in the documentation are interactive. **You can run them!** Use `n` and `p` (next/previous) to navigate through the examples. Press `Enter` to evaluate an example! Try to evaluate the following example using `n`, `p` and `Enter`:
```forth
saw sound
-400 freq
-1 decay
+c4 note
+0.5 decay
.
```
## What is live coding?
-Live coding is a technique where you write code in real-time to create audiovisual performances. Most often, it is practiced in front of an audience. Live coding is a way to experiment with code, to share things and thoughts openly, to think through code. It can be technical, poetic, weird, preferably all at once. Live coding can be used to create music, visual art, and other forms of media with a strong emphasis on _improvisation_. Learn more about live coding on [https://toplap.org](https://toplap.org) or [https://livecoding.fr](https://livecoding.fr). Live coding is an autotelic activity: the act of doing it is its own reward. There are no errors, only fun.
+Live coding is a technique where you write code in real-time to create audiovisual performances. Most often, it is practiced in front of an audience. Live coding is a way to experiment with code, to share things and thoughts openly, to think through code. It can be technical, poetic, weird, preferably all at once. Live coding can be used to create music, visual art, and other forms of media with a strong emphasis on _improvisation_. Learn more about live coding on [toplap.org](https://toplap.org) or [livecoding.fr](https://livecoding.fr). Live coding is an autotelic activity: the act of doing it is its own reward. There are no errors, only fun.
## About
-Cagire is mainly developed by BuboBubo (Raphaël Maurice Forment, [https://raphaelforment.fr](https://raphaelforment.fr)). It is a free and open-source project licensed under the `AGPL-3.0 License`. You are free to contribute to the project by contributing to the codebase or by sharing feedback. Help and feedback are welcome!
+Cagire is mainly developed by BuboBubo (Raphaël Maurice Forment, [raphaelforment.fr](https://raphaelforment.fr)). It is a free and open-source project licensed under the `AGPL-3.0 License`. You are free to contribute to the project by contributing to the codebase or by sharing feedback. Help and feedback are welcome!
### Credits
* **Doux** (audio engine) is a Rust port of Dough, originally written in C by Felix Roos.
-* **mi-plaits-dsp-rs** is a Rust port of the code used by the Mutable Instruments Plaits.
- * **Author**: Oliver Rockstedt [info@sourcebox.de](info@sourcebox.de).
- * **Original author**: Emilie Gillet [emilie.o.gillet@gmail.com](emilie.o.gillet@gmail.com).
+* **mi-plaits-dsp-rs** is a Rust port of the code used by the Mutable Instruments Plaits (Emilie Gillet). Rust port by Oliver Rockstedt.
diff --git a/src/README.md b/src/README.md
new file mode 100644
index 0000000..695f524
--- /dev/null
+++ b/src/README.md
@@ -0,0 +1,26 @@
+# cagire (main application)
+
+Terminal UI application — ties together the Forth VM, audio engine, and project model.
+
+## Modules
+
+| Module | Description |
+|--------|-------------|
+| `app/` | `App` struct and submodules: dispatch, editing, navigation, persistence, scripting, sequencer, clipboard, staging, undo |
+| `engine/` | Audio engine: `sequencer`, `audio`, `link` (Ableton Link), `dispatcher`, `realtime`, `timing` |
+| `input/` | Keyboard/mouse handling: per-page handlers, modal input, `InputContext` |
+| `views/` | Pure rendering functions taking `&App` |
+| `state/` | UI state modules (audio, editor, modals, panels, playback, ...) |
+| `services/` | Domain logic: clipboard, dict navigation, euclidean, help navigation, pattern editor, stack preview |
+| `model/` | Domain models: docs, categories, onboarding, script |
+| `commands` | `AppCommand` enum (~150 variants) |
+| `page` | `Page` navigation enum |
+| `midi` | MIDI I/O (up to 4 inputs/outputs) |
+| `settings` | Confy-based persistent settings |
+
+## Key Types
+
+- **`App`** — Central application state, coordinates all subsystems
+- **`AppCommand`** — Enum of all user actions, dispatched via `App::dispatch()`
+- **`InputContext`** — Holds `&mut App` + channel senders, bridges input to commands
+- **`Page`** — 3x2 page grid (Dict, Patterns, Options, Help, Main, Engine)
diff --git a/src/app/dispatch.rs b/src/app/dispatch.rs
index 4cccac4..ff67451 100644
--- a/src/app/dispatch.rs
+++ b/src/app/dispatch.rs
@@ -308,12 +308,6 @@ impl App {
self.ui.show_title = false;
self.maybe_show_onboarding();
}
- AppCommand::ToggleEditorStack => {
- self.editor_ctx.show_stack = !self.editor_ctx.show_stack;
- if self.editor_ctx.show_stack {
- crate::services::stack_preview::update_cache(&self.editor_ctx);
- }
- }
AppCommand::SetColorScheme(scheme) => {
self.ui.color_scheme = scheme;
let palette = scheme.to_palette();
@@ -494,9 +488,6 @@ impl App {
}
AppCommand::ScriptSave => self.save_script_from_editor(),
AppCommand::ScriptEvaluate => self.evaluate_script_page(link),
- AppCommand::ToggleScriptStack => {
- self.script_editor.show_stack = !self.script_editor.show_stack;
- }
}
}
diff --git a/src/app/scripting.rs b/src/app/scripting.rs
index 65aed77..76a85e3 100644
--- a/src/app/scripting.rs
+++ b/src/app/scripting.rs
@@ -61,9 +61,6 @@ impl App {
.set_completion_enabled(self.ui.show_completion);
let tree = SampleTree::from_paths(&self.audio.config.sample_paths);
self.editor_ctx.editor.set_sample_folders(tree.all_folder_names());
- if self.editor_ctx.show_stack {
- crate::services::stack_preview::update_cache(&self.editor_ctx);
- }
}
}
@@ -129,20 +126,33 @@ impl App {
}
/// Evaluate a script and immediately send its audio commands.
+ /// Returns collected `print` output, if any.
pub fn execute_script_oneshot(
&self,
script: &str,
link: &LinkState,
audio_tx: &arc_swap::ArcSwap>,
- ) -> Result<(), String> {
+ ) -> Result