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.

98 lines
3.6KB

  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_AUDIOPROCESSORPLAYER_H_INCLUDED
  18. #define JUCE_AUDIOPROCESSORPLAYER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An AudioIODeviceCallback object which streams audio through an AudioProcessor.
  22. To use one of these, just make it the callback used by your AudioIODevice, and
  23. give it a processor to use by calling setProcessor().
  24. It's also a MidiInputCallback, so you can connect it to both an audio and midi
  25. input to send both streams through the processor.
  26. @see AudioProcessor, AudioProcessorGraph
  27. */
  28. class JUCE_API AudioProcessorPlayer : public AudioIODeviceCallback,
  29. public MidiInputCallback
  30. {
  31. public:
  32. //==============================================================================
  33. AudioProcessorPlayer();
  34. /** Destructor. */
  35. virtual ~AudioProcessorPlayer();
  36. //==============================================================================
  37. /** Sets the processor that should be played.
  38. The processor that is passed in will not be deleted or owned by this object.
  39. To stop anything playing, pass a nullptr to this method.
  40. */
  41. void setProcessor (AudioProcessor* processorToPlay);
  42. /** Returns the current audio processor that is being played. */
  43. AudioProcessor* getCurrentProcessor() const noexcept { return processor; }
  44. /** Returns a midi message collector that you can pass midi messages to if you
  45. want them to be injected into the midi stream that is being sent to the
  46. processor.
  47. */
  48. MidiMessageCollector& getMidiMessageCollector() noexcept { return messageCollector; }
  49. //==============================================================================
  50. /** @internal */
  51. void audioDeviceIOCallback (const float**, int, float**, int, int) override;
  52. /** @internal */
  53. void audioDeviceAboutToStart (AudioIODevice*) override;
  54. /** @internal */
  55. void audioDeviceStopped() override;
  56. /** @internal */
  57. void handleIncomingMidiMessage (MidiInput*, const MidiMessage&) override;
  58. private:
  59. //==============================================================================
  60. AudioProcessor* processor;
  61. CriticalSection lock;
  62. double sampleRate;
  63. int blockSize;
  64. bool isPrepared;
  65. int numInputChans, numOutputChans;
  66. HeapBlock<float*> channels;
  67. AudioSampleBuffer tempBuffer;
  68. MidiBuffer incomingMidi;
  69. MidiMessageCollector messageCollector;
  70. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessorPlayer)
  71. };
  72. #endif // JUCE_AUDIOPROCESSORPLAYER_H_INCLUDED