# Rhythm

## Rest or silence

Use `r` to create rhythm with musical rest in the melodies. `r` can be combined with note length, meaning it will sleep the length of the r, for example:

``````# Play quarter note 1 (D) and then sleep half note and then play half note 2 (E)
@swim
def z(p=1, i=0):
dur = ZD("superpiano","q 0 e3 qr e 2 4 r 1", i = i) # Returns length of the pattern in beats
again(z, p=dur, i=i+1)
``````

## Dotted notes

`.` for dotted notes. First dot increases the duration of the basic note by half of its original value. Second dot half of the half, third dot half of the half of the half ... and so on. For example dots added to Whole note `w` will change the duration to 1.5, second dot `w..` to 1.75, third dot to 1.875.

``````# Row row row your boat using dotted notes
@swim
def z(p=1, i=0):
dur = ZD("superpiano","q. 0 0 | q0 e1 q.2 | q2 e1 q2 e3 | h.4 | e 7 7 7 4 4 4 2 2 2 0 0 0 | q4 e3 q2 e1 | h. 0 ", i = i) # Returns length of the pattern in beats
again(z, p=dur, i=i+1)
``````

## Subdivision

Subdivision notation divides the previous note length to equal proportions and can be used to create complex patterns:

``````# Subdivided from 0.25 by default
Pa * zd('superpiano', '[4 2 4 2] [4 5 4 2] [3 1 3 1] [3 4 3 1] [4 2 4 2] [4 5 4 2] 4 [4 3 2 1] 0')
# Note length for the next subdivision can be defined using characters or decimals
Pa * zd('superpiano', 'w [1 2 3 4] 0.5 [1 2 3 4] q [1 2 3 4] w [1 2[3 4]] h [ 1 [ 2 [ 3 [ 4 ]]]]')
``````

## Triplets

Triplets can be defined using note characters or by list notation, for example:

``````# Triplets with note characters
Pa * zd('superpiano', 'q 2 6 a 1 3 2 q 5 1 a 4 3 2')

# Triplets with list notation
Pa * zd('superpiano', 'q 2 6 h [1 3 2] q 5 1 h [4 3 2]')
``````

## Ties

Ties can be created using multiple note length characters. Tied note lengths are summed up for the next degree, for example:

``````# q+e=0.375
Pa * zd('superpiano', 'q 0 qe2 3 4 qe 3 q 4')
``````

## List of all note length characters

CharacterNote lengthNote name (US)Note name (UK)Ticks
m8.0MaximaLarge15360
k5.333Triplet longTriplet large10240
l4.0LongLonga7680
p2.667Triplet wholeTriplet longa5120
d2.0Double whole noteBreve3840
c1.333Triplet wholeTriplet breve2560
w1.0Whole noteSemibreve1920
y0.667Triplet halfTriplet semibreve1280
h0.5Half note Minim960
n0.333Triplet quarterTriplet minim640
q0.25Quarter noteCrotchet480
a0.167Triplet 8thTriplet crochet 320
e0.1258th noteQuaver240
f0.083Triplet 16thTriplet quaver160
s0.062516th noteSemiquaver120
x0.042Triplet 32thTriplet semiquaver80
t0.03132th noteDemisemiquaver60
g0.021Triplet 32thTriplet demi-semiquaver40
u0.01664th noteHemidemisemiquaver30
j0.0078Triplet 128thTriplet Hemidemisemiquaver15
o0.00416128thSemihemidemisemiquaver8
z0.0No lengthNo length0

Note that `i`, `v` (chords), `r` (rest) and `b` (flat) are exceptions to a rule that all lower letters are note lengths!