Creating an audio sequencer
Before we can play the game, we need some way to play songs on the piano by playing back notes in a certain order, at the correct time, and at the correct speed. We will create an object called AudioSequencer
that takes an array of musical event objects and turns them into music.
To implement our audio sequencer we need to define a format for our music events. We will roughly follow the MIDI format, but much more simplified. MIDI is the standard to record and play back music events. Each event contains information about how and when to play notes, or turn notes off.
Our event object will contain three fields:
deltaTime
: The amount of time to wait before executing the event.event
: This is an integer event code that determines what the event does. It can be one of the following:- Turn a note on
- Turn a note off
- Cue point will be at the beginning of a song
- End of track will signal that the song is over
note
: This is the note to play. It contains the octave and note, and matches...