1992-04-13 15:22:53 -03:00
|
|
|
/* CD module -- interface to Mark Callow's and Roger Chickering's */
|
|
|
|
/* CD Audio Library (CD). */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <cdaudio.h>
|
1997-01-03 19:00:51 -04:00
|
|
|
#include "Python.h"
|
1992-04-13 15:22:53 -03:00
|
|
|
|
|
|
|
#define NCALLBACKS 8
|
|
|
|
|
|
|
|
typedef struct {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyObject_HEAD
|
1992-04-13 15:22:53 -03:00
|
|
|
CDPLAYER *ob_cdplayer;
|
|
|
|
} cdplayerobject;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *CdError; /* exception cd.error */
|
1992-09-24 07:48:40 -03:00
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_allowremoval(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":allowremoval"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CDallowremoval(self->ob_cdplayer);
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_preventremoval(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":preventremoval"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CDpreventremoval(self->ob_cdplayer);
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_bestreadsize(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":bestreadsize"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return PyInt_FromLong((long) CDbestreadsize(self->ob_cdplayer));
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_close(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":close"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDclose(self->ob_cdplayer)) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetFromErrno(CdError); /* XXX - ??? */
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
self->ob_cdplayer = NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_eject(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":eject"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDeject(self->ob_cdplayer)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "eject failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_getstatus(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
CDSTATUS status;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":getstatus"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDgetstatus(self->ob_cdplayer, &status)) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetFromErrno(CdError); /* XXX - ??? */
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return Py_BuildValue("(ii(iii)(iii)(iii)iiii)", status.state,
|
1992-04-15 12:56:11 -03:00
|
|
|
status.track, status.min, status.sec, status.frame,
|
|
|
|
status.abs_min, status.abs_sec, status.abs_frame,
|
|
|
|
status.total_min, status.total_sec, status.total_frame,
|
|
|
|
status.first, status.last, status.scsi_audio,
|
1995-03-28 08:06:23 -04:00
|
|
|
status.cur_block);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_gettrackinfo(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int track;
|
|
|
|
CDTRACKINFO info;
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "i:gettrackinfo", &track))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDgettrackinfo(self->ob_cdplayer, track, &info)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "gettrackinfo failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return Py_BuildValue("((iii)(iii))",
|
1992-04-13 15:22:53 -03:00
|
|
|
info.start_min, info.start_sec, info.start_frame,
|
|
|
|
info.total_min, info.total_sec, info.total_frame);
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_msftoblock(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int min, sec, frame;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "iii:msftoblock", &min, &sec, &frame))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return PyInt_FromLong((long) CDmsftoblock(self->ob_cdplayer,
|
1995-03-28 08:06:23 -04:00
|
|
|
min, sec, frame));
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_play(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int start, play;
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "ii:play", &start, &play))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDplay(self->ob_cdplayer, start, play)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "play failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_playabs(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int min, sec, frame, play;
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "iiii:playabs", &min, &sec, &frame, &play))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDplayabs(self->ob_cdplayer, min, sec, frame, play)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "playabs failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_playtrack(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int start, play;
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "ii:playtrack", &start, &play))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDplaytrack(self->ob_cdplayer, start, play)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "playtrack failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_playtrackabs(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int track, min, sec, frame, play;
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "iiiii:playtrackabs", &track, &min, &sec,
|
1997-01-03 19:00:51 -04:00
|
|
|
&frame, &play))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDplaytrackabs(self->ob_cdplayer, track, min, sec, frame, play)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "playtrackabs failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_readda(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int numframes, n;
|
1997-01-03 19:00:51 -04:00
|
|
|
PyObject *result;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "i:readda", &numframes))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
result = PyString_FromStringAndSize(NULL, numframes * sizeof(CDFRAME));
|
1992-04-13 15:22:53 -03:00
|
|
|
if (result == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
n = CDreadda(self->ob_cdplayer,
|
|
|
|
(CDFRAME *) PyString_AsString(result), numframes);
|
1992-04-13 15:22:53 -03:00
|
|
|
if (n == -1) {
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_DECREF(result);
|
|
|
|
PyErr_SetFromErrno(CdError);
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (n < numframes)
|
2002-04-27 15:44:32 -03:00
|
|
|
_PyString_Resize(&result, n * sizeof(CDFRAME));
|
1992-04-13 15:22:53 -03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_seek(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int min, sec, frame;
|
1997-01-03 19:00:51 -04:00
|
|
|
long PyTryBlock;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "iii:seek", &min, &sec, &frame))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
PyTryBlock = CDseek(self->ob_cdplayer, min, sec, frame);
|
|
|
|
if (PyTryBlock == -1) {
|
|
|
|
PyErr_SetFromErrno(CdError);
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return PyInt_FromLong(PyTryBlock);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_seektrack(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int track;
|
1997-01-03 19:00:51 -04:00
|
|
|
long PyTryBlock;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "i:seektrack", &track))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
PyTryBlock = CDseektrack(self->ob_cdplayer, track);
|
|
|
|
if (PyTryBlock == -1) {
|
|
|
|
PyErr_SetFromErrno(CdError);
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return PyInt_FromLong(PyTryBlock);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_seekblock(cdplayerobject *self, PyObject *args)
|
1995-03-28 08:06:23 -04:00
|
|
|
{
|
1997-01-03 19:00:51 -04:00
|
|
|
unsigned long PyTryBlock;
|
1995-03-28 08:06:23 -04:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "l:seekblock", &PyTryBlock))
|
1995-03-28 08:06:23 -04:00
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
PyTryBlock = CDseekblock(self->ob_cdplayer, PyTryBlock);
|
|
|
|
if (PyTryBlock == (unsigned long) -1) {
|
|
|
|
PyErr_SetFromErrno(CdError);
|
1995-03-28 08:06:23 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return PyInt_FromLong(PyTryBlock);
|
1995-03-28 08:06:23 -04:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_stop(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":stop"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDstop(self->ob_cdplayer)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "stop failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_togglepause(cdplayerobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1992-05-06 06:48:30 -03:00
|
|
|
CDSTATUS status;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":togglepause"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!CDtogglepause(self->ob_cdplayer)) {
|
1992-05-06 06:48:30 -03:00
|
|
|
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
|
|
|
status.state == CD_NODISC)
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "no disc in player");
|
1992-05-06 06:48:30 -03:00
|
|
|
else
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "togglepause failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyMethodDef cdplayer_methods[] = {
|
2002-01-17 19:15:58 -04:00
|
|
|
{"allowremoval", (PyCFunction)CD_allowremoval, METH_VARARGS},
|
|
|
|
{"bestreadsize", (PyCFunction)CD_bestreadsize, METH_VARARGS},
|
|
|
|
{"close", (PyCFunction)CD_close, METH_VARARGS},
|
|
|
|
{"eject", (PyCFunction)CD_eject, METH_VARARGS},
|
|
|
|
{"getstatus", (PyCFunction)CD_getstatus, METH_VARARGS},
|
|
|
|
{"gettrackinfo", (PyCFunction)CD_gettrackinfo, METH_VARARGS},
|
|
|
|
{"msftoblock", (PyCFunction)CD_msftoblock, METH_VARARGS},
|
|
|
|
{"play", (PyCFunction)CD_play, METH_VARARGS},
|
|
|
|
{"playabs", (PyCFunction)CD_playabs, METH_VARARGS},
|
|
|
|
{"playtrack", (PyCFunction)CD_playtrack, METH_VARARGS},
|
|
|
|
{"playtrackabs", (PyCFunction)CD_playtrackabs, METH_VARARGS},
|
|
|
|
{"preventremoval", (PyCFunction)CD_preventremoval, METH_VARARGS},
|
|
|
|
{"readda", (PyCFunction)CD_readda, METH_VARARGS},
|
|
|
|
{"seek", (PyCFunction)CD_seek, METH_VARARGS},
|
|
|
|
{"seekblock", (PyCFunction)CD_seekblock, METH_VARARGS},
|
|
|
|
{"seektrack", (PyCFunction)CD_seektrack, METH_VARARGS},
|
|
|
|
{"stop", (PyCFunction)CD_stop, METH_VARARGS},
|
|
|
|
{"togglepause", (PyCFunction)CD_togglepause, METH_VARARGS},
|
1992-04-13 15:22:53 -03:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2000-07-10 14:04:33 -03:00
|
|
|
cdplayer_dealloc(cdplayerobject *self)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
if (self->ob_cdplayer != NULL)
|
|
|
|
CDclose(self->ob_cdplayer);
|
2000-05-03 20:44:39 -03:00
|
|
|
PyObject_Del(self);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
cdplayer_getattr(cdplayerobject *self, char *name)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1995-03-28 08:06:23 -04:00
|
|
|
if (self->ob_cdplayer == NULL) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(PyExc_RuntimeError, "no player active");
|
1995-03-28 08:06:23 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
1997-01-03 19:00:51 -04:00
|
|
|
return Py_FindMethod(cdplayer_methods, (PyObject *)self, name);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
PyTypeObject CdPlayertype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1992-04-13 15:22:53 -03:00
|
|
|
0, /*ob_size*/
|
2001-12-08 14:02:58 -04:00
|
|
|
"cd.cdplayer", /*tp_name*/
|
1992-04-13 15:22:53 -03:00
|
|
|
sizeof(cdplayerobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
1994-08-01 08:34:53 -03:00
|
|
|
(destructor)cdplayer_dealloc, /*tp_dealloc*/
|
1992-04-13 15:22:53 -03:00
|
|
|
0, /*tp_print*/
|
1994-08-01 08:34:53 -03:00
|
|
|
(getattrfunc)cdplayer_getattr, /*tp_getattr*/
|
1992-04-13 15:22:53 -03:00
|
|
|
0, /*tp_setattr*/
|
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
};
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
newcdplayerobject(CDPLAYER *cdp)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
cdplayerobject *p;
|
|
|
|
|
2000-05-03 20:44:39 -03:00
|
|
|
p = PyObject_New(cdplayerobject, &CdPlayertype);
|
1992-04-13 15:22:53 -03:00
|
|
|
if (p == NULL)
|
|
|
|
return NULL;
|
|
|
|
p->ob_cdplayer = cdp;
|
1997-01-03 19:00:51 -04:00
|
|
|
return (PyObject *) p;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_open(PyObject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
char *dev, *direction;
|
|
|
|
CDPLAYER *cdp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable number of args.
|
|
|
|
* First defaults to "None", second defaults to "r".
|
|
|
|
*/
|
|
|
|
dev = NULL;
|
|
|
|
direction = "r";
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "|zs:open", &dev, &direction))
|
1995-03-28 08:06:23 -04:00
|
|
|
return NULL;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
|
|
|
cdp = CDopen(dev, direction);
|
|
|
|
if (cdp == NULL) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetFromErrno(CdError);
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newcdplayerobject(cdp);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyObject_HEAD
|
1992-04-13 15:22:53 -03:00
|
|
|
CDPARSER *ob_cdparser;
|
|
|
|
struct {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyObject *ob_cdcallback;
|
|
|
|
PyObject *ob_cdcallbackarg;
|
1992-04-13 15:22:53 -03:00
|
|
|
} ob_cdcallbacks[NCALLBACKS];
|
|
|
|
} cdparserobject;
|
|
|
|
|
|
|
|
static void
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_callback(void *arg, CDDATATYPES type, void *data)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1997-01-03 19:00:51 -04:00
|
|
|
PyObject *result, *args, *v = NULL;
|
1992-04-13 15:22:53 -03:00
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
cdparserobject *self;
|
|
|
|
|
|
|
|
self = (cdparserobject *) arg;
|
1997-01-03 19:00:51 -04:00
|
|
|
args = PyTuple_New(3);
|
1992-04-13 15:22:53 -03:00
|
|
|
if (args == NULL)
|
|
|
|
return;
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
|
|
|
PyTuple_SetItem(args, 0, self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
|
|
|
PyTuple_SetItem(args, 1, PyInt_FromLong((long) type));
|
1992-04-13 15:22:53 -03:00
|
|
|
switch (type) {
|
|
|
|
case cd_audio:
|
1997-01-03 19:00:51 -04:00
|
|
|
v = PyString_FromStringAndSize(data, CDDA_DATASIZE);
|
1992-04-13 15:22:53 -03:00
|
|
|
break;
|
|
|
|
case cd_pnum:
|
|
|
|
case cd_index:
|
1997-01-03 19:00:51 -04:00
|
|
|
v = PyInt_FromLong(((CDPROGNUM *) data)->value);
|
1992-04-13 15:22:53 -03:00
|
|
|
break;
|
|
|
|
case cd_ptime:
|
|
|
|
case cd_atime:
|
1992-04-15 12:56:11 -03:00
|
|
|
#define ptr ((struct cdtimecode *) data)
|
1997-01-03 19:00:51 -04:00
|
|
|
v = Py_BuildValue("(iii)",
|
1995-03-28 08:06:23 -04:00
|
|
|
ptr->mhi * 10 + ptr->mlo,
|
1992-04-15 12:56:11 -03:00
|
|
|
ptr->shi * 10 + ptr->slo,
|
|
|
|
ptr->fhi * 10 + ptr->flo);
|
|
|
|
#undef ptr
|
1992-04-13 15:22:53 -03:00
|
|
|
break;
|
|
|
|
case cd_catalog:
|
1997-01-03 19:00:51 -04:00
|
|
|
v = PyString_FromStringAndSize(NULL, 13);
|
|
|
|
p = PyString_AsString(v);
|
1992-04-13 15:22:53 -03:00
|
|
|
for (i = 0; i < 13; i++)
|
|
|
|
*p++ = ((char *) data)[i] + '0';
|
|
|
|
break;
|
|
|
|
case cd_ident:
|
1995-03-28 08:06:23 -04:00
|
|
|
#define ptr ((struct cdident *) data)
|
1997-01-03 19:00:51 -04:00
|
|
|
v = PyString_FromStringAndSize(NULL, 12);
|
|
|
|
p = PyString_AsString(v);
|
1995-03-28 08:06:23 -04:00
|
|
|
CDsbtoa(p, ptr->country, 2);
|
1992-04-13 15:22:53 -03:00
|
|
|
p += 2;
|
1995-03-28 08:06:23 -04:00
|
|
|
CDsbtoa(p, ptr->owner, 3);
|
1992-04-13 15:22:53 -03:00
|
|
|
p += 3;
|
1995-03-28 08:06:23 -04:00
|
|
|
*p++ = ptr->year[0] + '0';
|
|
|
|
*p++ = ptr->year[1] + '0';
|
|
|
|
*p++ = ptr->serial[0] + '0';
|
|
|
|
*p++ = ptr->serial[1] + '0';
|
|
|
|
*p++ = ptr->serial[2] + '0';
|
|
|
|
*p++ = ptr->serial[3] + '0';
|
|
|
|
*p++ = ptr->serial[4] + '0';
|
|
|
|
#undef ptr
|
1992-04-13 15:22:53 -03:00
|
|
|
break;
|
|
|
|
case cd_control:
|
1997-01-03 19:00:51 -04:00
|
|
|
v = PyInt_FromLong((long) *((unchar *) data));
|
1992-04-13 15:22:53 -03:00
|
|
|
break;
|
|
|
|
}
|
1997-01-03 19:00:51 -04:00
|
|
|
PyTuple_SetItem(args, 2, v);
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
Py_DECREF(args);
|
1992-04-13 15:22:53 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
result = PyEval_CallObject(self->ob_cdcallbacks[type].ob_cdcallback,
|
|
|
|
args);
|
|
|
|
Py_DECREF(args);
|
|
|
|
Py_XDECREF(result);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_deleteparser(cdparserobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":deleteparser"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CDdeleteparser(self->ob_cdparser);
|
|
|
|
self->ob_cdparser = NULL;
|
|
|
|
|
|
|
|
/* no sense in keeping the callbacks, so remove them */
|
|
|
|
for (i = 0; i < NCALLBACKS; i++) {
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
|
1992-04-13 15:22:53 -03:00
|
|
|
self->ob_cdcallbacks[i].ob_cdcallback = NULL;
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
|
1992-04-13 15:22:53 -03:00
|
|
|
self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_parseframe(cdparserobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
char *cdfp;
|
|
|
|
int length;
|
|
|
|
CDFRAME *p;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "s#:parseframe", &cdfp, &length))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (length % sizeof(CDFRAME) != 0) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(PyExc_TypeError, "bad length");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (CDFRAME *) cdfp;
|
|
|
|
while (length > 0) {
|
|
|
|
CDparseframe(self->ob_cdparser, p);
|
|
|
|
length -= sizeof(CDFRAME);
|
|
|
|
p++;
|
1997-01-03 19:00:51 -04:00
|
|
|
if (PyErr_Occurred())
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_removecallback(cdparserobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "i:removecallback", &type))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
1992-08-03 16:06:59 -03:00
|
|
|
if (type < 0 || type >= NCALLBACKS) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(PyExc_TypeError, "bad type");
|
1992-08-03 16:06:59 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1992-04-13 15:22:53 -03:00
|
|
|
CDremovecallback(self->ob_cdparser, (CDDATATYPES) type);
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback);
|
1992-04-13 15:22:53 -03:00
|
|
|
self->ob_cdcallbacks[type].ob_cdcallback = NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
1992-04-13 15:22:53 -03:00
|
|
|
self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_resetparser(cdparserobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":resetparser"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CDresetparser(self->ob_cdparser);
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_addcallback(cdparserobject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int type;
|
1997-01-03 19:00:51 -04:00
|
|
|
PyObject *func, *funcarg;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
|
|
|
/* XXX - more work here */
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "iOO:addcallback", &type, &func, &funcarg))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (type < 0 || type >= NCALLBACKS) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(PyExc_TypeError, "argument out of range");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1992-09-25 08:15:58 -03:00
|
|
|
#ifdef CDsetcallback
|
1997-01-03 19:00:51 -04:00
|
|
|
CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback,
|
|
|
|
(void *) self);
|
1992-08-03 16:06:59 -03:00
|
|
|
#else
|
1997-01-03 19:00:51 -04:00
|
|
|
CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback,
|
|
|
|
(void *) self);
|
1992-08-03 16:06:59 -03:00
|
|
|
#endif
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback);
|
|
|
|
Py_INCREF(func);
|
1993-06-17 09:35:49 -03:00
|
|
|
self->ob_cdcallbacks[type].ob_cdcallback = func;
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
|
|
|
Py_INCREF(funcarg);
|
1993-06-17 09:35:49 -03:00
|
|
|
self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
1995-03-28 08:06:23 -04:00
|
|
|
/*
|
|
|
|
if (type == cd_audio) {
|
|
|
|
sigfpe_[_UNDERFL].repls = _ZERO;
|
1997-01-03 19:00:51 -04:00
|
|
|
handle_sigfpes(_ON, _EN_UNDERFL, NULL,
|
|
|
|
_ABORT_ON_ERROR, NULL);
|
1995-03-28 08:06:23 -04:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyMethodDef cdparser_methods[] = {
|
2002-01-17 19:15:58 -04:00
|
|
|
{"addcallback", (PyCFunction)CD_addcallback, METH_VARARGS},
|
|
|
|
{"deleteparser", (PyCFunction)CD_deleteparser, METH_VARARGS},
|
|
|
|
{"parseframe", (PyCFunction)CD_parseframe, METH_VARARGS},
|
|
|
|
{"removecallback", (PyCFunction)CD_removecallback, METH_VARARGS},
|
|
|
|
{"resetparser", (PyCFunction)CD_resetparser, METH_VARARGS},
|
1997-01-03 19:00:51 -04:00
|
|
|
/* backward compatibility */
|
2002-01-17 19:15:58 -04:00
|
|
|
{"setcallback", (PyCFunction)CD_addcallback, METH_VARARGS},
|
1992-04-13 15:22:53 -03:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2000-07-10 14:04:33 -03:00
|
|
|
cdparser_dealloc(cdparserobject *self)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NCALLBACKS; i++) {
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
|
1992-04-13 15:22:53 -03:00
|
|
|
self->ob_cdcallbacks[i].ob_cdcallback = NULL;
|
1997-01-03 19:00:51 -04:00
|
|
|
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
|
1992-04-13 15:22:53 -03:00
|
|
|
self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
|
|
|
}
|
|
|
|
CDdeleteparser(self->ob_cdparser);
|
2000-05-03 20:44:39 -03:00
|
|
|
PyObject_Del(self);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
cdparser_getattr(cdparserobject *self, char *name)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1995-03-28 08:06:23 -04:00
|
|
|
if (self->ob_cdparser == NULL) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(PyExc_RuntimeError, "no parser active");
|
1995-03-28 08:06:23 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return Py_FindMethod(cdparser_methods, (PyObject *)self, name);
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
PyTypeObject CdParsertype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1992-04-13 15:22:53 -03:00
|
|
|
0, /*ob_size*/
|
2001-12-08 14:02:58 -04:00
|
|
|
"cd.cdparser", /*tp_name*/
|
1992-04-13 15:22:53 -03:00
|
|
|
sizeof(cdparserobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
1994-08-01 08:34:53 -03:00
|
|
|
(destructor)cdparser_dealloc, /*tp_dealloc*/
|
1992-04-13 15:22:53 -03:00
|
|
|
0, /*tp_print*/
|
1994-08-01 08:34:53 -03:00
|
|
|
(getattrfunc)cdparser_getattr, /*tp_getattr*/
|
1992-04-13 15:22:53 -03:00
|
|
|
0, /*tp_setattr*/
|
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
};
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
newcdparserobject(CDPARSER *cdp)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
cdparserobject *p;
|
|
|
|
int i;
|
|
|
|
|
2000-05-03 20:44:39 -03:00
|
|
|
p = PyObject_New(cdparserobject, &CdParsertype);
|
1992-04-13 15:22:53 -03:00
|
|
|
if (p == NULL)
|
|
|
|
return NULL;
|
|
|
|
p->ob_cdparser = cdp;
|
|
|
|
for (i = 0; i < NCALLBACKS; i++) {
|
|
|
|
p->ob_cdcallbacks[i].ob_cdcallback = NULL;
|
|
|
|
p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
|
|
|
}
|
1997-01-03 19:00:51 -04:00
|
|
|
return (PyObject *) p;
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_createparser(PyObject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
|
|
|
CDPARSER *cdp;
|
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, ":createparser"))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
cdp = CDcreateparser();
|
|
|
|
if (cdp == NULL) {
|
1997-01-03 19:00:51 -04:00
|
|
|
PyErr_SetString(CdError, "createparser failed");
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newcdparserobject(cdp);
|
|
|
|
}
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
CD_msftoframe(PyObject *self, PyObject *args)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1995-03-28 08:06:23 -04:00
|
|
|
int min, sec, frame;
|
1992-04-13 15:22:53 -03:00
|
|
|
|
2000-02-29 09:59:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "iii:msftoframe", &min, &sec, &frame))
|
1992-04-13 15:22:53 -03:00
|
|
|
return NULL;
|
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
return PyInt_FromLong((long) CDmsftoframe(min, sec, frame));
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|
1995-03-28 08:06:23 -04:00
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
static PyMethodDef CD_methods[] = {
|
2002-01-17 19:15:58 -04:00
|
|
|
{"open", (PyCFunction)CD_open, METH_VARARGS},
|
|
|
|
{"createparser", (PyCFunction)CD_createparser, METH_VARARGS},
|
|
|
|
{"msftoframe", (PyCFunction)CD_msftoframe, METH_VARARGS},
|
1992-04-13 15:22:53 -03:00
|
|
|
{NULL, NULL} /* Sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2000-07-21 03:00:07 -03:00
|
|
|
initcd(void)
|
1992-04-13 15:22:53 -03:00
|
|
|
{
|
1997-01-03 19:00:51 -04:00
|
|
|
PyObject *m, *d;
|
1992-09-24 07:48:40 -03:00
|
|
|
|
1997-01-03 19:00:51 -04:00
|
|
|
m = Py_InitModule("cd", CD_methods);
|
|
|
|
d = PyModule_GetDict(m);
|
1992-09-24 07:48:40 -03:00
|
|
|
|
1997-10-01 01:43:39 -03:00
|
|
|
CdError = PyErr_NewException("cd.error", NULL, NULL);
|
1997-01-03 19:00:51 -04:00
|
|
|
PyDict_SetItemString(d, "error", CdError);
|
1995-03-28 08:06:23 -04:00
|
|
|
|
|
|
|
/* Identifiers for the different types of callbacks from the parser */
|
1997-01-03 19:00:51 -04:00
|
|
|
PyDict_SetItemString(d, "audio", PyInt_FromLong((long) cd_audio));
|
|
|
|
PyDict_SetItemString(d, "pnum", PyInt_FromLong((long) cd_pnum));
|
|
|
|
PyDict_SetItemString(d, "index", PyInt_FromLong((long) cd_index));
|
|
|
|
PyDict_SetItemString(d, "ptime", PyInt_FromLong((long) cd_ptime));
|
|
|
|
PyDict_SetItemString(d, "atime", PyInt_FromLong((long) cd_atime));
|
|
|
|
PyDict_SetItemString(d, "catalog", PyInt_FromLong((long) cd_catalog));
|
|
|
|
PyDict_SetItemString(d, "ident", PyInt_FromLong((long) cd_ident));
|
|
|
|
PyDict_SetItemString(d, "control", PyInt_FromLong((long) cd_control));
|
1995-03-28 08:06:23 -04:00
|
|
|
|
|
|
|
/* Block size information for digital audio data */
|
1997-01-03 19:00:51 -04:00
|
|
|
PyDict_SetItemString(d, "DATASIZE",
|
|
|
|
PyInt_FromLong((long) CDDA_DATASIZE));
|
|
|
|
PyDict_SetItemString(d, "BLOCKSIZE",
|
|
|
|
PyInt_FromLong((long) CDDA_BLOCKSIZE));
|
1995-03-28 08:06:23 -04:00
|
|
|
|
|
|
|
/* Possible states for the cd player */
|
1997-01-03 19:00:51 -04:00
|
|
|
PyDict_SetItemString(d, "ERROR", PyInt_FromLong((long) CD_ERROR));
|
|
|
|
PyDict_SetItemString(d, "NODISC", PyInt_FromLong((long) CD_NODISC));
|
|
|
|
PyDict_SetItemString(d, "READY", PyInt_FromLong((long) CD_READY));
|
|
|
|
PyDict_SetItemString(d, "PLAYING", PyInt_FromLong((long) CD_PLAYING));
|
|
|
|
PyDict_SetItemString(d, "PAUSED", PyInt_FromLong((long) CD_PAUSED));
|
|
|
|
PyDict_SetItemString(d, "STILL", PyInt_FromLong((long) CD_STILL));
|
1995-03-28 08:06:23 -04:00
|
|
|
#ifdef CD_CDROM /* only newer versions of the library */
|
1997-01-03 19:00:51 -04:00
|
|
|
PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM));
|
1995-03-28 08:06:23 -04:00
|
|
|
#endif
|
1992-04-13 15:22:53 -03:00
|
|
|
}
|