]> camargo.eng.br - camargo/neiasound.git/blob - src/nSoundSystem.h
Fixed conflict
[camargo/neiasound.git] / src / nSoundSystem.h
1 // Copyright (C) 2015 Lucas Pires Camargo
2 // 
3 // This file is part of neiasound - Qt-style OpenAL wrapper for games.
4 // 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 // 
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // 
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.
15 // 
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 NSOUNDSYSTEM_H
27 #define NSOUNDSYSTEM_H
28
29 #include "neiasound_global.h"
30 #include <QObject>
31 #include <QHash>
32 #include "nSoundSourceRole.h"
33 #include "nSoundFormat.h"
34
35 // *sigh* ugly but necessary
36 struct ALCcontext_struct;
37 struct ALCdevice_struct;
38 typedef struct ALCcontext_struct ALCcontext;
39 typedef struct ALCdevice_struct ALCdevice;
40
41 class nSoundSource;
42 class nSoundBuffer;
43 class nSoundListener;
44 class nSoundStreamer;
45 class nSoundStreamerPlaylist;
46
47 class NEIASOUNDSHARED_EXPORT nSoundSystem : public QObject
48 {
49     Q_OBJECT
50     Q_PROPERTY(int supportedAuxiliarySends READ supportedAuxiliarySends)
51     Q_PROPERTY(qreal masterGain READ masterGain WRITE setMasterGain NOTIFY masterGainChanged)
52     Q_PROPERTY(nSoundListener * listener READ listener)
53     Q_PROPERTY(ALCcontext * openalContext READ openalContext)
54     Q_PROPERTY(ALCdevice * openalDevice READ openalDevice)
55     Q_ENUMS(nSoundFormat)
56     Q_ENUMS(nSoundSourceRole)
57 public:
58     explicit nSoundSystem(QObject *parent = 0);
59     virtual ~nSoundSystem();
60
61     ALCcontext * openalContext(){return m_context;}
62     ALCdevice * openalDevice(){return m_device;}
63
64     nSoundListener * listener(){return m_listener;}
65
66     qreal masterGain();
67
68     int supportedAuxiliarySends(){return m_numSends;}
69
70 signals:
71
72     void masterGainChanged(qreal arg);
73
74 public slots:
75
76     void update(qreal);
77
78     void setMasterGain(qreal gain);
79
80     nSoundSource * createSource(QString name = "", nSoundSourceRole = SSR_SFX);
81     nSoundSource * source(QString name);
82     bool destroySource(QString name);
83     bool destroySource(nSoundSource * source);
84
85     nSoundBuffer * createBuffer(QString name);
86     nSoundBuffer * buffer(QString name);
87     bool destroyBuffer(QString name);
88     bool destroyBuffer(nSoundBuffer * buffer);
89
90
91     nSoundStreamer * createStreamer(QString name, nSoundSource * source, nSoundStreamerPlaylist * playlist = 0);
92     nSoundStreamerPlaylist * createStreamerPlaylist(QObject * parent);
93     nSoundStreamer * streamer(QString name);
94     bool destroyStreamer(QString name);
95     bool destroyStreamer(nSoundStreamer * streamer);
96
97 private:
98     QHash<QString, nSoundSource*> m_sources;
99     QHash<QString, nSoundBuffer*> m_buffers;
100     QHash<QString, nSoundStreamer*> m_streamers;
101
102     nSoundListener * m_listener;
103
104     bool m_success;
105     int m_numSends;
106     ALCcontext * m_context;
107     ALCdevice * m_device;
108     qreal m_masterGain;
109 };
110
111 #endif // NSOUNDSYSTEM_H