updated Cdrom and Event and SDL pods,
[sdlgit/SDL_perl.git] / lib / SDL / Cdrom.pm
CommitLineData
7b6a53a1 1#!/usr/bin/env perl
8fde61e3 2#
7b6a53a1 3# Cdrom.pm
8fde61e3 4#
7b6a53a1 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
8fde61e3 29#
30
31package SDL::Cdrom;
32use strict;
084b921f 33use warnings;
34use Carp;
8fde61e3 35
36BEGIN {
37 use Exporter();
38 use vars qw(@ISA @EXPORT);
39 @ISA = qw(Exporter);
40 @EXPORT = qw/ &CD_NUM_DRIVES /;
41}
42
43sub new {
44 my $proto = shift;
45 my $class = ref($proto) || $proto;
46 my $self;
47 my $number = shift;
48 $self = \SDL::CDOpen($number);
084b921f 49 croak SDL::GetError() if ( SDL::CD_ERROR() eq SDL::CDStatus($$self));
8fde61e3 50 bless $self,$class;
51 return $self;
52}
53
54sub DESTROY {
55 my $self = shift;
56 SDL::CDClose($$self);
57}
58
15a6855a 59sub cd_num_drives {
8fde61e3 60 return SDL::CDNumDrives();
61}
62
63sub name ($) {
64 my $self = shift;
65 return SDL::CDName($$self);
66}
67
68sub status ($) {
69 my $self = shift;
70 return SDL::CDstatus($$self);
71}
72
73sub play ($$$;$$) {
74 my ($self,$start,$length,$fs,$fl) = @_;
75 return SDL::CDPlayTracks($$self,$start,$length,$fs,$fl);
76}
77
78sub pause ($) {
79 my $self = shift;
80 return SDL::CDPause($$self);
81}
82
83sub resume ($) {
84 my $self = shift;
85 return SDL::CDResume($$self);
86}
87
88sub stop ($) {
89 my $self = shift;
90 return SDL::CDStop($$self);
91}
92
93sub eject ($) {
94 my $self = shift;
95 return SDL::CDEject($$self);
96}
97
98sub id ($) {
99 my $self = shift;
100 return SDL::CDId($$self);
101}
102
103sub num_tracks ($) {
104 my $self = shift;
105 return SDL::CDNumTracks($$self);
106}
107
108my $buildtrack = sub {
109 my $ptr = shift;
110 my %track = ();
111 $track{-id} = SDL::CDTrackId($ptr);
112 $track{-type} = SDL::CDTrackType($ptr);
113 $track{-length} = SDL::CDTrackLength($ptr);
114 $track{-offset} = SDL::CDTrackOffset($ptr);
115 return \%track;
116};
117
118sub track {
119 my $self = shift;
120 my $number = shift;
121 return &$buildtrack(SDL::CDTrack($$self,$number));
122}
123
124sub current {
125 my $self = shift;
126 return $self->track(SDL::CDCurTrack($$self));
127}
128
129sub current_frame {
130 my $self = shift;
131 return SDL::CDCurFrame($$self);
132}
133
1341;
135
136__END__;
137
138=pod
139
140
141
142=head1 NAME
143
144SDL::Cdrom - a SDL perl extension for managing CD-ROM drives
145
146=head1 SYNOPSIS
147
148 use SDL::Cdrom;
149 $cdrom = SDL::Cdrom->new(0);
150 $cdrom->play();
151
152=head1 EXPORTS
153
154=over 4
155
156=item *
157
15a6855a 158C<cd_num_drives>.
8fde61e3 159
160=back
161
162=head1 DESCRIPTION
163
164Create a new SDL::Cdrom object. The passed $id is the number of the drive,
165whereas 0 is the first drive etc.
166
167 use SDL::Cdrom;
168 my $drive => SDL::Cdrom->new($id);
169
170=head1 METHODS
171
15a6855a 172=head2 cd_num_drives()
8fde61e3 173
174Returns the number of CD-ROM drives present.
175
176=head2 name()
177
178Returns the system dependent name of the CD-ROM device.
179
180=head2 status()
181
182Return the status of the drive.
183
184=head2 play()
185
186Play a track.
187
188=head2 pause()
189
190Pause the playing.
191
192=head2 resume()
193
194Resume the playing.
195
196=head2 stop()
197
198Stop the playing.
199
200=head2 eject()
201
202Eject the medium in the drive.
203
204=head2 id()
205
206Return the ID of the drive.
207
208=head2 num_tracks()
209
210Return the number of tracks on the medium.
211
212=head2 track()
213
214Returns the track description
215
216=head2 current()
217
218Return the current played track number.
219
220=head2 current_frame()
221
222Return the current frame.
223
224=head1 AUTHORS
225
226David J. Goehrig
227Documentation by Tels <http://bloodgate.com/>.
228
229=head1 SEE ALSO
230
231L<perl> L<SDL::Mixer> L<SDL::App>.
232
233=cut