adamcogen / drum-machine-py-poc

Polyrhythmic drum machine proof-of-concept written in Python
0 stars 0 forks source link

Polyrhythmic Drum machine

Polyrhythmic drum machine

About

Every drum machine I've ever encountered only lets you subdivide using powers of two (quarter note, 8th note, 16th, 32nd, etc.) and triplets. This is a drum machine that lets you subdivide measures by any number you want!!!!! The drum machine just outputs midi, the same way a hardware midi controller keyboard would, so you can map any midi-triggered drum samples to work with it. The drum machine doesn't handle audio samples, it just outputs midi. You can use a DAW or something to map samples to each midi note.

I'd recommend closing any applications you don't need to have open when running this, because having a bunch of stuff open on your computer will make the machine run slow.

Currently the drum machine has literally no input validation. If you give it bad text inputs it will throw errors and crash etc.

Installation:

Compressed installation instructions (Mac):

Run these commands in your computer's terminal application, one at a time.

     # check if you have python 3
     python3 --version

     # if you don't have python 3, install homebrew
     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

     # then install python 3
     brew install python

     # if you already have homebrew and python 3, make sure python 3 is up to date
     brew update
     brew upgrade python3

     # then install mido and python-rtmidi, for python midi support
     pip3 install mido
     pip3 install python-rtmidi

Next, set up a virtual midi port.

This software is designed to be used with some kind of DAW that can map midi input to drum samples. The drum machine works the same way a hardware midi controller keyboard works, outputting midi to the DAW. I arbitrarily use Reason 7's Redrum but probably any DAW with built-in midi instruments will work. The drum machine sends its midi output to the virtual midi port, and the DAW takes the virtual midi port as its input device. Just select the virtual midi port you just set up, which should be called IAC Driver Bus 1, as your midi input device within your DAW and it should work.

Running the drum machine

If you've done all the stuff in the Installation section, you should be able to type these commands into your computer's terminal application to start the drum machine:

# this is assuming that the drum machine folder is on your desktop
cd ~/Desktop/drum_machine_5
python3 drum_machine_5.py

How to use

I tried to make everything as self-explanatory as possible.

Unlabelled buttons

The non-text buttons going down the left side of the drum machine are (from top to bottom):

Midi note and velocity

Tempo

Normally tempo is defined in terms of beats-per-minute, but with so much freedom to change subdivisions, "beats-per-minute" becomes confusing. Instead, the software measures tempo in terms of the length of the full pattern in milliseconds (length in milliseconds). You can do some scratch paper calculations to figure out the number of milliseconds needed for a particular BPM. Currently only integer values are supported for length in milliseconds.

Other tips and tricks

Save-file format

You can save and load patterns as .txt files. Their format will be (anything between brackets [] would be replaced with actual data):

length_in_milliseconds: [length]
number_of_rows: [number]
[subdivision of first row] [beat, zero-indexed],[pitch],[velocity] [beat, zero-indexed],[pitch],[velocity] [etc.]
[... more similar rows ...]
[subdivision of last row] [beat number, zero-indexed],[pitch],[velocity] [beat number, zero-indexed],[pitch],[velocity] [etc.]

Editing the code for extra functionality

Some useful functionality hasn't been added to the actual GUI yet, and you can get to it by editing the code itself.