SPB Git

Repository Public

beats-and-bars.md 8.0 KB

# Beats and Bars

DJs count in beats and bars, and so does ORIX Script. This chapter explains exactly how positions are counted, how the automation's own bars relate to the bars of the master clock, and how to make things land where you expect.

# The grid

  • A beat is one beat of the master clock.
  • A bar is 4 beats. This is fixed; ORIX Script has no other time signature.
  • Phrases in dance music are usually 4, 8, 16 or 32 bars: 16, 32, 64 or 128 beats.
Length Beats At 128 BPM
1 beat 1 0.47 s
1 bar 4 1.875 s
4 bars 16 7.5 s
8 bars 32 15 s
16 bars 64 30 s
32 bars 128 60 s

# Counting from 1

Positions are counted the way a musician counts: the first bar is bar 1, and its first beat is beat 1.

text
bar:     |   1   |   2   |   3   |   4   |   5   |
beat:     1 2 3 4 5 6 7 8 9 …             17
offset:   0 1 2 3 4 5 6 7 8 …             16     (beats elapsed since the start)
Position Beats elapsed since the start of the automation
at bar 1, at beat 1, at 0 beats 0
at beat 2 1
at bar 2, at beat 5, at 1 bar 4
at bar 3, at beat 9, at 2 bars 8
at bar 5, at beat 17, at 4 bars 16
at bar 9, at beat 33, at 8 bars 32

In general:

text
bar N   is (N - 1) × 4 beats after the start
beat N  is (N - 1) beats after the start

at bar 0 and at beat 0 do not exist (E-RANGE): counting starts at 1.

The bar and beat numbers can be computed. Fractions are allowed: at beat 2.5 is one and a half beats after the start, the "and" of beat 2.

orixdj
for hit in 1...4 {
    at beat hit + 0.5 { deck.A.eq.high = -26dB }      // on every off-beat of bar 1
    at beat hit + 0.75 { deck.A.eq.high = 0dB }
}
wait 1 bar

# Durations count from 0

A duration is a length, not a position. wait 8 bars lasts 32 beats. A ramp over 8 bars started at bar 1 ends at the start of bar 9, not during bar 8.

This is the most common source of off-by-one-bar surprises:

You want Write
Something at the end of an 8-bar ramp started at bar 1 at bar 9 { … }, or simply put it after the over block
Something on the last bar of an 8-bar phrase at bar 8 { … } (28 beats in; the ramp is still running)
Something on the last beat of an 8-bar phrase at beat 32 { … } (31 beats in)
orixdj
at bar 8 { deck.B.play() }                 // last bar of the phrase: B starts under the ramp
over 8 bars { deck.A.volume -> -60dB }     // ends at the start of bar 9
deck.A.pause()                             // start of bar 9
deck.A.volume = 0dB

# Two grids: the automation and the master clock

There are two ways of talking about bars, and they are the same only if you ask for it.

  • The automation's bars start when the automation starts. at bar N, at beat N and wait until bar N count on this timeline.
  • The master clock's bars are the bars of the music: the clock follows the beat grid of the master deck, bar lines included. wait nextBar, wait nextBeat, at nextBar, at nextBeat, the on bar and on beat events and quantize use this grid.

If you start an automation in the middle of a bar without quantizing, its "bar 2" is four beats after the moment you pressed the button, which is in the middle of a musical bar.

quantize bar aligns the two. The automation then starts on a bar line of the master clock, so the automation's bar lines fall on the music's bar lines.

orixdj
automation "On The Grid" quantize bar {
    // bar 1 of this automation is a real bar line of the music
    at bar 3 { deck.A.eq.low = -26dB }
    at bar 5 { deck.A.eq.low = 0dB }
    wait 4 bars
}

Use quantize bar for anything that has to sit on the phrase. Use quantize beat for short rhythmic effects that only need to be on the beat. Leave quantizing out for things that should react immediately, such as a console command or a trigger handler.

quantize bar gives you a bar line, not necessarily the first bar of a phrase. Starting the automation during the last bar of a phrase is up to you.

# Getting back on the grid in the middle of a script

wait nextBar and wait nextBeat move the cursor to the next line of the master clock. They are useful after something that is not musical: a wait in seconds, or an event.

orixdj
wait 1500ms                 // not a whole number of beats
wait nextBar                // realign with the music
deck.A.eq.low = -26dB
wait 1 bar
deck.A.eq.low = 0dB

Remember that when the cursor is already on a line, these statements do not wait.

# Subdivisions

Fractions of a beat give the usual rhythmic values.

Written Notes per beat Name
1 beat 1 Quarter note
1/2beat 2 Eighth note
1/3beat 3 Eighth-note triplet
1/4beat 4 Sixteenth note
1/8beat 8 Thirty-second note
3/4beat – Dotted eighth (the classic delay time)
3/2beat – Dotted quarter
orixdj
// a sixteenth-note stutter for one bar, then a dotted-eighth echo
every 1/4beat for 1 bar {
    deck.A.volume = -60dB
    wait 1/8beat
    deck.A.volume = 0dB
}
fx.echo.time = 3/4beat
fx.echo.enable()
wait 2 bars
fx.echo.disable()

The shortest period accepted by every is 1/64 of a beat.

# Reading the clock

Path Value
master.bpm Tempo of the master clock
master.beat Beat counter of the master clock (a fractional number that keeps increasing)
master.bar Bar counter of the master clock: master.beat divided by 4, rounded down
master.deck Letter of the deck that drives the clock, or "" when the clock runs free
deck.X.beat Fractional beat index of the playhead on the track's own beat grid
deck.X.bpm Effective tempo of the deck (track tempo × playback rate)
deck.X.trackBpm Analysed tempo of the track at original speed; 0 when unknown. The analysis reports tempos between 78 and 156 BPM (the ÷2 and ×2 buttons on the deck change it)

master.beat and master.bar are counters of the clock, not positions in the automation, and they start from 0. Use them for arithmetic such as "is this an even bar".

orixdj
if master.bar % 2 == 0 {
    print("even bar of the master clock")
} else {
    print("odd bar of the master clock")
}

# The master clock and the master deck

The master clock follows the master deck: its tempo is the effective tempo of that deck, and its beats and bar lines are locked to the deck's beat grid. The master deck is the deck you chose as master, or else the current master while it keeps playing, or else the first playing deck that has a beat grid.

When no deck with a beat grid is playing, the clock runs free at its own tempo. Writing master.bpm sets that free-running tempo; it has no audible effect while a master deck is driving the clock.

orixdj
if master.deck == "" {
    master.bpm = 124          // nothing is driving the clock: choose the tempo
}

A deck with sync on follows the tempo of the clock and is steered onto its beat phase. That is why transitions start with deck.B.sync(true): afterwards "one bar" means the same thing on both decks.

# Deck positions are a different thing

deck.X.seek(…), deck.X.jump(…) and deck.X.loop(…) work on the track, not on the automation's timeline.

  • deck.A.seek(64 beats) moves the playhead to beat 64 of the track's beat grid, counted from the first beat of the grid. deck.A.seek(30s) moves it 30 seconds from the start of the file.
  • deck.A.jump(-4 beats) moves the playhead back four beats from where it is.
  • deck.A.loop(4 beats) starts a four-beat loop at the playhead. A loop length must be between 1/64 beat and 256 beats.
orixdj
deck.B.seek(32 beats)        // cue deck B at its ninth bar
deck.B.sync(true)
wait nextBar
deck.B.play()
Files main
Menu

Theme