ValueBuffer related cleanups

* Move implementation to a new cpp file
* Use std::vector as base class instead of doing our own memory management
* Remove unused dangerous functions
* Make more use of std algorithms
* Some cleanups in code using ValueBuffer
This commit is contained in:
Lukas W
2017-03-08 17:08:51 +01:00
parent 1b6a9f4885
commit 85ed63be85
12 changed files with 89 additions and 176 deletions

View File

@@ -63,6 +63,7 @@ set(LMMS_SRCS
core/ToolPlugin.cpp
core/Track.cpp
core/TrackContainer.cpp
core/ValueBuffer.cpp
core/VstSyncController.cpp
core/audio/AudioAlsa.cpp

View File

@@ -136,11 +136,7 @@ ValueBuffer * Controller::valueBuffer()
void Controller::updateValueBuffer()
{
float * values = m_valueBuffer.values();
for( int i = 0; i < m_valueBuffer.length(); i++ )
{
values[i] = 0.5f;
}
m_valueBuffer.fill(0.5f);
m_bufferLastUpdated = s_periods;
}

View File

@@ -86,7 +86,6 @@ LfoController::~LfoController()
void LfoController::updateValueBuffer()
{
m_phaseOffset = m_phaseModel.value() / 360.0;
float * values = m_valueBuffer.values();
float phase = m_currentPhase + m_phaseOffset;
// roll phase up until we're in sync with period counter
@@ -103,13 +102,13 @@ void LfoController::updateValueBuffer()
int amountInc = amountBuffer ? 1 : 0;
float *amountPtr = amountBuffer ? &(amountBuffer->values()[ 0 ] ) : &amount;
for( int i = 0; i < m_valueBuffer.length(); i++ )
for( float& f : m_valueBuffer )
{
const float currentSample = m_sampleFunction != NULL
? m_sampleFunction( phase )
: m_userDefSampleBuffer->userWaveSample( phase );
values[i] = qBound( 0.0f, m_baseModel.value() + ( *amountPtr * currentSample / 2.0f ), 1.0f );
f = qBound( 0.0f, m_baseModel.value() + ( *amountPtr * currentSample / 2.0f ), 1.0f );
phase += 1.0 / m_duration;
amountPtr += amountInc;

41
src/core/ValueBuffer.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "ValueBuffer.h"
ValueBuffer::ValueBuffer()
{}
ValueBuffer::ValueBuffer(int length)
: std::vector<float>(length)
{}
void ValueBuffer::fill(float value)
{
std::fill(begin(), end(), value);
}
float ValueBuffer::value(int offset) const
{
return at(offset % length());
}
const float *ValueBuffer::values() const
{
return data();
}
float *ValueBuffer::values()
{
return data();
}
int ValueBuffer::length() const
{
return size();
}
void ValueBuffer::interpolate(float start, float end_)
{
float i = 0;
std::generate(begin(), end(), [&]() {
return linearInterpolate( start, end_, i++ / length());
});
}

View File

@@ -38,6 +38,8 @@
#include "TextFloat.h"
#include "ToolTip.h"
#include "Engine.h"
QPixmap * AutomationPatternView::s_pat_rec = NULL;

View File

@@ -24,6 +24,8 @@
#include "Editor.h"
#include "Song.h"
#include "MainWindow.h"
#include "embed.h"

View File

@@ -64,7 +64,6 @@
#include "Pattern.h"
#include "Piano.h"
#include "PixmapButton.h"
#include "Song.h"
#include "SongEditor.h"
#include "templates.h"
#include "TextFloat.h"