BeatScript Editor

#Forms: arrange shapes from classical music

A form is a shape for a whole track: which sections there are, the order they come in, and what the arrangement does to them
pass after pass. Classical music named its shapes centuries ago, and they turn out to be BeatScript arrangements: a section
list plus a plan of arrange mutations (~ from here on, @ for the next section only). This page names six of them, and a
seventh made for crossing two seeds (cross), and gives each a template built from public-domain themes, so
arrange from template(quodlibet, @psalm42_deep_calleth) is a whole track, and the written-out program (expand) is the form
as plain BeatScript to edit. A form's roles can be filled with other sources: seeds, themes, notes, stored programs and sets,
other forms and their sections (see "Roles" and "Extensions" below).

It is the found-material principle again (found phrases): borrow the structure, not the recording,
from sources clean by construction. The themes are melodies composed and first published before 1929, written from the
melody itself (the theme library), and the forms are older still. The shapes are starting points, not rules: try a
fugue at 170 or a passacaglia under a gabber kick, and ignore the plan when ignoring it sounds better.

Everything here is one source with many views. The forms are templates (crates/djlive/src/template.rs, each with its section
shape, mutation plan and themes); the themes are a CC0 file (crates/djengine/data/themes-pd.txt, served at /themes,
/themes.txt and /themes.jsonld, by CID too). The MCP genre_template tool takes a form (the form at a genre's tempo)
or a theme (one theme put into a genre's program, in its key), and list_examples with themes lists the library. The
ontology has ns:Form and a term for each form, linked to the mutation operators it uses and to the found-phrases technique.

#How a form is written

Every form here is built the same way, and so can yours be:

#Quodlibet

Several themes take turns by section and cross-morph toward each other and away, in cycles. A quodlibet was a joke of
the Baroque: popular tunes sung at once, made to fit.

text
arrange {
  canon
  ~ ode_to_joy_* morph pachelbel_violin_1 0.25
  ode
  ~ pachelbel_violin_* morph ode_to_joy_1 0.25
  fate
  @ pachelbel_violin_* morph fate_b_1 0.3
  voices
  ~ ode_to_joy_* morph fate_b_2 0.2
} loop 3 then end

Write it: arrange from template(quodlibet, @psalm42_deep_calleth). Reference program: Canon of Fate. Its roles are a,
b, ground and third ("Extensions"): template(quodlibet, @psalm42_deep_calleth, a=badinerie, third=mountain_king).

#Passacaglia

A fixed ground in the bass, never changed, and cumulative variations above it: each pass adds a change on top of
the last.

BeatScript
section ground 8 bars {
  deck A: kick kick4 kit=drums | bass/20 mars_ostinato inst=bass
  deck B: harmony chords inst=strings len=8
}
arrange {
  ground variation
  ~ upper_* rot 2 | accent 0.25
  sung
  ~ upper_* rev | drift 0.1
  variation
} loop 3 then end

Write it: arrange from template(passacaglia, @eccl3_season). Reference program: Full fathom five.

#Canon

A theme chasing its own delayed or rotated copy. Pachelbel's three violins play one line two bars apart; a round is
a canon anyone can sing.

BeatScript
let follow = <pachelbel_violin_2 pachelbel_violin_1>
let close = rotate(pachelbel_violin, 4)
section round 8 bars {
  deck B: melody pachelbel_violin | arp octave(follow, -1) | harmony close
}

Write it: arrange from template(canon, @mgm_pease_porridge_hot). How far behind and at what interval the chase's copy is are
the canon's numbers, delay= (beats) and interval= (semitones): template(canon, @mgm_pease_porridge_hot, delay=6, interval=7) is a canon at the fifth, a bar and two beats behind ("Extensions").

#Rondo

A refrain that keeps coming back, changed each time, between contrasting sections: A B A C A.

text
arrange {
  refrain episode
  ~ the_entertainer_* rot 2 | accent 0.3
  refrain sung
  @ the_entertainer_* mirror | vel 2
  refrain
} loop 2 then end

Write it: arrange from template(rondo, @shanty_drunken_sailor). Reference program: Rag Rondo.

#Fugue

A subject that enters, is answered a fifth up, and re-enters transposed while the other lines morph toward
it
.

BeatScript
section answer 8 bars {
  deck B: melody mountain_king | arp transpose(mountain_king, 7)
}
arrange {
  subject answer
  ~ badinerie_* morph mountain_king_1 0.25
  counter
  ~ mountain_king_* down 2
  sung
} loop 3 then end

Write it: arrange from template(fugue, @tyger_burning_bright).

#Theme and variations

One source, a different transform each section, and no cross-morphs: the theme is heard plain, then changed one way,
then another, and comes back.

text
arrange {
  theme
  @ new_world_largo_* rev
  variation
  @ new_world_largo_* invert
  variation
  @ new_world_largo_* stutter 2
  variation
  theme
} loop 2 then end

Write it: arrange from template(theme-and-variations, @dickinson_chariot_death).

#Cross

Two sources take turns, overlap, and morph toward each other and back: a quodlibet of two, made for crossing two seeds of
the generator, in any genres (a=gen@1 dubstep seed=54876, b=gen@1 house seed=7).

Write it: arrange from template(cross, @psalm42_deep_calleth, a=gen@1 dubstep seed=54876, b=gen@1 house seed=7). Example:
cross two seeds (cross-two-seeds).

#Roles: the form is the structure, sources fill it

Every form names its roles, and any of them can be bound to a source after the phrase, role=source:

text
arrange from template(passacaglia, @eccl3_season, ground=gen@1 dubstep seed=54876 part=bass, upper=ode_to_joy)
arrange from template(rondo, @shanty_drunken_sailor, refrain=gen@1 dubstep seed=54876 part=melody, episodes=template(passacaglia, ground=gen@1 dubstep seed=54876 part=bass))

A role nobody binds keeps the form's own theme, so a template with no roles is the track it always was.

form roles what each role is default written as
quodlibet a, b, ground, third the first tune; the second, drawn toward the first; the bass; the third line both are pulled toward Pachelbel's violin; Ode to Joy; Pachelbel's ground; the fate motif in B minor tune_a, tune_b, ground, third
passacaglia ground, upper the bass under every section, never changed; the line the variations change Holst's Mars ostinato; the form's own line ostinato, upper
canon subject, ground (and the numbers delay, interval) the line chased by copies of itself, a bar and a beat behind; the bass Pachelbel's violin; Pachelbel's ground subject, ground
rondo refrain, episodes the tune that comes back; what plays between the returns, a line or sections Joplin's Entertainer; Bach's Prelude in C tune, figure or sections
fugue subject, counter the theme entered, answered a fifth up, re-entered; the countersubject drawn toward it Grieg's Mountain King; Bach's Badinerie dux, countersubject
theme and variations theme the one source every variation changes Dvorak's New World Largo air
cross a, b (and their parts alone, a.bass ...) the two sources, each its melody, bass and chords Ode to Joy over Pachelbel's ground; the Badinerie over a B minor bass a_melody a_bass a_harmony, b_...

The sources: a seed (gen@1 dubstep seed=54876, with section= and part= or without: the form takes the role's part from
the first section that plays it, the drop first, and a whole seed in a role of sections is its sections); a theme of the
library by id (ode_to_joy, moved into the key the role plays in); notes, a bar each ([d2 ~ a1 ~], <[d2 ~] [g1 ~]>); a
stored program's part (<cid>.drop.bass), section (<cid>.drop) or whole (<cid>, its sections in its order); a stored
set
(<cid> of a set { play ... }: its tracks in order) or one of its tracks (<cid>.track2); another form
(template(passacaglia, ground=...), no phrase), written inside this one under the role's prefix (ep_ground), its plan spread
over the role's places; and one section of another form (template(cross).both, .both.arp). A role is written as a let
a bar the sections and the plan read by name, so the plan's ~ subject_* rot 2 moves whatever fills it; a seed stays a pinned
gen@1 call in the written-out text. Forms nest three deep, a line is at most 16 bars and a role of sections at most 128 a pass.
The whole design is the long note docs/beatscript/ext-roles.md.

#Extensions: sets, sections, parts, numbers

Five ways to go further with a form's roles, each with a default that keeps every reference that does not say it written out
as it was (the pins of roles.rs bound_forms_are_pinned and template.rs templates_v1_are_pinned, and the examples' pins). Code: crates/djlive/src/roles.rs;
tests: crates/djlive/tests/form_extensions.rs (no generator) and crates/beatscript-api/tests/forms_roles.rs (sets, stored programs,
seeds). Example: Canon of the crossing (canon-of-the-crossing).

#Grammar

ebnf
binding     = NAME [ "." role ] "=" ( source | [ "-" ] INT ) ;
source      = gen | NAME | notes | form | stored | track ;
form        = "template" "(" NAME { "," binding } ")" [ "." NAME [ "." role ] ] ;
track       = CID "." NAME [ "." NAME ] [ "." role ] ;

The canonical spelling puts each role's parts right after the role (in the order melody, bass, harmony) and a form's numbers
after its roles: template(canon, @x, subject=..., delay=6, interval=7), template(cross, @x, a=..., a.bass=..., b=...).

#A stored set in a role

A set (set { play ... }, docs/BEATSCRIPT.md "Sets") is a program by CID like any other, so a role that takes sections takes one: the
set's tracks, in order, each its sections in the order it plays them, one track a place. The rondo's two episodes a pass
are the set's first track and its second:

text
arrange from template(rondo, @shanty_drunken_sailor, episodes=<set cid>)

is written out as section ep_t1_verse from <track 1>.verse, section ep_t1_hook from <track 1>.hook, section ep_t2_intro from <track 2>.intro ..., each under its doc comment, the arrangement's episode places taking ep_t1_verse ep_t1_hook ep_t1_verse and then ep_t2_intro ep_t2_lift. With more tracks than places they are shared out in order; with fewer they come
round. .trackN names one track, and is that track's program from then on: <cid>.track2 (its sections), <cid>.track2.lift
(a section), <cid>.track2.lift.melody (a part, a line). A track that is itself a set is its tracks in turn, named by their
place (ep_t2_1_drop: the drop of track 1 of track 2). After a program that is no set, .track2 is its section called track2,
as it always was.

#A section where a line goes

A section is a source where a line is expected: the role takes its own part of it (a subject's is the melody, a ground's the
bass, the episodes' line the arp), or the part it names. This was already so for a seed (gen@1 dubstep seed=54876 section=drop fills in the part); now it is so for a stored program's section (subject=<cid>.both is <cid>.both.melody) and
for one section of another form, written after its ):

text
arrange from template(canon, @mgm_pease_porridge_hot, subject=template(cross).both.arp, delay=6, interval=7)

is a canon whose subject is the cross's overlap: the arp of its both section, which is Ode to Joy as the cross's plan has
moved it by then (morphed a quarter of the way toward the Badinerie; the plan's one-shot xfer falls on the second both),
chased by copies of itself.

#Parts of a role (a.bass=)

A seed role (the cross's a and b: melody, bass, chords) has its parts bound one at a time. Alone, a.bass= replaces the
default's bass and leaves its tune and chords; with the whole role bound, the part bound alone wins over what the whole gives it:

text
arrange from template(cross, @psalm42_deep_calleth, a=gen@1 dubstep seed=54876, a.bass=<[d2 ~ ~ ~ a1 ~ ~ ~] [g1 ~ ~ ~ a1 ~ ~ ~]>)

is the seed's melody and chords over a hand-written bass; the plan's ~ a_bass_* morph b_bass_1 0.2 reads the bound bass.

#The canon's delay= and interval=

The chase's copy (follow, played by the chase, round and sung sections as the arp) is a bar behind and an octave down. Two
numbers move it:

The comments say the delay and the interval in words (# chase: the copy a bar and 2 beats behind, a fifth up), the header gives
each number given, and check says each in a note. The round's third voice (close) stays a beat behind, in unison.
Refuses: a delay of the subject's length or more ("1 to 7 beats for a subject of 2 bars: 8 beats is the subject itself, in
unison"); an interval past two octaves; a number that is not whole (delay=2.5); a source for a number (delay=ode_to_joy) or a
number for a role (subject=3); a number another form does not take (delay is no role of the rondo).

#The quodlibet's roles

The quodlibet names its roles as the other forms do: a (the first tune, Pachelbel's violin, written tune_a), b (the
second, Ode to Joy, tune_b), ground (Pachelbel's ground) and third (the line the other two are pulled toward, the fate
motif a semitone down in B minor). Its plan's cross-morphs read them (~ tune_b_* morph tune_a_1 0.25, @ tune_a_* morph third_1 0.3); binding third also takes away the fate motif's own lets, which only the default was made of.

text
arrange from template(quodlibet, @psalm42_deep_calleth, a=badinerie, b=new_world_largo, third=mountain_king)

#Decisions

#Not done

#Proposals

A source can be named first, on a line of its own, and the name bound to the role (use, docs/BEATSCRIPT.md "Name a source"), so a
nested reference reads in lines:

text
use gen@1 dubstep seed=54876 section=drop part=bass as walk
use theme the_entertainer as tune
use template(passacaglia, ground=walk) as episode_form
arrange from template(rondo, @shanty_drunken_sailor, refrain=tune, episodes=episode_form)

In a role the name is its source, exactly as if written there (the theme is moved into the role's key by the role). And a form's
sections can be borrowed one at a time into a program of your own, as canned sections: use template(passacaglia).ground as ground is the passacaglia's ground (the Mars ostinato under its chords, written with the form's own example phrase), and
arrange intro ground places it like a section of yours (list_examples with imports lists every template's sections).

#The theme library

The forms' material is the public-domain theme library (crates/djengine/data/themes-pd.txt, CC0), the
melodic twin of the phrasebook. Each entry is let-ready bars on the 16-step grid in a stated key, with its
role (melody, bass, harmony, arp), work, composer, year (before 1929), mode, meter and the themes it pairs with: those that
share its key or its harmony and morph well with it. A bar of 3/4 is twelve sixteenths (melody/12) and a bar of 5/4
twenty (bass/20); two bars of 2/4 are one 16-step bar.

#Reference programs

Three whole hand-written tracks, each the shape its form's template generalises. Each is CC0, carries its sources in a
comment and in linked data beside it (examples/beatscript/<name>.jsonld, isBasedOn the public-domain works), and is pinned by
its CID.

form program after CID
quodlibet Canon of Fate (canon-of-fate) Pachelbel, Canon in D (composed about 1680-1706, first printed 1919); Beethoven, Symphony No. 9 (1824), Ode to Joy; Beethoven, Symphony No. 5 (1808), the fate motif z4EBG9j86dPTC9HH6EjtBJFAWZsJLiPum4np9zoJQC9PzWm9SoC
passacaglia Full fathom five (full-fathom-five) Shakespeare, The Tempest (1623), Ariel's song, sung z4EBG9j3xZiLH5Sa8EnFW5sg2WuSPRuMbBaTr3JHeQjfWWE7Ug9
rondo Rag Rondo (rag-rondo) Joplin, The Entertainer (1902) and Maple Leaf Rag (1899; its figure approximated in C, not transcribed) z4EBG9izzm3asNWWapjXtPFSZoPzgyj4cKjPELrw4jvrhdjPxrW

#For an agent

  1. Pick a form for the shape you want: cross-talk between tunes (quodlibet), slow accumulation (passacaglia), a chase
    (canon), a hook that keeps returning (rondo), voices entering one by one (fugue), one idea seen many ways (theme and
    variations), two seeds crossed (cross).
  2. genre_template with genre and form (and a phrase, else the form's own): the answer has the program, its form
    (shape, plan, themes, reference) and expanded, the written-out text to edit.
  3. Or write the reference yourself, arrange from template(<form>, @<phrasebook id>), and expand it.
  4. To make a form your own music, bind its roles: ground=gen@1 dubstep seed=54876 part=bass, subject=ode_to_joy, notes, a
    stored program's part, a stored set, another form or one of its sections (template(cross).both.arp), one part of a seed
    role (a.bass=[d2 ~ a1 ~]), the canon's delay= and interval=. check says what each role got, in a note at it.
  5. For your own form, start from the plan: themes as lets a bar, drm_* for the drums that change, the vocal only moved or
    crossed, and check and listen until it says nothing you did not mean.

View source (the raw markdown of this page, for models and scripts)