VOLTAlearn

Learn Volta / Reuse

The library

Package musical ideas for reuse across songs.

lesson 28 of 39 · about 9 minutes

Open this lesson in the workbench →

Every lesson so far had you spell out the sound: a patch per voice, a pattern literal per part. Volta ships fifteen library modules that already contain most of it — tuned drums, basses, keys, effect chains, the six drum patterns everybody types — as plain .volta source you can read. This lesson is about taking them: import is the whole mechanism, and it is smaller than you expect.

import "drums" (kick, snare, hat) reads the drums module and binds exactly those three names into your buffer. After that they are ordinary patches — play them, with-override a field, put them in a mixer. A module is just a .volta file with no song in it; nothing is compiled specially and nothing is hidden.

Only public names cross the line. drums marks its internal sine-thump helper priv body, so import "drums" (body) is a compile error rather than a surprise — that is the entire module contract.

import "rhythm" (fourFloor) does the same for patterns. rhythm's six — fourFloor, backbeat, offbeat, sixteenths, clave, tresillo — are written on c2 so they drive any drum voice. A snare wants c3 and a hat c5, though, which is why rhythm also ships rhythmKit: snares = rhythmKit { shift = 12 } applies all six patterns at one trigger register, reached as snares.backbeat. The register is named once instead of re-typed into every literal.

The real reason libraries go unused is that their names are your names — you already have a kick, a sub, a pad. import "drums" as d binds no names at all: it gives the module one short handle and every export is reached through it as d.kick, d.snare, d.hat. Your own kick stays exactly where it is. Mix the two forms freely — take the names that read fine bare, alias the module that would collide.

The workbench serves the library at /lib/, and the source of truth is examples/songs/*.volta in the repo. Open one: drums.volta is 90 lines you could have written, which is the point — a library you can read is a library you can fork.

The starting point#

The lesson opens with this song in the editor. Every edit recompiles and plays.

-- The library: a kick spelled out by hand, and a pattern spelled out by
-- hand. Both of them already ship with Volta.
tempo = 124bpm

kick = patch {
  source = sine (freq pitch + ((vel * 60Semitones) |> withDecay 50ms)),
  ampEnv = adsr 0ms 100ms 0 80ms,
  cutoff = 250Hz,
  gain   = vel * 0.9
}

beat = play kick !"c2 ~ ~ ~ c2 ~ ~ ~ c2 ~ ~ ~ c2 ~ ~ ~"

What to watch#

Play the starter and note the shape of the kick on the scope — one blunt sine thump. Swap in the library's kick and watch the same slot grow a sharper attack transient and a longer, more curved decay: the imported voice has a pitch envelope on it. Same pattern, same level, visibly more sound.

Goals#

The workbench checks these as you work; the solution is there when you want it.

  1. Import a voice instead of writing one
  2. Import the pattern too
  3. Delete the hand-written patch
  4. Stretch: name a whole module with as

Make it yours#

Open drums.volta and rhythm.volta in the reference panel and read them end to end — they are short. Then build a kit out of nothing but imports: a voice from drums, a bass from bass under an alias, a fx chain on the bus, and every pattern from rhythm through one rhythmKit per register.

Further reading#

The standard library in the reference.