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