study 09 of 10
Live scripts
Every function so far ran once, when you chose it, and then finished. A live script keeps running with the sequencer: it wakes on the clock, on a MIDI note, a controller or a trig, does its work, and sleeps until the next event. This study builds a bass filter that moves on its own, then pads you play from a MIDI controller.
Waking on the clock: in clock
in clock n: runs its block every n clock ticks. A quarter note is 96 ticks, so
in clock 24 is every sixteenth and in clock 96 every beat.
def wobble
var cut 64
in clock 96:
cut lim add cut sub rnd 21 10 20 120
trk 1:
par.set fx1 2 cutHere var matters: a live script keeps its named variables from one wake to the next, so
cut walks up and down instead of starting over. par.set fx1 2 cut writes the second
parameter of FX1 on track 1, the cutoff when FX1 is the filter. How a live script is started and stopped depends on
your firmware.
Starting on the bar: launch
launch n makes the first wake wait for the next multiple of n ticks:
launch 384 starts the script on the next bar in 4/4.
Waking on MIDI and on trigs
| block | wakes on | reads |
|---|---|---|
in note [ch]: | a note-on, from any channel or channel ch | note.num note.vel note.ch |
in cc ch n: | controller n on channel ch | cc.val cc.num cc.ch |
in trig t: | each trig of track t that plays | trig.step |
in trig t all: | each trig placed on track t, played or not | trig.step trig.hit |
def pad_play
in note 1:
a sub note.num 59
if and gt a 0 lt a 9:
trk a:
trk.level note.vel
play aThe other direction works too: send.note, send.cc, send.prog and
send.nrpn send MIDI out, from a live script or from a menu function.
Scripts that talk to each other
Live scripts can be wired like modules in a patch. gate n sends a gate on one of the script's four
outputs; another script that declares in gate NAME n: wakes on it, in the same tick.
out n v publishes a number on an output, and cv NAME n reads it from another script.
def acid
in clock 24:
prob 50: gate 1
out 1 rnd 128
def follow
in gate acid 1:
trk 2:
par.set fx1 2 cv acid 1
play 2What a live script may not do
A live script runs while the music plays, with no one to answer a question: it cannot use an operation that
asks for confirmation, such as pat.copy. The checker refuses it, in the script and in the bricks it
calls.
What you learned
in clock n:- wake every n ticks, 96 per quarter note
var- kept from one wake to the next
launch n- wait for the next multiple of n ticks to start
in note·in cc·in trig- wake on MIDI or on the sequencer
send.note·send.cc…- MIDI out
gate·in gate·out·cv- links between scripts
Try it
- Make
wobblefaster, on every sixteenth, with smaller steps. - Change
pad_playso that notes 36 to 43 play the tracks. - Read the drum and bass script
DNB.OTY: you can now read it from top to bottom.