Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sakertooth committed Jul 4, 2024
1 parent 1374831 commit 26df2e7
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 57 deletions.
5 changes: 3 additions & 2 deletions plugins/AudioFileProcessor/AudioFileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "SampleLoader.h"
#include "Song.h"

#include "lmms_basics.h"
#include "plugin_export.h"

#include <QDomElement>
Expand Down Expand Up @@ -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<Sample::Loop>(m_loopModel.value()) != Sample::Loop::Off) { return 0; }
Expand All @@ -292,7 +293,7 @@ auto AudioFileProcessor::beatLen(NotePlayHandle* note) const -> int
: m_nextPlayStartPoint;
const auto duration = m_sample.endFrame() - startFrame;

return static_cast<int>(std::floor(duration * freqFactor));
return static_cast<f_cnt_t>(std::floor(duration * freqFactor));
}


Expand Down
3 changes: 2 additions & 1 deletion plugins/AudioFileProcessor/AudioFileProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "Instrument.h"
#include "Sample.h"
#include "lmms_basics.h"


namespace lmms
Expand All @@ -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
{
Expand Down
64 changes: 29 additions & 35 deletions plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<lmms::f_cnt_t>(m_sample->sampleSize()));
m_to = std::min(to, static_cast<int>(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;
}
Expand Down Expand Up @@ -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) *
Expand Down Expand Up @@ -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<int>(m_from);
const auto d_to = static_cast<int>(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<double>(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<int>(frames));

const auto toStep = static_cast<f_cnt_t>(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<int>(toStep), 0, start);

const auto fromStep = static_cast<f_cnt_t>(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<int>(fromStep), end, static_cast<int>(frames))
: boundedTo;

if (static_cast<double>(newTo - newFrom) / m_sample->sampleRate() > 0.05)
{
Expand All @@ -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<size_t>(0, m_from + step, m_sample->sampleSize()) - m_from;
f_cnt_t step_to = qBound<size_t>(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<int>(m_from + step, 0, m_sample->sampleSize()) - m_from;
const auto stepTo = std::clamp<int>(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);
Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 10 additions & 10 deletions plugins/AudioFileProcessor/AudioFileProcessorWaveView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions plugins/Lb302/Lb302.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(_n->framesLeft()) + static_cast<int>(_n->offset()));
}


Expand Down
7 changes: 4 additions & 3 deletions plugins/MultitapEcho/MultitapEcho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "MultitapEcho.h"
#include "embed.h"
#include "lmms_basics.h"
#include "plugin_export.h"

namespace lmms
Expand Down Expand Up @@ -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<f_cnt_t>(0), frames, dryGain);

// swapped inputs?
if( swapInputs )
{
Expand Down Expand Up @@ -176,4 +177,4 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main( Model* parent, void* data )
}


} // namespace lmms
} // namespace lmms
3 changes: 2 additions & 1 deletion plugins/Vibed/VibratingString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "interpolation.h"
#include "AudioEngine.h"
#include "Engine.h"
#include "lmms_basics.h"

#include <algorithm>
#include <cstdlib>
Expand Down Expand Up @@ -99,7 +100,7 @@ void VibratingString::resample(const float* src, f_cnt_t srcFrames, f_cnt_t dstF
{
const float srcFrameFloat = frame * static_cast<float>(srcFrames) / dstFrames;
const float fracPos = srcFrameFloat - static_cast<f_cnt_t>(srcFrameFloat);
const f_cnt_t srcFrame = std::clamp(static_cast<f_cnt_t>(srcFrameFloat), 1, srcFrames - 3);
const f_cnt_t srcFrame = std::clamp<f_cnt_t>(static_cast<f_cnt_t>(srcFrameFloat), 1, srcFrames - 3);
m_impulse[frame] = cubicInterpolate(
src[srcFrame - 1],
src[srcFrame + 0],
Expand Down
2 changes: 1 addition & 1 deletion src/core/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/core/Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "DummyInstrument.h"
#include "InstrumentTrack.h"
#include "lmms_basics.h"
#include "lmms_constants.h"


Expand Down Expand Up @@ -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<int>(endFrame) - static_cast<int>(releaseFrames));

for (auto f = startFrame; f < endFrame && f < fpp; f++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/audio/AudioSdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<f_cnt_t>(1024, audioEngine()->framesPerPeriod() * 2);

m_audioHandle.callback = sdlAudioCallback;
m_audioHandle.userdata = this;
Expand Down

0 comments on commit 26df2e7

Please sign in to comment.