Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825
SDL: Enumerating CDROM Tracks

Author Topic: SDL: Enumerating CDROM Tracks  (Read 2425 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
SDL: Enumerating CDROM Tracks
« on: July 27, 2008, 10:49:41 PM »
 
The following example enumerates the tracks of a CDROM.

Code: [Select]
#COMPILE EXE
#DIM ALL
#INCLUDE "SDL.INC"

FUNCTION PBMAIN () AS LONG

   ' Initialize SDL
   IF SDL_Init(%SDL_INIT_CDROM) < 0 THEN
      ? "Couldn't initialize SDL" & SDL_GetError
      #IF %DEF(%PB_CC32)
         WAITKEY$
      #ENDIF
      EXIT FUNCTION
   END IF

   LOCAL pcdrom AS SDL_CD PTR
   pcdrom = SDL_CDOpen(0)
   IF pcdrom = %NULL THEN
      ? "Couldn't open default CD-ROM drive: " & SDL_GetError
      #IF %DEF(%PB_CC32)
         WAITKEY$
      #ENDIF
      SDL_Quit
      EXIT FUNCTION
   END IF

   LOCAL nTracks AS LONG
   LOCAL i AS LONG
   LOCAL m, s, f AS LONG

   SDL_CDStatus(pcdrom)
   nTracks = @pcdrom.numtracks
   ? "Drive tracks:" & STR$(nTracks)
   FOR i = 0 TO nTracks - 1
      FRAMES_TO_MSF(@pcdrom.track(i).length, m, s, f)
      ? "Track (index" & STR$(i) & ")" & _
         STR$(@pcdrom.track(i).id) & STR$(m) & "." & FORMAT$(s)
   NEXT

   ' Close the SDL_CD handle
   SDL_CDClose(pcdrom)

   ' Shut down SDL
   SDL_Quit

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION
« Last Edit: August 07, 2011, 08:06:44 PM by José Roca »