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.

83 lines
2.4KB

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