Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 1 | /********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | /* CD module -- interface to Mark Callow's and Roger Chickering's */ |
| 33 | /* CD Audio Library (CD). */ |
| 34 | |
| 35 | #include <sys/types.h> |
| 36 | #include <cdaudio.h> |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 37 | /* #include <sigfpe.h> */ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 38 | #include "allobjects.h" |
| 39 | #include "import.h" |
| 40 | #include "modsupport.h" |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 41 | #include "ceval.h" |
| 42 | |
| 43 | #define NCALLBACKS 8 |
| 44 | |
| 45 | typedef struct { |
| 46 | OB_HEAD |
| 47 | CDPLAYER *ob_cdplayer; |
| 48 | } cdplayerobject; |
| 49 | |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 50 | static object *CdError; /* exception cd.error */ |
| 51 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 52 | static object * |
| 53 | CD_allowremoval(self, args) |
| 54 | cdplayerobject *self; |
| 55 | object *args; |
| 56 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 57 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 58 | return NULL; |
| 59 | |
| 60 | CDallowremoval(self->ob_cdplayer); |
| 61 | |
| 62 | INCREF(None); |
| 63 | return None; |
| 64 | } |
| 65 | |
| 66 | static object * |
| 67 | CD_preventremoval(self, args) |
| 68 | cdplayerobject *self; |
| 69 | object *args; |
| 70 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 71 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 72 | return NULL; |
| 73 | |
| 74 | CDpreventremoval(self->ob_cdplayer); |
| 75 | |
| 76 | INCREF(None); |
| 77 | return None; |
| 78 | } |
| 79 | |
| 80 | static object * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 81 | CD_bestreadsize(self, args) |
| 82 | cdplayerobject *self; |
| 83 | object *args; |
| 84 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 85 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 86 | return NULL; |
| 87 | |
| 88 | return newintobject((long) CDbestreadsize(self->ob_cdplayer)); |
| 89 | } |
| 90 | |
| 91 | static object * |
| 92 | CD_close(self, args) |
| 93 | cdplayerobject *self; |
| 94 | object *args; |
| 95 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 96 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 97 | return NULL; |
| 98 | |
| 99 | if (!CDclose(self->ob_cdplayer)) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 100 | err_errno(CdError); /* XXX - ??? */ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 101 | return NULL; |
| 102 | } |
| 103 | self->ob_cdplayer = NULL; |
| 104 | |
| 105 | INCREF(None); |
| 106 | return None; |
| 107 | } |
| 108 | |
| 109 | static object * |
| 110 | CD_eject(self, args) |
| 111 | cdplayerobject *self; |
| 112 | object *args; |
| 113 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 114 | CDSTATUS status; |
| 115 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 116 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 117 | return NULL; |
| 118 | |
| 119 | if (!CDeject(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 120 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 121 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 122 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 123 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 124 | err_setstr(CdError, "eject failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | INCREF(None); |
| 129 | return None; |
| 130 | } |
| 131 | |
| 132 | static object * |
| 133 | CD_getstatus(self, args) |
| 134 | cdplayerobject *self; |
| 135 | object *args; |
| 136 | { |
| 137 | CDSTATUS status; |
| 138 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 139 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 140 | return NULL; |
| 141 | |
| 142 | if (!CDgetstatus(self->ob_cdplayer, &status)) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 143 | err_errno(CdError); /* XXX - ??? */ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 144 | return NULL; |
| 145 | } |
| 146 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 147 | return mkvalue("(ii(iii)(iii)(iii)iiii)", status.state, |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 148 | status.track, status.min, status.sec, status.frame, |
| 149 | status.abs_min, status.abs_sec, status.abs_frame, |
| 150 | status.total_min, status.total_sec, status.total_frame, |
| 151 | status.first, status.last, status.scsi_audio, |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 152 | status.cur_block); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static object * |
| 156 | CD_gettrackinfo(self, args) |
| 157 | cdplayerobject *self; |
| 158 | object *args; |
| 159 | { |
| 160 | int track; |
| 161 | CDTRACKINFO info; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 162 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 163 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 164 | if (!newgetargs(args, "i", &track)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 165 | return NULL; |
| 166 | |
| 167 | if (!CDgettrackinfo(self->ob_cdplayer, track, &info)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 168 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 169 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 170 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 171 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 172 | err_setstr(CdError, "gettrackinfo failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 173 | return NULL; |
| 174 | } |
| 175 | |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 176 | return mkvalue("((iii)(iii))", |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 177 | info.start_min, info.start_sec, info.start_frame, |
| 178 | info.total_min, info.total_sec, info.total_frame); |
| 179 | } |
| 180 | |
| 181 | static object * |
| 182 | CD_msftoblock(self, args) |
| 183 | cdplayerobject *self; |
| 184 | object *args; |
| 185 | { |
| 186 | int min, sec, frame; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 187 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 188 | if (!newgetargs(args, "iii", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 189 | return NULL; |
| 190 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 191 | return newintobject((long) CDmsftoblock(self->ob_cdplayer, |
| 192 | min, sec, frame)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static object * |
| 196 | CD_play(self, args) |
| 197 | cdplayerobject *self; |
| 198 | object *args; |
| 199 | { |
| 200 | int start, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 201 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 202 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 203 | if (!newgetargs(args, "ii", &start, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 204 | return NULL; |
| 205 | |
| 206 | if (!CDplay(self->ob_cdplayer, start, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 207 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 208 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 209 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 210 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 211 | err_setstr(CdError, "play failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | INCREF(None); |
| 216 | return None; |
| 217 | } |
| 218 | |
| 219 | static object * |
| 220 | CD_playabs(self, args) |
| 221 | cdplayerobject *self; |
| 222 | object *args; |
| 223 | { |
| 224 | int min, sec, frame, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 225 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 226 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 227 | if (!newgetargs(args, "iiii", &min, &sec, &frame, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 228 | return NULL; |
| 229 | |
| 230 | if (!CDplayabs(self->ob_cdplayer, min, sec, frame, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 231 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 232 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 233 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 234 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 235 | err_setstr(CdError, "playabs failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | INCREF(None); |
| 240 | return None; |
| 241 | } |
| 242 | |
| 243 | static object * |
| 244 | CD_playtrack(self, args) |
| 245 | cdplayerobject *self; |
| 246 | object *args; |
| 247 | { |
| 248 | int start, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 249 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 250 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 251 | if (!newgetargs(args, "ii", &start, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 252 | return NULL; |
| 253 | |
| 254 | if (!CDplaytrack(self->ob_cdplayer, start, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 255 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 256 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 257 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 258 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 259 | err_setstr(CdError, "playtrack failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 260 | return NULL; |
| 261 | } |
| 262 | |
| 263 | INCREF(None); |
| 264 | return None; |
| 265 | } |
| 266 | |
| 267 | static object * |
| 268 | CD_playtrackabs(self, args) |
| 269 | cdplayerobject *self; |
| 270 | object *args; |
| 271 | { |
| 272 | int track, min, sec, frame, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 273 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 274 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 275 | if (!newgetargs(args, "iiiii", &track, &min, &sec, &frame, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 276 | return NULL; |
| 277 | |
| 278 | if (!CDplaytrackabs(self->ob_cdplayer, track, min, sec, frame, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 279 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 280 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 281 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 282 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 283 | err_setstr(CdError, "playtrackabs failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | INCREF(None); |
| 288 | return None; |
| 289 | } |
| 290 | |
| 291 | static object * |
| 292 | CD_readda(self, args) |
| 293 | cdplayerobject *self; |
| 294 | object *args; |
| 295 | { |
| 296 | int numframes, n; |
| 297 | object *result; |
| 298 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 299 | if (!newgetargs(args, "i", &numframes)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 300 | return NULL; |
| 301 | |
| 302 | result = newsizedstringobject(NULL, numframes * sizeof(CDFRAME)); |
| 303 | if (result == NULL) |
| 304 | return NULL; |
| 305 | |
| 306 | n = CDreadda(self->ob_cdplayer, (CDFRAME *) getstringvalue(result), numframes); |
| 307 | if (n == -1) { |
| 308 | DECREF(result); |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 309 | err_errno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 310 | return NULL; |
| 311 | } |
| 312 | if (n < numframes) |
| 313 | if (resizestring(&result, n * sizeof(CDFRAME))) |
| 314 | return NULL; |
| 315 | |
| 316 | return result; |
| 317 | } |
| 318 | |
| 319 | static object * |
| 320 | CD_seek(self, args) |
| 321 | cdplayerobject *self; |
| 322 | object *args; |
| 323 | { |
| 324 | int min, sec, frame; |
| 325 | long block; |
| 326 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 327 | if (!newgetargs(args, "iii", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 328 | return NULL; |
| 329 | |
| 330 | block = CDseek(self->ob_cdplayer, min, sec, frame); |
| 331 | if (block == -1) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 332 | err_errno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 333 | return NULL; |
| 334 | } |
| 335 | |
| 336 | return newintobject(block); |
| 337 | } |
| 338 | |
| 339 | static object * |
| 340 | CD_seektrack(self, args) |
| 341 | cdplayerobject *self; |
| 342 | object *args; |
| 343 | { |
| 344 | int track; |
| 345 | long block; |
| 346 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 347 | if (!newgetargs(args, "i", &track)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 348 | return NULL; |
| 349 | |
| 350 | block = CDseektrack(self->ob_cdplayer, track); |
| 351 | if (block == -1) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 352 | err_errno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 353 | return NULL; |
| 354 | } |
| 355 | |
| 356 | return newintobject(block); |
| 357 | } |
| 358 | |
| 359 | static object * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 360 | CD_seekblock(self, args) |
| 361 | cdplayerobject *self; |
| 362 | object *args; |
| 363 | { |
| 364 | unsigned long block; |
| 365 | |
| 366 | if (!newgetargs(args, "l", &block)) |
| 367 | return NULL; |
| 368 | |
| 369 | block = CDseekblock(self->ob_cdplayer, block); |
| 370 | if (block == (unsigned long) -1) { |
| 371 | err_errno(CdError); |
| 372 | return NULL; |
| 373 | } |
| 374 | |
| 375 | return newintobject(block); |
| 376 | } |
| 377 | |
| 378 | static object * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 379 | CD_stop(self, args) |
| 380 | cdplayerobject *self; |
| 381 | object *args; |
| 382 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 383 | CDSTATUS status; |
| 384 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 385 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 386 | return NULL; |
| 387 | |
| 388 | if (!CDstop(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 389 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 390 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 391 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 392 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 393 | err_setstr(CdError, "stop failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | INCREF(None); |
| 398 | return None; |
| 399 | } |
| 400 | |
| 401 | static object * |
| 402 | CD_togglepause(self, args) |
| 403 | cdplayerobject *self; |
| 404 | object *args; |
| 405 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 406 | CDSTATUS status; |
| 407 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 408 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 409 | return NULL; |
| 410 | |
| 411 | if (!CDtogglepause(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 412 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 413 | status.state == CD_NODISC) |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 414 | err_setstr(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 415 | else |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 416 | err_setstr(CdError, "togglepause failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 417 | return NULL; |
| 418 | } |
| 419 | |
| 420 | INCREF(None); |
| 421 | return None; |
| 422 | } |
| 423 | |
| 424 | static struct methodlist cdplayer_methods[] = { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 425 | {"allowremoval", (method)CD_allowremoval, 1}, |
| 426 | {"bestreadsize", (method)CD_bestreadsize, 1}, |
| 427 | {"close", (method)CD_close, 1}, |
| 428 | {"eject", (method)CD_eject, 1}, |
| 429 | {"getstatus", (method)CD_getstatus, 1}, |
| 430 | {"gettrackinfo", (method)CD_gettrackinfo, 1}, |
| 431 | {"msftoblock", (method)CD_msftoblock, 1}, |
| 432 | {"play", (method)CD_play, 1}, |
| 433 | {"playabs", (method)CD_playabs, 1}, |
| 434 | {"playtrack", (method)CD_playtrack, 1}, |
| 435 | {"playtrackabs", (method)CD_playtrackabs, 1}, |
| 436 | {"preventremoval", (method)CD_preventremoval, 1}, |
| 437 | {"readda", (method)CD_readda, 1}, |
| 438 | {"seek", (method)CD_seek, 1}, |
| 439 | {"seekblock", (method)CD_seekblock, 1}, |
| 440 | {"seektrack", (method)CD_seektrack, 1}, |
| 441 | {"stop", (method)CD_stop, 1}, |
| 442 | {"togglepause", (method)CD_togglepause, 1}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 443 | {NULL, NULL} /* sentinel */ |
| 444 | }; |
| 445 | |
| 446 | static void |
| 447 | cdplayer_dealloc(self) |
| 448 | cdplayerobject *self; |
| 449 | { |
| 450 | if (self->ob_cdplayer != NULL) |
| 451 | CDclose(self->ob_cdplayer); |
| 452 | DEL(self); |
| 453 | } |
| 454 | |
| 455 | static object * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 456 | cdplayer_getattr(self, name) |
| 457 | cdplayerobject *self; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 458 | char *name; |
| 459 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 460 | if (self->ob_cdplayer == NULL) { |
| 461 | err_setstr(RuntimeError, "no player active"); |
| 462 | return NULL; |
| 463 | } |
| 464 | return findmethod(cdplayer_methods, (object *)self, name); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | typeobject CdPlayertype = { |
| 468 | OB_HEAD_INIT(&Typetype) |
| 469 | 0, /*ob_size*/ |
| 470 | "cdplayer", /*tp_name*/ |
| 471 | sizeof(cdplayerobject), /*tp_size*/ |
| 472 | 0, /*tp_itemsize*/ |
| 473 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 474 | (destructor)cdplayer_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 475 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 476 | (getattrfunc)cdplayer_getattr, /*tp_getattr*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 477 | 0, /*tp_setattr*/ |
| 478 | 0, /*tp_compare*/ |
| 479 | 0, /*tp_repr*/ |
| 480 | }; |
| 481 | |
| 482 | static object * |
| 483 | newcdplayerobject(cdp) |
| 484 | CDPLAYER *cdp; |
| 485 | { |
| 486 | cdplayerobject *p; |
| 487 | |
| 488 | p = NEWOBJ(cdplayerobject, &CdPlayertype); |
| 489 | if (p == NULL) |
| 490 | return NULL; |
| 491 | p->ob_cdplayer = cdp; |
| 492 | return (object *) p; |
| 493 | } |
| 494 | |
| 495 | static object * |
| 496 | CD_open(self, args) |
| 497 | object *self, *args; |
| 498 | { |
| 499 | char *dev, *direction; |
| 500 | CDPLAYER *cdp; |
| 501 | |
| 502 | /* |
| 503 | * Variable number of args. |
| 504 | * First defaults to "None", second defaults to "r". |
| 505 | */ |
| 506 | dev = NULL; |
| 507 | direction = "r"; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 508 | if (!newgetargs(args, "|zs", &dev, &direction)) |
| 509 | return NULL; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 510 | |
| 511 | cdp = CDopen(dev, direction); |
| 512 | if (cdp == NULL) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 513 | err_errno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 514 | return NULL; |
| 515 | } |
| 516 | |
| 517 | return newcdplayerobject(cdp); |
| 518 | } |
| 519 | |
| 520 | typedef struct { |
| 521 | OB_HEAD |
| 522 | CDPARSER *ob_cdparser; |
| 523 | struct { |
| 524 | object *ob_cdcallback; |
| 525 | object *ob_cdcallbackarg; |
| 526 | } ob_cdcallbacks[NCALLBACKS]; |
| 527 | } cdparserobject; |
| 528 | |
| 529 | static void |
| 530 | CD_callback(arg, type, data) |
| 531 | void *arg; |
| 532 | CDDATATYPES type; |
| 533 | void *data; |
| 534 | { |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 535 | object *result, *args, *v = NULL; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 536 | char *p; |
| 537 | int i; |
| 538 | cdparserobject *self; |
| 539 | |
| 540 | self = (cdparserobject *) arg; |
| 541 | args = newtupleobject(3); |
| 542 | if (args == NULL) |
| 543 | return; |
| 544 | INCREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 545 | settupleitem(args, 0, self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 546 | settupleitem(args, 1, newintobject((long) type)); |
| 547 | switch (type) { |
| 548 | case cd_audio: |
| 549 | v = newsizedstringobject(data, CDDA_DATASIZE); |
| 550 | break; |
| 551 | case cd_pnum: |
| 552 | case cd_index: |
| 553 | v = newintobject(((CDPROGNUM *) data)->value); |
| 554 | break; |
| 555 | case cd_ptime: |
| 556 | case cd_atime: |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 557 | #define ptr ((struct cdtimecode *) data) |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 558 | v = mkvalue("(iii)", |
| 559 | ptr->mhi * 10 + ptr->mlo, |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 560 | ptr->shi * 10 + ptr->slo, |
| 561 | ptr->fhi * 10 + ptr->flo); |
| 562 | #undef ptr |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 563 | break; |
| 564 | case cd_catalog: |
| 565 | v = newsizedstringobject(NULL, 13); |
| 566 | p = getstringvalue(v); |
| 567 | for (i = 0; i < 13; i++) |
| 568 | *p++ = ((char *) data)[i] + '0'; |
| 569 | break; |
| 570 | case cd_ident: |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 571 | #define ptr ((struct cdident *) data) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 572 | v = newsizedstringobject(NULL, 12); |
| 573 | p = getstringvalue(v); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 574 | CDsbtoa(p, ptr->country, 2); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 575 | p += 2; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 576 | CDsbtoa(p, ptr->owner, 3); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 577 | p += 3; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 578 | *p++ = ptr->year[0] + '0'; |
| 579 | *p++ = ptr->year[1] + '0'; |
| 580 | *p++ = ptr->serial[0] + '0'; |
| 581 | *p++ = ptr->serial[1] + '0'; |
| 582 | *p++ = ptr->serial[2] + '0'; |
| 583 | *p++ = ptr->serial[3] + '0'; |
| 584 | *p++ = ptr->serial[4] + '0'; |
| 585 | #undef ptr |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 586 | break; |
| 587 | case cd_control: |
| 588 | v = newintobject((long) *((unchar *) data)); |
| 589 | break; |
| 590 | } |
| 591 | settupleitem(args, 2, v); |
| 592 | if (err_occurred()) { |
| 593 | DECREF(args); |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | result = call_object(self->ob_cdcallbacks[type].ob_cdcallback, args); |
| 598 | DECREF(args); |
| 599 | XDECREF(result); |
| 600 | } |
| 601 | |
| 602 | static object * |
| 603 | CD_deleteparser(self, args) |
| 604 | cdparserobject *self; |
| 605 | object *args; |
| 606 | { |
| 607 | int i; |
| 608 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 609 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 610 | return NULL; |
| 611 | |
| 612 | CDdeleteparser(self->ob_cdparser); |
| 613 | self->ob_cdparser = NULL; |
| 614 | |
| 615 | /* no sense in keeping the callbacks, so remove them */ |
| 616 | for (i = 0; i < NCALLBACKS; i++) { |
| 617 | XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); |
| 618 | self->ob_cdcallbacks[i].ob_cdcallback = NULL; |
| 619 | XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); |
| 620 | self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 621 | } |
| 622 | |
| 623 | INCREF(None); |
| 624 | return None; |
| 625 | } |
| 626 | |
| 627 | static object * |
| 628 | CD_parseframe(self, args) |
| 629 | cdparserobject *self; |
| 630 | object *args; |
| 631 | { |
| 632 | char *cdfp; |
| 633 | int length; |
| 634 | CDFRAME *p; |
| 635 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 636 | if (!newgetargs(args, "s#", &cdfp, &length)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 637 | return NULL; |
| 638 | |
| 639 | if (length % sizeof(CDFRAME) != 0) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 640 | err_setstr(TypeError, "bad length"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 641 | return NULL; |
| 642 | } |
| 643 | |
| 644 | p = (CDFRAME *) cdfp; |
| 645 | while (length > 0) { |
| 646 | CDparseframe(self->ob_cdparser, p); |
| 647 | length -= sizeof(CDFRAME); |
| 648 | p++; |
| 649 | if (err_occurred()) |
| 650 | return NULL; |
| 651 | } |
| 652 | |
| 653 | INCREF(None); |
| 654 | return None; |
| 655 | } |
| 656 | |
| 657 | static object * |
| 658 | CD_removecallback(self, args) |
| 659 | cdparserobject *self; |
| 660 | object *args; |
| 661 | { |
| 662 | int type; |
| 663 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 664 | if (!newgetargs(args, "i", &type)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 665 | return NULL; |
| 666 | |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 667 | if (type < 0 || type >= NCALLBACKS) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 668 | err_setstr(TypeError, "bad type"); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 669 | return NULL; |
| 670 | } |
| 671 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 672 | CDremovecallback(self->ob_cdparser, (CDDATATYPES) type); |
| 673 | |
| 674 | XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); |
| 675 | self->ob_cdcallbacks[type].ob_cdcallback = NULL; |
| 676 | |
| 677 | XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 678 | self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL; |
| 679 | |
| 680 | INCREF(None); |
| 681 | return None; |
| 682 | } |
| 683 | |
| 684 | static object * |
| 685 | CD_resetparser(self, args) |
| 686 | cdparserobject *self; |
| 687 | object *args; |
| 688 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 689 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 690 | return NULL; |
| 691 | |
| 692 | CDresetparser(self->ob_cdparser); |
| 693 | |
| 694 | INCREF(None); |
| 695 | return None; |
| 696 | } |
| 697 | |
| 698 | static object * |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 699 | CD_addcallback(self, args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 700 | cdparserobject *self; |
| 701 | object *args; |
| 702 | { |
| 703 | int type; |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 704 | object *func, *funcarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 705 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 706 | /* XXX - more work here */ |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 707 | if (!newgetargs(args, "iOO", &type, &func, &funcarg)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 708 | return NULL; |
| 709 | |
| 710 | if (type < 0 || type >= NCALLBACKS) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 711 | err_setstr(TypeError, "argument out of range"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 712 | return NULL; |
| 713 | } |
| 714 | |
Sjoerd Mullender | 7c4eb40 | 1992-09-25 11:15:58 +0000 | [diff] [blame] | 715 | #ifdef CDsetcallback |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 716 | CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self); |
| 717 | #else |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 718 | CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 719 | #endif |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 720 | XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 721 | INCREF(func); |
| 722 | self->ob_cdcallbacks[type].ob_cdcallback = func; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 723 | XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 724 | INCREF(funcarg); |
| 725 | self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 726 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 727 | /* |
| 728 | if (type == cd_audio) { |
| 729 | sigfpe_[_UNDERFL].repls = _ZERO; |
| 730 | handle_sigfpes(_ON, _EN_UNDERFL, NULL, _ABORT_ON_ERROR, NULL); |
| 731 | } |
| 732 | */ |
| 733 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 734 | INCREF(None); |
| 735 | return None; |
| 736 | } |
| 737 | |
| 738 | static struct methodlist cdparser_methods[] = { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 739 | {"addcallback", (method)CD_addcallback, 1}, |
| 740 | {"deleteparser", (method)CD_deleteparser, 1}, |
| 741 | {"parseframe", (method)CD_parseframe, 1}, |
| 742 | {"removecallback", (method)CD_removecallback, 1}, |
| 743 | {"resetparser", (method)CD_resetparser, 1}, |
| 744 | {"setcallback", (method)CD_addcallback, 1}, /* backward compatibility */ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 745 | {NULL, NULL} /* sentinel */ |
| 746 | }; |
| 747 | |
| 748 | static void |
| 749 | cdparser_dealloc(self) |
| 750 | cdparserobject *self; |
| 751 | { |
| 752 | int i; |
| 753 | |
| 754 | for (i = 0; i < NCALLBACKS; i++) { |
| 755 | XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); |
| 756 | self->ob_cdcallbacks[i].ob_cdcallback = NULL; |
| 757 | XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); |
| 758 | self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 759 | } |
| 760 | CDdeleteparser(self->ob_cdparser); |
| 761 | DEL(self); |
| 762 | } |
| 763 | |
| 764 | static object * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 765 | cdparser_getattr(self, name) |
| 766 | cdparserobject *self; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 767 | char *name; |
| 768 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 769 | if (self->ob_cdparser == NULL) { |
| 770 | err_setstr(RuntimeError, "no parser active"); |
| 771 | return NULL; |
| 772 | } |
| 773 | |
| 774 | return findmethod(cdparser_methods, (object *)self, name); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | typeobject CdParsertype = { |
| 778 | OB_HEAD_INIT(&Typetype) |
| 779 | 0, /*ob_size*/ |
| 780 | "cdparser", /*tp_name*/ |
| 781 | sizeof(cdparserobject), /*tp_size*/ |
| 782 | 0, /*tp_itemsize*/ |
| 783 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 784 | (destructor)cdparser_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 785 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 786 | (getattrfunc)cdparser_getattr, /*tp_getattr*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 787 | 0, /*tp_setattr*/ |
| 788 | 0, /*tp_compare*/ |
| 789 | 0, /*tp_repr*/ |
| 790 | }; |
| 791 | |
| 792 | static object * |
| 793 | newcdparserobject(cdp) |
| 794 | CDPARSER *cdp; |
| 795 | { |
| 796 | cdparserobject *p; |
| 797 | int i; |
| 798 | |
| 799 | p = NEWOBJ(cdparserobject, &CdParsertype); |
| 800 | if (p == NULL) |
| 801 | return NULL; |
| 802 | p->ob_cdparser = cdp; |
| 803 | for (i = 0; i < NCALLBACKS; i++) { |
| 804 | p->ob_cdcallbacks[i].ob_cdcallback = NULL; |
| 805 | p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 806 | } |
| 807 | return (object *) p; |
| 808 | } |
| 809 | |
| 810 | static object * |
| 811 | CD_createparser(self, args) |
| 812 | object *self, *args; |
| 813 | { |
| 814 | CDPARSER *cdp; |
| 815 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 816 | if (!newgetargs(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 817 | return NULL; |
| 818 | cdp = CDcreateparser(); |
| 819 | if (cdp == NULL) { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 820 | err_setstr(CdError, "createparser failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 821 | return NULL; |
| 822 | } |
| 823 | |
| 824 | return newcdparserobject(cdp); |
| 825 | } |
| 826 | |
| 827 | static object * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 828 | CD_msftoframe(self, args) |
| 829 | object *self, *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 830 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 831 | int min, sec, frame; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 832 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 833 | if (!newgetargs(args, "iii", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 834 | return NULL; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 835 | |
| 836 | return newintobject((long) CDmsftoframe(min, sec, frame)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 837 | } |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 838 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 839 | static struct methodlist CD_methods[] = { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 840 | {"open", (method)CD_open, 1}, |
| 841 | {"createparser", (method)CD_createparser, 1}, |
| 842 | {"msftoframe", (method)CD_msftoframe, 1}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 843 | {NULL, NULL} /* Sentinel */ |
| 844 | }; |
| 845 | |
| 846 | void |
| 847 | initcd() |
| 848 | { |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 849 | object *m, *d; |
| 850 | |
| 851 | m = initmodule("cd", CD_methods); |
| 852 | d = getmoduledict(m); |
| 853 | |
| 854 | CdError = newstringobject("cd.error"); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 855 | dictinsert(d, "error", CdError); |
| 856 | |
| 857 | /* Identifiers for the different types of callbacks from the parser */ |
| 858 | dictinsert(d, "audio", newintobject((long) cd_audio)); |
| 859 | dictinsert(d, "pnum", newintobject((long) cd_pnum)); |
| 860 | dictinsert(d, "index", newintobject((long) cd_index)); |
| 861 | dictinsert(d, "ptime", newintobject((long) cd_ptime)); |
| 862 | dictinsert(d, "atime", newintobject((long) cd_atime)); |
| 863 | dictinsert(d, "catalog", newintobject((long) cd_catalog)); |
| 864 | dictinsert(d, "ident", newintobject((long) cd_ident)); |
| 865 | dictinsert(d, "control", newintobject((long) cd_control)); |
| 866 | |
| 867 | /* Block size information for digital audio data */ |
| 868 | dictinsert(d, "DATASIZE", newintobject((long) CDDA_DATASIZE)); |
| 869 | dictinsert(d, "BLOCKSIZE", newintobject((long) CDDA_BLOCKSIZE)); |
| 870 | |
| 871 | /* Possible states for the cd player */ |
| 872 | dictinsert(d, "ERROR", newintobject((long) CD_ERROR)); |
| 873 | dictinsert(d, "NODISC", newintobject((long) CD_NODISC)); |
| 874 | dictinsert(d, "READY", newintobject((long) CD_READY)); |
| 875 | dictinsert(d, "PLAYING", newintobject((long) CD_PLAYING)); |
| 876 | dictinsert(d, "PAUSED", newintobject((long) CD_PAUSED)); |
| 877 | dictinsert(d, "STILL", newintobject((long) CD_STILL)); |
| 878 | #ifdef CD_CDROM /* only newer versions of the library */ |
| 879 | dictinsert(d, "CDROM", newintobject((long) CD_CDROM)); |
| 880 | #endif |
| 881 | |
| 882 | if (err_occurred()) |
| 883 | fatal("can't initialize module cd"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 884 | } |