We built a text editor in the last project. In the process, we looked at some common Tkinter widgets such as Menu, Buttons, Label, and Text. Now, let us now do some music. Let us build a cross-platform drum machine using Tkinter and some other Python modules.
In this project, we will build a programmable drum machine. The graphical user interface of the drum machine is based on Tkinter. You will be able to create an unlimited number of beat patterns using an unlimited number of drum samples. You can then store multiple riffs in a project and playback or edit the project later on.
To create your own drum beat patterns, simply load some drum samples using the buttons on the left. You can change the units that constitute a beat pattern, which in turn decides the tempo of the rhythm. You can also decide the number of beats per units. Most western beats have four beats per unit, waltz would have three beats per unit, and some Indian and Arabic rhythms that I composed on this machine had 3 to 16 beats per unit!
Don't be misled by the small size of the GUI. This is a powerful drum machine that can match features offered by some large commercial drum machine programs. By the end of this project, you should be in a position to extend it to outdo some of the commercial drum programs out there.
Some of the key features of the machine include:
A few drum samples are provided in the Loops
subdirectory; however, you can load any other drum sample. You can download a large number of samples for free from the Internet.
In the process of developing this program, we tweak Tkinter further and take a look at several important concepts and ideas that are normally encountered in GUI programming.
Some of the key objectives for taking up this project include:
grid
geometry managerpickle
moduleApart from these key concepts, we discuss several other vital nuggets of GUI programming in the course of the project.
In this project, we will use some more built-in libraries from the standard Python distribution. This includes Tkinter
, ttk
, tkFileDialog
, tkMessageBox
, os
, time
, threading
, wave
, and pickle
modules.
To verify that these modules do exist, simply run the following statement in the IDLE interactive prompt:
>>> import Tkinter, ttk, os, time, threading, wave, pickle, tkFileDialog, tkMessageBox
This should not cause an error as the standard Python distribution comes with these modules built into the distribution.
Other than this, you need to add an extra Python module called pymedia
.
The pymedia
module can be downloaded at http://pymedia.org/.
After you have installed the module, you can verify it by importing it:
>>> import pymedia
If no errors are rported, you are ready to program the drum machine. Let's start!
3.145.17.140