Raspberry Pi Drum Machine

About: hobbyist musician/programmer.

Sample Sequencer! With a Raspberry Pi + Python.

The sequencer has 4 polyphony and allows the user to store and cue up 6 different sequences that they can alternate between in real time, and supports the ability to change between different samples, all mappable to your controller.

I wrote the script in a way that is totally operable with really any MIDI controller and sounds. Personally I use 18 different sound banks, 16 samples each, however adding or subtracting banks and samples is super easy and requires few modifications. If you have any trouble shoot me an email: auscarpenter@gmail.com

Find the code on GitHub at: https://github.com/auscarpenter/pythonsamplesequen...

Please let me know if you use it, and especially so if you make a video with it!

Step 1: Dependancies

This program requires the following (non built in) Python Modules:

mido

pygame

numpy

However, Mido throws some complications as Mido itself requires a few dependancies. In order to make sure they all get installed, just type in the following commands into the terminal of your Raspberry Pi (omitting the '$') and all will be well. The other modules can be installed normally.

$ sudo apt-get update

$ sudo apt-get install build-essential

$ sudo apt-get install libasound-dev or libasound2-dev

$ sudo apt-get install libjack0

$ sudo apt-get install libjack-dev

$ sudo apt-get install python-pip

$ sudo apt-get install python-dev

$ sudo pip install python-rtmidi

$ sudo pip install mido

Step 2: Configure Midi Input Values

Within the main Python Script there exists an array called noteList that is comprised of 16 integers (line 165.) These are the MIDI note values that our controller sends to the Pi to trigger the sounds. Every midi controller is different though, so unless you also have an Akai LPD8 you'll most likely need to alter these values to match your device.

The Github repo also includes another script called "midihelp.py" that is made specifically for this purpose! All it does is print the input values from the first MIDI controller the computer recognizes to the console. All you'll have to do is replace these values in the array if they differ from the ones included in noteList.

The order to the notes also correlates to which sound effect per folder is played, so keep that in mind as well.

Step 3: Add Additional Folders With Samples

Sample kits within the script are stored via folders in the same directory, set up exactly how the 808 kit is within the GitHub file. This way I can have all sorts of different sample sets stored within folders that are easily organized and replaced.

The only thing to change in the script itself is the variable foldNum which just tells the script how many folders of samples there are. Currently the script has foldNum set to one because there is only one subfolder in the same directory (the 808 kit.) The maximum folders the script can handle at the moment is 18, which is how many I am using, however it's fairly trivial to alter this, let me know if you need help.

The names of the folders don't really matter (as long as they are all different) as the Script just reads the amount of folders in the same directory and grabs the paths that way. The names of the files themselves is important though, more on that in the next step.

Step 4: Add and Configure Additional Samples Within New Folders

Sounds are loaded into the sampler via folders in the same directory containing .wav files with names numbered between 0-15. See the included 808 folder for an example of this. EVERY subfolder with samples should look identical to one another.

The index of MIDI inputs in the array noteList corresponds exactly to the .wav file name.

For example:

  • when you trigger the MIDI note stored in noteList[0] the wav file 0.wav would play.
  • when you trigger the MIDI note stored in noteList[8] the wav file 8.wav would play.

I did this in part so that every single MIDI controller could be set up easily to work with the script, and also so I could easy extend or limit the sample and input number, as well as organize the files and the script so the kick drum sounds, for instance, would always be saved as 0.wav and would be triggered by the first MIDI note.

I've chosen 16 values somewhat arbitrarily to correspond to the 16 inputs on my controller, so if you would prefer to make a sequencer with only 1 sample, or with many more, all you would have to do is number the audio files accordingly and subtract or add the numbers stored within the noteList array to match.

If the included 808 kit works properly but you have trouble with your own samples the solution would most likely be to alter the sample rate of the files to match PyGame's 22,050khz sample rate and bit depth of 16. You can do this in Audacity or any other Audio editing software. They should work perfectly from there!

Step 5: Number Pad Reference!

Ok there is a lot of stuff going on within the sequencer, more than I initially had in mind, so I crammed quite a bit onto a Number Pad to match the increased functionality. This in mind, the Asterisk * and the Period. both operate as function keys.

REFERENCE

MAINFUNCTIONS

[8] - Toggle Metronome on and off

[9] - Toggle Recording Mode on and off

[Enter] - Play/Pause sequence

[0] - Delete Current Note in Sequence

[Num Lock and *] - Shut down

[MIDI Note and .] - Don't quantize to even numbers

TEMPO FUNCTIONS

[+] - Course Speed Up BPM

[-] - Course Slow Down BPM

[+ and *] - Rapidly Speed Up BPM

[- and *] - Rapidly Slow Down BPM

[+ and .] - Fine Speed Up BPM

[- and .] - Fine Slow Down BPM

SEQUENCE FUNCTIONS

[1-6] Recall Sequence 1-6

[1-6 and .] Store Sequence 1-6

[0 and .] Clear Current Sequence

CHANGING SAMPLE FOLDERS

[1-9 and *] - Change to Sample Pack in Folders 1-9

[1-9 and * and .] - Change to Sample Pack in Folders 10-18

SEQUENCE TIPS:

-Clear the current sequence [0 and .] and store it to any sequences you want cleared out of memory.

-Recall a sequence and store it to a different number to copy it.

Share

    Recommendations

    • Remix Contest

      Remix Contest
    • Build a Tool Contest

      Build a Tool Contest
    • Weaving Challenge

      Weaving Challenge

    Discussions

    0
    None
    lewisb42

    24 days ago

    As it happened, I had pretty much everything I needed close at hand. Thanks for a fun morning at our house. (Video is of my 6 y/o jamming while I record :) )

    https://www.youtube.com/watch?v=_GTiAX7SEAE

    I had to tweak the script a little -- my midi controller showed up as the 2nd device, and my keyboard doesn't have a numpad, so I had to change the key mappings. Also, you might mention this seems to only work on Python 3 (default on my distro was v2).