Author: dandersen

Markov Melodies

This module will show you how to make music using Markov chains. If you’re not familiar with Markov chains, this page gives a great, interactive introduction. The basic idea is that we can input melodies of a certain style, and our model will output similar melodies that reflect that style. First, start up Python and […]

Transposition Functions

This module builds on the Transposition module by illustrating how to create transposition-related functions. In the previous module, we covered how to identify how two melodies were related by transposition. In this module, we’ll create a few transposition-related functions. Let’s start out with a function to transpose a given melody. We’ll use the violin melody […]

If Statements (Python)

This tutorial module covers conditional if…else statements in Python. In Python, we use if to determine whether a certain condition has been satisfied. The if statement establishing the condition is aligned to the left, and the operation dependent on the condition is indented: We can use the keyword “elif” (short for “else if”) to add […]

Skips and Steps and Style (and Chords)

This module builds on the previous Skips and Steps and Style module. In the previous module, we counted the skips and steps in Maple Leaf Rag, a piano composition by Scott Joplin from the late nineteenth century. Here’s a summary of our work so far (see the previous module for the code for the count_skipstep […]

Finding Examples

This module will help you find musical examples to study or use in the classroom. This page gives an overview of the files included in the music21 corpus. Click here for help importing files, or click here once you have a file imported to extract specific parts. MusicXML is an emerging standard for digital notation […]

Skips and Steps and Style

This module explores the prevalence of melodic skips and styles in different styles of music. It builds directly on the techniques covered in the Skips and Steps module. In the previous module, we established that melodic steps are significantly more prevalent than skips in the Kyrie of the Pope Marcellus Mass: While in the previous […]

Skips and Steps

The module introduces the concept of melodic skips and steps. Skips and steps refer to the distance, or interval, between two notes in a melody. Most melodies are made up of a combination of steps (short distances or small intervals) and skips (large distances or wide intervals). Many musical traditions exhibit a consistent preference for […]

Functions (Python)

This tutorial module demonstrates how to create a function in Python. A function is a block of code that runs when called. In computational music research, functions may be used to define common tasks or operations that will be applied to different musical works or excerpts. The keyword def is used to define a function. […]


This module demonstrates how to perform the post-tonal transposition operation on pitches and pitch classes. There are two ways of thinking about transposition in post-tonal music: as a way of measuring distance between notes, or as an operation that can be applied to notes. Let’s start with two notes, G4 and C5, given as 67 […]

Extracting Parts and Melodies

This module explains how to extract a part or melody from an existing piece of music. Rather than manually entering all of the notes of a melody, we can import a musical work into music21 and then return the MIDI note numbers. We can import a work from a file, or from the online music21 […]