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