; Pokemon RB - Pallet Town
#song 9
; Song 9 is the theme for most towns

t120
; 120 bpm (march tempo).
; At this tempo, 8th notes are 15 frames, which means
; we don't have symmetrical 16th notes.
; Luckily, this song doesn't use 16th notes.

#Sq1 {
	!start	
	; start is not necessary, strictly speaking, unless you write
	; a subroutine above it.

	!pulse $DUTY_50 $LEN_RUN $CONST_VOL 0
	; 50% duty cycle (sounds kind of like a clarinet).
	; Always put LEN_RUN and CONST_VOL. These are part of the 
	; byte that is written to the volume and duty cycle registers
	; by Faxanadu's engine. You don't need to understand this 
	; so don't worry too much!
	; I think the trailing 0 sets a base volume level. Each note 
	; ordinarily fades to 0 volume. Setting this higher will
	; allow a little sustain volume.
	
	!envelope 0 
	; Envelope 0 is a gradual decay.
	; Envelope 1 is sustain.
	; Envelope 2 (not used much) is a crescendo and decrescendo.
	
	v13 o7 l8
	; Slightly louder than Sq2.
	; I recommend not using volume 14 and 15 because the square
	; channels tend to be louder than everything else.
	; Octave 7 may seem high but it's just octave 5 in famitracker.
	; l8 means that a note without a number after it is an 8th note.
	; This is how other versions of MML work too.

	dc < ba > ge f+e 
	; Type a through g to play a note and r to play a rest.
	; + signifies a sharp and - signifies a flat.
	; To go down or up octaves, use < and >.
	; OR specify the octave with o2, o3, etc.

	d4. < b gg ab > 
	; Numbers after notes are their rhythms. 4. is a dotted quarter.
	; I find it useful to write 1 measure per line.
	; Most people do not use as much whitespace as I do, 
	; but that's OK because the MML interpreter will get rid of it.
	
	c4. r4 < f+ ga
	b4. > c16 < b16 a4. r >
	dc < b > d gf+ f+g
	e4. d d4. r 
	c < bag > dc < ba 
	g4. r4 gab >
	c4. r d4. c <
	; c4. r could be written as a half note (c2)
	; but I wanted it to cut off early.
	
	b4. r4 gab >
	c4 c4 d4. c16 d16 <
	b4. r4 bag l4
	a4. r8 eb 
	a4. r8 ge
	f+4. r8 gb
	b4. r8 a4. r8
	!restart
	; restart is only necessary in one channel
}

#Sq2 {
	!start
	!pulse $DUTY_50 $LEN_RUN $CONST_VOL 0
	!envelope 0 

	[ v11 o5 l8 
	; This channel is a little quieter because Sq1 has the melody.
	; Anything inside of [ ] is a loop. If there is a number after
	; the ], it will loop that many times.
	; Otherwise, it is an infinite loop.
	; You can put a second loop inside an infinite loop, but you
	; cannot use a finite loop inside another finite loop.

	b4 > c d4 gdc <
	b4 g > d4 d !endloopif 1 c < b 
	rb > c < b > c4. r4 <
	b > c < abgaf+ ]2
	o6 g f+ e4 d c4 < 
	ab > cdc < ba g4 f+4

	[ o6 c < geg > d < a f+ a
	bgdgbgdg ]2
	; Use repeats whenever possible to save space in the ROM.
	[o5 aece ]4
	f+ dcdgece
	gece f+ dcd
}

#Tri {
	!start
	[ o4 l4
	; default length is 4 in this block instead of 8,
	; because this channel has no 8th notes.
	; Unlike the square channels, o4 is the same in Famitracker.
	; Triangle doesn't have volume or duty cycles.

	g4. e4. f+
	g4. a4. g
	e4. f+4. !endloopif 1
	; this breaks the loop if it has played all the way through once.
	; The number you use with !endloopif should be 1 less than
	; the total number of loops (in this case, two). 

	e g4. f+4. d ]2 ; 1st ending
	l4 a g4. e4. d ; 2nd ending.
	; l4 has to be specified again because the last note
	; before endloopif was a different length.

	c2 d2 g2 ed 
	c2 d2 g2 ag
	l2 eaeg f+ 
	; I set l2 here because there are so many half notes
	e1 f+
}

#Noise {
	!end
	; You have to specify the noise channel, 
	; even if there is nothing in it.
}