music.rhythm_to_durations

music.rhythm_to_durations(durations=(4, 2, 2, 4, 1, 1, 1, 1, 2, 2, 4), freqs=None, duration=0.25, bpm=None, total_duration=None)[source]

Returns durations from rhythmic patterns.

Parameters:
durationsinterable of scalars

The relative durations of each item (e.g. note).

freqsiterable of scalars

The number of the entry’s duration that fits into the pulse. If supplied, durations is ignored.

durationscalar

A basic duration (e.g. for the pulse) in seconds.

bpmscalar

The number of beats per second. If supplied, duration is ignored.

total_duration: scalar

The total duration of the sequence in seconds. If supplied, both BPM and duration are ignored.

Returns:
dursList of durations in seconds.

Notes

The durations parameter is considered to be in a temporal notation for durations/rhythm: each entry is a relative duration to be multiplied by the base duration given through duration, BPM or total_duration:

durs = [i*duration for i in durations]

The frequencies parameter is considered to be in a frequential notation: each entry is the number of the entry that fits a same duration (also given through duration, BPM or total_duration):

durs = [duration/i for i in freqs]

The examples above yield (two by two) the same sequences of durations by using duration=0.25 when in temporal notation or duration=4 when in frequency notation.

To facilitate the description of rhythms (e.g. for tuplets), some set of durations might be an iterable inside durations or frequencies. In this case:

### if mode is temporal:
    total_dur = cell[0]*duration
    # durations are proportional to remaining values:
    d_ = [i/sum(cell[1:]) for i in cell[1:]]
    durs = [i*total_dur for i in d_]
### if mode is frequential:
    total_dur = duration/cell[0]
    # durations are inversely proportional to remaining values:
    d_ = [i/sum(cell[1:]) for i in cell[1:]]
    durs = [i*total_dur for i in d_]

An example for achieving the same sequence of durations through temporal or frequential notation and with cells for tuplets is the last two sequences of the examples.

It might be a good idea to incorporate also this notation:

d2 = [1, 4, 1, 4]  # [quarter note + 4 sixteenth notes] x 2

Cite the following article whenever you use this function.

References

[1]

Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)

Examples

>>> dt = [4, 2, 2, 4, 1,1,1,1, 2, 2, 4]
>>> durs0 = rhythm_to_durations(dt, duration=.25)
>>> df = [4, 8, 8, 4, 16, 16, 16, 16, 8, 8, 4]
>>> durs0_ = rhythm_to_durations(freqs=df, duration=4)
>>> dtut = [4,2,2, [8, 1,1,1], 4, [4, 1,1,.5,.5], 3,1, 3,1, 4]
>>> durs1 = rhythm_to_durations(dtut)
>>> dtuf2 = [4,8,8, [2, 3,3,3], 4, [4, 3,3,6,6], 16/3, 16, 16/3, 16, 4]
>>> durs1_ = rhythm_to_durations(freqs=dtut2, duration=4)