| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | /**********************************************************
 | 
					
						
							| 
									
										
										
										
											2000-06-30 23:50:40 +00:00
										 |  |  | Copyright (c) 2000, BeOpen.com. | 
					
						
							|  |  |  | Copyright (c) 1995-2000, Corporation for National Research Initiatives. | 
					
						
							|  |  |  | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. | 
					
						
							|  |  |  | All rights reserved. | 
					
						
							| 
									
										
										
										
											1996-10-25 14:44:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-30 23:50:40 +00:00
										 |  |  | See the file "Misc/COPYRIGHT" for information on usage and | 
					
						
							|  |  |  | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00: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 23:00:51 +00:00
										 |  |  | #include "Python.h"
 | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define NCALLBACKS	8
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyObject_HEAD | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	CDPLAYER *ob_cdplayer; | 
					
						
							|  |  |  | } cdplayerobject; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject *CdError;		/* exception cd.error */ | 
					
						
							| 
									
										
										
										
											1992-09-24 10:48:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_allowremoval(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":allowremoval")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CDallowremoval(self->ob_cdplayer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_preventremoval(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":preventremoval")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CDpreventremoval(self->ob_cdplayer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_bestreadsize(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":bestreadsize")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return PyInt_FromLong((long) CDbestreadsize(self->ob_cdplayer)); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_close(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":close")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDclose(self->ob_cdplayer)) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetFromErrno(CdError); /* XXX - ??? */ | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	self->ob_cdplayer = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_eject(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":eject")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDeject(self->ob_cdplayer)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "eject failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_getstatus(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	CDSTATUS status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":getstatus")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDgetstatus(self->ob_cdplayer, &status)) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetFromErrno(CdError); /* XXX - ??? */ | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return Py_BuildValue("(ii(iii)(iii)(iii)iiii)", status.state, | 
					
						
							| 
									
										
										
										
											1992-04-15 15:56:11 +00: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 12:06:23 +00:00
										 |  |  | 		       status.cur_block); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_gettrackinfo(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int track; | 
					
						
							|  |  |  | 	CDTRACKINFO info; | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "i:gettrackinfo", &track)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDgettrackinfo(self->ob_cdplayer, track, &info)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "gettrackinfo failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return Py_BuildValue("((iii)(iii))", | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		       info.start_min, info.start_sec, info.start_frame, | 
					
						
							|  |  |  | 		       info.total_min, info.total_sec, info.total_frame); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_msftoblock(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int min, sec, frame; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "iii:msftoblock", &min, &sec, &frame)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return PyInt_FromLong((long) CDmsftoblock(self->ob_cdplayer, | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 						min, sec, frame)); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_play(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int start, play; | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "ii:play", &start, &play)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDplay(self->ob_cdplayer, start, play)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "play failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_playabs(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int min, sec, frame, play; | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "iiii:playabs", &min, &sec, &frame, &play)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDplayabs(self->ob_cdplayer, min, sec, frame, play)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "playabs failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_playtrack(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int start, play; | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "ii:playtrack", &start, &play)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDplaytrack(self->ob_cdplayer, start, play)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "playtrack failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_playtrackabs(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int track, min, sec, frame, play; | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "iiiii:playtrackabs", &track, &min, &sec, | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			      &frame, &play)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDplaytrackabs(self->ob_cdplayer, track, min, sec, frame, play)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "playtrackabs failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_readda(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int numframes, n; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyObject *result; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "i:readda", &numframes)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	result = PyString_FromStringAndSize(NULL, numframes * sizeof(CDFRAME)); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	if (result == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	n = CDreadda(self->ob_cdplayer, | 
					
						
							|  |  |  | 		       (CDFRAME *) PyString_AsString(result), numframes); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	if (n == -1) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		Py_DECREF(result); | 
					
						
							|  |  |  | 		PyErr_SetFromErrno(CdError); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (n < numframes) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		if (_PyString_Resize(&result, n * sizeof(CDFRAME))) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_seek(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int min, sec, frame; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	long PyTryBlock; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "iii:seek", &min, &sec, &frame)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyTryBlock = CDseek(self->ob_cdplayer, min, sec, frame); | 
					
						
							|  |  |  | 	if (PyTryBlock == -1) { | 
					
						
							|  |  |  | 		PyErr_SetFromErrno(CdError); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return PyInt_FromLong(PyTryBlock); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_seektrack(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int track; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	long PyTryBlock; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "i:seektrack", &track)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyTryBlock = CDseektrack(self->ob_cdplayer, track); | 
					
						
							|  |  |  | 	if (PyTryBlock == -1) { | 
					
						
							|  |  |  | 		PyErr_SetFromErrno(CdError); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return PyInt_FromLong(PyTryBlock); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_seekblock(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	unsigned long PyTryBlock; | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "l:seekblock", &PyTryBlock)) | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyTryBlock = CDseekblock(self->ob_cdplayer, PyTryBlock); | 
					
						
							|  |  |  | 	if (PyTryBlock == (unsigned long) -1) { | 
					
						
							|  |  |  | 		PyErr_SetFromErrno(CdError); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return PyInt_FromLong(PyTryBlock); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_stop(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":stop")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDstop(self->ob_cdplayer)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "stop failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_togglepause(cdplayerobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 	CDSTATUS status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":togglepause")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CDtogglepause(self->ob_cdplayer)) { | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		if (CDgetstatus(self->ob_cdplayer, &status) && | 
					
						
							|  |  |  | 		    status.state == CD_NODISC) | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "no disc in player"); | 
					
						
							| 
									
										
										
										
											1992-05-06 09:48:30 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 			PyErr_SetString(CdError, "togglepause failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyMethodDef cdplayer_methods[] = { | 
					
						
							|  |  |  | 	{"allowremoval",	(PyCFunction)CD_allowremoval,	1}, | 
					
						
							|  |  |  | 	{"bestreadsize",	(PyCFunction)CD_bestreadsize,	1}, | 
					
						
							|  |  |  | 	{"close",		(PyCFunction)CD_close,		1}, | 
					
						
							|  |  |  | 	{"eject",		(PyCFunction)CD_eject,		1}, | 
					
						
							|  |  |  | 	{"getstatus",		(PyCFunction)CD_getstatus,		1}, | 
					
						
							|  |  |  | 	{"gettrackinfo",	(PyCFunction)CD_gettrackinfo,	1}, | 
					
						
							|  |  |  | 	{"msftoblock",		(PyCFunction)CD_msftoblock,		1}, | 
					
						
							|  |  |  | 	{"play",		(PyCFunction)CD_play,		1}, | 
					
						
							|  |  |  | 	{"playabs",		(PyCFunction)CD_playabs,		1}, | 
					
						
							|  |  |  | 	{"playtrack",		(PyCFunction)CD_playtrack,		1}, | 
					
						
							|  |  |  | 	{"playtrackabs",	(PyCFunction)CD_playtrackabs,	1}, | 
					
						
							|  |  |  | 	{"preventremoval",	(PyCFunction)CD_preventremoval,	1}, | 
					
						
							|  |  |  | 	{"readda",		(PyCFunction)CD_readda,		1}, | 
					
						
							|  |  |  | 	{"seek",		(PyCFunction)CD_seek,		1}, | 
					
						
							|  |  |  | 	{"seekblock",		(PyCFunction)CD_seekblock,		1}, | 
					
						
							|  |  |  | 	{"seektrack",		(PyCFunction)CD_seektrack,		1}, | 
					
						
							|  |  |  | 	{"stop",		(PyCFunction)CD_stop,		1}, | 
					
						
							|  |  |  | 	{"togglepause",		(PyCFunction)CD_togglepause,   	1}, | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	{NULL,			NULL} 		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | cdplayer_dealloc(cdplayerobject *self) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (self->ob_cdplayer != NULL) | 
					
						
							|  |  |  | 		CDclose(self->ob_cdplayer); | 
					
						
							| 
									
										
										
										
											2000-05-03 23:44:39 +00:00
										 |  |  | 	PyObject_Del(self); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | cdplayer_getattr(cdplayerobject *self, char *name) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 	if (self->ob_cdplayer == NULL) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetString(PyExc_RuntimeError, "no player active"); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return Py_FindMethod(cdplayer_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | PyTypeObject CdPlayertype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	0,			/*ob_size*/ | 
					
						
							|  |  |  | 	"cdplayer",		/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(cdplayerobject),	/*tp_size*/ | 
					
						
							|  |  |  | 	0,			/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											1994-08-01 11:34:53 +00:00
										 |  |  | 	(destructor)cdplayer_dealloc, /*tp_dealloc*/ | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	0,			/*tp_print*/ | 
					
						
							| 
									
										
										
										
											1994-08-01 11:34:53 +00:00
										 |  |  | 	(getattrfunc)cdplayer_getattr, /*tp_getattr*/ | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	0,			/*tp_setattr*/ | 
					
						
							|  |  |  | 	0,			/*tp_compare*/ | 
					
						
							|  |  |  | 	0,			/*tp_repr*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | newcdplayerobject(CDPLAYER *cdp) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	cdplayerobject *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-03 23:44:39 +00:00
										 |  |  | 	p = PyObject_New(cdplayerobject, &CdPlayertype); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	if (p == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	p->ob_cdplayer = cdp; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return (PyObject *) p; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_open(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00: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 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|zs:open", &dev, &direction)) | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cdp = CDopen(dev, direction); | 
					
						
							|  |  |  | 	if (cdp == NULL) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetFromErrno(CdError); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return newcdplayerobject(cdp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyObject_HEAD | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	CDPARSER *ob_cdparser; | 
					
						
							|  |  |  | 	struct { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyObject *ob_cdcallback; | 
					
						
							|  |  |  | 		PyObject *ob_cdcallbackarg; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	} ob_cdcallbacks[NCALLBACKS]; | 
					
						
							|  |  |  | } cdparserobject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_callback(void *arg, CDDATATYPES type, void *data) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyObject *result, *args, *v = NULL; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	char *p; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	cdparserobject *self; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self = (cdparserobject *) arg; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	args = PyTuple_New(3); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	if (args == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00: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 18:22:53 +00:00
										 |  |  | 	switch (type) { | 
					
						
							|  |  |  | 	case cd_audio: | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		v = PyString_FromStringAndSize(data, CDDA_DATASIZE); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case cd_pnum: | 
					
						
							|  |  |  | 	case cd_index: | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		v = PyInt_FromLong(((CDPROGNUM *) data)->value); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case cd_ptime: | 
					
						
							|  |  |  | 	case cd_atime: | 
					
						
							| 
									
										
										
										
											1992-04-15 15:56:11 +00:00
										 |  |  | #define ptr ((struct cdtimecode *) data)
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		v = Py_BuildValue("(iii)", | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 			    ptr->mhi * 10 + ptr->mlo, | 
					
						
							| 
									
										
										
										
											1992-04-15 15:56:11 +00:00
										 |  |  | 			    ptr->shi * 10 + ptr->slo, | 
					
						
							|  |  |  | 			    ptr->fhi * 10 + ptr->flo); | 
					
						
							|  |  |  | #undef ptr
 | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case cd_catalog: | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		v = PyString_FromStringAndSize(NULL, 13); | 
					
						
							|  |  |  | 		p = PyString_AsString(v); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		for (i = 0; i < 13; i++) | 
					
						
							|  |  |  | 			*p++ = ((char *) data)[i] + '0'; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case cd_ident: | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | #define ptr ((struct cdident *) data)
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		v = PyString_FromStringAndSize(NULL, 12); | 
					
						
							|  |  |  | 		p = PyString_AsString(v); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 		CDsbtoa(p, ptr->country, 2); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		p += 2; | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 		CDsbtoa(p, ptr->owner, 3); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		p += 3; | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00: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 18:22:53 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case cd_control: | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		v = PyInt_FromLong((long) *((unchar *) data)); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyTuple_SetItem(args, 2, v); | 
					
						
							|  |  |  | 	if (PyErr_Occurred()) { | 
					
						
							|  |  |  | 		Py_DECREF(args); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	result = PyEval_CallObject(self->ob_cdcallbacks[type].ob_cdcallback, | 
					
						
							|  |  |  | 				   args); | 
					
						
							|  |  |  | 	Py_DECREF(args); | 
					
						
							|  |  |  | 	Py_XDECREF(result); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_deleteparser(cdparserobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":deleteparser")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00: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 23:00:51 +00:00
										 |  |  | 		Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		self->ob_cdcallbacks[i].ob_cdcallback = NULL; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_parseframe(cdparserobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *cdfp; | 
					
						
							|  |  |  | 	int length; | 
					
						
							|  |  |  | 	CDFRAME *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s#:parseframe", &cdfp, &length)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (length % sizeof(CDFRAME) != 0) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, "bad length"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p = (CDFRAME *) cdfp; | 
					
						
							|  |  |  | 	while (length > 0) { | 
					
						
							|  |  |  | 		CDparseframe(self->ob_cdparser, p); | 
					
						
							|  |  |  | 		length -= sizeof(CDFRAME); | 
					
						
							|  |  |  | 		p++; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		if (PyErr_Occurred()) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_removecallback(cdparserobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "i:removecallback", &type)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1992-08-03 19:06:59 +00:00
										 |  |  | 	if (type < 0 || type >= NCALLBACKS) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, "bad type"); | 
					
						
							| 
									
										
										
										
											1992-08-03 19:06:59 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	CDremovecallback(self->ob_cdparser, (CDDATATYPES) type); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	self->ob_cdcallbacks[type].ob_cdcallback = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_resetparser(cdparserobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":resetparser")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CDresetparser(self->ob_cdparser); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_addcallback(cdparserobject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int type; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyObject *func, *funcarg; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* XXX - more work here */ | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "iOO:addcallback", &type, &func, &funcarg)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (type < 0 || type >= NCALLBACKS) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, "argument out of range"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1992-09-25 11:15:58 +00:00
										 |  |  | #ifdef CDsetcallback
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, | 
					
						
							|  |  |  | 		      (void *) self); | 
					
						
							| 
									
										
										
										
											1992-08-03 19:06:59 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, | 
					
						
							|  |  |  | 		      (void *) self); | 
					
						
							| 
									
										
										
										
											1992-08-03 19:06:59 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); | 
					
						
							|  |  |  | 	Py_INCREF(func); | 
					
						
							| 
									
										
										
										
											1993-06-17 12:35:49 +00:00
										 |  |  | 	self->ob_cdcallbacks[type].ob_cdcallback = func; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); | 
					
						
							|  |  |  | 	Py_INCREF(funcarg); | 
					
						
							| 
									
										
										
										
											1993-06-17 12:35:49 +00:00
										 |  |  | 	self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | 	if (type == cd_audio) { | 
					
						
							|  |  |  | 		sigfpe_[_UNDERFL].repls = _ZERO; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		handle_sigfpes(_ON, _EN_UNDERFL, NULL, | 
					
						
							|  |  |  | 		                        _ABORT_ON_ERROR, NULL); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyMethodDef cdparser_methods[] = { | 
					
						
							|  |  |  | 	{"addcallback",		(PyCFunction)CD_addcallback,   	1}, | 
					
						
							|  |  |  | 	{"deleteparser",	(PyCFunction)CD_deleteparser,	1}, | 
					
						
							|  |  |  | 	{"parseframe",		(PyCFunction)CD_parseframe,	1}, | 
					
						
							|  |  |  | 	{"removecallback",	(PyCFunction)CD_removecallback,	1}, | 
					
						
							|  |  |  | 	{"resetparser",		(PyCFunction)CD_resetparser,	1}, | 
					
						
							|  |  |  | 		                                /* backward compatibility */ | 
					
						
							|  |  |  | 	{"setcallback",		(PyCFunction)CD_addcallback,   	1}, | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	{NULL,			NULL} 		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | cdparser_dealloc(cdparserobject *self) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < NCALLBACKS; i++) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		self->ob_cdcallbacks[i].ob_cdcallback = NULL; | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	CDdeleteparser(self->ob_cdparser); | 
					
						
							| 
									
										
										
										
											2000-05-03 23:44:39 +00:00
										 |  |  | 	PyObject_Del(self); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | cdparser_getattr(cdparserobject *self, char *name) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 	if (self->ob_cdparser == NULL) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetString(PyExc_RuntimeError, "no parser active"); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return Py_FindMethod(cdparser_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | PyTypeObject CdParsertype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	0,			/*ob_size*/ | 
					
						
							|  |  |  | 	"cdparser",		/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(cdparserobject),	/*tp_size*/ | 
					
						
							|  |  |  | 	0,			/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											1994-08-01 11:34:53 +00:00
										 |  |  | 	(destructor)cdparser_dealloc, /*tp_dealloc*/ | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	0,			/*tp_print*/ | 
					
						
							| 
									
										
										
										
											1994-08-01 11:34:53 +00:00
										 |  |  | 	(getattrfunc)cdparser_getattr, /*tp_getattr*/ | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	0,			/*tp_setattr*/ | 
					
						
							|  |  |  | 	0,			/*tp_compare*/ | 
					
						
							|  |  |  | 	0,			/*tp_repr*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | newcdparserobject(CDPARSER *cdp) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	cdparserobject *p; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-03 23:44:39 +00:00
										 |  |  | 	p = PyObject_New(cdparserobject, &CdParsertype); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00: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 23:00:51 +00:00
										 |  |  | 	return (PyObject *) p; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_createparser(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	CDPARSER *cdp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":createparser")) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	cdp = CDcreateparser(); | 
					
						
							|  |  |  | 	if (cdp == NULL) { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 		PyErr_SetString(CdError, "createparser failed"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return newcdparserobject(cdp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2000-07-10 17:04:33 +00:00
										 |  |  | CD_msftoframe(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 	int min, sec, frame; | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-02-29 13:59:29 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "iii:msftoframe", &min, &sec, &frame)) | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	return PyInt_FromLong((long) CDmsftoframe(min, sec, frame)); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | static PyMethodDef CD_methods[] = { | 
					
						
							|  |  |  | 	{"open",		(PyCFunction)CD_open,		1}, | 
					
						
							|  |  |  | 	{"createparser",	(PyCFunction)CD_createparser,	1}, | 
					
						
							|  |  |  | 	{"msftoframe",		(PyCFunction)CD_msftoframe,	1}, | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | 	{NULL,		NULL}	/* Sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | initcd() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyObject *m, *d; | 
					
						
							| 
									
										
										
										
											1992-09-24 10:48:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	m = Py_InitModule("cd", CD_methods); | 
					
						
							|  |  |  | 	d = PyModule_GetDict(m); | 
					
						
							| 
									
										
										
										
											1992-09-24 10:48:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-10-01 04:43:39 +00:00
										 |  |  | 	CdError = PyErr_NewException("cd.error", NULL, NULL); | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyDict_SetItemString(d, "error", CdError); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Identifiers for the different types of callbacks from the parser */ | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00: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 12:06:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Block size information for digital audio data */ | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyDict_SetItemString(d, "DATASIZE", | 
					
						
							|  |  |  | 			   PyInt_FromLong((long) CDDA_DATASIZE)); | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, "BLOCKSIZE", | 
					
						
							|  |  |  | 			   PyInt_FromLong((long) CDDA_BLOCKSIZE)); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Possible states for the cd player */ | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00: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 12:06:23 +00:00
										 |  |  | #ifdef CD_CDROM			/* only newer versions of the library */
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM)); | 
					
						
							| 
									
										
										
										
											1995-03-28 12:06:23 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-03 23:00:51 +00:00
										 |  |  | 	if (PyErr_Occurred()) | 
					
						
							|  |  |  | 		Py_FatalError("can't initialize module cd"); | 
					
						
							| 
									
										
										
										
											1992-04-13 18:22:53 +00:00
										 |  |  | } |