The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. AudioAppComponent::AudioAppComponent()
  21. : deviceManager (defaultDeviceManager),
  22. usingCustomDeviceManager (false)
  23. {
  24. }
  25. AudioAppComponent::AudioAppComponent (AudioDeviceManager& adm)
  26. : deviceManager (adm),
  27. usingCustomDeviceManager (true)
  28. {
  29. }
  30. AudioAppComponent::~AudioAppComponent()
  31. {
  32. // If you hit this then your derived class must call shutdown audio in
  33. // destructor!
  34. jassert (audioSourcePlayer.getCurrentSource() == nullptr);
  35. }
  36. void AudioAppComponent::setAudioChannels (int numInputChannels, int numOutputChannels, const XmlElement* const xml)
  37. {
  38. String audioError;
  39. if (usingCustomDeviceManager && xml == nullptr)
  40. {
  41. auto setup = deviceManager.getAudioDeviceSetup();
  42. if (setup.inputChannels.countNumberOfSetBits() != numInputChannels
  43. || setup.outputChannels.countNumberOfSetBits() != numOutputChannels)
  44. {
  45. setup.inputChannels.clear();
  46. setup.outputChannels.clear();
  47. setup.inputChannels.setRange (0, numInputChannels, true);
  48. setup.outputChannels.setRange (0, numOutputChannels, true);
  49. audioError = deviceManager.setAudioDeviceSetup (setup, false);
  50. }
  51. }
  52. else
  53. {
  54. audioError = deviceManager.initialise (numInputChannels, numOutputChannels, xml, true);
  55. }
  56. jassert (audioError.isEmpty());
  57. deviceManager.addAudioCallback (&audioSourcePlayer);
  58. audioSourcePlayer.setSource (this);
  59. }
  60. void AudioAppComponent::shutdownAudio()
  61. {
  62. audioSourcePlayer.setSource (nullptr);
  63. deviceManager.removeAudioCallback (&audioSourcePlayer);
  64. // other audio callbacks may still be using the device
  65. if (! usingCustomDeviceManager)
  66. deviceManager.closeAudioDevice();
  67. }
  68. } // namespace juce