Reduce indirection to sample buffer from Sample

This commit is contained in:
sakertooth
2023-08-27 20:43:00 -04:00
parent 25bb7abbb7
commit aca875b0e4
6 changed files with 39 additions and 13 deletions

View File

@@ -237,6 +237,26 @@ auto Sample::sampleDuration() const -> int
: 0;
}
auto Sample::sampleFile() const -> QString
{
return m_buffer->audioFile();
}
auto Sample::sampleRate() const -> int
{
return m_buffer->sampleRate();
}
auto Sample::sampleSize() const -> int
{
return m_buffer->size();
}
auto Sample::toBase64() const -> QString
{
return m_buffer->toBase64();
}
auto Sample::playbackSize() const -> int
{
const auto lock = std::shared_lock{m_mutex};

View File

@@ -120,7 +120,7 @@ void SampleClip::changeLength( const TimePos & _length )
QString SampleClip::sampleFile() const
{
return m_sample->buffer()->audioFile();
return m_sample->sampleFile();
}
@@ -260,10 +260,10 @@ void SampleClip::saveSettings( QDomDocument & _doc, QDomElement & _this )
if( sampleFile() == "" )
{
QString s;
_this.setAttribute("data", m_sample->buffer()->toBase64());
_this.setAttribute("data", m_sample->toBase64());
}
_this.setAttribute("sample_rate", m_sample->buffer()->sampleRate());
_this.setAttribute("sample_rate", m_sample->sampleRate());
if( usesCustomClipColor() )
{
_this.setAttribute( "color", color().name() );

View File

@@ -144,7 +144,7 @@ bool SamplePlayHandle::isFromTrack( const Track * _track ) const
f_cnt_t SamplePlayHandle::totalFrames() const
{
return (m_sample->endFrame() - m_sample->startFrame()) *
(static_cast<float>(Engine::audioEngine()->processingSampleRate()) / m_sample->buffer()->sampleRate());
(static_cast<float>(Engine::audioEngine()->processingSampleRate()) / m_sample->sampleRate());
}

View File

@@ -60,8 +60,8 @@ void SampleClipView::updateSample()
update();
// set tooltip to filename so that user can see what sample this
// sample-clip contains
setToolTip(m_clip->m_sample->buffer()->audioFile() != "" ?
PathUtil::toAbsolute(m_clip->m_sample->buffer()->audioFile()) :
setToolTip(m_clip->m_sample->sampleFile() != "" ?
PathUtil::toAbsolute(m_clip->m_sample->sampleFile()) :
tr( "Double-click to open sample" ) );
}
@@ -173,9 +173,9 @@ void SampleClipView::mouseDoubleClickEvent( QMouseEvent * )
QString af = gui::SampleLoader::openAudioFile();
if ( af.isEmpty() ) {} //Don't do anything if no file is loaded
else if (af == m_clip->m_sample->buffer()->audioFile())
else if (af == m_clip->m_sample->sampleFile())
{ //Instead of reloading the existing file, just reset the size
int length = static_cast<int>(m_clip->m_sample->buffer()->size() / Engine::framesPerTick());
int length = static_cast<int>(m_clip->m_sample->sampleSize() / Engine::framesPerTick());
m_clip->changeLength(length);
}
else
@@ -264,7 +264,7 @@ void SampleClipView::paintEvent( QPaintEvent * pe )
qMax( static_cast<int>( m_clip->sampleLength() * ppb / ticksPerBar ), 1 ), rect().bottom() - 2 * spacing );
m_clip->m_sample->visualize(p, r);
QString name = PathUtil::cleanName(m_clip->m_sample->buffer()->audioFile());
QString name = PathUtil::cleanName(m_clip->m_sample->sampleFile());
paintTextLabel(name, p);
// disable antialiasing for borders, since its not needed

View File

@@ -108,10 +108,10 @@ bool SampleTrack::play( const TimePos & _start, const fpp_t _frames,
{
if( sClip->isPlaying() == false && _start >= (sClip->startPosition() + sClip->startTimeOffset()) )
{
auto bufferFramesPerTick = Engine::framesPerTick(sClip->sample()->buffer()->sampleRate());
auto bufferFramesPerTick = Engine::framesPerTick(sClip->sample()->sampleRate());
f_cnt_t sampleStart = bufferFramesPerTick * ( _start - sClip->startPosition() - sClip->startTimeOffset() );
f_cnt_t clipFrameLength = bufferFramesPerTick * ( sClip->endPosition() - sClip->startPosition() - sClip->startTimeOffset() );
f_cnt_t sampleBufferLength = sClip->sample()->buffer()->size();
f_cnt_t sampleBufferLength = sClip->sample()->sampleSize();
//if the Clip smaller than the sample length we play only until Clip end
//else we play the sample to the end but nothing more
f_cnt_t samplePlayLength = clipFrameLength > sampleBufferLength ? sampleBufferLength : clipFrameLength;