Skip to content

Commit

Permalink
wrap OutputSoundFile
Browse files Browse the repository at this point in the history
Fix Glyph and Text for floating point extents
Correct some InputSoundFile method names
  • Loading branch information
aubade committed Apr 2, 2016
1 parent 5ead9a9 commit 412cb3a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.d
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void initialize()

//Setting up our aa with our lists of files because GDC crashes when searching for them at runtime
fileList["system"] = ["clock.d", "config.d", "err.d", "inputstream.d", "lock.d", "mutex.d", "package.d", "sleep.d", "string.d", "thread.d", "vector2.d", "vector3.d"];
fileList["audio"] = ["listener.d", "music.d", "package.d", "sound.d", "soundbuffer.d", "soundbufferrecorder.d", "inputsoundfile.d", "soundrecorder.d", "soundsource.d", "soundstream.d"];
fileList["audio"] = ["listener.d", "music.d", "package.d", "sound.d", "soundbuffer.d", "soundbufferrecorder.d", "inputsoundfile.d", "outputsoundfile.d", "soundrecorder.d", "soundsource.d", "soundstream.d"];
fileList["network"] = ["ftp.d", "http.d", "ipaddress.d", "package.d", "packet.d", "socket.d", "socketselector.d", "tcplistener.d", "tcpsocket.d", "udpsocket.d"];
fileList["window"] = ["context.d", "contextsettings.d", "event.d", "joystick.d", "keyboard.d", "mouse.d", "sensor.d", "touch.d", "package.d", "videomode.d", "window.d", "windowhandle.d"];
fileList["graphics"] = ["blendmode.d", "circleshape.d", "color.d", "convexshape.d", "drawable.d", "font.d", "glyph.d", "image.d", "package.d", "primitivetype.d", "rect.d", "rectangleshape.d", "renderstates.d", "rendertarget.d", "rendertexture.d", "renderwindow.d", "shader.d", "shape.d", "sprite.d", "text.d", "texture.d", "transform.d", "transformable.d", "vertex.d", "vertexarray.d", "view.d"];
Expand Down
23 changes: 3 additions & 20 deletions src/dsfml/audio/inputsoundfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ struct InputSoundFile
sfInputSoundFile_destroy(m_soundFile);
}

bool openReadFromFile(string filename)
bool openFromFile(string filename)
{
import dsfml.system.string;
bool toReturn = sfInputSoundFile_openFromFile(m_soundFile, toStringz(filename));
err.write(toString(sfErr_getOutput()));
return toReturn;
}

bool openReadFromMemory(const(void)[] data)
bool openFromMemory(const(void)[] data)
{
import dsfml.system.string;
bool toReturn = sfInputSoundFile_openFromMemory(m_soundFile, data.ptr, data.length);
err.write(toString(sfErr_getOutput()));
return toReturn;
}
bool openReadFromStream(InputStream stream)
bool openFromStream(InputStream stream)
{
import dsfml.system.string;
m_stream = new soundFileStream(stream);
Expand All @@ -65,25 +65,12 @@ struct InputSoundFile
return toReturn;
}

/*bool openWrite(string filename,uint channelCount,uint sampleRate)
{
import dsfml.system.string;
bool toReturn = sfInputSoundFile_openForWriting(m_soundFile, toStringz(filename),channelCount,sampleRate);
err.write(toString(sfErr_getOutput()));
return toReturn;
}*/

long read(ref short[] data)
{
return sfInputSoundFile_read(m_soundFile,data.ptr, data.length);

}

/*void write(const(short)[] data)
{
sfInputSoundFile_write(m_soundFile, data.ptr, data.length);
}*/

void seek(long timeOffset)
{
import dsfml.system.string;
Expand Down Expand Up @@ -193,14 +180,10 @@ bool sfInputSoundFile_openFromMemory(sfInputSoundFile* file,const(void)* data, l

bool sfInputSoundFile_openFromStream(sfInputSoundFile* file, soundInputStream stream);

//bool sfInputSoundFile_openReadFromStream(sfInputSoundFile* file, void* stream);

bool sfInputSoundFile_openForWriting(sfInputSoundFile* file, const(char)* filename,uint channelCount,uint sampleRate);

long sfInputSoundFile_read(sfInputSoundFile* file, short* data, long sampleCount);

//void sfInputSoundFile_write(sfInputSoundFile* file, const short* data, long sampleCount);

void sfInputSoundFile_seek(sfInputSoundFile* file, long timeOffset);
}
}
6 changes: 3 additions & 3 deletions src/dsfml/audio/music.d
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Music : SoundStream
//stop music if already playing
stop();

if(!m_file.openReadFromFile(filename))
if(!m_file.openFromFile(filename))
{
return false;
}
Expand All @@ -105,7 +105,7 @@ class Music : SoundStream
{
stop();

if(!m_file.openReadFromMemory(data))
if(!m_file.openFromMemory(data))
{
return false;
}
Expand All @@ -131,7 +131,7 @@ class Music : SoundStream
{
stop();

if(!m_file.openReadFromStream(stream))
if(!m_file.openFromStream(stream))
{
return false;
}
Expand Down
78 changes: 78 additions & 0 deletions src/dsfml/audio/outputsoundfile.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
DSFML - The Simple and Fast Multimedia Library for D
Copyright (c) 2013 - 2015 Jeremy DeHaan ([email protected])
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.outputsoundfile;

import std.string;
import dsfml.system.err;

/**
*Provide write access to sound files.
*
*This class encodes audio samples to a sound file.
*
*It is used internally by higher-level classes such as sf::SoundBuffer, but can also be useful if you want to create audio files from
*custom data sources, like generated audio samples.
*/
struct OutputSoundFile
{
private sfOutputSoundFile* m_soundFile;

void create()
{
m_soundFile = sfOutputSoundFile_create();
}

~this()
{
sfOutputSoundFile_destroy(m_soundFile);
}

bool openFromFile(string filename,uint channelCount,uint sampleRate)
{
import dsfml.system.string;
bool toReturn = sfOutputSoundFile_openFromFile(m_soundFile, toStringz(filename),channelCount,sampleRate);
err.write(toString(sfErr_getOutput()));
return toReturn;
}

void write(const(short)[] data)
{
sfOutputSoundFile_write(m_soundFile, data.ptr, data.length);
}

}

extern(C) const(char)* sfErr_getOutput();


private extern(C)
{

struct sfOutputSoundFile;

sfOutputSoundFile* sfOutputSoundFile_create();

void sfOutputSoundFile_destroy(sfOutputSoundFile* file);

bool sfOutputSoundFile_openFromFile(sfOutputSoundFile* file, const(char)* filename,uint channelCount,uint sampleRate);

void sfOutputSoundFile_write(sfOutputSoundFile* file, const short* data, long sampleCount);

}
2 changes: 1 addition & 1 deletion src/dsfml/graphics/font.d
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void sfFont_destroy(sfFont* font);


//Get a glyph in a font
void sfFont_getGlyph(const(sfFont)* font, uint codePoint, int characterSize, bool bold, int* glyphAdvance, int* glyphBoundsLeft, int* glyphBoundsTop, int* glyphBoundsWidth, int* glyphBoundsHeight, int* glyphTextRectLeft, int* glyphTextRectTop, int* glyphTextRectWidth, int* glyphTextRectHeight);
void sfFont_getGlyph(const(sfFont)* font, uint codePoint, int characterSize, bool bold, float* glyphAdvance, float* glyphBoundsLeft, float* glyphBoundsTop, float* glyphBoundsWidth, float* glyphBoundsHeight, int* glyphTextRectLeft, int* glyphTextRectTop, int* glyphTextRectWidth, int* glyphTextRectHeight);


//Get the kerning value corresponding to a given pair of characters in a font
Expand Down
4 changes: 2 additions & 2 deletions src/dsfml/graphics/glyph.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public import dsfml.graphics.rect;
+/
struct Glyph
{
int advance; /// Offset to move horizontally to the next character.
IntRect bounds; /// Bounding rectangle of the glyph, in coordinates relative to the baseline.
float advance; /// Offset to move horizontally to the next character.
FloatRect bounds; /// Bounding rectangle of the glyph, in coordinates relative to the baseline.
IntRect textureRect; /// Texture coordinates of the glyph inside the font's texture.
}
8 changes: 4 additions & 4 deletions src/dsfml/graphics/text.d
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ private:
// Extract the current glyph's description
Glyph glyph = m_font.getGlyph(curChar, m_characterSize, bold);

int left = glyph.bounds.left;
int top = glyph.bounds.top;
int right = glyph.bounds.left + glyph.bounds.width;
int bottom = glyph.bounds.top + glyph.bounds.height;
float left = glyph.bounds.left;
float top = glyph.bounds.top;
float right = glyph.bounds.left + glyph.bounds.width;
float bottom = glyph.bounds.top + glyph.bounds.height;

float u1 = cast(float)(glyph.textureRect.left);
float v1 = cast(float)(glyph.textureRect.top);
Expand Down

0 comments on commit 412cb3a

Please sign in to comment.