mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-09 23:35:33 -04:00
Use remaining sample duration for AFP beat length (#6872)
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
|
||||
#include "AudioFileProcessor.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include <QDropEvent>
|
||||
@@ -289,19 +291,28 @@ QString AudioFileProcessor::nodeName() const
|
||||
|
||||
|
||||
|
||||
int AudioFileProcessor::getBeatLen( NotePlayHandle * _n ) const
|
||||
auto AudioFileProcessor::beatLen(NotePlayHandle* note) const -> int
|
||||
{
|
||||
// If we can play indefinitely, use the default beat note duration
|
||||
if (static_cast<SampleBuffer::LoopMode>(m_loopModel.value()) != SampleBuffer::LoopMode::Off) { return 0; }
|
||||
|
||||
// Otherwise, use the remaining sample duration
|
||||
const auto baseFreq = instrumentTrack()->baseFreq();
|
||||
const float freq_factor = baseFreq / _n->frequency() *
|
||||
Engine::audioEngine()->processingSampleRate() / Engine::audioEngine()->baseSampleRate();
|
||||
const auto freqFactor = baseFreq / note->frequency()
|
||||
* Engine::audioEngine()->processingSampleRate()
|
||||
/ Engine::audioEngine()->baseSampleRate();
|
||||
|
||||
return static_cast<int>( floorf( ( m_sampleBuffer.endFrame() - m_sampleBuffer.startFrame() ) * freq_factor ) );
|
||||
const auto startFrame = m_nextPlayStartPoint >= m_sampleBuffer.endFrame()
|
||||
? m_sampleBuffer.startFrame()
|
||||
: m_nextPlayStartPoint;
|
||||
const auto duration = m_sampleBuffer.endFrame() - startFrame;
|
||||
|
||||
return static_cast<int>(std::floor(duration * freqFactor));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
gui::PluginView* AudioFileProcessor::instantiateView( QWidget * _parent )
|
||||
{
|
||||
return new gui::AudioFileProcessorView( this, _parent );
|
||||
|
||||
Reference in New Issue
Block a user