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.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_AUDIOAPPCOMPONENT_H_INCLUDED
  18. #define JUCE_AUDIOAPPCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A base class for writing audio apps that stream from the audio i/o devices.
  22. A subclass can inherit from this and implement just a few methods such as
  23. renderAudio(). The base class provides a basic AudioDeviceManager object
  24. and runs audio through the
  25. */
  26. class AudioAppComponent : public Component,
  27. public AudioSource
  28. {
  29. public:
  30. AudioAppComponent();
  31. ~AudioAppComponent();
  32. /** A subclass should call this from their constructor, to set up the audio. */
  33. void setAudioChannels (int numInputChannels, int numOutputChannels);
  34. /** Tells the source to prepare for playing.
  35. An AudioSource has two states: prepared and unprepared.
  36. The prepareToPlay() method is guaranteed to be called at least once on an 'unpreprared'
  37. source to put it into a 'prepared' state before any calls will be made to getNextAudioBlock().
  38. This callback allows the source to initialise any resources it might need when playing.
  39. Once playback has finished, the releaseResources() method is called to put the stream
  40. back into an 'unprepared' state.
  41. Note that this method could be called more than once in succession without
  42. a matching call to releaseResources(), so make sure your code is robust and
  43. can handle that kind of situation.
  44. @param samplesPerBlockExpected the number of samples that the source
  45. will be expected to supply each time its
  46. getNextAudioBlock() method is called. This
  47. number may vary slightly, because it will be dependent
  48. on audio hardware callbacks, and these aren't
  49. guaranteed to always use a constant block size, so
  50. the source should be able to cope with small variations.
  51. @param sampleRate the sample rate that the output will be used at - this
  52. is needed by sources such as tone generators.
  53. @see releaseResources, getNextAudioBlock
  54. */
  55. virtual void prepareToPlay (int samplesPerBlockExpected,
  56. double sampleRate) = 0;
  57. /** Allows the source to release anything it no longer needs after playback has stopped.
  58. This will be called when the source is no longer going to have its getNextAudioBlock()
  59. method called, so it should release any spare memory, etc. that it might have
  60. allocated during the prepareToPlay() call.
  61. Note that there's no guarantee that prepareToPlay() will actually have been called before
  62. releaseResources(), and it may be called more than once in succession, so make sure your
  63. code is robust and doesn't make any assumptions about when it will be called.
  64. @see prepareToPlay, getNextAudioBlock
  65. */
  66. virtual void releaseResources() = 0;
  67. /** Called repeatedly to fetch subsequent blocks of audio data.
  68. After calling the prepareToPlay() method, this callback will be made each
  69. time the audio playback hardware (or whatever other destination the audio
  70. data is going to) needs another block of data.
  71. It will generally be called on a high-priority system thread, or possibly even
  72. an interrupt, so be careful not to do too much work here, as that will cause
  73. audio glitches!
  74. @see AudioSourceChannelInfo, prepareToPlay, releaseResources
  75. */
  76. virtual void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) = 0;
  77. void shutdownAudio();
  78. AudioDeviceManager deviceManager;
  79. private:
  80. //==============================================================================
  81. AudioSourcePlayer audioSourcePlayer;
  82. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioAppComponent)
  83. };
  84. #endif // JUCE_AUDIOAPPCOMPONENT_H_INCLUDED