Skip to content

Commit

Permalink
clang-tidy: Apply modernize-avoid-c-arrays everywhere (LMMS#6564)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominic Clark <[email protected]>
Co-authored-by: Hyunjin Song <[email protected]>
  • Loading branch information
3 people committed May 30, 2023
1 parent 91d1e0a commit 5a15f2b
Show file tree
Hide file tree
Showing 54 changed files with 369 additions and 366 deletions.
8 changes: 0 additions & 8 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ class LMMS_EXPORT DataFile : public QDomDocument

void loadData( const QByteArray & _data, const QString & _sourceFile );


struct LMMS_EXPORT typeDescStruct
{
Type m_type;
QString m_name;
} ;
static typeDescStruct s_types[TypeCount];

QString m_fileName; //!< The origin file name or "" if this DataFile didn't originate from a file
QDomElement m_content;
QDomElement m_head;
Expand Down
3 changes: 2 additions & 1 deletion include/InstrumentFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class InstrumentFunctionNoteStacking : public Model, public JournallingObject

public:
static const int MAX_CHORD_POLYPHONY = 13;
static const int NUM_CHORD_TABLES = 95;

private:
using ChordSemiTones = std::array<int8_t, MAX_CHORD_POLYPHONY>;
Expand Down Expand Up @@ -129,7 +130,7 @@ class InstrumentFunctionNoteStacking : public Model, public JournallingObject
ChordSemiTones m_semiTones;
};

static Init s_initTable[];
static std::array<Init, NUM_CHORD_TABLES> s_initTable;

public:
static const ChordTable & getInstance()
Expand Down
2 changes: 1 addition & 1 deletion include/Oscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class LMMS_EXPORT Oscillator
static fftwf_plan s_fftPlan;
static fftwf_plan s_ifftPlan;
static fftwf_complex * s_specBuf;
static float s_sampleBuffer[OscillatorConstants::WAVETABLE_LENGTH];
static std::array<float, OscillatorConstants::WAVETABLE_LENGTH> s_sampleBuffer;

static void generateSawWaveTable(int bands, sample_t* table, int firstBand = 1);
static void generateTriangleWaveTable(int bands, sample_t* table, int firstBand = 1);
Expand Down
2 changes: 1 addition & 1 deletion include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ protected slots:
static QPixmap * s_toolOpen;
static QPixmap* s_toolKnife;

static PianoRollKeyTypes prKeyOrder[];
static std::array<PianoRollKeyTypes, 12> prKeyOrder;

static TextFloat * s_textFloat;

Expand Down
2 changes: 1 addition & 1 deletion include/ProjectRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class LMMS_EXPORT ProjectRenderer : public QThread

static QString getFileExtensionFromFormat( ExportFileFormats fmt );

static const FileEncodeDevice fileEncodeDevices[];
static const std::array<FileEncodeDevice, 5> fileEncodeDevices;

public slots:
void startProcessing();
Expand Down
16 changes: 8 additions & 8 deletions plugins/Amplifier/Amplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool AmplifierEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
double outSum = 0.0;
const float d = dryLevel();
const float w = wetLevel();

const ValueBuffer * volBuf = m_ampControls.m_volumeModel.valueBuffer();
const ValueBuffer * panBuf = m_ampControls.m_panModel.valueBuffer();
const ValueBuffer * leftBuf = m_ampControls.m_leftModel.valueBuffer();
Expand All @@ -83,8 +83,8 @@ bool AmplifierEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
for( fpp_t f = 0; f < frames; ++f )
{
// qDebug( "offset %d, value %f", f, m_ampControls.m_volumeModel.value( f ) );
sample_t s[2] = { buf[f][0], buf[f][1] };

auto s = std::array{buf[f][0], buf[f][1]};

// vol knob
if( volBuf )
Expand All @@ -99,8 +99,8 @@ bool AmplifierEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
}

// convert pan values to left/right values
const float pan = panBuf
? panBuf->value( f )
const float pan = panBuf
? panBuf->value( f )
: m_ampControls.m_panModel.value();
const float left1 = pan <= 0
? 1.0
Expand All @@ -111,12 +111,12 @@ bool AmplifierEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )

// second stage amplification
const float left2 = leftBuf
? leftBuf->value( f )
? leftBuf->value( f )
: m_ampControls.m_leftModel.value();
const float right2 = rightBuf
? rightBuf->value( f )
? rightBuf->value( f )
: m_ampControls.m_rightModel.value();

s[0] *= left1 * left2 * 0.01;
s[1] *= right1 * right2 * 0.01;

Expand Down
2 changes: 1 addition & 1 deletion plugins/BassBooster/BassBooster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool BassBoosterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames
m_bbFX.leftFX().setGain( gain );
m_bbFX.rightFX().setGain( gain);

sample_t s[2] = { buf[f][0], buf[f][1] };
auto s = std::array{buf[f][0], buf[f][1]};
m_bbFX.nextSample( s[0], s[1] );

buf[f][0] = d * buf[f][0] + w * s[0];
Expand Down
40 changes: 20 additions & 20 deletions plugins/Bitcrush/Bitcrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const int OS_RATE = 5;
const float OS_RATIO = 1.0f / OS_RATE;
const float CUTOFF_RATIO = 0.353553391f;
const int SILENCEFRAMES = 10;
const float OS_RESAMPLE [5] = { 0.0001490062883964112, 0.1645978376763992, 0.6705063120704088,
0.1645978376763992, 0.0001490062883964112 };
const auto OS_RESAMPLE = std::array{0.0001490062883964112f, 0.1645978376763992f, 0.6705063120704088f,
0.1645978376763992f, 0.0001490062883964112f };

extern "C"
{
Expand Down Expand Up @@ -65,13 +65,13 @@ BitcrushEffect::BitcrushEffect( Model * parent, const Descriptor::SubPluginFeatu
m_buffer = MM_ALLOC<sampleFrame>( Engine::audioEngine()->framesPerPeriod() * OS_RATE );
m_filter.setLowpass( m_sampleRate * ( CUTOFF_RATIO * OS_RATIO ) );
m_needsUpdate = true;

m_bitCounterL = 0.0f;
m_bitCounterR = 0.0f;

m_left = 0.0f;
m_right = 0.0f;

m_silenceCounter = 0;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )

m_rateCoeffL = ( m_sampleRate * OS_RATE ) / ( rate - diff );
m_rateCoeffR = ( m_sampleRate * OS_RATE ) / ( rate + diff );

m_bitCounterL = 0.0f;
m_bitCounterR = 0.0f;
}
Expand All @@ -147,9 +147,9 @@ bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
m_outClip = dbfsToAmp( m_controls.m_outClip.value() );
}
m_needsUpdate = false;

const float noiseAmt = m_controls.m_inNoise.value() * 0.01f;

// read input buffer and write it to oversampled buffer
if( m_rateEnabled ) // rate crushing enabled so do that
{
Expand All @@ -164,15 +164,15 @@ bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
if( m_bitCounterL > m_rateCoeffL )
{
m_bitCounterL -= m_rateCoeffL;
m_left = m_depthEnabled
? depthCrush( buf[f][0] * m_inGain + noise( buf[f][0] * noiseAmt ) )
m_left = m_depthEnabled
? depthCrush( buf[f][0] * m_inGain + noise( buf[f][0] * noiseAmt ) )
: buf[f][0] * m_inGain + noise( buf[f][0] * noiseAmt );
}
if( m_bitCounterR > m_rateCoeffR )
{
m_bitCounterR -= m_rateCoeffR;
m_right = m_depthEnabled
? depthCrush( buf[f][1] * m_inGain + noise( buf[f][1] * noiseAmt ) )
m_right = m_depthEnabled
? depthCrush( buf[f][1] * m_inGain + noise( buf[f][1] * noiseAmt ) )
: buf[f][1] * m_inGain + noise( buf[f][1] * noiseAmt );
}
}
Expand All @@ -185,17 +185,17 @@ bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
for( int o = 0; o < OS_RATE; ++o )
{
m_buffer[f * OS_RATE + o][0] = m_depthEnabled
? depthCrush( buf[f][0] * m_inGain + noise( buf[f][0] * noiseAmt ) )
? depthCrush( buf[f][0] * m_inGain + noise( buf[f][0] * noiseAmt ) )
: buf[f][0] * m_inGain + noise( buf[f][0] * noiseAmt );
m_buffer[f * OS_RATE + o][1] = m_depthEnabled
? depthCrush( buf[f][1] * m_inGain + noise( buf[f][1] * noiseAmt ) )
? depthCrush( buf[f][1] * m_inGain + noise( buf[f][1] * noiseAmt ) )
: buf[f][1] * m_inGain + noise( buf[f][1] * noiseAmt );
}
}
}

// the oversampled buffer is now written, so filter it to reduce aliasing

for( int f = 0; f < frames * OS_RATE; ++f )
{
if( qMax( qAbs( m_buffer[f][0] ), qAbs( m_buffer[f][1] ) ) >= 1.0e-10f )
Expand All @@ -218,10 +218,10 @@ bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
}
}
}


// now downsample and write it back to main buffer

double outSum = 0.0;
const float d = dryLevel();
const float w = wetLevel();
Expand All @@ -238,7 +238,7 @@ bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
buf[f][1] = d * buf[f][1] + w * qBound( -m_outClip, rsum, m_outClip ) * m_outGain;
outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];
}

checkGate( outSum / frames );

return isRunning();
Expand Down
12 changes: 6 additions & 6 deletions plugins/Compressor/Compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ bool CompressorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frames)
float rOutPeak = 0.0;
float lInPeak = 0.0;
float rInPeak = 0.0;

const bool midside = m_compressorControls.m_midsideModel.value();
const bool peakmode = m_compressorControls.m_peakmodeModel.value();
const float inBalance = m_compressorControls.m_inBalanceModel.value();
Expand All @@ -292,8 +292,8 @@ bool CompressorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frames)

for(fpp_t f = 0; f < frames; ++f)
{
sample_t drySignal[2] = {buf[f][0], buf[f][1]};
sample_t s[2] = {drySignal[0] * m_inGainVal, drySignal[1] * m_inGainVal};
auto drySignal = std::array{buf[f][0], buf[f][1]};
auto s = std::array{drySignal[0] * m_inGainVal, drySignal[1] * m_inGainVal};

// Calculate tilt filters, to bias the sidechain to the low or high frequencies
if (m_tiltVal)
Expand Down Expand Up @@ -512,7 +512,7 @@ bool CompressorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frames)
m_inputBufLoc = 0;
}

const float temp[2] = {drySignal[0], drySignal[1]};
const auto temp = std::array{drySignal[0], drySignal[1]};
s[0] = m_inputBuf[0][m_inputBufLoc];
s[1] = m_inputBuf[1][m_inputBufLoc];

Expand All @@ -525,8 +525,8 @@ bool CompressorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frames)
s[1] = drySignal[1];
}

float delayedDrySignal[2] = {s[0], s[1]};
auto delayedDrySignal = std::array{s[0], s[1]};

if (midside)// Convert left/right to mid/side
{
const float temp = s[0];
Expand Down
10 changes: 5 additions & 5 deletions plugins/Compressor/CompressorControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ CompressorControlDialog::CompressorControlDialog(CompressorControls* controls) :
peakButton->setActiveGraphic(PLUGIN_NAME::getIconPixmap("peak_sel"));
peakButton->setInactiveGraphic(PLUGIN_NAME::getIconPixmap("peak_unsel"));
peakButton->setToolTip(tr("Use absolute value of the input"));

rmsPeakGroup = new automatableButtonGroup(this);
rmsPeakGroup->addButton(rmsButton);
rmsPeakGroup->addButton(peakButton);
Expand All @@ -221,7 +221,7 @@ CompressorControlDialog::CompressorControlDialog(CompressorControls* controls) :
midSideButton->setActiveGraphic(PLUGIN_NAME::getIconPixmap("midside_sel"));
midSideButton->setInactiveGraphic(PLUGIN_NAME::getIconPixmap("midside_unsel"));
midSideButton->setToolTip(tr("Compress mid and side audio"));

leftRightMidSideGroup = new automatableButtonGroup(this);
leftRightMidSideGroup->addButton(leftRightButton);
leftRightMidSideGroup->addButton(midSideButton);
Expand Down Expand Up @@ -514,8 +514,8 @@ void CompressorControlDialog::redrawKnee()
{
m_p.setPen(QPen(m_kneeColor2, 3));

float prevPoint[2] = {kneePoint1, kneePoint1};
float newPoint[2] = {0, 0};
auto prevPoint = std::array{kneePoint1, kneePoint1};
auto newPoint = std::array{0.f, 0.f};

// Draw knee curve using many straight lines.
for (int i = 0; i < COMP_KNEE_LINES; ++i)
Expand All @@ -542,7 +542,7 @@ void CompressorControlDialog::redrawKnee()
m_p.end();

m_p.begin(&m_kneePixmap2);

m_p.setCompositionMode(QPainter::CompositionMode_Source);
m_p.fillRect(0, 0, m_windowSizeX, m_kneeWindowSizeY, QColor("transparent"));
m_p.setCompositionMode(QPainter::CompositionMode_SourceOver);
Expand Down
2 changes: 1 addition & 1 deletion plugins/Delay/DelayEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
const float sr = Engine::audioEngine()->processingSampleRate();
const float d = dryLevel();
const float w = wetLevel();
sample_t dryS[2];
auto dryS = std::array<sample_t, 2>{};
float lPeak = 0.0;
float rPeak = 0.0;
float length = m_delayControls.m_delayTimeModel.value();
Expand Down
10 changes: 5 additions & 5 deletions plugins/DualFilter/DualFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames
const bool enabled1 = m_dfControls.m_enabled1Model.value();
const bool enabled2 = m_dfControls.m_enabled2Model.value();




// buffer processing loop
for( fpp_t f = 0; f < frames; ++f )
Expand All @@ -145,9 +145,9 @@ bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames
const float mix1 = 1.0f - mix2;
const float gain1 = *gain1Ptr * 0.01f;
const float gain2 = *gain2Ptr * 0.01f;
sample_t s[2] = { 0.0f, 0.0f }; // mix
sample_t s1[2] = { buf[f][0], buf[f][1] }; // filter 1
sample_t s2[2] = { buf[f][0], buf[f][1] }; // filter 2
auto s = std::array{0.0f, 0.0f}; // mix
auto s1 = std::array{buf[f][0], buf[f][1]}; // filter 1
auto s2 = std::array{buf[f][0], buf[f][1]}; // filter 2

// update filter 1
if( enabled1 )
Expand Down
10 changes: 5 additions & 5 deletions plugins/DynamicsProcessor/DynamicsProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ bool DynProcEffect::processAudioBuffer( sampleFrame * _buf,
// variables for effect
int i = 0;

float sm_peak[2] = { 0.0f, 0.0f };
auto sm_peak = std::array{0.0f, 0.0f};
float gain;

double out_sum = 0.0;
const float d = dryLevel();
const float w = wetLevel();

const int stereoMode = m_dpControls.m_stereomodeModel.value();
const float inputGain = m_dpControls.m_inputModel.value();
const float outputGain = m_dpControls.m_outputModel.value();

const float * samples = m_dpControls.m_wavegraphModel.samples();

// debug code
Expand Down Expand Up @@ -143,7 +143,7 @@ bool DynProcEffect::processAudioBuffer( sampleFrame * _buf,

for( fpp_t f = 0; f < _frames; ++f )
{
double s[2] = { _buf[f][0], _buf[f][1] };
auto s = std::array{_buf[f][0], _buf[f][1]};

// apply input gain
s[0] *= inputGain;
Expand Down Expand Up @@ -211,7 +211,7 @@ bool DynProcEffect::processAudioBuffer( sampleFrame * _buf,
gain = samples[199];
};

s[i] *= gain;
s[i] *= gain;
s[i] /= sm_peak[i];
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/DynamicsProcessor/DynamicsProcessorControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void DynProcControls::saveSettings( QDomDocument & _doc,

void DynProcControls::setDefaultShape()
{
float shp [200] = { };
auto shp = std::array<float, 200>{};
for ( int i = 0; i<200; i++)
{
shp[i] = ((float)i + 1.0f) / 200.0f;
Expand Down
2 changes: 1 addition & 1 deletion plugins/Eq/EqEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool EqEffect::processAudioBuffer( sampleFrame *buf, const fpp_t frames )
//wet/dry controls
const float dry = dryLevel();
const float wet = wetLevel();
sample_t dryS[2];
auto dryS = std::array<sample_t, 2>{};
// setup sample exact controls
float hpRes = m_eqControls.m_hpResModel.value();
float lowShelfRes = m_eqControls.m_lowShelfResModel.value();
Expand Down
Loading

0 comments on commit 5a15f2b

Please sign in to comment.