Fixed tests. Now installable
[sdlgit/SDL_perl.git] / lib / SDL / Mixer.pm
CommitLineData
8fde61e3 1# Mixer.pm
2#
3# a SDL module for manipulating the SDL_mixer lib.
4#
5# Copyright (C) 2000,2002 David J. Goehrig
6
7package SDL::Mixer;
8use strict;
9use SDL;
10use SDL::Sound;
11use SDL::Music;
12
13BEGIN {
14}
15
16$SDL::Mixer::initialized = 0;
17
18sub new {
19 my $proto = shift;
20 my $class = ref($proto) || $proto;
21 my $self = {};
22 my %options = @_;
23 my $frequency = $options{-frequency} || $options{-rate} || SDL::MIX_DEFAULT_FREQUENCY();
24 my $format = $options{-format} || SDL::MIX_DEFAULT_FORMAT();
25 my $channels = $options{-channels} || SDL::MIX_DEFAULT_CHANNELS();
26 my $size = $options{-size} || 4096;
27 unless ( $SDL::Mixer::initialized ) {
28 SDL::MixOpenAudio($frequency,$format,$channels,$size ) &&
29 die SDL::GetError();
30 $SDL::Mixer::initialized = 1;
31 } else {
32 ++$SDL::Mixer::initialized;
33 }
34 bless $self,$class;
35 return $self;
36}
37
38sub DESTROY {
39 my $self = shift;
40 --$SDL::Mixer::initialized;
41 unless ($SDL::Mixer::initialized) {
42 SDL::MixCloseAudio();
43 }
44}
45
46
47sub query_spec () {
48 my ($status,$freq,$format,$channels) = SDL::MixQuerySpec();
49 my %hash = ( -status => $status, -frequency => $freq,
50 -format => $format, -channels => $channels );
51 return \%hash;
52}
53
54sub reserve_channels ($$) {
55 my ($self,$channels) = @_;
56 return SDL::MixReserveChannels($channels);
57}
58
59sub allocate_channels ($$) {
60 my ($self,$channels) = @_;
61 return SDL::MixAllocateChannels($channels);
62}
63
64sub group_channel ($$$) {
65 my ($self,$channel,$group) = @_;
66 return SDL::MixGroupChannel($channel, $group);
67}
68
69sub group_channels ($$$$) {
70 my ($self,$from,$to,$group) = @_;
71 return SDL::MixGroupChannels($from,$to,$group);
72}
73
74sub group_available ($$) {
75 my ($self,$group) = @_;
76 return SDL::MixGroupAvailable($group);
77}
78
79sub group_count ($$) {
80 my ($self,$group) = @_;
81 return SDL::MixGroupCount($group);
82}
83
84sub group_oldest ($$) {
85 my ($self,$group) = @_;
86 return SDL::MixGroupOldest($group);
87}
88
89sub group_newer ($$) {
90 my ($self,$group) = @_;
91 return SDL::MixGroupNewer($group);
92}
93
94sub play_channel ($$$$;$) {
95 my ($self,$channel,$chunk,$loops,$ticks) = @_;
96 $ticks ||= -1;
97 return SDL::MixPlayChannelTimed($channel,$$chunk,$loops,$ticks);
98}
99
100sub play_music ($$$) {
101 my ($self,$music,$loops) = @_;
102 return SDL::MixPlayMusic($$music,$loops);
103}
104
105sub fade_in_channel ($$$$$;$) {
106 my ($self,$channel,$chunk,$loops,$ms,$ticks) = @_;
107 $ticks ||= -1;
108 return SDL::MixFadeInChannelTimed($channel,$$chunk,$loops,$ms,$ticks);
109}
110
111sub fade_in_music ($$$$) {
112 my ($self,$music,$loops,$ms) = @_;
113 return SDL::MixFadeInMusic($$music,$loops,$ms);
114}
115
116sub channel_volume ($$$) {
117 my ($self,$channel,$volume) = @_;
118 return SDL::MixVolume($channel,$volume);
119}
120
121sub music_volume ($$) {
122 my ($self,$volume) = @_;
123 return SDL::MixVolumeMusic($volume);
124}
125
126sub halt_channel ($$) {
127 my ($self,$channel) = @_;
128 return SDL::MixHaltChannel($channel);
129}
130
131sub halt_group ($$) {
132 my ($self,$group) = @_;
133 return SDL::MixHaltGroup($group);
134}
135
136sub halt_music (){
137 return SDL::MixHaltMusic();
138}
139
140sub channel_expire ($$$) {
141 my ($self,$channel,$ticks) = @_;
142 return SDL::MixExpireChannel($channel,$ticks);
143}
144
145sub fade_out_channel ($$$) {
146 my ($self,$channel,$ms) = @_;
147 return SDL::MixFadeOutChannel($channel,$ms);
148}
149
150sub fade_out_group ($$$) {
151 my ($self,$group,$ms) = @_;
152 return SDL::MixFadeOutGroup($group,$ms);
153}
154
155sub fade_out_music ($$) {
156 my ($self,$ms) = @_;
157 return SDL::MixFadeOutMusic($ms);
158}
159
160sub fading_music () {
161 return SDL::MixFadingMusic();
162}
163
164sub fading_channel ($$) {
165 my ($self,$channel) = @_;
166 return SDL::MixFadingChannel($channel);
167}
168
169sub pause ($$) {
170 my ($self,$channel) = @_;
171 SDL::MixPause($channel);
172}
173
174sub resume ($$) {
175 my ($self,$channel) = @_;
176 SDL::MixResume($channel);
177}
178
179sub paused ($$) {
180 my ($self,$channel) = @_;
181 return SDL::MixPaused($channel);
182}
183
184sub pause_music () {
185 SDL::MixPauseMusic();
186}
187
188sub resume_music () {
189 SDL::MixResumeMusic();
190}
191
192sub rewind_music (){
193 SDL::MixRewindMusic();
194}
195
196sub music_paused (){
197 return SDL::MixPausedMusic();
198}
199
200sub playing ($$) {
201 my ($self,$channel) = @_;
202 return SDL::MixPlaying($channel);
203}
204
205sub playing_music () {
206 return SDL::MixPlayingMusic();
207}
208
2091;
210
211__END__;
212
213=pod
214
215=head1 NAME
216
217SDL::Mixer - a SDL perl extension
218
219=head1 SYNOPSIS
220
221 $mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY,
222 -format => MIX_DEFAULT_FORMAT,
223 -channels => MIX_DEFAULT_CHANNELS,
224 -size => 4096;
225
226=head1 DESCRIPTION
227
228SDL::Mixer allows you access to the SDL mixer library, enablig sound and
229music volume setting, playing, pausing and resuming, as well as fading
230the sound and music in and out.
231
232=head1 METHODS
233
234=head2 new()
235
236 $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY,
237 -format => MIX_DEFAULT_FORMAT,
238 -channels => MIX_DEFAULT_CHANNELS,
239 -size => 4096);
240
241Creates a new SDL::Mixer object. C<$size> is the buffer size in bytes.
242
243=head2 query_spec()
244
245 my $specs = SDL::Mixer::query_spec();
246
247Returns a hash reference, containing the following keys and their respective
248values:
249
250 -status
251 -frequency
252 -channels
253 -format
254
255=head2 reserve_channels
256
257 $mixer->reserve_channels(4);
258
259Reserve so many channels.
260
261=head2 allocate_channels()
262
263 $mixer->reserve_channels(2);
264
265Allocate so many channels.
266
267=head2 group_channel(channel,group)
268
269Group the channel number C<$channel> into group C<$group>.
270
271=head2 group_channels(from,to,group)
272
273Groups a range of channels
274
275=head2 group_available(group)
276
277Return true when the group is available.
278
279=head2 group_count(group)
280
281Returns the number of channels in the group
282
283=head2 group_oldest()
284
285
286=head2 group_newer()
287
288
289=head2 play_channel()
290
291
292=head2 play_music()
293
294Play C<$music> C<$loop> times.
295
296=head2 fade_in_channel(channel,chunk,loops,ms,ticks)
297
298Fades a channel in
299
300=head2 fade_in_music(music,loops,ms)
301
302Fades the music in over a number of ms, looping as it does
303
304=head2 channel_volume(channel,volume)
305
306Sets the volume for a single channel
307
308=head2 mucis_volume(volume)
309
310Set the volume for the music.
311
312=head2 halt_channel(channel)
313
314Stops a specific channel
315
316=head2 halt_group(group)
317
318Stops a group of channels
319
320=head2 halt_music()
321
322Stops the music
323
324=head2 channel_expire(channel,ticks)
325
326Ignores the channel after C<ticks> has expired
327
328=head2 fade_out_channel(channel,ms)
329
330Fade the channel number C<$channel> in C<$ms> ms out.
331
332=head2 fade_out_group(group,ms)
333
334Fade the channel group C<$group> in C<$ms> ms out.
335
336=head2 fade_out_music(ms)
337
338Fade the music in C<$ms> ms out.
339
340=head2 fading_music()
341
342Return true when the music is currently fading in or out.
343
344=head2 fading_channel()
345
346Return true when the channel number C<$channel> is currently fading in or out.
347
348=head2 pause( channel )
349
350Pause the channel C<$channel>.
351
352=head2 resume(channel)
353
354Resume the channel C<$channel>.
355
356=head2 paused()
357
358Return true when the channel is currently paused.
359
360=head2 pause_music()
361
362Pause the music play.
363
364=head2 resume_music()
365
366Resume the music play.
367
368=head2 rewind_music()
369
370Resets the music file to the beginning
371
372=head2 music_paused()
373
374Return true when the music is currently paused.
375
376=head2 playing()
377
378Return true when the channel is currently playing.
379
380=head2 playing_music ()
381
382Return true when the music is currently playing.
383
384=head1 AUTHORS
385
386David J. Goehrig, basic doc added by Tels <http://bloodgate.com>.
387
388=head1 SEE ALSO
389
390L<perl>, L<SDL::Music> and L<SDL::Sound>.
391
392=cut