Audacity  2.2.2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
DeviceManager Class Referencefinal

A singleton that manages the audio devices known to Audacity. More...

#include <DeviceManager.h>

Public Member Functions

void Rescan ()
 
DeviceSourceMapGetDefaultOutputDevice (int hostIndex)
 
DeviceSourceMapGetDefaultInputDevice (int hostIndex)
 
const std::vector
< DeviceSourceMap > & 
GetInputDeviceMaps ()
 
const std::vector
< DeviceSourceMap > & 
GetOutputDeviceMaps ()
 

Static Public Member Functions

static DeviceManagerInstance ()
 Gets the singleton instance. More...
 

Protected Member Functions

 DeviceManager ()
 
 ~DeviceManager ()
 
void Init ()
 
DeviceSourceMapGetDefaultDevice (int hostIndex, int isInput)
 

Protected Attributes

bool m_inited
 
std::vector< DeviceSourceMapmInputDeviceSourceMaps
 
std::vector< DeviceSourceMapmOutputDeviceSourceMaps
 

Static Protected Attributes

static DeviceManager dm
 

Detailed Description

A singleton that manages the audio devices known to Audacity.

Definition at line 43 of file DeviceManager.h.

Constructor & Destructor Documentation

DeviceManager::DeviceManager ( )
protected

Definition at line 312 of file DeviceManager.cpp.

315 : DeviceChangeHandler()
316 #endif
317 #endif
318 {
319  m_inited = false;
320 }
DeviceManager::~DeviceManager ( )
protected

Definition at line 322 of file DeviceManager.cpp.

323 {
324 
325 }

Member Function Documentation

DeviceSourceMap * DeviceManager::GetDefaultDevice ( int  hostIndex,
int  isInput 
)
protected

Definition at line 74 of file DeviceManager.cpp.

References mInputDeviceSourceMaps, and mOutputDeviceSourceMaps.

Referenced by GetDefaultInputDevice(), and GetDefaultOutputDevice().

75 {
76  if (hostIndex < 0 || hostIndex >= Pa_GetHostApiCount()) {
77  return NULL;
78  }
79 
80  const struct PaHostApiInfo *apiinfo = Pa_GetHostApiInfo(hostIndex); // get info on API
81  std::vector<DeviceSourceMap> & maps = isInput ? mInputDeviceSourceMaps : mOutputDeviceSourceMaps;
82  size_t i;
83  int targetDevice = isInput ? apiinfo->defaultInputDevice : apiinfo->defaultOutputDevice;
84 
85  for (i = 0; i < maps.size(); i++) {
86  if (maps[i].deviceIndex == targetDevice)
87  return &maps[i];
88  }
89 
90  wxLogDebug(wxT("GetDefaultDevice() no default device"));
91  return NULL;
92 }
std::vector< DeviceSourceMap > mInputDeviceSourceMaps
Definition: DeviceManager.h:83
std::vector< DeviceSourceMap > mOutputDeviceSourceMaps
Definition: DeviceManager.h:84
DeviceSourceMap * DeviceManager::GetDefaultInputDevice ( int  hostIndex)

Definition at line 98 of file DeviceManager.cpp.

References GetDefaultDevice().

Referenced by DevicePrefs::OnHost(), and DeviceToolBar::UpdatePrefs().

99 {
100  return GetDefaultDevice(hostIndex, 1);
101 }
DeviceSourceMap * GetDefaultDevice(int hostIndex, int isInput)
DeviceSourceMap * DeviceManager::GetDefaultOutputDevice ( int  hostIndex)

Definition at line 94 of file DeviceManager.cpp.

References GetDefaultDevice().

Referenced by DevicePrefs::OnHost(), and DeviceToolBar::UpdatePrefs().

95 {
96  return GetDefaultDevice(hostIndex, 0);
97 }
DeviceSourceMap * GetDefaultDevice(int hostIndex, int isInput)
const std::vector< DeviceSourceMap > & DeviceManager::GetInputDeviceMaps ( )
const std::vector< DeviceSourceMap > & DeviceManager::GetOutputDeviceMaps ( )

Definition at line 56 of file DeviceManager.cpp.

References Init(), m_inited, and mOutputDeviceSourceMaps.

Referenced by DeviceToolBar::ChangeDevice(), DeviceToolBar::FillHostDevices(), DeviceToolBar::FillHosts(), DevicePrefs::OnHost(), and DeviceToolBar::UpdatePrefs().

57 {
58  if (!m_inited)
59  Init();
61 }
std::vector< DeviceSourceMap > mOutputDeviceSourceMaps
Definition: DeviceManager.h:84
void DeviceManager::Init ( )
protected

Does an initial scan. Called by GetInputDeviceMaps and GetOutputDeviceMaps when needed.

Definition at line 327 of file DeviceManager.cpp.

References Rescan().

Referenced by GetInputDeviceMaps(), and GetOutputDeviceMaps().

328 {
329  Rescan();
330 
331 #if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
332 #if defined(HAVE_DEVICE_CHANGE)
333  DeviceChangeHandler::Enable(true);
334 #endif
335 #endif
336 }
DeviceManager * DeviceManager::Instance ( )
static
void DeviceManager::Rescan ( )

Gets a NEW list of devices by terminating and restarting portaudio Assumes that DeviceManager is only used on the main thread.

Definition at line 251 of file DeviceManager.cpp.

References AddSources(), gAudacityProjects, gAudioIO, AudioIO::IsBusy(), AudioIO::IsMonitoring(), m_inited, mInputDeviceSourceMaps, mOutputDeviceSourceMaps, DeviceToolBar::RefillCombos(), and AudioIO::StopStream().

Referenced by Init(), and AudacityProject::OnRescanDevices().

252 {
253  // get rid of the previous scan info
254  this->mInputDeviceSourceMaps.clear();
255  this->mOutputDeviceSourceMaps.clear();
256 
257  // if we are doing a second scan then restart portaudio to get NEW devices
258  if (m_inited) {
259  // check to see if there is a stream open - can happen if monitoring,
260  // but otherwise Rescan() should not be available to the user.
261  if (gAudioIO) {
262  if (gAudioIO->IsMonitoring())
263  {
264  gAudioIO->StopStream();
265  while (gAudioIO->IsBusy())
266  wxMilliSleep(100);
267  }
268  }
269 
270  // restart portaudio - this updates the device list
271  // FIXME: TRAP_ERR restarting PortAudio
272  Pa_Terminate();
273  Pa_Initialize();
274  }
275 
276  // FIXME: TRAP_ERR PaErrorCode not handled in ReScan()
277  int nDevices = Pa_GetDeviceCount();
278 
279  //The heirarchy for devices is Host/device/source.
280  //Some newer systems aggregate this.
281  //So we need to call port mixer for every device to get the sources
282  for (int i = 0; i < nDevices; i++) {
283  const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
284  if (info->maxOutputChannels > 0) {
285  AddSources(i, info->defaultSampleRate, &mOutputDeviceSourceMaps, 0);
286  }
287 
288  if (info->maxInputChannels > 0) {
289 #ifdef __WXMSW__
290 #if !defined(EXPERIMENTAL_FULL_WASAPI)
291  if (Pa_GetHostApiInfo(info->hostApi)->type != paWASAPI ||
292  PaWasapi_IsLoopback(i) > 0)
293 #endif
294 #endif
295  AddSources(i, info->defaultSampleRate, &mInputDeviceSourceMaps, 1);
296  }
297  }
298 
299  // If this was not an initial scan update each device toolbar.
300  // Hosts may have disappeared or appeared so a complete repopulate is needed.
301  if (m_inited) {
302  DeviceToolBar *dt;
303  for (size_t i = 0; i < gAudacityProjects.size(); i++) {
304  dt = gAudacityProjects[i]->GetDeviceToolBar();
305  dt->RefillCombos();
306  }
307  }
308  m_inited = true;
309 }
void StopStream()
Stop recording, playback or input monitoring.
Definition: AudioIO.cpp:2551
AProjectArray gAudacityProjects
Definition: Project.cpp:303
bool IsBusy()
Returns true if audio i/o is busy starting, stopping, playing, or recording.
Definition: AudioIO.cpp:2868
std::vector< DeviceSourceMap > mInputDeviceSourceMaps
Definition: DeviceManager.h:83
A toobar to allow easier changing of input and output devices .
Definition: DeviceToolBar.h:25
std::vector< DeviceSourceMap > mOutputDeviceSourceMaps
Definition: DeviceManager.h:84
AudioIO * gAudioIO
Definition: AudioIO.cpp:482
bool IsMonitoring()
Returns true if we're monitoring input (but not recording or playing actual audio) ...
Definition: AudioIO.cpp:2900
static void AddSources(int deviceIndex, int rate, std::vector< DeviceSourceMap > *maps, int isInput)

Member Data Documentation

DeviceManager DeviceManager::dm
staticprotected

Definition at line 86 of file DeviceManager.h.

Referenced by Instance().

bool DeviceManager::m_inited
protected

Definition at line 81 of file DeviceManager.h.

Referenced by GetInputDeviceMaps(), GetOutputDeviceMaps(), and Rescan().

std::vector<DeviceSourceMap> DeviceManager::mInputDeviceSourceMaps
protected

Definition at line 83 of file DeviceManager.h.

Referenced by GetDefaultDevice(), GetInputDeviceMaps(), and Rescan().

std::vector<DeviceSourceMap> DeviceManager::mOutputDeviceSourceMaps
protected

Definition at line 84 of file DeviceManager.h.

Referenced by GetDefaultDevice(), GetOutputDeviceMaps(), and Rescan().


The documentation for this class was generated from the following files: