openshot-audio  0.1.2
juce_AudioDeviceManager.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_AUDIODEVICEMANAGER_H_INCLUDED
26 #define JUCE_AUDIODEVICEMANAGER_H_INCLUDED
27 
28 
29 //==============================================================================
68 {
69 public:
70  //==============================================================================
78 
81 
82  //==============================================================================
92  {
100 
101  bool operator== (const AudioDeviceSetup& other) const;
102 
110 
116 
122  double sampleRate;
123 
129 
136 
142 
149 
155  };
156 
157 
158  //==============================================================================
189  String initialise (int numInputChannelsNeeded,
190  int numOutputChannelsNeeded,
191  const XmlElement* savedState,
192  bool selectDefaultDeviceOnFailure,
193  const String& preferredDefaultDeviceName = String(),
194  const AudioDeviceSetup* preferredSetupOptions = nullptr);
195 
197  String initialiseWithDefaultDevices (int numInputChannelsNeeded,
198  int numOutputChannelsNeeded);
199 
208  XmlElement* createStateXml() const;
209 
210  //==============================================================================
214  void getAudioDeviceSetup (AudioDeviceSetup& result);
215 
235  String setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
236  bool treatAsChosenDevice);
237 
238 
240  AudioIODevice* getCurrentAudioDevice() const noexcept { return currentAudioDevice; }
241 
245  String getCurrentAudioDeviceType() const { return currentDeviceType; }
246 
251  AudioIODeviceType* getCurrentDeviceTypeObject() const;
252 
260  void setCurrentAudioDeviceType (const String& type,
261  bool treatAsChosenDevice);
262 
267  void closeAudioDevice();
268 
277  void restartLastAudioDevice();
278 
279  //==============================================================================
292  void addAudioCallback (AudioIODeviceCallback* newCallback);
293 
301  void removeAudioCallback (AudioIODeviceCallback* callback);
302 
303  //==============================================================================
308  double getCpuUsage() const;
309 
310  //==============================================================================
330  void setMidiInputEnabled (const String& midiInputDeviceName, bool enabled);
331 
335  bool isMidiInputEnabled (const String& midiInputDeviceName) const;
336 
347  void addMidiInputCallback (const String& midiInputDeviceName,
348  MidiInputCallback* callback);
349 
351  void removeMidiInputCallback (const String& midiInputDeviceName,
352  MidiInputCallback* callback);
353 
354  //==============================================================================
367  void setDefaultMidiOutput (const String& deviceName);
368 
372  const String& getDefaultMidiOutputName() const noexcept { return defaultMidiOutputName; }
373 
378  MidiOutput* getDefaultMidiOutput() const noexcept { return defaultMidiOutput; }
379 
381  const OwnedArray<AudioIODeviceType>& getAvailableDeviceTypes();
382 
383  //==============================================================================
392  virtual void createAudioDeviceTypes (OwnedArray<AudioIODeviceType>& types);
393 
397  void addAudioDeviceType (AudioIODeviceType* newDeviceType);
398 
399  //==============================================================================
405  void playTestSound();
406 
420  void enableInputLevelMeasurement (bool enableMeasurement);
421 
426  double getCurrentInputLevel() const;
427 
432  CriticalSection& getAudioCallbackLock() noexcept { return audioCallbackLock; }
433 
438  CriticalSection& getMidiCallbackLock() noexcept { return midiCallbackLock; }
439 
440 private:
441  //==============================================================================
442  OwnedArray<AudioIODeviceType> availableDeviceTypes;
443  OwnedArray<AudioDeviceSetup> lastDeviceTypeConfigs;
444 
445  AudioDeviceSetup currentSetup;
446  ScopedPointer<AudioIODevice> currentAudioDevice;
448  int numInputChansNeeded, numOutputChansNeeded;
449  String currentDeviceType;
450  BigInteger inputChannels, outputChannels;
451  ScopedPointer<XmlElement> lastExplicitSettings;
452  mutable bool listNeedsScanning;
453  Atomic<int> inputLevelMeasurementEnabledCount;
454  double inputLevel;
456  int testSoundPosition;
457  AudioSampleBuffer tempBuffer;
458 
459  struct MidiCallbackInfo
460  {
461  String deviceName;
462  MidiInputCallback* callback;
463  };
464 
465  StringArray midiInsFromXml;
466  OwnedArray<MidiInput> enabledMidiInputs;
467  Array<MidiCallbackInfo> midiCallbacks;
468 
469  String defaultMidiOutputName;
470  ScopedPointer<MidiOutput> defaultMidiOutput;
471  CriticalSection audioCallbackLock, midiCallbackLock;
472 
473  double cpuUsageMs, timeToCpuScale;
474 
475  //==============================================================================
477  friend class CallbackHandler;
479  ScopedPointer<CallbackHandler> callbackHandler;
480 
481  void audioDeviceIOCallbackInt (const float** inputChannelData, int totalNumInputChannels,
482  float** outputChannelData, int totalNumOutputChannels, int numSamples);
483  void audioDeviceAboutToStartInt (AudioIODevice*);
484  void audioDeviceStoppedInt();
485  void audioDeviceErrorInt (const String&);
486  void handleIncomingMidiMessageInt (MidiInput*, const MidiMessage&);
487  void audioDeviceListChanged();
488 
489  String restartDevice (int blockSizeToUse, double sampleRateToUse,
490  const BigInteger& ins, const BigInteger& outs);
491  void stopDevice();
492 
493  void updateXml();
494 
495  void createDeviceTypesIfNeeded();
496  void scanDevicesIfNeeded();
497  void deleteCurrentDevice();
498  double chooseBestSampleRate (double preferred) const;
499  int chooseBestBufferSize (int preferred) const;
500  void insertDefaultDeviceNames (AudioDeviceSetup&) const;
501  String initialiseDefault (const String& preferredDefaultDeviceName, const AudioDeviceSetup*);
502  String initialiseFromXML (const XmlElement&, bool selectDefaultDeviceOnFailure,
503  const String& preferredDefaultDeviceName, const AudioDeviceSetup*);
504 
505  AudioIODeviceType* findType (const String& inputName, const String& outputName);
506  AudioIODeviceType* findType (const String& typeName);
507 
509 };
510 
511 #endif // JUCE_AUDIODEVICEMANAGER_H_INCLUDED
Definition: juce_AudioSampleBuffer.h:34
Definition: juce_BigInteger.h:43
BigInteger inputChannels
Definition: juce_AudioDeviceManager.h:135
const String & getDefaultMidiOutputName() const noexcept
Definition: juce_AudioDeviceManager.h:372
Definition: juce_AudioIODevice.h:42
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_Atomic.h:41
Definition: juce_AudioDeviceManager.cpp:46
BigInteger outputChannels
Definition: juce_AudioDeviceManager.h:148
Definition: juce_String.h:43
Definition: juce_MidiOutput.h:38
Definition: juce_ChangeBroadcaster.h:35
String outputDeviceName
Definition: juce_AudioDeviceManager.h:109
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_AudioDeviceManager.h:67
String getCurrentAudioDeviceType() const
Definition: juce_AudioDeviceManager.h:245
#define const
int bufferSize
Definition: juce_AudioDeviceManager.h:128
Definition: juce_MidiInput.h:91
Definition: juce_CriticalSection.h:47
String inputDeviceName
Definition: juce_AudioDeviceManager.h:115
Definition: juce_XmlElement.h:142
CriticalSection & getMidiCallbackLock() noexcept
Definition: juce_AudioDeviceManager.h:438
MidiOutput * getDefaultMidiOutput() const noexcept
Definition: juce_AudioDeviceManager.h:378
double sampleRate
Definition: juce_AudioDeviceManager.h:122
bool useDefaultInputChannels
Definition: juce_AudioDeviceManager.h:141
Definition: juce_MidiInput.h:40
Definition: juce_StringArray.h:39
bool operator==(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:565
Definition: juce_ContainerDeletePolicy.h:44
Definition: juce_AudioIODeviceType.h:62
CriticalSection & getAudioCallbackLock() noexcept
Definition: juce_AudioDeviceManager.h:432
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
AudioIODevice * getCurrentAudioDevice() const noexcept
Definition: juce_AudioDeviceManager.h:240
Definition: juce_MidiMessage.h:35
bool useDefaultOutputChannels
Definition: juce_AudioDeviceManager.h:154
Definition: juce_AudioIODevice.h:132
Definition: juce_AudioDeviceManager.h:91