SDL_cdrom.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. SDL - Simple DirectMedia Layer
  3. Copyright (C) 1997-2009 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. Sam Lantinga
  16. slouken@libsdl.org
  17. */
  18. /**
  19. * @file SDL_cdrom.h
  20. * This is the CD-audio control API for Simple DirectMedia Layer
  21. */
  22. #ifndef _SDL_cdrom_h
  23. #define _SDL_cdrom_h
  24. #include "SDL_stdinc.h"
  25. #include "SDL_error.h"
  26. #include "begin_code.h"
  27. /* Set up for C function definitions, even when using C++ */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. * @file SDL_cdrom.h
  33. * In order to use these functions, SDL_Init() must have been called
  34. * with the SDL_INIT_CDROM flag. This causes SDL to scan the system
  35. * for CD-ROM drives, and load appropriate drivers.
  36. */
  37. /** The maximum number of CD-ROM tracks on a disk */
  38. #define SDL_MAX_TRACKS 99
  39. /** @name Track Types
  40. * The types of CD-ROM track possible
  41. */
  42. /*@{*/
  43. #define SDL_AUDIO_TRACK 0x00
  44. #define SDL_DATA_TRACK 0x04
  45. /*@}*/
  46. /** The possible states which a CD-ROM drive can be in. */
  47. typedef enum {
  48. CD_TRAYEMPTY,
  49. CD_STOPPED,
  50. CD_PLAYING,
  51. CD_PAUSED,
  52. CD_ERROR = -1
  53. } CDstatus;
  54. /** Given a status, returns true if there's a disk in the drive */
  55. #define CD_INDRIVE(status) ((int)(status) > 0)
  56. typedef struct SDL_CDtrack {
  57. Uint8 id; /**< Track number */
  58. Uint8 type; /**< Data or audio track */
  59. Uint16 unused;
  60. Uint32 length; /**< Length, in frames, of this track */
  61. Uint32 offset; /**< Offset, in frames, from start of disk */
  62. } SDL_CDtrack;
  63. /** This structure is only current as of the last call to SDL_CDStatus() */
  64. typedef struct SDL_CD {
  65. int id; /**< Private drive identifier */
  66. CDstatus status; /**< Current drive status */
  67. /** The rest of this structure is only valid if there's a CD in drive */
  68. /*@{*/
  69. int numtracks; /**< Number of tracks on disk */
  70. int cur_track; /**< Current track position */
  71. int cur_frame; /**< Current frame offset within current track */
  72. SDL_CDtrack track[SDL_MAX_TRACKS+1];
  73. /*@}*/
  74. } SDL_CD;
  75. /** @name Frames / MSF Conversion Functions
  76. * Conversion functions from frames to Minute/Second/Frames and vice versa
  77. */
  78. /*@{*/
  79. #define CD_FPS 75
  80. #define FRAMES_TO_MSF(f, M,S,F) { \
  81. int value = f; \
  82. *(F) = value%CD_FPS; \
  83. value /= CD_FPS; \
  84. *(S) = value%60; \
  85. value /= 60; \
  86. *(M) = value; \
  87. }
  88. #define MSF_TO_FRAMES(M, S, F) ((M)*60*CD_FPS+(S)*CD_FPS+(F))
  89. /*@}*/
  90. /* CD-audio API functions: */
  91. /**
  92. * Returns the number of CD-ROM drives on the system, or -1 if
  93. * SDL_Init() has not been called with the SDL_INIT_CDROM flag.
  94. */
  95. extern DECLSPEC int SDLCALL SDL_CDNumDrives(void);
  96. /**
  97. * Returns a human-readable, system-dependent identifier for the CD-ROM.
  98. * Example:
  99. * - "/dev/cdrom"
  100. * - "E:"
  101. * - "/dev/disk/ide/1/master"
  102. */
  103. extern DECLSPEC const char * SDLCALL SDL_CDName(int drive);
  104. /**
  105. * Opens a CD-ROM drive for access. It returns a drive handle on success,
  106. * or NULL if the drive was invalid or busy. This newly opened CD-ROM
  107. * becomes the default CD used when other CD functions are passed a NULL
  108. * CD-ROM handle.
  109. * Drives are numbered starting with 0. Drive 0 is the system default CD-ROM.
  110. */
  111. extern DECLSPEC SDL_CD * SDLCALL SDL_CDOpen(int drive);
  112. /**
  113. * This function returns the current status of the given drive.
  114. * If the drive has a CD in it, the table of contents of the CD and current
  115. * play position of the CD will be stored in the SDL_CD structure.
  116. */
  117. extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom);
  118. /**
  119. * Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
  120. * tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play
  121. * until the end of the CD. This function will skip data tracks.
  122. * This function should only be called after calling SDL_CDStatus() to
  123. * get track information about the CD.
  124. * For example:
  125. * @code
  126. * // Play entire CD:
  127. * if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
  128. * SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
  129. * // Play last track:
  130. * if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
  131. * SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
  132. * }
  133. * // Play first and second track and 10 seconds of third track:
  134. * if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
  135. * SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
  136. * @endcode
  137. *
  138. * @return This function returns 0, or -1 if there was an error.
  139. */
  140. extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom,
  141. int start_track, int start_frame, int ntracks, int nframes);
  142. /**
  143. * Play the given CD starting at 'start' frame for 'length' frames.
  144. * @return It returns 0, or -1 if there was an error.
  145. */
  146. extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD *cdrom, int start, int length);
  147. /** Pause play
  148. * @return returns 0, or -1 on error
  149. */
  150. extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD *cdrom);
  151. /** Resume play
  152. * @return returns 0, or -1 on error
  153. */
  154. extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD *cdrom);
  155. /** Stop play
  156. * @return returns 0, or -1 on error
  157. */
  158. extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD *cdrom);
  159. /** Eject CD-ROM
  160. * @return returns 0, or -1 on error
  161. */
  162. extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD *cdrom);
  163. /** Closes the handle for the CD-ROM drive */
  164. extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD *cdrom);
  165. /* Ends C function definitions when using C++ */
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #include "close_code.h"
  170. #endif /* _SDL_video_h */