mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
First check-in of the "jucequake": a major re-organisation of the library to break it up into modules. For more details about this, see the website forum..
This commit is contained in:
parent
1a21c89755
commit
b70e0a28d2
1527 changed files with 90380 additions and 396643 deletions
187
modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp
Normal file
187
modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
BEGIN_JUCE_NAMESPACE
|
||||
|
||||
//==============================================================================
|
||||
AudioProcessorPlayer::AudioProcessorPlayer()
|
||||
: processor (nullptr),
|
||||
sampleRate (0),
|
||||
blockSize (0),
|
||||
isPrepared (false),
|
||||
numInputChans (0),
|
||||
numOutputChans (0),
|
||||
tempBuffer (1, 1)
|
||||
{
|
||||
}
|
||||
|
||||
AudioProcessorPlayer::~AudioProcessorPlayer()
|
||||
{
|
||||
setProcessor (nullptr);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
|
||||
{
|
||||
if (processor != processorToPlay)
|
||||
{
|
||||
if (processorToPlay != nullptr && sampleRate > 0 && blockSize > 0)
|
||||
{
|
||||
processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
|
||||
sampleRate, blockSize);
|
||||
|
||||
processorToPlay->prepareToPlay (sampleRate, blockSize);
|
||||
}
|
||||
|
||||
AudioProcessor* oldOne;
|
||||
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
oldOne = isPrepared ? processor : nullptr;
|
||||
processor = processorToPlay;
|
||||
isPrepared = true;
|
||||
}
|
||||
|
||||
if (oldOne != nullptr)
|
||||
oldOne->releaseResources();
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void AudioProcessorPlayer::audioDeviceIOCallback (const float** const inputChannelData,
|
||||
const int numInputChannels,
|
||||
float** const outputChannelData,
|
||||
const int numOutputChannels,
|
||||
const int numSamples)
|
||||
{
|
||||
// these should have been prepared by audioDeviceAboutToStart()...
|
||||
jassert (sampleRate > 0 && blockSize > 0);
|
||||
|
||||
incomingMidi.clear();
|
||||
messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
|
||||
int i, totalNumChans = 0;
|
||||
|
||||
if (numInputChannels > numOutputChannels)
|
||||
{
|
||||
// if there aren't enough output channels for the number of
|
||||
// inputs, we need to create some temporary extra ones (can't
|
||||
// use the input data in case it gets written to)
|
||||
tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
|
||||
false, false, true);
|
||||
|
||||
for (i = 0; i < numOutputChannels; ++i)
|
||||
{
|
||||
channels[totalNumChans] = outputChannelData[i];
|
||||
memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
|
||||
++totalNumChans;
|
||||
}
|
||||
|
||||
for (i = numOutputChannels; i < numInputChannels; ++i)
|
||||
{
|
||||
channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
|
||||
memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
|
||||
++totalNumChans;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < numInputChannels; ++i)
|
||||
{
|
||||
channels[totalNumChans] = outputChannelData[i];
|
||||
memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
|
||||
++totalNumChans;
|
||||
}
|
||||
|
||||
for (i = numInputChannels; i < numOutputChannels; ++i)
|
||||
{
|
||||
channels[totalNumChans] = outputChannelData[i];
|
||||
zeromem (channels[totalNumChans], sizeof (float) * numSamples);
|
||||
++totalNumChans;
|
||||
}
|
||||
}
|
||||
|
||||
AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
|
||||
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
if (processor != nullptr)
|
||||
{
|
||||
const ScopedLock sl2 (processor->getCallbackLock());
|
||||
|
||||
if (processor->isSuspended())
|
||||
{
|
||||
for (i = 0; i < numOutputChannels; ++i)
|
||||
zeromem (outputChannelData[i], sizeof (float) * numSamples);
|
||||
}
|
||||
else
|
||||
{
|
||||
processor->processBlock (buffer, incomingMidi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
sampleRate = device->getCurrentSampleRate();
|
||||
blockSize = device->getCurrentBufferSizeSamples();
|
||||
numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
|
||||
numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
|
||||
|
||||
messageCollector.reset (sampleRate);
|
||||
zeromem (channels, sizeof (channels));
|
||||
|
||||
if (processor != nullptr)
|
||||
{
|
||||
if (isPrepared)
|
||||
processor->releaseResources();
|
||||
|
||||
AudioProcessor* const oldProcessor = processor;
|
||||
setProcessor (nullptr);
|
||||
setProcessor (oldProcessor);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioProcessorPlayer::audioDeviceStopped()
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
if (processor != nullptr && isPrepared)
|
||||
processor->releaseResources();
|
||||
|
||||
sampleRate = 0.0;
|
||||
blockSize = 0;
|
||||
isPrepared = false;
|
||||
tempBuffer.setSize (1, 1);
|
||||
}
|
||||
|
||||
void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
|
||||
{
|
||||
messageCollector.addMessageToQueue (message);
|
||||
}
|
||||
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
105
modules/juce_audio_utils/players/juce_AudioProcessorPlayer.h
Normal file
105
modules/juce_audio_utils/players/juce_AudioProcessorPlayer.h
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
|
||||
#define __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
|
||||
|
||||
#include "../../juce_audio_processors/processors/juce_AudioProcessor.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
An AudioIODeviceCallback object which streams audio through an AudioProcessor.
|
||||
|
||||
To use one of these, just make it the callback used by your AudioIODevice, and
|
||||
give it a processor to use by calling setProcessor().
|
||||
|
||||
It's also a MidiInputCallback, so you can connect it to both an audio and midi
|
||||
input to send both streams through the processor.
|
||||
|
||||
@see AudioProcessor, AudioProcessorGraph
|
||||
*/
|
||||
class JUCE_API AudioProcessorPlayer : public AudioIODeviceCallback,
|
||||
public MidiInputCallback
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
AudioProcessorPlayer();
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~AudioProcessorPlayer();
|
||||
|
||||
//==============================================================================
|
||||
/** Sets the processor that should be played.
|
||||
|
||||
The processor that is passed in will not be deleted or owned by this object.
|
||||
To stop anything playing, pass in 0 to this method.
|
||||
*/
|
||||
void setProcessor (AudioProcessor* processorToPlay);
|
||||
|
||||
/** Returns the current audio processor that is being played.
|
||||
*/
|
||||
AudioProcessor* getCurrentProcessor() const { return processor; }
|
||||
|
||||
/** Returns a midi message collector that you can pass midi messages to if you
|
||||
want them to be injected into the midi stream that is being sent to the
|
||||
processor.
|
||||
*/
|
||||
MidiMessageCollector& getMidiMessageCollector() { return messageCollector; }
|
||||
|
||||
//==============================================================================
|
||||
/** @internal */
|
||||
void audioDeviceIOCallback (const float** inputChannelData,
|
||||
int totalNumInputChannels,
|
||||
float** outputChannelData,
|
||||
int totalNumOutputChannels,
|
||||
int numSamples);
|
||||
/** @internal */
|
||||
void audioDeviceAboutToStart (AudioIODevice* device);
|
||||
/** @internal */
|
||||
void audioDeviceStopped();
|
||||
/** @internal */
|
||||
void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message);
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
AudioProcessor* processor;
|
||||
CriticalSection lock;
|
||||
double sampleRate;
|
||||
int blockSize;
|
||||
bool isPrepared;
|
||||
|
||||
int numInputChans, numOutputChans;
|
||||
float* channels [128];
|
||||
AudioSampleBuffer tempBuffer;
|
||||
|
||||
MidiBuffer incomingMidi;
|
||||
MidiMessageCollector messageCollector;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessorPlayer);
|
||||
};
|
||||
|
||||
|
||||
#endif // __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
|
||||
Loading…
Add table
Add a link
Reference in a new issue