/curriculum/activities/livecode-reggaeton/
Learn to code a basic Reggaetón beat using your own Python functions.

Lesson Plan

Functional Reggaetón Beat

Learn to code a basic Reggaetón beat using your own Python functions.

Level

Intermediate

Time

45 minutes
Try It

Reggaetón originated in Puerto Rico during the late 1990s and today is regarded as one of the most popular styles of music worldwide. Reggaetón consists of an easy-to-code pattern of kick and snare drums. We'll start by coding the basic pattern, and then we'll learn how to use our own functions to make the pattern more interesting.

Here's what the basic pattern looks like:

Step 1: Create a new project

  • Log into TunePad and create a new project.
  • Name your project Reggaetón Beat

Step 2: Code the Basic Pattern

  • Add a new Drum cell to your project
  • Set the instrument to Drums → Headlines Drums
  • Add this code for the kicks and snares.
/# Kick drums for i in range(4): playNote(0) / /# Snare drums rewind(4) for i in range(2): rest(0.75) playNote(2, beats = 0.75) playNote(2, beats = 0.5)

Can we make it more interesting?

This is a great beat pattern, but it also gets repetative (just like our other beats). Music producers and drummers will add variety to a beat by switching up the pattern, adding different instruments, adding effects, and adding drum fills or breaks. We can do all of these same things with computer code!

User-Defined Functions

In this activity, we'll explore one powerful technique called user-defined functions. Essentially, a function lets us take a bunch of code and give it a nickname. Then we can use that code over and over again by calling the nickname as a shortcut. This helps keep code neat and easy to understand. It also helps with live coding because you can define a bunch of helper functions ahead of time that you call during the performance.

Here's what a function looks like:

def basic_beat():
    for i in range(4): playNote(0)
    rewind(4)
    for i in range(2):
        rest(0.75)
        playNote(2, beats = 0.75)
        playNote(2, beats = 0.5)

All we've done here is take the code from STEP 2 above and copy it inside a function definition.

  • The def keyword on line 1 says we're defining a function
  • The name of the function can be anything you want as long as it's a valid Python identifier (more on that later).
  • We've called this function basic_beat.
  • The parentheses after the function name are for the function's parameters. This function doesn't have any parameters, so it's just empty.
  • The colon character at the end of line 1 says that the next lines will be the function's body.
  • Finally, everything that we want to include in the function (lines 2-8) is indented by four spaces

Defining Some Functions

Now let's define several functions to create a more interesting beat pattern. In the code below, we've created three functions called variation1, variation2, and variation3. But just defining the functions doesn't do anything yet. To actually play the music we need to call the functions, which we do starting on line 20.

/# The first variation just has kick drums def variation1(): for i in range(4): playNote(0) / /# The second variation plays kick drums and adds snares def variation2(): variation1() rewind(4) for i in range(2): rest(0.75) playNote(2, beats = 0.75) playNote(2, beats = 0.5) / /# The third variation adds hi-hats def variation3(): variation2() rewind(4) for i in range(8): playNote(5, beats = 0.5) / variation1() # call the functions to play the music variation2() variation3() variation3()