Chapter 3. Programmable Drum Machine

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.

Mission Briefing

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.

Mission Briefing

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!

Why Is It Awesome?

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:

  • Large number of beats
  • Large number of patterns to accompany songs
  • Variable number of beats per pattern
  • Use of 16 bit, 44100 kHz WAV samples (mono or stereo)
  • Support for various file formats
  • Ability to save projects comprising of several patterns

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.

Your Hotshot Objectives

Some of the key objectives for taking up this project include:

  • Understanding how Tkinter is normally applied in context of OOP
  • Working with a few more Tkinter widgets such as Spinbox, Button, Entry, and Checkbutton
  • Working with the grid geometry manager
  • Working with ttk-themed widgets
  • Understanding threaded programming in relation to Tkinter
  • Working with other common modules from the Python standard library
  • Object persistence with the pickle module

Apart from these key concepts, we discuss several other vital nuggets of GUI programming in the course of the project.

Mission Checklist

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!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.140