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