Assuming that by "arpeggio", you're referring to arpeggio effects in the pattern, not arpeggio-type envelopes on instruments.
Let's say the pattern enables the arpeggio effect 047. This means arpeggio1 = 4 and arpeggio2 = 7. The numbers represent intervals measured in semitones: 4 is a major third above the base note, and 7 is a perfect fifth above the base note. Thus 047 represents a major chord in inversion 0.
Here is pseudocode:
Code:
On note start:
Set arpeggio phase to 0
Remember the base pitch of the note
Each frame:
If arpeggio phase == 0:
Set pitch to base pitch
If arpeggio phase == 1:
Set pitch to base pitch + arpeggio1
If arpeggio phase == 2:
Set pitch to base pitch + arpeggio2
Add 1 to arpeggio phase
If arpeggio phase >= 3:
Set arpeggio phase to 0
Let me know the first line you don't understand.
This allows for no arpeggio (arpeggio1=0 and arpeggio2=0), even combinations of three notes (arpeggio1=x and arpeggio2=y), a combination of two notes with more of the base note (arpeggio1=0 and arpeggio2=x), a combination of two notes with more of the upper note (arpeggio1=x and arpeggio2=x)
One enhancement is to replace the last if-then as follows:
Code:
If arpeggio phase >= 3:
Set arpeggio phase to 0
If arpeggio2 == 0:
Set arpeggio phase to 1
This allows an additional type of arpeggio: an even combination of two notes (arpeggio1=x and arpeggio2=0).
The Pently music engine implements exactly this arpeggio algorithm. In
pentlymusic.s, look around
storePitchWithArpeggio.