first commit in a series to change property functions into D style

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1454 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-03-13 01:56:39 +00:00
parent 809b09292f
commit 1c72b919e7
5 changed files with 443 additions and 460 deletions

View file

@ -1,28 +1,28 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.soundbuffer;
@ -32,20 +32,20 @@ import dsfml.system.stringutil;
/**
* SoundBuffer is the low-level for loading and manipulating
* sound buffers
*/
* SoundBuffer is the low-level for loading and manipulating
* sound buffers
*/
class SoundBuffer : DSFMLObject
{
/**
* Load the sound buffer from a file
*
* Params:
* filename = Path of the sound file to load
*
* Throws:
* LoadingException on failure
*/
* Load the sound buffer from a file
*
* Params:
* filename = Path of the sound file to load
*
* Throws:
* LoadingException on failure
*/
this(string filename)
{
if (filename is null || filename.length == 0)
@ -55,14 +55,14 @@ class SoundBuffer : DSFMLObject
}
/**
* Load the sound buffer from a file in memory
*
* Params:
* data = Array of file data in memory
*
* Throws:
* LoadingException on failure
*/
* Load the sound buffer from a file in memory
*
* Params:
* data = Array of file data in memory
*
* Throws:
* LoadingException on failure
*/
this(byte[] data)
{
if (data is null || data.length == 0)
@ -72,18 +72,18 @@ class SoundBuffer : DSFMLObject
}
/**
* Load the sound buffer from an array of samples - assumed format for
* samples is 16 bits signed integer
*
* Params:
* samples = Array of samples in memory
* channelsCount = Number of channels (1 = mono, 2 = stereo, ...)
* sampleRate = Frequency (number of samples to play per second)
*
* Throws:
* LoadingException on failure
*/
this(short[] samples, uint channelsCount, uint sampleRate)
* Load the sound buffer from an array of samples - assumed format for
* samples is 16 bits signed integer
*
* Params:
* samples = Array of samples in memory
* channelsCount = Number of channels (1 = mono, 2 = stereo, ...)
* sampleRate = Frequency (number of samples to play per second)
*
* Throws:
* LoadingException on failure
*/
this(const(short)[] samples, uint channelsCount, uint sampleRate)
{
if (samples is null || samples.length == 0)
throw new Exception("LoadingException : Samples array is invalid.");
@ -99,14 +99,14 @@ class SoundBuffer : DSFMLObject
/**
* Save the sound buffer to a file
*
* Params:
* filename = Path of the sound file to write
*
* Returns:
* True if saving has been successful
*/
* Save the sound buffer to a file
*
* Params:
* filename = Path of the sound file to write
*
* Returns:
* True if saving has been successful
*/
bool saveToFile(string filename)
{
if (filename !is null && filename.length > 0 )
@ -116,63 +116,66 @@ class SoundBuffer : DSFMLObject
return false;
}
@property
{
/**
* Return the sound samples
*
* Returns:
* Array of sound samples, in 16 bits signed integer format
*/
short[] getSamples()
* Return the sound samples
*
* Returns:
* Array of sound samples, in 16 bits signed integer format
*/
short[] samples()
{
short* temp = null;
temp = sfSoundBuffer_GetSamples(m_ptr);
return temp is null ? null : temp[0..getSamplesCount];
return temp is null ? null : temp[0..samplesCount()];
}
/**
* Return the samples count
*
* Returns:
* Number of samples
*/
size_t getSamplesCount()
* Return the samples count
*
* Returns:
* Number of samples
*/
size_t samplesCount()
{
return sfSoundBuffer_GetSamplesCount(m_ptr);
}
/**
* Get the sample rate
*
* Returns:
* Sound frequency (number of samples per second)
*/
uint getSampleRate()
* Get the sample rate
*
* Returns:
* Sound frequency (number of samples per second)
*/
uint sampleRate()
{
return sfSoundBuffer_GetSampleRate(m_ptr);
}
/**
* Return the number of channels (1 = mono, 2 = stereo, ...)
*
* Returns:
* Number of channels
*/
uint getChannelsCount()
* Return the number of channels (1 = mono, 2 = stereo, ...)
*
* Returns:
* Number of channels
*/
uint channelsCount()
{
return sfSoundBuffer_GetChannelsCount(m_ptr);
}
/**
* Get the sound duration
*
* Returns:
* Sound duration, in seconds
*/
float getDuration()
* Get the sound duration
*
* Returns:
* Sound duration, in seconds
*/
float duration()
{
return sfSoundBuffer_GetDuration(m_ptr);
}
}
package:
this(void* ptr)
@ -181,50 +184,22 @@ package:
}
private:
// External ====================================================================
extern (C)
static extern(C)
{
typedef void* function(cchar*) pf_sfSoundBuffer_CreateFromFile;
typedef void* function(byte*, size_t) pf_sfSoundBuffer_CreateFromMemory;
typedef void* function(short*, size_t, uint, uint) pf_sfSoundBuffer_CreateFromSamples;
typedef void function(void*) pf_sfSoundBuffer_Destroy;
typedef int function(void*, cchar*) pf_sfSoundBuffer_SaveToFile;
typedef short* function(void*) pf_sfSoundBuffer_GetSamples;
typedef size_t function(void*) pf_sfSoundBuffer_GetSamplesCount;
typedef uint function(void*) pf_sfSoundBuffer_GetSampleRate;
typedef uint function(void*) pf_sfSoundBuffer_GetChannelsCount;
typedef float function(void*) pf_sfSoundBuffer_GetDuration;
static pf_sfSoundBuffer_CreateFromFile sfSoundBuffer_CreateFromFile;
static pf_sfSoundBuffer_CreateFromMemory sfSoundBuffer_CreateFromMemory;
static pf_sfSoundBuffer_CreateFromSamples sfSoundBuffer_CreateFromSamples;
static pf_sfSoundBuffer_Destroy sfSoundBuffer_Destroy;
static pf_sfSoundBuffer_SaveToFile sfSoundBuffer_SaveToFile;
static pf_sfSoundBuffer_GetSamples sfSoundBuffer_GetSamples;
static pf_sfSoundBuffer_GetSamplesCount sfSoundBuffer_GetSamplesCount;
static pf_sfSoundBuffer_GetSampleRate sfSoundBuffer_GetSampleRate;
static pf_sfSoundBuffer_GetChannelsCount sfSoundBuffer_GetChannelsCount;
static pf_sfSoundBuffer_GetDuration sfSoundBuffer_GetDuration;
void* function(cchar*) sfSoundBuffer_CreateFromFile;
void* function(const(byte)*, size_t) sfSoundBuffer_CreateFromMemory;
void* function(const(short)*, size_t, uint, uint) sfSoundBuffer_CreateFromSamples;
void function(void*) sfSoundBuffer_Destroy;
int function(void*, cchar*) sfSoundBuffer_SaveToFile;
short* function(void*) sfSoundBuffer_GetSamples;
size_t function(void*) sfSoundBuffer_GetSamplesCount;
uint function(void*) sfSoundBuffer_GetSampleRate;
uint function(void*) sfSoundBuffer_GetChannelsCount;
float function(void*) sfSoundBuffer_GetDuration;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-audio-d");
else
DllLoader dll = DllLoader.load("csfml-audio");
sfSoundBuffer_CreateFromFile = cast(pf_sfSoundBuffer_CreateFromFile)dll.getSymbol("sfSoundBuffer_CreateFromFile");
sfSoundBuffer_CreateFromMemory = cast(pf_sfSoundBuffer_CreateFromMemory)dll.getSymbol("sfSoundBuffer_CreateFromMemory");
sfSoundBuffer_CreateFromSamples = cast(pf_sfSoundBuffer_CreateFromSamples)dll.getSymbol("sfSoundBuffer_CreateFromSamples");
sfSoundBuffer_Destroy = cast(pf_sfSoundBuffer_Destroy)dll.getSymbol("sfSoundBuffer_Destroy");
sfSoundBuffer_SaveToFile = cast(pf_sfSoundBuffer_SaveToFile)dll.getSymbol("sfSoundBuffer_SaveToFile");
sfSoundBuffer_GetSamples = cast(pf_sfSoundBuffer_GetSamples)dll.getSymbol("sfSoundBuffer_GetSamples");
sfSoundBuffer_GetSamplesCount = cast(pf_sfSoundBuffer_GetSamplesCount)dll.getSymbol("sfSoundBuffer_GetSamplesCount");
sfSoundBuffer_GetSampleRate = cast(pf_sfSoundBuffer_GetSampleRate)dll.getSymbol("sfSoundBuffer_GetSampleRate");
sfSoundBuffer_GetChannelsCount = cast(pf_sfSoundBuffer_GetChannelsCount)dll.getSymbol("sfSoundBuffer_GetChannelsCount");
sfSoundBuffer_GetDuration = cast(pf_sfSoundBuffer_GetDuration)dll.getSymbol("sfSoundBuffer_GetDuration");
}
}
mixin(loadFromSharedLib2("csfml-audio", "sfSoundBuffer",
"CreateFromFile", "CreateFromMemory", "CreateFromSamples", "Destroy", "SaveToFile", "GetSamples", "GetSamplesCount",
"GetSampleRate", "GetChannelsCount", "GetDuration"));
}