Audacity  3.0.3
DeviceManager.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  DeviceManager.h
6 
7  Created by Michael Chinen (mchinen) on 2/12/11
8  Audacity(R) is copyright (c) 1999-2011 Audacity Team.
9  License: GPL v2. See License.txt.
10 
11 ******************************************************************//*******************************************************************/
17 
18 #ifndef __AUDACITY_DEVICEMANAGER__
19 #define __AUDACITY_DEVICEMANAGER__
20 
21 #include <chrono>
22 #include <vector>
23 
24 #include <wx/event.h> // to declare a custom event type
25 #include <wx/string.h> // member variables
26 
27 #if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
28 #include "DeviceChange.h"
29 #endif
30 
31 // Event sent to the application
32 wxDECLARE_EXPORTED_EVENT(AUDIO_DEVICES_API,
33  EVT_RESCANNED_DEVICES, wxEvent);
34 
35 typedef struct DeviceSourceMap {
38  int hostIndex;
41  wxString sourceString;
42  wxString deviceString;
43  wxString hostString;
45 
46 AUDIO_DEVICES_API
47 wxString MakeDeviceSourceString(const DeviceSourceMap *map);
48 
49 class AUDIO_DEVICES_API DeviceManager final
50 #if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER) && defined(HAVE_DEVICE_CHANGE)
51 : public DeviceChangeHandler
52 #else
53 : public wxEvtHandler
54 #endif
55 {
56  public:
58  static DeviceManager* Instance();
59 
62  void Rescan();
63 
64  // Time since devices scanned in seconds.
65  float GetTimeSinceRescan();
66 
67  DeviceSourceMap* GetDefaultOutputDevice(int hostIndex);
68  DeviceSourceMap* GetDefaultInputDevice(int hostIndex);
69 
70  const std::vector<DeviceSourceMap> &GetInputDeviceMaps();
71  const std::vector<DeviceSourceMap> &GetOutputDeviceMaps();
72 
73 #if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
74 #if defined(HAVE_DEVICE_CHANGE)
75  // DeviceChangeHandler implementation
76  void DeviceChangeNotification();
77 #endif
78 #endif
79 
80 private:
81  std::chrono::time_point<std::chrono::steady_clock> mRescanTime;
82 
83  protected:
84  //private constructor - Singleton.
85  DeviceManager();
86  ~DeviceManager();
89  void Init();
90 
91  DeviceSourceMap* GetDefaultDevice(int hostIndex, int isInput);
92 
93  bool m_inited;
94 
95  std::vector<DeviceSourceMap> mInputDeviceSourceMaps;
96  std::vector<DeviceSourceMap> mOutputDeviceSourceMaps;
97 
98  static DeviceManager dm;
99 };
100 
101 #endif
102 
DeviceManager::dm
static DeviceManager dm
Definition: DeviceManager.h:98
Init
Definition: ModuleManager.h:152
DeviceManager::mInputDeviceSourceMaps
std::vector< DeviceSourceMap > mInputDeviceSourceMaps
Definition: DeviceManager.h:95
DeviceSourceMap::numChannels
int numChannels
Definition: DeviceManager.h:40
DeviceManager::m_inited
bool m_inited
Definition: DeviceManager.h:93
DeviceSourceMap::deviceString
wxString deviceString
Definition: DeviceManager.h:42
DeviceSourceMap
Definition: DeviceManager.h:35
DeviceSourceMap
struct DeviceSourceMap DeviceSourceMap
DeviceManager::mOutputDeviceSourceMaps
std::vector< DeviceSourceMap > mOutputDeviceSourceMaps
Definition: DeviceManager.h:96
DeviceSourceMap::totalSources
int totalSources
Definition: DeviceManager.h:39
DeviceSourceMap::deviceIndex
int deviceIndex
Definition: DeviceManager.h:36
DeviceSourceMap::sourceIndex
int sourceIndex
Definition: DeviceManager.h:37
DeviceManager
A singleton that manages the audio devices known to Audacity.
Definition: DeviceManager.h:55
DeviceChange.h
MakeDeviceSourceString
AUDIO_DEVICES_API wxString MakeDeviceSourceString(const DeviceSourceMap *map)
Definition: DeviceManager.cpp:54
DeviceSourceMap::hostString
wxString hostString
Definition: DeviceManager.h:43
DeviceSourceMap::hostIndex
int hostIndex
Definition: DeviceManager.h:38
DeviceSourceMap::sourceString
wxString sourceString
Definition: DeviceManager.h:41
DeviceManager::mRescanTime
std::chrono::time_point< std::chrono::steady_clock > mRescanTime
Definition: DeviceManager.h:81
wxDECLARE_EXPORTED_EVENT
wxDECLARE_EXPORTED_EVENT(AUDIO_DEVICES_API, EVT_RESCANNED_DEVICES, wxEvent)