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) |
Tim Peters | 5de9842 | 2002-04-27 18:44:32 +0000 | [diff] [blame] | 254 | _PyString_Resize(&result, n * sizeof(CDFRAME)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 255 | |
| 256 | return result; |
| 257 | } |
| 258 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 259 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 260 | CD_seek(cdplayerobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 261 | { |
| 262 | int min, sec, frame; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 263 | long PyTryBlock; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 264 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 265 | if (!PyArg_ParseTuple(args, "iii:seek", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 266 | return NULL; |
| 267 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 268 | PyTryBlock = CDseek(self->ob_cdplayer, min, sec, frame); |
| 269 | if (PyTryBlock == -1) { |
| 270 | PyErr_SetFromErrno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 271 | return NULL; |
| 272 | } |
| 273 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 274 | return PyInt_FromLong(PyTryBlock); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 277 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 278 | CD_seektrack(cdplayerobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 279 | { |
| 280 | int track; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 281 | long PyTryBlock; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 282 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 283 | if (!PyArg_ParseTuple(args, "i:seektrack", &track)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 284 | return NULL; |
| 285 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 286 | PyTryBlock = CDseektrack(self->ob_cdplayer, track); |
| 287 | if (PyTryBlock == -1) { |
| 288 | PyErr_SetFromErrno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 289 | return NULL; |
| 290 | } |
| 291 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 292 | return PyInt_FromLong(PyTryBlock); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 295 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 296 | CD_seekblock(cdplayerobject *self, PyObject *args) |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 297 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 298 | unsigned long PyTryBlock; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 299 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 300 | if (!PyArg_ParseTuple(args, "l:seekblock", &PyTryBlock)) |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 301 | return NULL; |
| 302 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 303 | PyTryBlock = CDseekblock(self->ob_cdplayer, PyTryBlock); |
| 304 | if (PyTryBlock == (unsigned long) -1) { |
| 305 | PyErr_SetFromErrno(CdError); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 306 | return NULL; |
| 307 | } |
| 308 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 309 | return PyInt_FromLong(PyTryBlock); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 312 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 313 | CD_stop(cdplayerobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 314 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 315 | CDSTATUS status; |
| 316 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 317 | if (!PyArg_ParseTuple(args, ":stop")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 318 | return NULL; |
| 319 | |
| 320 | if (!CDstop(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 321 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 322 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 323 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 324 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 325 | PyErr_SetString(CdError, "stop failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 326 | return NULL; |
| 327 | } |
| 328 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 329 | Py_INCREF(Py_None); |
| 330 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 333 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 334 | CD_togglepause(cdplayerobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 335 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 336 | CDSTATUS status; |
| 337 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 338 | if (!PyArg_ParseTuple(args, ":togglepause")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 339 | return NULL; |
| 340 | |
| 341 | if (!CDtogglepause(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 342 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 343 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 344 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 345 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 346 | PyErr_SetString(CdError, "togglepause failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
| 349 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 350 | Py_INCREF(Py_None); |
| 351 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 354 | static PyMethodDef cdplayer_methods[] = { |
Martin v. Löwis | 43b936d | 2002-01-17 23:15:58 +0000 | [diff] [blame] | 355 | {"allowremoval", (PyCFunction)CD_allowremoval, METH_VARARGS}, |
| 356 | {"bestreadsize", (PyCFunction)CD_bestreadsize, METH_VARARGS}, |
| 357 | {"close", (PyCFunction)CD_close, METH_VARARGS}, |
| 358 | {"eject", (PyCFunction)CD_eject, METH_VARARGS}, |
| 359 | {"getstatus", (PyCFunction)CD_getstatus, METH_VARARGS}, |
| 360 | {"gettrackinfo", (PyCFunction)CD_gettrackinfo, METH_VARARGS}, |
| 361 | {"msftoblock", (PyCFunction)CD_msftoblock, METH_VARARGS}, |
| 362 | {"play", (PyCFunction)CD_play, METH_VARARGS}, |
| 363 | {"playabs", (PyCFunction)CD_playabs, METH_VARARGS}, |
| 364 | {"playtrack", (PyCFunction)CD_playtrack, METH_VARARGS}, |
| 365 | {"playtrackabs", (PyCFunction)CD_playtrackabs, METH_VARARGS}, |
| 366 | {"preventremoval", (PyCFunction)CD_preventremoval, METH_VARARGS}, |
| 367 | {"readda", (PyCFunction)CD_readda, METH_VARARGS}, |
| 368 | {"seek", (PyCFunction)CD_seek, METH_VARARGS}, |
| 369 | {"seekblock", (PyCFunction)CD_seekblock, METH_VARARGS}, |
| 370 | {"seektrack", (PyCFunction)CD_seektrack, METH_VARARGS}, |
| 371 | {"stop", (PyCFunction)CD_stop, METH_VARARGS}, |
| 372 | {"togglepause", (PyCFunction)CD_togglepause, METH_VARARGS}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 373 | {NULL, NULL} /* sentinel */ |
| 374 | }; |
| 375 | |
| 376 | static void |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 377 | cdplayer_dealloc(cdplayerobject *self) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 378 | { |
| 379 | if (self->ob_cdplayer != NULL) |
| 380 | CDclose(self->ob_cdplayer); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 381 | PyObject_Del(self); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 384 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 385 | cdplayer_getattr(cdplayerobject *self, char *name) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 386 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 387 | if (self->ob_cdplayer == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 388 | PyErr_SetString(PyExc_RuntimeError, "no player active"); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 389 | return NULL; |
| 390 | } |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 391 | return Py_FindMethod(cdplayer_methods, (PyObject *)self, name); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 394 | PyTypeObject CdPlayertype = { |
| 395 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 396 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 397 | "cd.cdplayer", /*tp_name*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 398 | sizeof(cdplayerobject), /*tp_size*/ |
| 399 | 0, /*tp_itemsize*/ |
| 400 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 401 | (destructor)cdplayer_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 402 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 403 | (getattrfunc)cdplayer_getattr, /*tp_getattr*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 404 | 0, /*tp_setattr*/ |
| 405 | 0, /*tp_compare*/ |
| 406 | 0, /*tp_repr*/ |
| 407 | }; |
| 408 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 409 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 410 | newcdplayerobject(CDPLAYER *cdp) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 411 | { |
| 412 | cdplayerobject *p; |
| 413 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 414 | p = PyObject_New(cdplayerobject, &CdPlayertype); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 415 | if (p == NULL) |
| 416 | return NULL; |
| 417 | p->ob_cdplayer = cdp; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 418 | return (PyObject *) p; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 421 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 422 | CD_open(PyObject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 423 | { |
| 424 | char *dev, *direction; |
| 425 | CDPLAYER *cdp; |
| 426 | |
| 427 | /* |
| 428 | * Variable number of args. |
| 429 | * First defaults to "None", second defaults to "r". |
| 430 | */ |
| 431 | dev = NULL; |
| 432 | direction = "r"; |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 433 | if (!PyArg_ParseTuple(args, "|zs:open", &dev, &direction)) |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 434 | return NULL; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 435 | |
| 436 | cdp = CDopen(dev, direction); |
| 437 | if (cdp == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 438 | PyErr_SetFromErrno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 439 | return NULL; |
| 440 | } |
| 441 | |
| 442 | return newcdplayerobject(cdp); |
| 443 | } |
| 444 | |
| 445 | typedef struct { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 446 | PyObject_HEAD |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 447 | CDPARSER *ob_cdparser; |
| 448 | struct { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 449 | PyObject *ob_cdcallback; |
| 450 | PyObject *ob_cdcallbackarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 451 | } ob_cdcallbacks[NCALLBACKS]; |
| 452 | } cdparserobject; |
| 453 | |
| 454 | static void |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 455 | CD_callback(void *arg, CDDATATYPES type, void *data) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 456 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 457 | PyObject *result, *args, *v = NULL; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 458 | char *p; |
| 459 | int i; |
| 460 | cdparserobject *self; |
| 461 | |
| 462 | self = (cdparserobject *) arg; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 463 | args = PyTuple_New(3); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 464 | if (args == NULL) |
| 465 | return; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 466 | Py_INCREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 467 | PyTuple_SetItem(args, 0, self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 468 | PyTuple_SetItem(args, 1, PyInt_FromLong((long) type)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 469 | switch (type) { |
| 470 | case cd_audio: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 471 | v = PyString_FromStringAndSize(data, CDDA_DATASIZE); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 472 | break; |
| 473 | case cd_pnum: |
| 474 | case cd_index: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 475 | v = PyInt_FromLong(((CDPROGNUM *) data)->value); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 476 | break; |
| 477 | case cd_ptime: |
| 478 | case cd_atime: |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 479 | #define ptr ((struct cdtimecode *) data) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 480 | v = Py_BuildValue("(iii)", |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 481 | ptr->mhi * 10 + ptr->mlo, |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 482 | ptr->shi * 10 + ptr->slo, |
| 483 | ptr->fhi * 10 + ptr->flo); |
| 484 | #undef ptr |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 485 | break; |
| 486 | case cd_catalog: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 487 | v = PyString_FromStringAndSize(NULL, 13); |
| 488 | p = PyString_AsString(v); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 489 | for (i = 0; i < 13; i++) |
| 490 | *p++ = ((char *) data)[i] + '0'; |
| 491 | break; |
| 492 | case cd_ident: |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 493 | #define ptr ((struct cdident *) data) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 494 | v = PyString_FromStringAndSize(NULL, 12); |
| 495 | p = PyString_AsString(v); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 496 | CDsbtoa(p, ptr->country, 2); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 497 | p += 2; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 498 | CDsbtoa(p, ptr->owner, 3); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 499 | p += 3; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 500 | *p++ = ptr->year[0] + '0'; |
| 501 | *p++ = ptr->year[1] + '0'; |
| 502 | *p++ = ptr->serial[0] + '0'; |
| 503 | *p++ = ptr->serial[1] + '0'; |
| 504 | *p++ = ptr->serial[2] + '0'; |
| 505 | *p++ = ptr->serial[3] + '0'; |
| 506 | *p++ = ptr->serial[4] + '0'; |
| 507 | #undef ptr |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 508 | break; |
| 509 | case cd_control: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 510 | v = PyInt_FromLong((long) *((unchar *) data)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 511 | break; |
| 512 | } |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 513 | PyTuple_SetItem(args, 2, v); |
| 514 | if (PyErr_Occurred()) { |
| 515 | Py_DECREF(args); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 516 | return; |
| 517 | } |
| 518 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 519 | result = PyEval_CallObject(self->ob_cdcallbacks[type].ob_cdcallback, |
| 520 | args); |
| 521 | Py_DECREF(args); |
| 522 | Py_XDECREF(result); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 525 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 526 | CD_deleteparser(cdparserobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 527 | { |
| 528 | int i; |
| 529 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 530 | if (!PyArg_ParseTuple(args, ":deleteparser")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 531 | return NULL; |
| 532 | |
| 533 | CDdeleteparser(self->ob_cdparser); |
| 534 | self->ob_cdparser = NULL; |
| 535 | |
| 536 | /* no sense in keeping the callbacks, so remove them */ |
| 537 | for (i = 0; i < NCALLBACKS; i++) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 538 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 539 | self->ob_cdcallbacks[i].ob_cdcallback = NULL; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 540 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 541 | self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 542 | } |
| 543 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 544 | Py_INCREF(Py_None); |
| 545 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 548 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 549 | CD_parseframe(cdparserobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 550 | { |
| 551 | char *cdfp; |
| 552 | int length; |
| 553 | CDFRAME *p; |
| 554 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 555 | if (!PyArg_ParseTuple(args, "s#:parseframe", &cdfp, &length)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 556 | return NULL; |
| 557 | |
| 558 | if (length % sizeof(CDFRAME) != 0) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 559 | PyErr_SetString(PyExc_TypeError, "bad length"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 560 | return NULL; |
| 561 | } |
| 562 | |
| 563 | p = (CDFRAME *) cdfp; |
| 564 | while (length > 0) { |
| 565 | CDparseframe(self->ob_cdparser, p); |
| 566 | length -= sizeof(CDFRAME); |
| 567 | p++; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 568 | if (PyErr_Occurred()) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 569 | return NULL; |
| 570 | } |
| 571 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 572 | Py_INCREF(Py_None); |
| 573 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 576 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 577 | CD_removecallback(cdparserobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 578 | { |
| 579 | int type; |
| 580 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 581 | if (!PyArg_ParseTuple(args, "i:removecallback", &type)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 582 | return NULL; |
| 583 | |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 584 | if (type < 0 || type >= NCALLBACKS) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 585 | PyErr_SetString(PyExc_TypeError, "bad type"); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 586 | return NULL; |
| 587 | } |
| 588 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 589 | CDremovecallback(self->ob_cdparser, (CDDATATYPES) type); |
| 590 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 591 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 592 | self->ob_cdcallbacks[type].ob_cdcallback = NULL; |
| 593 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 594 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 595 | self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL; |
| 596 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 597 | Py_INCREF(Py_None); |
| 598 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 601 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 602 | CD_resetparser(cdparserobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 603 | { |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 604 | if (!PyArg_ParseTuple(args, ":resetparser")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 605 | return NULL; |
| 606 | |
| 607 | CDresetparser(self->ob_cdparser); |
| 608 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 609 | Py_INCREF(Py_None); |
| 610 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 613 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 614 | CD_addcallback(cdparserobject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 615 | { |
| 616 | int type; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 617 | PyObject *func, *funcarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 618 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 619 | /* XXX - more work here */ |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 620 | if (!PyArg_ParseTuple(args, "iOO:addcallback", &type, &func, &funcarg)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 621 | return NULL; |
| 622 | |
| 623 | if (type < 0 || type >= NCALLBACKS) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 624 | PyErr_SetString(PyExc_TypeError, "argument out of range"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 625 | return NULL; |
| 626 | } |
| 627 | |
Sjoerd Mullender | 7c4eb40 | 1992-09-25 11:15:58 +0000 | [diff] [blame] | 628 | #ifdef CDsetcallback |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 629 | CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, |
| 630 | (void *) self); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 631 | #else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 632 | CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, |
| 633 | (void *) self); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 634 | #endif |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 635 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); |
| 636 | Py_INCREF(func); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 637 | self->ob_cdcallbacks[type].ob_cdcallback = func; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 638 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 639 | Py_INCREF(funcarg); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 640 | self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 641 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 642 | /* |
| 643 | if (type == cd_audio) { |
| 644 | sigfpe_[_UNDERFL].repls = _ZERO; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 645 | handle_sigfpes(_ON, _EN_UNDERFL, NULL, |
| 646 | _ABORT_ON_ERROR, NULL); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 647 | } |
| 648 | */ |
| 649 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 650 | Py_INCREF(Py_None); |
| 651 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 654 | static PyMethodDef cdparser_methods[] = { |
Martin v. Löwis | 43b936d | 2002-01-17 23:15:58 +0000 | [diff] [blame] | 655 | {"addcallback", (PyCFunction)CD_addcallback, METH_VARARGS}, |
| 656 | {"deleteparser", (PyCFunction)CD_deleteparser, METH_VARARGS}, |
| 657 | {"parseframe", (PyCFunction)CD_parseframe, METH_VARARGS}, |
| 658 | {"removecallback", (PyCFunction)CD_removecallback, METH_VARARGS}, |
| 659 | {"resetparser", (PyCFunction)CD_resetparser, METH_VARARGS}, |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 660 | /* backward compatibility */ |
Martin v. Löwis | 43b936d | 2002-01-17 23:15:58 +0000 | [diff] [blame] | 661 | {"setcallback", (PyCFunction)CD_addcallback, METH_VARARGS}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 662 | {NULL, NULL} /* sentinel */ |
| 663 | }; |
| 664 | |
| 665 | static void |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 666 | cdparser_dealloc(cdparserobject *self) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 667 | { |
| 668 | int i; |
| 669 | |
| 670 | for (i = 0; i < NCALLBACKS; i++) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 671 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 672 | self->ob_cdcallbacks[i].ob_cdcallback = NULL; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 673 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 674 | self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 675 | } |
| 676 | CDdeleteparser(self->ob_cdparser); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 677 | PyObject_Del(self); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 680 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 681 | cdparser_getattr(cdparserobject *self, char *name) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 682 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 683 | if (self->ob_cdparser == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 684 | PyErr_SetString(PyExc_RuntimeError, "no parser active"); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 685 | return NULL; |
| 686 | } |
| 687 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 688 | return Py_FindMethod(cdparser_methods, (PyObject *)self, name); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 691 | PyTypeObject CdParsertype = { |
| 692 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 693 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 694 | "cd.cdparser", /*tp_name*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 695 | sizeof(cdparserobject), /*tp_size*/ |
| 696 | 0, /*tp_itemsize*/ |
| 697 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 698 | (destructor)cdparser_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 699 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 700 | (getattrfunc)cdparser_getattr, /*tp_getattr*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 701 | 0, /*tp_setattr*/ |
| 702 | 0, /*tp_compare*/ |
| 703 | 0, /*tp_repr*/ |
| 704 | }; |
| 705 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 706 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 707 | newcdparserobject(CDPARSER *cdp) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 708 | { |
| 709 | cdparserobject *p; |
| 710 | int i; |
| 711 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 712 | p = PyObject_New(cdparserobject, &CdParsertype); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 713 | if (p == NULL) |
| 714 | return NULL; |
| 715 | p->ob_cdparser = cdp; |
| 716 | for (i = 0; i < NCALLBACKS; i++) { |
| 717 | p->ob_cdcallbacks[i].ob_cdcallback = NULL; |
| 718 | p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 719 | } |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 720 | return (PyObject *) p; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 723 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 724 | CD_createparser(PyObject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 725 | { |
| 726 | CDPARSER *cdp; |
| 727 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 728 | if (!PyArg_ParseTuple(args, ":createparser")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 729 | return NULL; |
| 730 | cdp = CDcreateparser(); |
| 731 | if (cdp == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 732 | PyErr_SetString(CdError, "createparser failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 733 | return NULL; |
| 734 | } |
| 735 | |
| 736 | return newcdparserobject(cdp); |
| 737 | } |
| 738 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 739 | static PyObject * |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 740 | CD_msftoframe(PyObject *self, PyObject *args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 741 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 742 | int min, sec, frame; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 743 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 744 | if (!PyArg_ParseTuple(args, "iii:msftoframe", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 745 | return NULL; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 746 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 747 | return PyInt_FromLong((long) CDmsftoframe(min, sec, frame)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 748 | } |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 749 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 750 | static PyMethodDef CD_methods[] = { |
Martin v. Löwis | 43b936d | 2002-01-17 23:15:58 +0000 | [diff] [blame] | 751 | {"open", (PyCFunction)CD_open, METH_VARARGS}, |
| 752 | {"createparser", (PyCFunction)CD_createparser, METH_VARARGS}, |
| 753 | {"msftoframe", (PyCFunction)CD_msftoframe, METH_VARARGS}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 754 | {NULL, NULL} /* Sentinel */ |
| 755 | }; |
| 756 | |
| 757 | void |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 758 | initcd(void) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 759 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 760 | PyObject *m, *d; |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 761 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 762 | m = Py_InitModule("cd", CD_methods); |
| 763 | d = PyModule_GetDict(m); |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 764 | |
Guido van Rossum | 88d8bee | 1997-10-01 04:43:39 +0000 | [diff] [blame] | 765 | CdError = PyErr_NewException("cd.error", NULL, NULL); |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 766 | PyDict_SetItemString(d, "error", CdError); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 767 | |
| 768 | /* Identifiers for the different types of callbacks from the parser */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 769 | PyDict_SetItemString(d, "audio", PyInt_FromLong((long) cd_audio)); |
| 770 | PyDict_SetItemString(d, "pnum", PyInt_FromLong((long) cd_pnum)); |
| 771 | PyDict_SetItemString(d, "index", PyInt_FromLong((long) cd_index)); |
| 772 | PyDict_SetItemString(d, "ptime", PyInt_FromLong((long) cd_ptime)); |
| 773 | PyDict_SetItemString(d, "atime", PyInt_FromLong((long) cd_atime)); |
| 774 | PyDict_SetItemString(d, "catalog", PyInt_FromLong((long) cd_catalog)); |
| 775 | PyDict_SetItemString(d, "ident", PyInt_FromLong((long) cd_ident)); |
| 776 | PyDict_SetItemString(d, "control", PyInt_FromLong((long) cd_control)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 777 | |
| 778 | /* Block size information for digital audio data */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 779 | PyDict_SetItemString(d, "DATASIZE", |
| 780 | PyInt_FromLong((long) CDDA_DATASIZE)); |
| 781 | PyDict_SetItemString(d, "BLOCKSIZE", |
| 782 | PyInt_FromLong((long) CDDA_BLOCKSIZE)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 783 | |
| 784 | /* Possible states for the cd player */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 785 | PyDict_SetItemString(d, "ERROR", PyInt_FromLong((long) CD_ERROR)); |
| 786 | PyDict_SetItemString(d, "NODISC", PyInt_FromLong((long) CD_NODISC)); |
| 787 | PyDict_SetItemString(d, "READY", PyInt_FromLong((long) CD_READY)); |
| 788 | PyDict_SetItemString(d, "PLAYING", PyInt_FromLong((long) CD_PLAYING)); |
| 789 | PyDict_SetItemString(d, "PAUSED", PyInt_FromLong((long) CD_PAUSED)); |
| 790 | PyDict_SetItemString(d, "STILL", PyInt_FromLong((long) CD_STILL)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 791 | #ifdef CD_CDROM /* only newer versions of the library */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 792 | PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 793 | #endif |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 794 | } |