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 01 of 10

Quickstart

In this study you write a script that places a kick on every beat, check it on the computer, see what it does to a pattern, then run it on the Octatrack. Then you change it twice, to see how quickly an idea becomes a new function.

Write the file

Create a text file named BASICS.OTY and type this in it:

Listing 1-1 · BASICS.OTY
def four_floor
  menu "BASICS" >> "FOUR FLOOR"
  tr.clr
  l 1 16: if eq mod i 4 1: tr.add i
Output · what the simulator prints for $ otype.py run four_floor
four_floor  seed 1 (--seed)  pattern A01 len 16 (default)  track 1
T1  1   5   9   13
    X...X...X...X...
      X trig  ! one-shot  o trigless trig  - trigless lock  l locks only  . none
part:  tempo 120
cost: 176/224   random draws: rand 0  toss 0  prob 0  drunk 0  file 0

Line by line:

  • def four_floor starts a function named four_floor. Everything indented below it is its body.
  • menu "BASICS" >> "FOUR FLOOR" says where the function appears in the script menu: in the category BASICS, under the name FOUR FLOOR.
  • tr.clr clears the trigs of the track. Names with a dot are the Octatrack's operations: tr is the family (trigs), clr the action.
  • l 1 16: … repeats the rest of the line for i = 1, 2, … 16, the steps of the pattern. On each step, if eq mod i 4 1: asks: is the remainder of i divided by 4 equal to 1? It is on steps 1, 5, 9 and 13, and there tr.add i places a trig.

Do not worry yet about eq mod i 4 1: the next study is about reading that kind of line. Note the indentation: two spaces here, but any width works, as long as the lines of one block line up.

Check it

From the OType repository, run the checker on your file. It applies exactly the rules the unit applies when it loads the scripts:

python3 tools/otype.py check -v BASICS.OTY

It answers with one line per function: ok, its menu entry, and its cost, the most work one run can do (more on this in the last study). A mistake gives the file, the line and what is wrong instead.

See what it does

The simulator runs a function on a pattern, on the computer, and shows the steps afterwards:

python3 tools/otype.py run four_floor BASICS.OTY

The output under the listing above is what it prints. T1 is track 1: an X is a trig, a dot an empty step. With --bank you can run the same function on a real bank file copied from your card; nothing is ever written to it.

Run it on the machine

Copy BASICS.OTY into the folder /SCRIPTS/ at the root of the CF card, put the card back, and load the scripts (your firmware says how). The unit compiles the file itself: no firmware to rebuild.

Open the script menu (in OT1, press FUNCTION twice), choose BASICS, then FOUR FLOOR. A box asks YES or NO first: because tr.clr erases trigs, OType asks before any function that changes the project in a way you might regret. Answer YES, and the current track has its four kicks.

Change it

An eighth-note hat instead: a trig on every odd step. Add a second function to the same file:

Listing 1-2 · BASICS.OTY, a second function
def eighths
  menu "BASICS" >> "EIGHTHS"
  tr.clr
  l 1 16: if eq mod i 2 1: tr.add i
Output · what the simulator prints for $ otype.py run eighths
eighths  seed 1 (--seed)  pattern A01 len 16 (default)  track 1
T1  1   5   9   13
    X.X.X.X.X.X.X.X.
      X trig  ! one-shot  o trigless trig  - trigless lock  l locks only  . none
part:  tempo 120
cost: 192/224   random draws: rand 0  toss 0  prob 0  drunk 0  file 0

Now let the player choose the spacing before the function runs. param declares a setting with a default, a minimum and a maximum; the menu shows it, and the script reads it like a number:

Listing 1-3 · A setting the player edits on the unit
def every_n
  menu "BASICS" >> "EVERY N"
  param gap 4 1 16
  tr.clr
  l 1 16: if eq mod i gap 1: tr.add i
Output · what the simulator prints for $ otype.py run every_n
every_n  seed 1 (--seed)  pattern A01 len 16 (default)  track 1
T1  1   5   9   13
    X...X...X...X...
      X trig  ! one-shot  o trigless trig  - trigless lock  l locks only  . none
part:  tempo 120
cost: 176/224   random draws: rand 0  toss 0  prob 0  drunk 0  file 0

Copy the file again and load the scripts: the three functions are in BASICS. That is the whole loop of working with OType: edit, check, copy, run.

What you learned

def name
starts a function; its body is indented below
menu "CAT" >> "NAME"
lists the function in the script menu
param name default min max
a setting the player edits before the run
tr.clr · tr.add s
clear the trigs · place a trig on step s
l a b:
repeat for i = a … b
if c:
do the rest of the line only if c is true
check · run
check a file, run a function on the computer

Try it

  • Move the kicks to the off-beats: steps 3, 7, 11 and 15.
  • Give every_n a second param, start, that shifts the first trig.
  • Make a mistake on purpose (remove the i after tr.add) and read what the checker says.