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

Welcome to TunePad

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

Welcome to TunePad

TunePad is an online learning platform that lets you create music with the Python programming language. TunePad was developed at Northwestern University with funding from the National Science Foundation. It's free for everyone to use, and we will never sell your personal information.

What is Python Programming?

Python logo
  • Python is one of the most widely-used programming languages in the world.
  • It's 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, and video game development.
  • 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.

/playNote(0) /playNote(0) /playNote(0) /playNote(0, beats = 0.5) /playNote(0, beats = 0.5) /

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 playNote(2) # play sound number 2 (snare drum) rest(1) playNote(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 hi-hat sounds between the kicks and snares.

/# play hi-hats /for i in range(4): / rest(0.5) # rest for half a beat / playNote(4, beats = 0.25) # play two hi-hat sounds / playNote(4, beats = 0.25) # each for 0.25 beats /

Bass!!

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

/playNote(33, beats = 4) /playNote(36, beats = 4) /playNote(35, beats = 4) /playNote(34, beats = 3) /playNote(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 /playNote([57, 60, 64], beats = 4) /playNote([55, 60, 64], beats = 4) /playNote([55, 59, 62], beats = 4) /playNote([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: / playNote(note, beats = 0.5) / /for note in [ 55, 60, 64, 60] * 2: / playNote(note, beats = 0.5) / /for note in [ 55, 59, 62, 59] * 2: / playNote(note, beats = 0.5) / /for note in [55, 58, 60, 58] * 2: / playNote(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 21 tutorials ⇨
Chicago House Beat

Chicago House Beat

In this short warmup activity, create a Chicago House beat using Python code.
Beginner
Bad Bunny Remix

Bad Bunny Remix

Learn to use lists in Python to create chords. Practice using chords together to make progressions.
Beginner
Bassthoven

Bassthoven

Use Python lists to create longer melodies with this remix of Bassthoven by Kyle Exum.
Advanced
Halloween Theme

Halloween Theme

Practice using functions and parameters in Python to play repeated patterns. Practice with variables, lists, and operators
Intermediate

TunePad Puzzlers

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

Browse all 7 puzzlers ⇨
Taylor Swift Mystery Melody

Taylor Swift Mystery Melody

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

Another Mystery Melody

Use your understanding of variables, lists, functions, and for-loops to fix all of the syntax errors and reveal the mystery melody!
Expert
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
Underwater Mystery Melody

Underwater Mystery Melody

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

TunePad Interactives

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

Browse all 5 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.