From d40a84d27ec12149b3ea9188a025f9c890c31c0f Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Thu, 13 Jul 2023 13:40:07 -0700 Subject: [PATCH 1/6] Clean up warnings --- module/SFZero/SFZero.h | 2 +- module/SFZero/SFZero/RIFF.cpp | 12 ++-- module/SFZero/SFZero/RIFF.h | 12 ++-- module/SFZero/SFZero/SF2.cpp | 24 ++++---- module/SFZero/SFZero/SF2.h | 24 ++++---- module/SFZero/SFZero/SF2Reader.cpp | 44 +++++++-------- module/SFZero/SFZero/SF2Reader.h | 31 +++++------ module/SFZero/SFZero/SF2Sound.cpp | 22 ++++---- module/SFZero/SFZero/SF2Sound.h | 76 +++++++++++++------------- module/SFZero/SFZero/SFZDebug.cpp | 44 ++++++++------- module/SFZero/SFZero/SFZDebug.h | 10 ++-- module/SFZero/SFZero/SFZEG.cpp | 12 ++-- module/SFZero/SFZero/SFZReader.cpp | 57 ++++++++++--------- module/SFZero/SFZero/SFZReader.h | 18 +++--- module/SFZero/SFZero/SFZRegion.cpp | 12 ++-- module/SFZero/SFZero/SFZRegion.h | 6 +- module/SFZero/SFZero/SFZSample.cpp | 18 +++--- module/SFZero/SFZero/SFZSample.h | 49 +++++++++-------- module/SFZero/SFZero/SFZSound.cpp | 48 ++++++++-------- module/SFZero/SFZero/SFZSound.h | 2 +- module/SFZero/SFZero/SFZSynth.cpp | 16 +++--- module/SFZero/SFZero/SFZVoice.cpp | 48 +++++++--------- module/SFZero/SFZero/StringSlice.h | 2 +- module/SFZero/SFZero/sf2-chunks/iver.h | 4 +- 24 files changed, 292 insertions(+), 301 deletions(-) diff --git a/module/SFZero/SFZero.h b/module/SFZero/SFZero.h index 5eff040..0adc966 100644 --- a/module/SFZero/SFZero.h +++ b/module/SFZero/SFZero.h @@ -5,7 +5,7 @@ BEGIN_JUCE_MODULE_DECLARATION version: 1.0.0 name: SFZero description: Player for SFZ and SF2 files. - dependencies: juce_audio_basics, juce_audio_processor + dependencies: juce_audio_basics, juce_audio_processors website: http://stevefolta.github.io/SFZero/ license: MIT END_JUCE_MODULE_DECLARATION diff --git a/module/SFZero/SFZero/RIFF.cpp b/module/SFZero/SFZero/RIFF.cpp index c5a0af9..5b8b944 100644 --- a/module/SFZero/SFZero/RIFF.cpp +++ b/module/SFZero/SFZero/RIFF.cpp @@ -3,7 +3,7 @@ using namespace SFZero; -void RIFFChunk::ReadFrom(InputStream* file) +void RIFFChunk::ReadFrom(juce::InputStream* file) { file->read(&id, sizeof(fourcc)); size = (dword) file->readInt(); @@ -26,26 +26,26 @@ void RIFFChunk::ReadFrom(InputStream* file) } -void RIFFChunk::Seek(InputStream* file) +void RIFFChunk::Seek(juce::InputStream* file) { file->setPosition(start); } -void RIFFChunk::SeekAfter(InputStream* file) +void RIFFChunk::SeekAfter(juce::InputStream* file) { - int64 next = start + size; + int64_t next = start + size; if (next % 2 != 0) next += 1; file->setPosition(next); } -String RIFFChunk::ReadString(InputStream* file) +juce::String RIFFChunk::ReadString(juce::InputStream* file) { char str[size]; file->read(str, size); - return String(str); + return juce::String(str); } diff --git a/module/SFZero/SFZero/RIFF.h b/module/SFZero/SFZero/RIFF.h index 3ffb2d7..13b84bf 100644 --- a/module/SFZero/SFZero/RIFF.h +++ b/module/SFZero/SFZero/RIFF.h @@ -17,14 +17,14 @@ struct RIFFChunk { fourcc id; dword size; Type type; - int64 start; + int64_t start; - void ReadFrom(InputStream* file); - void Seek(InputStream* file); - void SeekAfter(InputStream* file); - int64 End() { return start + size; } + void ReadFrom(juce::InputStream* file); + void Seek(juce::InputStream* file); + void SeekAfter(juce::InputStream* file); + int64_t End() { return start + size; } - String ReadString(InputStream* file); + juce::String ReadString(juce::InputStream* file); }; diff --git a/module/SFZero/SFZero/SF2.cpp b/module/SFZero/SFZero/SF2.cpp index cc35d16..b2f4586 100644 --- a/module/SFZero/SFZero/SF2.cpp +++ b/module/SFZero/SFZero/SF2.cpp @@ -23,61 +23,61 @@ using namespace SFZero; readA##type(name, file) -void SF2::iver::ReadFrom(InputStream* file) +void SF2::iver::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/iver.h" } -void SF2::phdr::ReadFrom(InputStream* file) +void SF2::phdr::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/phdr.h" } -void SF2::pbag::ReadFrom(InputStream* file) +void SF2::pbag::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/pbag.h" } -void SF2::pmod::ReadFrom(InputStream* file) +void SF2::pmod::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/pmod.h" } -void SF2::pgen::ReadFrom(InputStream* file) +void SF2::pgen::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/pgen.h" } -void SF2::inst::ReadFrom(InputStream* file) +void SF2::inst::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/inst.h" } -void SF2::ibag::ReadFrom(InputStream* file) +void SF2::ibag::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/ibag.h" } -void SF2::imod::ReadFrom(InputStream* file) +void SF2::imod::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/imod.h" } -void SF2::igen::ReadFrom(InputStream* file) +void SF2::igen::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/igen.h" } -void SF2::shdr::ReadFrom(InputStream* file) +void SF2::shdr::ReadFrom(juce::InputStream* file) { #include "sf2-chunks/shdr.h" } @@ -105,13 +105,13 @@ SF2::Hydra::~Hydra() } -void SF2::Hydra::ReadFrom(InputStream* file, int64 pdtaChunkEnd) +void SF2::Hydra::ReadFrom(juce::InputStream* file, int64_t pdtaChunkEnd) { int i, numItems; #define HandleChunk(chunkName) \ if (FourCCEquals(chunk.id, #chunkName)) { \ - numItems = chunk.size / SF2::chunkName::sizeInFile; \ + numItems = int (chunk.size) / SF2::chunkName::sizeInFile; \ chunkName##NumItems = numItems; \ chunkName##Items = new SF2::chunkName[numItems]; \ for (i = 0; i < numItems; ++i) \ diff --git a/module/SFZero/SFZero/SF2.h b/module/SFZero/SFZero/SF2.h index ffe460e..2b2a5af 100644 --- a/module/SFZero/SFZero/SF2.h +++ b/module/SFZero/SFZero/SF2.h @@ -23,60 +23,60 @@ namespace SF2 { struct iver { #include "sf2-chunks/iver.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); }; struct phdr { #include "sf2-chunks/phdr.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 38; }; struct pbag { #include "sf2-chunks/pbag.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 4; }; struct pmod { #include "sf2-chunks/pmod.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 10; }; struct pgen { #include "sf2-chunks/pgen.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 4; }; struct inst { #include "sf2-chunks/inst.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 22; }; struct ibag { #include "sf2-chunks/ibag.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 4; }; struct imod { #include "sf2-chunks/imod.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 10; }; struct igen { #include "sf2-chunks/igen.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 4; }; struct shdr { #include "sf2-chunks/shdr.h" - void ReadFrom(InputStream* file); + void ReadFrom(juce::InputStream* file); static const int sizeInFile = 46; }; @@ -99,11 +99,11 @@ namespace SF2 { Hydra(); ~Hydra(); - void ReadFrom(InputStream* file, int64 pdtaChunkEnd); + void ReadFrom(juce::InputStream* file, int64_t pdtaChunkEnd); bool IsComplete(); }; - }; + } #undef SF2Field diff --git a/module/SFZero/SFZero/SF2Reader.cpp b/module/SFZero/SFZero/SF2Reader.cpp index 7272668..2da7ee3 100644 --- a/module/SFZero/SFZero/SF2Reader.cpp +++ b/module/SFZero/SFZero/SF2Reader.cpp @@ -9,7 +9,7 @@ using namespace SFZero; -SF2Reader::SF2Reader(SF2Sound* soundIn, const File& fileIn) +SF2Reader::SF2Reader(SF2Sound* soundIn, const juce::File& fileIn) : sound(soundIn) { file = fileIn.createInputStream(); @@ -18,7 +18,6 @@ SF2Reader::SF2Reader(SF2Sound* soundIn, const File& fileIn) SF2Reader::~SF2Reader() { - delete file; } @@ -33,15 +32,15 @@ void SF2Reader::read() SF2::Hydra hydra; file->setPosition(0); RIFFChunk riffChunk; - riffChunk.ReadFrom(file); + riffChunk.ReadFrom(file.get()); while (file->getPosition() < riffChunk.End()) { RIFFChunk chunk; - chunk.ReadFrom(file); + chunk.ReadFrom(file.get()); if (FourCCEquals(chunk.id, "pdta")) { - hydra.ReadFrom(file, chunk.End()); + hydra.ReadFrom(file.get(), chunk.End()); break; } - chunk.SeekAfter(file); + chunk.SeekAfter(file.get()); } if (!hydra.IsComplete()) { sound->addError("Invalid SF2 file (missing or incomplete hydra)."); @@ -85,16 +84,16 @@ void SF2Reader::read() SF2::inst* inst = &hydra.instItems[whichInst]; int firstZone = inst->instBagNdx; - int zoneEnd = inst[1].instBagNdx; - for (int whichZone = firstZone; whichZone < zoneEnd; ++whichZone) { - SF2::ibag* ibag = &hydra.ibagItems[whichZone]; + int zoneEndL = inst[1].instBagNdx; + for (int whichZoneL = firstZone; whichZoneL < zoneEndL; ++whichZoneL) { + SF2::ibag* ibag = &hydra.ibagItems[whichZoneL]; // Generators. SFZRegion zoneRegion = instRegion; bool hadSampleID = false; - int genEnd = ibag[1].instGenNdx; - for (int whichGen = ibag->instGenNdx; whichGen < genEnd; ++whichGen) { - SF2::igen* igen = &hydra.igenItems[whichGen]; + int genEndL = ibag[1].instGenNdx; + for (int whichGenL = ibag->instGenNdx; whichGenL < genEndL; ++whichGenL) { + SF2::igen* igen = &hydra.igenItems[whichGenL]; if (igen->genOper == SF2Generator::sampleID) { int whichSample = igen->genAmount.wordAmount; SF2::shdr* shdr = &hydra.shdrItems[whichSample]; @@ -128,7 +127,7 @@ void SF2Reader::read() } // Handle instrument's global zone. - if (whichZone == firstZone && !hadSampleID) + if (whichZoneL == firstZone && !hadSampleID) instRegion = zoneRegion; // Modulators. @@ -157,8 +156,7 @@ void SF2Reader::read() } -AudioSampleBuffer* SF2Reader::readSamples( - double* progressVar, Thread* thread) +juce::AudioSampleBuffer* SF2Reader::readSamples (double* progressVar, juce::Thread* thread) { static const unsigned long bufferSize = 32768; @@ -170,26 +168,26 @@ AudioSampleBuffer* SF2Reader::readSamples( // Find the "sdta" chunk. file->setPosition(0); RIFFChunk riffChunk; - riffChunk.ReadFrom(file); + riffChunk.ReadFrom(file.get()); bool found = false; RIFFChunk chunk; while (file->getPosition() < riffChunk.End()) { - chunk.ReadFrom(file); + chunk.ReadFrom(file.get()); if (FourCCEquals(chunk.id, "sdta")) { found = true; break; } - chunk.SeekAfter(file); + chunk.SeekAfter(file.get()); } - int64 sdtaEnd = chunk.End(); + int64_t sdtaEnd = chunk.End(); found = false; while (file->getPosition() < sdtaEnd) { - chunk.ReadFrom(file); + chunk.ReadFrom(file.get()); if (FourCCEquals(chunk.id, "smpl")) { found = true; break; } - chunk.SeekAfter(file); + chunk.SeekAfter(file.get()); } if (!found) { sound->addError("SF2 is missing its \"smpl\" chunk."); @@ -198,7 +196,7 @@ AudioSampleBuffer* SF2Reader::readSamples( // Allocate the AudioSampleBuffer. unsigned long numSamples = chunk.size / sizeof(short); - AudioSampleBuffer* sampleBuffer = new AudioSampleBuffer(1, numSamples); + juce::AudioSampleBuffer* sampleBuffer = new juce::AudioSampleBuffer(1, int (numSamples)); // Read and convert. short* buffer = new short[bufferSize]; @@ -209,7 +207,7 @@ AudioSampleBuffer* SF2Reader::readSamples( unsigned long samplesToRead = bufferSize; if (samplesToRead > samplesLeft) samplesToRead = samplesLeft; - file->read(buffer, samplesToRead * sizeof(short)); + file->read(buffer, int (samplesToRead * sizeof(short))); // Convert from signed 16-bit to float. unsigned long samplesToConvert = samplesToRead; diff --git a/module/SFZero/SFZero/SF2Reader.h b/module/SFZero/SFZero/SF2Reader.h index d98d857..a1debf6 100644 --- a/module/SFZero/SFZero/SF2Reader.h +++ b/module/SFZero/SFZero/SF2Reader.h @@ -11,22 +11,21 @@ class SFZRegion; class SFZSample; -class SF2Reader { - public: - SF2Reader(SF2Sound* sound, const File& file); - ~SF2Reader(); - - void read(); - AudioSampleBuffer* readSamples( - double* progressVar = NULL, Thread* thread = NULL); - - protected: - SF2Sound* sound; - FileInputStream* file; - - void addGeneratorToRegion( - word genOper, SF2::genAmountType* amount, SFZRegion* region); - }; +class SF2Reader +{ +public: + SF2Reader (SF2Sound* sound, const juce::File& file); + ~SF2Reader (); + + void read(); + juce::AudioSampleBuffer* readSamples (double* progressVar = NULL, juce::Thread* thread = NULL); + +protected: + SF2Sound* sound; + std::unique_ptr file; + + void addGeneratorToRegion (word genOper, SF2::genAmountType* amount, SFZRegion* region); +}; } diff --git a/module/SFZero/SFZero/SF2Sound.cpp b/module/SFZero/SFZero/SF2Sound.cpp index 6cea713..b55dbeb 100644 --- a/module/SFZero/SFZero/SF2Sound.cpp +++ b/module/SFZero/SFZero/SF2Sound.cpp @@ -6,7 +6,7 @@ using namespace SFZero; -SF2Sound::SF2Sound(const File& file) +SF2Sound::SF2Sound(const juce::File& file) : SFZSound(file) { } @@ -19,8 +19,8 @@ SF2Sound::~SF2Sound() regions.clear(); // The samples all share a single buffer, so make sure they don't all delete it. - AudioSampleBuffer* buffer = NULL; - for (HashMap::Iterator i(samplesByRate); i.next();) + juce::AudioSampleBuffer* buffer = NULL; + for (juce::HashMap::Iterator i(samplesByRate); i.next();) buffer = i.getValue()->detachBuffer(); delete buffer; } @@ -49,15 +49,13 @@ void SF2Sound::loadRegions() } -void SF2Sound::loadSamples( - AudioFormatManager* formatManager, - double* progressVar, Thread* thread) +void SF2Sound::loadSamples(juce::AudioFormatManager* /*formatManager*/, double* progressVar, juce::Thread* thread) { SF2Reader reader(this, file); - AudioSampleBuffer* buffer = reader.readSamples(progressVar, thread); + juce::AudioSampleBuffer* buffer = reader.readSamples(progressVar, thread); if (buffer) { // All the SFZSamples will share the buffer. - for (HashMap::Iterator i(samplesByRate); i.next();) + for (juce::HashMap::Iterator i(samplesByRate); i.next();) i.getValue()->setBuffer(buffer); } @@ -78,10 +76,10 @@ int SF2Sound::numSubsounds() } -String SF2Sound::subsoundName(int whichSubsound) +juce::String SF2Sound::subsoundName(int whichSubsound) { Preset* preset = presets[whichSubsound]; - String result; + juce::String result; if (preset->bank != 0) { result += preset->bank; result += "/"; @@ -118,9 +116,9 @@ SFZSample* SF2Sound::sampleFor(unsigned long sampleRate) } -void SF2Sound::setSamplesBuffer(AudioSampleBuffer* buffer) +void SF2Sound::setSamplesBuffer(juce::AudioSampleBuffer* buffer) { - for (HashMap::Iterator i(samplesByRate); i.next();) + for (juce::HashMap::Iterator i(samplesByRate); i.next();) i.getValue()->setBuffer(buffer); } diff --git a/module/SFZero/SFZero/SF2Sound.h b/module/SFZero/SFZero/SF2Sound.h index 86bccfe..3f2fa5b 100644 --- a/module/SFZero/SFZero/SF2Sound.h +++ b/module/SFZero/SFZero/SF2Sound.h @@ -6,45 +6,43 @@ namespace SFZero { -class SF2Sound : public SFZSound { - public: - SF2Sound(const File& file); - ~SF2Sound(); - - void loadRegions(); - void loadSamples( - AudioFormatManager* formatManager, - double* progressVar = NULL, Thread* thread = NULL); - - struct Preset { - String name; - int bank; - int preset; - OwnedArray regions; - - Preset(String nameIn, int bankIn, int presetIn) - : name(nameIn), bank(bankIn), preset(presetIn) {} - ~Preset() {} - - void addRegion(SFZRegion* region) { - regions.add(region); - } - }; - void addPreset(Preset* preset); - - int numSubsounds(); - String subsoundName(int whichSubsound); - void useSubsound(int whichSubsound); - int selectedSubsound(); - - SFZSample* sampleFor(unsigned long sampleRate); - void setSamplesBuffer(AudioSampleBuffer* buffer); - - protected: - OwnedArray presets; - HashMap samplesByRate; - int selectedPreset; - }; +class SF2Sound : public SFZSound +{ +public: + SF2Sound(const juce::File& file); + ~SF2Sound(); + + void loadRegions(); + void loadSamples(juce::AudioFormatManager* formatManager, double* progressVar = NULL, juce::Thread* thread = NULL); + + struct Preset + { + juce::String name; + int bank; + int preset; + juce::OwnedArray regions; + + Preset(juce::String nameIn, int bankIn, int presetIn) + : name(nameIn), bank(bankIn), preset(presetIn) {} + ~Preset() {} + + void addRegion(SFZRegion* region) { regions.add(region); } + }; + void addPreset(Preset* preset); + + int numSubsounds(); + juce::String subsoundName(int whichSubsound); + void useSubsound(int whichSubsound); + int selectedSubsound(); + + SFZSample* sampleFor (unsigned long sampleRate); + void setSamplesBuffer (juce::AudioSampleBuffer* buffer); + +protected: + juce::OwnedArray presets; + juce::HashMap samplesByRate; + int selectedPreset; +}; } diff --git a/module/SFZero/SFZero/SFZDebug.cpp b/module/SFZero/SFZero/SFZDebug.cpp index 3ae3253..1ed59e1 100644 --- a/module/SFZero/SFZero/SFZDebug.cpp +++ b/module/SFZero/SFZero/SFZDebug.cpp @@ -19,14 +19,14 @@ LogFifo::~LogFifo() } -void LogFifo::logMessage(const String& message) +void LogFifo::logMessage(const juce::String& message) { const char* p; // Stupid String class doesn't really let us get number of bytes. const char* bytes = message.getCharPointer(); unsigned long msgSize = strlen(bytes); - int totalSize = sizeof(unsigned long) + msgSize; + int totalSize = int (sizeof(unsigned long) + msgSize); int start1, size1, start2, size2; fifo.prepareToWrite(totalSize, start1, size1, start2, size2); int givenSize = size1 + size2; @@ -65,39 +65,43 @@ void LogFifo::logMessage(const String& message) void LogFifo::relayMessages() { - while (hasMessage()) { - String message = nextMessage(); - Logger::writeToLog(message); - } + while (hasMessage()) + { + juce::String message = nextMessage(); + juce::Logger::writeToLog(message); + } } -String LogFifo::nextMessage() +juce::String LogFifo::nextMessage() { // Read the count. unsigned long msgSize = 0; int start1, size1, start2, size2; fifo.prepareToRead(sizeof(unsigned long), start1, size1, start2, size2); char* p = (char*) &msgSize; - if (size1 > 0) { + if (size1 > 0) + { memcpy(p, &buffer[start1], size1); p += size1; - } + } if (size2 > 0) memcpy(p, &buffer[start2], size2); fifo.finishedRead(size1 + size2); // Read the string. - String result; - fifo.prepareToRead(msgSize, start1, size1, start2, size2); - if (size1 > 0) { + juce::String result; + fifo.prepareToRead(int (msgSize), start1, size1, start2, size2); + if (size1 > 0) + { p = &buffer[start1]; - result = String(CharPointer_UTF8(p), CharPointer_UTF8(p + size1)); - } - if (size2 > 0) { + result = juce::String(juce::CharPointer_UTF8(p), juce::CharPointer_UTF8(p + size1)); + } + if (size2 > 0) + { p = &buffer[start2]; - result += String(CharPointer_UTF8(p), CharPointer_UTF8(p + size2)); - } + result += juce::String(juce::CharPointer_UTF8(p), juce::CharPointer_UTF8(p + size2)); + } fifo.finishedRead(size1 + size2); return result; @@ -111,15 +115,15 @@ bool LogFifo::hasMessage() -void SFZero::setupLogging(Logger* logger) +void SFZero::setupLogging (juce::Logger* logger) { if (fifo == NULL) fifo = new LogFifo(); - Logger::setCurrentLogger(logger); + juce::Logger::setCurrentLogger(logger); } -void SFZero::fifoLogMessage(const String& message) +void SFZero::fifoLogMessage(const juce::String& message) { if (fifo) fifo->logMessage(message); diff --git a/module/SFZero/SFZero/SFZDebug.h b/module/SFZero/SFZero/SFZDebug.h index bbadc44..8ec3037 100644 --- a/module/SFZero/SFZero/SFZDebug.h +++ b/module/SFZero/SFZero/SFZDebug.h @@ -24,21 +24,21 @@ class LogFifo { LogFifo(); ~LogFifo(); - void logMessage(const String& message); + void logMessage(const juce::String& message); void relayMessages(); - String nextMessage(); + juce::String nextMessage(); bool hasMessage(); protected: enum { capacity = 512 * 1024, }; - AbstractFifo fifo; + juce::AbstractFifo fifo; char buffer[capacity]; }; -extern void setupLogging(Logger* logger); -extern void fifoLogMessage(const String& message); +extern void setupLogging(juce::Logger* logger); +extern void fifoLogMessage(const juce::String& message); extern void relayFifoLogMessages(); extern void dbgprintf(const char* msg, ...); diff --git a/module/SFZero/SFZero/SFZEG.cpp b/module/SFZero/SFZero/SFZEG.cpp index 65265bb..e2c8b0d 100644 --- a/module/SFZero/SFZero/SFZEG.cpp +++ b/module/SFZero/SFZero/SFZEG.cpp @@ -82,7 +82,7 @@ void SFZEG::noteOff() void SFZEG::fastRelease() { segment = Release; - samplesUntilNextSegment = fastReleaseTime * sampleRate; + samplesUntilNextSegment = long (fastReleaseTime * sampleRate); slope = -level / samplesUntilNextSegment; segmentIsExponential = false; } @@ -96,7 +96,7 @@ void SFZEG::startDelay() segment = Delay; level = 0.0; slope = 0.0; - samplesUntilNextSegment = parameters.delay * sampleRate; + samplesUntilNextSegment = long (parameters.delay * sampleRate); segmentIsExponential = false; } } @@ -109,7 +109,7 @@ void SFZEG::startAttack() else { segment = Attack; level = parameters.start / 100.0; - samplesUntilNextSegment = parameters.attack * sampleRate; + samplesUntilNextSegment = long (parameters.attack * sampleRate); slope = 1.0 / samplesUntilNextSegment; segmentIsExponential = false; } @@ -124,7 +124,7 @@ void SFZEG::startHold() } else { segment = Hold; - samplesUntilNextSegment = parameters.hold * sampleRate; + samplesUntilNextSegment = long (parameters.hold * sampleRate); level = 1.0; slope = 0.0; segmentIsExponential = false; @@ -138,7 +138,7 @@ void SFZEG::startDecay() startSustain(); else { segment = Decay; - samplesUntilNextSegment = parameters.decay * sampleRate; + samplesUntilNextSegment = long (parameters.decay * sampleRate); level = 1.0; if (exponentialDecay) { // I don't truly understand this; just following what LinuxSampler does. @@ -188,7 +188,7 @@ void SFZEG::startRelease() } segment = Release; - samplesUntilNextSegment = release * sampleRate; + samplesUntilNextSegment = long (release * sampleRate); if (exponentialDecay) { // I don't truly understand this; just following what LinuxSampler does. float mysterySlope = -9.226 / samplesUntilNextSegment; diff --git a/module/SFZero/SFZero/SFZReader.cpp b/module/SFZero/SFZero/SFZReader.cpp index 6f2451a..c38bb3b 100644 --- a/module/SFZero/SFZero/SFZReader.cpp +++ b/module/SFZero/SFZero/SFZReader.cpp @@ -18,16 +18,16 @@ SFZReader::~SFZReader() } -void SFZReader::read(const File& file) +void SFZReader::read(const juce::File& file) { - MemoryBlock contents; + juce::MemoryBlock contents; bool ok = file.loadFileAsData(contents); if (!ok) { sound->addError("Couldn't read \"" + file.getFullPathName() + "\""); return; } - read((const char*) contents.getData(), contents.getSize()); + read((const char*) contents.getData(), (unsigned int)contents.getSize()); } @@ -35,13 +35,13 @@ void SFZReader::read(const char* text, unsigned int length) { const char* p = text; const char* end = text + length; - char c; + char c = 0; SFZRegion curGroup; SFZRegion curRegion; SFZRegion* buildingRegion = NULL; bool inControl = false; - String defaultPath; + juce::String defaultPath; while (p < end) { // We're at the start of a line; skip any whitespace. @@ -155,14 +155,14 @@ void SFZReader::read(const char* text, unsigned int length) break; p++; } - String value(valueStart, p - valueStart); - String fauxOpcode = - String(opcode.start, opcode.length()) + " (in )"; + juce::String value(valueStart, p - valueStart); + juce::String fauxOpcode = juce::String(opcode.start, opcode.length()) + " (in )"; sound->addUnsupportedOpcode(fauxOpcode); } } - else if (opcode == "sample") { - String path; + else if (opcode == "sample") + { + juce::String path; p = readPathInto(&path, p, end); if (!path.isEmpty()) { if (buildingRegion) @@ -173,7 +173,8 @@ void SFZReader::read(const char* text, unsigned int length) else error("Empty sample path"); } - else { + else + { const char* valueStart = p; while (p < end) { c = *p; @@ -181,7 +182,7 @@ void SFZReader::read(const char* text, unsigned int length) break; p++; } - String value(valueStart, p - valueStart); + juce::String value(valueStart, p - valueStart); if (buildingRegion == NULL) error("Setting a parameter outside a region or group"); else if (opcode == "lokey") @@ -207,11 +208,11 @@ void SFZReader::read(const char* text, unsigned int length) else if (opcode == "offset") buildingRegion->offset = (unsigned long) value.getLargeIntValue(); else if (opcode == "end") { - int64 end = (unsigned long) value.getLargeIntValue(); - if (end < 0) + int64_t endV = (unsigned long) value.getLargeIntValue(); + if (endV < 0) buildingRegion->negative_end = true; else - buildingRegion->end = end; + buildingRegion->end = endV; } else if (opcode == "loop_mode") { bool modeIsSupported = @@ -221,8 +222,7 @@ void SFZReader::read(const char* text, unsigned int length) if (modeIsSupported) buildingRegion->loop_mode = (SFZRegion::LoopMode) loopModeValue(value); else { - String fauxOpcode = - String(opcode.start, opcode.length()) + "=" + value; + juce::String fauxOpcode = juce::String(opcode.start, opcode.length()) + "=" + value; sound->addUnsupportedOpcode(fauxOpcode); } } @@ -277,7 +277,7 @@ void SFZReader::read(const char* text, unsigned int length) else if (opcode == "default_path") error("\"default_path\" outside of tag"); else - sound->addUnsupportedOpcode(String(opcode.start, opcode.length())); + sound->addUnsupportedOpcode(juce::String(opcode.start, opcode.length())); } } @@ -314,8 +314,7 @@ const char* SFZReader::handleLineEnd(const char* p) } -const char* SFZReader::readPathInto( - String* pathOut, const char* pIn, const char* endIn) +const char* SFZReader::readPathInto(juce::String* pathOut, const char* pIn, const char* endIn) { // Paths are kind of funny to parse because they can contain whitespace. const char* p = pIn; @@ -347,17 +346,17 @@ const char* SFZReader::readPathInto( // Can't do this: // String path(CharPointer_UTF8(pathStart), CharPointer_UTF8(p)); // It won't compile for some unfathomable reason. - CharPointer_UTF8 end(p); - String path(CharPointer_UTF8(pathStart), end); + juce::CharPointer_UTF8 endL(p); + juce::String path(juce::CharPointer_UTF8(pathStart), endL); *pathOut = path; } else - *pathOut = String::empty; + *pathOut = juce::String (); return p; } -int SFZReader::keyValue(const String& str) +int SFZReader::keyValue(const juce::String& str) { char c = str[0]; if (c >= '0' && c <= '9') @@ -387,7 +386,7 @@ int SFZReader::keyValue(const String& str) } -int SFZReader::triggerValue(const String& str) +int SFZReader::triggerValue(const juce::String& str) { if (str == "release") return SFZRegion::release; @@ -399,7 +398,7 @@ int SFZReader::triggerValue(const String& str) } -int SFZReader::loopModeValue(const String& str) +int SFZReader::loopModeValue(const juce::String& str) { if (str == "no_loop") return SFZRegion::no_loop; @@ -421,10 +420,10 @@ void SFZReader::finishRegion(SFZRegion* region) } -void SFZReader::error(const String& message) +void SFZReader::error(const juce::String& message) { - String fullMessage = message; - fullMessage += " (line " + String(line) + ")."; + juce::String fullMessage = message; + fullMessage += " (line " + juce::String(line) + ")."; sound->addError(fullMessage); } diff --git a/module/SFZero/SFZero/SFZReader.h b/module/SFZero/SFZero/SFZReader.h index 24751e6..b3f5f20 100644 --- a/module/SFZero/SFZero/SFZReader.h +++ b/module/SFZero/SFZero/SFZReader.h @@ -14,20 +14,20 @@ class SFZReader { SFZReader(SFZSound* sound); ~SFZReader(); - void read(const File& file); - void read(const char* text, unsigned int length); + void read (const juce::File& file); + void read (const char* text, unsigned int length); protected: SFZSound* sound; int line; - const char* handleLineEnd(const char* p); - const char* readPathInto(String* pathOut, const char* p, const char* end); - int keyValue(const String& str); - int triggerValue(const String& str); - int loopModeValue(const String& str); - void finishRegion(SFZRegion* region); - void error(const String& message); + const char* handleLineEnd (const char* p); + const char* readPathInto (juce::String* pathOut, const char* p, const char* end); + int keyValue (const juce::String& str); + int triggerValue (const juce::String& str); + int loopModeValue (const juce::String& str); + void finishRegion (SFZRegion* region); + void error (const juce::String& message); }; } diff --git a/module/SFZero/SFZero/SFZRegion.cpp b/module/SFZero/SFZero/SFZRegion.cpp index bd3ab09..daeab3b 100644 --- a/module/SFZero/SFZero/SFZRegion.cpp +++ b/module/SFZero/SFZero/SFZRegion.cpp @@ -98,14 +98,14 @@ void SFZRegion::addForSF2(SFZRegion* other) void SFZRegion::sf2ToSFZ() { // EG times need to be converted from timecents to seconds. - ampeg.delay = timecents2Secs(ampeg.delay); - ampeg.attack = timecents2Secs(ampeg.attack); - ampeg.hold = timecents2Secs(ampeg.hold); - ampeg.decay = timecents2Secs(ampeg.decay); + ampeg.delay = timecents2Secs(short (ampeg.delay)); + ampeg.attack = timecents2Secs(short (ampeg.attack)); + ampeg.hold = timecents2Secs(short (ampeg.hold)); + ampeg.decay = timecents2Secs(short (ampeg.decay)); if (ampeg.sustain < 0.0) ampeg.sustain = 0.0; - ampeg.sustain = 100.0 * Decibels::decibelsToGain(-ampeg.sustain / 10.0); - ampeg.release = timecents2Secs(ampeg.release); + ampeg.sustain = 100.0 * juce::Decibels::decibelsToGain(-ampeg.sustain / 10.0); + ampeg.release = timecents2Secs(short (ampeg.release)); // Pin very short EG segments. Timecents don't get to zero, and our EG is // happier with zero values. diff --git a/module/SFZero/SFZero/SFZRegion.h b/module/SFZero/SFZero/SFZRegion.h index f565b1a..d789f92 100644 --- a/module/SFZero/SFZero/SFZRegion.h +++ b/module/SFZero/SFZero/SFZRegion.h @@ -36,12 +36,12 @@ class SFZRegion { void sf2ToSFZ(); void dump(); - bool matches(unsigned char note, unsigned char velocity, Trigger trigger) { + bool matches(unsigned char note, unsigned char velocity, Trigger triggerV) { return note >= lokey && note <= hikey && velocity >= lovel && velocity <= hivel && - (trigger == this->trigger || - (this->trigger == attack && (trigger == first || trigger == legato))); + (triggerV == this->trigger || + (this->trigger == attack && (triggerV == first || triggerV == legato))); } SFZSample* sample; diff --git a/module/SFZero/SFZero/SFZSample.cpp b/module/SFZero/SFZero/SFZSample.cpp index 5e127b0..c76fc36 100644 --- a/module/SFZero/SFZero/SFZSample.cpp +++ b/module/SFZero/SFZero/SFZSample.cpp @@ -4,18 +4,18 @@ using namespace SFZero; -bool SFZSample::load(AudioFormatManager* formatManager) +bool SFZSample::load(juce::AudioFormatManager* formatManager) { - AudioFormatReader* reader = formatManager->createReaderFor(file); + juce::AudioFormatReader* reader = formatManager->createReaderFor(file); if (reader == NULL) return false; sampleRate = reader->sampleRate; sampleLength = reader->lengthInSamples; // Read some extra samples, which will be filled with zeros, so interpolation // can be done without having to check for the edge all the time. - buffer = new AudioSampleBuffer(reader->numChannels, sampleLength + 4); - reader->read(buffer, 0, sampleLength + 4, 0, true, true); - StringPairArray* metadata = &reader->metadataValues; + buffer = new juce::AudioSampleBuffer(reader->numChannels, int (sampleLength + 4)); + reader->read(buffer, 0, int (sampleLength + 4), 0, true, true); + juce::StringPairArray* metadata = &reader->metadataValues; int numLoops = metadata->getValue("NumSampleLoops", "0").getIntValue(); if (numLoops > 0) { loopStart = metadata->getValue("Loop0Start", "0").getLargeIntValue(); @@ -32,22 +32,22 @@ SFZSample::~SFZSample() } -String SFZSample::getShortName() +juce::String SFZSample::getShortName() { return file.getFileName(); } -void SFZSample::setBuffer(AudioSampleBuffer* newBuffer) +void SFZSample::setBuffer(juce::AudioSampleBuffer* newBuffer) { buffer = newBuffer; sampleLength = buffer->getNumSamples(); } -AudioSampleBuffer* SFZSample::detachBuffer() +juce::AudioSampleBuffer* SFZSample::detachBuffer() { - AudioSampleBuffer* result = buffer; + juce::AudioSampleBuffer* result = buffer; buffer = NULL; return result; } diff --git a/module/SFZero/SFZero/SFZSample.h b/module/SFZero/SFZero/SFZSample.h index 28c90a5..fc4702c 100644 --- a/module/SFZero/SFZero/SFZSample.h +++ b/module/SFZero/SFZero/SFZSample.h @@ -6,35 +6,36 @@ namespace SFZero { -class SFZSample { - public: - SFZSample(const File& fileIn) - : loopStart(0), loopEnd(0), file(fileIn), buffer(NULL) {} - SFZSample(double sampleRateIn) - : sampleLength(0), loopStart(0), loopEnd(0), - buffer(NULL), sampleRate(sampleRateIn) {} - ~SFZSample(); - - bool load(AudioFormatManager* formatManager); - File getFile() { return file; } - AudioSampleBuffer* getBuffer() { return buffer; } - double getSampleRate() { return sampleRate; } - String getShortName(); - void setBuffer(AudioSampleBuffer* newBuffer); - AudioSampleBuffer* detachBuffer(); - void dump(); - - unsigned long sampleLength, loopStart, loopEnd; +class SFZSample +{ +public: + SFZSample(const juce::File& fileIn) + : loopStart(0), loopEnd(0), file(fileIn), buffer(NULL) {} + SFZSample(double sampleRateIn) + : sampleLength(0), loopStart(0), loopEnd(0), + buffer(NULL), sampleRate(sampleRateIn) {} + ~SFZSample(); + + bool load(juce::AudioFormatManager* formatManager); + juce::File getFile() { return file; } + juce::AudioSampleBuffer* getBuffer() { return buffer; } + double getSampleRate() { return sampleRate; } + juce::String getShortName(); + void setBuffer(juce::AudioSampleBuffer* newBuffer); + juce::AudioSampleBuffer* detachBuffer(); + void dump(); + + unsigned long sampleLength, loopStart, loopEnd; #ifdef JUCE_DEBUG void checkIfZeroed(const char* where); #endif - protected: - File file; - AudioSampleBuffer* buffer; - double sampleRate; - }; +protected: + juce::File file; + juce::AudioSampleBuffer* buffer; + double sampleRate; +}; } diff --git a/module/SFZero/SFZero/SFZSound.cpp b/module/SFZero/SFZero/SFZSound.cpp index a59f50f..0113ee9 100644 --- a/module/SFZero/SFZero/SFZSound.cpp +++ b/module/SFZero/SFZero/SFZSound.cpp @@ -21,19 +21,19 @@ SFZSound::~SFZSound() regions.set(i, NULL); } - for (HashMap::Iterator i(samples); i.next();) + for (juce::HashMap::Iterator i(samples); i.next();) delete i.getValue(); } -bool SFZSound::appliesToNote(const int midiNoteNumber) +bool SFZSound::appliesToNote(const int /*midiNoteNumber*/) { // Just say yes; we can't truly know unless we're told the velocity as well. return true; } -bool SFZSound::appliesToChannel(const int midiChannel) +bool SFZSound::appliesToChannel(const int /*midiChannel*/) { return true; } @@ -45,7 +45,7 @@ void SFZSound::addRegion(SFZRegion* region) } -SFZSample* SFZSound::addSample(String path, String defaultPath) +SFZSample* SFZSound::addSample(juce::String path, juce::String defaultPath) { path = path.replaceCharacter('\\', '/'); defaultPath = defaultPath.replaceCharacter('\\', '/'); @@ -56,7 +56,7 @@ SFZSample* SFZSound::addSample(String path, String defaultPath) juce::File defaultDir = file.getSiblingFile(defaultPath); sampleFile = defaultDir.getChildFile(path); } - String samplePath = sampleFile.getFullPathName(); + juce::String samplePath = sampleFile.getFullPathName(); SFZSample* sample = samples[samplePath]; if (sample == NULL) { sample = new SFZSample(sampleFile); @@ -66,13 +66,13 @@ SFZSample* SFZSound::addSample(String path, String defaultPath) } -void SFZSound::addError(const String& message) +void SFZSound::addError(const juce::String& message) { errors.add(message); } -void SFZSound::addUnsupportedOpcode(const String& opcode) +void SFZSound::addUnsupportedOpcode(const juce::String& opcode) { unsupportedOpcodes.set(opcode, opcode); } @@ -85,15 +85,13 @@ void SFZSound::loadRegions() } -void SFZSound::loadSamples( - AudioFormatManager* formatManager, - double* progressVar, Thread* thread) +void SFZSound::loadSamples (juce::AudioFormatManager* formatManager, double* progressVar, juce::Thread* thread) { if (progressVar) *progressVar = 0.0; double numSamplesLoaded = 1.0, numSamples = samples.size(); - for (HashMap::Iterator i(samples); i.next();) { + for (juce::HashMap::Iterator i(samples); i.next();) { SFZSample* sample = i.getValue(); bool ok = sample->load(formatManager); if (!ok) @@ -137,9 +135,9 @@ SFZRegion* SFZSound::regionAt(int index) } -String SFZSound::getErrorsString() +juce::String SFZSound::getErrorsString() { - String result; + juce::String result; int numErrors = errors.size(); for (int i = 0; i < numErrors; ++i) result += errors[i] + "\n"; @@ -147,7 +145,7 @@ String SFZSound::getErrorsString() if (unsupportedOpcodes.size() > 0) { result += "\nUnsupported opcodes:"; bool shownOne = false; - for (HashMap::Iterator i(unsupportedOpcodes); i.next();) { + for (juce::HashMap::Iterator i(unsupportedOpcodes); i.next();) { if (!shownOne) { result += " "; shownOne = true; @@ -168,13 +166,13 @@ int SFZSound::numSubsounds() } -String SFZSound::subsoundName(int whichSubsound) +juce::String SFZSound::subsoundName(int /*whichSubsound*/) { - return String::empty; + return {}; } -void SFZSound::useSubsound(int whichSubsound) +void SFZSound::useSubsound(int /*whichSubsound*/) { } @@ -200,15 +198,17 @@ void SFZSound::dump() printf("\n"); } - if (unsupportedOpcodes.size() > 0) { + if (unsupportedOpcodes.size() > 0) + { printf("Unused opcodes:\n"); - for (HashMap::Iterator i(unsupportedOpcodes); i.next();) { + for (juce::HashMap::Iterator itr(unsupportedOpcodes); itr.next();) + { char opcode[64]; - i.getKey().copyToUTF8(opcode, 64); + itr.getKey().copyToUTF8(opcode, 64); printf(" %s\n", opcode); - } - printf("\n"); } + printf("\n"); + } printf("Regions:\n"); int numRegions = regions.size(); @@ -217,8 +217,8 @@ void SFZSound::dump() printf("\n"); printf("Samples:\n"); - for (HashMap::Iterator i(samples); i.next();) - i.getValue()->dump(); + for (juce::HashMap::Iterator itr(samples); itr.next();) + itr.getValue()->dump(); } diff --git a/module/SFZero/SFZero/SFZSound.h b/module/SFZero/SFZero/SFZSound.h index a038a2a..30de5b5 100644 --- a/module/SFZero/SFZero/SFZSound.h +++ b/module/SFZero/SFZero/SFZSound.h @@ -19,7 +19,7 @@ class SFZSound : public juce::SynthesiserSound { bool appliesToChannel(const int midiChannel); void addRegion(SFZRegion* region); // Takes ownership of the region. - SFZSample* addSample(juce::String path, juce::String defaultPath = juce::String::empty); + SFZSample* addSample(juce::String path, juce::String defaultPath = {}); void addError(const juce::String& message); void addUnsupportedOpcode(const juce::String& opcode); diff --git a/module/SFZero/SFZero/SFZSynth.cpp b/module/SFZero/SFZero/SFZSynth.cpp index 6c7855b..13182e4 100644 --- a/module/SFZero/SFZero/SFZSynth.cpp +++ b/module/SFZero/SFZero/SFZSynth.cpp @@ -16,18 +16,18 @@ void SFZSynth::noteOn(int midiChannel, int midiNoteNumber, float velocity) { int i; - const ScopedLock locker(lock); + const juce::ScopedLock locker(lock); int midiVelocity = (int) (velocity * 127); // First, stop any currently-playing sounds in the group. //*** Currently, this only pays attention to the first matching region. int group = 0; - SFZSound* sound = dynamic_cast(getSound(0)); + SFZSound* sound = dynamic_cast(getSound(0).get()); if (sound) { SFZRegion* region = sound->getRegionFor(midiNoteNumber, midiVelocity); if (region) - group = region->group; + group = int (region->group); } if (group != 0) { for (i = voices.size(); --i >= 0;) { @@ -86,12 +86,12 @@ void SFZSynth::noteOff( int midiChannel, int midiNoteNumber, float velocity, bool allowTailOff) { - const ScopedLock locker(lock); + const juce::ScopedLock locker(lock); Synthesiser::noteOff(midiChannel, midiNoteNumber, velocity, allowTailOff); // Start release region. - SFZSound* sound = dynamic_cast(getSound(0)); + SFZSound* sound = dynamic_cast(getSound(0).get()); if (sound) { SFZRegion* region = sound->getRegionFor( @@ -125,13 +125,13 @@ int SFZSynth::numVoicesUsed() } -String SFZSynth::voiceInfoString() +juce::String SFZSynth::voiceInfoString() { enum { maxShownVoices = 20, }; - StringArray lines; + juce::StringArray lines; int numUsed = 0, numShown = 0; for (int i = voices.size(); --i >= 0;) { SFZVoice* voice = dynamic_cast(voices.getUnchecked(i)); @@ -142,7 +142,7 @@ String SFZSynth::voiceInfoString() continue; lines.add(voice->infoString()); } - lines.insert(0, "voices used: " + String(numUsed)); + lines.insert(0, "voices used: " + juce::String(numUsed)); return lines.joinIntoString("\n"); } diff --git a/module/SFZero/SFZero/SFZVoice.cpp b/module/SFZero/SFZero/SFZVoice.cpp index e770ba0..ce23190 100644 --- a/module/SFZero/SFZero/SFZVoice.cpp +++ b/module/SFZero/SFZero/SFZVoice.cpp @@ -22,17 +22,13 @@ SFZVoice::~SFZVoice() } -bool SFZVoice::canPlaySound(SynthesiserSound* sound) +bool SFZVoice::canPlaySound(juce::SynthesiserSound* sound) { return dynamic_cast(sound) != NULL; } -void SFZVoice::startNote( - const int midiNoteNumber, - const float floatVelocity, - SynthesiserSound* soundIn, - const int currentPitchWheelPosition) +void SFZVoice::startNote (const int midiNoteNumber, const float floatVelocity, juce::SynthesiserSound* soundIn, const int currentPitchWheelPosition) { SFZSound* sound = dynamic_cast(soundIn); if (sound == NULL) { @@ -66,7 +62,7 @@ void SFZVoice::startNote( double velocityGainDB = -20.0 * log10((127.0 * 127.0) / (velocity * velocity)); velocityGainDB *= region->amp_veltrack / 100.0; noteGainDB += velocityGainDB; - noteGainLeft = noteGainRight = Decibels::decibelsToGain(noteGainDB); + noteGainLeft = noteGainRight = juce::Decibels::decibelsToGain(noteGainDB); // The SFZ spec is silent about the pan curve, but a 3dB pan law seems // common. This sqrt() curve matches what Dimension LE does; Alchemy Free // seems closer to sin(adjustedPan * pi/2). @@ -105,7 +101,7 @@ void SFZVoice::startNote( } -void SFZVoice::stopNote(float velocity, const bool allowTailOff) +void SFZVoice::stopNote(float /*velocity*/, const bool allowTailOff) { if (!allowTailOff || region == NULL) { killNote(); @@ -146,9 +142,7 @@ void SFZVoice::pitchWheelMoved(const int newValue) } -void SFZVoice::controllerMoved( - const int controllerNumber, - const int newValue) +void SFZVoice::controllerMoved(const int /*controllerNumber*/, const int /*newValue*/) { /***/ } @@ -172,22 +166,22 @@ void SFZVoice::renderNextBlock( // Cache some values, to give them at least some chance of ending up in // registers. - double sourceSamplePosition = this->sourceSamplePosition; + double sourceSamplePositionL = this->sourceSamplePosition; float ampegGain = ampeg.level; float ampegSlope = ampeg.slope; long samplesUntilNextAmpSegment = ampeg.samplesUntilNextSegment; bool ampSegmentIsExponential = ampeg.segmentIsExponential; - float loopStart = this->loopStart; - float loopEnd = this->loopEnd; - float sampleEnd = this->sampleEnd; + float loopStartL = this->loopStart; + float loopEndL = this->loopEnd; + float sampleEndL = this->sampleEnd; while (--numSamples >= 0) { - int pos = (int) sourceSamplePosition; - float alpha = (float) (sourceSamplePosition - pos); + int pos = (int) sourceSamplePositionL; + float alpha = (float) (sourceSamplePositionL - pos); float invAlpha = 1.0f - alpha; int nextPos = pos + 1; - if (loopStart < loopEnd && nextPos > loopEnd) - nextPos = loopStart; + if (loopStartL < loopEndL && nextPos > loopEndL) + nextPos = int (loopStartL); // Simple linear interpolation. float l = (inL[pos] * invAlpha + inL[nextPos] * alpha); @@ -207,9 +201,9 @@ void SFZVoice::renderNextBlock( *outL++ += (l + r) * 0.5f; // Next sample. - sourceSamplePosition += pitchRatio; - if (loopStart < loopEnd && sourceSamplePosition > loopEnd) { - sourceSamplePosition = loopStart; + sourceSamplePositionL += pitchRatio; + if (loopStartL < loopEndL && sourceSamplePositionL > loopEndL) { + sourceSamplePositionL = loopStartL; numLoops += 1; } @@ -227,13 +221,13 @@ void SFZVoice::renderNextBlock( ampSegmentIsExponential = ampeg.segmentIsExponential; } - if (sourceSamplePosition >= sampleEnd || ampeg.isDone()) { + if (sourceSamplePositionL >= sampleEndL || ampeg.isDone()) { killNote(); break; } } - this->sourceSamplePosition = sourceSamplePosition; + this->sourceSamplePosition = sourceSamplePositionL; ampeg.level = ampegGain; ampeg.samplesUntilNextSegment = samplesUntilNextAmpSegment; } @@ -253,13 +247,13 @@ bool SFZVoice::isPlayingOneShot() int SFZVoice::getGroup() { - return (region ? region->group : 0); + return (region ? int (region->group) : 0); } int SFZVoice::getOffBy() { - return (region ? region->off_by : 0); + return (region ? int (region->off_by) : 0); } @@ -308,7 +302,7 @@ void SFZVoice::calcPitchRatio() adjustedPitch += wheel * region->bend_down / -100.0; } double targetFreq = noteHz(adjustedPitch); - double naturalFreq = MidiMessage::getMidiNoteInHertz(region->pitch_keycenter); + double naturalFreq = juce::MidiMessage::getMidiNoteInHertz(region->pitch_keycenter); pitchRatio = (targetFreq * region->sample->getSampleRate()) / (naturalFreq * sampleRate); diff --git a/module/SFZero/SFZero/StringSlice.h b/module/SFZero/SFZero/StringSlice.h index 77b04d3..2081280 100644 --- a/module/SFZero/SFZero/StringSlice.h +++ b/module/SFZero/SFZero/StringSlice.h @@ -13,7 +13,7 @@ class StringSlice { : start(startIn), end(endIn) {} unsigned int length() { - return end - start; + return (unsigned int)(end - start); } bool operator==(const char* other) { diff --git a/module/SFZero/SFZero/sf2-chunks/iver.h b/module/SFZero/SFZero/sf2-chunks/iver.h index 160a4eb..309af1a 100644 --- a/module/SFZero/SFZero/sf2-chunks/iver.h +++ b/module/SFZero/SFZero/sf2-chunks/iver.h @@ -1,3 +1,3 @@ -SF2Field(word, major); -SF2Field(word, minor); +SF2Field(word, major) +SF2Field(word, minor) From 97c0d3e05a715d123d7e1977ddcb6ec3a57caf68 Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Thu, 13 Jul 2023 13:56:46 -0700 Subject: [PATCH 2/6] More cleanup --- module/SFZero/SFZero.cpp | 3 ++- module/SFZero/SFZero.h | 8 ++++---- module/SFZero/SFZero/SF2.h | 1 - module/SFZero/SFZero/SF2Reader.h | 1 - module/SFZero/SFZero/SFZDebug.h | 2 -- module/SFZero/SFZero/SFZReader.h | 2 -- module/SFZero/SFZero/SFZSample.h | 3 --- module/SFZero/SFZero/SFZSound.cpp | 5 +++-- module/SFZero/SFZero/SFZSound.h | 2 -- module/SFZero/SFZero/SFZSynth.h | 3 --- module/SFZero/SFZero/SFZVoice.cpp | 1 - module/SFZero/SFZero/SFZVoice.h | 1 - 12 files changed, 9 insertions(+), 23 deletions(-) diff --git a/module/SFZero/SFZero.cpp b/module/SFZero/SFZero.cpp index e91339b..3c15d33 100644 --- a/module/SFZero/SFZero.cpp +++ b/module/SFZero/SFZero.cpp @@ -1,3 +1,5 @@ +#include + #include "SFZero/RIFF.cpp" #include "SFZero/SF2.cpp" #include "SFZero/SF2Generator.cpp" @@ -11,4 +13,3 @@ #include "SFZero/SFZSound.cpp" #include "SFZero/SFZSynth.cpp" #include "SFZero/SFZVoice.cpp" - diff --git a/module/SFZero/SFZero.h b/module/SFZero/SFZero.h index 0adc966..98f870c 100644 --- a/module/SFZero/SFZero.h +++ b/module/SFZero/SFZero.h @@ -11,13 +11,13 @@ BEGIN_JUCE_MODULE_DECLARATION END_JUCE_MODULE_DECLARATION */ -#ifndef SFZero_h -#define SFZero_h +#pragma once #include "SFZero/SFZVoice.h" #include "SFZero/SFZSound.h" #include "SFZero/SFZSynth.h" +#include "SFZero/SFZSound.h" +#include "SFZero/SFZSound.h" +#include "SFZero/SF2Sound.h" -#endif - diff --git a/module/SFZero/SFZero/SF2.h b/module/SFZero/SFZero/SF2.h index 2b2a5af..c6c6df1 100644 --- a/module/SFZero/SFZero/SF2.h +++ b/module/SFZero/SFZero/SF2.h @@ -1,7 +1,6 @@ #ifndef SF2_h #define SF2_h -#include "../JuceLibraryCode/JuceHeader.h" #include "WinTypes.h" namespace SFZero { diff --git a/module/SFZero/SFZero/SF2Reader.h b/module/SFZero/SFZero/SF2Reader.h index a1debf6..306e751 100644 --- a/module/SFZero/SFZero/SF2Reader.h +++ b/module/SFZero/SFZero/SF2Reader.h @@ -1,7 +1,6 @@ #ifndef SF2Reader_h #define SF2Reader_h -#include "../JuceLibraryCode/JuceHeader.h" #include "SF2.h" namespace SFZero { diff --git a/module/SFZero/SFZero/SFZDebug.h b/module/SFZero/SFZero/SFZDebug.h index 8ec3037..9cd9215 100644 --- a/module/SFZero/SFZero/SFZDebug.h +++ b/module/SFZero/SFZero/SFZDebug.h @@ -1,8 +1,6 @@ #ifndef SFZDebug_h #define SFZDebug_h -#include "../JuceLibraryCode/JuceHeader.h" - // Juce's standard DBG is all wrong; it only writes to stdout. So instead, use // one that'll write to the real log. diff --git a/module/SFZero/SFZero/SFZReader.h b/module/SFZero/SFZero/SFZReader.h index b3f5f20..2e27d31 100644 --- a/module/SFZero/SFZero/SFZReader.h +++ b/module/SFZero/SFZero/SFZReader.h @@ -1,8 +1,6 @@ #ifndef SFZReader_h #define SFZReader_h -#include "../JuceLibraryCode/JuceHeader.h" - namespace SFZero { class SFZRegion; diff --git a/module/SFZero/SFZero/SFZSample.h b/module/SFZero/SFZero/SFZSample.h index fc4702c..04fdad5 100644 --- a/module/SFZero/SFZero/SFZSample.h +++ b/module/SFZero/SFZero/SFZSample.h @@ -1,9 +1,6 @@ #ifndef SFZSample_h #define SFZSample_h -#include "../JuceLibraryCode/JuceHeader.h" - - namespace SFZero { class SFZSample diff --git a/module/SFZero/SFZero/SFZSound.cpp b/module/SFZero/SFZero/SFZSound.cpp index 0113ee9..5ec9171 100644 --- a/module/SFZero/SFZero/SFZSound.cpp +++ b/module/SFZero/SFZero/SFZSound.cpp @@ -16,10 +16,11 @@ SFZSound::SFZSound(const juce::File& fileIn) SFZSound::~SFZSound() { int numRegions = regions.size(); - for (int i = 0; i < numRegions; ++i) { + for (int i = 0; i < numRegions; ++i) + { delete regions[i]; regions.set(i, NULL); - } + } for (juce::HashMap::Iterator i(samples); i.next();) delete i.getValue(); diff --git a/module/SFZero/SFZero/SFZSound.h b/module/SFZero/SFZero/SFZSound.h index 30de5b5..0f7676a 100644 --- a/module/SFZero/SFZero/SFZSound.h +++ b/module/SFZero/SFZero/SFZSound.h @@ -1,10 +1,8 @@ #ifndef SFZSound_h #define SFZSound_h -#include "../JuceLibraryCode/JuceHeader.h" #include "SFZRegion.h" - namespace SFZero { class SFZSample; diff --git a/module/SFZero/SFZero/SFZSynth.h b/module/SFZero/SFZero/SFZSynth.h index 96cef95..f28bfd8 100644 --- a/module/SFZero/SFZero/SFZSynth.h +++ b/module/SFZero/SFZero/SFZSynth.h @@ -1,9 +1,6 @@ #ifndef SFZSynth_h #define SFZSynth_h -#include "../JuceLibraryCode/JuceHeader.h" - - namespace SFZero { class SFZSynth : public juce::Synthesiser { diff --git a/module/SFZero/SFZero/SFZVoice.cpp b/module/SFZero/SFZero/SFZVoice.cpp index ce23190..b71c785 100644 --- a/module/SFZero/SFZero/SFZVoice.cpp +++ b/module/SFZero/SFZero/SFZVoice.cpp @@ -3,7 +3,6 @@ #include "SFZRegion.h" #include "SFZSample.h" #include "SFZDebug.h" -#include using namespace SFZero; diff --git a/module/SFZero/SFZero/SFZVoice.h b/module/SFZero/SFZero/SFZVoice.h index ee4c95a..ea59dd5 100644 --- a/module/SFZero/SFZero/SFZVoice.h +++ b/module/SFZero/SFZero/SFZVoice.h @@ -1,7 +1,6 @@ #ifndef SFZVoice_h #define SFZVoice_h -#include "../JuceLibraryCode/JuceHeader.h" #include "SFZEG.h" namespace SFZero { From fbc6fb298e952f0a072b2bd6984908ea29f78d58 Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Tue, 4 Feb 2025 10:10:20 -0800 Subject: [PATCH 3/6] Modernize code --- SFZero.jucer | 16 +++--- Source/ClickableLabel.cpp | 6 +-- Source/ClickableLabel.h | 12 ++--- Source/SFZeroAudioProcessor.cpp | 78 ++++++++++++++--------------- Source/SFZeroAudioProcessor.h | 77 ++++++++++++++--------------- Source/SFZeroEditor.cpp | 88 +++++++++++++++++++-------------- Source/SFZeroEditor.h | 26 +++++----- module/SFZero/SFZero.h | 3 +- module/SFZero/SFZero/SF2Sound.h | 14 +++--- module/SFZero/SFZero/SFZSound.h | 6 +-- module/SFZero/SFZero/SFZSynth.h | 5 +- module/SFZero/SFZero/SFZVoice.h | 14 +++--- 12 files changed, 180 insertions(+), 165 deletions(-) diff --git a/SFZero.jucer b/SFZero.jucer index 1f62e61..b50f6c2 100644 --- a/SFZero.jucer +++ b/SFZero.jucer @@ -7,17 +7,21 @@ pluginIsSynth="1" pluginWantsMidiIn="1" pluginProducesMidiOut="0" pluginSilenceInIsSilenceOut="0" pluginTailLength="0" pluginEditorRequiresKeys="0" pluginAUExportPrefix="SFZeroDevAU" pluginAUViewClass="SFZeroAU_V1" - pluginRTASCategory="" jucerVersion="4.2.3" defines="" aaxIdentifier="com.yourcompany.SFZero-dev" - pluginAAXCategory="AAX_ePlugInCategory_Dynamics" buildVST3="0" - buildAUv3="0" buildAAX="0" pluginIsMidiEffectPlugin="0" includeBinaryInAppConfig="1"> + pluginRTASCategory="" defines="JUCE_MODAL_LOOPS_PERMITTED=1" + aaxIdentifier="com.yourcompany.SFZero-dev" pluginAAXCategory="2" + buildVST3="1" buildAUv3="0" buildAAX="0" pluginIsMidiEffectPlugin="0" + includeBinaryInAppConfig="1" pluginFormats="buildAU,buildStandalone,buildVST3" + pluginCharacteristicsValue="pluginIsSynth,pluginWantsMidiIn" + jucerFormatVersion="1" addUsingNamespaceToJuceHeader="0" buildStandalone="1" + enableIAA="0"> + osxSDK="default" osxCompatibility="default"/> + osxSDK="default" osxCompatibility="default"/> @@ -89,5 +93,5 @@ - + diff --git a/Source/ClickableLabel.cpp b/Source/ClickableLabel.cpp index 3249e47..4b5e0dd 100644 --- a/Source/ClickableLabel.cpp +++ b/Source/ClickableLabel.cpp @@ -12,8 +12,8 @@ ClickableLabel::ClickableLabel( - const String& componentName, - const String& labelText) + const juce::String& componentName, + const juce::String& labelText) : Label(componentName, labelText) { } @@ -31,7 +31,7 @@ void ClickableLabel::removeClickListener(ClickListener* listener) } -void ClickableLabel::mouseUp(const MouseEvent& e) +void ClickableLabel::mouseUp(const juce::MouseEvent& e) { bool goodClick = e.mouseWasClicked() && contains(e.getPosition()) && !e.mods.isPopupMenu(); diff --git a/Source/ClickableLabel.h b/Source/ClickableLabel.h index 83bee4e..502d60e 100644 --- a/Source/ClickableLabel.h +++ b/Source/ClickableLabel.h @@ -11,13 +11,13 @@ #ifndef __CLICKABLELABEL_H_F4AC0009__ #define __CLICKABLELABEL_H_F4AC0009__ -#include "../JuceLibraryCode/JuceHeader.h" +#include -class ClickableLabel : public Label { +class ClickableLabel : public juce::Label { public: ClickableLabel( - const String& componentName = String::empty, - const String& labelText = String::empty); + const juce::String& componentName = {}, + const juce::String& labelText = {}); class JUCE_API ClickListener { public: @@ -30,9 +30,9 @@ class ClickableLabel : public Label { void removeClickListener(ClickListener* listener); protected: - ListenerList clickListeners; + juce::ListenerList clickListeners; - void mouseUp(const MouseEvent& e); + void mouseUp(const juce::MouseEvent& e) override; }; diff --git a/Source/SFZeroAudioProcessor.cpp b/Source/SFZeroAudioProcessor.cpp index 2cbf8be..f06ce5f 100644 --- a/Source/SFZeroAudioProcessor.cpp +++ b/Source/SFZeroAudioProcessor.cpp @@ -1,9 +1,5 @@ #include "SFZeroAudioProcessor.h" #include "SFZeroEditor.h" -#include "SFZSound.h" -#include "SF2Sound.h" -#include "SFZVoice.h" -#include "SFZDebug.h" using namespace SFZero; @@ -13,12 +9,12 @@ SFZeroAudioProcessor::SFZeroAudioProcessor() { #if JUCE_DEBUG setupLogging( - FileLogger::createDefaultAppLogger( + juce::FileLogger::createDefaultAppLogger( "SFZero", "SFZero.log", "SFZero started")); #endif - formatManager.registerFormat(new WavAudioFormat(), false); - formatManager.registerFormat(new OggVorbisAudioFormat(), false); + formatManager.registerFormat(new juce::WavAudioFormat(), false); + formatManager.registerFormat(new juce::OggVorbisAudioFormat(), false); for (int i = 0; i < 128; ++i) synth.addVoice(new SFZVoice()); @@ -28,7 +24,7 @@ SFZeroAudioProcessor::~SFZeroAudioProcessor() { } -const String SFZeroAudioProcessor::getName() const +const juce::String SFZeroAudioProcessor::getName() const { return JucePlugin_Name; } @@ -47,40 +43,40 @@ void SFZeroAudioProcessor::setParameter(int index, float newValue) { } -const String SFZeroAudioProcessor::getParameterName(int index) +const juce::String SFZeroAudioProcessor::getParameterName(int index) { - return String::empty; + return {}; } -const String SFZeroAudioProcessor::getParameterText(int index) +const juce::String SFZeroAudioProcessor::getParameterText(int index) { - return String::empty; + return {}; } -void SFZeroAudioProcessor::setSfzFile(File* newSfzFile) +void SFZeroAudioProcessor::setSfzFile(const juce::File& newSfzFile) { - sfzFile = *newSfzFile; + sfzFile = newSfzFile; loadSound(); } -void SFZeroAudioProcessor::setSfzFileThreaded(File* newSfzFile) +void SFZeroAudioProcessor::setSfzFileThreaded(const juce::File& newSfzFile) { loadThread.stopThread(2000); - sfzFile = *newSfzFile; + sfzFile = newSfzFile; loadThread.startThread(); } -const String SFZeroAudioProcessor::getInputChannelName(int channelIndex) const +const juce::String SFZeroAudioProcessor::getInputChannelName(int channelIndex) const { - return String(channelIndex + 1); + return juce::String(channelIndex + 1); } -const String SFZeroAudioProcessor::getOutputChannelName(int channelIndex) const +const juce::String SFZeroAudioProcessor::getOutputChannelName(int channelIndex) const { - return String(channelIndex + 1); + return juce::String(channelIndex + 1); } bool SFZeroAudioProcessor::isInputChannelStereoPair(int index) const @@ -139,12 +135,12 @@ void SFZeroAudioProcessor::setCurrentProgram(int index) { } -const String SFZeroAudioProcessor::getProgramName(int index) +const juce::String SFZeroAudioProcessor::getProgramName(int index) { - return String::empty; + return {}; } -void SFZeroAudioProcessor::changeProgramName(int index, const String& newName) +void SFZeroAudioProcessor::changeProgramName(int index, const juce::String& newName) { } @@ -163,7 +159,7 @@ void SFZeroAudioProcessor::releaseResources() } -void SFZeroAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) +void SFZeroAudioProcessor::processBlock(juce::AudioSampleBuffer& buffer, juce::MidiBuffer& midiMessages) { int numSamples = buffer.getNumSamples(); keyboardState.processNextMidiBuffer(midiMessages, 0, numSamples, true); @@ -176,17 +172,17 @@ bool SFZeroAudioProcessor::hasEditor() const return true; // (change this to false if you choose to not supply an editor) } -AudioProcessorEditor* SFZeroAudioProcessor::createEditor() +juce::AudioProcessorEditor* SFZeroAudioProcessor::createEditor() { return new SFZeroEditor(this); } -void SFZeroAudioProcessor::getStateInformation(MemoryBlock& destData) +void SFZeroAudioProcessor::getStateInformation(juce::MemoryBlock& destData) { // There's something weird about JUCE's DynamicObjects that doesn't allow // them to be used as stack-allocated variables. - DynamicObject::Ptr state = new DynamicObject(); + juce::DynamicObject::Ptr state = new juce::DynamicObject(); state->setProperty("sfzFilePath", sfzFile.getFullPathName()); SFZSound* sound = getSound(); if (sound) { @@ -195,23 +191,23 @@ void SFZeroAudioProcessor::getStateInformation(MemoryBlock& destData) state->setProperty("subsound", subsound); } - MemoryOutputStream out(destData, false); - JSON::writeToStream(out, var(state)); + juce::MemoryOutputStream out(destData, false); + juce::JSON::writeToStream(out, juce::var(state)); } void SFZeroAudioProcessor::setStateInformation(const void* data, int sizeInBytes) { - MemoryInputStream in(data, sizeInBytes, false); - var state = JSON::parse(in); - var pathVar = state["sfzFilePath"]; + juce::MemoryInputStream in(data, sizeInBytes, false); + juce::var state = juce::JSON::parse(in); + juce::var pathVar = state["sfzFilePath"]; if (pathVar.isString()) { - String sfzFilePath = pathVar.toString(); + juce::String sfzFilePath = pathVar.toString(); if (!sfzFilePath.isEmpty()) { - File file(sfzFilePath); - setSfzFile(&file); + juce::File file(sfzFilePath); + setSfzFile(file); SFZSound* sound = getSound(); if (sound) { - var subsoundVar = state["subsound"]; + juce::var subsoundVar = state["subsound"]; if (subsoundVar.isInt()) sound->useSubsound(int(subsoundVar)); } @@ -222,7 +218,7 @@ void SFZeroAudioProcessor::setStateInformation(const void* data, int sizeInBytes SFZSound* SFZeroAudioProcessor::getSound() { - SynthesiserSound* sound = synth.getSound(0); + juce::SynthesiserSound* sound = synth.getSound(0); return dynamic_cast(sound); } @@ -233,7 +229,7 @@ int SFZeroAudioProcessor::numVoicesUsed() } -String SFZeroAudioProcessor::voiceInfoString() +juce::String SFZeroAudioProcessor::voiceInfoString() { return synth.voiceInfoString(); } @@ -248,7 +244,7 @@ void SFZeroAudioProcessor::relayLogMessages() -void SFZeroAudioProcessor::loadSound(Thread* thread) +void SFZeroAudioProcessor::loadSound(juce::Thread* thread) { loadProgress = 0.0; synth.clearSounds(); @@ -259,7 +255,7 @@ void SFZeroAudioProcessor::loadSound(Thread* thread) } SFZSound* sound; - String extension = sfzFile.getFileExtension(); + juce::String extension = sfzFile.getFileExtension(); if (extension == ".sf2" || extension == ".SF2") sound = new SF2Sound(sfzFile); else @@ -289,7 +285,7 @@ void SFZeroAudioProcessor::LoadThread::run() -AudioProcessor* JUCE_CALLTYPE createPluginFilter() +juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() { return new SFZeroAudioProcessor(); } diff --git a/Source/SFZeroAudioProcessor.h b/Source/SFZeroAudioProcessor.h index 348627c..03dfabd 100644 --- a/Source/SFZeroAudioProcessor.h +++ b/Source/SFZeroAudioProcessor.h @@ -1,73 +1,72 @@ #ifndef __PLUGINPROCESSOR_H_7DD34D53__ #define __PLUGINPROCESSOR_H_7DD34D53__ -#include "../JuceLibraryCode/JuceHeader.h" -#include "SFZSynth.h" +#include namespace SFZero { class SFZSound; } -class SFZeroAudioProcessor : public AudioProcessor { +class SFZeroAudioProcessor : public juce::AudioProcessor { public: SFZeroAudioProcessor(); ~SFZeroAudioProcessor(); - void prepareToPlay(double sampleRate, int samplesPerBlock); - void releaseResources(); - void processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages); + void prepareToPlay(double sampleRate, int samplesPerBlock) override; + void releaseResources() override; + void processBlock(juce::AudioSampleBuffer& buffer, juce::MidiBuffer& midiMessages) override; - AudioProcessorEditor* createEditor(); - bool hasEditor() const; + juce::AudioProcessorEditor* createEditor() override; + bool hasEditor() const override; - const String getName() const; + const juce::String getName() const override; - int getNumParameters(); + int getNumParameters() override; - float getParameter(int index); - void setParameter(int index, float newValue); + float getParameter(int index) override; + void setParameter(int index, float newValue) override; - const String getParameterName(int index); - const String getParameterText(int index); + const juce::String getParameterName(int index) override; + const juce::String getParameterText(int index) override; - void setSfzFile(File* newSfzFile); - void setSfzFileThreaded(File* newSfzFile); - File getSfzFile() { return sfzFile; } + void setSfzFile(const juce::File& newSfzFile); + void setSfzFileThreaded(const juce::File& newSfzFile); + juce::File getSfzFile() { return sfzFile; } - const String getInputChannelName(int channelIndex) const; - const String getOutputChannelName(int channelIndex) const; - bool isInputChannelStereoPair(int index) const; - bool isOutputChannelStereoPair(int index) const; + const juce::String getInputChannelName(int channelIndex) const override; + const juce::String getOutputChannelName(int channelIndex) const override; + bool isInputChannelStereoPair(int index) const override; + bool isOutputChannelStereoPair(int index) const override; - bool acceptsMidi() const; - bool producesMidi() const; - bool silenceInProducesSilenceOut() const; - double getTailLengthSeconds() const; + bool acceptsMidi() const override; + bool producesMidi() const override; + bool silenceInProducesSilenceOut() const override; + double getTailLengthSeconds() const override; - int getNumPrograms(); - int getCurrentProgram(); - void setCurrentProgram(int index); - const String getProgramName(int index); - void changeProgramName(int index, const String& newName); + int getNumPrograms() override; + int getCurrentProgram() override; + void setCurrentProgram(int index) override; + const juce::String getProgramName(int index) override; + void changeProgramName(int index, const juce::String& newName) override; - void getStateInformation(MemoryBlock& destData); - void setStateInformation(const void* data, int sizeInBytes); + void getStateInformation(juce::MemoryBlock& destData) override; + void setStateInformation(const void* data, int sizeInBytes) override; - MidiKeyboardState keyboardState; + juce::MidiKeyboardState keyboardState; double loadProgress; SFZero::SFZSound* getSound(); - int numVoicesUsed(); - String voiceInfoString(); + int numVoicesUsed(); + juce::String voiceInfoString(); #if JUCE_DEBUG void relayLogMessages(); #endif protected: - class LoadThread : public Thread { + class LoadThread : public juce::Thread { public: LoadThread(SFZeroAudioProcessor* processor); void run(); @@ -77,12 +76,12 @@ class SFZeroAudioProcessor : public AudioProcessor { }; friend class LoadThread; - File sfzFile; + juce::File sfzFile; SFZero::SFZSynth synth; - AudioFormatManager formatManager; + juce::AudioFormatManager formatManager; LoadThread loadThread; - void loadSound(Thread* thread = NULL); + void loadSound(juce::Thread* thread = NULL); private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SFZeroAudioProcessor); diff --git a/Source/SFZeroEditor.cpp b/Source/SFZeroEditor.cpp index 5c17827..78ce5e2 100644 --- a/Source/SFZeroEditor.cpp +++ b/Source/SFZeroEditor.cpp @@ -1,7 +1,5 @@ #include "SFZeroEditor.h" #include "SFZeroAudioProcessor.h" -#include "SFZSound.h" -#include "SFZDebug.h" #include using namespace SFZero; @@ -18,35 +16,35 @@ enum { SFZeroEditor::SFZeroEditor(SFZeroAudioProcessor* ownerFilter) : AudioProcessorEditor(ownerFilter), - fileLabel(String::empty, "File... (click here to choose)"), - pathLabel(String::empty), + fileLabel(juce::String(), "File... (click here to choose)"), + pathLabel(juce::String()), showingInfo(showingSoundInfo), - midiKeyboard(ownerFilter->keyboardState, MidiKeyboardComponent::horizontalKeyboard), + midiKeyboard(ownerFilter->keyboardState, juce::MidiKeyboardComponent::horizontalKeyboard), progressBar(NULL) { setSize(500, 300); #ifdef JUCE_MAC - Font fileFont("Helvetica", 22.0, Font::bold); - Font labelFont("Helvetica", 15.0, Font::plain); + juce::Font fileFont(juce::FontOptions("Helvetica", 22.0, juce::Font::bold)); + juce::Font labelFont(juce::FontOptions("Helvetica", 15.0, juce::Font::plain)); #else - Font fileFont("Ariel", 22.0, Font::bold); - Font labelFont("Ariel", 15.0, Font::plain); + juce::Font fileFont(juce::FontOptions("Ariel", 22.0, juce::Font::bold)); + juce::Font labelFont(juce::FontOptions("Ariel", 15.0, juce::Font::plain)); #endif addAndMakeVisible(&fileLabel); fileLabel.setFont(fileFont); - fileLabel.setColour(Label::textColourId, Colours::grey); + fileLabel.setColour(juce::Label::textColourId, juce::Colours::grey); fileLabel.addClickListener(this); addAndMakeVisible(&pathLabel); pathLabel.setFont(labelFont); - pathLabel.setColour(Label::textColourId, Colours::grey); + pathLabel.setColour(juce::Label::textColourId, juce::Colours::grey); pathLabel.addClickListener(this); addAndMakeVisible(&infoLabel); infoLabel.setFont(labelFont); - infoLabel.setJustificationType(Justification::topLeft); + infoLabel.setJustificationType(juce::Justification::topLeft); infoLabel.addClickListener(this); addAndMakeVisible(&midiKeyboard); @@ -54,9 +52,9 @@ SFZeroEditor::SFZeroEditor(SFZeroAudioProcessor* ownerFilter) startTimer(200); - File sfzFile = ownerFilter->getSfzFile(); - if (sfzFile != File::nonexistent) { - updateFile(&sfzFile); + juce::File sfzFile = ownerFilter->getSfzFile(); + if (sfzFile != juce::File()) { + updateFile(sfzFile); showSoundInfo(); SFZSound* sound = ownerFilter->getSound(); if (sound && sound->numSubsounds() > 1) @@ -73,9 +71,9 @@ SFZeroEditor::~SFZeroEditor() } -void SFZeroEditor::paint(Graphics& g) +void SFZeroEditor::paint(juce::Graphics& g) { - g.fillAll(Colours::white); + g.fillAll(juce::Colours::white); } @@ -95,7 +93,7 @@ void SFZeroEditor::resized() } -void SFZeroEditor::labelClicked(Label* clickedLabel) +void SFZeroEditor::labelClicked(juce::Label* clickedLabel) { if (clickedLabel == &fileLabel) chooseFile(); @@ -105,7 +103,7 @@ void SFZeroEditor::labelClicked(Label* clickedLabel) SFZeroAudioProcessor* processor = getProcessor(); SFZSound* sound = processor->getSound(); if (sound) { - PopupMenu menu; + juce::PopupMenu menu; int selectedSubsound = sound->selectedSubsound(); int numSubsounds = sound->numSubsounds(); for (int i = 0; i < numSubsounds; ++i) { @@ -159,18 +157,18 @@ void SFZeroEditor::timerCallback() void SFZeroEditor::chooseFile() { - FileChooser chooser( + juce::FileChooser chooser( "Select an SFZ file...", - File::nonexistent, + juce::File(), "*.sfz;*.SFZ;*.sf2;*.SF2"); if (chooser.browseForFileToOpen()) { - File sfzFile(chooser.getResult()); - setFile(&sfzFile); + juce::File sfzFile(chooser.getResult()); + setFile(sfzFile); } } -void SFZeroEditor::setFile(File* newFile) +void SFZeroEditor::setFile(const juce::File& newFile) { SFZeroAudioProcessor* processor = getProcessor(); processor->setSfzFileThreaded(newFile); @@ -180,10 +178,10 @@ void SFZeroEditor::setFile(File* newFile) } -void SFZeroEditor::updateFile(File* file) +void SFZeroEditor::updateFile(const juce::File& file) { - fileLabel.setText(file->getFileName(), dontSendNotification); - fileLabel.setColour(Label::textColourId, Colours::black); + fileLabel.setText(file.getFileName(), juce::dontSendNotification); + fileLabel.setColour(juce::Label::textColourId, juce::Colours::black); showPath(); } @@ -193,7 +191,7 @@ void SFZeroEditor::showSoundInfo() SFZeroAudioProcessor* processor = getProcessor(); SFZSound* sound = processor->getSound(); if (sound) - infoLabel.setText(sound->getErrorsString(), dontSendNotification); + infoLabel.setText(sound->getErrorsString(), juce::dontSendNotification); showingInfo = showingSoundInfo; } @@ -201,7 +199,7 @@ void SFZeroEditor::showSoundInfo() void SFZeroEditor::showVoiceInfo() { SFZeroAudioProcessor* processor = getProcessor(); - infoLabel.setText(processor->voiceInfoString(), dontSendNotification); + infoLabel.setText(processor->voiceInfoString(), juce::dontSendNotification); showingInfo = showingVoiceInfo; } @@ -211,9 +209,9 @@ void SFZeroEditor::showVersion() struct tm tm; strptime(__DATE__, "%b %d %Y", &tm); char str[64]; - sprintf(str, "SFZero beta %d.%d.%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); - pathLabel.setText(str, dontSendNotification); - pathLabel.setColour(Label::textColourId, Colours::grey); + snprintf(str, 64, "SFZero beta %d.%d.%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + pathLabel.setText(str, juce::dontSendNotification); + pathLabel.setColour(juce::Label::textColourId, juce::Colours::grey); hideProgress(); showing = showingVersion; } @@ -222,10 +220,10 @@ void SFZeroEditor::showVersion() void SFZeroEditor::showPath() { SFZeroAudioProcessor* processor = getProcessor(); - File file = processor->getSfzFile(); + juce::File file = processor->getSfzFile(); pathLabel.setText( - file.getParentDirectory().getFullPathName(), dontSendNotification); - pathLabel.setColour(Label::textColourId, Colours::grey); + file.getParentDirectory().getFullPathName(), juce::dontSendNotification); + pathLabel.setColour(juce::Label::textColourId, juce::Colours::grey); hideProgress(); showing = showingPath; } @@ -239,8 +237,8 @@ void SFZeroEditor::showSubsound() return; pathLabel.setText( - sound->subsoundName(sound->selectedSubsound()), dontSendNotification); - pathLabel.setColour(Label::textColourId, Colours::black); + sound->subsoundName(sound->selectedSubsound()), juce::dontSendNotification); + pathLabel.setColour(juce::Label::textColourId, juce::Colours::black); hideProgress(); showing = showingSubsound; } @@ -251,7 +249,7 @@ void SFZeroEditor::showProgress() SFZeroAudioProcessor* processor = getProcessor(); pathLabel.setVisible(false); infoLabel.setVisible(false); - progressBar = new ProgressBar(processor->loadProgress); + progressBar = new juce::ProgressBar(processor->loadProgress); addAndMakeVisible(progressBar); int marginedWidth = getWidth() - 2 * hMargin; progressBar->setBounds( @@ -273,5 +271,19 @@ void SFZeroEditor::hideProgress() infoLabel.setVisible(true); } +bool SFZeroEditor::isInterestedInFileDrag (const juce::StringArray& files) +{ + if (files.size() == 1) + { + auto f = juce::File(files[0]); + if (f.hasFileExtension(".sfz") || f.hasFileExtension(".sf2")) + return true; + } + return false; +} +void SFZeroEditor::filesDropped (const juce::StringArray& files, int, int) +{ + setFile(juce::File(files[0])); +} diff --git a/Source/SFZeroEditor.h b/Source/SFZeroEditor.h index c1177e5..12b1ec1 100644 --- a/Source/SFZeroEditor.h +++ b/Source/SFZeroEditor.h @@ -1,23 +1,27 @@ #ifndef __PLUGINEDITOR_H_A8E24640__ #define __PLUGINEDITOR_H_A8E24640__ -#include "../JuceLibraryCode/JuceHeader.h" +#include #include "SFZeroAudioProcessor.h" #include "ClickableLabel.h" class SFZeroEditor : - public AudioProcessorEditor, public Timer, - public ClickableLabel::ClickListener + public juce::AudioProcessorEditor, public juce::Timer, + public ClickableLabel::ClickListener, + public juce::FileDragAndDropTarget { public: SFZeroEditor(SFZeroAudioProcessor* ownerFilter); ~SFZeroEditor(); - void paint(Graphics& g); - void resized(); - void labelClicked(Label* clickedLabel); - void timerCallback(); + void paint(juce::Graphics& g) override; + void resized() override; + void labelClicked(juce::Label* clickedLabel) override; + void timerCallback() override; + + bool isInterestedInFileDrag (const juce::StringArray& files) override; + void filesDropped (const juce::StringArray& files, int x, int y) override; protected: // pathLabel options. @@ -38,16 +42,16 @@ class SFZeroEditor : ClickableLabel pathLabel; ClickableLabel infoLabel; int showing, showingInfo; - MidiKeyboardComponent midiKeyboard; - ProgressBar* progressBar; + juce::MidiKeyboardComponent midiKeyboard; + juce::ProgressBar* progressBar; SFZeroAudioProcessor* getProcessor() const { return static_cast (getAudioProcessor()); } void chooseFile(); - void setFile(File* newFile); - void updateFile(File* file); + void setFile(const juce::File& newFile); + void updateFile(const juce::File& file); void showSoundInfo(); void showVoiceInfo(); void showVersion(); diff --git a/module/SFZero/SFZero.h b/module/SFZero/SFZero.h index 98f870c..4c45642 100644 --- a/module/SFZero/SFZero.h +++ b/module/SFZero/SFZero.h @@ -16,8 +16,7 @@ END_JUCE_MODULE_DECLARATION #include "SFZero/SFZVoice.h" #include "SFZero/SFZSound.h" #include "SFZero/SFZSynth.h" -#include "SFZero/SFZSound.h" -#include "SFZero/SFZSound.h" #include "SFZero/SF2Sound.h" +#include "SFZero/SFZDebug.h" diff --git a/module/SFZero/SFZero/SF2Sound.h b/module/SFZero/SFZero/SF2Sound.h index 3f2fa5b..e43390a 100644 --- a/module/SFZero/SFZero/SF2Sound.h +++ b/module/SFZero/SFZero/SF2Sound.h @@ -10,10 +10,10 @@ class SF2Sound : public SFZSound { public: SF2Sound(const juce::File& file); - ~SF2Sound(); + ~SF2Sound() override; - void loadRegions(); - void loadSamples(juce::AudioFormatManager* formatManager, double* progressVar = NULL, juce::Thread* thread = NULL); + void loadRegions() override; + void loadSamples(juce::AudioFormatManager* formatManager, double* progressVar = NULL, juce::Thread* thread = NULL) override; struct Preset { @@ -30,10 +30,10 @@ class SF2Sound : public SFZSound }; void addPreset(Preset* preset); - int numSubsounds(); - juce::String subsoundName(int whichSubsound); - void useSubsound(int whichSubsound); - int selectedSubsound(); + int numSubsounds() override; + juce::String subsoundName(int whichSubsound) override; + void useSubsound(int whichSubsound) override; + int selectedSubsound() override; SFZSample* sampleFor (unsigned long sampleRate); void setSamplesBuffer (juce::AudioSampleBuffer* buffer); diff --git a/module/SFZero/SFZero/SFZSound.h b/module/SFZero/SFZero/SFZSound.h index 0f7676a..c865e29 100644 --- a/module/SFZero/SFZero/SFZSound.h +++ b/module/SFZero/SFZero/SFZSound.h @@ -11,10 +11,10 @@ class SFZSample; class SFZSound : public juce::SynthesiserSound { public: SFZSound(const juce::File& file); - ~SFZSound(); + ~SFZSound() override; - bool appliesToNote(const int midiNoteNumber); - bool appliesToChannel(const int midiChannel); + bool appliesToNote(const int midiNoteNumber) override; + bool appliesToChannel(const int midiChannel) override; void addRegion(SFZRegion* region); // Takes ownership of the region. SFZSample* addSample(juce::String path, juce::String defaultPath = {}); diff --git a/module/SFZero/SFZero/SFZSynth.h b/module/SFZero/SFZero/SFZSynth.h index f28bfd8..70da3ec 100644 --- a/module/SFZero/SFZero/SFZSynth.h +++ b/module/SFZero/SFZero/SFZSynth.h @@ -6,11 +6,12 @@ namespace SFZero { class SFZSynth : public juce::Synthesiser { public: SFZSynth(); + ~SFZSynth() override = default; - void noteOn(int midiChannel, int midiNoteNumber, float velocity); + void noteOn(int midiChannel, int midiNoteNumber, float velocity) override; void noteOff( int midiChannel, int midiNoteNumber, - float velocity, bool allowTailOff); + float velocity, bool allowTailOff) override; int numVoicesUsed(); juce::String voiceInfoString(); diff --git a/module/SFZero/SFZero/SFZVoice.h b/module/SFZero/SFZero/SFZVoice.h index ea59dd5..7f3292a 100644 --- a/module/SFZero/SFZero/SFZVoice.h +++ b/module/SFZero/SFZero/SFZVoice.h @@ -11,23 +11,23 @@ class SFZRegion; class JUCE_API SFZVoice : public juce::SynthesiserVoice { public: SFZVoice(); - ~SFZVoice(); + ~SFZVoice() override; - bool canPlaySound(juce::SynthesiserSound* sound); + bool canPlaySound(juce::SynthesiserSound* sound) override; void startNote( const int midiNoteNumber, const float velocity, juce::SynthesiserSound* sound, - const int currentPitchWheelPosition); - void stopNote(float velocity, const bool allowTailOff); + const int currentPitchWheelPosition) override; + void stopNote(float velocity, const bool allowTailOff) override; void stopNoteForGroup(); void stopNoteQuick(); - void pitchWheelMoved(const int newValue); + void pitchWheelMoved(const int newValue) override; void controllerMoved( const int controllerNumber, - const int newValue); + const int newValue) override; void renderNextBlock( - juce::AudioSampleBuffer& outputBuffer, int startSample, int numSamples); + juce::AudioSampleBuffer& outputBuffer, int startSample, int numSamples) override; bool isPlayingNoteDown(); bool isPlayingOneShot(); From e9992f235f799b8d55fa43abb556dc1a85fdf8bc Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Tue, 4 Feb 2025 10:48:17 -0800 Subject: [PATCH 4/6] More cleanup --- Source/SFZeroAudioProcessor.cpp | 28 +++++----- Source/SFZeroEditor.cpp | 14 +++-- module/SFZero/SFZero/RIFF.cpp | 7 +-- module/SFZero/SFZero/SF2.cpp | 74 +++++++++++++-------------- module/SFZero/SFZero/SF2Generator.cpp | 11 ++-- module/SFZero/SFZero/SF2Reader.cpp | 5 +- module/SFZero/SFZero/SF2Sound.cpp | 5 +- module/SFZero/SFZero/SFZDebug.cpp | 24 +++++---- module/SFZero/SFZero/SFZDebug.h | 13 ++--- module/SFZero/SFZero/SFZEG.cpp | 5 +- module/SFZero/SFZero/SFZReader.cpp | 6 +-- module/SFZero/SFZero/SFZRegion.cpp | 6 +-- module/SFZero/SFZero/SFZSample.cpp | 6 +-- module/SFZero/SFZero/SFZSound.cpp | 5 +- module/SFZero/SFZero/SFZSynth.cpp | 6 +-- module/SFZero/SFZero/SFZVoice.cpp | 5 +- 16 files changed, 99 insertions(+), 121 deletions(-) diff --git a/Source/SFZeroAudioProcessor.cpp b/Source/SFZeroAudioProcessor.cpp index f06ce5f..a6e183a 100644 --- a/Source/SFZeroAudioProcessor.cpp +++ b/Source/SFZeroAudioProcessor.cpp @@ -1,14 +1,11 @@ #include "SFZeroAudioProcessor.h" #include "SFZeroEditor.h" -using namespace SFZero; - - SFZeroAudioProcessor::SFZeroAudioProcessor() : loadProgress(0.0), loadThread(this) { #if JUCE_DEBUG - setupLogging( + SFZero::setupLogging( juce::FileLogger::createDefaultAppLogger( "SFZero", "SFZero.log", "SFZero started")); #endif @@ -17,7 +14,7 @@ SFZeroAudioProcessor::SFZeroAudioProcessor() formatManager.registerFormat(new juce::OggVorbisAudioFormat(), false); for (int i = 0; i < 128; ++i) - synth.addVoice(new SFZVoice()); + synth.addVoice(new SFZero::SFZVoice()); } SFZeroAudioProcessor::~SFZeroAudioProcessor() @@ -184,7 +181,7 @@ void SFZeroAudioProcessor::getStateInformation(juce::MemoryBlock& destData) // them to be used as stack-allocated variables. juce::DynamicObject::Ptr state = new juce::DynamicObject(); state->setProperty("sfzFilePath", sfzFile.getFullPathName()); - SFZSound* sound = getSound(); + auto sound = getSound(); if (sound) { int subsound = sound->selectedSubsound(); if (subsound != 0) @@ -205,7 +202,7 @@ void SFZeroAudioProcessor::setStateInformation(const void* data, int sizeInBytes if (!sfzFilePath.isEmpty()) { juce::File file(sfzFilePath); setSfzFile(file); - SFZSound* sound = getSound(); + auto sound = getSound(); if (sound) { juce::var subsoundVar = state["subsound"]; if (subsoundVar.isInt()) @@ -216,10 +213,10 @@ void SFZeroAudioProcessor::setStateInformation(const void* data, int sizeInBytes } -SFZSound* SFZeroAudioProcessor::getSound() +SFZero::SFZSound* SFZeroAudioProcessor::getSound() { - juce::SynthesiserSound* sound = synth.getSound(0); - return dynamic_cast(sound); + auto sound = synth.getSound(0).get(); + return dynamic_cast(sound); } @@ -238,7 +235,7 @@ juce::String SFZeroAudioProcessor::voiceInfoString() #if JUCE_DEBUG void SFZeroAudioProcessor::relayLogMessages() { - relayFifoLogMessages(); + SFZero::relayFifoLogMessages(); } #endif @@ -254,12 +251,11 @@ void SFZeroAudioProcessor::loadSound(juce::Thread* thread) return; } - SFZSound* sound; - juce::String extension = sfzFile.getFileExtension(); - if (extension == ".sf2" || extension == ".SF2") - sound = new SF2Sound(sfzFile); + SFZero::SFZSound* sound; + if (sfzFile.hasFileExtension (".sf2")) + sound = new SFZero::SF2Sound(sfzFile); else - sound = new SFZSound(sfzFile); + sound = new SFZero::SFZSound(sfzFile); sound->loadRegions(); sound->loadSamples(&formatManager, &loadProgress, thread); if (thread && thread->threadShouldExit()) { diff --git a/Source/SFZeroEditor.cpp b/Source/SFZeroEditor.cpp index 78ce5e2..147ab1b 100644 --- a/Source/SFZeroEditor.cpp +++ b/Source/SFZeroEditor.cpp @@ -2,8 +2,6 @@ #include "SFZeroAudioProcessor.h" #include -using namespace SFZero; - enum { hMargin = 12, @@ -56,7 +54,7 @@ SFZeroEditor::SFZeroEditor(SFZeroAudioProcessor* ownerFilter) if (sfzFile != juce::File()) { updateFile(sfzFile); showSoundInfo(); - SFZSound* sound = ownerFilter->getSound(); + auto sound = ownerFilter->getSound(); if (sound && sound->numSubsounds() > 1) showSubsound(); } @@ -101,7 +99,7 @@ void SFZeroEditor::labelClicked(juce::Label* clickedLabel) else if (clickedLabel == &pathLabel) { if (showing == showingSubsound) { SFZeroAudioProcessor* processor = getProcessor(); - SFZSound* sound = processor->getSound(); + auto sound = processor->getSound(); if (sound) { juce::PopupMenu menu; int selectedSubsound = sound->selectedSubsound(); @@ -141,7 +139,7 @@ void SFZeroEditor::timerCallback() if (showing == showingProgress) { SFZeroAudioProcessor* processor = getProcessor(); if (processor->loadProgress >= 1.0) { - SFZSound* sound = processor->getSound(); + auto sound = processor->getSound(); if (sound && sound->numSubsounds() > 1) showSubsound(); else @@ -189,7 +187,7 @@ void SFZeroEditor::updateFile(const juce::File& file) void SFZeroEditor::showSoundInfo() { SFZeroAudioProcessor* processor = getProcessor(); - SFZSound* sound = processor->getSound(); + auto sound = processor->getSound(); if (sound) infoLabel.setText(sound->getErrorsString(), juce::dontSendNotification); showingInfo = showingSoundInfo; @@ -232,8 +230,8 @@ void SFZeroEditor::showPath() void SFZeroEditor::showSubsound() { SFZeroAudioProcessor* processor = getProcessor(); - SFZSound* sound = processor->getSound(); - if (sound == NULL) + auto sound = processor->getSound(); + if (sound == nullptr) return; pathLabel.setText( diff --git a/module/SFZero/SFZero/RIFF.cpp b/module/SFZero/SFZero/RIFF.cpp index 5b8b944..6aab02a 100644 --- a/module/SFZero/SFZero/RIFF.cpp +++ b/module/SFZero/SFZero/RIFF.cpp @@ -1,7 +1,6 @@ #include "RIFF.h" -using namespace SFZero; - +namespace SFZero { void RIFFChunk::ReadFrom(juce::InputStream* file) { @@ -48,6 +47,4 @@ juce::String RIFFChunk::ReadString(juce::InputStream* file) return juce::String(str); } - - - +} diff --git a/module/SFZero/SFZero/SF2.cpp b/module/SFZero/SFZero/SF2.cpp index b2f4586..f93a705 100644 --- a/module/SFZero/SFZero/SF2.cpp +++ b/module/SFZero/SFZero/SF2.cpp @@ -1,92 +1,91 @@ #include "SF2.h" #include "RIFF.h" -using namespace SFZero; - +namespace SFZero { #define readAbyte(name, file) \ - name = (byte) file->readByte(); +name = (byte) file->readByte(); #define readAchar(name, file) \ - name = file->readByte(); +name = file->readByte(); #define readAdword(name, file) \ - name = (dword) file->readInt(); +name = (dword) file->readInt(); #define readAword(name, file) \ - name = (word) file->readShort(); +name = (word) file->readShort(); #define readAshort(name, file) \ - name = file->readShort(); +name = file->readShort(); #define readAchar20(name, file) \ - file->read(name, 20); +file->read(name, 20); #define readAgenAmountType(name, file) \ - name.shortAmount = file->readShort(); +name.shortAmount = file->readShort(); #define SF2Field(type, name) \ - readA##type(name, file) +readA##type(name, file) void SF2::iver::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/iver.h" +#include "sf2-chunks/iver.h" } void SF2::phdr::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/phdr.h" +#include "sf2-chunks/phdr.h" } void SF2::pbag::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/pbag.h" +#include "sf2-chunks/pbag.h" } void SF2::pmod::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/pmod.h" +#include "sf2-chunks/pmod.h" } void SF2::pgen::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/pgen.h" +#include "sf2-chunks/pgen.h" } void SF2::inst::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/inst.h" +#include "sf2-chunks/inst.h" } void SF2::ibag::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/ibag.h" +#include "sf2-chunks/ibag.h" } void SF2::imod::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/imod.h" +#include "sf2-chunks/imod.h" } void SF2::igen::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/igen.h" +#include "sf2-chunks/igen.h" } void SF2::shdr::ReadFrom(juce::InputStream* file) { - #include "sf2-chunks/shdr.h" +#include "sf2-chunks/shdr.h" } SF2::Hydra::Hydra() - : phdrItems(NULL), pbagItems(NULL), pmodItems(NULL), pgenItems(NULL), - instItems(NULL), ibagItems(NULL), imodItems(NULL), igenItems(NULL), - shdrItems(NULL) +: phdrItems(NULL), pbagItems(NULL), pmodItems(NULL), pgenItems(NULL), +instItems(NULL), ibagItems(NULL), imodItems(NULL), igenItems(NULL), +shdrItems(NULL) { } @@ -109,15 +108,15 @@ void SF2::Hydra::ReadFrom(juce::InputStream* file, int64_t pdtaChunkEnd) { int i, numItems; - #define HandleChunk(chunkName) \ - if (FourCCEquals(chunk.id, #chunkName)) { \ - numItems = int (chunk.size) / SF2::chunkName::sizeInFile; \ - chunkName##NumItems = numItems; \ - chunkName##Items = new SF2::chunkName[numItems]; \ - for (i = 0; i < numItems; ++i) \ - chunkName##Items[i].ReadFrom(file); \ - } \ - else +#define HandleChunk(chunkName) \ +if (FourCCEquals(chunk.id, #chunkName)) { \ +numItems = int (chunk.size) / SF2::chunkName::sizeInFile; \ +chunkName##NumItems = numItems; \ +chunkName##Items = new SF2::chunkName[numItems]; \ +for (i = 0; i < numItems; ++i) \ +chunkName##Items[i].ReadFrom(file); \ +} \ +else while (file->getPosition() < pdtaChunkEnd) { RIFFChunk chunk; @@ -135,17 +134,16 @@ void SF2::Hydra::ReadFrom(juce::InputStream* file, int64_t pdtaChunkEnd) {} chunk.SeekAfter(file); - } + } } bool SF2::Hydra::IsComplete() { return - phdrItems && pbagItems && pmodItems && pgenItems && - instItems && ibagItems && imodItems && igenItems && - shdrItems; + phdrItems && pbagItems && pmodItems && pgenItems && + instItems && ibagItems && imodItems && igenItems && + shdrItems; } - - +} diff --git a/module/SFZero/SFZero/SF2Generator.cpp b/module/SFZero/SFZero/SF2Generator.cpp index f5b0c3e..97d3165 100644 --- a/module/SFZero/SFZero/SF2Generator.cpp +++ b/module/SFZero/SFZero/SF2Generator.cpp @@ -1,8 +1,6 @@ #include "SF2Generator.h" -#include // just for NULL; where does that live really? - -using namespace SFZero; +namespace SFZero { #define SF2GeneratorValue(name, type) \ { #name, SF2Generator::type } @@ -13,12 +11,11 @@ static const SF2Generator generators[] = { static const int numGenerators = sizeof(generators) / sizeof(generators[0]); -const SF2Generator* SFZero::GeneratorFor(unsigned short index) +const SF2Generator* GeneratorFor(unsigned short index) { if (index >= numGenerators) - return NULL; + return nullptr; return &generators[index]; } - - +} diff --git a/module/SFZero/SFZero/SF2Reader.cpp b/module/SFZero/SFZero/SF2Reader.cpp index 2da7ee3..59c833b 100644 --- a/module/SFZero/SFZero/SF2Reader.cpp +++ b/module/SFZero/SFZero/SF2Reader.cpp @@ -6,7 +6,7 @@ #include "SF2Generator.h" #include "SFZDebug.h" -using namespace SFZero; +namespace SFZero { SF2Reader::SF2Reader(SF2Sound* soundIn, const juce::File& fileIn) @@ -372,5 +372,4 @@ void SF2Reader::addGeneratorToRegion( } } - - +} diff --git a/module/SFZero/SFZero/SF2Sound.cpp b/module/SFZero/SFZero/SF2Sound.cpp index b55dbeb..1a813cc 100644 --- a/module/SFZero/SFZero/SF2Sound.cpp +++ b/module/SFZero/SFZero/SF2Sound.cpp @@ -3,8 +3,7 @@ #include "SFZSample.h" #include "SFZDebug.h" -using namespace SFZero; - +namespace SFZero { SF2Sound::SF2Sound(const juce::File& file) : SFZSound(file) @@ -123,4 +122,4 @@ void SF2Sound::setSamplesBuffer(juce::AudioSampleBuffer* buffer) } - +} diff --git a/module/SFZero/SFZero/SFZDebug.cpp b/module/SFZero/SFZero/SFZDebug.cpp index 1ed59e1..70b71f9 100644 --- a/module/SFZero/SFZero/SFZDebug.cpp +++ b/module/SFZero/SFZero/SFZDebug.cpp @@ -1,21 +1,24 @@ #include "SFZDebug.h" #include -using namespace SFZero; +namespace SFZero { #ifdef JUCE_DEBUG -static LogFifo* fifo = NULL; +static LogFifo* fifo = nullptr; -LogFifo::LogFifo() - : fifo(capacity) +LogFifo::LogFifo (juce::Logger* l) + : fifo(capacity), logger (l) { } LogFifo::~LogFifo() { + if (juce::Logger::getCurrentLogger() == logger.get()) + juce::Logger::setCurrentLogger(nullptr); + SFZero::fifo = nullptr; } @@ -115,29 +118,29 @@ bool LogFifo::hasMessage() -void SFZero::setupLogging (juce::Logger* logger) +void setupLogging (juce::Logger* logger) { - if (fifo == NULL) - fifo = new LogFifo(); + if (fifo == nullptr) + fifo = new LogFifo(logger); juce::Logger::setCurrentLogger(logger); } -void SFZero::fifoLogMessage(const juce::String& message) +void fifoLogMessage(const juce::String& message) { if (fifo) fifo->logMessage(message); } -void SFZero::relayFifoLogMessages() +void relayFifoLogMessages() { if (fifo) fifo->relayMessages(); } -void SFZero::dbgprintf(const char* msg, ...) +void dbgprintf(const char* msg, ...) { va_list args; va_start(args, msg); @@ -153,3 +156,4 @@ void SFZero::dbgprintf(const char* msg, ...) #endif // JUCE_DEBUG +} diff --git a/module/SFZero/SFZero/SFZDebug.h b/module/SFZero/SFZero/SFZDebug.h index 9cd9215..fe2c671 100644 --- a/module/SFZero/SFZero/SFZDebug.h +++ b/module/SFZero/SFZero/SFZDebug.h @@ -17,21 +17,22 @@ namespace SFZero { -class LogFifo { +class LogFifo : public juce::DeletedAtShutdown { public: - LogFifo(); + LogFifo (juce::Logger* logger); ~LogFifo(); void logMessage(const juce::String& message); - void relayMessages(); - juce::String nextMessage(); - bool hasMessage(); + void relayMessages(); + juce::String nextMessage(); + bool hasMessage(); protected: enum { capacity = 512 * 1024, }; - juce::AbstractFifo fifo; + juce::AbstractFifo fifo; + std::unique_ptr logger; char buffer[capacity]; }; diff --git a/module/SFZero/SFZero/SFZEG.cpp b/module/SFZero/SFZero/SFZEG.cpp index e2c8b0d..abc83df 100644 --- a/module/SFZero/SFZero/SFZEG.cpp +++ b/module/SFZero/SFZero/SFZEG.cpp @@ -1,7 +1,7 @@ #include "SFZEG.h" #include "SFZDebug.h" -using namespace SFZero; +namespace SFZero { static const float fastReleaseTime = 0.01; @@ -201,5 +201,4 @@ void SFZEG::startRelease() } } - - +} diff --git a/module/SFZero/SFZero/SFZReader.cpp b/module/SFZero/SFZero/SFZReader.cpp index c38bb3b..61dbe49 100644 --- a/module/SFZero/SFZero/SFZReader.cpp +++ b/module/SFZero/SFZero/SFZReader.cpp @@ -4,8 +4,7 @@ #include "StringSlice.h" #include "SFZDebug.h" -using namespace SFZero; - +namespace SFZero { SFZReader::SFZReader(SFZSound* soundIn) : sound(soundIn), line(1) @@ -427,5 +426,4 @@ void SFZReader::error(const juce::String& message) sound->addError(fullMessage); } - - +} diff --git a/module/SFZero/SFZero/SFZRegion.cpp b/module/SFZero/SFZero/SFZRegion.cpp index daeab3b..6962ce9 100644 --- a/module/SFZero/SFZero/SFZRegion.cpp +++ b/module/SFZero/SFZero/SFZRegion.cpp @@ -4,8 +4,7 @@ #include #include -using namespace SFZero; - +namespace SFZero { void SFZEGParameters::clear() { @@ -145,5 +144,4 @@ float SFZRegion::timecents2Secs(short timecents) return pow(2.0, timecents / 1200.0); } - - +} diff --git a/module/SFZero/SFZero/SFZSample.cpp b/module/SFZero/SFZero/SFZSample.cpp index c76fc36..8c0da94 100644 --- a/module/SFZero/SFZero/SFZSample.cpp +++ b/module/SFZero/SFZero/SFZSample.cpp @@ -1,8 +1,7 @@ #include "SFZSample.h" #include "SFZDebug.h" -using namespace SFZero; - +namespace SFZero { bool SFZSample::load(juce::AudioFormatManager* formatManager) { @@ -85,5 +84,4 @@ void SFZSample::checkIfZeroed(const char* where) } #endif // JUCE_DEBUG - - +} diff --git a/module/SFZero/SFZero/SFZSound.cpp b/module/SFZero/SFZero/SFZSound.cpp index 5ec9171..0cd8bfe 100644 --- a/module/SFZero/SFZero/SFZSound.cpp +++ b/module/SFZero/SFZero/SFZSound.cpp @@ -4,7 +4,7 @@ #include "SFZReader.h" #include "SFZDebug.h" -using namespace SFZero; +namespace SFZero { SFZSound::SFZSound(const juce::File& fileIn) @@ -222,5 +222,4 @@ void SFZSound::dump() itr.getValue()->dump(); } - - +} diff --git a/module/SFZero/SFZero/SFZSynth.cpp b/module/SFZero/SFZero/SFZSynth.cpp index 13182e4..c3821ce 100644 --- a/module/SFZero/SFZero/SFZSynth.cpp +++ b/module/SFZero/SFZero/SFZSynth.cpp @@ -3,8 +3,7 @@ #include "SFZSound.h" #include "SFZDebug.h" -using namespace SFZero; - +namespace SFZero { SFZSynth::SFZSynth() : Synthesiser() @@ -146,5 +145,4 @@ juce::String SFZSynth::voiceInfoString() return lines.joinIntoString("\n"); } - - +} diff --git a/module/SFZero/SFZero/SFZVoice.cpp b/module/SFZero/SFZero/SFZVoice.cpp index b71c785..48c17e1 100644 --- a/module/SFZero/SFZero/SFZVoice.cpp +++ b/module/SFZero/SFZero/SFZVoice.cpp @@ -4,7 +4,7 @@ #include "SFZSample.h" #include "SFZDebug.h" -using namespace SFZero; +namespace SFZero { static const float globalGain = -1.0; @@ -323,5 +323,4 @@ double SFZVoice::noteHz(double note, const double freqOfA) return freqOfA * pow(2.0, note / 12.0); } - - +} From 29af331e8162415e28a64b9833792be46da93c87 Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Thu, 10 Apr 2025 12:23:15 -0700 Subject: [PATCH 5/6] Clean up more warnings --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 1 + module/SFZero/SFZero/RIFF.cpp | 2 +- module/SFZero/SFZero/SF2Reader.cpp | 6 +++--- module/SFZero/SFZero/SF2Sound.cpp | 4 ++-- module/SFZero/SFZero/SFZDebug.cpp | 2 +- module/SFZero/SFZero/SFZEG.cpp | 14 +++++++------- module/SFZero/SFZero/SFZRegion.cpp | 4 ++-- module/SFZero/SFZero/SFZSynth.cpp | 2 +- module/SFZero/SFZero/SFZVoice.cpp | 12 ++++++------ 10 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 3120b584a676ea626e2579089b00e1ab0437ae59..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T0#oO;Dj1(c|K|NJ{-XcnG0_N1=rttY~6{20~MsgdS=&zL2lt&F67u zcXJ5MS;Wr3?l(I>yV(!2vkL&i%flW(2LLQ=go2bBA#<&(VS)*Tnj?fXSf=wJPJ)_= z{-TM#y$v4Z5J3#p@Ba+uag=6`^DP?9)=qoZvTbXBGLB|pvhS)O|SLV51|Y>FPGkCG%tePW`=QJ761J4dTk@4PE}{mXS%uCC6UuDo#i>$PoJ zcIV4FJUP9-9r>%*_1n9qPaxAu4h)v?fl6g3Vfq{gxM-PB1~M`O%m6dM3~V_ArZ8B0 zTh0S-pBZ2VHW{GvL1H6x4Hg>J(SaRZpUK}MBtf0t5`@yAYp~FW9u%Qd5p}9CPYj{c z(JoD#Yp~F$(?O_}aUQdB`FIg(b+k(r4#L&QJu|=zR2gXMVTbDf4gNB}NI^lpatXizog>G}sr{04jB^bZ8fg}?t8_%Z N2q;3hV+MYKfgc2jNg)6L diff --git a/.gitignore b/.gitignore index a109269..f4b6201 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ JuceLibraryCode Builds tags +.DS_Store \ No newline at end of file diff --git a/module/SFZero/SFZero/RIFF.cpp b/module/SFZero/SFZero/RIFF.cpp index 6aab02a..daeda1b 100644 --- a/module/SFZero/SFZero/RIFF.cpp +++ b/module/SFZero/SFZero/RIFF.cpp @@ -42,7 +42,7 @@ void RIFFChunk::SeekAfter(juce::InputStream* file) juce::String RIFFChunk::ReadString(juce::InputStream* file) { - char str[size]; + char* str = (char*)alloca (size); file->read(str, size); return juce::String(str); } diff --git a/module/SFZero/SFZero/SF2Reader.cpp b/module/SFZero/SFZero/SF2Reader.cpp index 59c833b..05753b5 100644 --- a/module/SFZero/SFZero/SF2Reader.cpp +++ b/module/SFZero/SFZero/SF2Reader.cpp @@ -215,7 +215,7 @@ juce::AudioSampleBuffer* SF2Reader::readSamples (double* progressVar, juce::Thre for (; samplesToConvert > 0; --samplesToConvert) { // If we ever need to compile for big-endian platforms, we'll need to // byte-swap here. - *out++ = *in++ / 32767.0; + *out++ = *in++ / 32767.0f; } samplesLeft -= samplesToRead; @@ -260,7 +260,7 @@ void SF2Reader::addGeneratorToRegion( region->end += amount->shortAmount * 32768; break; case SF2Generator::pan: - region->pan = amount->shortAmount * (2.0 / 10.0); + region->pan = amount->shortAmount * (2.0f / 10.0f); break; case SF2Generator::delayVolEnv: region->ampeg.delay = amount->shortAmount; @@ -294,7 +294,7 @@ void SF2Reader::addGeneratorToRegion( case SF2Generator::initialAttenuation: // The spec says "initialAttenuation" is in centibels. But everyone // seems to treat it as millibels. - region->volume += -amount->shortAmount / 100.0; + region->volume += -amount->shortAmount / 100.0f; break; case SF2Generator::endloopAddrsCoarseOffset: region->loop_end += amount->shortAmount * 32768; diff --git a/module/SFZero/SFZero/SF2Sound.cpp b/module/SFZero/SFZero/SF2Sound.cpp index 1a813cc..3e936e4 100644 --- a/module/SFZero/SFZero/SF2Sound.cpp +++ b/module/SFZero/SFZero/SF2Sound.cpp @@ -5,8 +5,8 @@ namespace SFZero { -SF2Sound::SF2Sound(const juce::File& file) - : SFZSound(file) +SF2Sound::SF2Sound(const juce::File& f) + : SFZSound(f) { } diff --git a/module/SFZero/SFZero/SFZDebug.cpp b/module/SFZero/SFZero/SFZDebug.cpp index 70b71f9..d1ac7d7 100644 --- a/module/SFZero/SFZero/SFZDebug.cpp +++ b/module/SFZero/SFZero/SFZDebug.cpp @@ -37,7 +37,7 @@ void LogFifo::logMessage(const juce::String& message) msgSize -= givenSize - totalSize; // Write the count. - if (size1 >= sizeof(unsigned long)) { + if (size1 >= int (sizeof(unsigned long))) { memcpy(&buffer[start1], &msgSize, sizeof(unsigned long)); size1 -= sizeof(unsigned long); start1 += sizeof(unsigned long); diff --git a/module/SFZero/SFZero/SFZEG.cpp b/module/SFZero/SFZero/SFZEG.cpp index abc83df..67ce813 100644 --- a/module/SFZero/SFZero/SFZEG.cpp +++ b/module/SFZero/SFZero/SFZEG.cpp @@ -3,7 +3,7 @@ namespace SFZero { -static const float fastReleaseTime = 0.01; +static const float fastReleaseTime = 0.01f; SFZEG::SFZEG() @@ -108,9 +108,9 @@ void SFZEG::startAttack() startHold(); else { segment = Attack; - level = parameters.start / 100.0; + level = parameters.start / 100.0f; samplesUntilNextSegment = long (parameters.attack * sampleRate); - slope = 1.0 / samplesUntilNextSegment; + slope = 1.0f / samplesUntilNextSegment; segmentIsExponential = false; } } @@ -142,7 +142,7 @@ void SFZEG::startDecay() level = 1.0; if (exponentialDecay) { // I don't truly understand this; just following what LinuxSampler does. - float mysterySlope = -9.226 / samplesUntilNextSegment; + float mysterySlope = -9.226f / samplesUntilNextSegment; slope = exp(mysterySlope); segmentIsExponential = true; if (parameters.sustain > 0.0) { @@ -158,7 +158,7 @@ void SFZEG::startDecay() } } else { - slope = (parameters.sustain / 100.0 - 1.0) / samplesUntilNextSegment; + slope = (parameters.sustain / 100.0f - 1.0f) / samplesUntilNextSegment; segmentIsExponential = false; } } @@ -171,7 +171,7 @@ void SFZEG::startSustain() startRelease(); else { segment = Sustain; - level = parameters.sustain / 100.0; + level = parameters.sustain / 100.0f; slope = 0.0; samplesUntilNextSegment = 0x7FFFFFFF; segmentIsExponential = false; @@ -191,7 +191,7 @@ void SFZEG::startRelease() samplesUntilNextSegment = long (release * sampleRate); if (exponentialDecay) { // I don't truly understand this; just following what LinuxSampler does. - float mysterySlope = -9.226 / samplesUntilNextSegment; + float mysterySlope = -9.226f / samplesUntilNextSegment; slope = exp(mysterySlope); segmentIsExponential = true; } diff --git a/module/SFZero/SFZero/SFZRegion.cpp b/module/SFZero/SFZero/SFZRegion.cpp index 6962ce9..6f95fbf 100644 --- a/module/SFZero/SFZero/SFZRegion.cpp +++ b/module/SFZero/SFZero/SFZRegion.cpp @@ -103,7 +103,7 @@ void SFZRegion::sf2ToSFZ() ampeg.decay = timecents2Secs(short (ampeg.decay)); if (ampeg.sustain < 0.0) ampeg.sustain = 0.0; - ampeg.sustain = 100.0 * juce::Decibels::decibelsToGain(-ampeg.sustain / 10.0); + ampeg.sustain = 100.0f * juce::Decibels::decibelsToGain(-ampeg.sustain / 10.0f); ampeg.release = timecents2Secs(short (ampeg.release)); // Pin very short EG segments. Timecents don't get to zero, and our EG is @@ -141,7 +141,7 @@ void SFZRegion::dump() float SFZRegion::timecents2Secs(short timecents) { - return pow(2.0, timecents / 1200.0); + return pow(2.0f, timecents / 1200.0f); } } diff --git a/module/SFZero/SFZero/SFZSynth.cpp b/module/SFZero/SFZero/SFZSynth.cpp index c3821ce..8bc8b52 100644 --- a/module/SFZero/SFZero/SFZSynth.cpp +++ b/module/SFZero/SFZero/SFZSynth.cpp @@ -106,7 +106,7 @@ void SFZSynth::noteOff( startVoice( voice, sound, midiChannel, midiNoteNumber, - noteVelocities[midiNoteNumber] / 127.0); + noteVelocities[midiNoteNumber] / 127.0f); } } } diff --git a/module/SFZero/SFZero/SFZVoice.cpp b/module/SFZero/SFZero/SFZVoice.cpp index 48c17e1..4ae0e09 100644 --- a/module/SFZero/SFZero/SFZVoice.cpp +++ b/module/SFZero/SFZero/SFZVoice.cpp @@ -59,17 +59,17 @@ void SFZVoice::startNote (const int midiNoteNumber, const float floatVelocity, j // velocity curve in a way that I could understand, although they mean // "log10" when they say "log". double velocityGainDB = -20.0 * log10((127.0 * 127.0) / (velocity * velocity)); - velocityGainDB *= region->amp_veltrack / 100.0; + velocityGainDB *= region->amp_veltrack / 100.0f; noteGainDB += velocityGainDB; - noteGainLeft = noteGainRight = juce::Decibels::decibelsToGain(noteGainDB); + noteGainLeft = noteGainRight = float (juce::Decibels::decibelsToGain(noteGainDB)); // The SFZ spec is silent about the pan curve, but a 3dB pan law seems // common. This sqrt() curve matches what Dimension LE does; Alchemy Free // seems closer to sin(adjustedPan * pi/2). double adjustedPan = (region->pan + 100.0) / 200.0; - noteGainLeft *= sqrt(1.0 - adjustedPan); - noteGainRight *= sqrt(adjustedPan); + noteGainLeft *= float (std::sqrt(1.0f - adjustedPan)); + noteGainRight *= float (std::sqrt(adjustedPan)); ampeg.startNote( - ®ion->ampeg, floatVelocity, getSampleRate(), ®ion->ampeg_veltrack); + ®ion->ampeg, floatVelocity, float (getSampleRate()), ®ion->ampeg_veltrack); // Offset/end. sourceSamplePosition = region->offset; @@ -270,7 +270,7 @@ juce::String SFZVoice::infoString() #define numEGSegments (sizeof(egSegmentNames) / sizeof(egSegmentNames[0])) const char* egSegmentName = "-Invalid-"; int egSegmentIndex = ampeg.segmentIndex(); - if (egSegmentIndex >= 0 && egSegmentIndex < numEGSegments) + if (egSegmentIndex >= 0 && egSegmentIndex < int (numEGSegments)) egSegmentName = egSegmentNames[egSegmentIndex]; char str[128]; From 9c2b975bab48a45f5a298a1260a94bd07a6b239e Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Thu, 10 Apr 2025 15:40:17 -0700 Subject: [PATCH 6/6] More warnings --- module/SFZero/SFZero/RIFF.cpp | 2 +- module/SFZero/SFZero/SFZReader.cpp | 16 ++++++++-------- module/SFZero/SFZero/SFZSample.cpp | 6 +++--- module/SFZero/SFZero/SFZSound.cpp | 2 +- module/SFZero/SFZero/SFZSynth.cpp | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/module/SFZero/SFZero/RIFF.cpp b/module/SFZero/SFZero/RIFF.cpp index daeda1b..fd0f7c7 100644 --- a/module/SFZero/SFZero/RIFF.cpp +++ b/module/SFZero/SFZero/RIFF.cpp @@ -43,7 +43,7 @@ void RIFFChunk::SeekAfter(juce::InputStream* file) juce::String RIFFChunk::ReadString(juce::InputStream* file) { char* str = (char*)alloca (size); - file->read(str, size); + file->read(str, int (size)); return juce::String(str); } diff --git a/module/SFZero/SFZero/SFZReader.cpp b/module/SFZero/SFZero/SFZReader.cpp index 61dbe49..82d38cc 100644 --- a/module/SFZero/SFZero/SFZReader.cpp +++ b/module/SFZero/SFZero/SFZReader.cpp @@ -185,19 +185,19 @@ void SFZReader::read(const char* text, unsigned int length) if (buildingRegion == NULL) error("Setting a parameter outside a region or group"); else if (opcode == "lokey") - buildingRegion->lokey = keyValue(value); + buildingRegion->lokey = (unsigned char)keyValue(value); else if (opcode == "hikey") - buildingRegion->hikey = keyValue(value); + buildingRegion->hikey = (unsigned char)keyValue(value); else if (opcode == "key") { buildingRegion->hikey = buildingRegion->lokey = buildingRegion->pitch_keycenter = - keyValue(value); + (unsigned char)keyValue(value); } else if (opcode == "lovel") - buildingRegion->lovel = value.getIntValue(); + buildingRegion->lovel = (unsigned char)value.getIntValue(); else if (opcode == "hivel") - buildingRegion->hivel = value.getIntValue(); + buildingRegion->hivel = (unsigned char)value.getIntValue(); else if (opcode == "trigger") buildingRegion->trigger = (SFZRegion::Trigger) triggerValue(value); else if (opcode == "group") @@ -211,7 +211,7 @@ void SFZReader::read(const char* text, unsigned int length) if (endV < 0) buildingRegion->negative_end = true; else - buildingRegion->end = endV; + buildingRegion->end = (unsigned long)endV; } else if (opcode == "loop_mode") { bool modeIsSupported = @@ -357,7 +357,7 @@ const char* SFZReader::readPathInto(juce::String* pathOut, const char* pIn, cons int SFZReader::keyValue(const juce::String& str) { - char c = str[0]; + char c = (char)str[0]; if (c >= '0' && c <= '9') return str.getIntValue(); @@ -370,7 +370,7 @@ int SFZReader::keyValue(const juce::String& str) else if (c >= 'a' && c <= 'g') note = notes[c - 'a']; int octaveStart = 1; - c = str[1]; + c = (unsigned char)str[1]; if (c == 'b' || c == '#') { octaveStart += 1; if (c == 'b') diff --git a/module/SFZero/SFZero/SFZSample.cpp b/module/SFZero/SFZero/SFZSample.cpp index 8c0da94..76c9224 100644 --- a/module/SFZero/SFZero/SFZSample.cpp +++ b/module/SFZero/SFZero/SFZSample.cpp @@ -9,7 +9,7 @@ bool SFZSample::load(juce::AudioFormatManager* formatManager) if (reader == NULL) return false; sampleRate = reader->sampleRate; - sampleLength = reader->lengthInSamples; + sampleLength = (unsigned long)reader->lengthInSamples; // Read some extra samples, which will be filled with zeros, so interpolation // can be done without having to check for the edge all the time. buffer = new juce::AudioSampleBuffer(reader->numChannels, int (sampleLength + 4)); @@ -17,8 +17,8 @@ bool SFZSample::load(juce::AudioFormatManager* formatManager) juce::StringPairArray* metadata = &reader->metadataValues; int numLoops = metadata->getValue("NumSampleLoops", "0").getIntValue(); if (numLoops > 0) { - loopStart = metadata->getValue("Loop0Start", "0").getLargeIntValue(); - loopEnd = metadata->getValue("Loop0End", "0").getLargeIntValue(); + loopStart = (unsigned long)metadata->getValue("Loop0Start", "0").getLargeIntValue(); + loopEnd = (unsigned long)metadata->getValue("Loop0End", "0").getLargeIntValue(); } delete reader; return true; diff --git a/module/SFZero/SFZero/SFZSound.cpp b/module/SFZero/SFZero/SFZSound.cpp index 0cd8bfe..cd0ce31 100644 --- a/module/SFZero/SFZero/SFZSound.cpp +++ b/module/SFZero/SFZero/SFZSound.cpp @@ -116,7 +116,7 @@ SFZRegion* SFZSound::getRegionFor( int numRegions = regions.size(); for (int i = 0; i < numRegions; ++i) { SFZRegion* region = regions[i]; - if (region->matches(note, velocity, trigger)) + if (region->matches((unsigned char)note, (unsigned char)velocity, trigger)) return region; } diff --git a/module/SFZero/SFZero/SFZSynth.cpp b/module/SFZero/SFZero/SFZSynth.cpp index 8bc8b52..82c9933 100644 --- a/module/SFZero/SFZero/SFZSynth.cpp +++ b/module/SFZero/SFZero/SFZSynth.cpp @@ -64,7 +64,7 @@ void SFZSynth::noteOn(int midiChannel, int midiNoteNumber, float velocity) int numRegions = sound->getNumRegions(); for (i = 0; i < numRegions; ++i) { SFZRegion* region = sound->regionAt(i); - if (region->matches(midiNoteNumber, midiVelocity, trigger)) { + if (region->matches((unsigned char)midiNoteNumber, (unsigned char)midiVelocity, trigger)) { SFZVoice* voice = dynamic_cast( findFreeVoice( @@ -77,7 +77,7 @@ void SFZSynth::noteOn(int midiChannel, int midiNoteNumber, float velocity) } } - noteVelocities[midiNoteNumber] = midiVelocity; + noteVelocities[midiNoteNumber] = (unsigned char)midiVelocity; }