Lesson 10 of 15
Arpeggiation
Arpeggios
An arpeggio plays the notes of a chord one at a time rather than all together. This creates a flowing, harp-like texture.
Cycling Through Chord Notes
Given a chord as a MIDI array, an arpeggiator cycles through the notes:
arpNote(chord, step) = chord[step % chord.length]
The modulo operator (%) wraps the step index back to the start when it reaches the end of the chord.
Example: C Major Arpeggio
chord = [60, 64, 67] // C4, E4, G4
step 0 → chord[0 % 3] = chord[0] = 60 (C4)
step 1 → chord[1 % 3] = chord[1] = 64 (E4)
step 2 → chord[2 % 3] = chord[2] = 67 (G4)
step 3 → chord[3 % 3] = chord[0] = 60 (C4, wraps!)
step 4 → chord[4 % 3] = chord[1] = 64 (E4)
Your Task
Implement arpNote(chord, step) returning the MIDI note at the given step.
Run your code to hear a C major arpeggio ascend and descend.
Web Audio API loading...
Loading...
Click "Run" to execute your code.