xbmc
GUIAudioManager.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "GUIComponent.h"
12 #include "cores/AudioEngine/Interfaces/AESound.h"
13 #include "settings/lib/ISettingCallback.h"
14 #include "threads/CriticalSection.h"
15 
16 #include <map>
17 #include <memory>
18 #include <string>
19 
20 // forward definitions
21 class CAction;
22 class CSettings;
23 class TiXmlNode;
24 class IAESound;
25 
26 enum WINDOW_SOUND { SOUND_INIT = 0, SOUND_DEINIT };
27 
29 {
30  class CWindowSounds
31  {
32  public:
33  std::shared_ptr<IAESound> initSound;
34  std::shared_ptr<IAESound> deInitSound;
35  };
36 
37  struct IAESoundDeleter
38  {
39  void operator()(IAESound* s);
40  };
41 
42 public:
44  ~CGUIAudioManager() override;
45 
46  void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
47  bool OnSettingUpdate(const std::shared_ptr<CSetting>& setting,
48  const char* oldSettingId,
49  const TiXmlNode* oldSettingNode) override;
50 
51  void Initialize();
52  void DeInitialize();
53 
54  bool Load();
55  void UnLoad();
56 
57 
58  void PlayActionSound(const CAction& action);
59  void PlayWindowSound(int id, WINDOW_SOUND event);
60  void PlayPythonSound(const std::string& strFileName, bool useCached = true);
61 
62  void Enable(bool bEnable);
63  void SetVolume(float level);
64  void Stop();
65 
66 private:
67  // Construction parameters
68  std::shared_ptr<CSettings> m_settings;
69 
70  typedef std::map<const std::string, std::weak_ptr<IAESound>> soundCache;
71  typedef std::map<int, std::shared_ptr<IAESound>> actionSoundMap;
72  typedef std::map<int, CWindowSounds> windowSoundMap;
73  typedef std::map<const std::string, std::shared_ptr<IAESound>> pythonSoundsMap;
74 
75  soundCache m_soundCache;
76  actionSoundMap m_actionSoundMap;
77  windowSoundMap m_windowSoundMap;
78  pythonSoundsMap m_pythonSounds;
79 
80  std::string m_strMediaDir;
81  bool m_bEnabled;
82 
83  CCriticalSection m_cs;
84 
85  std::shared_ptr<IAESound> LoadSound(const std::string& filename);
86  std::shared_ptr<IAESound> LoadWindowSound(TiXmlNode* pWindowNode,
87  const std::string& strIdentifier);
88 };
89 
Definition: GUIAudioManager.h:28
Wrapper around CSettingsManager responsible for properly setting up the settings manager and register...
Definition: Settings.h:27
Definition: ISettingCallback.h:16
Definition: AESound.h:15
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
bool OnSettingUpdate(const std::shared_ptr< CSetting > &setting, const char *oldSettingId, const TiXmlNode *oldSettingNode) override
The given setting needs to be updated.
Definition: GUIAudioManager.cpp:57
void OnSettingChanged(const std::shared_ptr< const CSetting > &setting) override
The value of the given setting has changed.
Definition: GUIAudioManager.cpp:44