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.

89 lines
3.4KB

  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. virtual void prepareToPlay (int samplesPerBlockExpected,
  35. double sampleRate) = 0;
  36. /** Allows the source to release anything it no longer needs after playback has stopped.
  37. This will be called when the source is no longer going to have its getNextAudioBlock()
  38. method called, so it should release any spare memory, etc. that it might have
  39. allocated during the prepareToPlay() call.
  40. Note that there's no guarantee that prepareToPlay() will actually have been called before
  41. releaseResources(), and it may be called more than once in succession, so make sure your
  42. code is robust and doesn't make any assumptions about when it will be called.
  43. @see prepareToPlay, getNextAudioBlock
  44. */
  45. virtual void releaseResources() = 0;
  46. /** Called repeatedly to fetch subsequent blocks of audio data.
  47. After calling the prepareToPlay() method, this callback will be made each
  48. time the audio playback hardware (or whatever other destination the audio
  49. data is going to) needs another block of data.
  50. It will generally be called on a high-priority system thread, or possibly even
  51. an interrupt, so be careful not to do too much work here, as that will cause
  52. audio glitches!
  53. @see AudioSourceChannelInfo, prepareToPlay, releaseResources
  54. */
  55. virtual void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) = 0;
  56. AudioDeviceManager deviceManager;
  57. private:
  58. //==============================================================================
  59. AudioSourcePlayer audioSourcePlayer;
  60. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioAppComponent)
  61. };
  62. #endif // JUCE_AUDIOAPPCOMPONENT_H_INCLUDED