Stricter c++11 compliance

This commit is contained in:
Paul Fd 2020-04-07 20:14:55 +02:00 committed by Jean Pierre Cimalando
parent 5f9bbbede5
commit becdff5969
5 changed files with 29 additions and 27 deletions

View file

@ -7,16 +7,18 @@
template<typename F>
struct deferred
{
std::decay_t<F> f;
template<typename G>
deferred(G&& g) : f{std::forward<G>(g)} {}
F f;
deferred(F f) : f(f) {}
~deferred() { f(); }
};
template<typename G>
deferred(G&&) -> deferred<G>;
template <typename F>
deferred<F> deferred_func(F f) {
return deferred<F>(f);
}
#define CAT_(x, y) x##y
#define CAT(x, y) CAT_(x, y)
#define ANONYMOUS_VAR(x) CAT(x, __LINE__)
#define DEFER deferred ANONYMOUS_VAR(defer_variable) = [&]
#define DEFER(code) auto ANONYMOUS_VAR(defer_variable) = deferred_func([&] { code ; })

View file

@ -110,7 +110,7 @@ sfz::EQHolderPtr sfz::EQPool::getEQ(const EQDescription& description, unsigned n
{
if (!eqGuard.try_lock())
return {};
DEFER { eqGuard.unlock(); };
DEFER(eqGuard.unlock());
auto eq = absl::c_find_if(eqs, [](const EQHolderPtr& holder) {
return holder.use_count() == 1;
@ -132,7 +132,7 @@ size_t sfz::EQPool::getActiveEQs() const
size_t sfz::EQPool::setnumEQs(size_t numEQs)
{
const std::lock_guard eqLock { eqGuard };
const std::lock_guard<std::mutex> eqLock { eqGuard };
auto eqIterator = eqs.begin();
auto eqSentinel = eqs.rbegin();

View file

@ -306,7 +306,7 @@ void sfz::FilePool::setPreloadSize(uint32_t preloadSize) noexcept
void sfz::FilePool::tryToClearPromises()
{
const std::lock_guard promiseLock { promiseGuard };
const std::lock_guard<std::mutex> promiseLock { promiseGuard };
for (auto& promise: promisesToClear) {
if (promise->dataStatus != FilePromise::DataStatus::Wait)
@ -381,7 +381,7 @@ void sfz::FilePool::cleanupPromises() noexcept
{
if (!promiseGuard.try_lock())
return;
DEFER { promiseGuard.unlock(); };
DEFER(promiseGuard.unlock());
// The garbage collection cleared the data from these so we can move them
// back to the empty queue

View file

@ -111,7 +111,7 @@ sfz::FilterHolderPtr sfz::FilterPool::getFilter(const FilterDescription& descrip
{
if (!filterGuard.try_lock())
return {};
DEFER { filterGuard.unlock(); };
DEFER(filterGuard.unlock());
auto filter = absl::c_find_if(filters, [](const FilterHolderPtr& holder) {
return holder.use_count() == 1;
@ -133,7 +133,7 @@ size_t sfz::FilterPool::getActiveFilters() const
size_t sfz::FilterPool::setNumFilters(size_t numFilters)
{
const std::lock_guard filterLock { filterGuard };
const std::lock_guard<std::mutex> filterLock { filterGuard };
auto filterIterator = filters.begin();
auto filterSentinel = filters.rbegin();

View file

@ -28,7 +28,7 @@ sfz::Synth::Synth()
sfz::Synth::Synth(int numVoices)
{
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
parser.setListener(this);
effectFactory.registerStandardEffectTypes();
effectBuses.reserve(5); // sufficient room for main and fx1-4
@ -37,7 +37,7 @@ sfz::Synth::Synth(int numVoices)
sfz::Synth::~Synth()
{
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
for (auto& voice : voices)
voice->reset();
@ -123,7 +123,7 @@ void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
void sfz::Synth::clear()
{
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
for (auto& voice : voices)
voice->reset();
@ -321,7 +321,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file)
{
clear();
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
parser.parseFile(file);
if (parser.getErrorCount() > 0)
return false;
@ -496,7 +496,7 @@ void sfz::Synth::setSamplesPerBlock(int samplesPerBlock) noexcept
{
ASSERT(samplesPerBlock < config::maxBlockSize);
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
this->samplesPerBlock = samplesPerBlock;
for (auto& voice : voices)
@ -512,7 +512,7 @@ void sfz::Synth::setSamplesPerBlock(int samplesPerBlock) noexcept
void sfz::Synth::setSampleRate(float sampleRate) noexcept
{
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
this->sampleRate = sampleRate;
for (auto& voice : voices)
@ -541,7 +541,7 @@ void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
if (!callbackGuard.try_lock())
return;
DEFER { callbackGuard.unlock(); };
DEFER(callbackGuard.unlock());
size_t numFrames = buffer.getNumFrames();
@ -637,7 +637,7 @@ void sfz::Synth::noteOn(int delay, int noteNumber, uint8_t velocity) noexcept
if (!callbackGuard.try_lock())
return;
DEFER { callbackGuard.unlock(); };
DEFER(callbackGuard.unlock());
noteOnDispatch(delay, noteNumber, normalizedVelocity);
}
@ -653,7 +653,7 @@ void sfz::Synth::noteOff(int delay, int noteNumber, uint8_t velocity) noexcept
if (!callbackGuard.try_lock())
return;
DEFER { callbackGuard.unlock(); };
DEFER(callbackGuard.unlock());
// FIXME: Some keyboards (e.g. Casio PX5S) can send a real note-off velocity. In this case, do we have a
// way in sfz to specify that a release trigger should NOT use the note-on velocity?
@ -749,7 +749,7 @@ void sfz::Synth::cc(int delay, int ccNumber, uint8_t ccValue) noexcept
if (!callbackGuard.try_lock())
return;
DEFER { callbackGuard.unlock(); };
DEFER(callbackGuard.unlock());
if (ccNumber == config::resetCC) {
resetAllControllers(delay);
@ -941,7 +941,7 @@ int sfz::Synth::getNumVoices() const noexcept
void sfz::Synth::setNumVoices(int numVoices) noexcept
{
ASSERT(numVoices > 0);
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
resetVoices(numVoices);
}
@ -962,7 +962,7 @@ void sfz::Synth::resetVoices(int numVoices)
void sfz::Synth::setOversamplingFactor(sfz::Oversampling factor) noexcept
{
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
for (auto& voice : voices)
voice->reset();
@ -979,7 +979,7 @@ sfz::Oversampling sfz::Synth::getOversamplingFactor() const noexcept
void sfz::Synth::setPreloadSize(uint32_t preloadSize) noexcept
{
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
resources.filePool.setPreloadSize(preloadSize);
}
@ -1010,7 +1010,7 @@ void sfz::Synth::resetAllControllers(int delay) noexcept
if (!callbackGuard.try_lock())
return;
DEFER { callbackGuard.unlock(); };
DEFER(callbackGuard.unlock());
for (auto& voice : voices) {
voice->registerPitchWheel(delay, 0);
@ -1057,7 +1057,7 @@ void sfz::Synth::disableLogging() noexcept
void sfz::Synth::allSoundOff() noexcept
{
const std::lock_guard disableCallback { callbackGuard };
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
for (auto& voice : voices)
voice->reset();