OpenShot Audio Library | OpenShotAudio: juce_AudioDeviceManager.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0 |

Loading...
Searching...
No Matches
juce_AudioDeviceManager.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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 {
97 String outputDeviceName;
98
102 String inputDeviceName;
103
109 double sampleRate = 0;
110
115 int bufferSize = 0;
116
122 BigInteger inputChannels;
123
128 bool useDefaultInputChannels = true;
129
135 BigInteger outputChannels;
136
141 bool useDefaultOutputChannels = true;
142
143 bool operator== (const AudioDeviceSetup&) const;
144 bool operator!= (const AudioDeviceSetup&) const;
145 };
146
147
148 //==============================================================================
182 String initialise (int numInputChannelsNeeded,
183 int numOutputChannelsNeeded,
184 const XmlElement* savedState,
185 bool selectDefaultDeviceOnFailure,
186 const String& preferredDefaultDeviceName = String(),
187 const AudioDeviceSetup* preferredSetupOptions = nullptr);
188
190 String initialiseWithDefaultDevices (int numInputChannelsNeeded,
191 int numOutputChannelsNeeded);
192
201 std::unique_ptr<XmlElement> createStateXml() const;
202
203 //==============================================================================
207 AudioDeviceSetup getAudioDeviceSetup() const;
208
214 void getAudioDeviceSetup (AudioDeviceSetup& result) const;
215
239 String setAudioDeviceSetup (const AudioDeviceSetup& newSetup, bool treatAsChosenDevice);
240
241
243 AudioIODevice* getCurrentAudioDevice() const noexcept { return currentAudioDevice.get(); }
244
248 String getCurrentAudioDeviceType() const { return currentDeviceType; }
249
254 AudioIODeviceType* getCurrentDeviceTypeObject() const;
255
263 void setCurrentAudioDeviceType (const String& type, bool treatAsChosenDevice);
264
266 AudioWorkgroup getDeviceAudioWorkgroup() const;
267
272 void closeAudioDevice();
273
282 void restartLastAudioDevice();
283
284 //==============================================================================
297 void addAudioCallback (AudioIODeviceCallback* newCallback);
298
306 void removeAudioCallback (AudioIODeviceCallback* callback);
307
308 //==============================================================================
313 double getCpuUsage() const;
314
315 //==============================================================================
335 void setMidiInputDeviceEnabled (const String& deviceIdentifier, bool enabled);
336
341 bool isMidiInputDeviceEnabled (const String& deviceIdentifier) const;
342
353 void addMidiInputDeviceCallback (const String& deviceIdentifier,
354 MidiInputCallback* callback);
355
357 void removeMidiInputDeviceCallback (const String& deviceIdentifier,
358 MidiInputCallback* callback);
359
360 //==============================================================================
373 void setDefaultMidiOutputDevice (const String& deviceIdentifier);
374
379 const String& getDefaultMidiOutputIdentifier() const noexcept { return defaultMidiOutputDeviceInfo.identifier; }
380
386 MidiOutput* getDefaultMidiOutput() const noexcept { return defaultMidiOutput.get(); }
387
388 //==============================================================================
390 const OwnedArray<AudioIODeviceType>& getAvailableDeviceTypes();
391
400 virtual void createAudioDeviceTypes (OwnedArray<AudioIODeviceType>& types);
401
403 void addAudioDeviceType (std::unique_ptr<AudioIODeviceType> newDeviceType);
404
406 void removeAudioDeviceType (AudioIODeviceType* deviceTypeToRemove);
407
408 //==============================================================================
414 void playTestSound();
415
416 //==============================================================================
426 struct LevelMeter : public ReferenceCountedObject
427 {
428 LevelMeter() noexcept;
429 double getCurrentLevel() const noexcept;
430
431 using Ptr = ReferenceCountedObjectPtr<LevelMeter>;
432
433 private:
434 friend class AudioDeviceManager;
435
436 Atomic<float> level { 0 };
437 void updateLevel (const float* const*, int numChannels, int numSamples) noexcept;
438 };
439
445 LevelMeter::Ptr getInputLevelGetter() noexcept { return inputLevelGetter; }
446
452 LevelMeter::Ptr getOutputLevelGetter() noexcept { return outputLevelGetter; }
453
454 //==============================================================================
459 CriticalSection& getAudioCallbackLock() noexcept { return audioCallbackLock; }
460
465 CriticalSection& getMidiCallbackLock() noexcept { return midiCallbackLock; }
466
467 //==============================================================================
474 int getXRunCount() const noexcept;
475
476 //==============================================================================
477 #ifndef DOXYGEN
478 [[deprecated ("Use setMidiInputDeviceEnabled instead.")]]
479 void setMidiInputEnabled (const String&, bool);
480 [[deprecated ("Use isMidiInputDeviceEnabled instead.")]]
481 bool isMidiInputEnabled (const String&) const;
482 [[deprecated ("Use addMidiInputDeviceCallback instead.")]]
483 void addMidiInputCallback (const String&, MidiInputCallback*);
484 [[deprecated ("Use removeMidiInputDeviceCallback instead.")]]
485 void removeMidiInputCallback (const String&, MidiInputCallback*);
486 [[deprecated ("Use setDefaultMidiOutputDevice instead.")]]
487 void setDefaultMidiOutput (const String&);
488 [[deprecated ("Use getDefaultMidiOutputIdentifier instead.")]]
489 const String& getDefaultMidiOutputName() const noexcept { return defaultMidiOutputDeviceInfo.name; }
490 #endif
491
492private:
493 //==============================================================================
494 OwnedArray<AudioIODeviceType> availableDeviceTypes;
495 OwnedArray<AudioDeviceSetup> lastDeviceTypeConfigs;
496
497 AudioDeviceSetup currentSetup;
498 std::unique_ptr<AudioIODevice> currentAudioDevice;
499 Array<AudioIODeviceCallback*> callbacks;
500 int numInputChansNeeded = 0, numOutputChansNeeded = 2;
501 String preferredDeviceName, currentDeviceType;
502 std::unique_ptr<XmlElement> lastExplicitSettings;
503 mutable bool listNeedsScanning = true;
504 AudioBuffer<float> tempBuffer;
505 MidiDeviceListConnection midiDeviceListConnection = MidiDeviceListConnection::make ([this]
506 {
507 midiDeviceListChanged();
508 });
509
510 struct MidiCallbackInfo
511 {
512 String deviceIdentifier;
513 MidiInputCallback* callback;
514 };
515
516 Array<MidiDeviceInfo> midiDeviceInfosFromXml;
517 std::vector<std::unique_ptr<MidiInput>> enabledMidiInputs;
518 Array<MidiCallbackInfo> midiCallbacks;
519
520 MidiDeviceInfo defaultMidiOutputDeviceInfo;
521 std::unique_ptr<MidiOutput> defaultMidiOutput;
522 CriticalSection audioCallbackLock, midiCallbackLock;
523
524 std::unique_ptr<AudioBuffer<float>> testSound;
525 int testSoundPosition = 0;
526
527 AudioProcessLoadMeasurer loadMeasurer;
528
529 LevelMeter::Ptr inputLevelGetter { new LevelMeter() },
530 outputLevelGetter { new LevelMeter() };
531
532 //==============================================================================
533 class CallbackHandler;
534 std::unique_ptr<CallbackHandler> callbackHandler;
535
536 void audioDeviceIOCallbackInt (const float* const* inputChannelData,
537 int totalNumInputChannels,
538 float* const* outputChannelData,
539 int totalNumOutputChannels,
540 int numSamples,
541 const AudioIODeviceCallbackContext& context);
542 void audioDeviceAboutToStartInt (AudioIODevice*);
543 void audioDeviceStoppedInt();
544 void audioDeviceErrorInt (const String&);
545 void handleIncomingMidiMessageInt (MidiInput*, const MidiMessage&);
546 void audioDeviceListChanged();
547 void midiDeviceListChanged();
548
549 String restartDevice (int blockSizeToUse, double sampleRateToUse,
550 const BigInteger& ins, const BigInteger& outs);
551 void stopDevice();
552
553 void updateXml();
554
555 void updateCurrentSetup();
556 void createDeviceTypesIfNeeded();
557 void scanDevicesIfNeeded();
558 void deleteCurrentDevice();
559 double chooseBestSampleRate (double preferred) const;
560 int chooseBestBufferSize (int preferred) const;
561 void insertDefaultDeviceNames (AudioDeviceSetup&) const;
562 String initialiseDefault (const String& preferredDefaultDeviceName, const AudioDeviceSetup*);
563 String initialiseFromXML (const XmlElement&, bool selectDefaultDeviceOnFailure,
564 const String& preferredDefaultDeviceName, const AudioDeviceSetup*);
565 void openLastRequestedMidiDevices (const Array<MidiDeviceInfo>&, const MidiDeviceInfo&);
566
567 AudioIODeviceType* findType (const String& inputName, const String& outputName);
568 AudioIODeviceType* findType (const String& typeName);
569 void pickCurrentDeviceTypeWithDevices();
570
571 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioDeviceManager)
572};
573
574} // namespace juce
juce::AudioDeviceManager::getDefaultMidiOutput
MidiOutput * getDefaultMidiOutput() const noexcept
Definition juce_AudioDeviceManager.h:386
juce::AudioDeviceManager::getInputLevelGetter
LevelMeter::Ptr getInputLevelGetter() noexcept
Definition juce_AudioDeviceManager.h:445
juce::AudioDeviceManager::getMidiCallbackLock
CriticalSection & getMidiCallbackLock() noexcept
Definition juce_AudioDeviceManager.h:465
juce::AudioDeviceManager::AudioDeviceManager
AudioDeviceManager()
Definition juce_AudioDeviceManager.cpp:113
juce::AudioDeviceManager::getAudioDeviceSetup
AudioDeviceSetup getAudioDeviceSetup() const
Definition juce_AudioDeviceManager.cpp:641
juce::AudioDeviceManager::getDefaultMidiOutputIdentifier
const String & getDefaultMidiOutputIdentifier() const noexcept
Definition juce_AudioDeviceManager.h:379
juce::AudioDeviceManager::setAudioDeviceSetup
String setAudioDeviceSetup(const AudioDeviceSetup &newSetup, bool treatAsChosenDevice)
Definition juce_AudioDeviceManager.cpp:718
juce::AudioDeviceManager::getOutputLevelGetter
LevelMeter::Ptr getOutputLevelGetter() noexcept
Definition juce_AudioDeviceManager.h:452
juce::AudioDeviceManager::getCurrentAudioDevice
AudioIODevice * getCurrentAudioDevice() const noexcept
Definition juce_AudioDeviceManager.h:243
juce::AudioDeviceManager::getCurrentAudioDeviceType
String getCurrentAudioDeviceType() const
Definition juce_AudioDeviceManager.h:248
juce::AudioDeviceManager::initialise
String initialise(int numInputChannelsNeeded, int numOutputChannelsNeeded, const XmlElement *savedState, bool selectDefaultDeviceOnFailure, const String &preferredDefaultDeviceName=String(), const AudioDeviceSetup *preferredSetupOptions=nullptr)
Definition juce_AudioDeviceManager.cpp:292
juce::AudioDeviceManager::getAudioCallbackLock
CriticalSection & getAudioCallbackLock() noexcept
Definition juce_AudioDeviceManager.h:459
juce::AudioDeviceManager::initialiseWithDefaultDevices
String initialiseWithDefaultDevices(int numInputChannelsNeeded, int numOutputChannelsNeeded)
Definition juce_AudioDeviceManager.cpp:497
juce::AudioDeviceManager::createStateXml
std::unique_ptr< XmlElement > createStateXml() const
Definition juce_AudioDeviceManager.cpp:596
juce::AudioIODeviceCallback
Definition juce_AudioIODevice.h:55
juce::AudioIODeviceType
Definition juce_AudioIODeviceType.h:62
juce::AudioIODevice
Definition juce_AudioIODevice.h:151
juce::AudioWorkgroup
Definition juce_AudioWorkgroup.h:142
juce::BigInteger
Definition juce_BigInteger.h:39
juce::ChangeBroadcaster::ChangeBroadcaster
ChangeBroadcaster() noexcept
Definition juce_ChangeBroadcaster.cpp:26
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::MidiInputCallback
Definition juce_MidiDevices.h:277
juce::MidiOutput
Definition juce_MidiDevices.h:325
juce::OwnedArray
Definition juce_OwnedArray.h:50
juce::ReferenceCountedObjectPtr
Definition juce_ReferenceCountedObject.h:247
juce::ReferenceCountedObject::ReferenceCountedObject
ReferenceCountedObject()=default
juce::String
Definition juce_String.h:53
juce::XmlElement
Definition juce_XmlElement.h:83
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:97
juce::AudioDeviceManager::AudioDeviceSetup::useDefaultInputChannels
bool useDefaultInputChannels
Definition juce_AudioDeviceManager.h:128
juce::AudioDeviceManager::AudioDeviceSetup::inputDeviceName
String inputDeviceName
Definition juce_AudioDeviceManager.h:102
juce::AudioDeviceManager::AudioDeviceSetup::outputChannels
BigInteger outputChannels
Definition juce_AudioDeviceManager.h:135
juce::AudioDeviceManager::AudioDeviceSetup::sampleRate
double sampleRate
Definition juce_AudioDeviceManager.h:109
juce::AudioDeviceManager::AudioDeviceSetup::inputChannels
BigInteger inputChannels
Definition juce_AudioDeviceManager.h:122
juce::AudioDeviceManager::AudioDeviceSetup::bufferSize
int bufferSize
Definition juce_AudioDeviceManager.h:115
juce::AudioDeviceManager::AudioDeviceSetup::useDefaultOutputChannels
bool useDefaultOutputChannels
Definition juce_AudioDeviceManager.h:141