Skip to main content

Partition a musical duration into a rhythmic phrase

Project description

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 x 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'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

random_rhythms-0.1.11.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

random_rhythms-0.1.11-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file random_rhythms-0.1.11.tar.gz.

File metadata

  • Download URL: random_rhythms-0.1.11.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for random_rhythms-0.1.11.tar.gz
Algorithm Hash digest
SHA256 4e6ccd42d87a1e91359c3ae2f7636de134d10dbd33b461455e697505ad15be9e
MD5 9b65e74b671803a2236391a795ef2968
BLAKE2b-256 968b17d132b6869f7cf4900ecfec3a391c3e26c2e5590b44587da08845dd5fdc

See more details on using hashes here.

File details

Details for the file random_rhythms-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for random_rhythms-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5d929abc8586caf801c1f6a4ba2e754967b615297d1af386f28e37a635ccee54
MD5 2bb2d8394e26c3c0d913019b3e589df8
BLAKE2b-256 b621e51d0d16db010574037fcd349fa5df8c6aa5fd5fea8e1d44d58e32075d3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page