From 4b77bd59ee982aa70168c1ab414868cbcd8e24ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 7 Nov 2024 10:41:04 +0100 Subject: [PATCH] remove lamda --- .../backends/builtin/metronomeeffect.cpp | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/src/effects/backends/builtin/metronomeeffect.cpp b/src/effects/backends/builtin/metronomeeffect.cpp index 79e959b2cf6..21c318c53e7 100644 --- a/src/effects/backends/builtin/metronomeeffect.cpp +++ b/src/effects/backends/builtin/metronomeeffect.cpp @@ -135,41 +135,34 @@ void MetronomeEffect::processChannel( } gs->framesSinceLastClick += engineParameters.framesPerBuffer(); - std::span outputBufferOffset = [&] { - if (shouldSync && hasBeatInfo) { - double beatFractionBufferEnd = *groupFeatures.beat_fraction_buffer_end; - std::optional beatLengthAndScratch = groupFeatures.beat_length; - if (!beatLengthAndScratch.has_value() || beatLengthAndScratch->scratch_rate == 0.0) { - return std::span(); - } - double beatLength = beatLengthAndScratch->frames / beatLengthAndScratch->scratch_rate; - - const bool needsPreviousBeat = beatLength < 0; - double beatToBufferEndFrames = std::abs(beatLength) * - (needsPreviousBeat ? (1 - beatFractionBufferEnd) - : beatFractionBufferEnd); - std::size_t beatToBufferEndSamples = - static_cast(beatToBufferEndFrames) * - mixxx::kEngineChannelOutputCount; - - if (beatToBufferEndSamples <= output.size()) { - return output.last(beatToBufferEndSamples); - } - return std::span(); - } else { - // EngineParameters::sampleRate in reality returns the framerate. - mixxx::audio::SampleRate framesPerSecond = engineParameters.sampleRate(); - std::size_t offset = (gs->framesSinceLastClick % - framesPerBeat(framesPerSecond, m_pBpmParameter->value())) * - mixxx::kEngineChannelOutputCount; - if (offset < output.size()) { - return output.subspan(offset); - } - return std::span(); + if (shouldSync && hasBeatInfo) { + double beatFractionBufferEnd = *groupFeatures.beat_fraction_buffer_end; + std::optional beatLengthAndScratch = groupFeatures.beat_length; + if (!beatLengthAndScratch.has_value() || beatLengthAndScratch->scratch_rate == 0.0) { + return; } - }(); - - if (!outputBufferOffset.empty()) { - gs->framesSinceLastClick = playMonoSamplesWithGain(click, outputBufferOffset, gain); + double beatLength = beatLengthAndScratch->frames / beatLengthAndScratch->scratch_rate; + const bool needsPreviousBeat = beatLength < 0; + double beatToBufferEndFrames = std::abs(beatLength) * + (needsPreviousBeat ? (1 - beatFractionBufferEnd) + : beatFractionBufferEnd); + std::size_t beatToBufferEndSamples = + static_cast(beatToBufferEndFrames) * + mixxx::kEngineChannelOutputCount; + + if (beatToBufferEndSamples <= output.size()) { + gs->framesSinceLastClick = playMonoSamplesWithGain(click, output.last(beatToBufferEndSamples), gain); + } + } else { + // EngineParameters::sampleRate in reality returns the framerate. + mixxx::audio::SampleRate framesPerSecond = engineParameters.sampleRate(); + std::size_t offset = (gs->framesSinceLastClick % + framesPerBeat(framesPerSecond, m_pBpmParameter->value())) * + mixxx::kEngineChannelOutputCount; + if (offset < output.size()) { + gs->framesSinceLastClick = playMonoSamplesWithGain(click, output.subspan(offset), gain); + } } } + +