Applied Magnet's Patch
[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;