Play random melodies with various scales and instruments.
Run the code to create a musical note, then click the Play button to hear it. Try note numbers other than 0:
SoundNote denotes a musical note. Pitch 0 is middle C:
SoundNote by itself doesn’t make a sound. Put it inside Sound to make a playable note (click the Play button to play the note):
Play the note immediately with EmitSound:
Play a sequence of notes. Try other sequences:
To play a sequence of notes, put the notes in a list (indicated by the curly braces):
This is how the note numbers correspond to piano keys:
Lower notes have negative numbers. Note numbers can range from -60 to 67:
Play the notes faster. Try other durations:
Unless you indicate otherwise, each note is played for 1 second:
To play notes faster or slower, specify the length of the entire sequence in seconds:
Play a random 8-note melody. Try other lengths of melodies:
Hint: run the code again to get a different melody.
Get a random number between 1 and 12. Each time you run the code, a different number is chosen:
Play a random note. Each time you run the code, a different note is played:
Make a list of 8 random notes:
Play 8 random notes for a duration of 2 seconds:
Play a random melody from a scale. Try different scales:
The black keys on the piano form a pentatonic scale:
This chooses a random note from a pentatonic scale:
Play 8 random pentatonic notes:
You can also use note names to specify the notes:
Play 8 random notes from a C-major chord. The C above middle C is called “c5”. Another name for “c” is “c4”:
Play a random melody on random instruments. Try other instruments, like "Oboe", "Glockenspiel" or "HonkyTonkPiano":
Hint: you can also specify instruments with numbers from 1 to 128.
Play a note with a xylophone sound (the second value, 1, is the note’s duration):
Play a note with a clarinet sound:
Play a note with a xylophone, clarinet or violin sound chosen at random:
Play 8 random notes with random instruments:
Here’s a list of the available instruments: