Generate a clip's notes from code¶
Task: let a small program write a clip's notes for you — an arpeggio, a generative pattern, a seeded variation — instead of drawing them by hand. This is a script clip: its notes come from a generator you write in Common Lisp or Python.
Experimental
Script clips are new and still evolving. You need a language runtime installed —
SBCL for Common Lisp, or Python with grpcio and grpcio-tools.
Write the generator¶
- Add an instrument track and an (empty) MIDI clip on it.
- Right-click the clip → Edit script code…. Gloopy creates a source file for the
clip and opens it in your editor (from
$VISUAL/$EDITOR). -
The file starts from a template. Define a generator — a function that returns a list of notes:
(in-package :gloopy-kernel) (set-generator (lambda (ctx) ;; one note per beat, an ascending run from middle C (let ((beats (max 1 (floor (gloopy.pb::clip-len-beats ctx))))) (loop for b below beats collect (note (+ 60 b) b 0.9)))))notetakes(pitch start length &optional velocity)— start and length in beats within the clip.ctxgives you the clip length, key, and a per-clip seed for repeatable randomness.Name notes musically
pitchaccepts names ("C#4") andlengthduration codes ("q"), andscale,chord,seqandminibuild note lists for you — e.g.(seq '(("C4" "q") ("Eb4" "q") ("G4" "h")))or(mini "c4q eb g4h"). See Describing notes. -
Save the file.
Generate the notes¶
Right-click the clip → Generate from script. Gloopy runs your generator and fills the clip with the notes it returns. Edit the code and Generate again to iterate.
The result is materialised into the clip — normal notes you can see and edit in the piano roll, saved with the project. The generated notes are cached, so the clip plays on any machine even without the runtime installed; you only need the runtime to re-generate. Generation is deterministic: the same code and the same seed always produce the same notes.
Keep a clip "live"¶
Right-click the clip → Live (auto-generate on playback) marks it live (a LIVE badge appears). While you play, Gloopy re-runs the generator about a bar before the clip plays and swaps in the fresh notes — so if you're editing the generator (see below), a looping clip reflects each change on the next pass without a manual Generate. Toggle it off to freeze the clip again.
Play the script live instead¶
Right-click the clip → Live-drive from script plays the generator's notes live during playback without writing them into the clip — they're ephemeral and re-fetched each pass. Use this for generative parts you want to stay code, not fixed notes.
Develop interactively (Common Lisp)¶
Gloopy keeps a warm Lisp kernel running to generate clips, and it hosts a Slynk server
so you can attach Emacs (Sly) to the live image, redefine a generator, and re-run the clip
without a restart. In Emacs with gloopy.el loaded: M-x gloopy-connect. Once
connected, clicking a script clip opens its source in Emacs. File → Connect Emacs to
Kernel (Slynk)… shows the connection details.
See also¶
- Write a script-clip generator — the scripting details, the Python generator, and driving it over the control API.
- Develop generators live in Emacs (Sly) — the full Emacs workflow.