81 changes: 39 additions & 42 deletions mythplugins/mythmusic/mythmusic/smartplaylist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct SmartPLField
int m_defaultValue;
};

static SmartPLField SmartPLFields[] =
{
static const std::array<const SmartPLField,13> SmartPLFields
{{
{ "", "", ftString, 0, 0, 0 },
{ "Artist", "music_artists.artist_name", ftString, 0, 0, 0 },
{ "Album", "music_albums.album_name", ftString, 0, 0, 0 },
Expand All @@ -57,7 +57,7 @@ static SmartPLField SmartPLFields[] =
ftDate, 0, 0, 0 },
{ "Date Imported", "FROM_DAYS(TO_DAYS(music_songs.date_entered))",
ftDate, 0, 0, 0 },
};
}};

struct SmartPLOperator
{
Expand All @@ -67,8 +67,8 @@ struct SmartPLOperator
bool m_validForBoolean;
};

static SmartPLOperator SmartPLOperators[] =
{
static const std::array<const SmartPLOperator,11> SmartPLOperators
{{
{ "is equal to", 1, false, true },
{ "is not equal to", 1, false, true },
{ "is greater than", 1, false, false },
Expand All @@ -80,27 +80,24 @@ static SmartPLOperator SmartPLOperators[] =
{ "is between", 2, false, false },
{ "is set", 0, false, false },
{ "is not set", 0, false, false },
};

static int SmartPLOperatorsCount = sizeof(SmartPLOperators) / sizeof(SmartPLOperators[0]);
static int SmartPLFieldsCount = sizeof(SmartPLFields) / sizeof(SmartPLFields[0]);
}};

static SmartPLOperator *lookupOperator(const QString& name)
static const SmartPLOperator *lookupOperator(const QString& name)
{
for (int x = 0; x < SmartPLOperatorsCount; x++)
for (const auto & oper : SmartPLOperators)
{
if (SmartPLOperators[x].m_name == name)
return &SmartPLOperators[x];
if (oper.m_name == name)
return &oper;
}
return nullptr;
}

static SmartPLField *lookupField(const QString& name)
static const SmartPLField *lookupField(const QString& name)
{
for (int x = 0; x < SmartPLFieldsCount; x++)
for (const auto & field : SmartPLFields)
{
if (SmartPLFields[x].m_name == name)
return &SmartPLFields[x];
if (field.m_name == name)
return &field;
}
return nullptr;
}
Expand Down Expand Up @@ -154,15 +151,15 @@ QString getCriteriaSQL(const QString& fieldName, const QString &operatorName,
if (fieldName.isEmpty())
return result;

SmartPLField *Field = lookupField(fieldName);
const SmartPLField *Field = lookupField(fieldName);
if (!Field)
{
return "";
}

result = Field->m_sqlName;

SmartPLOperator *Operator = lookupOperator(operatorName);
const SmartPLOperator *Operator = lookupOperator(operatorName);
if (!Operator)
{
return QString();
Expand Down Expand Up @@ -251,7 +248,7 @@ QString getOrderBySQL(const QString& orderByFields)
for (int x = 0; x < list.count(); x++)
{
fieldName = list[x].trimmed();
SmartPLField *Field = lookupField(fieldName.left(fieldName.length() - 4));
const SmartPLField *Field = lookupField(fieldName.left(fieldName.length() - 4));
if (Field)
{
if (fieldName.right(3) == "(D)")
Expand All @@ -274,7 +271,7 @@ QString getOrderBySQL(const QString& orderByFields)

QString getSQLFieldName(const QString &fieldName)
{
SmartPLField *Field = lookupField(fieldName);
const SmartPLField *Field = lookupField(fieldName);
if (!Field)
{
return "";
Expand Down Expand Up @@ -328,7 +325,7 @@ bool SmartPLCriteriaRow::saveToDatabase(int smartPlaylistID) const

QString SmartPLCriteriaRow::toString(void) const
{
SmartPLOperator *PLOperator = lookupOperator(m_operator);
const SmartPLOperator *PLOperator = lookupOperator(m_operator);
if (PLOperator)
{
QString result;
Expand Down Expand Up @@ -397,12 +394,12 @@ bool SmartPlaylistEditor::Create(void)
new MythUIButtonListItem(m_matchSelector, tr("Any"));
connect(m_matchSelector, SIGNAL(itemSelected(MythUIButtonListItem*)), SLOT(updateMatches()));

for (int x = 0; x < SmartPLFieldsCount; x++)
for (const auto & field : SmartPLFields)
{
if (SmartPLFields[x].m_name == "")
new MythUIButtonListItem(m_orderBySelector, SmartPLFields[x].m_name);
if (field.m_name == "")
new MythUIButtonListItem(m_orderBySelector, field.m_name);
else
new MythUIButtonListItem(m_orderBySelector, SmartPLFields[x].m_name + " (A)");
new MythUIButtonListItem(m_orderBySelector, field.m_name + " (A)");
}

m_limitSpin->SetRange(0, 9999, 10);
Expand Down Expand Up @@ -1257,16 +1254,16 @@ bool CriteriaRowEditor::Create(void)

void CriteriaRowEditor::updateFields(void)
{
for (int x = 0; x < SmartPLFieldsCount; x++)
new MythUIButtonListItem(m_fieldSelector, SmartPLFields[x].m_name);
for (const auto & field : SmartPLFields)
new MythUIButtonListItem(m_fieldSelector, field.m_name);

m_fieldSelector->SetValue(m_criteriaRow->m_field);
}

void CriteriaRowEditor::updateOperators(void)
{
for (int x = 0; x < SmartPLOperatorsCount; x++)
new MythUIButtonListItem(m_operatorSelector, SmartPLOperators[x].m_name);
for (const auto & oper : SmartPLOperators)
new MythUIButtonListItem(m_operatorSelector, oper.m_name);

m_operatorSelector->SetValue(m_criteriaRow->m_operator);
}
Expand Down Expand Up @@ -1300,7 +1297,7 @@ void CriteriaRowEditor::updateValues(void)

void CriteriaRowEditor::saveClicked()
{
SmartPLField *Field = lookupField(m_fieldSelector->GetValue());
const SmartPLField *Field = lookupField(m_fieldSelector->GetValue());
if (!Field)
return;

Expand Down Expand Up @@ -1333,9 +1330,9 @@ void CriteriaRowEditor::enableSaveButton()
{
bool enabled = false;

SmartPLField *Field = lookupField(m_fieldSelector->GetValue());
const SmartPLField *Field = lookupField(m_fieldSelector->GetValue());

SmartPLOperator *Operator = lookupOperator(m_operatorSelector->GetValue());
const SmartPLOperator *Operator = lookupOperator(m_operatorSelector->GetValue());

if (Field && Operator)
{
Expand Down Expand Up @@ -1364,7 +1361,7 @@ void CriteriaRowEditor::enableSaveButton()

void CriteriaRowEditor::fieldChanged(void)
{
SmartPLField *Field = lookupField(m_fieldSelector->GetValue());
const SmartPLField *Field = lookupField(m_fieldSelector->GetValue());
if (!Field)
return;

Expand Down Expand Up @@ -1415,11 +1412,11 @@ void CriteriaRowEditor::fieldChanged(void)

void CriteriaRowEditor::operatorChanged(void)
{
SmartPLField *Field = lookupField(m_fieldSelector->GetValue());
const SmartPLField *Field = lookupField(m_fieldSelector->GetValue());
if (!Field)
return;

SmartPLOperator *Operator = lookupOperator(m_operatorSelector->GetValue());
const SmartPLOperator *Operator = lookupOperator(m_operatorSelector->GetValue());
if (!Operator)
return;

Expand Down Expand Up @@ -1499,17 +1496,17 @@ void CriteriaRowEditor::getOperatorList(SmartPLFieldType fieldType)

m_operatorSelector->Reset();

for (int x = 0; x < SmartPLOperatorsCount; x++)
for (const auto & oper : SmartPLOperators)
{
// don't add operators that only work with string fields
if (fieldType != ftString && SmartPLOperators[x].m_stringOnly)
if (fieldType != ftString && oper.m_stringOnly)
continue;

// don't add operators that only work with boolean fields
if (fieldType == ftBoolean && !SmartPLOperators[x].m_validForBoolean)
if (fieldType == ftBoolean && !oper.m_validForBoolean)
continue;

new MythUIButtonListItem(m_operatorSelector, SmartPLOperators[x].m_name);
new MythUIButtonListItem(m_operatorSelector, oper.m_name);
}

// try to set the operatorCombo to the same operator or else the first item
Expand Down Expand Up @@ -1959,8 +1956,8 @@ void SmartPLOrderByDialog::orderByChanged(void)
void SmartPLOrderByDialog::getOrderByFields(void)
{
m_orderSelector->Reset();
for (int x = 1; x < SmartPLFieldsCount; x++)
new MythUIButtonListItem(m_orderSelector, SmartPLFields[x].m_name);
for (const auto & field : SmartPLFields)
new MythUIButtonListItem(m_orderSelector, field.m_name);
}

/*
Expand Down
15 changes: 6 additions & 9 deletions mythplugins/mythmusic/mythmusic/synaesthesia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,18 @@ bool Synaesthesia::process(VisualNode *node)
if (!node)
return false;

double x[NumSamples];
double y[NumSamples];
double a[NumSamples];
double b[NumSamples];
int clarity[NumSamples];
samp_dbl_array x {};
samp_dbl_array y {};
samp_dbl_array a {};
samp_dbl_array b {};
samp_int_array clarity {};

int brightFactor = int(Brightness * m_brightnessTwiddler / (m_starSize + 0.01));

int numSamps = NumSamples;
if (node->m_length < NumSamples)
numSamps = node->m_length;

memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));

for (int i = 0; i < numSamps; i++)
{
x[i] = node->m_left[i];
Expand All @@ -470,7 +467,7 @@ bool Synaesthesia::process(VisualNode *node)
y[i] = x[i];
}

fft(x, y);
fft(x.data(), y.data());

double energy = 0.0;

Expand Down
14 changes: 9 additions & 5 deletions mythplugins/mythmusic/mythmusic/synaesthesia.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SYNAETHESIA
#define SYNAETHESIA

#include <array>
#include <visual.h>
#include "polygon.h"
#include "mainvisual.h"
Expand All @@ -12,6 +13,9 @@ class QImage;
#define Brightness 150
#define NumSamples (1<<LogSize)

using samp_dbl_array = std::array<double,NumSamples>;
using samp_int_array = std::array<int,NumSamples>;

#define Flame 0
#define Wave 1
#define Stars 2
Expand Down Expand Up @@ -48,10 +52,10 @@ class Synaesthesia : public VisualBase

QSize m_size {0,0};

double m_cosTable[NumSamples] {};
double m_negSinTable[NumSamples] {};
int m_bitReverse[NumSamples] {};
int m_scaleDown[256] {};
samp_dbl_array m_cosTable {};
samp_dbl_array m_negSinTable {};
samp_int_array m_bitReverse {};
std::array<int,256> m_scaleDown {};
int m_maxStarRadius {1};
int m_fadeMode {Stars};
bool m_pointsAreDiamonds {true};
Expand All @@ -66,7 +70,7 @@ class Synaesthesia : public VisualBase
Bitmap<unsigned short> m_lastLastOutputBmp;
QImage *m_outputImage {nullptr};

unsigned char m_palette[768] {};
std::array<uint8_t,768> m_palette {};
double m_fgRedSlider {0.0};
double m_fgGreenSlider {0.5};
double m_bgRedSlider {0.75};
Expand Down