1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 23:59:41 +02:00
audacity/src/DeviceManager.h
lllucius 71d8b0d8ec Possible fix for bug #435
I say possible because I can't fully test it as my motherboard
audio device doesn't show up in Windows (don't know why yet).

So, because of that and because this "fix" needs a little discussion
amongst the troops, I've ifdef'd it with EXPERIMENTAL_HAVE_DEVICE_CHANGE
and have disabled it by default.

What is does is it sets up a device change listener and performs an
automatic rescan when a change is detected.  (That's the part that
needs discussion.)
2014-12-06 04:11:31 +00:00

92 lines
2.3 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
DeviceManager.h
Created by Michael Chinen (mchinen) on 2/12/11
Audacity(R) is copyright (c) 1999-2011 Audacity Team.
License: GPL v2. See License.txt.
******************************************************************//**
\class DeviceManager
\brief A singleton that manages the audio devices known to Audacity
*//*******************************************************************/
#ifndef __AUDACITY_DEVICEMANAGER__
#define __AUDACITY_DEVICEMANAGER__
#include <vector>
#include "wx/wx.h"
#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
#include "DeviceChange.h"
#endif
typedef struct DeviceSourceMap {
int deviceIndex;
int sourceIndex;
int hostIndex;
int totalSources;
int numChannels;
wxString sourceString;
wxString deviceString;
wxString hostString;
} DeviceSourceMap;
wxString MakeDeviceSourceString(const DeviceSourceMap *map);
class DeviceManager
#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
#if defined(HAVE_DEVICE_CHANGE)
: public DeviceChangeHandler
#endif
#endif
{
public:
/// Gets the singleton instance
static DeviceManager* Instance();
/// Releases memory assosiated with the singleton
static void Destroy();
/// Gets a new list of devices by terminating and restarting portaudio
/// Assumes that DeviceManager is only used on the main thread.
void Rescan();
DeviceSourceMap* GetDefaultOutputDevice(int hostIndex);
DeviceSourceMap* GetDefaultInputDevice(int hostIndex);
const std::vector<DeviceSourceMap> &GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &GetOutputDeviceMaps();
#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
#if defined(HAVE_DEVICE_CHANGE)
// DeviceChangeHandler implementation
void DeviceChangeNotification();
#endif
#endif
protected:
//private constructor - Singleton.
DeviceManager();
virtual ~DeviceManager();
/// Does an initial scan.
/// Called by GetInputDeviceMaps and GetOutputDeviceMaps when needed.
void Init();
DeviceSourceMap* GetDefaultDevice(int hostIndex, int isInput);
bool m_inited;
std::vector<DeviceSourceMap> mInputDeviceSourceMaps;
std::vector<DeviceSourceMap> mOutputDeviceSourceMaps;
static DeviceManager dm;
};
#endif