Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1 | |
| 2 | :mod:`cd` --- CD-ROM access on SGI systems |
| 3 | ========================================== |
| 4 | |
| 5 | .. module:: cd |
| 6 | :platform: IRIX |
| 7 | :synopsis: Interface to the CD-ROM on Silicon Graphics systems. |
| 8 | |
| 9 | |
| 10 | This module provides an interface to the Silicon Graphics CD library. It is |
| 11 | available only on Silicon Graphics systems. |
| 12 | |
| 13 | The way the library works is as follows. A program opens the CD-ROM device with |
| 14 | :func:`open` and creates a parser to parse the data from the CD with |
| 15 | :func:`createparser`. The object returned by :func:`open` can be used to read |
| 16 | data from the CD, but also to get status information for the CD-ROM device, and |
| 17 | to get information about the CD, such as the table of contents. Data from the |
| 18 | CD is passed to the parser, which parses the frames, and calls any callback |
| 19 | functions that have previously been added. |
| 20 | |
| 21 | An audio CD is divided into :dfn:`tracks` or :dfn:`programs` (the terms are used |
| 22 | interchangeably). Tracks can be subdivided into :dfn:`indices`. An audio CD |
| 23 | contains a :dfn:`table of contents` which gives the starts of the tracks on the |
| 24 | CD. Index 0 is usually the pause before the start of a track. The start of the |
| 25 | track as given by the table of contents is normally the start of index 1. |
| 26 | |
| 27 | Positions on a CD can be represented in two ways. Either a frame number or a |
| 28 | tuple of three values, minutes, seconds and frames. Most functions use the |
| 29 | latter representation. Positions can be both relative to the beginning of the |
| 30 | CD, and to the beginning of the track. |
| 31 | |
| 32 | Module :mod:`cd` defines the following functions and constants: |
| 33 | |
| 34 | |
| 35 | .. function:: createparser() |
| 36 | |
| 37 | Create and return an opaque parser object. The methods of the parser object are |
| 38 | described below. |
| 39 | |
| 40 | |
| 41 | .. function:: msftoframe(minutes, seconds, frames) |
| 42 | |
| 43 | Converts a ``(minutes, seconds, frames)`` triple representing time in absolute |
| 44 | time code into the corresponding CD frame number. |
| 45 | |
| 46 | |
| 47 | .. function:: open([device[, mode]]) |
| 48 | |
| 49 | Open the CD-ROM device. The return value is an opaque player object; methods of |
| 50 | the player object are described below. The device is the name of the SCSI |
| 51 | device file, e.g. ``'/dev/scsi/sc0d4l0'``, or ``None``. If omitted or ``None``, |
| 52 | the hardware inventory is consulted to locate a CD-ROM drive. The *mode*, if |
| 53 | not omitted, should be the string ``'r'``. |
| 54 | |
| 55 | The module defines the following variables: |
| 56 | |
| 57 | |
| 58 | .. exception:: error |
| 59 | |
| 60 | Exception raised on various errors. |
| 61 | |
| 62 | |
| 63 | .. data:: DATASIZE |
| 64 | |
| 65 | The size of one frame's worth of audio data. This is the size of the audio data |
| 66 | as passed to the callback of type ``audio``. |
| 67 | |
| 68 | |
| 69 | .. data:: BLOCKSIZE |
| 70 | |
| 71 | The size of one uninterpreted frame of audio data. |
| 72 | |
| 73 | The following variables are states as returned by :func:`getstatus`: |
| 74 | |
| 75 | |
| 76 | .. data:: READY |
| 77 | |
| 78 | The drive is ready for operation loaded with an audio CD. |
| 79 | |
| 80 | |
| 81 | .. data:: NODISC |
| 82 | |
| 83 | The drive does not have a CD loaded. |
| 84 | |
| 85 | |
| 86 | .. data:: CDROM |
| 87 | |
| 88 | The drive is loaded with a CD-ROM. Subsequent play or read operations will |
| 89 | return I/O errors. |
| 90 | |
| 91 | |
| 92 | .. data:: ERROR |
| 93 | |
| 94 | An error occurred while trying to read the disc or its table of contents. |
| 95 | |
| 96 | |
| 97 | .. data:: PLAYING |
| 98 | |
| 99 | The drive is in CD player mode playing an audio CD through its audio jacks. |
| 100 | |
| 101 | |
| 102 | .. data:: PAUSED |
| 103 | |
| 104 | The drive is in CD layer mode with play paused. |
| 105 | |
| 106 | |
| 107 | .. data:: STILL |
| 108 | |
| 109 | The equivalent of :const:`PAUSED` on older (non 3301) model Toshiba CD-ROM |
| 110 | drives. Such drives have never been shipped by SGI. |
| 111 | |
| 112 | |
| 113 | .. data:: audio |
| 114 | pnum |
| 115 | index |
| 116 | ptime |
| 117 | atime |
| 118 | catalog |
| 119 | ident |
| 120 | control |
| 121 | |
| 122 | Integer constants describing the various types of parser callbacks that can be |
| 123 | set by the :meth:`addcallback` method of CD parser objects (see below). |
| 124 | |
| 125 | |
| 126 | .. _player-objects: |
| 127 | |
| 128 | Player Objects |
| 129 | -------------- |
| 130 | |
| 131 | Player objects (returned by :func:`open`) have the following methods: |
| 132 | |
| 133 | |
| 134 | .. method:: CD player.allowremoval() |
| 135 | |
| 136 | Unlocks the eject button on the CD-ROM drive permitting the user to eject the |
| 137 | caddy if desired. |
| 138 | |
| 139 | |
| 140 | .. method:: CD player.bestreadsize() |
| 141 | |
| 142 | Returns the best value to use for the *num_frames* parameter of the |
| 143 | :meth:`readda` method. Best is defined as the value that permits a continuous |
| 144 | flow of data from the CD-ROM drive. |
| 145 | |
| 146 | |
| 147 | .. method:: CD player.close() |
| 148 | |
| 149 | Frees the resources associated with the player object. After calling |
| 150 | :meth:`close`, the methods of the object should no longer be used. |
| 151 | |
| 152 | |
| 153 | .. method:: CD player.eject() |
| 154 | |
| 155 | Ejects the caddy from the CD-ROM drive. |
| 156 | |
| 157 | |
| 158 | .. method:: CD player.getstatus() |
| 159 | |
| 160 | Returns information pertaining to the current state of the CD-ROM drive. The |
| 161 | returned information is a tuple with the following values: *state*, *track*, |
| 162 | *rtime*, *atime*, *ttime*, *first*, *last*, *scsi_audio*, *cur_block*. *rtime* |
| 163 | is the time relative to the start of the current track; *atime* is the time |
| 164 | relative to the beginning of the disc; *ttime* is the total time on the disc. |
| 165 | For more information on the meaning of the values, see the man page |
| 166 | :manpage:`CDgetstatus(3dm)`. The value of *state* is one of the following: |
| 167 | :const:`ERROR`, :const:`NODISC`, :const:`READY`, :const:`PLAYING`, |
| 168 | :const:`PAUSED`, :const:`STILL`, or :const:`CDROM`. |
| 169 | |
| 170 | |
| 171 | .. method:: CD player.gettrackinfo(track) |
| 172 | |
| 173 | Returns information about the specified track. The returned information is a |
| 174 | tuple consisting of two elements, the start time of the track and the duration |
| 175 | of the track. |
| 176 | |
| 177 | |
| 178 | .. method:: CD player.msftoblock(min, sec, frame) |
| 179 | |
| 180 | Converts a minutes, seconds, frames triple representing a time in absolute time |
| 181 | code into the corresponding logical block number for the given CD-ROM drive. |
| 182 | You should use :func:`msftoframe` rather than :meth:`msftoblock` for comparing |
| 183 | times. The logical block number differs from the frame number by an offset |
| 184 | required by certain CD-ROM drives. |
| 185 | |
| 186 | |
| 187 | .. method:: CD player.play(start, play) |
| 188 | |
| 189 | Starts playback of an audio CD in the CD-ROM drive at the specified track. The |
| 190 | audio output appears on the CD-ROM drive's headphone and audio jacks (if |
| 191 | fitted). Play stops at the end of the disc. *start* is the number of the track |
| 192 | at which to start playing the CD; if *play* is 0, the CD will be set to an |
| 193 | initial paused state. The method :meth:`togglepause` can then be used to |
| 194 | commence play. |
| 195 | |
| 196 | |
| 197 | .. method:: CD player.playabs(minutes, seconds, frames, play) |
| 198 | |
| 199 | Like :meth:`play`, except that the start is given in minutes, seconds, and |
| 200 | frames instead of a track number. |
| 201 | |
| 202 | |
| 203 | .. method:: CD player.playtrack(start, play) |
| 204 | |
| 205 | Like :meth:`play`, except that playing stops at the end of the track. |
| 206 | |
| 207 | |
| 208 | .. method:: CD player.playtrackabs(track, minutes, seconds, frames, play) |
| 209 | |
| 210 | Like :meth:`play`, except that playing begins at the specified absolute time and |
| 211 | ends at the end of the specified track. |
| 212 | |
| 213 | |
| 214 | .. method:: CD player.preventremoval() |
| 215 | |
| 216 | Locks the eject button on the CD-ROM drive thus preventing the user from |
| 217 | arbitrarily ejecting the caddy. |
| 218 | |
| 219 | |
| 220 | .. method:: CD player.readda(num_frames) |
| 221 | |
| 222 | Reads the specified number of frames from an audio CD mounted in the CD-ROM |
| 223 | drive. The return value is a string representing the audio frames. This string |
| 224 | can be passed unaltered to the :meth:`parseframe` method of the parser object. |
| 225 | |
| 226 | |
| 227 | .. method:: CD player.seek(minutes, seconds, frames) |
| 228 | |
| 229 | Sets the pointer that indicates the starting point of the next read of digital |
| 230 | audio data from a CD-ROM. The pointer is set to an absolute time code location |
| 231 | specified in *minutes*, *seconds*, and *frames*. The return value is the |
| 232 | logical block number to which the pointer has been set. |
| 233 | |
| 234 | |
| 235 | .. method:: CD player.seekblock(block) |
| 236 | |
| 237 | Sets the pointer that indicates the starting point of the next read of digital |
| 238 | audio data from a CD-ROM. The pointer is set to the specified logical block |
| 239 | number. The return value is the logical block number to which the pointer has |
| 240 | been set. |
| 241 | |
| 242 | |
| 243 | .. method:: CD player.seektrack(track) |
| 244 | |
| 245 | Sets the pointer that indicates the starting point of the next read of digital |
| 246 | audio data from a CD-ROM. The pointer is set to the specified track. The |
| 247 | return value is the logical block number to which the pointer has been set. |
| 248 | |
| 249 | |
| 250 | .. method:: CD player.stop() |
| 251 | |
| 252 | Stops the current playing operation. |
| 253 | |
| 254 | |
| 255 | .. method:: CD player.togglepause() |
| 256 | |
| 257 | Pauses the CD if it is playing, and makes it play if it is paused. |
| 258 | |
| 259 | |
| 260 | .. _cd-parser-objects: |
| 261 | |
| 262 | Parser Objects |
| 263 | -------------- |
| 264 | |
| 265 | Parser objects (returned by :func:`createparser`) have the following methods: |
| 266 | |
| 267 | |
| 268 | .. method:: CD parser.addcallback(type, func, arg) |
| 269 | |
| 270 | Adds a callback for the parser. The parser has callbacks for eight different |
| 271 | types of data in the digital audio data stream. Constants for these types are |
| 272 | defined at the :mod:`cd` module level (see above). The callback is called as |
| 273 | follows: ``func(arg, type, data)``, where *arg* is the user supplied argument, |
| 274 | *type* is the particular type of callback, and *data* is the data returned for |
| 275 | this *type* of callback. The type of the data depends on the *type* of callback |
| 276 | as follows: |
| 277 | |
| 278 | +-------------+---------------------------------------------+ |
| 279 | | Type | Value | |
| 280 | +=============+=============================================+ |
| 281 | | ``audio`` | String which can be passed unmodified to | |
| 282 | | | :func:`al.writesamps`. | |
| 283 | +-------------+---------------------------------------------+ |
| 284 | | ``pnum`` | Integer giving the program (track) number. | |
| 285 | +-------------+---------------------------------------------+ |
| 286 | | ``index`` | Integer giving the index number. | |
| 287 | +-------------+---------------------------------------------+ |
| 288 | | ``ptime`` | Tuple consisting of the program time in | |
| 289 | | | minutes, seconds, and frames. | |
| 290 | +-------------+---------------------------------------------+ |
| 291 | | ``atime`` | Tuple consisting of the absolute time in | |
| 292 | | | minutes, seconds, and frames. | |
| 293 | +-------------+---------------------------------------------+ |
| 294 | | ``catalog`` | String of 13 characters, giving the catalog | |
| 295 | | | number of the CD. | |
| 296 | +-------------+---------------------------------------------+ |
| 297 | | ``ident`` | String of 12 characters, giving the ISRC | |
| 298 | | | identification number of the recording. | |
| 299 | | | The string consists of two characters | |
| 300 | | | country code, three characters owner code, | |
| 301 | | | two characters giving the year, and five | |
| 302 | | | characters giving a serial number. | |
| 303 | +-------------+---------------------------------------------+ |
| 304 | | ``control`` | Integer giving the control bits from the CD | |
| 305 | | | subcode data | |
| 306 | +-------------+---------------------------------------------+ |
| 307 | |
| 308 | |
| 309 | .. method:: CD parser.deleteparser() |
| 310 | |
| 311 | Deletes the parser and frees the memory it was using. The object should not be |
| 312 | used after this call. This call is done automatically when the last reference |
| 313 | to the object is removed. |
| 314 | |
| 315 | |
| 316 | .. method:: CD parser.parseframe(frame) |
| 317 | |
| 318 | Parses one or more frames of digital audio data from a CD such as returned by |
| 319 | :meth:`readda`. It determines which subcodes are present in the data. If these |
| 320 | subcodes have changed since the last frame, then :meth:`parseframe` executes a |
| 321 | callback of the appropriate type passing to it the subcode data found in the |
| 322 | frame. Unlike the C function, more than one frame of digital audio data can be |
| 323 | passed to this method. |
| 324 | |
| 325 | |
| 326 | .. method:: CD parser.removecallback(type) |
| 327 | |
| 328 | Removes the callback for the given *type*. |
| 329 | |
| 330 | |
| 331 | .. method:: CD parser.resetparser() |
| 332 | |
| 333 | Resets the fields of the parser used for tracking subcodes to an initial state. |
| 334 | :meth:`resetparser` should be called after the disc has been changed. |
| 335 | |