'
' DS4QB++ CD Audio demo
'

' NOTE: Depending on your CD Drive, you may or may not be able to adjust
'       the volume.

DEFINT A-Z

DECLARE FUNCTION ToMS$ (Seconds AS LONG)

'$INCLUDE: 'DEXTERN.BI'

CONST Title = "DS4QB++ v1.2 CD Audio demo"
CONST True = -1
CONST False = NOT True

CLS

PRINT "Initializing DS4QB++...";

R = DS4QB.Init(CURRENT, DEFAULT)

IF R = -1 THEN
  PRINT "Error! Essential file missing!": END
 ELSEIF R = -3 THEN
  PRINT "Error! Please run SETUP.EXE!": END
 ELSEIF R = -2 THEN
  PRINT "Error! Could not connect to slave!": END
END IF

PRINT "Done.": PRINT

COLOR 0, 4
LOCATE 1, 1: PRINT SPACE$(80)
LOCATE 1, 40 - (LEN(Title) / 2): PRINT Title$
COLOR 7, 0

PRINT
PRINT "Initializing CD Audio...";

DS4QB.InitCD

Tracks = DS4QB.GetCDTracks
IF Tracks < 1 THEN
 PRINT "Invalid CD or no CD in drive."
 PRINT
 GOTO Shutdown
END IF

Track = Tracks
Volume = 5

LOCATE 3, 1: PRINT SPACE$(40)

DS4QB.SetMusicAttr CDMUSIC, Volume * 10, CURRENT

DO

 Key$ = UCASE$(INKEY$)
 SELECT CASE Key$
  CASE ","
   Track = Track - 1
   IF Track < 1 THEN Track = Tracks
  CASE "."
   Track = Track + 1
   IF Track > Tracks THEN Track = 1
  CASE "+", "="
   NewTrackPosition& = TrackPosition& + (TrackLength& / 10)
   IF NewTrackPosition& > TrackLength& THEN NewTrackPosition& = TrackLength&
  CASE "-"
   NewTrackPosition& = TrackPosition& - (TrackLength& / 10)
   IF NewTrackPosition& < 0 THEN NewTrackPosition& = 0
  CASE "S"
   IF Stopped = False THEN
     NewTrackPosition& = 0
     NewStopped = True
    ELSE
     DS4QB.PlayCD Track, False
     NewStopped = False
   END IF
   Stopped = NewStopped
  CASE "P"
   DS4QB.PauseMusic CDMUSIC
  CASE "R"
   DS4QB.ResumeMusic CDMUSIC
  CASE "1" TO "9"
   OldVolume = Volume
   Volume = VAL(Key$)
   DS4QB.SetMusicAttr CDMUSIC, Volume * 10, CURRENT
  CASE CHR$(27)
   EXIT DO
 END SELECT

 IF TIMER - Pacer# > 1 THEN
  IF NewTrackPosition& <> TrackPosition& THEN
    DS4QB.SetMusicPosition CDMUSIC, NewTrackPosition&
    TrackPosition& = NewTrackPosition&
    IF Stopped = True THEN DS4QB.StopMusic CDMUSIC
   ELSE
    TrackPosition& = DS4QB.GetMusicPosition&(CDMUSIC)
    NewTrackPosition& = TrackPosition&
  END IF
  IF TrackPosition& = TrackLength& THEN
   Track = Track + 1
   IF Track > Tracks THEN Track = 1
  END IF
  Pacer# = TIMER
 END IF

 IF LastTrack <> Track THEN
  DS4QB.PlayCD Track, False
  TrackLength& = DS4QB.GetCDTrackLength&(Track)
  TrackPosition& = 0
  NewTrackPosition& = 0
 END IF
 LastTrack = Track

 LOCATE 3, 1: PRINT " þ Track"; Track; "of"; Tracks; SPACE$(40)
 LOCATE 4, 1: PRINT " þ Time "; ToMS$(TrackPosition&); " of "; ToMS$(TrackLength&); SPACE$(40)
 IF Stopped = False THEN
   LOCATE 6, 1: PRINT " - [S]top  [P]ause [R]esume"
  ELSE
   LOCATE 6, 1: PRINT " - [S]tart [P]ause [R]esume"
 END IF
 LOCATE 7, 1: PRINT " - [>] Next track  [<] Previous track"
 LOCATE 8, 1: PRINT " - [+] Skip ahead  [-] Skip back"
 LOCATE 10, 1: PRINT " þ Volume [1] [2] [3] [4] [5] [6] [7] [8] [9]"
 IF OldVolume THEN LOCATE 11, 12 + (OldVolume - 1) * 4: PRINT " "
 LOCATE 11, 12 + (Volume - 1) * 4: PRINT "^"
LOOP

DS4QB.DeInitCD

Shutdown:
PRINT "Shutting down...";
DS4QB.Close

FUNCTION ToMS$ (Seconds AS LONG)
 Minutes = Seconds \ 60
 NewSeconds = Seconds MOD 60
 ToMS$ = LTRIM$(STR$(Minutes)) + ":" + LTRIM$(STR$(NewSeconds))
END FUNCTION

