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