Music Drummer
Glorified Metronome
DESCRIPTION
The methods of this package depend upon music21.
For this package (and music21 too), a duration of 1 is a quarter-note. So, 1/2 would be an eighth-note, etc.
For this package, the (general MIDI) kit is made up of the following instrument types (and defaults):
'kick' (default: 'kick1')
'snare' (default: 'snare1')
'hihat' (default: 'hihat1')
'toms' (default 'tom3')
'cymbals' (default: 'crash1')
'percussion' (default: 'woodblock1')
Each above type includes a music21 Part and a beat counter (that starts at 0 of course).
The known instruments and their names, MIDI numbers, and types can be seen by printing the return of instrument_map().
The high-hats are special-cased and are named closed, open, and pedal. All are added to the hihat Part, so that they can interact with each other. In a pattern(), besides 0 and 1, the special 2 and 3 digits can be used to indicate that the open and pedal high-hat should be played. This allows the high-hats to interact in that method.
You can change default instruments with the set_instrument() method. This is most useful for the kick and snare types, because there are two variations for each: acoustic and electric.
SYNOPSIS
from music_drummer import Drummer
# basic 4/4 metronome groove:
d = Drummer()
d.set_bpm(60) # set the beats per minute
d.set_ts() # set the default time signature of 4/4
# add a 16-beat phrase for 64 measures
for _ in range(64):
d.pattern(
patterns={
'kick': '1000000010000000',
'snare': '0000100000001000',
'hihat': '2310101010101010',
},
)
d.sync_parts() # make the parts play simultaneously
d.show(format='midi') # or nothing, ='text', etc. see music21 docs
# it don't mean a thing, if it ain't got that swing
d.pattern(
duration=1/2,
swing=67,
straight=['kick'],
single=['snare'],
patterns={
'kick': '1000000010100000',
'snare': '0000100000001000',
'hihat': '1010101010101010',
}
)
# 5/8 groove with intro:
d = Drummer()
kit = d.instrument_map() # get all the known kit instruments
sidestick = d.instrument_map(name='Side Stick')
sidestick = d.instrument_map(num=37)
d.set_instrument('kick', 'kick2') # change to the electric kick
d.set_instrument('snare', 'snare2') # change to the electric snare
d.set_bpm(99) # change the beats per minute from 120
d.set_ts('5/8') # change the time signature from 4/4
d.count_in(2) # count-in on the hi-hats for 2 measures
d.rest('kick', duration=10)
d.rest('snare', duration=10)
d.rest('cymbals', duration=10)
d.rest('toms', duration=10)
# 3 known hi-hat states: closed, open, pedal
d.note('closed', duration=1/2)
d.note('open', duration=1/2)
d.note('pedal', duration=1/2)
d.note('closed', duration=1/2)
d.rest(['snare', 'kick', 'cymbals', 'toms'], duration=2)
# 7 known cymbals
d.note('crash1')
d.note('crash2')
d.note('china')
d.note('splash')
d.note('ride1')
d.note('ride2')
d.note('ridebell')
d.rest(['kick', 'snare', 'hihat', 'toms'], duration=7)
# 6 known toms
d.note(['tom1', 'tom2', 'tom3', 'tom4', 'tom5', 'tom6'], duration=1/3)
d.rest(['kick', 'snare', 'hihat', 'cymbals'], duration=2)
# add a eighth-note snare flam to the score
d.note('snare', duration=1/2, flam=1/16)
d.rest(['kick', 'hihat', 'cymbals', 'toms'], duration=1/2)
# add a 5-note snare roll for an eighth-note, increasing in volume
d.roll('snare', duration=1/2, subdivisions=5, crescendo=[100, 127])
d.rest(['kick', 'hihat', 'cymbals', 'toms'], duration=1/2)
# crash and kick!
d.note(['kick', 'crash1'], duration=1/2)
d.rest(['snare', 'hihat', 'toms'], duration=1/2)
# add a 4-part, 8-bar, eighth-note phrase to the score
for _ in range(4):
d.pattern(
patterns={
'kick': '1000000010',
'snare': '0000001000',
'hihat': '2311111111',
},
duration=1/2
)
d.sync_parts() # make the parts play simultaneously
m = d.to_mido() # convert to a format mido can understand
d.show() # or format='text', format='midi', etc. see music21 docs
# or
d.write() # or filename='groove.mid' for example
Musical Examples
from music_drummer import Drummer
d = Drummer()
d.set_bpm(70)
d.set_ts()
for _ in range(8):
d.pattern(
patterns={
'kick': '1000000010000000',
'snare': '0000100000001000',
'hihat': '2310101010101010',
},
)
d.sync_parts()
d.show('midi')
import mido
import random
import sys
from music_drummer import Drummer
port_name = sys.argv[1] if len(sys.argv) > 1 else 'USB MIDI Interface'
random_bits = lambda: f'{random.getrandbits(16):016b}' # 16-bit beat-string
with mido.open_output(port_name) as outport:
print(outport)
d = Drummer()
d.set_bpm(60)
d.set_ts()
kick = random_bits()
snare = random_bits()
hihat = random_bits()
for _ in range(8):
d.pattern(
patterns={
'kick': kick,
'snare': snare,
'hihat': hihat,
},
)
d.sync_parts()
m = d.to_mido()
for msg in m.play():
outport.send(msg)
SEE ALSO
The test file and examples directory in this distribution.
Metadata
Release files for music-drummer 0.4.0
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 | Actions |
|---|---|---|---|---|
| music_drummer-0.4.0.tar.gz | 45.5 kB | Without provenance | Details for music_drummer-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| music_drummer-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for music_drummer-0.4.0-py3-none-any.whl |
Total release size: 76.5 kB
Release files / music_drummer-0.4.0.tar.gz
| Download URL | music_drummer-0.4.0.tar.gz |
|---|---|
| Size | 45.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41fec6f22d1381a77e17375310e9fb35a1b1c71a32f29e904408bff6132d96cd
|
|
BLAKE2b-256 checksum How to use checksums |
f5c1624bc074568814abd8814f0588836423ffc12fac9e79f2d1a770146ed066
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / music_drummer-0.4.0-py3-none-any.whl
| Download URL | music_drummer-0.4.0-py3-none-any.whl |
|---|---|
| Size | 31.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c27160bb34bc86214a21c16860106b098a3f5988591a84399d7dd684c339ae06
|
|
BLAKE2b-256 checksum How to use checksums |
77f8f7be21dcdfdb2fe2168a3ae06cef6a5522d5c4d1f57017fa564db5f8d78e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for music-drummer 0.4.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.