1 module nudsfml.audio.sound; 2 3 import bindbc.sfml.audio; 4 import bindbc.sfml.system; 5 6 import nudsfml.audio.soundbuffer; 7 import nudsfml.audio.soundstatus; 8 import nudsfml.system.vector3; 9 import nudsfml.system.time; 10 11 class Sound { 12 sfSound * m_sound = null; 13 14 this(){ 15 m_sound = sfSound_create(); 16 } 17 18 ~this(){ 19 if(m_sound !is null){ 20 sfSound_destroy(m_sound); 21 } 22 } 23 24 @property { 25 SoundBuffer buffer(){ 26 SoundBuffer temp = new SoundBuffer(sfSound_getBuffer(m_sound)); 27 return temp; 28 } 29 void buffer(SoundBuffer soundBuffer){ 30 sfSound_setBuffer(m_sound, soundBuffer.m_soundBuffer); 31 } 32 } 33 34 @property { 35 bool loop() { 36 return sfSound_getLoop(m_sound) != 0; 37 } 38 void loop(bool doLoop){ 39 sfSound_setLoop(m_sound, doLoop); 40 } 41 } 42 43 @property { 44 SoundStatus status() { 45 sfSoundStatus stat = sfSound_getStatus(m_sound); 46 return cast(SoundStatus)stat; 47 } 48 } 49 50 @property { 51 float pitch() { 52 return sfSound_getPitch(m_sound); 53 } 54 void pitch(float pitch_){ 55 sfSound_setPitch(m_sound, pitch_); 56 } 57 } 58 59 @property { 60 float volume(){ 61 return sfSound_getVolume(m_sound); 62 } 63 64 void volume(float vol){ 65 if(vol < 0f){ 66 vol = 0f; 67 } else if (vol > 100f){ 68 vol = 100f; 69 } 70 sfSound_setVolume(m_sound, vol); 71 } 72 } 73 74 @property { 75 void position(Vector3f pos){ 76 sfSound_setPosition(m_sound, cast(sfVector3f) pos); 77 } 78 Vector3f position(){ 79 return cast(Vector3f) sfSound_getPosition(m_sound); 80 } 81 } 82 83 @property { 84 void relativeToListener(bool relative){ 85 sfSound_setRelativeToListener(m_sound, relative); 86 } 87 bool relativeToListener(){ 88 return cast(bool)sfSound_isRelativeToListener(m_sound); 89 } 90 } 91 92 @property { 93 void minDistance(float distance){ 94 sfSound_setMinDistance(m_sound, distance); 95 } 96 float minDistance(){ 97 return sfSound_getMinDistance(m_sound); 98 } 99 } 100 101 @property { 102 void attenuation(float atten) { 103 sfSound_setAttenuation(m_sound, atten); 104 } 105 float attenuation() { 106 return sfSound_getAttenuation(m_sound); 107 } 108 } 109 110 @property { 111 void playingOffset(Time timeOffset){ 112 sfSound_setPlayingOffset(m_sound, cast(sfTime)timeOffset); 113 } 114 Time playingOffset(){ 115 return cast(Time)sfSound_getPlayingOffset(m_sound); 116 } 117 } 118 119 void play(){ 120 sfSound_play(m_sound); 121 } 122 123 void pause() { 124 sfSound_pause(m_sound); 125 } 126 127 void stop() { 128 sfSound_stop(m_sound); 129 } 130 }