Skip to content

Commit

Permalink
added load_MUS_RW feature, docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FROGGS committed Dec 1, 2011
1 parent 7338e3b commit b001a91
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/pods/SDL/Mixer/Music.pod
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ Mixer


C<load_MUS> loads a music file into a C<SDL::Mixer::MixMusic> structure. This can be passed to L<play_music|SDL::Mixer::Music/"play_music">. C<load_MUS> loads a music file into a C<SDL::Mixer::MixMusic> structure. This can be passed to L<play_music|SDL::Mixer::Music/"play_music">.


=head2 load_MUS_RW

my $music = SDL::Mixer::Music::load_MUS_RW( $rwops );

C<load_MUS_RW> does the same like C<load_MUS> except that it accepts an L<SDL::RWOps>-object rather than a filename.

Example for loading music from a variable:

use SDL;
use SDL::Mixer;
use SDL::Mixer::Music;
use SDL::RWOps;

[...]

my $rwops = SDL::RWOps->new_const_mem( $scalar_holding_music );
my $music = SDL::Mixer::Music::load_MUS( $rwops );

<b>Noet:</b> You need at least libSDL_mixer 1.2.7 for this feature.

=head2 hook_music =head2 hook_music


SDL::Mixer::Music::hook_music( $callback, $position ); SDL::Mixer::Music::hook_music( $callback, $position );
Expand Down
29 changes: 29 additions & 0 deletions src/Mixer/Music.xs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,6 +123,35 @@ mixmus_load_MUS( filename )
OUTPUT: OUTPUT:
RETVAL RETVAL


#if VERSION_ATLEAST(SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL, 1, 2, 7)

Mix_Music *
mixmus_load_MUS_RW( rw )
SDL_RWops *rw
PREINIT:
char * CLASS = "SDL::Mixer::MixMusic";
CODE:
Mix_Music * mixmusic;
mixmusic = Mix_LoadMUS_RW(rw);
if (mixmusic == NULL)
fprintf(stderr, "Could not load SDL::RWOp object\n");
RETVAL = mixmusic;
OUTPUT:
RETVAL

#else

Mix_Music *
mixmus_load_MUS_RW( rw )
SDL_RWops *rw
CODE:
warn("SDL_mixer >= 1.2.7 needed for SDL::Mixer::Music::load_MUS_RW( rw )");
XSRETURN_UNDEF;
OUTPUT:
RETVAL

#endif

void void
mixmus_free_music( music ) mixmus_free_music( music )
Mix_Music *music Mix_Music *music
Expand Down
14 changes: 14 additions & 0 deletions t/mixer_music.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ BEGIN {
use SDL::Mixer; use SDL::Mixer;
use SDL::Mixer::Music; use SDL::Mixer::Music;
use SDL::Mixer::Samples; use SDL::Mixer::Samples;
use SDL::RWOps;
use SDL::Version; use SDL::Version;


my $v = SDL::Mixer::linked_version(); my $v = SDL::Mixer::linked_version();
Expand Down Expand Up @@ -108,6 +109,19 @@ is( SDL::Mixer::Music::play_music( $sample_music, 0 ),
0, "[play_music] plays $audio_test_file" 0, "[play_music] plays $audio_test_file"
); );


SKIP:
{
skip( 'Version 1.2.7 needed', 2 )
unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 7 );

my $rw = SDL::RWOps->new_file( $audio_test_file, "rb" );
my $sample_music_rw = SDL::Mixer::Music::load_MUS_RW( $rw );
isa_ok( $sample_music_rw, 'SDL::Mixer::MixMusic', '[load_MUS_RW]' );
is( SDL::Mixer::Music::play_music( $sample_music_rw, 0 ),
0, "[play_music_rw] plays $audio_test_file"
);
}

SKIP: SKIP:
{ {
skip( 'Version 1.2.9 needed', 2 ) skip( 'Version 1.2.9 needed', 2 )
Expand Down

0 comments on commit b001a91

Please sign in to comment.