Music Creating-Rhythms
Combinatorial algorithms to generate rhythms
DESCRIPTION
This package provides most of the the combinatorial algorithms described in the book, "Creating Rhythms", by Hollos. Additionally, this module provides utilities that are not part of the book but are handy nonetheless.
The comp* methods are used to generate compositions of numbers. They are "the set of combinatorial variations of the partitions of n with the duplicates removed." The arguments passed to these functions determine the specific composition that is generated.
The neck* methods generate binary necklaces of a certain length with or without specific constraints on their intervals.
The part* methods are used to generate all possible partitions of an integer into smaller parts, either with or without specific constraints on the lengths of those parts.
NB: Some arguments are switched between book and this software.
MUSICAL EXAMPLE
from music_creatingrhythms import Rhythms
from music_drummer import Drummer
r = Rhythms()
beats = 16
kick = ''.join([str(num) for num in r.euclid(2, beats)])
snare = ''.join([str(num) for num in r.rotate_n(4, r.euclid(2, beats))])
hihat = ''.join([str(num) for num in r.euclid(11, beats)])
d = Drummer()
d.set_bpm(100)
d.set_ts()
for _ in range(8):
d.pattern(patterns={ 'kick': kick, 'snare': snare, 'hihat': hihat })
d.sync_parts()
d.show(format='midi')
METHODS
b2int
This method takes a binary string sequence like 110100 and converts it into a list of intervals like [1,2,3].
int2b
Convert intervals of the form [2,3] into a set of binary sequences.
r.int2b([[1,2,3]]) # [[1,1,0,1,0,0]]
r.int2b([[1],[2],[3]]) # [[1],[1,0],[1,0,0]]
cfcv
This method calculates the continued fraction convergent given a set of terms. It is used to find the best rational approximations to real numbers by using their continued fraction expansions.
r.cfcv(1, 2, 2) # [7,5]
cfsqrt
Calculate the continued fraction for sqrt(n) to m digits, where n and m are integers.
r.cfsqrt(2, 3) # [1,2,2]
chsequl
Generate the upper or lower Christoffel word for p and q.
Arguments:
t: required type of word (u: upper, l: lower)
p: required numerator of slope
q: required denominator of slope
n: optional number of terms to generate, default: p+q
r.chsequl('l', 11, 5, 4) # [0,1,1,0]
r.chsequl('u', 11, 5, 4) # [1,1,1,0]
comp
Generate all compositions of n.
r.comp(4) # [1,1,1,1],[1,1,2],[1,2,1],[1,3],[2,1,1],[2,2],[3,1],[4]
A "composition" is the set of combinatorial "variations" of the partitions of n with the duplicates removed.
compa
Generate compositions of n with allowed intervals p1, p2, ... pn.
r.compa(4, 1,2) # [[1,1,1,1],[1,1,2],[1,2,1],[2,1,1],[2,2]]
Here, the "intervals" are the terms of the partition.
compam
Generate compositions of n with m parts and allowed intervals p1, p2, ... pn.
r.compam(4, 3, 1,2) # [[1,1,2],[1,2,1],[2,1,1]]
Here, the "parts" are the number of elements of each interval set.
compm
Generate all compositions of n into m parts.
r.compm(4, 2) # [[1,3],[2,2],[3,1]]
Again, the "parts" are the number of elements of each interval set.
compmrnd
Generate a random composition of n into m parts.
r.compmrnd(16, 4) # [6,1,3,6], etc.
comprnd
Generate a random composition of n.
r.comprnd(16) # [1,3,2,1,1,2,1,3,2], etc.
count_digits
Count the number of a given digit in a string or vector.
r.count_digits(0, '100110100') # 5
r.count_digits(1, [1,0,0,1,1,0,1,0,0]) # 4
count_ones
Count the number of 1s in a string or vector.
r.count_ones('100110100') # 4
r.count_ones([1,0,0,1,1,0,1,0,0]) # 4
count_zeros
Count the number of 0s in a string or vector.
r.count_zeros('100110100') # 5
r.count_zeros([1,0,0,1,1,0,1,0,0]) # 5
de_bruijn
This method generates the largest de Bruijn sequence of order n, which is a cyclic sequence containing all possible combinations of length n with no repeating subsequences.
r.de_bruijn(3) # [1,1,1,0,1,0,0,0]
euclid
Generate a Euclidean rhythm given n onsets distributed over m beats.
r.euclid(2, 4) # [1,0,1,0]
invert_at
Invert a section of a parts binary sequence at n.
r.invert_at(2, [1,0,1,0,0]) # [1,0,0,1,1]
neck
Generate all binary necklaces of length n.
r.neck(3) # [1,1,1],[1,1,0],[1,0,0],[0,0,0]
necka
Generate binary necklaces of length n with allowed intervals p1, p2, ... pn. For these "necklace" class of methods, the word "intervals" refers to the size of a number given trailing zeros. So intervals 1, 2, and 3 are represented as 1, 1,0, and 1,0,0, respectively.
r.necka(4, 1,2) # [1,1,1,1],[1,1,1,0],[1,0,1,0]
neckam
Generate binary necklaces of length n with m ones, and allowed intervals p1, p2, ... pn.
r.neckam(4, 3, 1,2) # [[1,1,1,0]]
neckm
Generate all binary necklaces of length n with m ones.
r.neckm(4, 2) # [[1,1,0,0],[1,0,1,0]]
part
Generate all partitions of n.
r.part(4) # [1,1,1,1],[1,1,2],[2,2],[1,3],[4]
parta
Generate all partitions of n with allowed intervals p1, p2, ... pn.
r.parta(4, 1,2) # [1,1,1,1],[1,1,2],[2,2]
partam
Generate all partitions of n with m parts from the intervals p1, p2, ... pn.
r.partam(4, 2, 2) # [2,2]
partm
Generate all partitions of n into m parts.
r.partm(4, 2) # [1,3],[2,2]
permi
Return all permutations of the given parts list.
r.permi([1,0,1]) # [1,0,1],[1,1,0],[0,1,1],[0,1,1],[1,1,0],[1,0,1]
pfold
Generate "paper folding" sequences, where n is the number of terms to calculate, m is the size of the binary representation of the folding function, and f is the folding function number, which can range from 0 to 2^m - 1.
r.pfold(15, 4, 0) # [0,0,1,0,0,1,1,0,0,0,1,1,0,1,1]
This method generates "paper folding" sequences, which are binary sequences that represent the creases on a piece of paper after it has been folded multiple times in different directions. The arguments passed to this function determine the specific sequence that is generated.
To quote the book, "Put a rectangular strip of paper on a flat surface in front of you, with the long dimension going left to right. Now pick up the right end of the paper and fold it over onto the left end. Repeat this process a few times and unfold the paper. [There will be] a sequence of creases in the paper, some will look like valleys and some will look like ridges... Let valley creases be symbolized by the number 1 and ridge creases by the number 0..."
reverse_at
Reverse a section of a parts sequence at n.
r.reverse_at(2, [1,0,1,0,0]) # [1,0,0,0,1]
rotate_n
Rotate a necklace of the given parts, n times.
r.rotate_n(2, [1,0,1,0,0]) # [0,0,1,0,1]
SEE ALSO
https://abrazol.com/books/rhythm1/ - "Creating Rhythms", the book.
Please see the tests.py program in this distribution for method usage.
Metadata
Release files for music-creatingrhythms 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| music_creatingrhythms-0.1.8.tar.gz | 46.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| music_creatingrhythms-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 77.6 kB
Release files / music_creatingrhythms-0.1.8.tar.gz
| Download URL | music_creatingrhythms-0.1.8.tar.gz |
|---|---|
| Size | 46.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba3a1c8b640c26565778aba09e035ff26ff9e72f3885cb42c3dade941e3d9fbb
|
|
BLAKE2b-256 checksum How to use checksums |
277c539c950ec1ab342e6986ce9bd507309c0f86b86b4a99f9853859975d7f17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / music_creatingrhythms-0.1.8-py3-none-any.whl
| Download URL | music_creatingrhythms-0.1.8-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd31e09f10136416c174d5fcdd408035a1ce1e9f9b25b0a2312085295644c03e
|
|
BLAKE2b-256 checksum How to use checksums |
aa23e0a47d6fab2e38d89c415a0326d770d68bf484ec9b22ee02d1997458e2d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for music-creatingrhythms 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.