OpenShot Library | libopenshot-audio  0.2.0
juce_AudioIODeviceType.h
1 
2 /** @weakgroup juce_audio_devices-audio_io
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Represents a type of audio driver, such as DirectSound, ASIO, CoreAudio, etc.
33 
34  To get a list of available audio driver types, use the AudioDeviceManager::createAudioDeviceTypes()
35  method. Each of the objects returned can then be used to list the available
36  devices of that type. E.g.
37  @code
38  OwnedArray<AudioIODeviceType> types;
39  myAudioDeviceManager.createAudioDeviceTypes (types);
40 
41  for (int i = 0; i < types.size(); ++i)
42  {
43  String typeName (types[i]->getTypeName()); // This will be things like "DirectSound", "CoreAudio", etc.
44 
45  types[i]->scanForDevices(); // This must be called before getting the list of devices
46 
47  StringArray deviceNames (types[i]->getDeviceNames()); // This will now return a list of available devices of this type
48 
49  for (int j = 0; j < deviceNames.size(); ++j)
50  {
51  AudioIODevice* device = types[i]->createDevice (deviceNames [j]);
52 
53  ...
54  }
55  }
56  @endcode
57 
58  For an easier way of managing audio devices and their settings, have a look at the
59  AudioDeviceManager class.
60 
61  @see AudioIODevice, AudioDeviceManager
62 
63  @tags{Audio}
64 */
66 {
67 public:
68  //==============================================================================
69  /** Returns the name of this type of driver that this object manages.
70 
71  This will be something like "DirectSound", "ASIO", "CoreAudio", "ALSA", etc.
72  */
73  const String& getTypeName() const noexcept { return typeName; }
74 
75  //==============================================================================
76  /** Refreshes the object's cached list of known devices.
77 
78  This must be called at least once before calling getDeviceNames() or any of
79  the other device creation methods.
80  */
81  virtual void scanForDevices() = 0;
82 
83  /** Returns the list of available devices of this type.
84 
85  The scanForDevices() method must have been called to create this list.
86 
87  @param wantInputNames only really used by DirectSound where devices are split up
88  into inputs and outputs, this indicates whether to use
89  the input or output name to refer to a pair of devices.
90  */
91  virtual StringArray getDeviceNames (bool wantInputNames = false) const = 0;
92 
93  /** Returns the name of the default device.
94 
95  This will be one of the names from the getDeviceNames() list.
96 
97  @param forInput if true, this means that a default input device should be
98  returned; if false, it should return the default output
99  */
100  virtual int getDefaultDeviceIndex (bool forInput) const = 0;
101 
102  /** Returns the index of a given device in the list of device names.
103  If asInput is true, it shows the index in the inputs list, otherwise it
104  looks for it in the outputs list.
105  */
106  virtual int getIndexOfDevice (AudioIODevice* device, bool asInput) const = 0;
107 
108  /** Returns true if two different devices can be used for the input and output.
109  */
110  virtual bool hasSeparateInputsAndOutputs() const = 0;
111 
112  /** Creates one of the devices of this type.
113 
114  The deviceName must be one of the strings returned by getDeviceNames(), and
115  scanForDevices() must have been called before this method is used.
116  */
117  virtual AudioIODevice* createDevice (const String& outputDeviceName,
118  const String& inputDeviceName) = 0;
119 
120  //==============================================================================
121  /**
122  A class for receiving events when audio devices are inserted or removed.
123 
124  You can register an AudioIODeviceType::Listener with an~AudioIODeviceType object
125  using the AudioIODeviceType::addListener() method, and it will be called when
126  devices of that type are added or removed.
127 
128  @see AudioIODeviceType::addListener, AudioIODeviceType::removeListener
129  */
130  class Listener
131  {
132  public:
133  virtual ~Listener() = default;
134 
135  /** Called when the list of available audio devices changes. */
136  virtual void audioDeviceListChanged() = 0;
137  };
138 
139  /** Adds a listener that will be called when this type of device is added or
140  removed from the system.
141  */
142  void addListener (Listener* listener);
143 
144  /** Removes a listener that was previously added with addListener(). */
145  void removeListener (Listener* listener);
146 
147  //==============================================================================
148  /** Destructor. */
149  virtual ~AudioIODeviceType();
150 
151  //==============================================================================
152  /** Creates a CoreAudio device type if it's available on this platform, or returns null. */
153  static AudioIODeviceType* createAudioIODeviceType_CoreAudio();
154  /** Creates an iOS device type if it's available on this platform, or returns null. */
155  static AudioIODeviceType* createAudioIODeviceType_iOSAudio();
156  /** Creates a WASAPI device type if it's available on this platform, or returns null. */
157  static AudioIODeviceType* createAudioIODeviceType_WASAPI (bool exclusiveMode);
158  /** Creates a DirectSound device type if it's available on this platform, or returns null. */
159  static AudioIODeviceType* createAudioIODeviceType_DirectSound();
160  /** Creates an ASIO device type if it's available on this platform, or returns null. */
161  static AudioIODeviceType* createAudioIODeviceType_ASIO();
162  /** Creates an ALSA device type if it's available on this platform, or returns null. */
163  static AudioIODeviceType* createAudioIODeviceType_ALSA();
164  /** Creates a JACK device type if it's available on this platform, or returns null. */
165  static AudioIODeviceType* createAudioIODeviceType_JACK();
166  /** Creates an Android device type if it's available on this platform, or returns null. */
167  static AudioIODeviceType* createAudioIODeviceType_Android();
168  /** Creates an Android OpenSLES device type if it's available on this platform, or returns null. */
169  static AudioIODeviceType* createAudioIODeviceType_OpenSLES();
170  /** Creates an Oboe device type if it's available on this platform, or returns null. */
171  static AudioIODeviceType* createAudioIODeviceType_Oboe();
172  /** Creates a Bela device type if it's available on this platform, or returns null. */
173  static AudioIODeviceType* createAudioIODeviceType_Bela();
174 
175 protected:
176  explicit AudioIODeviceType (const String& typeName);
177 
178  /** Synchronously calls all the registered device list change listeners. */
179  void callDeviceChangeListeners();
180 
181 private:
182  String typeName;
183  ListenerList<Listener> listeners;
184 
185  JUCE_DECLARE_NON_COPYABLE (AudioIODeviceType)
186 };
187 
188 } // namespace juce
189 
190 /** @}*/
juce::StringArray
A special array for holding a list of strings.
Definition: juce_StringArray.h:38
juce::ListenerList
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Definition: juce_ListenerList.h:72
JUCE_API
#define JUCE_API
This macro is added to all JUCE public class declarations.
Definition: juce_StandardHeader.h:143
juce::AudioIODeviceType
Represents a type of audio driver, such as DirectSound, ASIO, CoreAudio, etc.
Definition: juce_AudioIODeviceType.h:65
juce::AudioIODevice
Base class for an audio device with synchronised input and output channels.
Definition: juce_AudioIODevice.h:140
juce::String
The JUCE String class!
Definition: juce_String.h:42
juce::AudioIODeviceType::getTypeName
const String & getTypeName() const noexcept
Returns the name of this type of driver that this object manages.
Definition: juce_AudioIODeviceType.h:73
juce::AudioIODeviceType::Listener
A class for receiving events when audio devices are inserted or removed.
Definition: juce_AudioIODeviceType.h:130