Tag: python


This module introduces the concept of musical pitches. In the western art music tradition, musical notes or pitches are represented by letters of the alphabet. We use the letters A through G, and then begin with A again. In Python, we can use a list to represent these letters in order: If we want to […]

Installing Python Libraries

In this module, we will explore how to install libraries or packages to Python on your computer. Python comes installed with many features, but from time to time we need specialized tools that must be downloaded separately. These are called libraries or packages. Some common Python libraries include numpy, matplotlib, and pandas. Lots of Linewaves […]

Classifying Genre Using Machine Learning, Part I

In this module, we will use machine learning to classify songs by genre. This module is the first in a series on using classifying songs by genre using machine learning. This module takes a simplified approach to machine learning, introducing fundamental concepts along the way. We will use tools from the Orange Data Mining Library. […]

Pedal Point

This module illustrates how to identify and analyze a pedal point. This module requires the music21 package. A pedal point is a tone that is sustained (or repeated) through several different chords or harmonies. It is often, but not always, in the lowest voice. Typically, it will function as a chord tone in some of […]

Scale Degrees

This module explores how the notes in a melody can be represented as degrees of a scale. This module requires the music21 package. All major and minor scales (known collectively as “diatonic” scales) contain seven different notes. After the seventh note, the first note repeats again. For example, the C major scale contains the notes […]

Cantus Firmus, Part II

This module is a continuation of the previous module on composing a cantus firmus. In this module, we will continue our algorithmic approach to generating a well-formed cantus firmus based on clearly defined rules and guidelines. In the previous module, we created a function that was responsive the following principles: We nested the random_note() function […]

Cantus Firmus, Part I

This module explores the basics of composing a cantus firmus. The cantus firmus is a melody that forms the basis for polyphonic music and other musical textures that employ strict counterpoint, including specifies counterpoint exercises. The cantus firmus must exhibit certain musical qualities to be considered “well-formed,” including smoothness, motion, and variety. We’ll use the […]

While Loop (Python)

This tutorial module explains the syntax and usage of while loops. While loops are loops that continue to run while a given condition is satisfied. This stands in contrast to for loops, which run over a range or sequence. (Compare the use of conditional logic here with if statements.) This block of code prints the […]

Importing Notation

This brief tutorial module illustrates how to import music notation files into the music21 environment. There are two main approaches to importing notation: importing from a file on your computer, or from a file in the music21 corpus. To import from a file (whether you created it or downloaded it), replace the directory in quotation […]

Voice Roles, Part II

This module is a continuation of the previous module exploring the roles of the different voices in a four-part texture. We’ll continue with J. S. Bach’s Jesu, meine Freude: Let’s load the chorale in music21: The four voices are aligned vertically in the score to reflect their usual relationship to one another in terms of […]