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.

106 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
  19. #define __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
  20. #include "../../juce_audio_processors/processors/juce_AudioProcessor.h"
  21. //==============================================================================
  22. /**
  23. An AudioIODeviceCallback object which streams audio through an AudioProcessor.
  24. To use one of these, just make it the callback used by your AudioIODevice, and
  25. give it a processor to use by calling setProcessor().
  26. It's also a MidiInputCallback, so you can connect it to both an audio and midi
  27. input to send both streams through the processor.
  28. @see AudioProcessor, AudioProcessorGraph
  29. */
  30. class JUCE_API AudioProcessorPlayer : public AudioIODeviceCallback,
  31. public MidiInputCallback
  32. {
  33. public:
  34. //==============================================================================
  35. AudioProcessorPlayer();
  36. /** Destructor. */
  37. virtual ~AudioProcessorPlayer();
  38. //==============================================================================
  39. /** Sets the processor that should be played.
  40. The processor that is passed in will not be deleted or owned by this object.
  41. To stop anything playing, pass in 0 to this method.
  42. */
  43. void setProcessor (AudioProcessor* processorToPlay);
  44. /** Returns the current audio processor that is being played.
  45. */
  46. AudioProcessor* getCurrentProcessor() const { return processor; }
  47. /** Returns a midi message collector that you can pass midi messages to if you
  48. want them to be injected into the midi stream that is being sent to the
  49. processor.
  50. */
  51. MidiMessageCollector& getMidiMessageCollector() { return messageCollector; }
  52. //==============================================================================
  53. /** @internal */
  54. void audioDeviceIOCallback (const float** inputChannelData,
  55. int totalNumInputChannels,
  56. float** outputChannelData,
  57. int totalNumOutputChannels,
  58. int numSamples);
  59. /** @internal */
  60. void audioDeviceAboutToStart (AudioIODevice* device);
  61. /** @internal */
  62. void audioDeviceStopped();
  63. /** @internal */
  64. void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message);
  65. private:
  66. //==============================================================================
  67. AudioProcessor* processor;
  68. CriticalSection lock;
  69. double sampleRate;
  70. int blockSize;
  71. bool isPrepared;
  72. int numInputChans, numOutputChans;
  73. float* channels [128];
  74. AudioSampleBuffer tempBuffer;
  75. MidiBuffer incomingMidi;
  76. MidiMessageCollector messageCollector;
  77. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessorPlayer);
  78. };
  79. #endif // __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__