From: Leon Brocard Date: Fri, 6 Nov 2009 13:51:49 +0000 (+0000) Subject: Implement MixMusic X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=47cda863937d64cfd77fe1bd9eef4b9bc060a4ea;p=sdlgit%2FSDL_perl.git Implement MixMusic --- diff --git a/Build.PL b/Build.PL index 38bd454..0fc45b1 100644 --- a/Build.PL +++ b/Build.PL @@ -180,7 +180,14 @@ my %subsystems = from => 'src/Core/objects/MixChunk.xs', to => 'lib/SDL/MixChunk.xs', }, - libraries => [qw( SDL )], + libraries => [qw( SDL SDL_mixer )], + }, + MixMusic => { + file => { + from => 'src/Core/objects/MixMusic.xs', + to => 'lib/SDL/MixMusic.xs', + }, + libraries => [qw( SDL SDL_mixer )], }, Palette => { file => { diff --git a/lib/SDL/MixMusic.pm b/lib/SDL/MixMusic.pm new file mode 100644 index 0000000..1db704d --- /dev/null +++ b/lib/SDL/MixMusic.pm @@ -0,0 +1,9 @@ +package SDL::MixMusic; +use strict; +use warnings; +require Exporter; +require DynaLoader; +our @ISA = qw(Exporter DynaLoader); +bootstrap SDL::MixMusic; + +1; diff --git a/src/Core/objects/MixMusic.xs b/src/Core/objects/MixMusic.xs new file mode 100644 index 0000000..5b289aa --- /dev/null +++ b/src/Core/objects/MixMusic.xs @@ -0,0 +1,26 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#ifndef aTHX_ +#define aTHX_ +#endif + +#include +#include + +MODULE = SDL::MixMusic PACKAGE = SDL::MixMusic PREFIX = mixmusic_ + +=for documentation + +SDL_mixmusic - This is an opaque data type used for Music data + + typedef struct _Mix_Music Mix_Music; + +=cut + +void +mixmusic_DESTROY(mixmusic) + Mix_Chunk *mixmusic + CODE: + Mix_FreeMusic(mixmusic); diff --git a/src/SDL.xs b/src/SDL.xs index 69ad5f7..9b91a17 100644 --- a/src/SDL.xs +++ b/src/SDL.xs @@ -1202,10 +1202,17 @@ MixLoadWAV ( filename ) RETVAL Mix_Music * -MixLoadMusic ( filename ) +MixLoadMUS ( filename ) char *filename + PREINIT: + char * CLASS = "SDL::MixMusic"; CODE: - RETVAL = Mix_LoadMUS(filename); + Mix_Music * mixmusic; + mixmusic = Mix_LoadMUS(filename); + if (mixmusic == NULL) { + fprintf(stderr, "Could not load %s\n", filename); + } + RETVAL = mixmusic; OUTPUT: RETVAL diff --git a/t/core_mixmusic.t b/t/core_mixmusic.t new file mode 100644 index 0000000..795b6a5 --- /dev/null +++ b/t/core_mixmusic.t @@ -0,0 +1,28 @@ +#!perl +use strict; +use warnings; +use SDL; +use SDL::MixMusic; +use Test::More tests => 4; + +is( SDL::init(SDL_INIT_AUDIO), 0, '[init] returns 0 on success' ); + +is( SDL::MixOpenAudio( 44100, SDL::Constants::AUDIO_S16, 2, 4096 ), + 0, 'MixOpenAudio passed' ); + +my $mix_music = SDL::MixLoadMUS('test/data/sample.wav'); + +{ + local $TODO = 1; + + # I'm not sure why this fails + isa_ok( $mix_music, 'SDL::MixMusic' ); +}; + +SDL::MixPlayMusic( $mix_music, 0 ); + +# we close straight away so no audio is actually played + +SDL::MixCloseAudio; + +ok( 1, 'Got to the end' ); diff --git a/typemap b/typemap index 38d3f28..7eedfbf 100644 --- a/typemap +++ b/typemap @@ -45,7 +45,7 @@ SDL_AudioSpec * T_PTR SDL_AudioCVT * T_PTR Mix_Fading T_UV Mix_Chunk * O_OBJECT -Mix_Music * T_PTR +Mix_Music * O_OBJECT SDL_GLattr T_IV int * T_PTR void * T_PTR