OpenShot Audio Library | OpenShotAudio: juce_AudioDeviceManager.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.1

Loading...
Searching...
No Matches
juce_AudioDeviceManager.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
66 class JUCE_API AudioDeviceManager : public ChangeBroadcaster
67{
68public:
69 //==============================================================================
76 AudioDeviceManager();
77
79 ~AudioDeviceManager() override;
80
81 //==============================================================================
90 struct JUCE_API AudioDeviceSetup
91 {
98 String outputDeviceName;
99
104 String inputDeviceName;
105
111 double sampleRate = 0;
112
117 int bufferSize = 0;
118
124 BigInteger inputChannels;
125
130 bool useDefaultInputChannels = true;
131
137 BigInteger outputChannels;
138
143 bool useDefaultOutputChannels = true;
144
145 bool operator== (const AudioDeviceSetup&) const;
146 bool operator!= (const AudioDeviceSetup&) const;
147 };
148
149
150 //==============================================================================
181 String initialise (int numInputChannelsNeeded,
182 int numOutputChannelsNeeded,
183 const XmlElement* savedState,
184 bool selectDefaultDeviceOnFailure,
185 const String& preferredDefaultDeviceName = String(),
186 const AudioDeviceSetup* preferredSetupOptions = nullptr);
187
189 String initialiseWithDefaultDevices (int numInputChannelsNeeded,
190 int numOutputChannelsNeeded);
191
200 std::unique_ptr<XmlElement> createStateXml() const;
201
202 //==============================================================================
206 AudioDeviceSetup getAudioDeviceSetup() const;
207
213 void getAudioDeviceSetup (AudioDeviceSetup& result) const;
214
234 String setAudioDeviceSetup (const AudioDeviceSetup& newSetup, bool treatAsChosenDevice);
235
236
238 AudioIODevice* getCurrentAudioDevice() const noexcept { return currentAudioDevice.get(); }
239
243 String getCurrentAudioDeviceType() const { return currentDeviceType; }
244
249 AudioIODeviceType* getCurrentDeviceTypeObject() const;
250
258 void setCurrentAudioDeviceType (const String& type, bool treatAsChosenDevice);
259
264 void closeAudioDevice();
265
274 void restartLastAudioDevice();
275
276 //==============================================================================
289 void addAudioCallback (AudioIODeviceCallback* newCallback);
290
298 void removeAudioCallback (AudioIODeviceCallback* callback);
299
300 //==============================================================================
305 double getCpuUsage() const;
306
307 //==============================================================================
327 void setMidiInputDeviceEnabled (const String& deviceIdentifier, bool enabled);
328
333 bool isMidiInputDeviceEnabled (const String& deviceIdentifier) const;
334
345 void addMidiInputDeviceCallback (const String& deviceIdentifier,
346 MidiInputCallback* callback);
347
349 void removeMidiInputDeviceCallback (const String& deviceIdentifier,
350 MidiInputCallback* callback);
351
352 //==============================================================================
365 void setDefaultMidiOutputDevice (const String& deviceIdentifier);
366
371 const String& getDefaultMidiOutputIdentifier() const noexcept { return defaultMidiOutputDeviceInfo.identifier; }
372
378 MidiOutput* getDefaultMidiOutput() const noexcept { return defaultMidiOutput.get(); }
379
380 //==============================================================================
382 const OwnedArray<AudioIODeviceType>& getAvailableDeviceTypes();
383
392 virtual void createAudioDeviceTypes (OwnedArray<AudioIODeviceType>& types);
393
395 void addAudioDeviceType (std::unique_ptr<AudioIODeviceType> newDeviceType);
396
398 void removeAudioDeviceType (AudioIODeviceType* deviceTypeToRemove);
399
400 //==============================================================================
406 void playTestSound();
407
408 //==============================================================================
418 struct LevelMeter : public ReferenceCountedObject
419 {
420 LevelMeter() noexcept;
421 double getCurrentLevel() const noexcept;
422
423 using Ptr = ReferenceCountedObjectPtr<LevelMeter>;
424
425 private:
426 friend class AudioDeviceManager;
427
428 Atomic<float> level { 0 };
429 void updateLevel (const float* const*, int numChannels, int numSamples) noexcept;
430 };
431
437 LevelMeter::Ptr getInputLevelGetter() noexcept { return inputLevelGetter; }
438
444 LevelMeter::Ptr getOutputLevelGetter() noexcept { return outputLevelGetter; }
445
446 //==============================================================================
451 CriticalSection& getAudioCallbackLock() noexcept { return audioCallbackLock; }
452
457 CriticalSection& getMidiCallbackLock() noexcept { return midiCallbackLock; }
458
459 //==============================================================================
466 int getXRunCount() const noexcept;
467
468 //==============================================================================
470 void setMidiInputEnabled (const String&, bool);
472 bool isMidiInputEnabled (const String&) const;
474 void addMidiInputCallback (const String&, MidiInputCallback*);
476 void removeMidiInputCallback (const String&, MidiInputCallback*);
478 void setDefaultMidiOutput (const String&);
480 const String& getDefaultMidiOutputName() const noexcept { return defaultMidiOutputDeviceInfo.name; }
481
482private:
483 //==============================================================================
484 OwnedArray<AudioIODeviceType> availableDeviceTypes;
485 OwnedArray<AudioDeviceSetup> lastDeviceTypeConfigs;
486
487 AudioDeviceSetup currentSetup;
488 std::unique_ptr<AudioIODevice> currentAudioDevice;
489 Array<AudioIODeviceCallback*> callbacks;
490 int numInputChansNeeded = 0, numOutputChansNeeded = 2;
491 String preferredDeviceName, currentDeviceType;
492 std::unique_ptr<XmlElement> lastExplicitSettings;
493 mutable bool listNeedsScanning = true;
494 AudioBuffer<float> tempBuffer;
495
496 struct MidiCallbackInfo
497 {
498 String deviceIdentifier;
499 MidiInputCallback* callback;
500 };
501
502 Array<MidiDeviceInfo> midiDeviceInfosFromXml;
503 std::vector<std::unique_ptr<MidiInput>> enabledMidiInputs;
504 Array<MidiCallbackInfo> midiCallbacks;
505
506 MidiDeviceInfo defaultMidiOutputDeviceInfo;
507 std::unique_ptr<MidiOutput> defaultMidiOutput;
508 CriticalSection audioCallbackLock, midiCallbackLock;
509
510 std::unique_ptr<AudioBuffer<float>> testSound;
511 int testSoundPosition = 0;
512
513 AudioProcessLoadMeasurer loadMeasurer;
514
515 LevelMeter::Ptr inputLevelGetter { new LevelMeter() },
516 outputLevelGetter { new LevelMeter() };
517
518 //==============================================================================
519 class CallbackHandler;
520 std::unique_ptr<CallbackHandler> callbackHandler;
521
522 void audioDeviceIOCallbackInt (const float** inputChannelData, int totalNumInputChannels,
523 float** outputChannelData, int totalNumOutputChannels, int numSamples);
524 void audioDeviceAboutToStartInt (AudioIODevice*);
525 void audioDeviceStoppedInt();
526 void audioDeviceErrorInt (const String&);
527 void handleIncomingMidiMessageInt (MidiInput*, const MidiMessage&);
528 void audioDeviceListChanged();
529
530 String restartDevice (int blockSizeToUse, double sampleRateToUse,
531 const BigInteger& ins, const BigInteger& outs);
532 void stopDevice();
533
534 void updateXml();
535
536 void createDeviceTypesIfNeeded();
537 void scanDevicesIfNeeded();
538 void deleteCurrentDevice();
539 double chooseBestSampleRate (double preferred) const;
540 int chooseBestBufferSize (int preferred) const;
541 void insertDefaultDeviceNames (AudioDeviceSetup&) const;
542 String initialiseDefault (const String& preferredDefaultDeviceName, const AudioDeviceSetup*);
543 String initialiseFromXML (const XmlElement&, bool selectDefaultDeviceOnFailure,
544 const String& preferredDefaultDeviceName, const AudioDeviceSetup*);
545
546 AudioIODeviceType* findType (const String& inputName, const String& outputName);
547 AudioIODeviceType* findType (const String& typeName);
548
549 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioDeviceManager)
550};
551
552} // namespace juce
juce::Array
Definition: juce_Array.h:56
juce::AudioBuffer
Definition: juce_AudioSampleBuffer.h:34
juce::AudioDeviceManager
Definition: juce_AudioDeviceManager.h:67
juce::AudioDeviceManager::getDefaultMidiOutput
MidiOutput * getDefaultMidiOutput() const noexcept
Definition: juce_AudioDeviceManager.h:378
juce::AudioDeviceManager::getInputLevelGetter
LevelMeter::Ptr getInputLevelGetter() noexcept
Definition: juce_AudioDeviceManager.h:437
juce::AudioDeviceManager::getMidiCallbackLock
CriticalSection & getMidiCallbackLock() noexcept
Definition: juce_AudioDeviceManager.h:457
juce::AudioDeviceManager::getDefaultMidiOutputIdentifier
const String & getDefaultMidiOutputIdentifier() const noexcept
Definition: juce_AudioDeviceManager.h:371
juce::AudioDeviceManager::getOutputLevelGetter
LevelMeter::Ptr getOutputLevelGetter() noexcept
Definition: juce_AudioDeviceManager.h:444
juce::AudioDeviceManager::getCurrentAudioDevice
AudioIODevice * getCurrentAudioDevice() const noexcept
Definition: juce_AudioDeviceManager.h:238
juce::AudioDeviceManager::getCurrentAudioDeviceType
String getCurrentAudioDeviceType() const
Definition: juce_AudioDeviceManager.h:243
juce::AudioDeviceManager::getAudioCallbackLock
CriticalSection & getAudioCallbackLock() noexcept
Definition: juce_AudioDeviceManager.h:451
juce::AudioIODeviceCallback
Definition: juce_AudioIODevice.h:43
juce::AudioIODeviceType
Definition: juce_AudioIODeviceType.h:62
juce::AudioIODevice
Definition: juce_AudioIODevice.h:137
juce::BigInteger
Definition: juce_BigInteger.h:39
juce::ChangeBroadcaster
Definition: juce_ChangeBroadcaster.h:35
juce::CriticalSection
Definition: juce_CriticalSection.h:43
juce::MidiInputCallback
Definition: juce_MidiDevices.h:189
juce::MidiOutput
Definition: juce_MidiDevices.h:240
juce::OwnedArray
Definition: juce_OwnedArray.h:51
juce::ReferenceCountedObjectPtr< LevelMeter >
juce::ReferenceCountedObject
Definition: juce_ReferenceCountedObject.h:66
juce::String
Definition: juce_String.h:39
juce::XmlElement
Definition: juce_XmlElement.h:138
juce::Atomic
Definition: juce_Atomic.h:42
juce::AudioDeviceManager::AudioDeviceSetup
Definition: juce_AudioDeviceManager.h:91
juce::AudioDeviceManager::AudioDeviceSetup::outputDeviceName
String outputDeviceName
Definition: juce_AudioDeviceManager.h:98
juce::AudioDeviceManager::AudioDeviceSetup::inputDeviceName
String inputDeviceName
Definition: juce_AudioDeviceManager.h:104
juce::AudioDeviceManager::AudioDeviceSetup::outputChannels
BigInteger outputChannels
Definition: juce_AudioDeviceManager.h:137
juce::AudioDeviceManager::AudioDeviceSetup::inputChannels
BigInteger inputChannels
Definition: juce_AudioDeviceManager.h:124
juce::AudioDeviceManager::LevelMeter
Definition: juce_AudioDeviceManager.h:419