1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#ifndef _LIBKVISND_H_
#define _LIBKVISND_H_
//=============================================================================
//
// File : libkvisnd.h
// Creation date : Thu Dec 27 2002 17:13:12 GMT by Juanjo Alvarez
//
// This file is part of the KVIrc IRC client distribution
// Copyright (C) 2002 Juanjo Alvarez (juanjux at yahoo dot es)
// Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
//
// This program is FREE software. You can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================
#include "kvi_settings.h"
#include "KviPointerList.h"
#include "KviPointerHashTable.h"
#include "KviOptions.h"
#include "KviThread.h"
#include "KviCString.h"
#include <QObject>
class KviSoundPlayer;
class KviSoundThread : public KviThread
{
public:
KviSoundThread(const QString & szFileName);
virtual ~KviSoundThread();
protected:
bool m_bTerminate;
QString m_szFileName;
public:
void terminate();
protected:
virtual void play();
virtual void run();
};
#if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW)
#ifdef COMPILE_OSS_SUPPORT
class KviOssSoundThread : public KviSoundThread
{
public:
KviOssSoundThread(const QString & szFileName);
virtual ~KviOssSoundThread();
protected:
virtual void play();
};
#ifdef COMPILE_AUDIOFILE_SUPPORT
class KviOssAudiofileSoundThread : public KviSoundThread
{
public:
KviOssAudiofileSoundThread(const QString & szFileName);
virtual ~KviOssAudiofileSoundThread();
protected:
virtual void play();
};
#endif //COMPILE_AUDIOFILE_SUPPORT
#endif //COMPILE_OSS_SUPPORT
#endif //!COMPILE_ON_WINDOWS
#ifdef COMPILE_PHONON_SUPPORT
namespace Phonon
{
class MediaObject;
}
#endif //!COMPILE_PHONON_SUPPORT
#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
class QMediaPlayer;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
class QAudioOutput;
#endif
#endif
typedef bool (KviSoundPlayer::*SoundSystemPlayRoutine)(const QString & szFileName);
typedef void (KviSoundPlayer::*SoundSystemCleanupRoutine)();
class KviSoundPlayerEntry
{
private:
SoundSystemPlayRoutine m_pPlayRoutine;
SoundSystemCleanupRoutine m_pCleanupRoutine;
public:
KviSoundPlayerEntry(SoundSystemPlayRoutine pPlayRoutine, SoundSystemCleanupRoutine pCleanupRoutine)
: m_pPlayRoutine(pPlayRoutine), m_pCleanupRoutine(pCleanupRoutine)
{
}
SoundSystemPlayRoutine playRoutine() const
{
return m_pPlayRoutine;
}
SoundSystemCleanupRoutine cleanupRoutine() const
{
return m_pCleanupRoutine;
}
};
class KviSoundPlayer : public QObject
{
friend class KviSoundThread;
Q_OBJECT
public:
KviSoundPlayer();
virtual ~KviSoundPlayer();
public:
bool play(const QString & szFileName);
bool detectSoundSystem(QString & szSoundSystem);
bool havePlayingSounds();
void getAvailableSoundSystems(QStringList * l);
bool isMuted()
{
return KVI_OPTION_BOOL(KviOption_boolMuteAllSounds);
}
void setMuted(bool muted)
{
KVI_OPTION_BOOL(KviOption_boolMuteAllSounds) = muted;
}
protected:
KviPointerList<KviSoundThread> * m_pThreadList;
KviPointerHashTable<QString, KviSoundPlayerEntry> * m_pSoundSystemDict;
#ifdef COMPILE_PHONON_SUPPORT
std::unique_ptr<Phonon::MediaObject> m_pPhononPlayer;
#endif //!COMPILE_PHONON_SUPPORT
#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
std::unique_ptr<QMediaPlayer> m_pMediaPlayer;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
std::unique_ptr<QAudioOutput> m_pAudioOutput;
#endif
#endif //!COMPILE_QTMULTIMEDIA_SUPPORT
KviSoundPlayerEntry * m_pLastUsedSoundPlayerEntry;
protected:
void registerSoundThread(KviSoundThread * t);
void unregisterSoundThread(KviSoundThread * t);
bool event(QEvent * e) override;
protected:
void stopAllSoundThreads();
void cleanupAfterLastPlayerEntry();
#ifdef COMPILE_PHONON_SUPPORT
bool playPhonon(const QString & szFileName);
void cleanupPhonon();
#endif //!COMPILE_PHONON_SUPPORT
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
bool playWinmm(const QString & szFileName);
void cleanupWinmm();
#else //!COMPILE_ON_WINDOWS
#ifdef COMPILE_OSS_SUPPORT
bool playOss(const QString & szFileName);
void cleanupOss();
#ifdef COMPILE_AUDIOFILE_SUPPORT
bool playOssAudiofile(const QString & szFileName);
void cleanupOssAudiofile();
#endif //COMPILE_AUDIOFILE_SUPPORT
#endif //COMPILE_OSS_SUPPORT
#endif //!COMPILE_ON_WINDOWS
#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
bool playQt(const QString & szFileName);
void cleanupQt();
#endif
bool playNull(const QString & szFileName);
void cleanupNull();
};
#endif // _KVISND_H_
|