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.

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