BBC micro:bit Music: All About That Bass - Meghan Trainor

Meghan Trainor on stage

Play the bass and the treble with this micro:bit pop song cover!

A superstar in both the US and the UK, Meghan Trainor's all about girl power, rocking a retro look... and of course she's also All About That Bass.
Once again we'll be using Python to put this song together. However, this time we're going one step further - not only are we doing the melody... you know we'll be doing the bassline too!
If that sounds a bit too intense, have a crack at The Vamp's Somebody to You activity or Little Mix's Hair activity to prepare you for this final challenge.

Getting Started

First off, we need to define what Python modules we're using. We want to play music in this script, so of course we're using the Music module!
"import music" typed into Python
We also need to state how quickly the song should play. Your micro:bit sets a default tempo of 120 Beats Per Minute (BPM) but All About That Bass is slightly faster - 135 BPM.
music.set_tempo(bpm=135)

Composing the Melody

To start with, let's build the melody. We really like the bridge just before the song's chorus - the lyrics of it go like this:
Yeah, my momma she told me don't worry about your size
She says, boys they like a little more booty to hold at night
You know I won't be no stick-figure, silicone Barbie doll,
So, if that's what's you're into
Then go ahead and move along
The melody here breaks down really nicely into repeating phrases. Here's how we've cut up the melody:
  • "Yeah my momma she told me don't worry about your-" and "You know I won't be no stick-figure, silicone Barbie-"
  • "She says: Boys, they like a little more booty to hold-" and "So, if that's what's you're into then go ahead and move-"
  • "Size"
  • "At night"
  • "Doll"
  • "Along"

Writing the long song chunks

The way we've split up the chorus gives us two longer lists and two short lists.
Here are the two longer lists written out in Python:
yeahMyMomma=["f#4:2", "g#", "a:3", "a", "a:2", "g#:3", "g#", "g#:2", "f#:3", "f#", "f#:2", "e:4", "c#:2", "e"]
sheSaid=["e4:2", "f#4", "g#:3", "g#", "g#:2", "f#:3", "f#", "f#:2", "e:3", "e", "e:2", "d:4"]

Writing the shorter song chunks

Each of the long bits of melody is paired with a shorter melody to end each line. These small parts are really fun to sing along to!
Here are all four shorter parts:
size=["d4:12", "r:16"]
atNight=["b3:2", "d4", "c#:12", "r:14"]
doll=["d4:6", "c#:2", "b3:8", "r:10"]
along=["d4:2", "d4", "c#4:6", "b3:2", "a3:6"]

Putting it all together

Now we have the main parts of our chorus written in lists, we can tell our micro:bit what order to play them in.
We want the music to play while the micro:bit is on, so first we'll type in 'while True:'.
Now we can start playing our music. The code for playing music is 'music.play()' with the name of a list or specific music notes inside the brackets.
Our lists cover almost all of the song and the pattern is really simple, but there are a few pauses and an extra note that need to be added in to have the final result sounding perfect. Here's what the playback code should look like:
music.play(wellMyMomma) #"Yeah my momma she told me don't worry about your-"
music.play(size) #"Size"
music.play(sheSaid) #"She says: Boys, they like a little more booty to hold-"
music.play(atNight) #"At night"
music.play("e4:2") #"You-"
music.play(wellMyMomma) #"Know I won't be no stick-figure, silicone Barbie-"
music.play(doll) #"Doll"
music.play(sheSaid) #"So, if that's what's you're into Then go ahead and move-"
music.play(along) #"Along"
music.play("r:12") #Rest for the remaining bar
Remember to make sure that the names of your lists here match the ones you wrote earlier. If anything is spelled differently, Python will get confused and give you an error!
Flash your code to your micro:bit and have a listen to the results! If there's an error don't panic - your micro:bit will tell you what line the problem is on, so look carefully and see if there's a spelling mistake or an indentation that's missing.
You can also look at our version of the All About that Bass (Melody) script for hints on how to get yours working.

Bonus: Make the bassline, too!

It wouldn't be All About that Bass without... the bass, right? So here's a quick script to do the bassline, too.
Start a new Python script for this one, using the same tempo as the melody we've just written.
The bassline is very simple, so instead of building the full tune out of multiple lists, we can use just the one list here.
Oh, and a hint for you - in Python, as long as the contents of list is kept inside [square brackets] and each item is separated by a comma, you don't need to write all of your list on one line.
This means that for a long list like the one we're about to write, we can split up the contents into lines and make it much easier to read.
bassline = [
'r:12',
'a1:6', 'c2:2', 'c#', 'e:4', 'c#:2',
'a1:4', 'r:12',
'b1:6', 'c#2:2', 'd', 'f#:4', 'd:2',
'b1:4', 'r:12',
'e1:6', 'g:2', 'g#', 'b:4', 'g#:2',
'e:4', 'r:12',
'a1:6', 'c2:2', 'c#', 'e:4', 'c#:2',
'a1:4'
]
Since it's just the one list, playback is really simple - use the 'music.play()' command to get the bass pumpin'.
As ever, you can look at our version of the All About that Bass (Bassline) script for a working example of the code.