Importing SDLPerl 2.2
[sdlgit/SDL_perl.git] / lib / SDL / Cdrom.pm
CommitLineData
bfd90409 1#!/usr/bin/env perl
2#
3# Cdrom.pm
4#
5# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6#
7# ------------------------------------------------------------------------------
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2.1 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this library; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22#
23# ------------------------------------------------------------------------------
24#
25# Please feel free to send questions, suggestions or improvements to:
26#
27# David J. Goehrig
28# dgoehrig@cpan.org
29#
30
31package SDL::Cdrom;
32use strict;
33
34BEGIN {
35 use Exporter();
36 use vars qw(@ISA @EXPORT);
37 @ISA = qw(Exporter);
38 @EXPORT = qw/ &CD_NUM_DRIVES /;
39}
40
41sub new {
42 my $proto = shift;
43 my $class = ref($proto) || $proto;
44 my $self;
45 my $number = shift;
46 $self = \SDL::CDOpen($number);
47 die SDL::GetError() if ( SDL::CD_ERROR() eq SDL::CDStatus($$self));
48 bless $self,$class;
49 return $self;
50}
51
52sub DESTROY {
53 my $self = shift;
54 SDL::CDClose($$self);
55}
56
57sub CD_NUM_DRIVES {
58 return SDL::CDNumDrives();
59}
60
61sub name ($) {
62 my $self = shift;
63 return SDL::CDName($$self);
64}
65
66sub status ($) {
67 my $self = shift;
68 return SDL::CDstatus($$self);
69}
70
71sub play ($$$;$$) {
72 my ($self,$start,$length,$fs,$fl) = @_;
73 return SDL::CDPlayTracks($$self,$start,$length,$fs,$fl);
74}
75
76sub pause ($) {
77 my $self = shift;
78 return SDL::CDPause($$self);
79}
80
81sub resume ($) {
82 my $self = shift;
83 return SDL::CDResume($$self);
84}
85
86sub stop ($) {
87 my $self = shift;
88 return SDL::CDStop($$self);
89}
90
91sub eject ($) {
92 my $self = shift;
93 return SDL::CDEject($$self);
94}
95
96sub id ($) {
97 my $self = shift;
98 return SDL::CDId($$self);
99}
100
101sub num_tracks ($) {
102 my $self = shift;
103 return SDL::CDNumTracks($$self);
104}
105
106my $buildtrack = sub {
107 my $ptr = shift;
108 my %track = ();
109 $track{-id} = SDL::CDTrackId($ptr);
110 $track{-type} = SDL::CDTrackType($ptr);
111 $track{-length} = SDL::CDTrackLength($ptr);
112 $track{-offset} = SDL::CDTrackOffset($ptr);
113 return \%track;
114};
115
116sub track {
117 my $self = shift;
118 my $number = shift;
119 return &$buildtrack(SDL::CDTrack($$self,$number));
120}
121
122sub current {
123 my $self = shift;
124 return $self->track(SDL::CDCurTrack($$self));
125}
126
127sub current_frame {
128 my $self = shift;
129 return SDL::CDCurFrame($$self);
130}
131
1321;
133
134__END__;
135
136=pod
137
138
139
140=head1 NAME
141
142SDL::Cdrom - a SDL perl extension for managing CD-ROM drives
143
144=head1 SYNOPSIS
145
146 use SDL::Cdrom;
147 $cdrom = SDL::Cdrom->new(0);
148 $cdrom->play();
149
150=head1 EXPORTS
151
152=over 4
153
154=item *
155
156C<CD_NUM_DRIVES>.
157
158=back
159
160=head1 DESCRIPTION
161
162Create a new SDL::Cdrom object. The passed $id is the number of the drive,
163whereas 0 is the first drive etc.
164
165 use SDL::Cdrom;
166 my $drive => SDL::Cdrom->new($id);
167
168=head1 METHODS
169
170=head2 CD_NUM_DRIVES()
171
172Returns the number of CD-ROM drives present.
173
174=head2 name()
175
176Returns the system dependent name of the CD-ROM device.
177
178=head2 status()
179
180Return the status of the drive.
181
182=head2 play()
183
184Play a track.
185
186=head2 pause()
187
188Pause the playing.
189
190=head2 resume()
191
192Resume the playing.
193
194=head2 stop()
195
196Stop the playing.
197
198=head2 eject()
199
200Eject the medium in the drive.
201
202=head2 id()
203
204Return the ID of the drive.
205
206=head2 num_tracks()
207
208Return the number of tracks on the medium.
209
210=head2 track()
211
212Returns the track description
213
214=head2 current()
215
216Return the current played track number.
217
218=head2 current_frame()
219
220Return the current frame.
221
222=head1 AUTHORS
223
224David J. Goehrig
225Documentation by Tels <http://bloodgate.com/>.
226
227=head1 SEE ALSO
228
229L<perl> L<SDL::Mixer> L<SDL::App>.
230
231=cut