Skip to content

Commit

Permalink
DEBUG BpmFilterNode
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Oct 8, 2023
1 parent a8de05e commit fcd122a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/library/searchquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,11 @@ BpmFilterNode::BpmFilterNode(const QString& argument, bool fuzzy, bool negate)
}

void BpmFilterNode::init(QString argument) {
qWarning() << " .";
qWarning() << " .";
qWarning() << " BPM arg:" << argument;
if (argument == kMissingFieldSearchTerm) {
qWarning() << " Null";
m_bNullQuery = true;
return;
}
Expand All @@ -497,21 +501,25 @@ void BpmFilterNode::init(QString argument) {
if (opMatch.hasMatch()) {
m_operator = opMatch.captured(1);
argument = opMatch.captured(2);
qWarning() << " opMatch:" << m_operator;
}

bool parsed = false;
const double bpm = parse(argument, &parsed);
if (parsed) {
if (m_fuzzy) {
if (opMatch.hasMatch()) {
qWarning() << " ! fuzzy but op, return";
// invalid arg
return;
}
qWarning() << " fuzzy";
// fuzzy search
m_dRangeLow = std::floor((1 - kRelativeBpmRange) * bpm);
m_dRangeHigh = std::ceil((1 + kRelativeBpmRange) * bpm);
m_bRangeQuery = true;
} else if (!opMatch.hasMatch() && !m_negate) {
qWarning() << " half/double";
// include half/double BPM
// TODO(ronso0) Make this optional in Preferences > Library
m_bpm = bpm;
Expand All @@ -522,13 +530,15 @@ void BpmFilterNode::init(QString argument) {
m_bpmDouble, &m_bpmDoubleLow, &m_bpmDoubleHigh);
m_bHalfDoubleQuery = true;
} else {
qWarning() << " exact / op / negate";
// exact / op / negate
m_bpm = bpm;
m_bOperatorQuery = true;
}
return;
} else if (m_fuzzy) {
// invalid arg
qWarning() << " ! fuzzy but invalid arg, return";
return;
}

Expand All @@ -540,7 +550,10 @@ void BpmFilterNode::init(QString argument) {
m_dRangeHigh = parse(rangeArgs[1], &highOk);

if (lowOk && highOk && m_dRangeLow <= m_dRangeHigh) {
qWarning() << " range";
m_bRangeQuery = true;
} else {
qWarning() << " ! range args invalid";
}
}
}
Expand Down Expand Up @@ -586,14 +599,17 @@ bool BpmFilterNode::match(const TrackPointer& pTrack) const {
}

QString BpmFilterNode::toSql() const {
qWarning() << " #toSql";
if (m_bNullQuery) {
return QString("bpm IS NULL");
}

if (m_bOperatorQuery) {
if (m_fuzzy) {
qWarning() << " !fuzzy but op";
return QString();
}
qWarning() << " op:" << QString("bpm %1 %2").arg(m_operator, QString::number(m_bpm));
return QString("bpm %1 %2").arg(m_operator, QString::number(m_bpm));
}

Expand All @@ -614,11 +630,15 @@ QString BpmFilterNode::toSql() const {
.arg(QString::number(m_bpmDoubleLow),
QString::number(m_bpmDoubleHigh));
}
searchClauses << QString("bpm = %1").arg(QString::number(m_bpmDouble));
qWarning() << " half/Double:" << concatSqlClauses(searchClauses, "OR");
return concatSqlClauses(searchClauses, "OR");
}

if (m_bRangeQuery) {
qWarning() << " range:"
<< QString(QStringLiteral("bpm BETWEEN %1 AND %2"))
.arg(QString::number(m_dRangeLow),
QString::number(m_dRangeHigh));
return QString(QStringLiteral("bpm BETWEEN %1 AND %2"))
.arg(QString::number(m_dRangeLow),
QString::number(m_dRangeHigh));
Expand Down

0 comments on commit fcd122a

Please sign in to comment.