Applied Magnet's Patch
[sdlgit/SDL_perl.git] / lib / SDL / Cdrom.pm
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
31 package SDL::Cdrom;
32 use strict;
33 use warnings;
34 use Carp;
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);
49         croak SDL::GetError() if ( SDL::CD_ERROR() eq SDL::CDStatus($$self));
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;