AudioCD::Mac - MacPerl extension for controlling Audio CDs
#!perl -w use AudioCD; use strict; my $cd = new AudioCD; $cd->volume(255); $cd->play(2); print "Now playing\n" if $cd->status == CD_PLAY; printf "Volume is %d\n", $cd->volume; sleep(5); $cd->pause; print "Now paused\n" if $cd->status == CD_PAUSE; sleep(5); $cd->volume(100); $cd->continue; print "Now playing\n" if $cd->status == CD_PLAY; printf "Volume is %d\n", $cd->volume; sleep(5); my @info = $cd->info; printf "Currently at track %d, %.2d:%.2d\n", @info[0..2]; $cd->stop; my $status = $cd->status; print "Now stopped\n" if ($status == CD_FINISH || $status == CD_STOP); if (do 'CDDB.pm') { # sold separately my $cddb = new CDDB; my @cddb_info = $cddb->calculate_id( $cd->cddb_toc ); my @discs = $cddb->get_discs(@cddb_info[0, 3, 4]); print "You were probably listening to $discs[0]->[2]\n"; } $cd->eject;
This is the MacPerl module to be used by the AudioCD module. Other modules can be written for other platforms, but this one is Mac specific, calling Mac OS APIs to control the CD player.
AudioCD
All functions except for new are methods that need to be called via the AudioCD object. All functions attempt to return undef and set $^E on failure, and unless otherwise specified, return 1 on success.
new
undef
$^E
1
Note that the data returned from the Mac OS APIs is often in BCD format, but the functions that return track and time data convert it to decimal.
Should be called from AudioCD, not AudioCD::Mac, but should work either way. Returns the object.
AudioCD::Mac
Returns the current status of the CD, one of: CD_PLAY, CD_PAUSE, CD_MUTE, CD_FINISH, CD_ERR, CD_STOP, CD_OFFLINE.
Returns an array of information about the CD, with two sets of times, one for the current track, one for the disc. The first item in the list is the current track number.
# 0 1 2 3 4 5 6 ($t_number, $t_min, $t_sec, $t_frames, $a_min, $a_sec, $a_frames) = $cd->info;
If called without a track number, will start from the first track if stopped, or continue if paused. Otherwise will start at specified track number, and continue until the CD is finished.
Stops the CD. Time settings will likely be left at last play point, not at beginning of CD.
Will pause the CD if it is playing, or continue playing if paused.
Will continue playing if paused.
Will unmount the volumes on the drive if any, and then eject the tray.
Sets the left and right channels to a valume from 0 to 255. Returns the left and right channel volumes, unless the two have the same value and the method is called in a scalar context, in which case it returns just one value.
If RIGHT_VOLUME is not supplied, it will be set to the same value as supplied in LEFT_VOLUME. If not values are supplied, the current volume value(s) will be returned, and will remain unchanged.
RIGHT_VOLUME
LEFT_VOLUME
Returns the table of contents in an anonymous array, where each element is another anonymous array, containing the track number [0] and the track's starting time offset from the beginning of the CD in minutes [1], seconds [2], and frames [3].
Returns the same as above, but in a format suitable for passing to the CDDB module.
CDDB
Ideally, returns the last audio track number on the CD. If this turns out to be wrong, let me know.
Chris Nandor <pudge@pobox.com> http://pudge.net/
Copyright (c) 1998 Chris Nandor. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Please see the Perl Artistic License.
Special thanks to Matthias Neeracher for help with MacPerl XS and C, and Glenn Howes <grhowes@kagi.com> for his code examples that helped me understand this stuff.
http://www.xnet.com/~grhowes/html/helpful.html
For more info, check out Technote DV22:
http://developer.apple.com/technotes/dv/dv_22.html
Significant clean up of Perl and XS code, lots of misc. changes.
Hopefully fixed cd_toc to give all the right values.
cd_toc
Fixed eject problems.
eject
"no pointer is a pointer, too" -- Matthias Neeracher
Renamed to AudioCD, added controls for Audio CD.
First version, made for Mac OS to get CDDB TOC data.
v0.25, Thursday, December 11, 1998
CDDB.pm.
To install AudioCD::Mac, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AudioCD::Mac
CPAN shell
perl -MCPAN -e shell install AudioCD::Mac
For more information on module installation, please visit the detailed CPAN module installation guide.