Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitinvader - Fix saving with automation and division by 0 #5805

Merged
merged 8 commits into from
Nov 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions plugins/bit_invader/bit_invader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

#include "plugin_export.h"

static const int wavetableSize = 200;

extern "C"
{

Expand Down Expand Up @@ -72,8 +74,8 @@ bSynth::bSynth( float * _shape, NotePlayHandle * _nph, bool _interpolation,
sample_rate( _sample_rate ),
interpolation( _interpolation)
{
sample_shape = new float[200];
for (int i=0; i < 200; ++i)
sample_shape = new float[wavetableSize];
for (int i=0; i < wavetableSize; ++i)
{
sample_shape[i] = _shape[i] * _factor;
}
Expand Down Expand Up @@ -138,12 +140,12 @@ sample_t bSynth::nextStringSample( float sample_length )

bitInvader::bitInvader( InstrumentTrack * _instrument_track ) :
Instrument( _instrument_track, &bitinvader_plugin_descriptor ),
m_sampleLength( 128, 4, 200, 1, this, tr( "Sample length" ) ),
m_graph( -1.0f, 1.0f, 200, this ),
m_sampleLength(128, 4, wavetableSize, 1, this, tr("Sample length")),
m_graph(-1.0f, 1.0f, wavetableSize, this),
m_interpolation( false, this ),
m_normalize( false, this )
{

lengthChanged();

m_graph.setWaveToSine();
Expand Down Expand Up @@ -177,8 +179,8 @@ void bitInvader::saveSettings( QDomDocument & _doc, QDomElement & _this )

// Save sample shape base64-encoded
QString sampleString;
base64::encode( (const char *)m_graph.samples(),
m_graph.length() * sizeof(float), sampleString );
base64::encode((const char *)m_graph.samples(),
wavetableSize * sizeof(float), sampleString);
_this.setAttribute( "sampleShape", sampleString );


Expand All @@ -194,6 +196,9 @@ void bitInvader::saveSettings( QDomDocument & _doc, QDomElement & _this )

void bitInvader::loadSettings( const QDomElement & _this )
{
// Clear wavetable before loading a new
zonkmachine marked this conversation as resolved.
Show resolved Hide resolved
m_graph.clear();

// Load sample length
m_sampleLength.loadSettings( _this, "sampleLength" );

Expand All @@ -204,8 +209,9 @@ void bitInvader::loadSettings( const QDomElement & _this )
char * dst = 0;
base64::decode( _this.attribute( "sampleShape"), &dst, &size );

m_graph.setLength( sampleLength );
m_graph.setSamples( (float*) dst );
m_graph.setLength(size / sizeof(float));
m_graph.setSamples(reinterpret_cast<float*>(dst));
m_graph.setLength(sampleLength);
delete[] dst;

// Load LED normalize
Expand Down Expand Up @@ -240,7 +246,7 @@ void bitInvader::samplesChanged( int _begin, int _end )
void bitInvader::normalize()
{
// analyze
float max = 0;
float max = std::numeric_limits<float>::epsilon();
const float* samples = m_graph.samples();
for(int i=0; i < m_graph.length(); i++)
{
Expand Down