diff --git a/examples/Plugins/AUv3SynthPluginDemo.h b/examples/Plugins/AUv3SynthPluginDemo.h index 9958f16ea0..55e8eeb53f 100644 --- a/examples/Plugins/AUv3SynthPluginDemo.h +++ b/examples/Plugins/AUv3SynthPluginDemo.h @@ -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 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 formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer, true)); diff --git a/examples/Plugins/DSPModulePluginDemo.h b/examples/Plugins/DSPModulePluginDemo.h index 3c8e5499cb..7523b01738 100644 --- a/examples/Plugins/DSPModulePluginDemo.h +++ b/examples/Plugins/DSPModulePluginDemo.h @@ -267,14 +267,20 @@ public: if (type != currentType) { - cabinetType.set(type); + cabinetType.set (type); auto maxSize = static_cast (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 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::Coefficients> lowPassFilter, highPassFilter; dsp::Convolution convolution; + MemoryBlock currentCabinetData; static constexpr size_t numWaveShapers = 2; dsp::WaveShaper waveShapers[numWaveShapers]; diff --git a/examples/Plugins/MultiOutSynthPluginDemo.h b/examples/Plugins/MultiOutSynthPluginDemo.h index 0f84047bc0..70a2390af6 100644 --- a/examples/Plugins/MultiOutSynthPluginDemo.h +++ b/examples/Plugins/MultiOutSynthPluginDemo.h @@ -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 formatReader (formatManager.findFormatForFileExtension ("ogg")->createReaderFor (soundBuffer, true)); + ScopedPointer formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer, true)); BigInteger midiNotes; midiNotes.setRange (0, 126, true); diff --git a/examples/Plugins/SamplerPluginDemo.h b/examples/Plugins/SamplerPluginDemo.h index a26890e15d..a53e67438b 100644 --- a/examples/Plugins/SamplerPluginDemo.h +++ b/examples/Plugins/SamplerPluginDemo.h @@ -183,7 +183,7 @@ private: class MPESamplerSound final { public: - void setSample (ScopedPointer value) + void setSample (std::unique_ptr value) { sample = move (value); setLoopPointsInSeconds (loopPoints); @@ -227,7 +227,7 @@ public: } private: - ScopedPointer sample; + std::unique_ptr sample; double centreFrequencyInHz { 440.0 }; Range loopPoints; LoopMode loopMode { LoopMode::none }; @@ -477,27 +477,27 @@ private: }; template -ScopedPointer> +std::unique_ptr> make_reference_counted (Args&&... args) { auto adapter = new ReferenceCountingAdapter (std::forward (args)...); - return ScopedPointer> (adapter); + return std::unique_ptr> (adapter); } //============================================================================== -inline ScopedPointer makeAudioFormatReader (AudioFormatManager& manager, +inline std::unique_ptr makeAudioFormatReader (AudioFormatManager& manager, const void* sampleData, size_t dataSize) { - return ScopedPointer (manager.createReaderFor (new MemoryInputStream (sampleData, + return std::unique_ptr (manager.createReaderFor (new MemoryInputStream (sampleData, dataSize, false))); } -inline ScopedPointer makeAudioFormatReader (AudioFormatManager& manager, +inline std::unique_ptr makeAudioFormatReader (AudioFormatManager& manager, const File& file) { - return ScopedPointer (manager.createReaderFor (file)); + return std::unique_ptr (manager.createReaderFor (file)); } //============================================================================== @@ -505,8 +505,8 @@ class AudioFormatReaderFactory { public: virtual ~AudioFormatReaderFactory() noexcept = default; - virtual ScopedPointer make (AudioFormatManager&) const = 0; - virtual ScopedPointer clone() const = 0; + virtual std::unique_ptr make (AudioFormatManager&) const = 0; + virtual std::unique_ptr clone() const = 0; }; //============================================================================== @@ -518,14 +518,14 @@ public: dataSize (dataSize) {} - ScopedPointer make (AudioFormatManager&manager ) const override + std::unique_ptr make (AudioFormatManager&manager ) const override { return makeAudioFormatReader (manager, sampleData, dataSize); } - ScopedPointer clone() const override + std::unique_ptr clone() const override { - return ScopedPointer (new MemoryAudioFormatReaderFactory (*this)); + return std::unique_ptr (new MemoryAudioFormatReaderFactory (*this)); } private: @@ -541,14 +541,14 @@ public: : file (std::move (file)) {} - ScopedPointer make (AudioFormatManager& manager) const override + std::unique_ptr make (AudioFormatManager& manager) const override { return makeAudioFormatReader (manager, file); } - ScopedPointer clone() const override + std::unique_ptr clone() const override { - return ScopedPointer (new FileAudioFormatReaderFactory (*this)); + return std::unique_ptr (new FileAudioFormatReaderFactory (*this)); } private: @@ -951,12 +951,12 @@ public: return *this; } - ScopedPointer getSampleReader() const + std::unique_ptr getSampleReader() const { return sampleReader != nullptr ? sampleReader.get()->make (*audioFormatManager) : nullptr; } - void setSampleReader (ScopedPointer readerFactory, + void setSampleReader (std::unique_ptr readerFactory, UndoManager* undoManager) { sampleReader.setValue (move (readerFactory), undoManager); @@ -1888,7 +1888,7 @@ public: { undoManager->beginNewTransaction(); auto readerFactory = new FileAudioFormatReaderFactory (fc.getResult()); - dataModel.setSampleReader (ScopedPointer (readerFactory), + dataModel.setSampleReader (std::unique_ptr (readerFactory), undoManager); }; @@ -2021,7 +2021,7 @@ struct ProcessorState int legacyPitchbendRange; bool voiceStealingEnabled; MPEZoneLayout mpeZoneLayout; - ScopedPointer readerFactory; + std::unique_ptr readerFactory; Range 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 (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 (new Sample (*reader, 10.0)); + auto sample = std::unique_ptr (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 readerFactory, + void setSample (std::unique_ptr readerFactory, AudioFormatManager& formatManager) { class SetSampleCommand { public: - SetSampleCommand (ScopedPointer readerFactory, - ScopedPointer sample, - std::vector> newVoices) + SetSampleCommand (std::unique_ptr readerFactory, + std::unique_ptr sample, + std::vector> newVoices) : readerFactory (move (readerFactory)), sample (move (sample)), newVoices (move (newVoices)) @@ -2210,15 +2218,15 @@ public: } private: - ScopedPointer readerFactory; - ScopedPointer sample; - std::vector> newVoices; + std::unique_ptr readerFactory; + std::unique_ptr sample; + std::vector> 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> newSamplerVoices; + std::vector> 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 (new Sample (*reader, 10.0)), + std::unique_ptr (new Sample (*reader, 10.0)), move (newSamplerVoices))); } } @@ -2307,7 +2315,7 @@ public: class SetNumVoicesCommand { public: - SetNumVoicesCommand (std::vector> newVoices) + SetNumVoicesCommand (std::vector> newVoices) : newVoices (move (newVoices)) {} @@ -2325,12 +2333,12 @@ public: } private: - std::vector> newVoices; + std::vector> newVoices; }; numberOfVoices = std::min (maxVoices, numberOfVoices); auto loadedSamplerSound = samplerSound.load(); - std::vector> newSamplerVoices; + std::vector> 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 (readerFactory), + dataModel.setSampleReader (std::unique_ptr (readerFactory), &undoManager); } @@ -2559,12 +2567,12 @@ private: }; template - static ScopedPointer make_command (Func&& func) + static std::unique_ptr make_command (Func&& func) { - return ScopedPointer> (new TemplateCommand (std::forward (func))); + return std::unique_ptr> (new TemplateCommand (std::forward (func))); } - using CommandFifo = MoveOnlyFifo>; + using CommandFifo = MoveOnlyFifo>; class OutgoingBufferCleaner : public Timer { @@ -2604,7 +2612,8 @@ private: CommandFifo outgoingCommands; OutgoingBufferCleaner outgoingBufferCleaner { outgoingCommands }; - ScopedPointer readerFactory { new FileAudioFormatReaderFactory (getAssetsDirectory().getChildFile ("cello.wav")) }; + MemoryBlock mb; + std::unique_ptr readerFactory; AtomicSharedPtr samplerSound { std::make_shared() }; MPESynthesiser synthesiser;