Skip to content
49 changes: 49 additions & 0 deletions include/EffectCategory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* EffectCategory - Associates an effect to a category (for grouping/filtering afterwards)
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LMMS_EFFECT_CATEGORY_H
#define LMMS_EFFECT_CATEGORY_H

#include <qlabel.h>
#include <qlist.h>
#include <qobject.h>

#include "lmms_export.h"
namespace lmms
{

class LMMS_EXPORT EffectCategory
{
public:
static EffectCategory* instance();
QString getCategoryName(QString effectName);
QStringList* getCategories();
private:
static std::unique_ptr<EffectCategory> s_instance;
QStringList* m_categories;
QStringList* getCategoriesFromMap(std::map<QString,QString> map);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QStringList* getCategoriesFromMap(std::map<QString,QString> map);
QStringList* getCategoriesFromMap(std::map<QString, QString> map);

};

// Short-hand function
LMMS_EXPORT EffectCategory* getEffectCategory();
} // namespace lmms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} // namespace lmms
} // namespace lmms

#endif // LMMS_EFFECT_CATEGORY_H
26 changes: 19 additions & 7 deletions include/EffectSelectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LMMS_GUI_EFFECT_SELECT_DIALOG_H
Expand All @@ -32,6 +31,7 @@
#include <QRegularExpression>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <qboxlayout.h>

class QScrollArea;
class QTableView;
Expand All @@ -40,11 +40,11 @@ class QLineEdit;
namespace lmms::gui
{

class DualColumnFilterProxyModel : public QSortFilterProxyModel
class MultipleColumnFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
DualColumnFilterProxyModel(QObject* parent = nullptr) : QSortFilterProxyModel(parent)
MultipleColumnFilterProxyModel(QObject* parent = nullptr) : QSortFilterProxyModel(parent)
{
}

Expand All @@ -54,27 +54,36 @@ class DualColumnFilterProxyModel : public QSortFilterProxyModel
invalidateFilter();
}

void setEffectCategoryFilter(const QString& filter)
{
m_effectCategoryFilter = filter;
invalidateFilter();
}

protected:
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
{
QModelIndex nameIndex = sourceModel()->index(source_row, 0, source_parent);
QModelIndex typeIndex = sourceModel()->index(source_row, 1, source_parent);
QModelIndex categoryIndex = sourceModel()->index(source_row, 1, source_parent);
QModelIndex typeIndex = sourceModel()->index(source_row, 2, source_parent);

QString name = sourceModel()->data(nameIndex, Qt::DisplayRole).toString();
QString category = sourceModel()->data(categoryIndex, Qt::DisplayRole).toString();
QString type = sourceModel()->data(typeIndex, Qt::DisplayRole).toString();

QRegularExpression nameRegularExpression(filterRegularExpression());
nameRegularExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption);

bool nameFilterPassed = nameRegularExpression.match(name).capturedStart() != -1;

bool typeFilterPassed = type.contains(m_effectTypeFilter, Qt::CaseInsensitive);
bool categoryFilterPassed = category.contains(m_effectCategoryFilter, Qt::CaseInsensitive);

return nameFilterPassed && typeFilterPassed;
return nameFilterPassed && typeFilterPassed && categoryFilterPassed;
}

private:
QString m_effectTypeFilter;
QString m_effectCategoryFilter;
};


Expand All @@ -98,11 +107,14 @@ protected slots:
EffectKey m_currentSelection;

QStandardItemModel m_sourceModel;
DualColumnFilterProxyModel m_model;
MultipleColumnFilterProxyModel m_model;
QWidget* m_descriptionWidget;
QTableView* m_pluginList;
QScrollArea* m_scrollArea;
QLineEdit* m_filterEdit;
QHBoxLayout* buildFiltersLayout();
QHBoxLayout* buildTypeFilterLayout();
QHBoxLayout* buildCategoryFilterLayout();
};

} // namespace lmms::gui
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(LMMS_SRCS
core/DataFile.cpp
core/DrumSynth.cpp
core/Effect.cpp
core/EffectCategory.cpp
core/EffectChain.cpp
core/Engine.cpp
core/EnvelopeAndLfoParameters.cpp
Expand Down
Loading