/Doc/library/cd.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 340 lines · 207 code · 133 blank · 0 comment · 0 complexity · 59e6b3547e8f6d9da21b7000fe05311f MD5 · raw file

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