rbcdio 0.03 → 0.04
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +623 -289
- data/ChangeLog +342 -219
- data/INSTALL +35 -26
- data/Makefile.am +2 -3
- data/Makefile.in +61 -45
- data/NEWS +7 -3
- data/README +8 -9
- data/THANKS +1 -0
- data/VERSION +1 -1
- data/config.guess +21 -11
- data/config.sub +38 -6
- data/configure +1195 -1031
- data/configure.ac +1 -1
- data/example/README +5 -3
- data/example/audio.rb +0 -0
- data/example/cd-read.rb +0 -0
- data/example/cdchange.rb +0 -0
- data/example/cdtext.rb +70 -0
- data/example/device.rb +0 -0
- data/example/drives.rb +30 -32
- data/example/eject.rb +0 -0
- data/example/iso1.rb +0 -0
- data/example/iso2.rb +0 -0
- data/example/iso3.rb +0 -0
- data/example/tracks.rb +0 -0
- data/ext/cdio/Makefile +92 -56
- data/ext/cdio/rubycdio_wrap.c +387 -101
- data/ext/iso9660/Makefile +93 -57
- data/ext/iso9660/rubyiso9660_wrap.c +127 -70
- data/install-sh +355 -159
- data/lib/cdio.rb +877 -843
- data/missing +34 -27
- data/swig/Makefile +1 -1
- data/swig/cdtext.swg +67 -0
- data/swig/device.swg +3 -3
- data/swig/disc.swg +2 -2
- data/swig/rubycdio.swg +3 -1
- data/swig/track.swg +9 -4
- data/test/cdiotest.rb +214 -216
- data/test/cdtext.rb +44 -0
- data/test/isocopy.rb +8 -9
- data/test/isotest.rb +126 -107
- metadata +21 -29
- data/doc/created.rid +0 -1
- data/doc/fr_class_index.html +0 -42
- data/doc/fr_file_index.html +0 -41
- data/doc/fr_method_index.html +0 -133
- data/doc/index.html +0 -24
- data/doc/rdoc-style.css +0 -208
- data/example/COPYING +0 -340
- data/example/copying +0 -340
- data/example/drivers.rb +0 -60
data/lib/cdio.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# $Id: cdio.rb,v 1.21 2008/05/02 13:05:40 karl Exp $
|
3
3
|
#
|
4
|
-
# Copyright (C) 2006, 2007, 2008 Rocky Bernstein <rocky@gnu.org>
|
4
|
+
# Copyright (C) 2006, 2007, 2008, 2009 Rocky Bernstein <rocky@gnu.org>
|
5
5
|
#
|
6
6
|
# This program is free software: you can redistribute it and/or modify
|
7
7
|
# it under the terms of the GNU General Public License as published by
|
@@ -62,925 +62,929 @@
|
|
62
62
|
# that die-hard libcdio C users who are very familiar with that
|
63
63
|
# interface could prefer that.
|
64
64
|
#
|
65
|
-
|
65
|
+
# require 'rubygems'; require 'ruby-debug'; Debugger.start
|
66
66
|
require "rubycdio"
|
67
67
|
|
68
68
|
module Cdio
|
69
69
|
|
70
|
-
# Raise a Driver Error exception on error as determined by drc
|
71
|
-
def possibly_raise_exception__(drc, msg=nil)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
# Raise a Driver Error exception on error as determined by drc
|
71
|
+
def possibly_raise_exception__(drc, msg=nil)
|
72
|
+
if drc==Rubycdio::DRIVER_OP_SUCCESS
|
73
|
+
return
|
74
|
+
end
|
75
|
+
if drc==Rubycdio::DRIVER_OP_ERROR
|
76
|
+
raise DriverError
|
77
|
+
end
|
78
|
+
if drc==Rubycdio::DRIVER_OP_UNINIT
|
79
|
+
raise DriverUninitError
|
80
|
+
end
|
81
|
+
if drc==Rubycdio::DRIVER_OP_UNSUPPORTED
|
82
82
|
raise DriverUnsupportedError
|
83
|
-
|
84
|
-
|
83
|
+
end
|
84
|
+
if drc==Rubycdio::DRIVER_OP_NOT_PERMITTED
|
85
85
|
raise DriverUnsupportedError
|
86
|
-
|
87
|
-
|
86
|
+
end
|
87
|
+
if drc==Rubycdio::DRIVER_OP_BAD_PARAMETER
|
88
88
|
raise DriverBadParameterError
|
89
|
-
|
90
|
-
|
89
|
+
end
|
90
|
+
if drc==Rubycdio::DRIVER_OP_BAD_POINTER
|
91
91
|
raise DriverBadPointerError
|
92
|
-
|
93
|
-
|
92
|
+
end
|
93
|
+
if drc==Rubycdio::DRIVER_OP_NO_DRIVER
|
94
94
|
raise NoDriverError
|
95
|
-
end
|
96
|
-
raise DeviceException('unknown exception %d' % drc)
|
97
|
-
end
|
98
|
-
|
99
|
-
# = class DeviceException
|
100
|
-
# General device or driver exceptions
|
101
|
-
|
102
|
-
class DeviceException < Exception
|
103
|
-
end
|
104
|
-
|
105
|
-
class DriverError < DeviceException; end
|
106
|
-
class DriverUnsupportedError < DeviceException; end
|
107
|
-
class DriverUninitError < DeviceException; end
|
108
|
-
class DriverNotPermittedError < DeviceException; end
|
109
|
-
class DriverBadParameterError < DeviceException; end
|
110
|
-
class DriverBadPointerError < DeviceException; end
|
111
|
-
class NoDriverError < DeviceException; end
|
112
|
-
|
113
|
-
class TrackError < DeviceException; end
|
114
|
-
|
115
|
-
|
116
|
-
# Note: the keys below match those the names returned by
|
117
|
-
# cdio_get_driver_name().
|
118
|
-
def drivers()
|
119
|
-
return {
|
120
|
-
:Unknown => Rubycdio::DRIVER_UNKNOWN,
|
121
|
-
:AIX => Rubycdio::DRIVER_AIX,
|
122
|
-
:BSDI => Rubycdio::DRIVER_BSDI,
|
123
|
-
:FreeBSD => Rubycdio::DRIVER_FREEBSD,
|
124
|
-
:"GNU/Linux" => Rubycdio::DRIVER_LINUX,
|
125
|
-
:Solaris => Rubycdio::DRIVER_SOLARIS,
|
126
|
-
:"OS X" => Rubycdio::DRIVER_OSX,
|
127
|
-
:WIN32 => Rubycdio::DRIVER_WIN32,
|
128
|
-
:CDRDAO => Rubycdio::DRIVER_CDRDAO,
|
129
|
-
:"BIN/CUE" => Rubycdio::DRIVER_BINCUE,
|
130
|
-
:NRG => Rubycdio::DRIVER_NRG,
|
131
|
-
:device => Rubycdio::DRIVER_DEVICE
|
132
|
-
}
|
133
|
-
end
|
134
|
-
|
135
|
-
def read_mode2blocksize()
|
136
|
-
return {
|
137
|
-
Rubycdio::READ_MODE_AUDIO => Rubycdio::CD_FRAMESIZE_RAW,
|
138
|
-
Rubycdio::READ_MODE_M1F1 => Rubycdio::M2RAW_SECTOR_SIZE,
|
139
|
-
Rubycdio::READ_MODE_M1F2 => Rubycdio::CD_FRAMESIZE,
|
140
|
-
Rubycdio::READ_MODE_M2F1 => Rubycdio::M2RAW_SECTOR_SIZE,
|
141
|
-
Rubycdio::READ_MODE_M2F2 => Rubycdio::CD_FRAMESIZE
|
142
|
-
}
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
# close media tray in CD drive if there is a routine to do so.
|
147
|
-
# The +driver id +is returned. A DeviceException is thrown on error.
|
148
|
-
def close_tray(drive=nil, driver_id=Rubycdio::DRIVER_UNKNOWN)
|
149
|
-
drc, found_driver_id = Rubycdio::close_tray(drive, driver_id)
|
150
|
-
possibly_raise_exception__(drc)
|
151
|
-
return found_driver_id
|
152
|
-
end
|
153
|
-
|
154
|
-
# Returns: [device, driver]
|
155
|
-
#
|
156
|
-
# Return a string containing the default CD device if none is
|
157
|
-
# specified. if +driver_id+ is DRIVER_UNKNOWN or DRIVER_DEVICE
|
158
|
-
# then one set the default device for that.
|
159
|
-
#
|
160
|
-
# nil is returned as the device if we couldn't get a default
|
161
|
-
# device.
|
162
|
-
def default_device_driver(driver_id=Rubycdio::DRIVER_DEVICE)
|
163
|
-
return Rubycdio::get_default_device_driver(driver_id)
|
164
|
-
end
|
165
|
-
|
166
|
-
# Returns: [device1, device2, ...]
|
167
|
-
#
|
168
|
-
# Get an list of device names.
|
169
|
-
def devices(driver_id=Rubycdio::DRIVER_UNKNOWN)
|
170
|
-
return Rubycdio::get_devices(driver_id)
|
171
|
-
end
|
172
|
-
|
173
|
-
# Returns: [device1, device2, ... driver_id]
|
174
|
-
#
|
175
|
-
# Like get_devices, but return the driver_id which may be different
|
176
|
-
# from the passed-in driver_id if it was Rubycdio::DRIVER_DEVICE or
|
177
|
-
# Rubycdio::DRIVER_UNKNOWN. The return +driver_id+ may be useful because
|
178
|
-
# often one wants to get a drive name and then *open* it
|
179
|
-
# afterwards. Giving the driver back facilitates this, and speeds things
|
180
|
-
# up for libcdio as well.
|
181
|
-
def devices_ret(driver_id=Rubycdio::DRIVER_UNKNOWN)
|
182
|
-
devices = Rubycdio::get_devices_ret(driver_id)
|
183
|
-
end
|
184
|
-
|
185
|
-
# Get an array of device names in search_devices that have at least
|
186
|
-
# the capabilities listed by the capabities parameter.
|
187
|
-
#
|
188
|
-
# If any is false then every capability listed in the
|
189
|
-
# extended portion of capabilities (i.e. not the basic filesystem)
|
190
|
-
# must be satisified. If any is true, then if any of the
|
191
|
-
# capabilities matches, we call that a success.
|
192
|
-
#
|
193
|
-
# To find a CD-drive of any type, use the mask Rubycdio::CDIO_FS_MATCH_ALL.
|
194
|
-
#
|
195
|
-
# The array of device names is returned or nil if we couldn't get a
|
196
|
-
# default device. It is also possible to return a non nil but after
|
197
|
-
# dereferencing the the value is nil. This also means nothing was
|
198
|
-
# found.
|
199
|
-
def devices_with_cap(capabilities, any=false)
|
200
|
-
return Rubycdio::get_devices_with_cap(capabilities, any)
|
201
|
-
end
|
202
|
-
|
203
|
-
# Returns: [device1, device2..., driver_id]
|
204
|
-
#
|
205
|
-
# Like cdio_get_devices_with_cap but we return the driver we found
|
206
|
-
# as well. This is because often one wants to search for kind of drive
|
207
|
-
# and then *open* it afterwards. Giving the driver back facilitates this,
|
208
|
-
# and speeds things up for libcdio as well.
|
209
|
-
def devices_with_cap_ret(capabilities, any=false)
|
210
|
-
return Rubycdio::get_devices_with_cap_ret(capabilities, any)
|
211
|
-
end
|
212
|
-
|
213
|
-
# return bool
|
214
|
-
#
|
215
|
-
# Return true if we have driver driver_id.
|
216
|
-
def driver?(driver_id)
|
217
|
-
if driver_id.class == Fixnum
|
218
|
-
return Rubycdio::have_driver(driver_id) == 1
|
219
|
-
elsif driver_id.class == Symbol and drivers.member?(driver_id)
|
220
|
-
ret = Rubycdio::have_driver(drivers[driver_id])
|
221
|
-
if ret == 0 then return false end
|
222
|
-
if ret == 1 then return true end
|
223
|
-
raise ArgumentError
|
224
|
-
else
|
225
|
-
raise ArgumentError
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
#--
|
230
|
-
# FIXME ? is not quite right
|
231
|
-
# binfile?(binfile_name)->cue_name
|
232
|
-
#++
|
233
|
-
#
|
234
|
-
# Determine if +binfile_name+ is the BIN file part of a CDRWIN CD
|
235
|
-
# disk image.
|
236
|
-
#
|
237
|
-
# Return the corresponding CUE file if bin_name is a BIN file or
|
238
|
-
# nil if not a BIN file.
|
239
|
-
def binfile?(binfile_name)
|
240
|
-
return Rubycdio::is_binfile(binfile_name)
|
241
|
-
end
|
242
|
-
|
243
|
-
#--
|
244
|
-
# FIXME ? is not quite right
|
245
|
-
#++
|
246
|
-
# return bin_name for a corresponding CUE file
|
247
|
-
#
|
248
|
-
# Determine if cuefile_name is the CUE file part of a CDRWIN CD
|
249
|
-
# disk image.
|
250
|
-
#
|
251
|
-
# Return the corresponding BIN file if bin_name is a CUE file or
|
252
|
-
# nil if not a CUE file.
|
253
|
-
def cuefile?(cuefile_name)
|
254
|
-
return Rubycdio::is_cuefile(cuefile_name)
|
255
|
-
end
|
256
|
-
|
257
|
-
# Returns: bool
|
258
|
-
#
|
259
|
-
# Return true if source refers to a real hardware CD-ROM.
|
260
|
-
def device?(source, driver_id=Rubycdio::DRIVER_UNKNOWN)
|
261
|
-
if not driver_id then driver_id=Rubycdio::DRIVER_UNKNOWN end
|
262
|
-
return Rubycdio::device?(source, driver_id)
|
263
|
-
end
|
264
|
-
|
265
|
-
# Returns: bool
|
266
|
-
#
|
267
|
-
# Determine if nrgfile_name is a Nero CD disc image
|
268
|
-
def nrg?(nrgfile_name)
|
269
|
-
return Rubycdio::nrg?(nrgfile_name)
|
270
|
-
end
|
271
|
-
|
272
|
-
# tocfile?(tocfile_name)->bool
|
273
|
-
#
|
274
|
-
# Determine if +tocfile_name+ is a cdrdao CD disc image
|
275
|
-
def tocfile?(tocfile_name)
|
276
|
-
return Rubycdio::tocfile?(tocfile_name)
|
277
|
-
end
|
278
|
-
|
279
|
-
# Convert +bitmask+ for miscellaneous drive properties
|
280
|
-
# into a dictionary of drive capabilities
|
281
|
-
def convert_drive_cap_misc(bitmask)
|
282
|
-
result={}
|
283
|
-
if bitmask & Rubycdio::DRIVE_CAP_ERROR
|
284
|
-
result[:DRIVE_CAP_ERROR] = true
|
285
|
-
end
|
286
|
-
if bitmask & Rubycdio::DRIVE_CAP_UNKNOWN
|
287
|
-
result[:DRIVE_CAP_UNKNOWN] = true
|
288
|
-
end
|
289
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_CLOSE_TRAY
|
290
|
-
result[:DRIVE_CAP_MISC_CLOSE_TRAY] = true
|
291
|
-
end
|
292
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_EJECT
|
293
|
-
result[:DRIVE_CAP_MISC_EJECT] = true
|
294
|
-
end
|
295
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_LOCK
|
296
|
-
result['DRIVE_CAP_MISC_LOCK'] = true
|
297
|
-
end
|
298
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_SELECT_SPEED
|
299
|
-
result[:DRIVE_CAP_MISC_SELECT_SPEED] = true
|
300
|
-
end
|
301
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_SELECT_DISC
|
302
|
-
result[:DRIVE_CAP_MISC_SELECT_DISC] = true
|
303
|
-
end
|
304
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_MULTI_SESSION
|
305
|
-
result[:DRIVE_CAP_MISC_MULTI_SESSION] = true
|
306
|
-
end
|
307
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_MEDIA_CHANGED
|
308
|
-
result[:DRIVE_CAP_MISC_MEDIA_CHANGED] = true
|
309
|
-
end
|
310
|
-
if bitmask & Rubycdio::DRIVE_CAP_MISC_RESET
|
311
|
-
result[:DRIVE_CAP_MISC_RESET] = true
|
312
95
|
end
|
313
|
-
|
314
|
-
result[:DRIVE_CAP_MISC_FILE] = true
|
315
|
-
end
|
316
|
-
return result
|
317
|
-
end
|
318
|
-
|
319
|
-
# Convert bit mask for drive read properties
|
320
|
-
# into a dictionary of drive capabilities
|
321
|
-
def convert_drive_cap_read(bitmask)
|
322
|
-
result={}
|
323
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_AUDIO
|
324
|
-
result[:DRIVE_CAP_READ_AUDIO] = true
|
325
|
-
end
|
326
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_DA
|
327
|
-
result[:DRIVE_CAP_READ_CD_DA] = true
|
328
|
-
end
|
329
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_G
|
330
|
-
result[:DRIVE_CAP_READ_CD_G] = true
|
331
|
-
end
|
332
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_R
|
333
|
-
result[:DRIVE_CAP_READ_CD_R] = true
|
334
|
-
end
|
335
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_RW
|
336
|
-
result[:DRIVE_CAP_READ_CD_RW] = true
|
337
|
-
end
|
338
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_R
|
339
|
-
result[:DRIVE_CAP_READ_DVD_R] = true
|
340
|
-
end
|
341
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_PR
|
342
|
-
result[:DRIVE_CAP_READ_DVD_PR] = true
|
343
|
-
end
|
344
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RAM
|
345
|
-
result[:DRIVE_CAP_READ_DVD_RAM] = true
|
346
|
-
end
|
347
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_ROM
|
348
|
-
result[:DRIVE_CAP_READ_DVD_ROM] = true
|
349
|
-
end
|
350
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RW
|
351
|
-
result[:DRIVE_CAP_READ_DVD_RW] = true
|
352
|
-
end
|
353
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RPW
|
354
|
-
result[:DRIVE_CAP_READ_DVD_RPW] = true
|
355
|
-
end
|
356
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_C2_ERRS
|
357
|
-
result[:DRIVE_CAP_READ_C2_ERRS] = true
|
358
|
-
end
|
359
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_MODE2_FORM1
|
360
|
-
result[:DRIVE_CAP_READ_MODE2_FORM1] = true
|
96
|
+
raise DeviceException('unknown exception %d' % drc)
|
361
97
|
end
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
end
|
368
|
-
if bitmask & Rubycdio::DRIVE_CAP_READ_ISRC
|
369
|
-
result[:DRIVE_CAP_READ_ISRC] = true
|
98
|
+
|
99
|
+
# = class DeviceException
|
100
|
+
# General device or driver exceptions
|
101
|
+
|
102
|
+
class DeviceException < Exception
|
370
103
|
end
|
371
|
-
|
372
|
-
end
|
104
|
+
|
105
|
+
class DriverError < DeviceException; end
|
106
|
+
class DriverUnsupportedError < DeviceException; end
|
107
|
+
class DriverUninitError < DeviceException; end
|
108
|
+
class DriverNotPermittedError < DeviceException; end
|
109
|
+
class DriverBadParameterError < DeviceException; end
|
110
|
+
class DriverBadPointerError < DeviceException; end
|
111
|
+
class NoDriverError < DeviceException; end
|
112
|
+
|
113
|
+
class TrackError < DeviceException; end
|
373
114
|
|
374
|
-
|
375
|
-
#
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
end
|
393
|
-
if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RW
|
394
|
-
result[:DRIVE_CAP_WRITE_DVD_RW] = true
|
395
|
-
end
|
396
|
-
if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RPW
|
397
|
-
result[:DRIVE_CAP_WRITE_DVD_RPW] = true
|
398
|
-
end
|
399
|
-
if bitmask & Rubycdio::DRIVE_CAP_WRITE_MT_RAINIER
|
400
|
-
result[:DRIVE_CAP_WRITE_MT_RAINIER] = true
|
115
|
+
|
116
|
+
# Note: the keys below match those the names returned by
|
117
|
+
# cdio_get_driver_name().
|
118
|
+
def drivers()
|
119
|
+
return {
|
120
|
+
:Unknown => Rubycdio::DRIVER_UNKNOWN,
|
121
|
+
:AIX => Rubycdio::DRIVER_AIX,
|
122
|
+
:BSDI => Rubycdio::DRIVER_BSDI,
|
123
|
+
:FreeBSD => Rubycdio::DRIVER_FREEBSD,
|
124
|
+
:"GNU/Linux" => Rubycdio::DRIVER_LINUX,
|
125
|
+
:Solaris => Rubycdio::DRIVER_SOLARIS,
|
126
|
+
:"OS X" => Rubycdio::DRIVER_OSX,
|
127
|
+
:WIN32 => Rubycdio::DRIVER_WIN32,
|
128
|
+
:CDRDAO => Rubycdio::DRIVER_CDRDAO,
|
129
|
+
:"BIN/CUE" => Rubycdio::DRIVER_BINCUE,
|
130
|
+
:NRG => Rubycdio::DRIVER_NRG,
|
131
|
+
:device => Rubycdio::DRIVER_DEVICE
|
132
|
+
}
|
401
133
|
end
|
402
|
-
|
403
|
-
|
134
|
+
|
135
|
+
def read_mode2blocksize()
|
136
|
+
return {
|
137
|
+
Rubycdio::READ_MODE_AUDIO => Rubycdio::CD_FRAMESIZE_RAW,
|
138
|
+
Rubycdio::READ_MODE_M1F1 => Rubycdio::M2RAW_SECTOR_SIZE,
|
139
|
+
Rubycdio::READ_MODE_M1F2 => Rubycdio::CD_FRAMESIZE,
|
140
|
+
Rubycdio::READ_MODE_M2F1 => Rubycdio::M2RAW_SECTOR_SIZE,
|
141
|
+
Rubycdio::READ_MODE_M2F2 => Rubycdio::CD_FRAMESIZE
|
142
|
+
}
|
404
143
|
end
|
405
|
-
return result
|
406
|
-
end
|
407
144
|
|
408
|
-
# = class Device
|
409
|
-
#
|
410
|
-
# CD Input and control class for discs/devices
|
411
|
-
#
|
412
|
-
# == SYNOPSIS
|
413
|
-
#
|
414
|
-
# require "cdio"
|
415
|
-
# d = Cdio::Device.new("", Rubycdio::DRIVER_UNKNOWN)
|
416
|
-
# drive_name = d.device()
|
417
|
-
# hw = d.hwinfo()
|
418
|
-
# if hw then
|
419
|
-
# puts "drive: %s, vendor: %s, model: %s, revision: %s" %
|
420
|
-
# [drive_name, hw["vendor"], hw["model"], hw["revision"]]
|
421
|
-
# end
|
422
|
-
#
|
423
|
-
# drivers.each_pair { |driver_name, driver_id|
|
424
|
-
# begin
|
425
|
-
# if driver?(driver_id):
|
426
|
-
# puts "Driver %s is installed." % driver_name
|
427
|
-
# end
|
428
|
-
# rescue ValueError
|
429
|
-
# end
|
430
145
|
|
431
|
-
|
432
|
-
|
433
|
-
def
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
open(source, driver_id, access_mode)
|
438
|
-
end
|
146
|
+
# close media tray in CD drive if there is a routine to do so.
|
147
|
+
# The +driver id +is returned. A DeviceException is thrown on error.
|
148
|
+
def close_tray(drive=nil, driver_id=Rubycdio::DRIVER_UNKNOWN)
|
149
|
+
drc, found_driver_id = Rubycdio::close_tray(drive, driver_id)
|
150
|
+
possibly_raise_exception__(drc)
|
151
|
+
return found_driver_id
|
439
152
|
end
|
440
153
|
|
441
|
-
#
|
154
|
+
# Returns: [device, driver]
|
442
155
|
#
|
443
|
-
#
|
444
|
-
|
445
|
-
|
156
|
+
# Return a string containing the default CD device if none is
|
157
|
+
# specified. if +driver_id+ is DRIVER_UNKNOWN or DRIVER_DEVICE
|
158
|
+
# then one set the default device for that.
|
159
|
+
#
|
160
|
+
# nil is returned as the device if we couldn't get a default
|
161
|
+
# device.
|
162
|
+
def default_device_driver(driver_id=Rubycdio::DRIVER_DEVICE)
|
163
|
+
return Rubycdio::get_default_device_driver(driver_id)
|
446
164
|
end
|
447
|
-
|
448
|
-
#
|
165
|
+
|
166
|
+
# Returns: [device1, device2, ...]
|
449
167
|
#
|
450
|
-
#
|
451
|
-
|
452
|
-
|
453
|
-
drc=Rubycdio::audio_pause(@cd)
|
454
|
-
possibly_raise_exception__(drc)
|
168
|
+
# Get an list of device names.
|
169
|
+
def devices(driver_id=Rubycdio::DRIVER_UNKNOWN)
|
170
|
+
return Rubycdio::get_devices(driver_id)
|
455
171
|
end
|
456
172
|
|
457
|
-
#
|
458
|
-
#
|
459
|
-
#
|
460
|
-
#
|
461
|
-
|
462
|
-
|
463
|
-
|
173
|
+
# Returns: [device1, device2, ... driver_id]
|
174
|
+
#
|
175
|
+
# Like get_devices, but return the driver_id which may be different
|
176
|
+
# from the passed-in driver_id if it was Rubycdio::DRIVER_DEVICE or
|
177
|
+
# Rubycdio::DRIVER_UNKNOWN. The return +driver_id+ may be useful because
|
178
|
+
# often one wants to get a drive name and then *open* it
|
179
|
+
# afterwards. Giving the driver back facilitates this, and speeds things
|
180
|
+
# up for libcdio as well.
|
181
|
+
def devices_ret(driver_id=Rubycdio::DRIVER_UNKNOWN)
|
182
|
+
devices = Rubycdio::get_devices_ret(driver_id)
|
464
183
|
end
|
465
|
-
|
466
|
-
#
|
467
|
-
#
|
468
|
-
#
|
469
|
-
#
|
470
|
-
|
471
|
-
|
472
|
-
|
184
|
+
|
185
|
+
# Get an array of device names in search_devices that have at least
|
186
|
+
# the capabilities listed by the capabities parameter.
|
187
|
+
#
|
188
|
+
# If any is false then every capability listed in the
|
189
|
+
# extended portion of capabilities (i.e. not the basic filesystem)
|
190
|
+
# must be satisified. If any is true, then if any of the
|
191
|
+
# capabilities matches, we call that a success.
|
192
|
+
#
|
193
|
+
# To find a CD-drive of any type, use the mask Rubycdio::CDIO_FS_MATCH_ALL.
|
194
|
+
#
|
195
|
+
# The array of device names is returned or nil if we couldn't get a
|
196
|
+
# default device. It is also possible to return a non nil but after
|
197
|
+
# dereferencing the the value is nil. This also means nothing was
|
198
|
+
# found.
|
199
|
+
def devices_with_cap(capabilities, any=false)
|
200
|
+
return Rubycdio::get_devices_with_cap(capabilities, any)
|
473
201
|
end
|
474
|
-
|
475
|
-
#
|
476
|
-
#
|
477
|
-
#
|
478
|
-
#
|
479
|
-
|
480
|
-
|
481
|
-
|
202
|
+
|
203
|
+
# Returns: [device1, device2..., driver_id]
|
204
|
+
#
|
205
|
+
# Like cdio_get_devices_with_cap but we return the driver we found
|
206
|
+
# as well. This is because often one wants to search for kind of drive
|
207
|
+
# and then *open* it afterwards. Giving the driver back facilitates this,
|
208
|
+
# and speeds things up for libcdio as well.
|
209
|
+
def devices_with_cap_ret(capabilities, any=false)
|
210
|
+
return Rubycdio::get_devices_with_cap_ret(capabilities, any)
|
482
211
|
end
|
483
212
|
|
484
|
-
#
|
485
|
-
#
|
486
|
-
#
|
487
|
-
def
|
488
|
-
if
|
489
|
-
Rubycdio::
|
213
|
+
# return bool
|
214
|
+
#
|
215
|
+
# Return true if we have driver driver_id.
|
216
|
+
def driver?(driver_id)
|
217
|
+
if driver_id.class == Fixnum
|
218
|
+
return Rubycdio::have_driver(driver_id) == 1
|
219
|
+
elsif driver_id.class == Symbol and drivers.member?(driver_id)
|
220
|
+
ret = Rubycdio::have_driver(drivers[driver_id])
|
221
|
+
if ret == 0 then return false end
|
222
|
+
if ret == 1 then return true end
|
223
|
+
raise ArgumentError
|
490
224
|
else
|
491
|
-
|
225
|
+
raise ArgumentError
|
492
226
|
end
|
493
|
-
@cd=nil
|
494
227
|
end
|
495
228
|
|
496
|
-
|
497
|
-
#
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
229
|
+
#--
|
230
|
+
# FIXME ? is not quite right
|
231
|
+
# binfile?(binfile_name)->cue_name
|
232
|
+
#++
|
233
|
+
#
|
234
|
+
# Determine if +binfile_name+ is the BIN file part of a CDRWIN CD
|
235
|
+
# disk image.
|
236
|
+
#
|
237
|
+
# Return the corresponding CUE file if bin_name is a BIN file or
|
238
|
+
# nil if not a BIN file.
|
239
|
+
def binfile?(binfile_name)
|
240
|
+
return Rubycdio::is_binfile(binfile_name)
|
502
241
|
end
|
503
|
-
|
504
|
-
|
505
|
-
#
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
242
|
+
|
243
|
+
#--
|
244
|
+
# FIXME ? is not quite right
|
245
|
+
#++
|
246
|
+
# return bin_name for a corresponding CUE file
|
247
|
+
#
|
248
|
+
# Determine if cuefile_name is the CUE file part of a CDRWIN CD
|
249
|
+
# disk image.
|
250
|
+
#
|
251
|
+
# Return the corresponding BIN file if bin_name is a CUE file or
|
252
|
+
# nil if not a CUE file.
|
253
|
+
def cuefile?(cuefile_name)
|
254
|
+
return Rubycdio::is_cuefile(cuefile_name)
|
510
255
|
end
|
511
|
-
|
512
|
-
# Returns: String
|
513
256
|
|
514
|
-
#
|
515
|
-
|
516
|
-
|
257
|
+
# Returns: bool
|
258
|
+
#
|
259
|
+
# Return true if source refers to a real hardware CD-ROM.
|
260
|
+
def device?(source, driver_id=Rubycdio::DRIVER_UNKNOWN)
|
261
|
+
if not driver_id then driver_id=Rubycdio::DRIVER_UNKNOWN end
|
262
|
+
return Rubycdio::device?(source, driver_id)
|
517
263
|
end
|
518
|
-
|
519
|
-
#
|
520
|
-
#
|
521
|
-
#
|
522
|
-
|
523
|
-
|
524
|
-
# In some situations of drivers or OS's we can't find a CD device if
|
525
|
-
# there is no media in it and it is possible for this routine to return
|
526
|
-
# nil even though there may be a hardware CD-ROM.
|
527
|
-
def device()
|
528
|
-
if @cd
|
529
|
-
return Rubycdio::get_arg(@cd, "source")
|
530
|
-
end
|
531
|
-
return Rubycdio::get_device(@cd)
|
264
|
+
|
265
|
+
# Returns: bool
|
266
|
+
#
|
267
|
+
# Determine if nrgfile_name is a Nero CD disc image
|
268
|
+
def nrg?(nrgfile_name)
|
269
|
+
return Rubycdio::nrg?(nrgfile_name)
|
532
270
|
end
|
533
|
-
|
534
|
-
#
|
535
|
-
#
|
536
|
-
#
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
271
|
+
|
272
|
+
# tocfile?(tocfile_name)->bool
|
273
|
+
#
|
274
|
+
# Determine if +tocfile_name+ is a cdrdao CD disc image
|
275
|
+
def tocfile?(tocfile_name)
|
276
|
+
return Rubycdio::tocfile?(tocfile_name)
|
277
|
+
end
|
278
|
+
|
279
|
+
# Convert +bitmask+ for miscellaneous drive properties
|
280
|
+
# into a dictionary of drive capabilities
|
281
|
+
def convert_drive_cap_misc(bitmask)
|
282
|
+
result={}
|
283
|
+
if bitmask & Rubycdio::DRIVE_CAP_ERROR
|
284
|
+
result[:DRIVE_CAP_ERROR] = true
|
285
|
+
end
|
286
|
+
if bitmask & Rubycdio::DRIVE_CAP_UNKNOWN
|
287
|
+
result[:DRIVE_CAP_UNKNOWN] = true
|
288
|
+
end
|
289
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_CLOSE_TRAY
|
290
|
+
result[:DRIVE_CAP_MISC_CLOSE_TRAY] = true
|
291
|
+
end
|
292
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_EJECT
|
293
|
+
result[:DRIVE_CAP_MISC_EJECT] = true
|
294
|
+
end
|
295
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_LOCK
|
296
|
+
result['DRIVE_CAP_MISC_LOCK'] = true
|
297
|
+
end
|
298
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_SELECT_SPEED
|
299
|
+
result[:DRIVE_CAP_MISC_SELECT_SPEED] = true
|
300
|
+
end
|
301
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_SELECT_DISC
|
302
|
+
result[:DRIVE_CAP_MISC_SELECT_DISC] = true
|
303
|
+
end
|
304
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_MULTI_SESSION
|
305
|
+
result[:DRIVE_CAP_MISC_MULTI_SESSION] = true
|
306
|
+
end
|
307
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_MEDIA_CHANGED
|
308
|
+
result[:DRIVE_CAP_MISC_MEDIA_CHANGED] = true
|
309
|
+
end
|
310
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_RESET
|
311
|
+
result[:DRIVE_CAP_MISC_RESET] = true
|
312
|
+
end
|
313
|
+
if bitmask & Rubycdio::DRIVE_CAP_MISC_FILE
|
314
|
+
result[:DRIVE_CAP_MISC_FILE] = true
|
543
315
|
end
|
544
|
-
return
|
316
|
+
return result
|
545
317
|
end
|
546
318
|
|
547
|
-
#
|
548
|
-
#
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
319
|
+
# Convert bit mask for drive read properties
|
320
|
+
# into a dictionary of drive capabilities
|
321
|
+
def convert_drive_cap_read(bitmask)
|
322
|
+
result={}
|
323
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_AUDIO
|
324
|
+
result[:DRIVE_CAP_READ_AUDIO] = true
|
325
|
+
end
|
326
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_DA
|
327
|
+
result[:DRIVE_CAP_READ_CD_DA] = true
|
328
|
+
end
|
329
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_G
|
330
|
+
result[:DRIVE_CAP_READ_CD_G] = true
|
331
|
+
end
|
332
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_R
|
333
|
+
result[:DRIVE_CAP_READ_CD_R] = true
|
334
|
+
end
|
335
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_CD_RW
|
336
|
+
result[:DRIVE_CAP_READ_CD_RW] = true
|
337
|
+
end
|
338
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_R
|
339
|
+
result[:DRIVE_CAP_READ_DVD_R] = true
|
340
|
+
end
|
341
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_PR
|
342
|
+
result[:DRIVE_CAP_READ_DVD_PR] = true
|
343
|
+
end
|
344
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RAM
|
345
|
+
result[:DRIVE_CAP_READ_DVD_RAM] = true
|
346
|
+
end
|
347
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_ROM
|
348
|
+
result[:DRIVE_CAP_READ_DVD_ROM] = true
|
349
|
+
end
|
350
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RW
|
351
|
+
result[:DRIVE_CAP_READ_DVD_RW] = true
|
352
|
+
end
|
353
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RPW
|
354
|
+
result[:DRIVE_CAP_READ_DVD_RPW] = true
|
355
|
+
end
|
356
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_C2_ERRS
|
357
|
+
result[:DRIVE_CAP_READ_C2_ERRS] = true
|
358
|
+
end
|
359
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_MODE2_FORM1
|
360
|
+
result[:DRIVE_CAP_READ_MODE2_FORM1] = true
|
361
|
+
end
|
362
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_MODE2_FORM2
|
363
|
+
result[:DRIVE_CAP_READ_MODE2_FORM2] = true
|
364
|
+
end
|
365
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_MCN
|
366
|
+
result[:DRIVE_CAP_READ_MCN] = true
|
367
|
+
end
|
368
|
+
if bitmask & Rubycdio::DRIVE_CAP_READ_ISRC
|
369
|
+
result[:DRIVE_CAP_READ_ISRC] = true
|
370
|
+
end
|
371
|
+
return result
|
555
372
|
end
|
556
|
-
|
557
|
-
#
|
373
|
+
|
374
|
+
# Convert +bitmask+ for drive write properties
|
375
|
+
# into a dictionary of drive capabilities
|
376
|
+
def convert_drive_cap_write(bitmask)
|
377
|
+
result={}
|
378
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_CD_R
|
379
|
+
result[:DRIVE_CAP_WRITE_CD_R] = true
|
380
|
+
end
|
381
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_CD_RW
|
382
|
+
result[:DRIVE_CAP_WRITE_CD_RW] = true
|
383
|
+
end
|
384
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_R
|
385
|
+
result[:DRIVE_CAP_WRITE_DVD_R] = true
|
386
|
+
end
|
387
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_PR
|
388
|
+
result[:DRIVE_CAP_WRITE_DVD_PR] = true
|
389
|
+
end
|
390
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RAM
|
391
|
+
result[:DRIVE_CAP_WRITE_DVD_RAM] = true
|
392
|
+
end
|
393
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RW
|
394
|
+
result[:DRIVE_CAP_WRITE_DVD_RW] = true
|
395
|
+
end
|
396
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RPW
|
397
|
+
result[:DRIVE_CAP_WRITE_DVD_RPW] = true
|
398
|
+
end
|
399
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_MT_RAINIER
|
400
|
+
result[:DRIVE_CAP_WRITE_MT_RAINIER] = true
|
401
|
+
end
|
402
|
+
if bitmask & Rubycdio::DRIVE_CAP_WRITE_BURN_PROOF
|
403
|
+
result[:DRIVE_CAP_WRITE_BURN_PROOF] = true
|
404
|
+
end
|
405
|
+
return result
|
406
|
+
end
|
407
|
+
|
408
|
+
# = class Device
|
409
|
+
#
|
410
|
+
# CD Input and control class for discs/devices
|
558
411
|
#
|
559
|
-
#
|
560
|
-
# device if there is no media in it. In this situation
|
561
|
-
# capabilities will show up as empty even though there is a
|
562
|
-
# hardware CD-ROM. get_drive_cap_dev()->(read_cap, write_cap,
|
563
|
-
# misc_cap)
|
412
|
+
# == SYNOPSIS
|
564
413
|
#
|
565
|
-
#
|
566
|
-
#
|
567
|
-
#
|
568
|
-
#
|
569
|
-
#
|
570
|
-
#
|
571
|
-
|
414
|
+
# require "cdio"
|
415
|
+
# d = Cdio::Device.new("", Rubycdio::DRIVER_UNKNOWN)
|
416
|
+
# drive_name = d.device()
|
417
|
+
# hw = d.hwinfo()
|
418
|
+
# if hw then
|
419
|
+
# puts "drive: %s, vendor: %s, model: %s, revision: %s" %
|
420
|
+
# [drive_name, hw["vendor"], hw["model"], hw["revision"]]
|
421
|
+
# end
|
422
|
+
#
|
423
|
+
# drivers.each_pair { |driver_name, driver_id|
|
424
|
+
# begin
|
425
|
+
# if driver?(driver_id):
|
426
|
+
# puts "Driver %s is installed." % driver_name
|
427
|
+
# end
|
428
|
+
# rescue ValueError
|
429
|
+
# end
|
430
|
+
|
431
|
+
class Device
|
432
|
+
|
433
|
+
def initialize(source=nil, driver_id=nil,
|
434
|
+
access_mode=nil)
|
435
|
+
@cd = nil
|
436
|
+
if source or driver_id
|
437
|
+
open(source, driver_id, access_mode)
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
# Returns: bool
|
442
|
+
#
|
443
|
+
# return true if CD-ROM understand ATAPI commands.
|
444
|
+
def ATAPI?()
|
445
|
+
return Rubycdio::ATAPI?(@cd)
|
446
|
+
end
|
447
|
+
|
448
|
+
# Returns: status
|
449
|
+
#
|
450
|
+
# Pause playing CD through analog output.
|
451
|
+
# A DeviceError exception may be raised.
|
452
|
+
def audio_pause()
|
453
|
+
drc=Rubycdio::audio_pause(@cd)
|
454
|
+
possibly_raise_exception__(drc)
|
455
|
+
end
|
456
|
+
|
457
|
+
# Returns: status
|
458
|
+
#
|
459
|
+
# Playing CD through analog output from +start_lsn+ to +ending_lsn+
|
460
|
+
# A DeviceError exception may be raised.
|
461
|
+
def audio_play_lsn(start_lsn, end_lsn)
|
462
|
+
drc=Rubycdio::audio_play_lsn(@cd, start_lsn, end_lsn)
|
463
|
+
possibly_raise_exception__(drc)
|
464
|
+
end
|
465
|
+
|
466
|
+
# Returns: status
|
467
|
+
#
|
468
|
+
# Resume playing an audio CD through the analog interface.
|
469
|
+
# A DeviceError exception may be raised.
|
470
|
+
def audio_resume()
|
471
|
+
drc=Rubycdio::audio_resume(@cd)
|
472
|
+
possibly_raise_exception__(drc)
|
473
|
+
end
|
474
|
+
|
475
|
+
# Returns: status
|
476
|
+
#
|
477
|
+
# Stop playing an audio CD through the analog interface.
|
478
|
+
# A DeviceError exception may be raised.
|
479
|
+
def audio_stop()
|
480
|
+
drc=Rubycdio::audio_stop(@cd)
|
481
|
+
possibly_raise_exception__(drc)
|
482
|
+
end
|
483
|
+
|
484
|
+
# Free (C memory) resources associated with the object. Call this when
|
485
|
+
# done using using CD reading/control operations for the current
|
486
|
+
# device.
|
487
|
+
def close()
|
488
|
+
if @cd
|
489
|
+
Rubycdio::close(@cd)
|
490
|
+
else
|
491
|
+
puts "***No object to close"
|
492
|
+
end
|
493
|
+
@cd=nil
|
494
|
+
end
|
495
|
+
|
496
|
+
# Eject media in CD drive if there is a routine to do so.
|
497
|
+
# A DeviceError exception may be raised.
|
498
|
+
def eject_media()
|
499
|
+
drc=Rubycdio::eject_media(@cd)
|
500
|
+
@cd = nil
|
501
|
+
possibly_raise_exception__(drc)
|
502
|
+
end
|
503
|
+
|
504
|
+
# Eject media in CD drive if there is a routine to do so.
|
505
|
+
# An exception is thrown on error.
|
506
|
+
def eject_media_drive(drive=nil)
|
507
|
+
### FIXME: combine into above by testing if drive is the string
|
508
|
+
### nil versus drive = Rubycdio::DRIVER_UNKNOWN
|
509
|
+
Rubycdio::eject_media_drive(drive)
|
510
|
+
end
|
511
|
+
|
512
|
+
# Returns: String
|
513
|
+
|
514
|
+
# Get the value associatied with key.
|
515
|
+
def arg(key)
|
516
|
+
return Rubycdio::get_arg(@cd, key)
|
517
|
+
end
|
518
|
+
|
519
|
+
# Returns: String
|
520
|
+
#
|
521
|
+
# Get the default CD device.
|
522
|
+
# If we haven't initialized a specific device driver),
|
523
|
+
# then find a suitable one and return the default device for that.
|
524
|
+
# In some situations of drivers or OS's we can't find a CD device if
|
525
|
+
# there is no media in it and it is possible for this routine to return
|
526
|
+
# nil even though there may be a hardware CD-ROM.
|
527
|
+
def device()
|
528
|
+
if @cd
|
529
|
+
return Rubycdio::get_arg(@cd, "source")
|
530
|
+
end
|
531
|
+
return Rubycdio::get_device(@cd)
|
532
|
+
end
|
533
|
+
|
534
|
+
# Returns: Fixnum
|
535
|
+
#
|
536
|
+
# Get the LSN of the end of the CD
|
537
|
+
#
|
538
|
+
# DriverError and IOError may raised on error.
|
539
|
+
def disc_last_lsn()
|
540
|
+
lsn = Rubycdio::get_disc_last_lsn(@cd)
|
541
|
+
if lsn == Rubycdio::INVALID_LSN
|
542
|
+
raise DriverError
|
543
|
+
end
|
544
|
+
return lsn
|
545
|
+
end
|
546
|
+
|
547
|
+
# Returns: String
|
548
|
+
#
|
549
|
+
# Get disc mode - the kind of CD (CD-DA, CD-ROM mode 1, CD-MIXED, ...)
|
550
|
+
# that we've got. The notion of 'CD' is extended a little to include
|
551
|
+
# DVD's.
|
552
|
+
def disc_mode()
|
553
|
+
if not @cd then return "Uninitialized Device" end
|
554
|
+
return Rubycdio::get_disc_mode(@cd)
|
555
|
+
end
|
556
|
+
|
557
|
+
# Get drive capabilities of device.
|
558
|
+
#
|
559
|
+
# In some situations of drivers or OS's we can't find a CD
|
560
|
+
# device if there is no media in it. In this situation
|
561
|
+
# capabilities will show up as empty even though there is a
|
562
|
+
# hardware CD-ROM. get_drive_cap_dev()->(read_cap, write_cap,
|
563
|
+
# misc_cap)
|
564
|
+
#
|
565
|
+
# Get drive capabilities of device.
|
566
|
+
#
|
567
|
+
# In some situations of drivers or OS's we can't find a CD
|
568
|
+
# device if there is no media in it. In this situation
|
569
|
+
# capabilities will show up as empty even though there is a
|
570
|
+
# hardware CD-ROM.
|
571
|
+
def drive_cap()
|
572
572
|
b_read_cap, b_write_cap, b_misc_cap = Rubycdio::get_drive_cap(@cd)
|
573
573
|
return [convert_drive_cap_read(b_read_cap),
|
574
574
|
convert_drive_cap_write(b_write_cap),
|
575
575
|
convert_drive_cap_misc(b_misc_cap)]
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
576
|
+
end
|
577
|
+
|
578
|
+
def drive_cap_dev(device=nil)
|
579
|
+
#---
|
580
|
+
### FIXME: combine into above by testing on the type of device.
|
581
|
+
#+++
|
582
|
+
b_read_cap, b_write_cap, b_misc_cap =
|
583
583
|
Rubycdio::get_drive_cap_dev(device);
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
end
|
588
|
-
|
589
|
-
# Returns: String
|
590
|
-
#
|
591
|
-
# return a string containing the name of the driver in use.
|
592
|
-
#
|
593
|
-
# An IOError exception is raised on error.
|
594
|
-
def driver_name()
|
595
|
-
if not @cd then raise DriverUninitError end
|
596
|
-
return Rubycdio::get_driver_name(@cd)
|
597
|
-
end
|
598
|
-
|
599
|
-
# Returns: Fixnum
|
600
|
-
#
|
601
|
-
# Return the driver id of the driver in use.
|
602
|
-
# if object has not been initialized or is nil,
|
603
|
-
# return Rubycdio::DRIVER_UNKNOWN.
|
604
|
-
def driver_id()
|
605
|
-
return Rubycdio::get_driver_id(@cd)
|
606
|
-
end
|
607
|
-
|
608
|
-
# Returns: Track
|
609
|
-
#
|
610
|
-
# return a Track object of the first track. nil is returned
|
611
|
-
# if there was a problem.
|
612
|
-
def first_track()
|
613
|
-
track = Rubycdio::get_first_track_num(@cd)
|
614
|
-
if track == Rubycdio::INVALID_TRACK
|
615
|
-
return nil
|
584
|
+
return [convert_drive_cap_read(b_read_cap),
|
585
|
+
convert_drive_cap_write(b_write_cap),
|
586
|
+
convert_drive_cap_misc(b_misc_cap)]
|
616
587
|
end
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
return session
|
645
|
-
end
|
646
|
-
|
647
|
-
# Returns: Track
|
648
|
-
#
|
649
|
-
# return a Track object of the first track. nil is returned
|
650
|
-
# if there was a problem.
|
651
|
-
def last_track()
|
652
|
-
track = Rubycdio::get_last_track_num(@cd)
|
653
|
-
if track == Rubycdio::INVALID_TRACK
|
588
|
+
|
589
|
+
# Returns: String
|
590
|
+
#
|
591
|
+
# return a string containing the name of the driver in use.
|
592
|
+
#
|
593
|
+
# An IOError exception is raised on error.
|
594
|
+
def driver_name()
|
595
|
+
if not @cd then raise DriverUninitError end
|
596
|
+
return Rubycdio::get_driver_name(@cd)
|
597
|
+
end
|
598
|
+
|
599
|
+
# Returns: Fixnum
|
600
|
+
#
|
601
|
+
# Return the driver id of the driver in use.
|
602
|
+
# if object has not been initialized or is nil,
|
603
|
+
# return Rubycdio::DRIVER_UNKNOWN.
|
604
|
+
def driver_id()
|
605
|
+
return Rubycdio::get_driver_id(@cd)
|
606
|
+
end
|
607
|
+
|
608
|
+
# Returns: Track
|
609
|
+
#
|
610
|
+
# return a Track object of the first track. nil is returned
|
611
|
+
# if there was a problem.
|
612
|
+
def first_track()
|
613
|
+
track = Rubycdio::get_first_track_num(@cd)
|
614
|
+
if track == Rubycdio::INVALID_TRACK
|
654
615
|
return nil
|
616
|
+
end
|
617
|
+
return Track.new(@cd, track)
|
655
618
|
end
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
def mcn()
|
663
|
-
return Rubycdio::get_mcn(@cd)
|
664
|
-
end
|
665
|
-
|
666
|
-
# Find out if media has changed since the last call.
|
667
|
-
# Return true if media has changed since last call. An exception
|
668
|
-
# Error is given on error.
|
669
|
-
def media_changed?()
|
670
|
-
drc = Rubycdio::get_media_changed(@cd)
|
671
|
-
if drc == 0 then return false end
|
672
|
-
if drc == 1 then return true end
|
673
|
-
possibly_raise_exception__(drc)
|
674
|
-
raise DeviceException
|
675
|
-
end
|
676
|
-
|
677
|
-
# Returns: Fixnum
|
678
|
-
#
|
679
|
-
# Return the number of tracks on the CD.
|
680
|
-
# A TrackError or IOError exception may be raised on error.
|
681
|
-
def num_tracks()
|
682
|
-
track = Rubycdio::get_num_tracks(@cd)
|
683
|
-
if track == Rubycdio::INVALID_TRACK
|
684
|
-
raise TrackError
|
619
|
+
|
620
|
+
# Returns: {"vendor"=>??, "model"=>??, "release"=>??}
|
621
|
+
#
|
622
|
+
# Get the CD-ROM hardware info via a SCSI MMC INQUIRY command.
|
623
|
+
def hwinfo()
|
624
|
+
return Rubycdio::get_hwinfo(@cd)
|
685
625
|
end
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
626
|
+
|
627
|
+
# Returns: FixNum
|
628
|
+
|
629
|
+
# Return the Joliet level recognized for cdio. This only makes
|
630
|
+
# sense for something that has an ISO-9660 filesystem.
|
631
|
+
|
632
|
+
def joliet_level()
|
633
|
+
return Rubycdio::get_joliet_level(@cd)
|
634
|
+
end
|
635
|
+
|
636
|
+
# Returns: Fixnum
|
637
|
+
|
638
|
+
# Get the LSN of the first track of the last session of on the CD.
|
639
|
+
# An exception is thrown on error.
|
640
|
+
|
641
|
+
def last_session()
|
642
|
+
drc, session = Rubycdio::get_last_session(@cd)
|
643
|
+
possibly_raise_exception__(drc)
|
644
|
+
return session
|
645
|
+
end
|
646
|
+
|
647
|
+
# Returns: Track
|
648
|
+
#
|
649
|
+
# return a Track object of the first track. nil is returned
|
650
|
+
# if there was a problem.
|
651
|
+
def last_track()
|
706
652
|
track = Rubycdio::get_last_track_num(@cd)
|
707
|
-
|
653
|
+
if track == Rubycdio::INVALID_TRACK
|
708
654
|
return nil
|
655
|
+
end
|
656
|
+
return Track.new(@cd, track)
|
709
657
|
end
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
#
|
717
|
-
# +offset+ is amount to seek and
|
718
|
-
# +whence+ is like corresponding parameter in libc's lseek, e.g.
|
719
|
-
# it should be SEEK_SET or SEEK_END.
|
720
|
-
#
|
721
|
-
# the offset is returned or -1 on error.
|
722
|
-
def lseek(offset, whence)
|
723
|
-
return Rubycdio::lseek(@cd, offset, whence)
|
724
|
-
end
|
725
|
-
|
726
|
-
# Sets up to read from place specified by +source+, +driver_id+ and
|
727
|
-
# +access_mode+. This should be called before using any other routine
|
728
|
-
# except those that act on a CD-ROM drive by name.
|
729
|
-
#
|
730
|
-
# If nil is the value of +source+, we'll use the default driver device.
|
731
|
-
# If nil is the value of +driver_id+, we'll find a suitable device driver.
|
732
|
-
#
|
733
|
-
# If device object was, previously opened it is closed first.
|
734
|
-
#
|
735
|
-
# Device is opened so that subsequent operations can be performed.
|
736
|
-
def open(source=nil, driver_id=Rubycdio::DRIVER_UNKNOWN,
|
737
|
-
access_mode=nil)
|
738
|
-
if not driver_id
|
739
|
-
driver_id=Rubycdio::DRIVER_UNKNOWN
|
658
|
+
|
659
|
+
# Returns: String
|
660
|
+
#
|
661
|
+
# Get the media catalog number (MCN) from the CD.
|
662
|
+
def mcn()
|
663
|
+
return Rubycdio::get_mcn(@cd)
|
740
664
|
end
|
741
|
-
|
742
|
-
|
665
|
+
|
666
|
+
# Find out if media has changed since the last call.
|
667
|
+
# Return true if media has changed since last call. An exception
|
668
|
+
# Error is given on error.
|
669
|
+
def media_changed?()
|
670
|
+
drc = Rubycdio::get_media_changed(@cd)
|
671
|
+
if drc == 0 then return false end
|
672
|
+
if drc == 1 then return true end
|
673
|
+
possibly_raise_exception__(drc)
|
674
|
+
raise DeviceException
|
675
|
+
end
|
676
|
+
|
677
|
+
# Returns: Fixnum
|
678
|
+
#
|
679
|
+
# Return the number of tracks on the CD.
|
680
|
+
# A TrackError or IOError exception may be raised on error.
|
681
|
+
def num_tracks()
|
682
|
+
track = Rubycdio::get_num_tracks(@cd)
|
683
|
+
if track == Rubycdio::INVALID_TRACK
|
684
|
+
raise TrackError
|
685
|
+
end
|
686
|
+
return track
|
687
|
+
end
|
688
|
+
|
689
|
+
# Returns: track
|
690
|
+
#
|
691
|
+
# Return a track object for the given track number.
|
692
|
+
def track(track_num)
|
693
|
+
return Track.new(@cd, track_num)
|
694
|
+
end
|
695
|
+
|
696
|
+
# Returns: track
|
697
|
+
#
|
698
|
+
# Find the track which contains +lsn+.
|
699
|
+
# nil is returned if the lsn outside of the CD or
|
700
|
+
# if there was some error.
|
701
|
+
#
|
702
|
+
# If +lsn+ is before the pregap of the first track,
|
703
|
+
# A track object with a 0 track is returned.
|
704
|
+
# Otherwise we return the track that spans the LSN.
|
705
|
+
def track_for_lsn(lsn)
|
706
|
+
track = Rubycdio::get_last_track_num(@cd)
|
707
|
+
if track == Rubycdio::INVALID_TRACK
|
708
|
+
return nil
|
709
|
+
end
|
710
|
+
return Track.new(@cd, track)
|
743
711
|
end
|
744
|
-
|
745
|
-
|
712
|
+
|
713
|
+
# Returns: Fixnum
|
714
|
+
# Reposition read offset
|
715
|
+
# Similar to (if not the same as) libc's fseek()
|
716
|
+
#
|
717
|
+
# +offset+ is amount to seek and
|
718
|
+
# +whence+ is like corresponding parameter in libc's lseek, e.g.
|
719
|
+
# it should be SEEK_SET or SEEK_END.
|
720
|
+
#
|
721
|
+
# the offset is returned or -1 on error.
|
722
|
+
def lseek(offset, whence)
|
723
|
+
return Rubycdio::lseek(@cd, offset, whence)
|
746
724
|
end
|
725
|
+
|
726
|
+
# Sets up to read from place specified by +source+, +driver_id+ and
|
727
|
+
# +access_mode+. This should be called before using any other routine
|
728
|
+
# except those that act on a CD-ROM drive by name.
|
729
|
+
#
|
730
|
+
# If nil is the value of +source+, we'll use the default driver device.
|
731
|
+
# If nil is the value of +driver_id+, we'll find a suitable device driver.
|
732
|
+
#
|
733
|
+
# If device object was, previously opened it is closed first.
|
734
|
+
#
|
735
|
+
# Device is opened so that subsequent operations can be performed.
|
736
|
+
def open(source=nil, driver_id=Rubycdio::DRIVER_UNKNOWN,
|
737
|
+
access_mode=nil)
|
738
|
+
if not driver_id
|
739
|
+
driver_id=Rubycdio::DRIVER_UNKNOWN
|
740
|
+
end
|
741
|
+
if not source
|
742
|
+
source = ''
|
743
|
+
end
|
744
|
+
if not access_mode
|
745
|
+
access_mode = ''
|
746
|
+
end
|
747
747
|
if @cd
|
748
748
|
close()
|
749
749
|
end
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
end
|
765
|
-
|
766
|
-
# return [size, data]
|
767
|
-
#
|
768
|
-
# Reads a number of data sectors (AKA blocks).
|
769
|
-
#
|
770
|
-
# +lsn+ is the sector to read; +bytes+ is the number of bytes to read.
|
771
|
-
# A DeviceError exception may be raised.
|
772
|
-
def read_data_blocks(lsn, blocks=1)
|
773
|
-
size = Rubycdio::ISO_BLOCKSIZE*blocks
|
774
|
-
triple = Rubycdio::read_data_bytes(@cd, lsn,
|
775
|
-
Rubycdio::ISO_BLOCKSIZE, size)
|
776
|
-
if not triple
|
777
|
-
return [-1, nil]
|
750
|
+
@cd = Rubycdio::open_cd(source, driver_id, access_mode)
|
751
|
+
end
|
752
|
+
|
753
|
+
# Returns: [size, data]
|
754
|
+
#
|
755
|
+
# Reads the next +size+ bytes.
|
756
|
+
# Similar to (if not the same as) libc's read()
|
757
|
+
#
|
758
|
+
# The number of bytes read and the data is returned.
|
759
|
+
# A DeviceError exception may be raised.
|
760
|
+
def read(size)
|
761
|
+
size, data = Rubycdio::read_cd(@cd, size)
|
762
|
+
possibly_raise_exception__(size)
|
763
|
+
return [size, data]
|
778
764
|
end
|
765
|
+
|
766
|
+
# return [size, data]
|
767
|
+
#
|
768
|
+
# Reads a number of data sectors (AKA blocks).
|
769
|
+
#
|
770
|
+
# +lsn+ is the sector to read; +bytes+ is the number of bytes to read.
|
771
|
+
# A DeviceError exception may be raised.
|
772
|
+
def read_data_blocks(lsn, blocks=1)
|
773
|
+
size = Rubycdio::ISO_BLOCKSIZE*blocks
|
774
|
+
triple = Rubycdio::read_data_bytes(@cd, lsn,
|
775
|
+
Rubycdio::ISO_BLOCKSIZE, size)
|
776
|
+
if not triple
|
777
|
+
return [-1, nil]
|
778
|
+
end
|
779
779
|
data, size, drc = triple
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
780
|
+
possibly_raise_exception__(drc)
|
781
|
+
return [size, data]
|
782
|
+
end
|
783
|
+
|
784
|
+
# return [blocks, data]
|
785
|
+
#
|
786
|
+
# Reads a number of sectors (AKA blocks).
|
787
|
+
#
|
788
|
+
# +lsn+ is the sector to read, +bytes+ is the number of bytes to read.
|
789
|
+
#
|
790
|
+
# If +read_mode+ is Rubycdio::MODE_AUDIO, the return buffer size will be
|
791
|
+
# truncated to multiple of Rubycdio::CDIO_FRAMESIZE_RAW i_blocks bytes.
|
792
|
+
#
|
793
|
+
# If +read_mode+ is Rubycdio::MODE_DATA, buffer will be truncated to a
|
794
|
+
# multiple of Rubycdio::ISO_BLOCKSIZE, Rubycdio::M1RAW_SECTOR_SIZE or
|
795
|
+
# Rubycdio::M2F2_SECTOR_SIZE bytes depending on what mode the data is in.
|
796
|
+
#
|
797
|
+
# If +read_mode+ is Rubycdio::MODE_M2F1, buffer will be truncated to a
|
798
|
+
# multiple of Rubycdio::M2RAW_SECTOR_SIZE bytes.
|
799
|
+
#
|
800
|
+
# If +read_mode+ is Rubycdio::MODE_M2F2, the return buffer size will be
|
801
|
+
# truncated to a multiple of Rubycdio::CD_FRAMESIZE bytes.
|
802
|
+
#
|
803
|
+
# The number of bytes read and the data is returned.
|
804
|
+
# A DeviceError exception may be raised.
|
805
|
+
def read_sectors(lsn, read_mode, blocks=1)
|
806
|
+
begin
|
807
|
+
blocksize = read_mode2blocksize()[read_mode]
|
808
|
+
size = blocks * blocksize
|
809
|
+
rescue
|
810
|
+
return [-1, nil]
|
811
|
+
end
|
812
|
+
triple = Rubycdio::read_sectors(@cd, lsn, read_mode, size)
|
813
|
+
if not triple
|
814
|
+
return [-1, nil]
|
815
|
+
end
|
816
|
+
data, size, drc = triple
|
817
|
+
possibly_raise_exception__(drc)
|
818
|
+
blocks = size / blocksize
|
819
|
+
return [blocks, data]
|
820
|
+
end
|
821
|
+
|
822
|
+
# Set the blocksize for subsequent reads.
|
823
|
+
# An exception is thrown on error.
|
824
|
+
def blocksize=(blocksize)
|
825
|
+
drc = Rubycdio::set_blocksize(@cd, blocksize)
|
826
|
+
possibly_raise_exception__(drc)
|
827
|
+
end
|
828
|
+
|
829
|
+
# Set the drive speed. An exception is thrown on error.
|
830
|
+
def speed=(speed)
|
831
|
+
drc = Rubycdio::set_speed(@cd, speed)
|
832
|
+
possibly_raise_exception__(drc)
|
833
|
+
end
|
834
|
+
end # Device
|
835
|
+
|
836
|
+
# = CD Input and control track class
|
785
837
|
#
|
786
|
-
#
|
787
|
-
#
|
788
|
-
# +lsn+ is the sector to read, +bytes+ is the number of bytes to read.
|
789
|
-
#
|
790
|
-
# If +read_mode+ is Rubycdio::MODE_AUDIO, the return buffer size will be
|
791
|
-
# truncated to multiple of Rubycdio::CDIO_FRAMESIZE_RAW i_blocks bytes.
|
792
|
-
#
|
793
|
-
# If +read_mode+ is Rubycdio::MODE_DATA, buffer will be truncated to a
|
794
|
-
# multiple of Rubycdio::ISO_BLOCKSIZE, Rubycdio::M1RAW_SECTOR_SIZE or
|
795
|
-
# Rubycdio::M2F2_SECTOR_SIZE bytes depending on what mode the data is in.
|
838
|
+
# == SYNOPSIS
|
796
839
|
#
|
797
|
-
#
|
798
|
-
#
|
799
|
-
#
|
800
|
-
#
|
801
|
-
#
|
802
|
-
#
|
803
|
-
#
|
804
|
-
#
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
840
|
+
# require "cdio"
|
841
|
+
# d = Device.new("/dev/cdrom")
|
842
|
+
# t = d.first_track()
|
843
|
+
# first_track = t.track
|
844
|
+
# num_tracks = d.num_tracks()
|
845
|
+
# last_track = first_track+num_tracks-1
|
846
|
+
# for i in first_track .. last_track
|
847
|
+
# t = d.track(i)
|
848
|
+
# puts "%3d: %06u %-6s %s" % [t.track, t.lsn(), t.msf(), t.format()]
|
849
|
+
# end
|
850
|
+
# puts "%3X: %06u leadout" % [Rubycdio::CDROM_LEADOUT_TRACK, d.disc_last_lsn()]
|
851
|
+
#
|
852
|
+
class Track
|
853
|
+
|
854
|
+
attr_accessor :track
|
855
|
+
|
856
|
+
def initialize(device, track_num)
|
857
|
+
|
858
|
+
if track_num.class != Fixnum
|
859
|
+
raise TrackError('track number parameter is not an integer')
|
860
|
+
end
|
861
|
+
@track = track_num
|
862
|
+
|
863
|
+
# See if the device parameter is a string or
|
864
|
+
# a device object.
|
865
|
+
if device.class == String
|
866
|
+
@device = Device.new(device)
|
867
|
+
else
|
868
|
+
@device = device
|
869
|
+
end
|
870
|
+
end
|
871
|
+
|
872
|
+
# Returns: Fixnum
|
873
|
+
#
|
874
|
+
# Return number of channels in track: 2 or 4.
|
875
|
+
# Not meaningful if track is not an audio track.
|
876
|
+
# An exception can be raised on error.
|
877
|
+
def audio_channels()
|
878
|
+
channels = Rubycdio::get_track_channels(@device, @track)
|
879
|
+
if -2 == channels
|
880
|
+
raise DriverUnsupportedError
|
881
|
+
elsif -1 == channels
|
882
|
+
raise TrackError
|
883
|
+
else
|
884
|
+
return channels
|
885
|
+
end
|
886
|
+
end
|
887
|
+
|
888
|
+
def cdtext
|
889
|
+
return CDText.new(Rubycdio::get_cdtext(@device, @track))
|
815
890
|
end
|
816
|
-
data, size, drc = triple
|
817
|
-
possibly_raise_exception__(drc)
|
818
|
-
blocks = size / blocksize
|
819
|
-
return [blocks, data]
|
820
|
-
end
|
821
|
-
|
822
|
-
# Set the blocksize for subsequent reads.
|
823
|
-
# An exception is thrown on error.
|
824
|
-
def blocksize=(blocksize)
|
825
|
-
drc = Rubycdio::set_blocksize(@cd, blocksize)
|
826
|
-
possibly_raise_exception__(drc)
|
827
|
-
end
|
828
|
-
|
829
|
-
# Set the drive speed. An exception is thrown on error.
|
830
|
-
def speed=(speed)
|
831
|
-
drc = Rubycdio::set_speed(@cd, speed)
|
832
|
-
possibly_raise_exception__(drc)
|
833
|
-
end
|
834
|
-
end # Device
|
835
891
|
|
836
|
-
#
|
837
|
-
#
|
838
|
-
#
|
839
|
-
#
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
# first_track = t.track
|
844
|
-
# num_tracks = d.num_tracks()
|
845
|
-
# last_track = first_track+num_tracks-1
|
846
|
-
# for i in first_track .. last_track
|
847
|
-
# t = d.track(i)
|
848
|
-
# puts "%3d: %06u %-6s %s" % [t.track, t.lsn(), t.msf(), t.format()]
|
849
|
-
# end
|
850
|
-
# puts "%3X: %06u leadout" % [Rubycdio::CDROM_LEADOUT_TRACK, d.disc_last_lsn()]
|
851
|
-
#
|
852
|
-
class Track
|
853
|
-
|
854
|
-
attr_accessor :track
|
855
|
-
|
856
|
-
def initialize(device, track_num)
|
892
|
+
# Returns: bool
|
893
|
+
#
|
894
|
+
# Return copy protection status on a track. Is this meaningful
|
895
|
+
# not an audio track?
|
896
|
+
def copy_permit?()
|
897
|
+
return Rubycdio::track_copy_permit?(@device, @track)
|
898
|
+
end
|
857
899
|
|
858
|
-
|
859
|
-
|
900
|
+
# Returns: format (String)
|
901
|
+
#
|
902
|
+
# Get the format (e.g. 'audio', 'mode2', 'mode1') of track.
|
903
|
+
def format()
|
904
|
+
return Rubycdio::get_track_format(@device, @track)
|
860
905
|
end
|
861
|
-
@track = track_num
|
862
906
|
|
863
|
-
#
|
864
|
-
#
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
907
|
+
# Returns: Fixnum (lsn)
|
908
|
+
#
|
909
|
+
# Return the ending LSN for a track.
|
910
|
+
# A TrackError or IOError exception may be raised on error.
|
911
|
+
def last_lsn()
|
912
|
+
lsn = Rubycdio::get_track_last_lsn(@device, @track)
|
913
|
+
if lsn == Rubycdio::INVALID_LSN
|
914
|
+
raise TrackError('Invalid LSN returned')
|
915
|
+
end
|
916
|
+
return lsn
|
869
917
|
end
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
elsif -1 == channels
|
882
|
-
raise TrackError
|
883
|
-
else
|
884
|
-
return channels
|
918
|
+
|
919
|
+
# Returns: Fixnum (lba)
|
920
|
+
#
|
921
|
+
# Return the starting LBA for a track
|
922
|
+
# A TrackError exception is raised on error.
|
923
|
+
def lba()
|
924
|
+
lba = Rubycdio::get_track_lba(@device, @track)
|
925
|
+
if lba == Rubycdio::INVALID_LBA
|
926
|
+
raise TrackError('Invalid LBA returned')
|
927
|
+
end
|
928
|
+
return lba
|
885
929
|
end
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
end
|
895
|
-
|
896
|
-
# Returns: format (String)
|
897
|
-
#
|
898
|
-
# Get the format (e.g. 'audio', 'mode2', 'mode1') of track.
|
899
|
-
def format()
|
900
|
-
return Rubycdio::get_track_format(@device, @track)
|
901
|
-
end
|
902
|
-
|
903
|
-
# Returns: Fixnum (lsn)
|
904
|
-
#
|
905
|
-
# Return the ending LSN for a track.
|
906
|
-
# A TrackError or IOError exception may be raised on error.
|
907
|
-
def last_lsn()
|
908
|
-
lsn = Rubycdio::get_track_last_lsn(@device, @track)
|
909
|
-
if lsn == Rubycdio::INVALID_LSN
|
910
|
-
raise TrackError('Invalid LSN returned')
|
911
|
-
end
|
912
|
-
return lsn
|
913
|
-
end
|
914
|
-
|
915
|
-
# Returns: Fixnum (lba)
|
916
|
-
#
|
917
|
-
# Return the starting LBA for a track
|
918
|
-
# A TrackError exception is raised on error.
|
919
|
-
def lba()
|
920
|
-
lba = Rubycdio::get_track_lba(@device, @track)
|
921
|
-
if lba == Rubycdio::INVALID_LBA
|
922
|
-
raise TrackError('Invalid LBA returned')
|
923
|
-
end
|
924
|
-
return lba
|
925
|
-
end
|
926
|
-
|
927
|
-
# Returns: Fixnum (lsn)
|
928
|
-
#
|
929
|
-
# Return the starting LSN for a track
|
930
|
-
# A TrackError exception is raised on error.
|
931
|
-
def lsn()
|
932
|
-
lsn = Rubycdio::get_track_lsn(@device, @track)
|
933
|
-
if lsn == Rubycdio::INVALID_LSN:
|
930
|
+
|
931
|
+
# Returns: Fixnum (lsn)
|
932
|
+
#
|
933
|
+
# Return the starting LSN for a track
|
934
|
+
# A TrackError exception is raised on error.
|
935
|
+
def lsn()
|
936
|
+
lsn = Rubycdio::get_track_lsn(@device, @track)
|
937
|
+
if lsn == Rubycdio::INVALID_LSN
|
934
938
|
raise TrackError('Invalid LSN returned')
|
939
|
+
end
|
940
|
+
return lsn
|
935
941
|
end
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
raise TrackError('Invalid return value %d' % d)
|
965
|
-
end
|
942
|
+
|
943
|
+
# Returns: String
|
944
|
+
#
|
945
|
+
# Return the starting MSF (minutes/secs/frames) for track number track.
|
946
|
+
# Track numbers usually start at something greater than 0, usually 1.
|
947
|
+
#
|
948
|
+
# Returns string of the form <i>mm:ss:ff</i> if all good, or string nil on
|
949
|
+
# error.
|
950
|
+
def msf()
|
951
|
+
return Rubycdio::get_track_msf(@device, @track)
|
952
|
+
end
|
953
|
+
|
954
|
+
# Returns: String
|
955
|
+
#
|
956
|
+
# Get linear preemphasis status on an audio track.
|
957
|
+
# This is not meaningful if not an audio track?
|
958
|
+
# A TrackError exception is raised on error.
|
959
|
+
def preemphasis()
|
960
|
+
rc = Rubycdio::get_track_preemphasis(@device, @track)
|
961
|
+
if rc == Rubycdio::TRACK_FLAG_FALSE
|
962
|
+
return 'none'
|
963
|
+
elsif rc == Rubycdio::TRACK_FLAG_TRUE
|
964
|
+
return 'preemphasis'
|
965
|
+
elsif rc == Rubycdio::TRACK_FLAG_UNKNOWN
|
966
|
+
return 'unknown'
|
967
|
+
else
|
968
|
+
raise TrackError('Invalid return value %d' % d)
|
969
|
+
end
|
966
970
|
end
|
967
971
|
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
972
|
+
# Returns: Fixnum
|
973
|
+
#
|
974
|
+
# Get the number of sectors between this track an the next. This
|
975
|
+
# includes any pregap sectors before the start of the next track.
|
976
|
+
# Track numbers usually start at something
|
977
|
+
# greater than 0, usually 1.
|
978
|
+
#
|
979
|
+
# A TrackError exception is raised on error.
|
976
980
|
def sec_count()
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
981
|
+
sec_count = Rubycdio::get_track_sec_count(@device, @track)
|
982
|
+
if sec_count == 0
|
983
|
+
raise TrackError
|
984
|
+
end
|
985
|
+
return sec_count
|
982
986
|
end
|
983
|
-
|
987
|
+
|
984
988
|
# Return true if we have XA data (green, mode2 form1) or
|
985
989
|
# XA data (green, mode2 form2). That is track begins:
|
986
990
|
# sync - header - subheader
|
@@ -991,7 +995,37 @@ class Track
|
|
991
995
|
|
992
996
|
end # class Track
|
993
997
|
|
994
|
-
|
998
|
+
class CDText
|
999
|
+
def initialize(opaque)
|
1000
|
+
@_cdtext = opaque
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
#
|
1004
|
+
# get(self, key)->string
|
1005
|
+
#
|
1006
|
+
# Get the value associatied with key.
|
1007
|
+
#
|
1008
|
+
def get(key)
|
1009
|
+
return Rubycdio::cdtext_get(key, @_cdtext)
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
def is_keyword(key)
|
1013
|
+
return Rubycdio::cdtext_is_keyword(key, @_cdtext)
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
#
|
1017
|
+
# set(self, key, string)->None
|
1018
|
+
#
|
1019
|
+
# Set the value associatied with key.
|
1020
|
+
#
|
1021
|
+
def set( key, string)
|
1022
|
+
return Rubycdio::cdtext_set(key, string, @_cdtext)
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
|
1026
|
+
end
|
1027
|
+
end # module Cdio
|
1028
|
+
|
995
1029
|
include Cdio
|
996
1030
|
#
|
997
1031
|
# Local variables:
|