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
31 #include "nSoundSourceRole.h"
37 class nSoundSource : public QObject
40 Q_ENUMS(nSoundSourceState)
41 Q_ENUMS(nSoundSourceRole)
43 Q_PROPERTY(unsigned int openalHandle READ openalHandle)
44 Q_PROPERTY(nSoundSourceRole role READ role)
45 Q_PROPERTY(nSoundSourceState state READ state)
46 Q_PROPERTY(qreal gain READ gain WRITE setGain)
47 Q_PROPERTY(qreal pitch READ pitch WRITE setPitch)
48 Q_PROPERTY(qreal rolloffFactor READ rolloffFactor WRITE setRolloffFactor)
49 Q_PROPERTY(bool loop READ loop WRITE setLoop)
50 Q_PROPERTY(QVector3D position READ position WRITE setPosition)
51 Q_PROPERTY(bool destroyAfterStopped READ destroyAfterStopped WRITE setDestroyAfterStopped NOTIFY onDestroyAfterStoppedChanged )
53 Q_PROPERTY(qreal fading READ isFading)
54 Q_PROPERTY(qreal fadeTarget READ fadeTarget)
55 Q_PROPERTY(qreal fadeDeltaPerSecond READ fadeDeltaPerSecond)
59 enum nSoundSourceState
68 explicit nSoundSource(QString name, nSoundSourceRole role, nSoundSystem * parent);
69 virtual ~nSoundSource();
71 unsigned int openalHandle(){return m_handle;}
72 nSoundSourceState state();
73 nSoundSourceRole role(){return m_role;}
76 qreal rolloffFactor();
80 bool isFading() const {return m_fading;}
81 qreal fadeTarget() const {return m_fadeTarget;}
82 qreal fadeDeltaPerSecond() const {return m_fadeDeltaPerSecond;}
85 static qreal _roleGainVolume(nSoundSourceRole role);
86 static void _resetRoleGains();
88 bool destroyAfterStopped() const
90 return m_destroyAfterStopped;
95 void onDestroyAfterStoppedChanged(bool arg);
98 bool update(qreal frameTime);
100 void attachBuffer(nSoundBuffer * buffer);
103 void setPitch(qreal);
104 void setRolloffFactor(qreal);
106 void setPosition(QVector3D pos);
108 void fade(qreal to, qreal duration, qreal from = -1.0f);
115 void setDestroyAfterStopped(bool arg)
117 if (m_destroyAfterStopped == arg)
120 m_destroyAfterStopped = arg;
121 emit onDestroyAfterStoppedChanged(arg);
125 unsigned int m_handle;
126 nSoundSourceRole m_role;
132 qreal m_fadeDeltaPerSecond;
135 static bool _m_gainsInitialized;
136 static qreal _m_musicGain;
137 static qreal _m_sfxGain;
138 static qreal _m_voiceGain;
139 static qreal _m_ambienceGain;
141 bool m_destroyAfterStopped;
144 #endif // NSOUNDSOURCE_H