It's tricky, considering that you might replay sound at 44100, which is 44.1 times more accurate than the timer(). It might do the trick though - maybe best to play the main theme, check to see when it's stopped, then play it again and reset a timer.
I recently added a syncing routine to a game front end, basically kung fu noises, like chants every bar, so had to work out how frequently the chants come in. So I stored the timer() value before playing the music, then divided that by the bar length, was about 1.22 seconds, or 1220 miliseconds or...
musictime=timer()
play music 1
do
oldbar=musicbar
musicbar=int((timer()-musictime)/1220)
if oldbar<>musicbar
`Do whatever
endif
loop
I was able to get the syncing quite good with just that, worked out the 1220 milliseconds by counting the chants and dividing the sample length to get the seconds. Would obviosly be more accurate if your making the music yourself, based on the BPM.
So.... I suggest storing the timer(), then use a bar counter, and then work out a multiplier for the bar position.
bartime=timer()-musictime
barmul#=(bartime-(int(bartime/1220)*1220))/1220.0
So now barmul# goes from 0.0 to 1.0 in the space of 1 bar. If you reduce the volume based on that, it would fade out and in in the space of 1 bar. That way it would sound more natural, as if you'd composed the fade out specially. Would be especially nice if both songs use the same BPM. Getting an exact bar length in miliseconds would be the trickiest part, with that though it should be very accurate.