Skip to content
Browse files

Implement MixMusic

  • Loading branch information...
1 parent bfededf commit 47cda863937d64cfd77fe1bd9eef4b9bc060a4ea @acme acme committed Nov 6, 2009
Showing with 81 additions and 4 deletions.
  1. +8 −1 Build.PL
  2. +9 −0 lib/SDL/MixMusic.pm
  3. +26 −0 src/Core/objects/MixMusic.xs
  4. +9 −2 src/SDL.xs
  5. +28 −0 t/core_mixmusic.t
  6. +1 −1 typemap
View
9 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 => {
View
9 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;
View
26 src/Core/objects/MixMusic.xs
@@ -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);
View
11 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
View
28 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' );
View
2 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

0 comments on commit 47cda86

Please sign in to comment.
Something went wrong with that request. Please try again.