Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

AudioCD::Mac
MacPerl extension for controlling Audio CDs

AudioCD::Mac - MacPerl extension for controlling Audio CDs


NAME

AudioCD::Mac - MacPerl extension for controlling Audio CDs


SYNOPSIS


    #!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;


DESCRIPTION

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.


FUNCTIONS

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.

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.

new
Should be called from AudioCD, not AudioCD::Mac, but should work either way. Returns the object.

status
Returns the current status of the CD, one of: CD_PLAY, CD_PAUSE, CD_MUTE, CD_FINISH, CD_ERR, CD_STOP, CD_OFFLINE.

info
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;

play([TRACK])
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.

stop
Stops the CD. Time settings will likely be left at last play point, not at beginning of CD.

pause
Will pause the CD if it is playing, or continue playing if paused.

continue
Will continue playing if paused.

eject
Will unmount the volumes on the drive if any, and then eject the tray.

volume([LEFT_VOLUME [, RIGHT_VOLUME]])
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.

cd_toc
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].

cddb_toc
Returns the same as above, but in a format suitable for passing to the CDDB module.

last_track
Ideally, returns the last audio track number on the CD. If this turns out to be wrong, let me know.


TODO

Change interface to work well with others (Tuomas' Linux code)
Add support for multiple drives, multiple volumes on drive
Add support for moving forward/backward in tracks, and scanning
Add support for modes (stereo/mono/etc., random/program/repeat/etc.)
Add support to add/extract data in the CD Remote Programs file
Need good test suite ... don't know how this should work, since I won't have good data to test against. Maybe I should just play some tracks, change the volume, print out the number of tracks and have the user say whether or not it passes.


AUTHOR

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


HISTORY

v0.25, Thursday, December 11, 1998
Significant clean up of Perl and XS code, lots of misc. changes.

Hopefully fixed cd_toc to give all the right values.

Fixed eject problems.


   "no pointer is a pointer, too" -- Matthias Neeracher

v0.20, Wednesday, December 9, 1998
Renamed to AudioCD, added controls for Audio CD.

v0.10, Thursday, October 8, 1998
First version, made for Mac OS to get CDDB TOC data.


VERSION

v0.25, Thursday, December 11, 1998


SEE ALSO

CDDB.pm.

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy