Cosmetics
This commit is contained in:
parent
dba851385d
commit
2f203fe163
6 changed files with 94 additions and 84 deletions
|
|
@ -6,11 +6,14 @@
|
|||
inline void trimInPlace(std::string_view &s)
|
||||
{
|
||||
const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v");
|
||||
if (leftPosition != s.npos) {
|
||||
if (leftPosition != s.npos)
|
||||
{
|
||||
s.remove_prefix(leftPosition);
|
||||
const auto rightPosition = s.find_last_not_of(" \r\t\n\f\v");
|
||||
s.remove_suffix(s.size() - rightPosition - 1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
s.remove_suffix(s.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -18,11 +21,14 @@ inline void trimInPlace(std::string_view& s)
|
|||
inline std::string_view trim(std::string_view s)
|
||||
{
|
||||
const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v");
|
||||
if (leftPosition != s.npos) {
|
||||
if (leftPosition != s.npos)
|
||||
{
|
||||
s.remove_prefix(leftPosition);
|
||||
const auto rightPosition = s.find_last_not_of(" \r\t\n\f\v");
|
||||
s.remove_suffix(s.size() - rightPosition - 1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
s.remove_suffix(s.size());
|
||||
}
|
||||
return s;
|
||||
|
|
@ -106,10 +112,11 @@ inline constexpr Type mag2db(Type in)
|
|||
return static_cast<Type>(20.0) * std::log10(in);
|
||||
}
|
||||
|
||||
namespace Random {
|
||||
namespace Random
|
||||
{
|
||||
static inline std::random_device randomDevice;
|
||||
static inline std::mt19937 randomGenerator{randomDevice()};
|
||||
}
|
||||
} // namespace Random
|
||||
|
||||
inline float midiNoteFrequency(const int noteNumber)
|
||||
{
|
||||
|
|
@ -125,16 +132,12 @@ constexpr Type piTwo { pi<Type> / 2 };
|
|||
|
||||
#include <atomic>
|
||||
template <class Owner>
|
||||
class LeakDetector {
|
||||
class LeakDetector
|
||||
{
|
||||
public:
|
||||
LeakDetector()
|
||||
{
|
||||
// auto currentCounter = objectCounter.count.load();
|
||||
// auto desiredCounter = currentCounter + 1;
|
||||
// while(!objectCounter.count.compare_exchange_weak(currentCounter, desiredCounter))
|
||||
// desiredCounter = currentCounter + 1;
|
||||
objectCounter.count++;
|
||||
// DBG("Counted " << desiredCounter << " " << Owner::getClassName());
|
||||
}
|
||||
LeakDetector(const LeakDetector &)
|
||||
{
|
||||
|
|
@ -143,27 +146,25 @@ public:
|
|||
~LeakDetector()
|
||||
{
|
||||
objectCounter.count--;
|
||||
// auto currentCounter = objectCounter.count.load();
|
||||
// auto desiredCounter = currentCounter - 1;
|
||||
// while(!objectCounter.count.compare_exchange_weak(currentCounter, desiredCounter))
|
||||
// desiredCounter = currentCounter - 1;
|
||||
// DBG("Counted " << desiredCounter << " " << Owner::getClassName() << " left after deletion");
|
||||
if (objectCounter.count.load() < 0) {
|
||||
if (objectCounter.count.load() < 0)
|
||||
{
|
||||
DBG("Deleted a dangling pointer for class " << Owner::getClassName());
|
||||
// Deleted a dangling pointer!
|
||||
// ASSERTFALSE;
|
||||
ASSERTFALSE;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
struct ObjectCounter {
|
||||
struct ObjectCounter
|
||||
{
|
||||
ObjectCounter() = default;
|
||||
~ObjectCounter()
|
||||
{
|
||||
if (auto residualCount = count.load() > 0) {
|
||||
if (auto residualCount = count.load() > 0)
|
||||
{
|
||||
DBG("Leaked " << residualCount << " instance(s) of class " << Owner::getClassName());
|
||||
// Leaked ojects
|
||||
// ASSERTFALSE;
|
||||
ASSERTFALSE;
|
||||
}
|
||||
};
|
||||
std::atomic<int> count{0};
|
||||
|
|
@ -174,7 +175,7 @@ private:
|
|||
#ifndef NDEBUG
|
||||
#define LEAK_DETECTOR(Class) \
|
||||
friend class LeakDetector<Class>; \
|
||||
static const char* getClassName() noexcept { return #Class; } \
|
||||
static const char *getClassName() { return #Class; } \
|
||||
LeakDetector<Class> leakDetector;
|
||||
#else
|
||||
#define LEAK_DETECTOR(Class)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
bool sfz::Region::parseOpcode(const Opcode &opcode)
|
||||
{
|
||||
switch (hash(opcode.opcode)) {
|
||||
switch (hash(opcode.opcode))
|
||||
{
|
||||
// Sound source: sample playback
|
||||
case hash("sample"):
|
||||
sample = absl::StrReplaceAll(trim(opcode.value), {{"\\", "/"}});
|
||||
|
|
@ -33,7 +34,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
break;
|
||||
case hash("loopmode"):
|
||||
case hash("loop_mode"):
|
||||
switch (hash(opcode.value)) {
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
case hash("no_loop"):
|
||||
loopMode = SfzLoopMode::no_loop;
|
||||
break;
|
||||
|
|
@ -68,7 +70,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
setValueFromOpcode(opcode, offBy, Default::groupRange);
|
||||
break;
|
||||
case hash("off_mode"):
|
||||
switch (hash(opcode.value)) {
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
case hash("fast"):
|
||||
offMode = SfzOffMode::fast;
|
||||
break;
|
||||
|
|
@ -112,7 +115,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
setRangeEndFromOpcode(opcode, bendRange, Default::bendRange);
|
||||
break;
|
||||
case hash("locc"):
|
||||
if (opcode.parameter) {
|
||||
if (opcode.parameter)
|
||||
{
|
||||
setRangeStartFromOpcode(opcode, ccConditions[*opcode.parameter], Default::ccRange);
|
||||
}
|
||||
break;
|
||||
|
|
@ -142,7 +146,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
previousKeySwitched = false;
|
||||
break;
|
||||
case hash("sw_vel"):
|
||||
switch (hash(opcode.value)) {
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
case hash("current"):
|
||||
velocityOverride = SfzVelocityOverride::current;
|
||||
break;
|
||||
|
|
@ -181,7 +186,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
break;
|
||||
// Region logic: triggers
|
||||
case hash("trigger"):
|
||||
switch (hash(opcode.value)) {
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
case hash("attack"):
|
||||
trigger = SfzTrigger::attack;
|
||||
break;
|
||||
|
|
@ -257,7 +263,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
gainDistribution.param(std::uniform_real_distribution<float>::param_type(-ampRandom, ampRandom));
|
||||
break;
|
||||
case hash("amp_velcurve_"):
|
||||
if (opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter)) {
|
||||
if (opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter))
|
||||
{
|
||||
if (auto value = readOpcode(opcode.value, Default::ampVelcurveRange); value)
|
||||
velocityPoints.emplace_back(*opcode.parameter, *value);
|
||||
}
|
||||
|
|
@ -287,7 +294,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
setRangeEndFromOpcode(opcode, crossfadeVelOutRange, Default::velocityRange);
|
||||
break;
|
||||
case hash("xf_keycurve"):
|
||||
switch (hash(opcode.value)) {
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
case hash("power"):
|
||||
crossfadeKeyCurve = SfzCrossfadeCurve::power;
|
||||
break;
|
||||
|
|
@ -299,7 +307,8 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
|||
}
|
||||
break;
|
||||
case hash("xf_velcurve"):
|
||||
switch (hash(opcode.value)) {
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
case hash("power"):
|
||||
crossfadeVelCurve = SfzCrossfadeCurve::power;
|
||||
break;
|
||||
|
|
@ -414,8 +423,10 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity,
|
|||
if (!chanOk)
|
||||
return false;
|
||||
|
||||
if (keyswitchRange.containsWithEnd(noteNumber)) {
|
||||
if (keyswitch) {
|
||||
if (keyswitchRange.containsWithEnd(noteNumber))
|
||||
{
|
||||
if (keyswitch)
|
||||
{
|
||||
if (*keyswitch == noteNumber)
|
||||
keySwitched = true;
|
||||
else
|
||||
|
|
@ -430,7 +441,8 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity,
|
|||
}
|
||||
|
||||
const bool keyOk = keyRange.containsWithEnd(noteNumber);
|
||||
if (keyOk) {
|
||||
if (keyOk)
|
||||
{
|
||||
// Update the number of notes playing for the region
|
||||
activeNotesInRange++;
|
||||
|
||||
|
|
@ -445,7 +457,8 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity,
|
|||
if (trigger == SfzTrigger::release_key || velocityOverride == SfzVelocityOverride::previous)
|
||||
lastNoteVelocities[noteNumber] = velocity;
|
||||
|
||||
if (previousNote) {
|
||||
if (previousNote)
|
||||
{
|
||||
if (*previousNote == noteNumber)
|
||||
previousKeySwitched = true;
|
||||
else
|
||||
|
|
@ -474,7 +487,8 @@ bool sfz::Region::registerNoteOff(int channel, int noteNumber, uint8_t velocity
|
|||
if (!chanOk)
|
||||
return false;
|
||||
|
||||
if (keyswitchRange.containsWithEnd(noteNumber)) {
|
||||
if (keyswitchRange.containsWithEnd(noteNumber))
|
||||
{
|
||||
if (keyswitchDown && *keyswitchDown == noteNumber)
|
||||
keySwitched = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,12 +13,6 @@ void writeInterleaved<float, true>(absl::Span<const float> inputLeft, absl::Span
|
|||
writeInterleaved<float, false>(inputLeft, inputRight, output);
|
||||
}
|
||||
|
||||
// template<class Type, bool SIMD=false>
|
||||
// void linearRamp(absl::Span<Type> output, Type start, Type step);
|
||||
|
||||
// template<class Type, bool SIMD=false>
|
||||
// void exponentialRamp(absl::Span<Type> output, Type start, Type step);
|
||||
|
||||
template<>
|
||||
void fill<float, true>(absl::Span<float> output, float value) noexcept
|
||||
{
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ public:
|
|||
void fillWithData(StereoSpan<float> buffer)
|
||||
{
|
||||
const StereoSpan<const float> source([&]() -> StereoBuffer<float>& {
|
||||
// TODO: shouldn't need to check fileData here, something is a bit strange...
|
||||
if (dataReady.load(std::memory_order_seq_cst) && fileData != nullptr)
|
||||
return *fileData;
|
||||
else
|
||||
|
|
@ -191,12 +192,12 @@ public:
|
|||
|
||||
void reset()
|
||||
{
|
||||
dataReady.store(false);
|
||||
state = State::idle;
|
||||
if (region != nullptr) {
|
||||
DBG("Reset voice with sample " << region->sample);
|
||||
}
|
||||
region = nullptr;
|
||||
state = State::idle;
|
||||
dataReady.store(false);
|
||||
noteIsOff = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue