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.

114 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A base class for writing audio apps that stream from the audio i/o devices.
  21. A subclass can inherit from this and implement just a few methods such as
  22. getNextAudioBlock(). The base class provides a basic AudioDeviceManager object
  23. and runs audio through the default output device.
  24. */
  25. class JUCE_API AudioAppComponent : public Component,
  26. public AudioSource
  27. {
  28. public:
  29. AudioAppComponent();
  30. ~AudioAppComponent();
  31. /** A subclass should call this from their constructor, to set up the audio. */
  32. void setAudioChannels (int numInputChannels, int numOutputChannels, const XmlElement* const storedSettings = nullptr);
  33. /** Tells the source to prepare for playing.
  34. An AudioSource has two states: prepared and unprepared.
  35. The prepareToPlay() method is guaranteed to be called at least once on an 'unpreprared'
  36. source to put it into a 'prepared' state before any calls will be made to getNextAudioBlock().
  37. This callback allows the source to initialise any resources it might need when playing.
  38. Once playback has finished, the releaseResources() method is called to put the stream
  39. back into an 'unprepared' state.
  40. Note that this method could be called more than once in succession without
  41. a matching call to releaseResources(), so make sure your code is robust and
  42. can handle that kind of situation.
  43. @param samplesPerBlockExpected the number of samples that the source
  44. will be expected to supply each time its
  45. getNextAudioBlock() method is called. This
  46. number may vary slightly, because it will be dependent
  47. on audio hardware callbacks, and these aren't
  48. guaranteed to always use a constant block size, so
  49. the source should be able to cope with small variations.
  50. @param sampleRate the sample rate that the output will be used at - this
  51. is needed by sources such as tone generators.
  52. @see releaseResources, getNextAudioBlock
  53. */
  54. virtual void prepareToPlay (int samplesPerBlockExpected,
  55. double sampleRate) = 0;
  56. /** Allows the source to release anything it no longer needs after playback has stopped.
  57. This will be called when the source is no longer going to have its getNextAudioBlock()
  58. method called, so it should release any spare memory, etc. that it might have
  59. allocated during the prepareToPlay() call.
  60. Note that there's no guarantee that prepareToPlay() will actually have been called before
  61. releaseResources(), and it may be called more than once in succession, so make sure your
  62. code is robust and doesn't make any assumptions about when it will be called.
  63. @see prepareToPlay, getNextAudioBlock
  64. */
  65. virtual void releaseResources() = 0;
  66. /** Called repeatedly to fetch subsequent blocks of audio data.
  67. After calling the prepareToPlay() method, this callback will be made each
  68. time the audio playback hardware (or whatever other destination the audio
  69. data is going to) needs another block of data.
  70. It will generally be called on a high-priority system thread, or possibly even
  71. an interrupt, so be careful not to do too much work here, as that will cause
  72. audio glitches!
  73. @see AudioSourceChannelInfo, prepareToPlay, releaseResources
  74. */
  75. virtual void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) = 0;
  76. void shutdownAudio();
  77. AudioDeviceManager deviceManager;
  78. private:
  79. //==============================================================================
  80. AudioSourcePlayer audioSourcePlayer;
  81. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioAppComponent)
  82. };