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.

118 lines
5.0KB

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