Music.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00026 // Headers
00028 #include <SFML/Audio/Music.h>
00029 #include <SFML/Audio/Music.hpp>
00030 #include <SFML/Internal.h>
00031 
00032 
00033 struct sfMusic
00034 {
00035     sf::Music This;
00036 };
00037 
00038 
00042 sfMusic* sfMusic_CreateFromFile(const char* Filename)
00043 {
00044     sfMusic* Music = new sfMusic;
00045 
00046     if (!Music->This.Open(Filename))
00047     {
00048         delete Music;
00049         Music = NULL;
00050     }
00051 
00052     return Music;
00053 }
00054 
00055 
00059 sfMusic* sfMusic_CreateFromMemory(const char* Data, size_t SizeInBytes)
00060 {
00061     sfMusic* Music = new sfMusic;
00062 
00063     if (!Music->This.OpenFromMemory(Data, SizeInBytes))
00064     {
00065         delete Music;
00066         Music = NULL;
00067     }
00068 
00069     return Music;
00070 }
00071 
00072 
00076 void sfMusic_Destroy(sfMusic* Music)
00077 {
00078     delete Music;
00079 }
00080 
00081 
00085 void sfMusic_SetLoop(sfMusic* Music, sfBool Loop)
00086 {
00087     CSFML_CALL(Music, SetLoop(Loop != 0));
00088 }
00089 
00090 
00094 sfBool sfMusic_GetLoop(sfMusic* Music)
00095 {
00096     CSFML_CALL_RETURN(Music, GetLoop(), sfFalse);
00097 }
00098 
00099 
00103 float sfMusic_GetDuration(sfMusic* Music)
00104 {
00105     CSFML_CALL_RETURN(Music, GetDuration(), 0.f);
00106 }
00107 
00108 
00112 void sfMusic_Play(sfMusic* Music)
00113 {
00114     CSFML_CALL(Music, Play());
00115 }
00116 
00117 
00121 void sfMusic_Pause(sfMusic* Music)
00122 {
00123     CSFML_CALL(Music, Pause());
00124 }
00125 
00126 
00130 void sfMusic_Stop(sfMusic* Music)
00131 {
00132     CSFML_CALL(Music, Stop());
00133 }
00134 
00135 
00139 unsigned int sfMusic_GetChannelsCount(sfMusic* Music)
00140 {
00141     CSFML_CALL_RETURN(Music, GetChannelsCount(), 0);
00142 }
00143 
00144 
00148 unsigned int sfMusic_GetSampleRate(sfMusic* Music)
00149 {
00150     CSFML_CALL_RETURN(Music, GetSampleRate(), 0);
00151 }
00152 
00153 
00157 sfSoundStatus sfMusic_GetStatus(sfMusic* Music)
00158 {
00159     CSFML_CHECK_RETURN(Music, sfStopped);
00160 
00161     return static_cast<sfSoundStatus>(Music->This.GetStatus());
00162 }
00163 
00164 
00168 void sfMusic_SetPitch(sfMusic* Music, float Pitch)
00169 {
00170     CSFML_CALL(Music, SetPitch(Pitch));
00171 }
00172 
00173 
00177 void sfMusic_SetVolume(sfMusic* Music, float Volume)
00178 {
00179     CSFML_CALL(Music, SetVolume(Volume));
00180 }
00181 
00182 
00186 void sfMusic_SetPosition(sfMusic* Music, float X, float Y, float Z)
00187 {
00188     CSFML_CALL(Music, SetPosition(X, Y, Z));
00189 }
00190 
00191 
00195 float sfMusic_GetPitch(sfMusic* Music)
00196 {
00197     CSFML_CALL_RETURN(Music, GetPitch(), 0.f);
00198 }
00199 
00200 
00204 float sfMusic_GetVolume(sfMusic* Music)
00205 {
00206     CSFML_CALL_RETURN(Music, GetVolume(), 0.f);
00207 }
00208 
00209 
00213 void sfMusic_GetPosition(sfMusic* Music, float* X, float* Y, float* Z)
00214 {
00215     if (X && Y && Z)
00216         CSFML_CALL(Music, GetPosition(*X, *Y, *Z));
00217 }