summaryrefslogtreecommitdiff
path: root/src/resources/music.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-01-24 22:59:25 +0300
committerAndrei Karas <akaras@inbox.ru>2012-01-24 22:59:25 +0300
commit53535919d3cf62f97bc9fee28ee31e4f577d2700 (patch)
tree98b8bc6b8da941b5d2c72c598756374623ad850a /src/resources/music.cpp
parentb4e47fb41a19ca09c02bcd009b28cb7c3caa2256 (diff)
downloadManaVerse-53535919d3cf62f97bc9fee28ee31e4f577d2700.tar.gz
ManaVerse-53535919d3cf62f97bc9fee28ee31e4f577d2700.tar.bz2
ManaVerse-53535919d3cf62f97bc9fee28ee31e4f577d2700.tar.xz
ManaVerse-53535919d3cf62f97bc9fee28ee31e4f577d2700.zip
Based on commit b856e8b47ab2dfd393e3c2720c5647eb66393931
Author: Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> Date: Tue Jan 24 19:14:24 2012 +0100 Stream music files directly from the archives Use Mix_LoadMUS_RW to stream music files directly from PhysFS. I kept around ResourceManager:copyFile for now, since it may have other uses.
Diffstat (limited to 'src/resources/music.cpp')
-rw-r--r--src/resources/music.cpp46
1 files changed, 10 insertions, 36 deletions
diff --git a/src/resources/music.cpp b/src/resources/music.cpp
index 7bdd51d36..b13812f18 100644
--- a/src/resources/music.cpp
+++ b/src/resources/music.cpp
@@ -26,27 +26,21 @@
#include "debug.h"
-Music::Music(Mix_Chunk *music):
- mChunk(music),
- mChannel(-1)
+Music::Music(Mix_Music *music) :
+ mMusic(music)
{
}
Music::~Music()
{
- //Mix_FreeMusic(music);
- Mix_FreeChunk(mChunk);
+ Mix_FreeMusic(mMusic);
}
Resource *Music::load(SDL_RWops *rw)
{
- // Use Mix_LoadMUS to load the raw music data
- //Mix_Music* music = Mix_LoadMUS_RW(rw); Need to be implemeted
- Mix_Chunk *tmpMusic = Mix_LoadWAV_RW(rw, 1);
-
- if (tmpMusic)
+ if (Mix_Music *music = Mix_LoadMUS_RW(rw))
{
- return new Music(tmpMusic);
+ return new Music(music);
}
else
{
@@ -55,30 +49,10 @@ Resource *Music::load(SDL_RWops *rw)
}
}
-bool Music::play(int loops)
+bool Music::play(int loops, int fadeIn)
{
- /*
- * Warning: loops should be always set to -1 (infinite) with current
- * implementation to avoid halting the playback of other samples
- */
-
- /*if (Mix_PlayMusic(music, loops))
- return true;*/
- Mix_VolumeChunk(mChunk, 120);
- mChannel = Mix_PlayChannel(-1, mChunk, loops);
-
- return mChannel != -1;
-}
-
-void Music::stop()
-{
- /*
- * Warning: very dungerous trick, it could try to stop channels occupied
- * by samples rather than the current music file
- */
-
- //Mix_HaltMusic();
-
- if (mChannel != -1)
- Mix_HaltChannel(mChannel);
+ if (fadeIn > 0)
+ return Mix_FadeInMusic(mMusic, loops, fadeIn);
+ else
+ return Mix_PlayMusic(mMusic, loops);
}