fix macOS build (following Projucer changes made in Windows, which removed /Applications/JUCE/modules from its headers). move JUCE headers under source control, so that Windows and macOS can both build against same version of JUCE. remove AUv3 target (I think it's an iOS thing, so it will never work with this macOS fluidsynth dylib).

This commit is contained in:
Alex Birch
2018-06-17 13:34:53 +01:00
parent a2be47c887
commit dff4d13a1d
1563 changed files with 601601 additions and 3466 deletions

View File

@ -0,0 +1,221 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
AudioProcessorPlayer::AudioProcessorPlayer (bool doDoublePrecisionProcessing)
: isDoublePrecision (doDoublePrecisionProcessing)
{
}
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);
bool supportsDouble = processorToPlay->supportsDoublePrecisionProcessing() && isDoublePrecision;
processorToPlay->setProcessingPrecision (supportsDouble ? AudioProcessor::doublePrecision
: AudioProcessor::singlePrecision);
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::setDoublePrecisionProcessing (bool doublePrecision)
{
if (doublePrecision != isDoublePrecision)
{
const ScopedLock sl (lock);
if (processor != nullptr)
{
processor->releaseResources();
bool supportsDouble = processor->supportsDoublePrecisionProcessing() && doublePrecision;
processor->setProcessingPrecision (supportsDouble ? AudioProcessor::doublePrecision
: AudioProcessor::singlePrecision);
processor->prepareToPlay (sampleRate, blockSize);
}
isDoublePrecision = doublePrecision;
}
}
//==============================================================================
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 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 (int i = 0; i < numOutputChannels; ++i)
{
channels[totalNumChans] = outputChannelData[i];
memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * (size_t) numSamples);
++totalNumChans;
}
for (int i = numOutputChannels; i < numInputChannels; ++i)
{
channels[totalNumChans] = tempBuffer.getWritePointer (i - numOutputChannels);
memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * (size_t) numSamples);
++totalNumChans;
}
}
else
{
for (int i = 0; i < numInputChannels; ++i)
{
channels[totalNumChans] = outputChannelData[i];
memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * (size_t) numSamples);
++totalNumChans;
}
for (int i = numInputChannels; i < numOutputChannels; ++i)
{
channels[totalNumChans] = outputChannelData[i];
zeromem (channels[totalNumChans], sizeof (float) * (size_t) numSamples);
++totalNumChans;
}
}
AudioBuffer<float> buffer (channels, totalNumChans, numSamples);
{
const ScopedLock sl (lock);
if (processor != nullptr)
{
const ScopedLock sl2 (processor->getCallbackLock());
if (! processor->isSuspended())
{
if (processor->isUsingDoublePrecision())
{
conversionBuffer.makeCopyOf (buffer, true);
processor->processBlock (conversionBuffer, incomingMidi);
buffer.makeCopyOf (conversionBuffer, true);
}
else
{
processor->processBlock (buffer, incomingMidi);
}
return;
}
}
}
for (int i = 0; i < numOutputChannels; ++i)
FloatVectorOperations::clear (outputChannelData[i], numSamples);
}
void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* const device)
{
auto newSampleRate = device->getCurrentSampleRate();
auto newBlockSize = device->getCurrentBufferSizeSamples();
auto numChansIn = device->getActiveInputChannels().countNumberOfSetBits();
auto numChansOut = device->getActiveOutputChannels().countNumberOfSetBits();
const ScopedLock sl (lock);
sampleRate = newSampleRate;
blockSize = newBlockSize;
numInputChans = numChansIn;
numOutputChans = numChansOut;
messageCollector.reset (sampleRate);
channels.calloc (jmax (numChansIn, numChansOut) + 2);
if (processor != nullptr)
{
if (isPrepared)
processor->releaseResources();
auto* 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);
}
} // namespace juce

View File

@ -0,0 +1,114 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
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
@tags{Audio}
*/
class JUCE_API AudioProcessorPlayer : public AudioIODeviceCallback,
public MidiInputCallback
{
public:
//==============================================================================
AudioProcessorPlayer (bool doDoublePrecisionProcessing = false);
/** 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 a nullptr to this method.
*/
void setProcessor (AudioProcessor* processorToPlay);
/** Returns the current audio processor that is being played. */
AudioProcessor* getCurrentProcessor() const noexcept { 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() noexcept { return messageCollector; }
/** Switch between double and single floating point precisions processing.
The audio IO callbacks will still operate in single floating point
precision, however, all internal processing including the
AudioProcessor will be processed in double floating point precision if
the AudioProcessor supports it (see
AudioProcessor::supportsDoublePrecisionProcessing()).
Otherwise, the processing will remain single precision irrespective of
the parameter doublePrecision. */
void setDoublePrecisionProcessing (bool doublePrecision);
/** Returns true if this player processes internally processes the samples with
double floating point precision. */
inline bool getDoublePrecisionProcessing() { return isDoublePrecision; }
//==============================================================================
/** @internal */
void audioDeviceIOCallback (const float**, int, float**, int, int) override;
/** @internal */
void audioDeviceAboutToStart (AudioIODevice*) override;
/** @internal */
void audioDeviceStopped() override;
/** @internal */
void handleIncomingMidiMessage (MidiInput*, const MidiMessage&) override;
private:
//==============================================================================
AudioProcessor* processor = nullptr;
CriticalSection lock;
double sampleRate = 0;
int blockSize = 0;
bool isPrepared = false, isDoublePrecision = false;
int numInputChans = 0, numOutputChans = 0;
HeapBlock<float*> channels;
AudioBuffer<float> tempBuffer;
AudioBuffer<double> conversionBuffer;
MidiBuffer incomingMidi;
MidiMessageCollector messageCollector;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessorPlayer)
};
} // namespace juce

View File

@ -0,0 +1,278 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
// This is an AudioTransportSource which will own it's assigned source
struct AudioSourceOwningTransportSource : public AudioTransportSource
{
AudioSourceOwningTransportSource (PositionableAudioSource* s, double sampleRate) : source (s)
{
AudioTransportSource::setSource (s, 0, nullptr, sampleRate);
}
~AudioSourceOwningTransportSource()
{
setSource (nullptr);
}
private:
std::unique_ptr<PositionableAudioSource> source;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSourceOwningTransportSource)
};
//==============================================================================
// An AudioSourcePlayer which will remove itself from the AudioDeviceManager's
// callback list once it finishes playing its source
struct AutoRemovingTransportSource : public AudioTransportSource,
private Timer
{
AutoRemovingTransportSource (MixerAudioSource& mixerToUse, AudioTransportSource* ts, bool ownSource,
int samplesPerBlock, double requiredSampleRate)
: mixer (mixerToUse), transportSource (ts, ownSource)
{
jassert (ts != nullptr);
setSource (transportSource);
prepareToPlay (samplesPerBlock, requiredSampleRate);
start();
mixer.addInputSource (this, true);
startTimerHz (10);
}
~AutoRemovingTransportSource()
{
setSource (nullptr);
}
void timerCallback() override
{
if (! transportSource->isPlaying())
mixer.removeInputSource (this);
}
private:
MixerAudioSource& mixer;
OptionalScopedPointer<AudioTransportSource> transportSource;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AutoRemovingTransportSource)
};
// An AudioSource which simply outputs a buffer
class AudioBufferSource : public PositionableAudioSource
{
public:
AudioBufferSource (AudioBuffer<float>* audioBuffer, bool ownBuffer, bool playOnAllChannels)
: buffer (audioBuffer, ownBuffer),
playAcrossAllChannels (playOnAllChannels)
{}
//==============================================================================
void setNextReadPosition (int64 newPosition) override
{
jassert (newPosition >= 0);
if (looping)
newPosition = newPosition % static_cast<int64> (buffer->getNumSamples());
position = jmin (buffer->getNumSamples(), static_cast<int> (newPosition));
}
int64 getNextReadPosition() const override { return static_cast<int64> (position); }
int64 getTotalLength() const override { return static_cast<int64> (buffer->getNumSamples()); }
bool isLooping() const override { return looping; }
void setLooping (bool shouldLoop) override { looping = shouldLoop; }
//==============================================================================
void prepareToPlay (int, double) override {}
void releaseResources() override {}
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
{
bufferToFill.clearActiveBufferRegion();
const int bufferSize = buffer->getNumSamples();
const int samplesNeeded = bufferToFill.numSamples;
const int samplesToCopy = jmin (bufferSize - position, samplesNeeded);
if (samplesToCopy > 0)
{
int maxInChannels = buffer->getNumChannels();
int maxOutChannels = bufferToFill.buffer->getNumChannels();
if (! playAcrossAllChannels)
maxOutChannels = jmin (maxOutChannels, maxInChannels);
for (int i = 0; i < maxOutChannels; ++i)
bufferToFill.buffer->copyFrom (i, bufferToFill.startSample, *buffer,
i % maxInChannels, position, samplesToCopy);
}
position += samplesNeeded;
if (looping)
position %= bufferSize;
}
private:
//==============================================================================
OptionalScopedPointer<AudioBuffer<float>> buffer;
int position = 0;
bool looping = false, playAcrossAllChannels;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioBufferSource)
};
SoundPlayer::SoundPlayer()
: sampleRate (44100.0), bufferSize (512)
{
formatManager.registerBasicFormats();
player.setSource (&mixer);
}
SoundPlayer::~SoundPlayer()
{
mixer.removeAllInputs();
player.setSource (nullptr);
}
void SoundPlayer::play (const File& file)
{
if (file.existsAsFile())
play (formatManager.createReaderFor (file), true);
}
void SoundPlayer::play (const void* resourceData, size_t resourceSize)
{
if (resourceData != nullptr && resourceSize > 0)
{
MemoryInputStream* mem = new MemoryInputStream (resourceData, resourceSize, false);
play (formatManager.createReaderFor (mem), true);
}
}
void SoundPlayer::play (AudioFormatReader* reader, bool deleteWhenFinished)
{
if (reader != nullptr)
play (new AudioFormatReaderSource (reader, deleteWhenFinished), true, reader->sampleRate);
}
void SoundPlayer::play (AudioBuffer<float>* buffer, bool deleteWhenFinished, bool playOnAllOutputChannels)
{
if (buffer != nullptr)
play (new AudioBufferSource (buffer, deleteWhenFinished, playOnAllOutputChannels), true);
}
void SoundPlayer::play (PositionableAudioSource* audioSource, bool deleteWhenFinished, double fileSampleRate)
{
if (audioSource != nullptr)
{
AudioTransportSource* transport = dynamic_cast<AudioTransportSource*> (audioSource);
if (transport == nullptr)
{
if (deleteWhenFinished)
{
transport = new AudioSourceOwningTransportSource (audioSource, fileSampleRate);
}
else
{
transport = new AudioTransportSource();
transport->setSource (audioSource, 0, nullptr, fileSampleRate);
deleteWhenFinished = true;
}
}
transport->start();
transport->prepareToPlay (bufferSize, sampleRate);
new AutoRemovingTransportSource (mixer, transport, deleteWhenFinished, bufferSize, sampleRate);
}
else
{
if (deleteWhenFinished)
delete audioSource;
}
}
void SoundPlayer::playTestSound()
{
auto soundLength = (int) sampleRate;
double frequency = 440.0;
float amplitude = 0.5f;
auto phasePerSample = MathConstants<double>::twoPi / (sampleRate / frequency);
auto* newSound = new AudioBuffer<float> (1, soundLength);
for (int i = 0; i < soundLength; ++i)
newSound->setSample (0, i, amplitude * (float) std::sin (i * phasePerSample));
newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
play (newSound, true, true);
}
//==============================================================================
void SoundPlayer::audioDeviceIOCallback (const float** inputChannelData,
int numInputChannels,
float** outputChannelData,
int numOutputChannels,
int numSamples)
{
player.audioDeviceIOCallback (inputChannelData, numInputChannels,
outputChannelData, numOutputChannels,
numSamples);
}
void SoundPlayer::audioDeviceAboutToStart (AudioIODevice* device)
{
if (device != nullptr)
{
sampleRate = device->getCurrentSampleRate();
bufferSize = device->getCurrentBufferSizeSamples();
}
player.audioDeviceAboutToStart (device);
}
void SoundPlayer::audioDeviceStopped()
{
player.audioDeviceStopped();
}
void SoundPlayer::audioDeviceError (const String& errorMessage)
{
player.audioDeviceError (errorMessage);
}
} // namespace juce

View File

@ -0,0 +1,137 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A simple sound player that you can add to the AudioDeviceManager to play
simple sounds.
@see AudioProcessor, AudioProcessorGraph
@tags{Audio}
*/
class JUCE_API SoundPlayer : public AudioIODeviceCallback
{
public:
//==============================================================================
SoundPlayer();
/** Destructor. */
virtual ~SoundPlayer();
//==============================================================================
/** Plays a sound from a file. */
void play (const File& file);
/** Convenient method to play sound from a JUCE resource. */
void play (const void* resourceData, size_t resourceSize);
/** Plays the sound from an audio format reader.
If deleteWhenFinished is true then the format reader will be
automatically deleted once the sound has finished playing.
*/
void play (AudioFormatReader* buffer, bool deleteWhenFinished = false);
/** Plays the sound from a positionable audio source.
This will output the sound coming from a positionable audio source.
This gives you slightly more control over the sound playback compared
to the other playSound methods. For example, if you would like to
stop the sound prematurely you can call this method with a
TransportAudioSource and then call audioSource->stop. Note that,
you must call audioSource->start to start the playback, if your
audioSource is a TransportAudioSource.
The audio device manager will not hold any references to this audio
source once the audio source has stopped playing for any reason,
for example when the sound has finished playing or when you have
called audioSource->stop. Therefore, calling audioSource->start() on
a finished audioSource will not restart the sound again. If this is
desired simply call playSound with the same audioSource again.
@param audioSource the audio source to play
@param deleteWhenFinished If this is true then the audio source will
be deleted once the device manager has finished
playing.
@param sampleRateOfSource The sample rate of the source. If this is zero, JUCE
will assume that the sample rate is the same as the
audio output device.
*/
void play (PositionableAudioSource* audioSource, bool deleteWhenFinished = false,
double sampleRateOfSource = 0.0);
/** Plays the sound from an audio sample buffer.
This will output the sound contained in an audio sample buffer. If
deleteWhenFinished is true then the audio sample buffer will be
automatically deleted once the sound has finished playing.
If playOnAllOutputChannels is true, then if there are more output channels
than buffer channels, then the ones that are available will be re-used on
multiple outputs so that something is sent to all output channels. If it
is false, then the buffer will just be played on the first output channels.
*/
void play (AudioBuffer<float>* buffer,
bool deleteWhenFinished = false,
bool playOnAllOutputChannels = false);
/** Plays a beep through the current audio device.
This is here to allow the audio setup UI panels to easily include a "test"
button so that the user can check where the audio is coming from.
*/
void playTestSound();
//==============================================================================
/** @internal */
void audioDeviceIOCallback (const float**, int, float**, int, int) override;
/** @internal */
void audioDeviceAboutToStart (AudioIODevice*) override;
/** @internal */
void audioDeviceStopped() override;
/** @internal */
void audioDeviceError (const String& errorMessage) override;
private:
//==============================================================================
AudioFormatManager formatManager;
AudioSourcePlayer player;
MixerAudioSource mixer;
OwnedArray<AudioSource> sources;
//==============================================================================
double sampleRate;
int bufferSize;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SoundPlayer)
};
} // namespace juce