Making and understanding music with Python and a little bit of Math

Audience level:
March 8th 1:20 p.m. – 4:40 p.m.


Are you interested in learning more about Music but have found most material to be kind of patronizing or to present things magically instead of logically? The good news is that much of music can be understood with programming and math, two things you're already good at! In this hands-on workshop you'll learn some elements of music from a (Python) programmer's perspective.


There are (many) music operations that can be expressed directly in Math and code. Just to give you a taste, tranposing a set of notes to an interval i is as simple as [(n + i) % 12 for n in notes].

In this tutorial we'll explore the primitives of Music (notes, intervals, dynamics, articulations, and duration), take a look inside them, the means of combining those primitives (motives, chords, operations such as transposition, retrograde, inversion), and the means of abstraction (phrases, harmonic functions and progressions, and form) using Python and some basic Math. At the end of this tutorial you should have a demysthified understanding of many elements of Music and be able to use Python to create short compositions.


  • Primitives of Music [15']

    A general view of notes, intervals, dynamics, articulations, and duration and how to represent them in Python.

  • Means of combination [35']

    • Motives: combination of notes horizontally
    • Chords: combination of notes vertically
    • Operations on sets of notes: transposition, retrograde, inversion, stretching, and compression
    • Filtering functions
  • Practice [45']

    • generate simple combinations
    • generate combinations with operations
    • generate combinations with filters
  • Break [15']

  • A look inside the Primitives [25']

    • How many notes are there? Pitch, notes, frequencies
    • Envelopes, the contour of sound
    • What really is articulation?
    • The harmonic series: a building block
    • The beautiful math of temperament systems
    • Examples
  • Practice [15']

Play with frequencies and interval relations

  • Means of abstraction (How to think like a composer) [15']

    • Phrases
    • Harmonic functions and progressions
    • Form
  • Practice [15']

    • create a simple phrase using the combinations generated in the previous practice session


This tutorial is aimed at intermediate Python programmers but no music knowledge is necessary. You don't need to know how to read music, but we'll use music notation as a graphical debugger. On the Python side, you should know how to use list comprehensions, lambda, high-order functions, and object-oriented.

You can find a list of required libraries and programs, with installation instructions at