From 26df2e709c304a8d663dbea8d795431d61b75fd6 Mon Sep 17 00:00:00 2001 From: saker Date: Thu, 4 Jul 2024 07:24:21 -0400 Subject: [PATCH] Fix errors --- .../AudioFileProcessor/AudioFileProcessor.cpp | 5 +- .../AudioFileProcessor/AudioFileProcessor.h | 3 +- .../AudioFileProcessorWaveView.cpp | 64 +++++++++---------- .../AudioFileProcessorWaveView.h | 20 +++--- plugins/Lb302/Lb302.cpp | 4 +- plugins/MultitapEcho/MultitapEcho.cpp | 7 +- plugins/Vibed/VibratingString.cpp | 3 +- src/core/AudioEngine.cpp | 2 +- src/core/Instrument.cpp | 3 +- src/core/audio/AudioSdl.cpp | 2 +- 10 files changed, 56 insertions(+), 57 deletions(-) diff --git a/plugins/AudioFileProcessor/AudioFileProcessor.cpp b/plugins/AudioFileProcessor/AudioFileProcessor.cpp index 767d15e735f..b10c065b29d 100644 --- a/plugins/AudioFileProcessor/AudioFileProcessor.cpp +++ b/plugins/AudioFileProcessor/AudioFileProcessor.cpp @@ -30,6 +30,7 @@ #include "SampleLoader.h" #include "Song.h" +#include "lmms_basics.h" #include "plugin_export.h" #include @@ -276,7 +277,7 @@ QString AudioFileProcessor::nodeName() const -auto AudioFileProcessor::beatLen(NotePlayHandle* note) const -> int +auto AudioFileProcessor::beatLen(NotePlayHandle* note) const -> f_cnt_t { // If we can play indefinitely, use the default beat note duration if (static_cast(m_loopModel.value()) != Sample::Loop::Off) { return 0; } @@ -292,7 +293,7 @@ auto AudioFileProcessor::beatLen(NotePlayHandle* note) const -> int : m_nextPlayStartPoint; const auto duration = m_sample.endFrame() - startFrame; - return static_cast(std::floor(duration * freqFactor)); + return static_cast(std::floor(duration * freqFactor)); } diff --git a/plugins/AudioFileProcessor/AudioFileProcessor.h b/plugins/AudioFileProcessor/AudioFileProcessor.h index b39342fd1fa..acdbc45f722 100644 --- a/plugins/AudioFileProcessor/AudioFileProcessor.h +++ b/plugins/AudioFileProcessor/AudioFileProcessor.h @@ -32,6 +32,7 @@ #include "Instrument.h" #include "Sample.h" +#include "lmms_basics.h" namespace lmms @@ -54,7 +55,7 @@ class AudioFileProcessor : public Instrument QString nodeName() const override; - auto beatLen(NotePlayHandle* note) const -> int override; + auto beatLen(NotePlayHandle* note) const -> f_cnt_t override; float desiredReleaseTimeMs() const override { diff --git a/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp b/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp index 1742ee3a7cd..6028566c666 100644 --- a/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp +++ b/plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp @@ -44,23 +44,23 @@ void AudioFileProcessorWaveView::updateSampleRange() { if (m_sample->sampleSize() > 1) { - const f_cnt_t marging = (m_sample->endFrame() - m_sample->startFrame()) * 0.1; + const auto marging = (m_sample->endFrame() - m_sample->startFrame()) * 0.1; setFrom(m_sample->startFrame() - marging); setTo(m_sample->endFrame() + marging); } } -void AudioFileProcessorWaveView::setTo(f_cnt_t to) +void AudioFileProcessorWaveView::setTo(int to) { - m_to = std::min(to, static_cast(m_sample->sampleSize())); + m_to = std::min(to, static_cast(m_sample->sampleSize())); } -void AudioFileProcessorWaveView::setFrom(f_cnt_t from) +void AudioFileProcessorWaveView::setFrom(int from) { m_from = std::max(from, 0); } -f_cnt_t AudioFileProcessorWaveView::range() const +int AudioFileProcessorWaveView::range() const { return m_to - m_from; } @@ -196,7 +196,7 @@ void AudioFileProcessorWaveView::paintEvent(QPaintEvent * pe) p.drawPixmap(s_padding, s_padding, m_graph); const QRect graph_rect(s_padding, s_padding, width() - 2 * s_padding, height() - 2 * s_padding); - const f_cnt_t frames = range(); + const auto frames = range(); m_startFrameX = graph_rect.x() + (m_sample->startFrame() - m_from) * double(graph_rect.width()) / frames; m_endFrameX = graph_rect.x() + (m_sample->endFrame() - m_from) * @@ -341,29 +341,30 @@ void AudioFileProcessorWaveView::updateGraph() void AudioFileProcessorWaveView::zoom(const bool out) { - const f_cnt_t start = m_sample->startFrame(); - const f_cnt_t end = m_sample->endFrame(); - const f_cnt_t frames = m_sample->sampleSize(); - const f_cnt_t d_from = start - m_from; - const f_cnt_t d_to = m_to - end; + const auto start = m_sample->startFrame(); + const auto end = m_sample->endFrame(); + const auto frames = m_sample->sampleSize(); + const auto d_from = start - static_cast(m_from); + const auto d_to = static_cast(m_to) - end; - const f_cnt_t step = qMax(1, qMax(d_from, d_to) / 10); - const f_cnt_t step_from = (out ? - step : step); - const f_cnt_t step_to = (out ? step : - step); + const auto step = std::max(1, std::max(d_from, d_to) / 10); + const auto step_from = (out ? - step : step); + const auto step_to = (out ? step : - step); - const double comp_ratio = double(qMin(d_from, d_to)) - / qMax(1, qMax(d_from, d_to)); + const auto compRatio = static_cast(std::min(d_from, d_to)) / std::max(1, std::max(d_from, d_to)); const auto boundedFrom = std::clamp(m_from + step_from, 0, start); - const auto boundedTo = std::clamp(m_to + step_to, end, frames); + const auto boundedTo = std::clamp(m_to + step_to, end, static_cast(frames)); - const auto toStep = static_cast(step_from * (boundedTo == m_to ? 1 : comp_ratio)); - const auto newFrom - = (out && d_from < d_to) || (!out && d_to < d_from) ? boundedFrom : std::clamp(m_from + toStep, 0, start); + const auto toStep = step_from * (boundedTo == m_to ? 1 : compRatio); + const auto newFrom = (out && d_from < d_to) || (!out && d_to < d_from) + ? boundedFrom + : std::clamp(m_from + static_cast(toStep), 0, start); - const auto fromStep = static_cast(step_to * (boundedFrom == m_from ? 1 : comp_ratio)); - const auto newTo - = (out && d_from < d_to) || (!out && d_to < d_from) ? std::clamp(m_to + fromStep, end, frames) : boundedTo; + const auto fromStep = step_to * (boundedFrom == m_from ? 1 : compRatio); + const auto newTo = (out && d_from < d_to) || (!out && d_to < d_from) + ? std::clamp(m_to + static_cast(fromStep), end, static_cast(frames)) + : boundedTo; if (static_cast(newTo - newFrom) / m_sample->sampleRate() > 0.05) { @@ -375,16 +376,11 @@ void AudioFileProcessorWaveView::zoom(const bool out) void AudioFileProcessorWaveView::slide(int px) { const double fact = qAbs(double(px) / width()); - f_cnt_t step = range() * fact; - if (px > 0) - { - step = -step; - } + auto step = range() * fact * (px > 0 ? -1 : 1); - f_cnt_t step_from = qBound(0, m_from + step, m_sample->sampleSize()) - m_from; - f_cnt_t step_to = qBound(m_from + 1, m_to + step, m_sample->sampleSize()) - m_to; - - step = qAbs(step_from) < qAbs(step_to) ? step_from : step_to; + const auto stepFrom = std::clamp(m_from + step, 0, m_sample->sampleSize()) - m_from; + const auto stepTo = std::clamp(m_to + step, m_from + 1, m_sample->sampleSize()) - m_to; + step = std::abs(stepFrom) < std::abs(stepTo) ? stepFrom : stepTo; setFrom(m_from + step); setTo(m_to + step); @@ -465,10 +461,8 @@ void AudioFileProcessorWaveView::reverse() - m_sample->startFrame() ); - const f_cnt_t from = m_from; setFrom(m_sample->sampleSize() - m_to); - setTo(m_sample->sampleSize() - from); - + setTo(m_sample->sampleSize() - m_from); m_reversed = ! m_reversed; } diff --git a/plugins/AudioFileProcessor/AudioFileProcessorWaveView.h b/plugins/AudioFileProcessor/AudioFileProcessorWaveView.h index f40b69d121f..8081d20ca63 100644 --- a/plugins/AudioFileProcessor/AudioFileProcessorWaveView.h +++ b/plugins/AudioFileProcessor/AudioFileProcessorWaveView.h @@ -125,17 +125,17 @@ public slots: Sample const* m_sample; QPixmap m_graph; - f_cnt_t m_from; - f_cnt_t m_to; - f_cnt_t m_last_from; - f_cnt_t m_last_to; + int m_from; + int m_to; + int m_last_from; + int m_last_to; float m_last_amp; knob* m_startKnob; knob* m_endKnob; knob* m_loopKnob; - f_cnt_t m_startFrameX; - f_cnt_t m_endFrameX; - f_cnt_t m_loopFrameX; + int m_startFrameX; + int m_endFrameX; + int m_loopFrameX; bool m_isDragging; QPoint m_draggingLastPoint; DraggingType m_draggingType; @@ -152,9 +152,9 @@ public slots: void updateSampleRange(); private: - void setTo(f_cnt_t to); - void setFrom(f_cnt_t from); - f_cnt_t range() const; + void setTo(int to); + void setFrom(int from); + int range() const; void zoom(const bool out = false); void slide(int px); void slideSamplePointByPx(Point point, int px); diff --git a/plugins/Lb302/Lb302.cpp b/plugins/Lb302/Lb302.cpp index 02038239ae1..0041b0c5127 100644 --- a/plugins/Lb302/Lb302.cpp +++ b/plugins/Lb302/Lb302.cpp @@ -750,8 +750,8 @@ void Lb302Synth::playNote( NotePlayHandle * _n, SampleFrame* _working_buffer ) m_notes.prepend( _n ); } m_notesMutex.unlock(); - - release_frame = qMax( release_frame, _n->framesLeft() + _n->offset() ); + + release_frame = std::max(release_frame, static_cast(_n->framesLeft()) + static_cast(_n->offset())); } diff --git a/plugins/MultitapEcho/MultitapEcho.cpp b/plugins/MultitapEcho/MultitapEcho.cpp index e779f228364..ec5c2412621 100644 --- a/plugins/MultitapEcho/MultitapEcho.cpp +++ b/plugins/MultitapEcho/MultitapEcho.cpp @@ -25,6 +25,7 @@ #include "MultitapEcho.h" #include "embed.h" +#include "lmms_basics.h" #include "plugin_export.h" namespace lmms @@ -118,8 +119,8 @@ bool MultitapEchoEffect::processAudioBuffer( SampleFrame* buf, const fpp_t frame } // add dry buffer - never swap inputs for dry - m_buffer.writeAddingMultiplied( buf, 0, frames, dryGain ); - + m_buffer.writeAddingMultiplied(buf, static_cast(0), frames, dryGain); + // swapped inputs? if( swapInputs ) { @@ -176,4 +177,4 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main( Model* parent, void* data ) } -} // namespace lmms \ No newline at end of file +} // namespace lmms diff --git a/plugins/Vibed/VibratingString.cpp b/plugins/Vibed/VibratingString.cpp index 216a5fbf333..159c0aced32 100644 --- a/plugins/Vibed/VibratingString.cpp +++ b/plugins/Vibed/VibratingString.cpp @@ -26,6 +26,7 @@ #include "interpolation.h" #include "AudioEngine.h" #include "Engine.h" +#include "lmms_basics.h" #include #include @@ -99,7 +100,7 @@ void VibratingString::resample(const float* src, f_cnt_t srcFrames, f_cnt_t dstF { const float srcFrameFloat = frame * static_cast(srcFrames) / dstFrames; const float fracPos = srcFrameFloat - static_cast(srcFrameFloat); - const f_cnt_t srcFrame = std::clamp(static_cast(srcFrameFloat), 1, srcFrames - 3); + const f_cnt_t srcFrame = std::clamp(static_cast(srcFrameFloat), 1, srcFrames - 3); m_impulse[frame] = cubicInterpolate( src[srcFrame - 1], src[srcFrame + 0], diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 8e4cc8e29c7..157b6fe65a7 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -283,7 +283,7 @@ void AudioEngine::pushInputFrames( SampleFrame* _ab, const f_cnt_t _frames ) requestChangeInModel(); f_cnt_t frames = m_inputBufferFrames[ m_inputBufferWrite ]; - int size = m_inputBufferSize[ m_inputBufferWrite ]; + auto size = m_inputBufferSize[m_inputBufferWrite]; SampleFrame* buf = m_inputBuffer[ m_inputBufferWrite ]; if( frames + _frames > size ) diff --git a/src/core/Instrument.cpp b/src/core/Instrument.cpp index 893fccbf502..e35e883d5b2 100644 --- a/src/core/Instrument.cpp +++ b/src/core/Instrument.cpp @@ -28,6 +28,7 @@ #include "DummyInstrument.h" #include "InstrumentTrack.h" +#include "lmms_basics.h" #include "lmms_constants.h" @@ -185,7 +186,7 @@ void Instrument::applyRelease( SampleFrame* buf, const NotePlayHandle * _n ) const auto releaseFrames = desiredReleaseFrames(); const auto endFrame = _n->framesLeft(); - const auto startFrame = std::max(0, endFrame - releaseFrames); + const auto startFrame = std::max(0, static_cast(endFrame) - static_cast(releaseFrames)); for (auto f = startFrame; f < endFrame && f < fpp; f++) { diff --git a/src/core/audio/AudioSdl.cpp b/src/core/audio/AudioSdl.cpp index 2a541404956..8c84d74b71d 100644 --- a/src/core/audio/AudioSdl.cpp +++ b/src/core/audio/AudioSdl.cpp @@ -69,7 +69,7 @@ AudioSdl::AudioSdl( bool & _success_ful, AudioEngine* _audioEngine ) : // to convert the buffers #endif m_audioHandle.channels = channels(); - m_audioHandle.samples = std::max(1024, audioEngine()->framesPerPeriod() * 2); + m_audioHandle.samples = std::max(1024, audioEngine()->framesPerPeriod() * 2); m_audioHandle.callback = sdlAudioCallback; m_audioHandle.userdata = this;