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.

105 lines
3.9KB

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