Tag: tutorial

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 […]

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 […]

Viewing Notation

This brief tutorial module explains how to view notation in the music21 environment. After you install music21, you must configure it for your system. As part of this process, you must install or specify a software program to display notation in the MusicXML format. The instructions for this configuration process are included as part of […]

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 […]

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 […]

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. […]

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 […]

Basic Math (Python)

This tutorial module surveys some of the basic math functions in Python. We can perform a mathematical operation on any numeric data type: Some additional functions include min (minimum) and max (maximum), which return the lowest and highest values in a sequence: You can use len to find the length of a list: Further functions […]

Melodies and MIDI Notes

This module describes how to transform a melody into a sequence of MIDI notes using music21. There are many instances in computational analysis when it is useful to represent notes as numeric values. For example, using numbers can be useful for music theoretical analysis, and for performing mathematical operations, such as those common to post-tonal […]