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: 2 additions & 1 deletion src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ QString DlgPrefController::askForMappingName(const QString& prefilledName) const
"special characters.");
QString fileExistsLabel = tr("A mapping file with that name already exists.");
// Only allow the name to contain letters, numbers, whitespaces and _-+()/
const QRegExp rxRemove = QRegExp("[^[(a-zA-Z0-9\\_\\-\\+\\(\\)\\/|\\s]");
const QRegularExpression rxRemove = QRegularExpression(
QStringLiteral("[^[(a-zA-Z0-9\\_\\-\\+\\(\\)\\/|\\s]"));

// Choose a new file (base) name
bool validMappingName = false;
Expand Down
130 changes: 54 additions & 76 deletions src/controllers/midi/portmidienumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <portmidi.h>

#include <QRegExp>
#include <QRegularExpression>

#include "controllers/midi/portmidicontroller.h"
#include "moc_portmidienumerator.cpp"
Expand All @@ -20,44 +20,33 @@ bool recognizeDevice(const PmDeviceInfo& deviceInfo) {
.startsWith(kMidiThroughPortPrefix, Qt::CaseInsensitive);
}

} // namespace
// Some platforms format MIDI device names as "deviceName MIDI ###" where
// ### is the instance # of the device. Therefore we want to link two
// devices that have an equivalent "deviceName" and ### section.
const QRegularExpression kMidiDeviceNameRegex(QStringLiteral("^(.*) MIDI (\\d+)( .*)?$"));

PortMidiEnumerator::PortMidiEnumerator() {
PmError err = Pm_Initialize();
// Based on reading the source, it's not possible for this to fail.
if (err != pmNoError) {
qWarning() << "PortMidi error:" << Pm_GetErrorText(err);
}
}
const QRegularExpression kInputRegex(QStringLiteral("^(.*) in (\\d+)( .*)?$"));
const QRegularExpression kOutputRegex(QStringLiteral("^(.*) out (\\d+)( .*)?$"));

PortMidiEnumerator::~PortMidiEnumerator() {
qDebug() << "Deleting PortMIDI devices...";
QListIterator<Controller*> dev_it(m_devices);
while (dev_it.hasNext()) {
delete dev_it.next();
}
PmError err = Pm_Terminate();
// Based on reading the source, it's not possible for this to fail.
if (err != pmNoError) {
qWarning() << "PortMidi error:" << Pm_GetErrorText(err);
}
}
// This is a broad pattern that matches a text blob followed by a numeral
// potentially followed by non-numeric text. The non-numeric requirement is
// meant to avoid corner cases around devices with names like "Hercules RMX
// 2" where we would potentially confuse the number in the device name as
// the ordinal index of the device.
const QRegularExpression kDeviceNameRegex(QStringLiteral("^(.*) (\\d+)( [^0-9]+)?$"));

bool namesMatchMidiPattern(const QString& input_name,
bool namesMatchRegexes(const QRegularExpression& kInputRegex,
const QString& input_name,
const QRegularExpression& kOutputRegex,
const QString& output_name) {
// Some platforms format MIDI device names as "deviceName MIDI ###" where
// ### is the instance # of the device. Therefore we want to link two
// devices that have an equivalent "deviceName" and ### section.
QRegExp deviceNamePattern("^(.*) MIDI (\\d+)( .*)?$");

int inputMatch = deviceNamePattern.indexIn(input_name);
if (inputMatch == 0) {
QString inputDeviceName = deviceNamePattern.cap(1);
QString inputDeviceIndex = deviceNamePattern.cap(2);
int outputMatch = deviceNamePattern.indexIn(output_name);
if (outputMatch == 0) {
QString outputDeviceName = deviceNamePattern.cap(1);
QString outputDeviceIndex = deviceNamePattern.cap(2);
QRegularExpressionMatch inputMatch = kInputRegex.match(input_name);
if (inputMatch.hasMatch()) {
QString inputDeviceName = inputMatch.captured(1);
QString inputDeviceIndex = inputMatch.captured(2);
QRegularExpressionMatch outputMatch = kOutputRegex.match(output_name);
if (outputMatch.hasMatch()) {
QString outputDeviceName = outputMatch.captured(1);
QString outputDeviceIndex = outputMatch.captured(2);
if (outputDeviceName.compare(inputDeviceName, Qt::CaseInsensitive) == 0 &&
outputDeviceIndex == inputDeviceIndex) {
return true;
Expand All @@ -67,53 +56,19 @@ bool namesMatchMidiPattern(const QString& input_name,
return false;
}

bool namesMatchMidiPattern(const QString& input_name,
const QString& output_name) {
return namesMatchRegexes(kMidiDeviceNameRegex, input_name, kMidiDeviceNameRegex, output_name);
}

bool namesMatchInOutPattern(const QString& input_name,
const QString& output_name) {
QString basePattern = "^(.*) %1 (\\d+)( .*)?$";
QRegExp inputPattern(basePattern.arg("in"));
QRegExp outputPattern(basePattern.arg("out"));

int inputMatch = inputPattern.indexIn(input_name);
if (inputMatch == 0) {
QString inputDeviceName = inputPattern.cap(1);
QString inputDeviceIndex = inputPattern.cap(2);
int outputMatch = outputPattern.indexIn(output_name);
if (outputMatch == 0) {
QString outputDeviceName = outputPattern.cap(1);
QString outputDeviceIndex = outputPattern.cap(2);
if (outputDeviceName.compare(inputDeviceName, Qt::CaseInsensitive) == 0 &&
outputDeviceIndex == inputDeviceIndex) {
return true;
}
}
}
return false;
return namesMatchRegexes(kInputRegex, input_name, kOutputRegex, output_name);
}

bool namesMatchPattern(const QString& input_name,
const QString& output_name) {
// This is a broad pattern that matches a text blob followed by a numeral
// potentially followed by non-numeric text. The non-numeric requirement is
// meant to avoid corner cases around devices with names like "Hercules RMX
// 2" where we would potentially confuse the number in the device name as
// the ordinal index of the device.
QRegExp deviceNamePattern("^(.*) (\\d+)( [^0-9]+)?$");

int inputMatch = deviceNamePattern.indexIn(input_name);
if (inputMatch == 0) {
QString inputDeviceName = deviceNamePattern.cap(1);
QString inputDeviceIndex = deviceNamePattern.cap(2);
int outputMatch = deviceNamePattern.indexIn(output_name);
if (outputMatch == 0) {
QString outputDeviceName = deviceNamePattern.cap(1);
QString outputDeviceIndex = deviceNamePattern.cap(2);
if (outputDeviceName.compare(inputDeviceName, Qt::CaseInsensitive) == 0 &&
outputDeviceIndex == inputDeviceIndex) {
return true;
}
}
}
return false;
return namesMatchRegexes(kDeviceNameRegex, input_name, kDeviceNameRegex, output_name);
}

bool namesMatchAllowableEdgeCases(const QString& input_name,
Expand All @@ -129,6 +84,29 @@ bool namesMatchAllowableEdgeCases(const QString& input_name,
return false;
}

} // namespace

PortMidiEnumerator::PortMidiEnumerator() {
PmError err = Pm_Initialize();
// Based on reading the source, it's not possible for this to fail.
if (err != pmNoError) {
qWarning() << "PortMidi error:" << Pm_GetErrorText(err);
}
}

PortMidiEnumerator::~PortMidiEnumerator() {
qDebug() << "Deleting PortMIDI devices...";
QListIterator<Controller*> dev_it(m_devices);
while (dev_it.hasNext()) {
delete dev_it.next();
}
PmError err = Pm_Terminate();
// Based on reading the source, it's not possible for this to fail.
if (err != pmNoError) {
qWarning() << "PortMidi error:" << Pm_GetErrorText(err);
}
}

bool shouldLinkInputToOutput(const QString& input_name,
const QString& output_name) {
// Early exit.
Expand Down
22 changes: 10 additions & 12 deletions src/effects/effectsmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "effects/effectsmanager.h"

#include <QMetaType>
#include <QRegularExpression>
#include <algorithm>

#include "effects/effectchainmanager.h"
Expand All @@ -19,6 +20,7 @@ namespace {
constexpr QChar kEffectGroupSeparator = '_';
constexpr QChar kGroupClose = ']';
const unsigned int kEffectMessagPipeFifoSize = 2048;
const QRegularExpression kIntRegex(QStringLiteral(".*(\\d+).*"));
} // anonymous namespace

EffectsManager::EffectsManager(QObject* pParent,
Expand Down Expand Up @@ -256,8 +258,6 @@ EffectRackPointer EffectsManager::getEffectRack(const QString& group) {

EffectSlotPointer EffectsManager::getEffectSlot(
const QString& group) {
QRegExp intRegEx(".*(\\d+).*");

QStringList parts = group.split(kEffectGroupSeparator);

EffectRackPointer pRack = getEffectRack(parts.at(0) + kGroupClose);
Expand All @@ -267,8 +267,8 @@ EffectSlotPointer EffectsManager::getEffectSlot(

EffectChainSlotPointer pChainSlot;
if (parts.at(0) == "[EffectRack1") {
intRegEx.indexIn(parts.at(1));
pChainSlot = pRack->getEffectChainSlot(intRegEx.cap(1).toInt() - 1);
QRegularExpressionMatch match = kIntRegex.match(parts.at(1));
pChainSlot = pRack->getEffectChainSlot(match.captured(1).toInt() - 1);
} else {
// Assume a PerGroupRack
const QString chainGroup =
Expand All @@ -285,9 +285,9 @@ EffectSlotPointer EffectsManager::getEffectSlot(
return EffectSlotPointer();
}

intRegEx.indexIn(parts.at(2));
QRegularExpressionMatch match = kIntRegex.match(parts.at(2));
EffectSlotPointer pEffectSlot =
pChainSlot->getEffectSlot(intRegEx.cap(1).toInt() - 1);
pChainSlot->getEffectSlot(match.captured(1).toInt() - 1);
return pEffectSlot;
}

Expand All @@ -299,10 +299,9 @@ EffectParameterSlotPointer EffectsManager::getEffectParameterSlot(
return EffectParameterSlotPointer();
}

QRegExp intRegEx(".*(\\d+).*");
intRegEx.indexIn(configKey.item);
QRegularExpressionMatch match = kIntRegex.match(configKey.item);
EffectParameterSlotPointer pParameterSlot =
pEffectSlot->getEffectParameterSlot(intRegEx.cap(1).toInt() - 1);
pEffectSlot->getEffectParameterSlot(match.captured(1).toInt() - 1);
return pParameterSlot;
}

Expand All @@ -314,10 +313,9 @@ EffectButtonParameterSlotPointer EffectsManager::getEffectButtonParameterSlot(
return EffectButtonParameterSlotPointer();
}

QRegExp intRegEx(".*(\\d+).*");
intRegEx.indexIn(configKey.item);
QRegularExpressionMatch match = kIntRegex.match(configKey.item);
EffectButtonParameterSlotPointer pParameterSlot =
pEffectSlot->getEffectButtonParameterSlot(intRegEx.cap(1).toInt() - 1);
pEffectSlot->getEffectButtonParameterSlot(match.captured(1).toInt() - 1);
return pParameterSlot;
}

Expand Down
10 changes: 6 additions & 4 deletions src/engine/sidechain/shoutconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const int kMaxNetworkCache = 491520; // 10 s mp3 @ 192 kbit/s
// http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2
const int kMaxShoutFailures = 3;

const QRegularExpression kArtistOrTitleRegex(QStringLiteral("\\$artist|\\$title"));
const QRegularExpression kArtistRegex(QStringLiteral("\\$artist"));

const mixxx::Logger kLogger("ShoutConnection");

} // namespace
Expand Down Expand Up @@ -842,13 +845,12 @@ void ShoutConnection::updateMetaData() {
do {
// find the next occurrence
replaceIndex = metadataFinal.indexOf(
QRegExp("\\$artist|\\$title"),
replaceIndex);
kArtistOrTitleRegex,
replaceIndex);

if (replaceIndex != -1) {
if (metadataFinal.indexOf(
QRegExp("\\$artist"), replaceIndex)
== replaceIndex) {
kArtistRegex, replaceIndex) == replaceIndex) {
metadataFinal.replace(replaceIndex, 7, artist);
// skip to the end of the replacement
replaceIndex += artist.length();
Expand Down
2 changes: 1 addition & 1 deletion src/library/basetrackcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BaseTrackCache : public QObject {
const QVariant& val1,
const QVariant& val2) const;
bool trackMatches(const TrackPointer& pTrack,
const QRegExp& matcher) const;
const QRegularExpression& matcher) const;
bool trackMatchesNumeric(const TrackPointer& pTrack,
const QStringList& numberMatchers) const;
bool trackMatchesNamedString(const TrackPointer& pTrack,
Expand Down
9 changes: 5 additions & 4 deletions src/library/coverartutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QDir>
#include <QDirIterator>
#include <QRegularExpression>
#include <QtConcurrentRun>

#include "sources/soundsourceproxy.h"
Expand Down Expand Up @@ -56,8 +57,8 @@ QImage CoverArtUtils::extractEmbeddedCover(
//static
QList<QFileInfo> CoverArtUtils::findPossibleCoversInFolder(const QString& folder) {
// Search for image files in the track directory.
QRegExp coverArtFilenames(supportedCoverArtExtensionsRegex(),
Qt::CaseInsensitive);
QRegularExpression coverArtFilenames(supportedCoverArtExtensionsRegex(),
QRegularExpression::CaseInsensitiveOption);
QDirIterator it(folder,
QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
QFile currentFile;
Expand All @@ -66,8 +67,8 @@ QList<QFileInfo> CoverArtUtils::findPossibleCoversInFolder(const QString& folder
while (it.hasNext()) {
it.next();
currentFileInfo = it.fileInfo();
if (currentFileInfo.isFile() &&
coverArtFilenames.indexIn(currentFileInfo.fileName()) != -1) {
const QRegularExpressionMatch match = coverArtFilenames.match(currentFileInfo.fileName());
if (currentFileInfo.isFile() && match.hasMatch()) {
possibleCovers.append(currentFileInfo);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <QDirIterator>
#include <QFileInfo>
#include <QImage>
#include <QRegExp>
#include <QtDebug>
#include <QtSql>

Expand Down
2 changes: 1 addition & 1 deletion src/library/proxytrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool ProxyTrackModel::filterAcceptsRow(int sourceRow,
dynamic_cast<QAbstractItemModel*>(m_pTrackModel);
bool rowMatches = false;

QRegExp filter = filterRegExp();
QRegularExpression filter = filterRegularExpression();
QListIterator<int> iter(filterColumns);

while (!rowMatches && iter.hasNext()) {
Expand Down
8 changes: 4 additions & 4 deletions src/library/scanner/libraryscanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ void LibraryScanner::slotStartScan() {

QSet<QString> trackLocations = m_trackDao.getAllTrackLocations();
QHash<QString, mixxx::cache_key_t> directoryHashes = m_libraryHashDao.getDirectoryHashes();
QRegExp extensionFilter(SoundSourceProxy::getSupportedFileNamesRegex());
QRegExp coverExtensionFilter =
QRegExp(CoverArtUtils::supportedCoverArtExtensionsRegex(),
Qt::CaseInsensitive);
QRegularExpression extensionFilter(SoundSourceProxy::getSupportedFileNamesRegex());
QRegularExpression coverExtensionFilter =
QRegularExpression(CoverArtUtils::supportedCoverArtExtensionsRegex(),
QRegularExpression::CaseInsensitiveOption);
QStringList directoryBlacklist = ScannerUtil::getDirectoryBlacklist();

m_scannerGlobal = ScannerGlobalPointer(
Expand Down
18 changes: 12 additions & 6 deletions src/library/scanner/recursivescandirectorytask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ void RecursiveScanDirectoryTask::run() {

QCryptographicHash hasher(QCryptographicHash::Sha256);

// TODO(rryan) benchmark QRegExp copy versus QMutex/QRegExp in ScannerGlobal
// TODO(rryan) benchmark QRegularExpression copy versus QMutex/QRegularExpression in ScannerGlobal
// versus slicing the extension off and checking for set/list containment.
QRegExp supportedExtensionsRegex =
QRegularExpression supportedExtensionsRegex =
m_scannerGlobal->supportedExtensionsRegex();
QRegExp supportedCoverExtensionsRegex =
QRegularExpression supportedCoverExtensionsRegex =
m_scannerGlobal->supportedCoverExtensionsRegex();

while (it.hasNext()) {
Expand All @@ -56,11 +56,17 @@ void RecursiveScanDirectoryTask::run() {

if (currentFileInfo.isFile()) {
const QString& fileName = currentFileInfo.fileName();
if (supportedExtensionsRegex.indexIn(fileName) != -1) {
const QRegularExpressionMatch supportedExtensionsMatch =
supportedExtensionsRegex.match(fileName);
if (supportedExtensionsMatch.hasMatch()) {
hasher.addData(currentFile.toUtf8());
filesToImport.push_back(currentFileInfo);
} else if (supportedCoverExtensionsRegex.indexIn(fileName) != -1) {
possibleCovers.push_back(currentFileInfo);
} else {
const QRegularExpressionMatch supportedCoverExtensionsMatch =
supportedCoverExtensionsRegex.match(fileName);
if (supportedCoverExtensionsMatch.hasMatch()) {
possibleCovers.push_back(currentFileInfo);
}
}
} else {
// File is a directory
Expand Down
Loading