Pass in unique_ptr to SampleClip::setSampleBuffer
This commit is contained in:
@@ -77,9 +77,9 @@ public:
|
||||
|
||||
bool isPlaying() const;
|
||||
void setIsPlaying(bool isPlaying);
|
||||
void setSampleBuffer(std::unique_ptr<SampleBuffer>&& sb);
|
||||
|
||||
public slots:
|
||||
void setSampleBuffer( lmms::SampleBuffer* sb );
|
||||
void setSampleFile( const QString & sf );
|
||||
void updateLength();
|
||||
void toggleRecord();
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <memory>
|
||||
|
||||
#include "PlayHandle.h"
|
||||
#include "TimePos.h"
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
bool isFromTrack( const Track * _track ) const override;
|
||||
|
||||
f_cnt_t framesRecorded() const;
|
||||
void createSampleBuffer(SampleBuffer** _sample_buf);
|
||||
std::unique_ptr<SampleBuffer> createSampleBuffer();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -123,12 +123,10 @@ QString SampleClip::sampleFile() const
|
||||
return m_sample->sampleFile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SampleClip::setSampleBuffer( SampleBuffer* sb )
|
||||
void SampleClip::setSampleBuffer(std::unique_ptr<SampleBuffer>&& sb)
|
||||
{
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
auto buffer = std::shared_ptr<const SampleBuffer>(sb);
|
||||
auto buffer = std::shared_ptr<const SampleBuffer>(std::move(sb));
|
||||
std::atomic_store(&m_sample, std::make_shared<Sample>(buffer));
|
||||
updateLength();
|
||||
|
||||
|
||||
@@ -51,13 +51,8 @@ SampleRecordHandle::SampleRecordHandle( SampleClip* clip ) :
|
||||
|
||||
SampleRecordHandle::~SampleRecordHandle()
|
||||
{
|
||||
if( !m_buffers.empty() )
|
||||
{
|
||||
SampleBuffer* sb;
|
||||
createSampleBuffer( &sb );
|
||||
m_clip->setSampleBuffer(sb);
|
||||
}
|
||||
|
||||
if (!m_buffers.empty()) { m_clip->setSampleBuffer(createSampleBuffer()); }
|
||||
|
||||
while( !m_buffers.empty() )
|
||||
{
|
||||
delete[] m_buffers.front().first;
|
||||
@@ -111,7 +106,7 @@ f_cnt_t SampleRecordHandle::framesRecorded() const
|
||||
|
||||
|
||||
|
||||
void SampleRecordHandle::createSampleBuffer(SampleBuffer** sampleBuf)
|
||||
std::unique_ptr<SampleBuffer> SampleRecordHandle::createSampleBuffer()
|
||||
{
|
||||
const f_cnt_t frames = framesRecorded();
|
||||
// create buffer to store all recorded buffers in
|
||||
@@ -130,8 +125,9 @@ void SampleRecordHandle::createSampleBuffer(SampleBuffer** sampleBuf)
|
||||
data_ptr += ( *it ).second;
|
||||
}
|
||||
// create according sample-buffer out of big buffer
|
||||
*sampleBuf = new SampleBuffer(data, frames, Engine::audioEngine()->inputSampleRate());
|
||||
auto sampleBuf = std::make_unique<SampleBuffer>(data, frames, Engine::audioEngine()->inputSampleRate());
|
||||
delete[] data;
|
||||
return sampleBuf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user