Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/library/columncache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ constexpr ColumnProperties kColumnPropertiesByEnum[] = {
DI(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK){&LIBRARYTABLE_BPM_LOCK,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_BEATS_VERSION){&LIBRARYTABLE_BEATS_VERSION,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW){&LIBRARYTABLE_PREVIEW,
QT_TRANSLATE_NOOP("BaseTrackTableModel", "Preview"),
kDefaultColumnWidth / 2},
Expand Down
3 changes: 3 additions & 0 deletions src/library/columncache.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

// Caches the index of frequently used columns and provides a lookup-table of
// column name to index.
// When you add columns, remember to also add them to
// constexpr ColumnProperties kColumnPropertiesByEnum
class ColumnCache : public QObject {
Q_OBJECT
public:
Expand Down Expand Up @@ -44,6 +46,7 @@ class ColumnCache : public QObject {
COLUMN_LIBRARYTABLE_KEY,
COLUMN_LIBRARYTABLE_KEY_ID,
COLUMN_LIBRARYTABLE_BPM_LOCK,
COLUMN_LIBRARYTABLE_BEATS_VERSION,
COLUMN_LIBRARYTABLE_PREVIEW,
COLUMN_LIBRARYTABLE_COLOR,
COLUMN_LIBRARYTABLE_COVERART,
Expand Down
1 change: 1 addition & 0 deletions src/library/dao/trackschema.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const QString LIBRARYTABLE_RATING = QStringLiteral("rating");
const QString LIBRARYTABLE_KEY = QStringLiteral("key");
const QString LIBRARYTABLE_KEY_ID = QStringLiteral("key_id");
const QString LIBRARYTABLE_BPM_LOCK = QStringLiteral("bpm_lock");
const QString LIBRARYTABLE_BEATS_VERSION = QStringLiteral("beats_version");
const QString LIBRARYTABLE_PREVIEW = QStringLiteral("preview");
const QString LIBRARYTABLE_COLOR = QStringLiteral("color");
const QString LIBRARYTABLE_COVERART = QStringLiteral("coverart");
Expand Down
1 change: 1 addition & 0 deletions src/library/librarytablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool LibraryTableModel::isColumnInternal(int column) {
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BEATS_VERSION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
(PlayerManager::numPreviewDecks() == 0 &&
Expand Down
1 change: 1 addition & 0 deletions src/library/missing_hidden/hiddentablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ bool HiddenTableModel::isColumnInternal(int column) {
return column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BEATS_VERSION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
Expand Down
1 change: 1 addition & 0 deletions src/library/missing_hidden/missingtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ bool MissingTableModel::isColumnInternal(int column) {
return column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BEATS_VERSION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
Expand Down
1 change: 1 addition & 0 deletions src/library/mixxxlibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ MixxxLibraryFeature::MixxxLibraryFeature(Library* pLibrary,
LIBRARYTABLE_KEY_ID,
LIBRARYTABLE_BPM,
LIBRARYTABLE_BPM_LOCK,
LIBRARYTABLE_BEATS_VERSION,
Comment thread
Swiftb0y marked this conversation as resolved.
LIBRARYTABLE_DURATION,
LIBRARYTABLE_BITRATE,
LIBRARYTABLE_REPLAYGAIN,
Expand Down
33 changes: 31 additions & 2 deletions src/library/searchquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,13 @@ inline std::pair<double, double> rangeFromTrailingDecimal(double bpm) {

} // namespace

BpmFilterNode::BpmFilterNode(QString& argument, bool fuzzy, bool negate)
: m_matchMode(MatchMode::Invalid),
BpmFilterNode::BpmFilterNode(
QString& argument,
bool fuzzy,
bool negate,
const QSqlDatabase& database)
: m_database(database),
m_matchMode(MatchMode::Invalid),
m_operator("="),
m_bpm(0.0),
m_rangeLower(0.0),
Expand All @@ -555,6 +560,17 @@ BpmFilterNode::BpmFilterNode(QString& argument, bool fuzzy, bool negate)
return;
}

if (argument == QStringLiteral("const") || argument == QStringLiteral("constant")) {
VERIFY_OR_DEBUG_ASSERT(database.isValid()) {
qWarning() << "BpmFilterNode constructed with 'const' arg"
"but no valid database provided!";
m_matchMode = MatchMode::Invalid;
return;
}
m_matchMode = MatchMode::Constant;
return;
}

QRegularExpressionMatch opMatch = kNumericOperatorRegex.match(argument);
if (opMatch.hasMatch()) {
if (fuzzy) {
Expand Down Expand Up @@ -697,6 +713,10 @@ bool BpmFilterNode::match(const TrackPointer& pTrack) const {
return pTrack->isBpmLocked();
}

if (m_matchMode == MatchMode::Constant) {
return pTrack->getBeats()->hasConstantTempo();
}

double value = pTrack->getBpm();

switch (m_matchMode) {
Expand Down Expand Up @@ -740,6 +760,15 @@ QString BpmFilterNode::toSql() const {
case MatchMode::Locked: {
return QStringLiteral("%1 IS 1").arg(LIBRARYTABLE_BPM_LOCK);
}
case MatchMode::Constant: {
FieldEscaper escaper(m_database);
// 'BeatGrid-[version]' means we have constant BPM
// 'BeatMap-[version]' means (likely) variable BPM
const QString beatGridEscaped = escaper.escapeString(
kSqlLikeMatchAll + "BeatGrid" + kSqlLikeMatchAll);
return QStringLiteral("%1 LIKE %2")
.arg(LIBRARYTABLE_BEATS_VERSION, beatGridEscaped);
}
case MatchMode::Null: {
return QStringLiteral("bpm IS 0");
}
Expand Down
9 changes: 8 additions & 1 deletion src/library/searchquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ class BpmFilterNode : public QueryNode {
static constexpr double kRelativeRangeDefault = 0.06;
static void setBpmRelativeRange(double range);

BpmFilterNode(QString& argument, bool fuzzy, bool negate = false);
BpmFilterNode(
QString& argument,
bool fuzzy,
bool negate = false,
const QSqlDatabase& database = QSqlDatabase());

enum class MatchMode {
Invalid,
Expand All @@ -206,6 +210,7 @@ class BpmFilterNode : public QueryNode {
HalveDoubleStrict, // bpm:120.0
Operator, // bpm:<=120
Locked, // bpm:locked
Constant, // bpm:const|constant
};

// Allows WSearchRelatedTracksMenu to construct the QAction title
Expand All @@ -218,6 +223,8 @@ class BpmFilterNode : public QueryNode {
private:
bool match(const TrackPointer& pTrack) const override;

QSqlDatabase m_database;

MatchMode m_matchMode;

QString m_operator;
Expand Down
6 changes: 5 additions & 1 deletion src/library/searchqueryparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ void SearchQueryParser::parseTokens(QStringList tokens,
// restore = operator removed by getTextArgument()
argument.prepend('=');
}
pNode = std::make_unique<BpmFilterNode>(argument, fuzzy, negate);
pNode = std::make_unique<BpmFilterNode>(
argument,
fuzzy,
negate,
m_pTrackCollection->database());
}
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/library/trackset/tracksettablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bool TrackSetTableModel::isColumnInternal(int column) {
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BEATS_VERSION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
(PlayerManager::numPreviewDecks() == 0 &&
Expand Down
Loading