blob: e2571ccb252549cb9ea8750d896dda1ee207bf8b [file] [log] [blame]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +00001\section{Built-in Module \sectcode{cd}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-cd}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +00003\bimodindex{cd}
4
5This module provides an interface to the Silicon Graphics CD library.
6It is available only on Silicon Graphics systems.
7
8The way the library works is as follows. A program opens the CD-ROM
Fred Draked98329c1998-03-16 06:38:42 +00009device with \function{open()} and creates a parser to parse the data
10from the CD with \function{createparser()}. The object returned by
11\function{open()} can be used to read data from the CD, but also to get
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000012status information for the CD-ROM device, and to get information about
13the CD, such as the table of contents. Data from the CD is passed to
14the parser, which parses the frames, and calls any callback
15functions that have previously been added.
16
17An audio CD is divided into \dfn{tracks} or \dfn{programs} (the terms
18are used interchangeably). Tracks can be subdivided into
19\dfn{indices}. An audio CD contains a \dfn{table of contents} which
20gives the starts of the tracks on the CD. Index 0 is usually the
21pause before the start of a track. The start of the track as given by
22the table of contents is normally the start of index 1.
23
24Positions on a CD can be represented in two ways. Either a frame
25number or a tuple of three values, minutes, seconds and frames. Most
26functions use the latter representation. Positions can be both
27relative to the beginning of the CD, and to the beginning of the
28track.
29
Fred Draked98329c1998-03-16 06:38:42 +000030Module \module{cd} defines the following functions and constants:
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000031
Guido van Rossumd45c1561995-03-30 11:47:50 +000032
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000033\begin{funcdesc}{createparser}{}
34Create and return an opaque parser object. The methods of the parser
35object are described below.
36\end{funcdesc}
37
Fred Draked98329c1998-03-16 06:38:42 +000038\begin{funcdesc}{msftoframe}{minutes, seconds, frames}
39Converts a \code{(\var{minutes}, \var{seconds}, \var{frames})} triple
40representing time in absolute time code into the corresponding CD
41frame number.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000042\end{funcdesc}
43
Fred Draked98329c1998-03-16 06:38:42 +000044\begin{funcdesc}{open}{\optional{device\optional{, mode}}}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000045Open the CD-ROM device. The return value is an opaque player object;
46methods of the player object are described below. The device is the
Fred Draked98329c1998-03-16 06:38:42 +000047name of the SCSI device file, e.g. \code{'/dev/scsi/sc0d4l0'}, or
48\code{None}. If omitted or \code{None}, the hardware inventory is
49consulted to locate a CD-ROM drive. The \var{mode}, if not omited,
50should be the string \code{'r'}.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000051\end{funcdesc}
52
53The module defines the following variables:
54
Fred Draked98329c1998-03-16 06:38:42 +000055\begin{excdesc}{error}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000056Exception raised on various errors.
Fred Draked98329c1998-03-16 06:38:42 +000057\end{excdesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000058
59\begin{datadesc}{DATASIZE}
60The size of one frame's worth of audio data. This is the size of the
61audio data as passed to the callback of type \code{audio}.
62\end{datadesc}
63
64\begin{datadesc}{BLOCKSIZE}
65The size of one uninterpreted frame of audio data.
66\end{datadesc}
67
Fred Draked98329c1998-03-16 06:38:42 +000068The following variables are states as returned by
69\function{getstatus()}:
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000070
71\begin{datadesc}{READY}
72The drive is ready for operation loaded with an audio CD.
73\end{datadesc}
74
75\begin{datadesc}{NODISC}
76The drive does not have a CD loaded.
77\end{datadesc}
78
79\begin{datadesc}{CDROM}
80The drive is loaded with a CD-ROM. Subsequent play or read operations
81will return I/O errors.
82\end{datadesc}
83
84\begin{datadesc}{ERROR}
85An error aoocurred while trying to read the disc or its table of
86contents.
87\end{datadesc}
88
89\begin{datadesc}{PLAYING}
90The drive is in CD player mode playing an audio CD through its audio
91jacks.
92\end{datadesc}
93
94\begin{datadesc}{PAUSED}
95The drive is in CD layer mode with play paused.
96\end{datadesc}
97
98\begin{datadesc}{STILL}
Fred Draked98329c1998-03-16 06:38:42 +000099The equivalent of \constant{PAUSED} on older (non 3301) model Toshiba
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000100CD-ROM drives. Such drives have never been shipped by SGI.
101\end{datadesc}
102
Guido van Rossumd45c1561995-03-30 11:47:50 +0000103\begin{datadesc}{audio}
104\dataline{pnum}
105\dataline{index}
106\dataline{ptime}
107\dataline{atime}
108\dataline{catalog}
109\dataline{ident}
110\dataline{control}
111Integer constants describing the various types of parser callbacks
Fred Draked98329c1998-03-16 06:38:42 +0000112that can be set by the \method{addcallback()} method of CD parser
Guido van Rossumd45c1561995-03-30 11:47:50 +0000113objects (see below).
114\end{datadesc}
115
Fred Draked98329c1998-03-16 06:38:42 +0000116Player objects (returned by \function{open()}) have the following
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000117methods:
118
Fred Draked98329c1998-03-16 06:38:42 +0000119\setindexsubitem{(CD player method)}
Guido van Rossumd45c1561995-03-30 11:47:50 +0000120
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000121\begin{funcdesc}{allowremoval}{}
122Unlocks the eject button on the CD-ROM drive permitting the user to
123eject the caddy if desired.
124\end{funcdesc}
125
126\begin{funcdesc}{bestreadsize}{}
Fred Draked98329c1998-03-16 06:38:42 +0000127Returns the best value to use for the \var{num_frames} parameter of
128the \method{readda()} method. Best is defined as the value that
129permits a continuous flow of data from the CD-ROM drive.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000130\end{funcdesc}
131
132\begin{funcdesc}{close}{}
133Frees the resources associated with the player object. After calling
Fred Draked98329c1998-03-16 06:38:42 +0000134\method{close()}, the methods of the object should no longer be used.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000135\end{funcdesc}
136
137\begin{funcdesc}{eject}{}
138Ejects the caddy from the CD-ROM drive.
139\end{funcdesc}
140
141\begin{funcdesc}{getstatus}{}
142Returns information pertaining to the current state of the CD-ROM
143drive. The returned information is a tuple with the following values:
Fred Draked98329c1998-03-16 06:38:42 +0000144\var{state}, \var{track}, \var{rtime}, \var{atime}, \var{ttime},
145\var{first}, \var{last}, \var{scsi_audio}, \var{cur_block}.
146\var{rtime} is the time relative to the start of the current track;
147\var{atime} is the time relative to the beginning of the disc;
148\var{ttime} is the total time on the disc. For more information on
149the meaning of the values, see the man page \manpage{CDgetstatus}{3dm}.
150The value of \var{state} is one of the following: \constant{ERROR},
151\constant{NODISC}, \constant{READY}, \constant{PLAYING},
152\constant{PAUSED}, \constant{STILL}, or \constant{CDROM}.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000153\end{funcdesc}
154
155\begin{funcdesc}{gettrackinfo}{track}
156Returns information about the specified track. The returned
157information is a tuple consisting of two elements, the start time of
158the track and the duration of the track.
159\end{funcdesc}
160
Fred Draked98329c1998-03-16 06:38:42 +0000161\begin{funcdesc}{msftoblock}{min, sec, frame}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000162Converts a minutes, seconds, frames triple representing a time in
163absolute time code into the corresponding logical block number for the
Fred Draked98329c1998-03-16 06:38:42 +0000164given CD-ROM drive. You should use \function{msftoframe()} rather than
165\method{msftoblock()} for comparing times. The logical block number
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000166differs from the frame number by an offset required by certain CD-ROM
167drives.
168\end{funcdesc}
169
Fred Draked98329c1998-03-16 06:38:42 +0000170\begin{funcdesc}{play}{start, play}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000171Starts playback of an audio CD in the CD-ROM drive at the specified
172track. The audio output appears on the CD-ROM drive's headphone and
173audio jacks (if fitted). Play stops at the end of the disc.
Fred Draked98329c1998-03-16 06:38:42 +0000174\var{start} is the number of the track at which to start playing the
175CD; if \var{play} is 0, the CD will be set to an initial paused
176state. The method \method{togglepause()} can then be used to commence
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000177play.
178\end{funcdesc}
179
Fred Draked98329c1998-03-16 06:38:42 +0000180\begin{funcdesc}{playabs}{minutes, seconds, frames, play}
181Like \method{play()}, except that the start is given in minutes,
182seconds, and frames instead of a track number.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000183\end{funcdesc}
184
Fred Draked98329c1998-03-16 06:38:42 +0000185\begin{funcdesc}{playtrack}{start, play}
186Like \method{play()}, except that playing stops at the end of the
187track.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000188\end{funcdesc}
189
Fred Draked98329c1998-03-16 06:38:42 +0000190\begin{funcdesc}{playtrackabs}{track, minutes, seconds, frames, play}
191Like \method{play()}, except that playing begins at the spcified
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000192absolute time and ends at the end of the specified track.
193\end{funcdesc}
194
195\begin{funcdesc}{preventremoval}{}
196Locks the eject button on the CD-ROM drive thus preventing the user
197from arbitrarily ejecting the caddy.
198\end{funcdesc}
199
200\begin{funcdesc}{readda}{num_frames}
201Reads the specified number of frames from an audio CD mounted in the
202CD-ROM drive. The return value is a string representing the audio
Fred Draked98329c1998-03-16 06:38:42 +0000203frames. This string can be passed unaltered to the
204\method{parseframe()} method of the parser object.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000205\end{funcdesc}
206
Fred Draked98329c1998-03-16 06:38:42 +0000207\begin{funcdesc}{seek}{minutes, seconds, frames}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000208Sets the pointer that indicates the starting point of the next read of
209digital audio data from a CD-ROM. The pointer is set to an absolute
Fred Draked98329c1998-03-16 06:38:42 +0000210time code location specified in \var{minutes}, \var{seconds}, and
211\var{frames}. The return value is the logical block number to which
212the pointer has been set.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000213\end{funcdesc}
214
215\begin{funcdesc}{seekblock}{block}
216Sets the pointer that indicates the starting point of the next read of
217digital audio data from a CD-ROM. The pointer is set to the specified
218logical block number. The return value is the logical block number to
219which the pointer has been set.
220\end{funcdesc}
221
222\begin{funcdesc}{seektrack}{track}
223Sets the pointer that indicates the starting point of the next read of
224digital audio data from a CD-ROM. The pointer is set to the specified
225track. The return value is the logical block number to which the
226pointer has been set.
227\end{funcdesc}
228
229\begin{funcdesc}{stop}{}
230Stops the current playing operation.
231\end{funcdesc}
232
233\begin{funcdesc}{togglepause}{}
234Pauses the CD if it is playing, and makes it play if it is paused.
235\end{funcdesc}
236
Fred Draked98329c1998-03-16 06:38:42 +0000237Parser objects (returned by \function{createparser()}) have the
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000238following methods:
239
Fred Draked98329c1998-03-16 06:38:42 +0000240\setindexsubitem{(CD parser method)}
Guido van Rossumd45c1561995-03-30 11:47:50 +0000241
Fred Draked98329c1998-03-16 06:38:42 +0000242\begin{funcdesc}{addcallback}{type, func, arg}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000243Adds a callback for the parser. The parser has callbacks for eight
Guido van Rossumd45c1561995-03-30 11:47:50 +0000244different types of data in the digital audio data stream. Constants
Fred Draked98329c1998-03-16 06:38:42 +0000245for these types are defined at the \module{cd} module level (see above).
246The callback is called as follows: \code{\var{func}(\var{arg}, type,
247data)}, where \var{arg} is the user supplied argument, \var{type} is
248the particular type of callback, and \var{data} is the data returned
249for this \var{type} of callback. The type of the data depends on the
250\var{type} of callback as follows:
251
252\begin{tableii}{|l|l|}{code}{Type}{Value}
253 \lineii{audio}{String which can be passed unmodified to
254\function{al.writesamps()}.}
255 \lineii{pnum}{Integer giving the program (track) number.}
256 \lineii{index}{Integer giving the index number.}
257 \lineii{ptime}{Tuple consisting of the program time in minutes,
258seconds, and frames.}
259 \lineii{atime}{Tuple consisting of the absolute time in minutes,
260seconds, and frames.}
261 \lineii{catalog}{String of 13 characters, giving the catalog number
262of the CD.}
263 \lineii{ident}{String of 12 characters, giving the ISRC
264identification number of the recording. \\
265&The string consists of two characters country code, three characters
266owner code, \\
267&two characters giving the year, and five characters giving a serial number.}
268 \lineii{control}{Integer giving the control bits from the CD
269subcode data}
270\end{tableii}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000271\end{funcdesc}
272
273\begin{funcdesc}{deleteparser}{}
274Deletes the parser and frees the memory it was using. The object
275should not be used after this call. This call is done automatically
276when the last reference to the object is removed.
277\end{funcdesc}
278
279\begin{funcdesc}{parseframe}{frame}
280Parses one or more frames of digital audio data from a CD such as
Fred Draked98329c1998-03-16 06:38:42 +0000281returned by \method{readda()}. It determines which subcodes are
282present in the data. If these subcodes have changed since the last
283frame, then \method{parseframe()} executes a callback of the
284appropriate type passing to it the subcode data found in the frame.
285Unlike the \C{} function, more than one frame of digital audio data
286can be passed to this method.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000287\end{funcdesc}
288
289\begin{funcdesc}{removecallback}{type}
Fred Draked98329c1998-03-16 06:38:42 +0000290Removes the callback for the given \var{type}.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000291\end{funcdesc}
292
293\begin{funcdesc}{resetparser}{}
294Resets the fields of the parser used for tracking subcodes to an
Fred Draked98329c1998-03-16 06:38:42 +0000295initial state. \method{resetparser()} should be called after the disc
296has been changed.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000297\end{funcdesc}