Commit | Line | Data |
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 | |
31 | package SDL::Cdrom; |
32 | use strict; |
084b921f |
33 | use warnings; |
34 | use Carp; |
8fde61e3 |
35 | |
36 | BEGIN { |
37 | use Exporter(); |
38 | use vars qw(@ISA @EXPORT); |
39 | @ISA = qw(Exporter); |
40 | @EXPORT = qw/ &CD_NUM_DRIVES /; |
41 | } |
42 | |
43 | sub 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 | |
54 | sub DESTROY { |
55 | my $self = shift; |
56 | SDL::CDClose($$self); |
57 | } |
58 | |
59 | sub CD_NUM_DRIVES { |
60 | return SDL::CDNumDrives(); |
61 | } |
62 | |
63 | sub name ($) { |
64 | my $self = shift; |
65 | return SDL::CDName($$self); |
66 | } |
67 | |
68 | sub status ($) { |
69 | my $self = shift; |
70 | return SDL::CDstatus($$self); |
71 | } |
72 | |
73 | sub play ($$$;$$) { |
74 | my ($self,$start,$length,$fs,$fl) = @_; |
75 | return SDL::CDPlayTracks($$self,$start,$length,$fs,$fl); |
76 | } |
77 | |
78 | sub pause ($) { |
79 | my $self = shift; |
80 | return SDL::CDPause($$self); |
81 | } |
82 | |
83 | sub resume ($) { |
84 | my $self = shift; |
85 | return SDL::CDResume($$self); |
86 | } |
87 | |
88 | sub stop ($) { |
89 | my $self = shift; |
90 | return SDL::CDStop($$self); |
91 | } |
92 | |
93 | sub eject ($) { |
94 | my $self = shift; |
95 | return SDL::CDEject($$self); |
96 | } |
97 | |
98 | sub id ($) { |
99 | my $self = shift; |
100 | return SDL::CDId($$self); |
101 | } |
102 | |
103 | sub num_tracks ($) { |
104 | my $self = shift; |
105 | return SDL::CDNumTracks($$self); |
106 | } |
107 | |
108 | my $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 | |
118 | sub track { |
119 | my $self = shift; |
120 | my $number = shift; |
121 | return &$buildtrack(SDL::CDTrack($$self,$number)); |
122 | } |
123 | |
124 | sub current { |
125 | my $self = shift; |
126 | return $self->track(SDL::CDCurTrack($$self)); |
127 | } |
128 | |
129 | sub current_frame { |
130 | my $self = shift; |
131 | return SDL::CDCurFrame($$self); |
132 | } |
133 | |
134 | 1; |
135 | |
136 | __END__; |
137 | |
138 | =pod |
139 | |
140 | |
141 | |
142 | =head1 NAME |
143 | |
144 | SDL::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 | |
158 | C<CD_NUM_DRIVES>. |
159 | |
160 | =back |
161 | |
162 | =head1 DESCRIPTION |
163 | |
164 | Create a new SDL::Cdrom object. The passed $id is the number of the drive, |
165 | whereas 0 is the first drive etc. |
166 | |
167 | use SDL::Cdrom; |
168 | my $drive => SDL::Cdrom->new($id); |
169 | |
170 | =head1 METHODS |
171 | |
172 | =head2 CD_NUM_DRIVES() |
173 | |
174 | Returns the number of CD-ROM drives present. |
175 | |
176 | =head2 name() |
177 | |
178 | Returns the system dependent name of the CD-ROM device. |
179 | |
180 | =head2 status() |
181 | |
182 | Return the status of the drive. |
183 | |
184 | =head2 play() |
185 | |
186 | Play a track. |
187 | |
188 | =head2 pause() |
189 | |
190 | Pause the playing. |
191 | |
192 | =head2 resume() |
193 | |
194 | Resume the playing. |
195 | |
196 | =head2 stop() |
197 | |
198 | Stop the playing. |
199 | |
200 | =head2 eject() |
201 | |
202 | Eject the medium in the drive. |
203 | |
204 | =head2 id() |
205 | |
206 | Return the ID of the drive. |
207 | |
208 | =head2 num_tracks() |
209 | |
210 | Return the number of tracks on the medium. |
211 | |
212 | =head2 track() |
213 | |
214 | Returns the track description |
215 | |
216 | =head2 current() |
217 | |
218 | Return the current played track number. |
219 | |
220 | =head2 current_frame() |
221 | |
222 | Return the current frame. |
223 | |
224 | =head1 AUTHORS |
225 | |
226 | David J. Goehrig |
227 | Documentation by Tels <http://bloodgate.com/>. |
228 | |
229 | =head1 SEE ALSO |
230 | |
231 | L<perl> L<SDL::Mixer> L<SDL::App>. |
232 | |
233 | =cut |