Implement MixMusic
Leon Brocard [Fri, 6 Nov 2009 13:51:49 +0000 (13:51 +0000)]
Build.PL
lib/SDL/MixMusic.pm [new file with mode: 0644]
src/Core/objects/MixMusic.xs [new file with mode: 0644]
src/SDL.xs
t/core_mixmusic.t [new file with mode: 0644]
typemap

index 38bd454..0fc45b1 100644 (file)
--- 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 (file)
index 0000000..1db704d
--- /dev/null
@@ -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 (file)
index 0000000..5b289aa
--- /dev/null
@@ -0,0 +1,26 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#ifndef aTHX_
+#define aTHX_
+#endif
+
+#include <SDL.h>
+#include <SDL_mixer.h>
+
+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);
index 69ad5f7..9b91a17 100644 (file)
@@ -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 (file)
index 0000000..795b6a5
--- /dev/null
@@ -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 (file)
--- 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