1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

PIPs: Fixed some errors in the plugin examples

This commit is contained in:
ed 2018-03-16 11:23:04 +00:00
parent 1be7db03cd
commit 3977403b1b
4 changed files with 73 additions and 61 deletions

View file

@ -193,15 +193,18 @@ public:
roomSizeSlider.setRange (0.0, 1.0); roomSizeSlider.setRange (0.0, 1.0);
addAndMakeVisible (roomSizeSlider); addAndMakeVisible (roomSizeSlider);
auto* fileStream = getAssetsDirectory().getChildFile ("proaudio.path").createInputStream(); if (auto* assetStream = createAssetInputStream ("proaudio.path"))
{
ScopedPointer<InputStream> fileStream (assetStream);
Path proAudioPath; Path proAudioPath;
proAudioPath.loadPathFromStream (*fileStream); proAudioPath.loadPathFromStream (*fileStream);
proAudioIcon.setPath (proAudioPath); proAudioIcon.setPath (proAudioPath);
addAndMakeVisible (proAudioIcon); addAndMakeVisible (proAudioIcon);
auto proAudioIconColour = findColour (TextButton::buttonOnColourId); auto proAudioIconColour = findColour (TextButton::buttonOnColourId);
proAudioIcon.setFill (FillType (proAudioIconColour)); proAudioIcon.setFill (FillType (proAudioIconColour));
}
setSize (600, 400); setSize (600, 400);
startTimer (100); startTimer (100);
@ -314,7 +317,7 @@ public:
for (auto i = 0; i < maxNumVoices; ++i) for (auto i = 0; i < maxNumVoices; ++i)
synth.addVoice (new SamplerVoice()); synth.addVoice (new SamplerVoice());
loadNewSampleFile (getAssetsDirectory().getChildFile ("singing.ogg"), "ogg"); loadNewSample (createAssetInputStream ("singing.ogg"), "ogg");
} }
//============================================================================== //==============================================================================
@ -410,12 +413,6 @@ private:
loadNewSample (soundBuffer, format); loadNewSample (soundBuffer, format);
} }
void loadNewSampleFile (const File& sampleFile, const char* format)
{
auto* soundBuffer = sampleFile.createInputStream();
loadNewSample (soundBuffer, format);
}
void loadNewSample (InputStream* soundBuffer, const char* format) void loadNewSample (InputStream* soundBuffer, const char* format)
{ {
ScopedPointer<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer, true)); ScopedPointer<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer, true));

View file

@ -267,14 +267,20 @@ public:
if (type != currentType) if (type != currentType)
{ {
cabinetType.set(type); cabinetType.set (type);
auto maxSize = static_cast<size_t> (roundToInt (getSampleRate() * (8192.0 / 44100.0))); auto maxSize = static_cast<size_t> (roundToInt (getSampleRate() * (8192.0 / 44100.0)));
auto assetName = (type == 0 ? "Impulse1.wav" : "Impulse2.wav");
if (type == 0) ScopedPointer<InputStream> assetInputStream (createAssetInputStream (assetName));
convolution.loadImpulseResponse (getAssetsDirectory().getChildFile ("Impulse1.wav"), false, true, maxSize); if (assetInputStream != nullptr)
else {
convolution.loadImpulseResponse (getAssetsDirectory().getChildFile ("Impulse2.wav"), false, true, maxSize); currentCabinetData.reset();
assetInputStream->readIntoMemoryBlock (currentCabinetData);
convolution.loadImpulseResponse (currentCabinetData.getData(), currentCabinetData.getSize(),
false, true, maxSize);
}
} }
cabinetIsBypassed = ! cabinetSimParam->get(); cabinetIsBypassed = ! cabinetSimParam->get();
@ -541,6 +547,7 @@ private:
//============================================================================== //==============================================================================
dsp::ProcessorDuplicator<dsp::IIR::Filter<float>, dsp::IIR::Coefficients<float>> lowPassFilter, highPassFilter; dsp::ProcessorDuplicator<dsp::IIR::Filter<float>, dsp::IIR::Coefficients<float>> lowPassFilter, highPassFilter;
dsp::Convolution convolution; dsp::Convolution convolution;
MemoryBlock currentCabinetData;
static constexpr size_t numWaveShapers = 2; static constexpr size_t numWaveShapers = 2;
dsp::WaveShaper<float> waveShapers[numWaveShapers]; dsp::WaveShaper<float> waveShapers[numWaveShapers];

View file

@ -89,7 +89,7 @@ public:
synth[midiChannel]->addVoice (new SamplerVoice()); synth[midiChannel]->addVoice (new SamplerVoice());
} }
loadNewSample (getAssetsDirectory().getChildFile ("singing.ogg")); loadNewSample (createAssetInputStream ("singing.ogg"), "ogg");
} }
~MultiOutSynth() {} ~MultiOutSynth() {}
@ -155,10 +155,9 @@ private:
return output; return output;
} }
void loadNewSample (const File& sampleFile) void loadNewSample (InputStream* soundBuffer, const char* format)
{ {
auto* soundBuffer = sampleFile.createInputStream(); ScopedPointer<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer, true));
ScopedPointer<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension ("ogg")->createReaderFor (soundBuffer, true));
BigInteger midiNotes; BigInteger midiNotes;
midiNotes.setRange (0, 126, true); midiNotes.setRange (0, 126, true);

View file

@ -183,7 +183,7 @@ private:
class MPESamplerSound final class MPESamplerSound final
{ {
public: public:
void setSample (ScopedPointer<Sample> value) void setSample (std::unique_ptr<Sample> value)
{ {
sample = move (value); sample = move (value);
setLoopPointsInSeconds (loopPoints); setLoopPointsInSeconds (loopPoints);
@ -227,7 +227,7 @@ public:
} }
private: private:
ScopedPointer<Sample> sample; std::unique_ptr<Sample> sample;
double centreFrequencyInHz { 440.0 }; double centreFrequencyInHz { 440.0 };
Range<double> loopPoints; Range<double> loopPoints;
LoopMode loopMode { LoopMode::none }; LoopMode loopMode { LoopMode::none };
@ -477,27 +477,27 @@ private:
}; };
template <typename Contents, typename... Args> template <typename Contents, typename... Args>
ScopedPointer<ReferenceCountingAdapter<Contents>> std::unique_ptr<ReferenceCountingAdapter<Contents>>
make_reference_counted (Args&&... args) make_reference_counted (Args&&... args)
{ {
auto adapter = new ReferenceCountingAdapter<Contents> (std::forward<Args> (args)...); auto adapter = new ReferenceCountingAdapter<Contents> (std::forward<Args> (args)...);
return ScopedPointer<ReferenceCountingAdapter<Contents>> (adapter); return std::unique_ptr<ReferenceCountingAdapter<Contents>> (adapter);
} }
//============================================================================== //==============================================================================
inline ScopedPointer<AudioFormatReader> makeAudioFormatReader (AudioFormatManager& manager, inline std::unique_ptr<AudioFormatReader> makeAudioFormatReader (AudioFormatManager& manager,
const void* sampleData, const void* sampleData,
size_t dataSize) size_t dataSize)
{ {
return ScopedPointer<AudioFormatReader> (manager.createReaderFor (new MemoryInputStream (sampleData, return std::unique_ptr<AudioFormatReader> (manager.createReaderFor (new MemoryInputStream (sampleData,
dataSize, dataSize,
false))); false)));
} }
inline ScopedPointer<AudioFormatReader> makeAudioFormatReader (AudioFormatManager& manager, inline std::unique_ptr<AudioFormatReader> makeAudioFormatReader (AudioFormatManager& manager,
const File& file) const File& file)
{ {
return ScopedPointer<AudioFormatReader> (manager.createReaderFor (file)); return std::unique_ptr<AudioFormatReader> (manager.createReaderFor (file));
} }
//============================================================================== //==============================================================================
@ -505,8 +505,8 @@ class AudioFormatReaderFactory
{ {
public: public:
virtual ~AudioFormatReaderFactory() noexcept = default; virtual ~AudioFormatReaderFactory() noexcept = default;
virtual ScopedPointer<AudioFormatReader> make (AudioFormatManager&) const = 0; virtual std::unique_ptr<AudioFormatReader> make (AudioFormatManager&) const = 0;
virtual ScopedPointer<AudioFormatReaderFactory> clone() const = 0; virtual std::unique_ptr<AudioFormatReaderFactory> clone() const = 0;
}; };
//============================================================================== //==============================================================================
@ -518,14 +518,14 @@ public:
dataSize (dataSize) dataSize (dataSize)
{} {}
ScopedPointer<AudioFormatReader> make (AudioFormatManager&manager ) const override std::unique_ptr<AudioFormatReader> make (AudioFormatManager&manager ) const override
{ {
return makeAudioFormatReader (manager, sampleData, dataSize); return makeAudioFormatReader (manager, sampleData, dataSize);
} }
ScopedPointer<AudioFormatReaderFactory> clone() const override std::unique_ptr<AudioFormatReaderFactory> clone() const override
{ {
return ScopedPointer<AudioFormatReaderFactory> (new MemoryAudioFormatReaderFactory (*this)); return std::unique_ptr<AudioFormatReaderFactory> (new MemoryAudioFormatReaderFactory (*this));
} }
private: private:
@ -541,14 +541,14 @@ public:
: file (std::move (file)) : file (std::move (file))
{} {}
ScopedPointer<AudioFormatReader> make (AudioFormatManager& manager) const override std::unique_ptr<AudioFormatReader> make (AudioFormatManager& manager) const override
{ {
return makeAudioFormatReader (manager, file); return makeAudioFormatReader (manager, file);
} }
ScopedPointer<AudioFormatReaderFactory> clone() const override std::unique_ptr<AudioFormatReaderFactory> clone() const override
{ {
return ScopedPointer<AudioFormatReaderFactory> (new FileAudioFormatReaderFactory (*this)); return std::unique_ptr<AudioFormatReaderFactory> (new FileAudioFormatReaderFactory (*this));
} }
private: private:
@ -951,12 +951,12 @@ public:
return *this; return *this;
} }
ScopedPointer<AudioFormatReader> getSampleReader() const std::unique_ptr<AudioFormatReader> getSampleReader() const
{ {
return sampleReader != nullptr ? sampleReader.get()->make (*audioFormatManager) : nullptr; return sampleReader != nullptr ? sampleReader.get()->make (*audioFormatManager) : nullptr;
} }
void setSampleReader (ScopedPointer<AudioFormatReaderFactory> readerFactory, void setSampleReader (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
UndoManager* undoManager) UndoManager* undoManager)
{ {
sampleReader.setValue (move (readerFactory), undoManager); sampleReader.setValue (move (readerFactory), undoManager);
@ -1888,7 +1888,7 @@ public:
{ {
undoManager->beginNewTransaction(); undoManager->beginNewTransaction();
auto readerFactory = new FileAudioFormatReaderFactory (fc.getResult()); auto readerFactory = new FileAudioFormatReaderFactory (fc.getResult());
dataModel.setSampleReader (ScopedPointer<AudioFormatReaderFactory> (readerFactory), dataModel.setSampleReader (std::unique_ptr<AudioFormatReaderFactory> (readerFactory),
undoManager); undoManager);
}; };
@ -2021,7 +2021,7 @@ struct ProcessorState
int legacyPitchbendRange; int legacyPitchbendRange;
bool voiceStealingEnabled; bool voiceStealingEnabled;
MPEZoneLayout mpeZoneLayout; MPEZoneLayout mpeZoneLayout;
ScopedPointer<AudioFormatReaderFactory> readerFactory; std::unique_ptr<AudioFormatReaderFactory> readerFactory;
Range<double> loopPointsSeconds; Range<double> loopPointsSeconds;
double centreFrequencyHz; double centreFrequencyHz;
LoopMode loopMode; LoopMode loopMode;
@ -2062,12 +2062,20 @@ public:
SamplerAudioProcessor() SamplerAudioProcessor()
: AudioProcessor (BusesProperties().withOutput ("Output", AudioChannelSet::stereo(), true)) : AudioProcessor (BusesProperties().withOutput ("Output", AudioChannelSet::stereo(), true))
{ {
if (auto* asset = createAssetInputStream ("cello.wav"))
{
ScopedPointer<InputStream> inputStream (asset);
inputStream->readIntoMemoryBlock (mb);
readerFactory.reset (new MemoryAudioFormatReaderFactory (mb.getData(), mb.getSize()));
}
// Set up initial sample, which we load from a binary resource // Set up initial sample, which we load from a binary resource
AudioFormatManager manager; AudioFormatManager manager;
manager.registerBasicFormats(); manager.registerBasicFormats();
auto reader = readerFactory->make (manager); auto reader = readerFactory->make (manager);
auto sound = samplerSound.load(); auto sound = samplerSound.load();
auto sample = ScopedPointer<Sample> (new Sample (*reader, 10.0)); auto sample = std::unique_ptr<Sample> (new Sample (*reader, 10.0));
auto lengthInSeconds = sample->getLength() / sample->getSampleRate(); auto lengthInSeconds = sample->getLength() / sample->getSampleRate();
sound->setLoopPointsInSeconds ({lengthInSeconds * 0.1, lengthInSeconds * 0.9 }); sound->setLoopPointsInSeconds ({lengthInSeconds * 0.1, lengthInSeconds * 0.9 });
sound->setSample (move (sample)); sound->setSample (move (sample));
@ -2181,15 +2189,15 @@ public:
// These should be called from the GUI thread, and will block until the // These should be called from the GUI thread, and will block until the
// command buffer has enough room to accept a command. // command buffer has enough room to accept a command.
void setSample (ScopedPointer<AudioFormatReaderFactory> readerFactory, void setSample (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
AudioFormatManager& formatManager) AudioFormatManager& formatManager)
{ {
class SetSampleCommand class SetSampleCommand
{ {
public: public:
SetSampleCommand (ScopedPointer<AudioFormatReaderFactory> readerFactory, SetSampleCommand (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
ScopedPointer<Sample> sample, std::unique_ptr<Sample> sample,
std::vector<ScopedPointer<MPESamplerVoice>> newVoices) std::vector<std::unique_ptr<MPESamplerVoice>> newVoices)
: readerFactory (move (readerFactory)), : readerFactory (move (readerFactory)),
sample (move (sample)), sample (move (sample)),
newVoices (move (newVoices)) newVoices (move (newVoices))
@ -2210,15 +2218,15 @@ public:
} }
private: private:
ScopedPointer<AudioFormatReaderFactory> readerFactory; std::unique_ptr<AudioFormatReaderFactory> readerFactory;
ScopedPointer<Sample> sample; std::unique_ptr<Sample> sample;
std::vector<ScopedPointer<MPESamplerVoice>> newVoices; std::vector<std::unique_ptr<MPESamplerVoice>> newVoices;
}; };
// Note that all allocation happens here, on the main message thread. Then, // Note that all allocation happens here, on the main message thread. Then,
// we transfer ownership across to the audio thread. // we transfer ownership across to the audio thread.
auto loadedSamplerSound = samplerSound.load(); auto loadedSamplerSound = samplerSound.load();
std::vector<ScopedPointer<MPESamplerVoice>> newSamplerVoices; std::vector<std::unique_ptr<MPESamplerVoice>> newSamplerVoices;
newSamplerVoices.reserve (maxVoices); newSamplerVoices.reserve (maxVoices);
for (auto i = 0; i != maxVoices; ++i) for (auto i = 0; i != maxVoices; ++i)
@ -2234,7 +2242,7 @@ public:
{ {
auto reader = readerFactory->make (formatManager); auto reader = readerFactory->make (formatManager);
pushCommand (SetSampleCommand (move (readerFactory), pushCommand (SetSampleCommand (move (readerFactory),
ScopedPointer<Sample> (new Sample (*reader, 10.0)), std::unique_ptr<Sample> (new Sample (*reader, 10.0)),
move (newSamplerVoices))); move (newSamplerVoices)));
} }
} }
@ -2307,7 +2315,7 @@ public:
class SetNumVoicesCommand class SetNumVoicesCommand
{ {
public: public:
SetNumVoicesCommand (std::vector<ScopedPointer<MPESamplerVoice>> newVoices) SetNumVoicesCommand (std::vector<std::unique_ptr<MPESamplerVoice>> newVoices)
: newVoices (move (newVoices)) : newVoices (move (newVoices))
{} {}
@ -2325,12 +2333,12 @@ public:
} }
private: private:
std::vector<ScopedPointer<MPESamplerVoice>> newVoices; std::vector<std::unique_ptr<MPESamplerVoice>> newVoices;
}; };
numberOfVoices = std::min (maxVoices, numberOfVoices); numberOfVoices = std::min (maxVoices, numberOfVoices);
auto loadedSamplerSound = samplerSound.load(); auto loadedSamplerSound = samplerSound.load();
std::vector<ScopedPointer<MPESamplerVoice>> newSamplerVoices; std::vector<std::unique_ptr<MPESamplerVoice>> newSamplerVoices;
newSamplerVoices.reserve (numberOfVoices); newSamplerVoices.reserve (numberOfVoices);
for (auto i = 0; i != numberOfVoices; ++i) for (auto i = 0; i != numberOfVoices; ++i)
@ -2441,7 +2449,7 @@ private:
jassert (files.size() == 1); jassert (files.size() == 1);
undoManager.beginNewTransaction(); undoManager.beginNewTransaction();
auto readerFactory = new FileAudioFormatReaderFactory (files[0]); auto readerFactory = new FileAudioFormatReaderFactory (files[0]);
dataModel.setSampleReader (ScopedPointer<AudioFormatReaderFactory> (readerFactory), dataModel.setSampleReader (std::unique_ptr<AudioFormatReaderFactory> (readerFactory),
&undoManager); &undoManager);
} }
@ -2559,12 +2567,12 @@ private:
}; };
template <typename Func> template <typename Func>
static ScopedPointer<Command> make_command (Func&& func) static std::unique_ptr<Command> make_command (Func&& func)
{ {
return ScopedPointer<TemplateCommand<Func>> (new TemplateCommand<Func> (std::forward<Func> (func))); return std::unique_ptr<TemplateCommand<Func>> (new TemplateCommand<Func> (std::forward<Func> (func)));
} }
using CommandFifo = MoveOnlyFifo<ScopedPointer<Command>>; using CommandFifo = MoveOnlyFifo<std::unique_ptr<Command>>;
class OutgoingBufferCleaner : public Timer class OutgoingBufferCleaner : public Timer
{ {
@ -2604,7 +2612,8 @@ private:
CommandFifo outgoingCommands; CommandFifo outgoingCommands;
OutgoingBufferCleaner outgoingBufferCleaner { outgoingCommands }; OutgoingBufferCleaner outgoingBufferCleaner { outgoingCommands };
ScopedPointer<AudioFormatReaderFactory> readerFactory { new FileAudioFormatReaderFactory (getAssetsDirectory().getChildFile ("cello.wav")) }; MemoryBlock mb;
std::unique_ptr<AudioFormatReaderFactory> readerFactory;
AtomicSharedPtr<MPESamplerSound> samplerSound { std::make_shared<MPESamplerSound>() }; AtomicSharedPtr<MPESamplerSound> samplerSound { std::make_shared<MPESamplerSound>() };
MPESynthesiser synthesiser; MPESynthesiser synthesiser;