WIP fixes: replace optional, string_view, nullopt with abseil versions, temporary clamp alternative.

This commit is contained in:
redtide 2019-09-18 20:33:08 +02:00 committed by paulfd
parent 025068b16b
commit 828440651f
21 changed files with 221 additions and 177 deletions

View file

@ -37,7 +37,7 @@ public:
int getNumMasters() const noexcept { return numMasters; }
int getNumCurves() const noexcept { return numCurves; }
protected:
void callback(std::string_view header, const std::vector<sfz::Opcode>& members [[maybe_unused]]) final
void callback(absl::string_view header, const std::vector<sfz::Opcode>& members [[maybe_unused]]) final
{
switch (hash(header))
{

View file

@ -24,7 +24,7 @@
#include "ADSREnvelope.h"
#include "Config.h"
#include "SIMDHelpers.h"
#include <algorithm>
#include "compat/algorithm.h"
namespace sfz {

View file

@ -72,7 +72,8 @@ public:
paddedData = static_cast<pointer>(newData);
normalData = static_cast<pointer>(std::align(Alignment, alignedSize, newData, tempSize));
normalEnd = normalData + alignedSize;
if (auto endMisalignment = (alignedSize & TypeAlignmentMask); endMisalignment != 0)
auto endMisalignment = (alignedSize & TypeAlignmentMask);
if (endMisalignment != 0)
_alignedEnd = normalEnd + Alignment - endMisalignment;
else
_alignedEnd = normalEnd;
@ -156,4 +157,4 @@ private:
pointer normalEnd { nullptr };
pointer _alignedEnd { nullptr };
LEAK_DETECTOR(Buffer);
};
};

View file

@ -39,114 +39,114 @@ namespace Default
// The categories match http://sfzformat.com/
// ******* SFZ 1 *******
// Sound source: sample playback
inline constexpr float delay { 0.0 };
inline constexpr float delayRandom { 0.0 };
inline constexpr Range<float> delayRange { 0.0, 100.0 };
inline constexpr uint32_t offset { 0 };
inline constexpr uint32_t offsetRandom { 0 };
inline constexpr Range<uint32_t> offsetRange { 0, std::numeric_limits<uint32_t>::max() };
inline constexpr Range<uint32_t> sampleEndRange { 0, std::numeric_limits<uint32_t>::max() };
inline constexpr Range<uint32_t> sampleCountRange { 0, std::numeric_limits<uint32_t>::max() };
inline constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop };
inline constexpr Range<uint32_t> loopRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr float delay { 0.0 };
constexpr float delayRandom { 0.0 };
constexpr Range<float> delayRange { 0.0, 100.0 };
constexpr uint32_t offset { 0 };
constexpr uint32_t offsetRandom { 0 };
constexpr Range<uint32_t> offsetRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr Range<uint32_t> sampleEndRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr Range<uint32_t> sampleCountRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop };
constexpr Range<uint32_t> loopRange { 0, std::numeric_limits<uint32_t>::max() };
// Instrument setting: voice lifecycle
inline constexpr uint32_t group { 0 };
inline constexpr Range<uint32_t> groupRange { 0, std::numeric_limits<uint32_t>::max() };
inline constexpr SfzOffMode offMode { SfzOffMode::fast };
constexpr uint32_t group { 0 };
constexpr Range<uint32_t> groupRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr SfzOffMode offMode { SfzOffMode::fast };
// Region logic: key mapping
inline constexpr Range<uint8_t> keyRange { 0, 127 };
inline constexpr Range<uint8_t> velocityRange { 0, 127 };
constexpr Range<uint8_t> keyRange { 0, 127 };
constexpr Range<uint8_t> velocityRange { 0, 127 };
// Region logic: MIDI conditions
inline constexpr Range<uint8_t> channelRange { 1, 16 };
inline constexpr Range<uint8_t> ccRange { 0, 127 };
inline constexpr uint8_t cc { 0 };
inline constexpr Range<int> bendRange { -8192, 8192 };
inline constexpr int bend { 0 };
inline constexpr SfzVelocityOverride velocityOverride { SfzVelocityOverride::current };
constexpr Range<uint8_t> channelRange { 1, 16 };
constexpr Range<uint8_t> ccRange { 0, 127 };
constexpr uint8_t cc { 0 };
constexpr Range<int> bendRange { -8192, 8192 };
constexpr int bend { 0 };
constexpr SfzVelocityOverride velocityOverride { SfzVelocityOverride::current };
// Region logic: internal conditions
inline constexpr Range<float> randRange { 0.0, 1.0 };
inline constexpr Range<uint8_t> aftertouchRange { 0, 127 };
inline constexpr uint8_t aftertouch { 0 };
inline constexpr Range<float> bpmRange { 0.0, 500.0 };
inline constexpr float bpm { 120.0 };
inline constexpr uint8_t sequenceLength{ 1 };
inline constexpr uint8_t sequencePosition{ 1 };
inline constexpr Range<uint8_t> sequenceRange { 1, 100 };
constexpr Range<float> randRange { 0.0, 1.0 };
constexpr Range<uint8_t> aftertouchRange { 0, 127 };
constexpr uint8_t aftertouch { 0 };
constexpr Range<float> bpmRange { 0.0, 500.0 };
constexpr float bpm { 120.0 };
constexpr uint8_t sequenceLength{ 1 };
constexpr uint8_t sequencePosition{ 1 };
constexpr Range<uint8_t> sequenceRange { 1, 100 };
// Region logic: Triggers
inline constexpr SfzTrigger trigger { SfzTrigger::attack };
inline constexpr Range<uint8_t> ccTriggerValueRange{ 0, 127 };
constexpr SfzTrigger trigger { SfzTrigger::attack };
constexpr Range<uint8_t> ccTriggerValueRange{ 0, 127 };
// Performance parameters: amplifier
inline constexpr float volume { -3.0 };
inline constexpr Range<float> volumeRange { -144.0, 6.0 };
inline constexpr Range<float> volumeCCRange { -144.0, 6.0 };
inline constexpr float amplitude { 100.0 };
inline constexpr Range<float> amplitudeRange { 0.0, 100.0 };
inline constexpr float pan { 0.0 };
inline constexpr Range<float> panRange { -100.0, 100.0 };
inline constexpr Range<float> panCCRange { -200.0, 200.0 };
inline constexpr float position { 0.0 };
inline constexpr Range<float> positionRange { -100.0, 100.0 };
inline constexpr Range<float> positionCCRange { -200.0, 200.0 };
inline constexpr float width { 0.0 };
inline constexpr Range<float> widthRange { -100.0, 100.0 };
inline constexpr Range<float> widthCCRange { -200.0, 200.0 };
inline constexpr uint8_t ampKeycenter { 60 };
inline constexpr float ampKeytrack { 0.0 };
inline constexpr Range<float> ampKeytrackRange { -96, 12 };
inline constexpr float ampVeltrack { 100.0 };
inline constexpr Range<float> ampVeltrackRange { -100.0, 100.0 };
inline constexpr Range<float> ampVelcurveRange { 0.0, 1.0 };
inline constexpr float ampRandom { 0.0 };
inline constexpr Range<float> ampRandomRange { 0.0, 24.0 };
inline constexpr Range<uint8_t> crossfadeKeyInRange { 0, 0 };
inline constexpr Range<uint8_t> crossfadeKeyOutRange { 127, 127 };
inline constexpr Range<uint8_t> crossfadeVelInRange { 0, 0 };
inline constexpr Range<uint8_t> crossfadeVelOutRange { 127, 127 };
inline constexpr Range<uint8_t> crossfadeCCInRange { 0, 0 };
inline constexpr Range<uint8_t> crossfadeCCOutRange { 127, 127 };
inline constexpr SfzCrossfadeCurve crossfadeKeyCurve { SfzCrossfadeCurve::power };
inline constexpr SfzCrossfadeCurve crossfadeVelCurve { SfzCrossfadeCurve::power };
inline constexpr SfzCrossfadeCurve crossfadeCCCurve { SfzCrossfadeCurve::power };
inline constexpr float rtDecay { 0.0f };
inline constexpr Range<float> rtDecayRange { 0.0f, 200.0f };
constexpr float volume { -3.0 };
constexpr Range<float> volumeRange { -144.0, 6.0 };
constexpr Range<float> volumeCCRange { -144.0, 6.0 };
constexpr float amplitude { 100.0 };
constexpr Range<float> amplitudeRange { 0.0, 100.0 };
constexpr float pan { 0.0 };
constexpr Range<float> panRange { -100.0, 100.0 };
constexpr Range<float> panCCRange { -200.0, 200.0 };
constexpr float position { 0.0 };
constexpr Range<float> positionRange { -100.0, 100.0 };
constexpr Range<float> positionCCRange { -200.0, 200.0 };
constexpr float width { 0.0 };
constexpr Range<float> widthRange { -100.0, 100.0 };
constexpr Range<float> widthCCRange { -200.0, 200.0 };
constexpr uint8_t ampKeycenter { 60 };
constexpr float ampKeytrack { 0.0 };
constexpr Range<float> ampKeytrackRange { -96, 12 };
constexpr float ampVeltrack { 100.0 };
constexpr Range<float> ampVeltrackRange { -100.0, 100.0 };
constexpr Range<float> ampVelcurveRange { 0.0, 1.0 };
constexpr float ampRandom { 0.0 };
constexpr Range<float> ampRandomRange { 0.0, 24.0 };
constexpr Range<uint8_t> crossfadeKeyInRange { 0, 0 };
constexpr Range<uint8_t> crossfadeKeyOutRange { 127, 127 };
constexpr Range<uint8_t> crossfadeVelInRange { 0, 0 };
constexpr Range<uint8_t> crossfadeVelOutRange { 127, 127 };
constexpr Range<uint8_t> crossfadeCCInRange { 0, 0 };
constexpr Range<uint8_t> crossfadeCCOutRange { 127, 127 };
constexpr SfzCrossfadeCurve crossfadeKeyCurve { SfzCrossfadeCurve::power };
constexpr SfzCrossfadeCurve crossfadeVelCurve { SfzCrossfadeCurve::power };
constexpr SfzCrossfadeCurve crossfadeCCCurve { SfzCrossfadeCurve::power };
constexpr float rtDecay { 0.0f };
constexpr Range<float> rtDecayRange { 0.0f, 200.0f };
// Performance parameters: pitch
inline constexpr uint8_t pitchKeycenter { 60 };
inline constexpr int pitchKeytrack { 100 };
inline constexpr Range<int> pitchKeytrackRange { -1200, 1200 };
inline constexpr int pitchRandom { 0 };
inline constexpr Range<int> pitchRandomRange { 0, 9600 };
inline constexpr int pitchVeltrack { 0 };
inline constexpr Range<int> pitchVeltrackRange { -9600, 9600 };
inline constexpr int transpose { 0 };
inline constexpr Range<int> transposeRange { -127, 127 };
inline constexpr int tune { 0 };
inline constexpr Range<int> tuneRange { -100, 100 };
constexpr uint8_t pitchKeycenter { 60 };
constexpr int pitchKeytrack { 100 };
constexpr Range<int> pitchKeytrackRange { -1200, 1200 };
constexpr int pitchRandom { 0 };
constexpr Range<int> pitchRandomRange { 0, 9600 };
constexpr int pitchVeltrack { 0 };
constexpr Range<int> pitchVeltrackRange { -9600, 9600 };
constexpr int transpose { 0 };
constexpr Range<int> transposeRange { -127, 127 };
constexpr int tune { 0 };
constexpr Range<int> tuneRange { -100, 100 };
// Envelope generators
inline constexpr float attack { 0 };
inline constexpr float decay { 0 };
inline constexpr float delayEG { 0 };
inline constexpr float hold { 0 };
inline constexpr float release { 0 };
inline constexpr float start { 0.0 };
inline constexpr float sustain { 100.0 };
inline constexpr float vel2sustain { 0.0 };
inline constexpr int depth { 0 };
inline constexpr Range<float> egTimeRange { 0.0, 100.0 };
inline constexpr Range<float> egPercentRange { 0.0, 100.0 };
inline constexpr Range<int> egDepthRange { -12000, 12000 };
inline constexpr Range<float> egOnCCTimeRange { -100.0, 100.0 };
inline constexpr Range<float> egOnCCPercentRange { -100.0, 100.0 };
constexpr float attack { 0 };
constexpr float decay { 0 };
constexpr float delayEG { 0 };
constexpr float hold { 0 };
constexpr float release { 0 };
constexpr float start { 0.0 };
constexpr float sustain { 100.0 };
constexpr float vel2sustain { 0.0 };
constexpr int depth { 0 };
constexpr Range<float> egTimeRange { 0.0, 100.0 };
constexpr Range<float> egPercentRange { 0.0, 100.0 };
constexpr Range<int> egDepthRange { -12000, 12000 };
constexpr Range<float> egOnCCTimeRange { -100.0, 100.0 };
constexpr Range<float> egOnCCPercentRange { -100.0, 100.0 };
// ***** SFZ v2 ********
inline constexpr bool checkSustain { true }; // sustain_sw
inline constexpr bool checkSostenuto { true }; // sostenuto_sw
constexpr bool checkSustain { true }; // sustain_sw
constexpr bool checkSostenuto { true }; // sostenuto_sw
}
}
}

View file

@ -26,7 +26,7 @@
#include "Defaults.h"
#include "LeakDetector.h"
#include "SfzHelpers.h"
#include <optional>
#include <absl/types/optional.h>
namespace sfz
@ -55,13 +55,13 @@ struct EGDescription
float vel2sustain { Default::vel2sustain };
int vel2depth { Default::depth };
std::optional<CCValuePair> ccAttack;
std::optional<CCValuePair> ccDecay;
std::optional<CCValuePair> ccDelay;
std::optional<CCValuePair> ccHold;
std::optional<CCValuePair> ccRelease;
std::optional<CCValuePair> ccStart;
std::optional<CCValuePair> ccSustain;
absl::optional<CCValuePair> ccAttack;
absl::optional<CCValuePair> ccDecay;
absl::optional<CCValuePair> ccDelay;
absl::optional<CCValuePair> ccHold;
absl::optional<CCValuePair> ccRelease;
absl::optional<CCValuePair> ccStart;
absl::optional<CCValuePair> ccSustain;
float getAttack(const CCValueArray &ccValues, uint8_t velocity) const noexcept
{
@ -94,4 +94,4 @@ struct EGDescription
LEAK_DETECTOR(EGDescription);
};
} //namespace sfz
} //namespace sfz

View file

@ -31,6 +31,7 @@
#include <mutex>
#include <sndfile.hh>
#include <thread>
#include <mutex>
using namespace std::chrono_literals;
template <class T>
@ -47,7 +48,7 @@ std::unique_ptr<AudioBuffer<T>> readFromFile(SndfileHandle& sndFile, int numFram
return returnedBuffer;
}
std::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(std::string_view filename, uint32_t offset) noexcept
absl::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(absl::string_view filename, uint32_t offset) noexcept
{
std::filesystem::path file { rootDirectory / filename };
if (!std::filesystem::exists(file))
@ -101,7 +102,7 @@ std::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(
return returnedValue;
}
void sfz::FilePool::enqueueLoading(Voice* voice, std::string_view sample, int numFrames, unsigned ticket) noexcept
void sfz::FilePool::enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept
{
if (!loadingQueue.try_enqueue({ voice, sample, numFrames, ticket })) {
DBG("Problem enqueuing a file read for file " << sample);
@ -161,4 +162,4 @@ void sfz::FilePool::clear()
while (loadingQueue.pop()) {
// Pop the queue
}
}
}

View file

@ -31,7 +31,7 @@
#include "readerwriterqueue.h"
#include <absl/container/flat_hash_map.h>
#include <mutex>
#include <optional>
#include <absl/types/optional.h>
#include <string_view>
#include <thread>
@ -56,14 +56,14 @@ public:
double sampleRate { config::defaultSampleRate };
std::shared_ptr<AudioBuffer<float>> preloadedData;
};
std::optional<FileInformation> getFileInformation(std::string_view filename, uint32_t offset) noexcept;
void enqueueLoading(Voice* voice, std::string_view sample, int numFrames, unsigned ticket) noexcept;
absl::optional<FileInformation> getFileInformation(absl::string_view filename, uint32_t offset) noexcept;
void enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept;
void clear();
private:
std::filesystem::path rootDirectory;
struct FileLoadingInformation {
Voice* voice;
std::string_view sample;
absl::string_view sample;
int numFrames;
unsigned ticket;
};
@ -76,7 +76,7 @@ private:
std::thread garbageCollectionThread { &FilePool::garbageThread, this };
std::vector<std::shared_ptr<AudioBuffer<float>>> fileHandles;
std::mutex fileHandleMutex;
absl::flat_hash_map<std::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
absl::flat_hash_map<absl::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
LEAK_DETECTOR(FilePool);
};
}

View file

@ -27,6 +27,7 @@
#include <absl/types/span.h>
#include <functional>
#include <type_traits>
#include <vector>
namespace sfz {
@ -50,4 +51,4 @@ private:
LEAK_DETECTOR(LinearEnvelope);
};
}
}

View file

@ -24,13 +24,13 @@
#include "Opcode.h"
#include "StringViewHelpers.h"
sfz::Opcode::Opcode(std::string_view inputOpcode, std::string_view inputValue)
sfz::Opcode::Opcode(absl::string_view inputOpcode, absl::string_view inputValue)
: opcode(inputOpcode)
, value(inputValue)
{
if (const auto lastCharIndex = inputOpcode.find_last_not_of("1234567890"); lastCharIndex != inputOpcode.npos) {
int returnedValue;
std::string_view parameterView = inputOpcode;
absl::string_view parameterView = inputOpcode;
parameterView.remove_prefix(lastCharIndex + 1);
if (absl::SimpleAtoi(parameterView, &returnedValue)) {
parameter = returnedValue;

View file

@ -27,7 +27,7 @@
#include "Range.h"
#include "SfzHelpers.h"
#include "StringViewHelpers.h"
#include <optional>
#include <absl/types/optional.h>
#include <string_view>
// charconv support is still sketchy with clang/gcc so we use abseil's numbers
@ -36,16 +36,16 @@
namespace sfz {
struct Opcode {
Opcode() = delete;
Opcode(std::string_view inputOpcode, std::string_view inputValue);
std::string_view opcode {};
std::string_view value {};
Opcode(absl::string_view inputOpcode, absl::string_view inputValue);
absl::string_view opcode {};
absl::string_view value {};
// This is to handle the integer parameter of some opcodes
std::optional<uint8_t> parameter;
absl::optional<uint8_t> parameter;
LEAK_DETECTOR(Opcode);
};
template <class ValueType>
inline std::optional<ValueType> readOpcode(std::string_view value, const Range<ValueType>& validRange)
inline absl::optional<ValueType> readOpcode(absl::string_view value, const Range<ValueType>& validRange)
{
if constexpr (std::is_integral<ValueType>::value) {
int64_t returnedValue;
@ -65,13 +65,13 @@ inline std::optional<ValueType> readOpcode(std::string_view value, const Range<V
} else {
float returnedValue;
if (!absl::SimpleAtof(value, &returnedValue))
return std::nullopt;
return absl::nullopt;
return validRange.clamp(returnedValue);
}
}
inline std::optional<bool> readBooleanFromOpcode(const Opcode& opcode)
inline absl::optional<bool> readBooleanFromOpcode(const Opcode& opcode)
{
switch (hash(opcode.value)) {
case hash("off"):
@ -94,7 +94,7 @@ inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Ra
}
template <class ValueType>
inline void setValueFromOpcode(const Opcode& opcode, std::optional<ValueType>& target, const Range<ValueType>& validRange)
inline void setValueFromOpcode(const Opcode& opcode, absl::optional<ValueType>& target, const Range<ValueType>& validRange)
{
auto value = readOpcode(opcode.value, validRange);
if (!value) // Try and read a note rather than a number
@ -124,7 +124,7 @@ inline void setRangeStartFromOpcode(const Opcode& opcode, Range<ValueType>& targ
}
template <class ValueType>
inline void setCCPairFromOpcode(const Opcode& opcode, std::optional<CCValuePair>& target, const Range<ValueType>& validRange)
inline void setCCPairFromOpcode(const Opcode& opcode, absl::optional<CCValuePair>& target, const Range<ValueType>& validRange)
{
auto value = readOpcode(opcode.value, validRange);
if (value && opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter))

View file

@ -28,12 +28,13 @@
#include <algorithm>
#include <fstream>
using svregex_iterator = std::regex_iterator<std::string_view::const_iterator>;
using svmatch_results = std::match_results<std::string_view::const_iterator>;
using svregex_iterator = std::regex_iterator<absl::string_view::const_iterator>;
using svmatch_results = std::match_results<absl::string_view::const_iterator>;
void removeCommentOnLine(std::string_view& line)
void removeCommentOnLine(absl::string_view& line)
{
if (auto position = line.find("//"); position != line.npos)
auto position = line.find("//");
if (position != line.npos)
line.remove_suffix(line.size() - position);
}
@ -48,7 +49,7 @@ bool sfz::Parser::loadSfzFile(const std::filesystem::path& file)
readSfzFile(file, lines);
aggregatedContent = absl::StrJoin(lines, " ");
const std::string_view aggregatedView { aggregatedContent };
const absl::string_view aggregatedView { aggregatedContent };
svregex_iterator headerIterator(aggregatedView.cbegin(), aggregatedView.cend(), sfz::Regexes::headers);
const auto regexEnd = svregex_iterator();
@ -59,15 +60,15 @@ bool sfz::Parser::loadSfzFile(const std::filesystem::path& file)
svmatch_results headerMatch = *headerIterator;
// Can't use uniform initialization here because it generates narrowing conversions
const std::string_view header(&*headerMatch[1].first, headerMatch[1].length());
const std::string_view members(&*headerMatch[2].first, headerMatch[2].length());
const absl::string_view header(&*headerMatch[1].first, headerMatch[1].length());
const absl::string_view members(&*headerMatch[2].first, headerMatch[2].length());
auto paramIterator = svregex_iterator(members.cbegin(), members.cend(), sfz::Regexes::members);
// Store or handle members
for (; paramIterator != regexEnd; ++paramIterator) {
const svmatch_results paramMatch = *paramIterator;
const std::string_view opcode(&*paramMatch[1].first, paramMatch[1].length());
const std::string_view value(&*paramMatch[2].first, paramMatch[2].length());
const absl::string_view opcode(&*paramMatch[1].first, paramMatch[1].length());
const absl::string_view value(&*paramMatch[2].first, paramMatch[2].length());
currentMembers.emplace_back(opcode, value);
}
callback(header, currentMembers);
@ -89,7 +90,7 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector
std::string tmpString;
while (std::getline(fileStream, tmpString)) {
std::string_view tmpView { tmpString };
absl::string_view tmpView { tmpString };
removeCommentOnLine(tmpView);
trimInPlace(tmpView);
@ -152,4 +153,4 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector
newString += tmpView.substr(lastPos);
lines.push_back(std::move(newString));
}
}
}

View file

@ -47,7 +47,7 @@ public:
void disableRecursiveIncludeGuard() { recursiveIncludeGuard = false; }
void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; }
protected:
virtual void callback(std::string_view header, const std::vector<Opcode>& members) = 0;
virtual void callback(absl::string_view header, const std::vector<Opcode>& members) = 0;
std::filesystem::path rootDirectory { std::filesystem::current_path() };
private:
bool recursiveIncludeGuard { false };

View file

@ -22,7 +22,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <algorithm>
#include "compat/algorithm.h"
#include <initializer_list>
#include <type_traits>
@ -108,4 +108,4 @@ template <class Type>
bool operator==(const std::pair<Type, Type>& lhs, const Range<Type>& rhs)
{
return rhs == lhs;
}
}

View file

@ -29,7 +29,7 @@
#include "Opcode.h"
#include "AudioBuffer.h"
#include <bitset>
#include <optional>
#include <absl/types/optional.h>
#include <random>
#include <string>
#include <vector>
@ -73,13 +73,13 @@ struct Region {
uint32_t offset { Default::offset }; // offset
uint32_t offsetRandom { Default::offsetRandom }; // offset_random
uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end
std::optional<uint32_t> sampleCount {}; // count
absl::optional<uint32_t> sampleCount {}; // count
SfzLoopMode loopMode { Default::loopMode }; // loopmode
Range<uint32_t> loopRange { Default::loopRange }; //loopstart and loopend
// Instrument settings: voice lifecycle
uint32_t group { Default::group }; // group
std::optional<uint32_t> offBy {}; // off_by
absl::optional<uint32_t> offBy {}; // off_by
SfzOffMode offMode { Default::offMode }; // off_mode
// Region logic: key mapping
@ -91,10 +91,10 @@ struct Region {
Range<int> bendRange { Default::bendRange }; // hibend and lobend
CCMap<Range<uint8_t>> ccConditions { Default::ccRange };
Range<uint8_t> keyswitchRange { Default::keyRange }; // sw_hikey and sw_lokey
std::optional<uint8_t> keyswitch {}; // sw_last
std::optional<uint8_t> keyswitchUp {}; // sw_up
std::optional<uint8_t> keyswitchDown {}; // sw_down
std::optional<uint8_t> previousNote {}; // sw_previous
absl::optional<uint8_t> keyswitch {}; // sw_last
absl::optional<uint8_t> keyswitchUp {}; // sw_up
absl::optional<uint8_t> keyswitchDown {}; // sw_down
absl::optional<uint8_t> previousNote {}; // sw_previous
SfzVelocityOverride velocityOverride { Default::velocityOverride }; // sw_vel
bool checkSustain { Default::checkSustain }; // sustain_sw
bool checkSostenuto { Default::checkSostenuto }; // sostenuto_sw
@ -116,11 +116,11 @@ struct Region {
float pan { Default::pan }; // pan
float width { Default::width }; // width
float position { Default::position }; // position
std::optional<CCValuePair> volumeCC; // volume_oncc
std::optional<CCValuePair> amplitudeCC; // amplitude_oncc
std::optional<CCValuePair> panCC; // pan_oncc
std::optional<CCValuePair> widthCC; // width_oncc
std::optional<CCValuePair> positionCC; // position_oncc
absl::optional<CCValuePair> volumeCC; // volume_oncc
absl::optional<CCValuePair> amplitudeCC; // amplitude_oncc
absl::optional<CCValuePair> panCC; // pan_oncc
absl::optional<CCValuePair> widthCC; // width_oncc
absl::optional<CCValuePair> positionCC; // position_oncc
uint8_t ampKeycenter { Default::ampKeycenter }; // amp_keycenter
float ampKeytrack { Default::ampKeytrack }; // amp_keytrack
float ampVeltrack { Default::ampVeltrack }; // amp_keytrack

View file

@ -24,7 +24,7 @@
#include "SfzHelpers.h"
#include "StringViewHelpers.h"
std::optional<uint8_t> sfz::readNoteValue(const std::string_view& value)
absl::optional<uint8_t> sfz::readNoteValue(const absl::string_view& value)
{
switch(hash(value))
{

View file

@ -22,8 +22,9 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <optional>
#include <string>
#include <absl/types/optional.h>
#include <absl/strings/string_view.h>
//#include <string>
#include <array>
#include <cmath>
@ -59,7 +60,7 @@ inline constexpr float normalizeNegativePercents(T percentValue)
return std::min(std::max(static_cast<float>(percentValue), -100.0f), 100.0f) / 100.0f;
}
inline float ccSwitchedValue(const CCValueArray& ccValues, const std::optional<CCValuePair>& ccSwitch, float value) noexcept
inline float ccSwitchedValue(const CCValueArray& ccValues, const absl::optional<CCValuePair>& ccSwitch, float value) noexcept
{
if (ccSwitch)
return value + ccSwitch->second * normalizeCC(ccValues[ccSwitch->first]);
@ -67,7 +68,7 @@ inline float ccSwitchedValue(const CCValueArray& ccValues, const std::optional<C
return value;
}
std::optional<uint8_t> readNoteValue(const std::string_view& value);
absl::optional<uint8_t> readNoteValue(const absl::string_view& value);
} // namespace sfz

View file

@ -24,7 +24,7 @@
#pragma once
#include <string_view>
inline void trimInPlace(std::string_view& s)
inline void trimInPlace(absl::string_view& s)
{
const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v");
if (leftPosition != s.npos) {
@ -36,7 +36,7 @@ inline void trimInPlace(std::string_view& s)
}
}
inline std::string_view trim(std::string_view s)
inline absl::string_view trim(absl::string_view s)
{
const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v");
if (leftPosition != s.npos) {
@ -52,7 +52,7 @@ inline std::string_view trim(std::string_view s)
inline constexpr uint64_t Fnv1aBasis = 0x811C9DC5;
inline constexpr uint64_t Fnv1aPrime = 0x01000193;
inline constexpr uint64_t hash(std::string_view s, uint64_t h = Fnv1aBasis)
inline constexpr uint64_t hash(absl::string_view s, uint64_t h = Fnv1aBasis)
{
if (s.length() > 0)
return hash( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime );

View file

@ -41,7 +41,7 @@ sfz::Synth::Synth()
voiceViewArray.reserve(config::numVoices);
}
void sfz::Synth::callback(std::string_view header, const std::vector<Opcode>& members)
void sfz::Synth::callback(absl::string_view header, const std::vector<Opcode>& members)
{
switch (hash(header)) {
case hash("global"):
@ -87,7 +87,7 @@ void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
auto parseOpcodes = [&](const auto& opcodes) {
for (auto& opcode : opcodes) {
const auto unknown = absl::c_find_if(unknownOpcodes, [&](std::string_view sv) { return sv.compare(opcode.opcode) == 0; });
const auto unknown = absl::c_find_if(unknownOpcodes, [&](absl::string_view sv) { return sv.compare(opcode.opcode) == 0; });
if (unknown != unknownOpcodes.end()) {
continue;
}
@ -113,7 +113,7 @@ void sfz::Synth::clear()
numMasters = 0;
numCurves = 0;
fileTicket = -1;
defaultSwitch = std::nullopt;
defaultSwitch = absl::nullopt;
for (auto& state : ccState)
state = 0;
ccNames.clear();
@ -426,11 +426,11 @@ const sfz::Region* sfz::Synth::getRegionView(int idx) const noexcept
{
return (size_t)idx < regions.size() ? regions[idx].get() : nullptr;
}
std::set<std::string_view> sfz::Synth::getUnknownOpcodes() const noexcept
std::set<absl::string_view> sfz::Synth::getUnknownOpcodes() const noexcept
{
return unknownOpcodes;
}
size_t sfz::Synth::getNumPreloadedSamples() const noexcept
{
return filePool.getNumPreloadedSamples();
}
}

View file

@ -28,7 +28,7 @@
#include "LeakDetector.h"
#include "AudioSpan.h"
#include "absl/types/span.h"
#include <optional>
#include <absl/types/optional.h>
#include <random>
#include <set>
#include <string_view>
@ -46,7 +46,7 @@ public:
int getNumMasters() const noexcept;
int getNumCurves() const noexcept;
const Region* getRegionView(int idx) const noexcept;
std::set<std::string_view> getUnknownOpcodes() const noexcept;
std::set<absl::string_view> getUnknownOpcodes() const noexcept;
size_t getNumPreloadedSamples() const noexcept;
void setSamplesPerBlock(int samplesPerBlock) noexcept;
@ -62,7 +62,7 @@ public:
void getNumActiveVoices() const noexcept;
void garbageCollect() noexcept;
protected:
void callback(std::string_view header, const std::vector<Opcode>& members) final;
void callback(absl::string_view header, const std::vector<Opcode>& members) final;
private:
bool hasGlobal { false };
@ -83,8 +83,8 @@ private:
CCValueArray ccState;
Voice* findFreeVoice() noexcept;
std::vector<CCNamePair> ccNames;
std::optional<uint8_t> defaultSwitch;
std::set<std::string_view> unknownOpcodes;
absl::optional<uint8_t> defaultSwitch;
std::set<absl::string_view> unknownOpcodes;
using RegionPtrVector = std::vector<Region*>;
using VoicePtrVector = std::vector<Voice*>;
std::vector<std::unique_ptr<Region>> regions;

39
sfizz/compat/algorithm.h Normal file
View file

@ -0,0 +1,39 @@
// Copyright (c) 2019, Paul Ferrand
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <algorithm>
#if __cplusplus <= 201402L
#include <cassert>
namespace std
{
template<class T>
constexpr const T& clamp( const T& v, const T& lo, const T& hi )
{
assert( !(hi < lo) );
return (v < lo) ? lo : (hi < v) ? hi : v;
}
}
#endif // lower than C++17

View file

@ -24,12 +24,12 @@
#pragma once
#if defined(__cpp_lib_filesystem) || (defined(__has_include) && __has_include(<filesystem>))
#include <filesystem>
#elif defined(__cpp_lib_experimental_filesystem) || (defined(__has_include) && __has_include(<experimental/filesystem>))
#include <experimental/filesystem>
namespace std {
namespace filesystem = std::experimental::filesystem;
}
#include <filesystem>
#elif __cplusplus >= 201103L
#include <experimental/filesystem>
namespace std {
namespace filesystem = std::experimental::filesystem;
}
#else
#error no filesystem support
#error no filesystem support
#endif