Skip to content

ology/python-random-rhythms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random Rhythms in Python!

Partition a musical duration into rhythmic phrases.

Usage:

  1. Determine the pool of durations to use in your rhythmic phrase:
128th to 128: .03125 .0625 .125 .25 .5 1 2 4 8 16 32 64 128
# durations = [ 2**x for x in range(-5, 8) ]
Triplets: .167 .333 .667 1.333 2.667
# durations = [ 2**x/3 for x in range(-1, 4) ]
Dotted: .375 .75 1.5 3 6
# durations = [ 2**x+2**x/2 for x in range(-2, 3) ]
Double dotted: .4375 .875 1.75 3.5 7
# durations = [ 2**x+2**x/2+2**x/4 for x in range(-2, 3) ]

where 1 is a quarter-note, 0.5 is an eighth, 2 is a half-note, etc.

  1. Import the class:
from random_rhythms import Rhythm
  1. Instantiate a random-rhythm object:
params = { # these are the defaults:
    measure_size: 4, # in quarter-notes (or fractions thereof)
    durations: [ 1/4, 1/2, 1/3, 1, 3/2, 2 ], # 1 = quarter-note
    weights:   [ 1,   1,   1,   1, 1,   1 ],
    groups: {}, # number of notes, keyed by a duration
    smallest: 1/128 # lower threshold for adding to the phrase
}
r = Rhythm(**params)
  1. Get a motif:
motif = r.motif()
print(motif)

Musical example:

from music21 import *
import random
from random_rhythms import Rhythm

r = Rhythm(measure_size=5 groups={1/3: 3, 1/2: 2})
motifs = [ r.motif() for _ in range(4) ]

sc = scale.WholeToneScale('C4')

s = stream.Stream()
s.append(meter.TimeSignature('5/4'))

for m in motifs:
    for d in m:
        p = random.choice(sc.pitches)
        n = note.Note(p)
        n.duration = duration.Duration(d)
        s.append(n)

s.show() # or 'midi'

About

Musical Rhythmic Duration Partitions

Topics

Resources

License

Stars

Watchers

Forks

Languages