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:
parent
1be7db03cd
commit
3977403b1b
4 changed files with 73 additions and 61 deletions
|
|
@ -193,15 +193,18 @@ public:
|
|||
roomSizeSlider.setRange (0.0, 1.0);
|
||||
addAndMakeVisible (roomSizeSlider);
|
||||
|
||||
auto* fileStream = getAssetsDirectory().getChildFile ("proaudio.path").createInputStream();
|
||||
if (auto* assetStream = createAssetInputStream ("proaudio.path"))
|
||||
{
|
||||
ScopedPointer<InputStream> fileStream (assetStream);
|
||||
|
||||
Path proAudioPath;
|
||||
proAudioPath.loadPathFromStream (*fileStream);
|
||||
proAudioIcon.setPath (proAudioPath);
|
||||
addAndMakeVisible (proAudioIcon);
|
||||
Path proAudioPath;
|
||||
proAudioPath.loadPathFromStream (*fileStream);
|
||||
proAudioIcon.setPath (proAudioPath);
|
||||
addAndMakeVisible (proAudioIcon);
|
||||
|
||||
auto proAudioIconColour = findColour (TextButton::buttonOnColourId);
|
||||
proAudioIcon.setFill (FillType (proAudioIconColour));
|
||||
auto proAudioIconColour = findColour (TextButton::buttonOnColourId);
|
||||
proAudioIcon.setFill (FillType (proAudioIconColour));
|
||||
}
|
||||
|
||||
setSize (600, 400);
|
||||
startTimer (100);
|
||||
|
|
@ -314,7 +317,7 @@ public:
|
|||
for (auto i = 0; i < maxNumVoices; ++i)
|
||||
synth.addVoice (new SamplerVoice());
|
||||
|
||||
loadNewSampleFile (getAssetsDirectory().getChildFile ("singing.ogg"), "ogg");
|
||||
loadNewSample (createAssetInputStream ("singing.ogg"), "ogg");
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -410,12 +413,6 @@ private:
|
|||
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)
|
||||
{
|
||||
ScopedPointer<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer, true));
|
||||
|
|
|
|||
|
|
@ -267,14 +267,20 @@ public:
|
|||
|
||||
if (type != currentType)
|
||||
{
|
||||
cabinetType.set(type);
|
||||
cabinetType.set (type);
|
||||
|
||||
auto maxSize = static_cast<size_t> (roundToInt (getSampleRate() * (8192.0 / 44100.0)));
|
||||
auto assetName = (type == 0 ? "Impulse1.wav" : "Impulse2.wav");
|
||||
|
||||
if (type == 0)
|
||||
convolution.loadImpulseResponse (getAssetsDirectory().getChildFile ("Impulse1.wav"), false, true, maxSize);
|
||||
else
|
||||
convolution.loadImpulseResponse (getAssetsDirectory().getChildFile ("Impulse2.wav"), false, true, maxSize);
|
||||
ScopedPointer<InputStream> assetInputStream (createAssetInputStream (assetName));
|
||||
if (assetInputStream != nullptr)
|
||||
{
|
||||
currentCabinetData.reset();
|
||||
assetInputStream->readIntoMemoryBlock (currentCabinetData);
|
||||
|
||||
convolution.loadImpulseResponse (currentCabinetData.getData(), currentCabinetData.getSize(),
|
||||
false, true, maxSize);
|
||||
}
|
||||
}
|
||||
|
||||
cabinetIsBypassed = ! cabinetSimParam->get();
|
||||
|
|
@ -541,6 +547,7 @@ private:
|
|||
//==============================================================================
|
||||
dsp::ProcessorDuplicator<dsp::IIR::Filter<float>, dsp::IIR::Coefficients<float>> lowPassFilter, highPassFilter;
|
||||
dsp::Convolution convolution;
|
||||
MemoryBlock currentCabinetData;
|
||||
|
||||
static constexpr size_t numWaveShapers = 2;
|
||||
dsp::WaveShaper<float> waveShapers[numWaveShapers];
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public:
|
|||
synth[midiChannel]->addVoice (new SamplerVoice());
|
||||
}
|
||||
|
||||
loadNewSample (getAssetsDirectory().getChildFile ("singing.ogg"));
|
||||
loadNewSample (createAssetInputStream ("singing.ogg"), "ogg");
|
||||
}
|
||||
|
||||
~MultiOutSynth() {}
|
||||
|
|
@ -155,10 +155,9 @@ private:
|
|||
return output;
|
||||
}
|
||||
|
||||
void loadNewSample (const File& sampleFile)
|
||||
void loadNewSample (InputStream* soundBuffer, const char* format)
|
||||
{
|
||||
auto* soundBuffer = sampleFile.createInputStream();
|
||||
ScopedPointer<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension ("ogg")->createReaderFor (soundBuffer, true));
|
||||
ScopedPointer<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer, true));
|
||||
|
||||
BigInteger midiNotes;
|
||||
midiNotes.setRange (0, 126, true);
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ private:
|
|||
class MPESamplerSound final
|
||||
{
|
||||
public:
|
||||
void setSample (ScopedPointer<Sample> value)
|
||||
void setSample (std::unique_ptr<Sample> value)
|
||||
{
|
||||
sample = move (value);
|
||||
setLoopPointsInSeconds (loopPoints);
|
||||
|
|
@ -227,7 +227,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
ScopedPointer<Sample> sample;
|
||||
std::unique_ptr<Sample> sample;
|
||||
double centreFrequencyInHz { 440.0 };
|
||||
Range<double> loopPoints;
|
||||
LoopMode loopMode { LoopMode::none };
|
||||
|
|
@ -477,27 +477,27 @@ private:
|
|||
};
|
||||
|
||||
template <typename Contents, typename... Args>
|
||||
ScopedPointer<ReferenceCountingAdapter<Contents>>
|
||||
std::unique_ptr<ReferenceCountingAdapter<Contents>>
|
||||
make_reference_counted (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,
|
||||
size_t dataSize)
|
||||
{
|
||||
return ScopedPointer<AudioFormatReader> (manager.createReaderFor (new MemoryInputStream (sampleData,
|
||||
return std::unique_ptr<AudioFormatReader> (manager.createReaderFor (new MemoryInputStream (sampleData,
|
||||
dataSize,
|
||||
false)));
|
||||
}
|
||||
|
||||
inline ScopedPointer<AudioFormatReader> makeAudioFormatReader (AudioFormatManager& manager,
|
||||
inline std::unique_ptr<AudioFormatReader> makeAudioFormatReader (AudioFormatManager& manager,
|
||||
const File& file)
|
||||
{
|
||||
return ScopedPointer<AudioFormatReader> (manager.createReaderFor (file));
|
||||
return std::unique_ptr<AudioFormatReader> (manager.createReaderFor (file));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -505,8 +505,8 @@ class AudioFormatReaderFactory
|
|||
{
|
||||
public:
|
||||
virtual ~AudioFormatReaderFactory() noexcept = default;
|
||||
virtual ScopedPointer<AudioFormatReader> make (AudioFormatManager&) const = 0;
|
||||
virtual ScopedPointer<AudioFormatReaderFactory> clone() const = 0;
|
||||
virtual std::unique_ptr<AudioFormatReader> make (AudioFormatManager&) const = 0;
|
||||
virtual std::unique_ptr<AudioFormatReaderFactory> clone() const = 0;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -518,14 +518,14 @@ public:
|
|||
dataSize (dataSize)
|
||||
{}
|
||||
|
||||
ScopedPointer<AudioFormatReader> make (AudioFormatManager&manager ) const override
|
||||
std::unique_ptr<AudioFormatReader> make (AudioFormatManager&manager ) const override
|
||||
{
|
||||
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:
|
||||
|
|
@ -541,14 +541,14 @@ public:
|
|||
: file (std::move (file))
|
||||
{}
|
||||
|
||||
ScopedPointer<AudioFormatReader> make (AudioFormatManager& manager) const override
|
||||
std::unique_ptr<AudioFormatReader> make (AudioFormatManager& manager) const override
|
||||
{
|
||||
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:
|
||||
|
|
@ -951,12 +951,12 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
ScopedPointer<AudioFormatReader> getSampleReader() const
|
||||
std::unique_ptr<AudioFormatReader> getSampleReader() const
|
||||
{
|
||||
return sampleReader != nullptr ? sampleReader.get()->make (*audioFormatManager) : nullptr;
|
||||
}
|
||||
|
||||
void setSampleReader (ScopedPointer<AudioFormatReaderFactory> readerFactory,
|
||||
void setSampleReader (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
|
||||
UndoManager* undoManager)
|
||||
{
|
||||
sampleReader.setValue (move (readerFactory), undoManager);
|
||||
|
|
@ -1888,7 +1888,7 @@ public:
|
|||
{
|
||||
undoManager->beginNewTransaction();
|
||||
auto readerFactory = new FileAudioFormatReaderFactory (fc.getResult());
|
||||
dataModel.setSampleReader (ScopedPointer<AudioFormatReaderFactory> (readerFactory),
|
||||
dataModel.setSampleReader (std::unique_ptr<AudioFormatReaderFactory> (readerFactory),
|
||||
undoManager);
|
||||
};
|
||||
|
||||
|
|
@ -2021,7 +2021,7 @@ struct ProcessorState
|
|||
int legacyPitchbendRange;
|
||||
bool voiceStealingEnabled;
|
||||
MPEZoneLayout mpeZoneLayout;
|
||||
ScopedPointer<AudioFormatReaderFactory> readerFactory;
|
||||
std::unique_ptr<AudioFormatReaderFactory> readerFactory;
|
||||
Range<double> loopPointsSeconds;
|
||||
double centreFrequencyHz;
|
||||
LoopMode loopMode;
|
||||
|
|
@ -2062,12 +2062,20 @@ public:
|
|||
SamplerAudioProcessor()
|
||||
: 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
|
||||
AudioFormatManager manager;
|
||||
manager.registerBasicFormats();
|
||||
auto reader = readerFactory->make (manager);
|
||||
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();
|
||||
sound->setLoopPointsInSeconds ({lengthInSeconds * 0.1, lengthInSeconds * 0.9 });
|
||||
sound->setSample (move (sample));
|
||||
|
|
@ -2181,15 +2189,15 @@ public:
|
|||
|
||||
// These should be called from the GUI thread, and will block until the
|
||||
// command buffer has enough room to accept a command.
|
||||
void setSample (ScopedPointer<AudioFormatReaderFactory> readerFactory,
|
||||
void setSample (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
|
||||
AudioFormatManager& formatManager)
|
||||
{
|
||||
class SetSampleCommand
|
||||
{
|
||||
public:
|
||||
SetSampleCommand (ScopedPointer<AudioFormatReaderFactory> readerFactory,
|
||||
ScopedPointer<Sample> sample,
|
||||
std::vector<ScopedPointer<MPESamplerVoice>> newVoices)
|
||||
SetSampleCommand (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
|
||||
std::unique_ptr<Sample> sample,
|
||||
std::vector<std::unique_ptr<MPESamplerVoice>> newVoices)
|
||||
: readerFactory (move (readerFactory)),
|
||||
sample (move (sample)),
|
||||
newVoices (move (newVoices))
|
||||
|
|
@ -2210,15 +2218,15 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
ScopedPointer<AudioFormatReaderFactory> readerFactory;
|
||||
ScopedPointer<Sample> sample;
|
||||
std::vector<ScopedPointer<MPESamplerVoice>> newVoices;
|
||||
std::unique_ptr<AudioFormatReaderFactory> readerFactory;
|
||||
std::unique_ptr<Sample> sample;
|
||||
std::vector<std::unique_ptr<MPESamplerVoice>> newVoices;
|
||||
};
|
||||
|
||||
// Note that all allocation happens here, on the main message thread. Then,
|
||||
// we transfer ownership across to the audio thread.
|
||||
auto loadedSamplerSound = samplerSound.load();
|
||||
std::vector<ScopedPointer<MPESamplerVoice>> newSamplerVoices;
|
||||
std::vector<std::unique_ptr<MPESamplerVoice>> newSamplerVoices;
|
||||
newSamplerVoices.reserve (maxVoices);
|
||||
|
||||
for (auto i = 0; i != maxVoices; ++i)
|
||||
|
|
@ -2234,7 +2242,7 @@ public:
|
|||
{
|
||||
auto reader = readerFactory->make (formatManager);
|
||||
pushCommand (SetSampleCommand (move (readerFactory),
|
||||
ScopedPointer<Sample> (new Sample (*reader, 10.0)),
|
||||
std::unique_ptr<Sample> (new Sample (*reader, 10.0)),
|
||||
move (newSamplerVoices)));
|
||||
}
|
||||
}
|
||||
|
|
@ -2307,7 +2315,7 @@ public:
|
|||
class SetNumVoicesCommand
|
||||
{
|
||||
public:
|
||||
SetNumVoicesCommand (std::vector<ScopedPointer<MPESamplerVoice>> newVoices)
|
||||
SetNumVoicesCommand (std::vector<std::unique_ptr<MPESamplerVoice>> newVoices)
|
||||
: newVoices (move (newVoices))
|
||||
{}
|
||||
|
||||
|
|
@ -2325,12 +2333,12 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::vector<ScopedPointer<MPESamplerVoice>> newVoices;
|
||||
std::vector<std::unique_ptr<MPESamplerVoice>> newVoices;
|
||||
};
|
||||
|
||||
numberOfVoices = std::min (maxVoices, numberOfVoices);
|
||||
auto loadedSamplerSound = samplerSound.load();
|
||||
std::vector<ScopedPointer<MPESamplerVoice>> newSamplerVoices;
|
||||
std::vector<std::unique_ptr<MPESamplerVoice>> newSamplerVoices;
|
||||
newSamplerVoices.reserve (numberOfVoices);
|
||||
|
||||
for (auto i = 0; i != numberOfVoices; ++i)
|
||||
|
|
@ -2441,7 +2449,7 @@ private:
|
|||
jassert (files.size() == 1);
|
||||
undoManager.beginNewTransaction();
|
||||
auto readerFactory = new FileAudioFormatReaderFactory (files[0]);
|
||||
dataModel.setSampleReader (ScopedPointer<AudioFormatReaderFactory> (readerFactory),
|
||||
dataModel.setSampleReader (std::unique_ptr<AudioFormatReaderFactory> (readerFactory),
|
||||
&undoManager);
|
||||
|
||||
}
|
||||
|
|
@ -2559,12 +2567,12 @@ private:
|
|||
};
|
||||
|
||||
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
|
||||
{
|
||||
|
|
@ -2604,7 +2612,8 @@ private:
|
|||
CommandFifo 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>() };
|
||||
MPESynthesiser synthesiser;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue