Author: dandersen

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

Pitch and Pitch Class

In this module, we’ll find the pitch class for each pitch of a melody. In post-tonal music, we draw a distinction between pitch and pitch class. Pitch refers to a specific note in a specific range. Pitch class refers to a class of notes that share the same name, plus enharmonic equivalents. A good analogy […]

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

Fundamentals (Python)

Python is a general-purpose programming language widely used in a variety of fields, including computational humanities research (and computational musicology in particular). Once you have Python installed, type the following and hit enter to print your first message: The print function displays the elements in parentheses in the console window. This can be a string […]

For Loop (Python)

A for loop is used to iterate over a list or other sequence. The for loop is a fundamental building block of Python programming. Let’s say we we have values stored in a list (notes, intervals, rhythms, etc.) and we want to step through or iterate through them in order to display them or perform […]

List Comprehension (Python)

A list comprehension is a concise way to build a list. It is often used in place of a for loop when creating a new list based on an existing list. For example, let’s say we have a list of pitches (MIDI note numbers) and we would like to generate a list of pitch classes: […]

Python Installation

Get started with Python by following the installation instructions. Here are a few options we recommend for running Python: Terminal (Mac) You can run Python directly in the Terminal on a Mac (Applications -> Utilities -> Terminal). This allow you to get going right away without installing any additional software. Using an IDE You can […]

Music21 Installation

This quick tutorial post explains how to install music21, a library of musicological tools for Python. How to install music21 on a Mac. How to install music21 on a PC (Windows). Once you install music21, you can load it in Python with a single line of code: You must configure music21 the first time you […]