Sub Form_Load ()
  '
  ' Initialize the sound system
  '
  status% = OpenSound()
  Select Case status
    Case S_SERDVNA
      MsgBox ("Music already in use")
      CloseSound
      End

    Case S_SEROFM
      MsgBox ("Out of Memory")
      CloseSound
      End

  End Select

  '
  ' Initialize voice buffer and default conditions
  '
  status% = SetVoiceQueueSize(1, Q_BUFF_SIZE)
  length% = 4
  octave% = 3
  mode% = S_NORMAL
  temp% = 120

End Sub

Sub OnPlay_Timer ()
  Static song$(5)
  Static songptr%

  '
  ' Initialize array first time through
  '
  If song$(1) = "" Then
    song$(1) = "O4MLT135D6P60<B10GP64GP64GP56MNE8D8G8MLAMNF#8"
    song$(2) = "MLGMNP32E8D8GE8D8GE8D8F#2.P16MLD8E8F#GMNA.P64"
    song$(3) = "MLD8GAMNB.G8MLA8MNBMLG8A8MNBMLG8A2.P15>MND5"
    song$(4) = "<B13GGMLGMNE8D8G8MLAP64MNF#8MLGP32MNF#8F8E
    song$(5) = "G#8B8EBMLA2.MNP8D8D8MLG.P64F#8GP64BP64A.P64
    song$(6) = "G#8P64AP17F#8P64D8P64E8GP60E7GP64F#P64G2.P6P6"
  End If

  '
  ' Make sure there are notes in the buffer
  '
  If CountVoiceNotes(1) < Q_THRESHHOLD Then
    Play (song$(songptr% Mod 6 + 1))
    songptr% = songptr% + 1
    status% = StartSound()
  End If
End Sub

Sub Form_Unload (Cancel As Integer)
  CloseSound
End Sub

Sub Quit_Click ()
  CloseSound: End
End Sub
