DECLARE SUB SaveState ()
DECLARE SUB LoadState ()
DECLARE SUB Notes ()
DECLARE SUB Menu (KeyChoice$)

REM Music Keys (C) Richard Copeland 1993

'Open Music.dat file.  If does not exist in current directory,
'  goto error handler to create and intialize it.
ON ERROR GOTO ErrorTrap
OPEN "B:\Music.dat" FOR INPUT AS #1
CLOSE
ON ERROR GOTO 0     'Reset error handler

' Error handler for program
' if data file not found, create and initaialize a new one.
ErrorTrap:
    SELECT CASE ERR
        ' If data file not found, create and initialize a new one.
        CASE 53
        MusicLine = 1
        SaveState
        RESUME
REM ** Keys **
' Main Program
CLS
DO
  CALL Menu(KeyChoice$)
SELECT CASE KeyChoice$
    CASE "A"
      PLAY "A"
    CASE "S"
      PLAY "B"
    CASE "D"
      PLAY "C"
    CASE "F"
      PLAY "D"
    CASE "J"
      PLAY "E"
    CASE "K"
      PLAY "F"
    CASE "L"
      PLAY "G"
    CASE "Q"
      PLAY "A#"
    CASE "W"
      PLAY "D#"
    CASE "E"
      PLAY "C#"
    CASE "R"
      PLAY "D#"
    CASE "U"
      PLAY "C#"
    CASE "I"
      PLAY "F#"
    CASE "O"
      PLAY "G#"
    CASE "."
      PLAY "o1>": PRINT "Octave > "
    CASE ","
      PLAY "o6<": PRINT "Octave < "
    CASE ">"
      PLAY "o1>": PRINT "Octave > "
    CASE "<"
      PLAY "o6<": PRINT "Octave < "
    CASE "M"
      PLAY "MF": LOCATE 19, 1: PRINT "Music in Foreground"
    CASE "B"
      PLAY "MB": LOCATE 19, 1: PRINT "Music in Background"
    CASE "1"
      PLAY "ML": LOCATE 20, 1: PRINT "Music in legato    "
    CASE "2"
      PLAY "MN": LOCATE 20, 1: PRINT "Music in normal    "
    CASE "3"
      PLAY "MS": LOCATE 20, 1: PRINT "Music in staccato  "
    CASE "4"
       Notes
    CASE "5"
       CHAIN "B:\Demo\List"
    CASE "0"
      PRINT "Quit"
      SCREEN 2: INPUT "Please insert Disk #1", a$: PRINT "Please Wait...": CHAIN "Moneycga"
    CASE ELSE
    LOCATE 22, 1: PRINT "An incorrect letter": SLEEP 1
    LOCATE 22, 1: PRINT "                   "
    END SELECT
LOOP
END

SUB LoadState
'LoadState:
' Load Music from Music.dat

        OPEN "B:\Music.Dat" FOR INPUT AS #1
        INPUT #1, MusicLine

        CLOSE
END SUB

SUB Menu (KeyChoice$)
  LOCATE 1, 33: PRINT CHR$(14); " M U S I C  K E Y S "; CHR$(14);
  LOCATE 23, 33: PRINT "Enter Keys: "
  LOCATE 2, 1: PRINT "How to use Music Keys:"
  LOCATE 3, 1: PRINT "To play a note use keys (A-F) and (J-L)"
  LOCATE 4, 1: PRINT "Keys A-F will play notes (A-D)"
  LOCATE 5, 1: PRINT "Keys J-L will play notes (E-G)"
  LOCATE 6, 1: PRINT "To play sharp keys use keys (Q-R) (U-O)"
  PRINT
  LOCATE 8, 1: PRINT "To set the Octave use (`<' for Treble / `>' for Base)"
  LOCATE 9, 1: PRINT "(M) key Plays music in Foreground"
  LOCATE 10, 1: PRINT "(B) key Plays music in Background"
  LOCATE 11, 1: PRINT "(1) key Sets music legato"
  LOCATE 12, 1: PRINT "(2) key Sets music normal"
  LOCATE 13, 1: PRINT "(3) key Sets music staccato"
  LOCATE 14, 1: PRINT "(4) key Lets you write the notes before playing them"
  LOCATE 15, 1: PRINT "(5) key will let you play the demo songs"
  LOCATE 16, 1: PRINT "To set the proper note status for this screen use the option 4."
  LOCATE 17, 1: PRINT "Do not type in a note when seting this."
  KeyChoice$ = UCASE$(INPUT$(1))
  IF INSTR("ASDFJKL<>MB1234E", KeyChoice$) = 0 THEN EXIT SUB
END SUB

SUB Notes
1 CLS : COLOR 0: COLOR 7
LOCATE 1, 10: PRINT "W R I T I N G  Y O U R  O W N  M U S I C  L I N E S": COLOR 12
LOCATE 2, 5: PRINT "Octave and tone commnds:"
LOCATE 3, 5: PRINT "(O)octave Sets the current octave (0 - 6)"
LOCATE 4, 5: PRINT "< or >    Moves up or down one octave."
LOCATE 5, 5: PRINT "A - G     Plays the specified note in the current octave."
LOCATE 6, 5: PRINT "(N)note   Plays a specified note (0 - 84) in the seven-octave"
LOCATE 7, 5: PRINT "          range  (0 is a rest)."
LOCATE 8, 5: PRINT "Duration and tempo commands:"
LOCATE 9, 5: PRINT "(L)length    Sets the length of each note (1 - 64).  L1 is whole note,"
LOCATE 10, 5: PRINT "             L2 is a half note, etc."
LOCATE 11, 5: PRINT "ML           Sets music legato."
LOCATE 12, 5: PRINT "MN           Sets music normal."
LOCATE 13, 5: PRINT "MS           Sets music staccato."
LOCATE 14, 5: PRINT "(P)pause     Specifies a pause (1 - 64).  P1 is a whole-note pause,"
LOCATE 15, 5: PRINT "             P2 is a half-note pause, etc."
LOCATE 16, 5: PRINT "(T)tempo     Sets the tempo in quarter notes per minut (32 - 255)."
LOCATE 17, 5: PRINT "Mode commands:"
LOCATE 18, 5: PRINT "MF        Plays music in foreground."
LOCATE 19, 5: PRINT "MB        Plays music in background."
LOCATE 20, 5: PRINT "Suffix commands:"
LOCATE 21, 5: PRINT "# or +    Turns preceding note into a sharp."
LOCATE 22, 5: PRINT "-         Turns preceding note into a flat."
LOCATE 23, 5: PRINT ".         Plays the preceding note 3/2 as long as specified."
a$ = PLAY$
  INPUT "Enter Music: ", a$
  IF a$ = "Q" OR a$ = "q" THEN CLS : EXIT SUB
  IF a$ = "L" OR a$ = "l" THEN LoadState: GOSUB 1
  IF a$ = "S" OR a$ = "s" THEN SaveState: GOSUB 1
PLAY a$
GOSUB 1

END SUB

SUB SaveState
'SaveState:
' Save Music Line to "Music.dat" data file.
  OPEN "B:\Music.Dat" FOR OUTPUT AS #2
  PRINT #2, MusicLine

  CLOSE #2

END SUB

