Get started creating music with code! This guide walks through the basics of coding music with Python in TunePad

TunePad Quick Start Guide

Get started creating music with code! This guide walks through the basics of coding music with Python in TunePad

Level

Beginner

Time

15-20 minutes

What is TunePad?

TunePad is a free learning platform for creating music using the Python programming language. It was developed at Northwestern University with funding from the National Science Foundation. TunePad is free for everyone to use, and we will never sell or share your personal information.

What is Python Programming?

Python logo
  • Python is one of the most widely-used programming languages in the world.
  • Python is easy to read and write, which makes it a popular choice for beginners.
  • It’s also powerful, which makes it a good choice for professionals.
  • Python is used for data science, artificial intelligence, web development, art, music, video game development, and more.
  • Python is a “text-based” language, which means that you type code instead of dragging blocks on the screen.

Try It!

Here's an example of what TunePad can do. This Python code plays five notes using a kick drum sound. Press the ▶ button below to hear how it sounds.

/play(0) /play(0) /play(0) /play(0, beats = 1/2) /play(0, beats = 1/2) /

You use the play function to play a specific note or drum sound. Each drum sound has its own number that you can see on the drum pad below the Python code. The beats part on the last two lines of code says how long each note should last. The last two sounds will play for half a beat each. Details of the play function

Adding Snare Drums

To make this beat more interesting, we can add layers of sound. This cell adds two snare drum sounds to play on beats 2 and 4. Try playing this cell while also playing the kick drums at the same time. In TunePad all cells will synchronize together.

# play two snare drums on beats 2 and 4 rest(1) # skip a beat play(2) # play sound number 2 (snare drum) rest(1) play(2) /

The text that comes after the hashtag symbol (#) is called a comment. It’s a note for human coders to help document their code. Anything that comes after the hashtag on a line is ignored by Python.

Hi-Hats

Let's keep layering sounds! This cell uses a loop in Python to add a run of 16 hi-hat sounds.

/# play 16 hi-hats in a row /for i in range(16): / play(4, beats = 0.25) / / / /

Bass!

Don't forget the bass! This cell adds a simple bass line.

/play(33, beats = 4) /play(36, beats = 4) /play(35, beats = 4) /play(34, beats = 3) /play(34, beats = 1) / /

Harmony?

In TunePad, you can add as many cells as you want to your project and select from over 170 different instrument. You can change your code while the music is playing to test out different ideas live and in real time.

/# You can play a chord in TunePad by using a list of note values /play([57, 60, 64], beats = 4) /play([55, 60, 64], beats = 4) /play([55, 59, 62], beats = 4) /play([55, 58, 60], beats = 4) /

Arpeggios

To wrap this example up, let's add some arpeggios. Arpeggios are just chords played one note at a time. In Python we can use a for loop to experiment with different patterns of notes.

/for note in [ 57, 60, 64, 60] * 2: / play(note, beats = 0.5) / /for note in [ 55, 60, 64, 60] * 2: / play(note, beats = 0.5) / /for note in [ 55, 59, 62, 59] * 2: / play(note, beats = 0.5) / /for note in [55, 58, 60, 58] * 2: / play(note, beats = 0.5) /

What's Next?

Start creating your own music! Go to tunepad.com and log in with a gmail account or create a new account with a different email address. Once you're logged in, click on the New Project button. You can also learn more by trying some of these resources:

Song Tutorials

TunePad tutorials give step-by-step instructions for recreating popular songs.

Browse all 22 tutorials ⇨
Chicago House Beat

Chicago House Beat

In this short warmup activity, create a Chicago House beat using Python code.
Beginner
Hedwig's Theme from Harry Potter

Hedwig's Theme from Harry Potter

Recreate the iconic melody from Harry Potter.
Beginner
Bad Bunny Remix

Bad Bunny Remix

Learn to use lists in Python to create chords. Practice using chords together to make progressions.
Beginner
Still D.R.E.

Still D.R.E.

Learn to use variables in Python to make your code more readable. Use loops to create repeated musical elements.
Beginner

TunePad Puzzlers

TunePad puzzlers are games and challenges designed to sharpen your music+coding skills.

Browse all 4 puzzlers ⇨
Underwater Mystery Melody

Underwater Mystery Melody

See if you can fix all of the syntax errors to reveal the mystery melody!
Beginner
Dark Side Mystery Melody

Dark Side Mystery Melody

See if you can fix all of the syntax errors to reveal the mystery melody!
Intermediate
Suspenseful Mystery Melody

Suspenseful Mystery Melody

See if you can fix all of the syntax errors to reveal the mystery melody!
Intermediate
Fix Someone Like You

Fix Someone Like You

Adele is sad because of the code someone wrote for her song in TunePad. See if you can make the Python program better.
Intermediate

TunePad Interactives

TunePad interactives are tools to help explore the connections between music and code.

Browse all 4 interactives ⇨
TunePad Beat Composer

TunePad Beat Composer

Experiment with digital drum sounds and create your own rhythmic patterns for TunePad.
Interactive Drum Kit

Interactive Drum Kit

Learn the names and sounds of percussion instruments. Get the TunePad command to play different drum sounds.
TunePad Drum Scope

TunePad Drum Scope

See waveforms for different accoustic drum sounds. Create your own drum patterns and see the resulting TunePad code.
TunePad Piano

TunePad Piano

Learn note names and values with this interactive piano keyboard.

TunePad Documentation

Ready to dig in? Read the documentation for all of the TunePad functions and modules.