1 // Copyright (C) 2015 Lucas Pires Camargo
3 // This file is part of neiasound - Qt-style OpenAL wrapper for games.
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright notice,
13 // this list of conditions and the following disclaimer in the documentation
14 // and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS
17 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 // NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef NSOUNDSOURCE_H
27 #define NSOUNDSOURCE_H
29 #include "neiasound_global.h"
32 #include "nSoundSourceRole.h"
38 class NEIASOUNDSHARED_EXPORT nSoundSource : public QObject
41 Q_ENUMS(nSoundSourceState)
42 Q_ENUMS(nSoundSourceRole)
44 Q_PROPERTY(unsigned int openalHandle READ openalHandle)
45 Q_PROPERTY(nSoundSourceRole role READ role)
46 Q_PROPERTY(nSoundSourceState state READ state)
47 Q_PROPERTY(qreal gain READ gain WRITE setGain)
48 Q_PROPERTY(qreal pitch READ pitch WRITE setPitch)
49 Q_PROPERTY(qreal rolloffFactor READ rolloffFactor WRITE setRolloffFactor)
50 Q_PROPERTY(bool loop READ loop WRITE setLoop)
51 Q_PROPERTY(QVector3D position READ position WRITE setPosition)
52 Q_PROPERTY(bool destroyAfterStopped READ destroyAfterStopped WRITE setDestroyAfterStopped NOTIFY onDestroyAfterStoppedChanged )
54 Q_PROPERTY(qreal fading READ isFading)
55 Q_PROPERTY(qreal fadeTarget READ fadeTarget)
56 Q_PROPERTY(qreal fadeDeltaPerSecond READ fadeDeltaPerSecond)
60 enum nSoundSourceState
69 explicit nSoundSource(QString name, nSoundSourceRole role, nSoundSystem * parent);
70 virtual ~nSoundSource();
72 unsigned int openalHandle(){return m_handle;}
73 nSoundSourceState state();
74 nSoundSourceRole role(){return m_role;}
77 qreal rolloffFactor();
81 bool isFading() const {return m_fading;}
82 qreal fadeTarget() const {return m_fadeTarget;}
83 qreal fadeDeltaPerSecond() const {return m_fadeDeltaPerSecond;}
86 static qreal _roleGainVolume(nSoundSourceRole role);
87 static void _resetRoleGains();
89 bool destroyAfterStopped() const
91 return m_destroyAfterStopped;
96 void onDestroyAfterStoppedChanged(bool arg);
99 bool update(qreal frameTime);
101 void attachBuffer(nSoundBuffer * buffer);
104 void setPitch(qreal);
105 void setRolloffFactor(qreal);
107 void setPosition(QVector3D pos);
109 void fade(qreal to, qreal duration, qreal from = -1.0f);
116 void setDestroyAfterStopped(bool arg)
118 if (m_destroyAfterStopped == arg)
121 m_destroyAfterStopped = arg;
122 emit onDestroyAfterStoppedChanged(arg);
126 unsigned int m_handle;
127 nSoundSourceRole m_role;
133 qreal m_fadeDeltaPerSecond;
136 static bool _m_gainsInitialized;
137 static qreal _m_musicGain;
138 static qreal _m_sfxGain;
139 static qreal _m_voiceGain;
140 static qreal _m_ambienceGain;
142 bool m_destroyAfterStopped;
145 #endif // NSOUNDSOURCE_H