OTYPElearn1.1scripting for the octatrackoctatrack

The studies
  1. Learn OType
  2. 01Quickstart
  3. 02Numbers and expressions
  4. 03Decisions and loops
  5. 04Variables and memory
  6. 05Tracks and steps
  7. 06Functions
  8. 07Asking the player
  9. 08Chance you can repeat
  10. 09Live scripts
  11. 10When something is wrong
  12. 11Appendix: scope at a glance

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.

Listing 9-1 · A filter that wanders on each 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 cut

Here 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

blockwakes onreads
in note [ch]:a note-on, from any channel or channel chnote.num note.vel note.ch
in cc ch n:controller n on channel chcc.val cc.num cc.ch
in trig t:each trig of track t that playstrig.step
in trig t all:each trig placed on track t, played or nottrig.step trig.hit
Listing 9-2 · Notes 60 to 67 play tracks 1 to 8, at their velocity
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 a

The 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.

Listing 9-3 · A random gate and value, followed by a second 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 2

What 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 wobble faster, on every sixteenth, with smaller steps.
  • Change pad_play so 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.