Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.3 Musicbrainz fixes #10875

Merged
merged 23 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
04bbef6
Make XML errors non fatal, because only one responds might be empty.
daschuer Sep 7, 2022
2d78c63
Make use of structured binding declaration
daschuer Sep 7, 2022
48d0378
Remove wrong setting of Inital state.
fatihemreyildiz Aug 27, 2022
a75d93f
fix feedback in case of client side timeout
daschuer Aug 30, 2022
ad3172d
Use emitNetworkError in case the URL is invalid
daschuer Sep 3, 2022
404d308
display the Http Status code instead of always -1
daschuer Sep 7, 2022
ef94bb0
Continue in case of non fatal errors during fetching of recordings
daschuer Sep 7, 2022
41abb4d
Improve error messages in case we have no error message and code from…
daschuer Sep 7, 2022
7ba6ae4
Do not mention the URi in case of sub class errors
daschuer Sep 8, 2022
498e828
Rename doNetworkError() to onNetworkError() to not conflict with a co…
daschuer Sep 9, 2022
86f4c07
Add class MockNetworkAccessManager
daschuer Oct 12, 2022
1e34da3
Reformat MockNetworkAccessManager using clang-format
daschuer Oct 12, 2022
a29fa94
Improve MockNetworkManager
daschuer Oct 14, 2022
9f69b96
Replace rlvalue reference by a normal reference parameter to make the…
daschuer Oct 16, 2022
ba501bc
Implement MockNetworkReply::abort()
daschuer Oct 21, 2022
7c388fa
Improve comment
daschuer Oct 21, 2022
8b1fffc
Make WebTask::isBusy() public
daschuer Oct 21, 2022
10326bc
Add MusicBrainzRecordingsTaskTest
daschuer Oct 21, 2022
e53c558
TagFetcher: add a terminate() function to discard stray canceled() si…
daschuer Oct 30, 2022
a4d8b70
Clear dialog in case of a null track
daschuer Oct 31, 2022
eb217e9
Don't request meta data from musikbrains after the Musivbrainz dialog…
daschuer Oct 31, 2022
ec09754
Avoid a double track update after next or previous
daschuer Oct 31, 2022
bb21444
Don't clear result if already cleared.
daschuer Oct 31, 2022
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,9 @@ add_executable(mixxx-test
src/test/metaknob_link_test.cpp
src/test/midicontrollertest.cpp
src/test/mixxxtest.cpp
src/test/mock_networkaccessmanager.cpp
src/test/movinginterquartilemean_test.cpp
src/test/musicbrainzrecordingstasktest.cpp
src/test/nativeeffects_test.cpp
src/test/performancetimer_test.cpp
src/test/playcountertest.cpp
Expand Down
60 changes: 29 additions & 31 deletions src/library/dlgtagfetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,44 @@ void DlgTagFetcher::init() {
}

void DlgTagFetcher::slotNext() {
QModelIndex nextRow = m_currentTrackIndex.sibling(
m_currentTrackIndex.row() + 1, m_currentTrackIndex.column());
if (nextRow.isValid()) {
loadTrack(nextRow);
if (isSignalConnected(QMetaMethod::fromSignal(&DlgTagFetcher::next))) {
emit next();
} else {
QModelIndex nextRow = m_currentTrackIndex.sibling(
m_currentTrackIndex.row() + 1, m_currentTrackIndex.column());
if (nextRow.isValid()) {
loadTrack(nextRow);
}
}
}

void DlgTagFetcher::slotPrev() {
QModelIndex prevRow = m_currentTrackIndex.sibling(
m_currentTrackIndex.row() - 1, m_currentTrackIndex.column());
if (prevRow.isValid()) {
loadTrack(prevRow);
if (isSignalConnected(QMetaMethod::fromSignal(&DlgTagFetcher::previous))) {
emit previous();
} else {
QModelIndex prevRow = m_currentTrackIndex.sibling(
m_currentTrackIndex.row() - 1, m_currentTrackIndex.column());
if (prevRow.isValid()) {
loadTrack(prevRow);
}
}
}

void DlgTagFetcher::loadTrackInternal(const TrackPointer& track) {
if (!track) {
return;
void DlgTagFetcher::loadTrack(const TrackPointer& pTrack) {
if (m_track) {
results->clear();
disconnect(m_track.get(),
&Track::changed,
this,
&DlgTagFetcher::slotTrackChanged);
m_data = Data();
m_networkResult = NetworkResult::Ok;
}
results->clear();
disconnect(m_track.get(),
&Track::changed,
this,
&DlgTagFetcher::slotTrackChanged);

m_track = track;
m_data = Data();
m_networkResult = NetworkResult::Ok;
m_track = pTrack;
if (!m_track) {
return;
}

connect(m_track.get(),
&Track::changed,
Expand All @@ -130,20 +138,10 @@ void DlgTagFetcher::loadTrackInternal(const TrackPointer& track) {
updateStack();
}

void DlgTagFetcher::loadTrack(const TrackPointer& track) {
VERIFY_OR_DEBUG_ASSERT(!m_pTrackModel) {
return;
}
loadTrackInternal(track);
}

void DlgTagFetcher::loadTrack(const QModelIndex& index) {
VERIFY_OR_DEBUG_ASSERT(m_pTrackModel) {
return;
}
TrackPointer pTrack = m_pTrackModel->getTrack(index);
m_currentTrackIndex = index;
loadTrackInternal(pTrack);
TrackPointer pTrack = m_pTrackModel->getTrack(index);
loadTrack(pTrack);
}

void DlgTagFetcher::slotTrackChanged(TrackId trackId) {
Expand Down
1 change: 0 additions & 1 deletion src/library/dlgtagfetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class DlgTagFetcher : public QDialog, public Ui::DlgTagFetcher {
void slotPrev();

private:
void loadTrackInternal(const TrackPointer& track);
void updateStack();
void addDivider(const QString& text, QTreeWidget* parent) const;

Expand Down
4 changes: 2 additions & 2 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void DlgTrackInfo::loadTrack(TrackPointer pTrack) {
return;
}
loadTrackInternal(pTrack);
if (m_pDlgTagFetcher && m_pLoadedTrack) {
if (m_pDlgTagFetcher && m_pDlgTagFetcher->isVisible()) {
m_pDlgTagFetcher->loadTrack(m_pLoadedTrack);
}
}
Expand All @@ -327,7 +327,7 @@ void DlgTrackInfo::loadTrack(const QModelIndex& index) {
TrackPointer pTrack = m_pTrackModel->getTrack(index);
m_currentTrackIndex = index;
loadTrackInternal(pTrack);
if (m_pDlgTagFetcher && m_currentTrackIndex.isValid()) {
if (m_pDlgTagFetcher && m_pDlgTagFetcher->isVisible()) {
m_pDlgTagFetcher->loadTrack(m_currentTrackIndex);
}
}
Expand Down
102 changes: 46 additions & 56 deletions src/musicbrainz/tagfetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TagFetcher::TagFetcher(QObject* parent)
void TagFetcher::startFetch(
TrackPointer pTrack) {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
cancel();
terminate();

m_pTrack = pTrack;

Expand Down Expand Up @@ -58,6 +58,26 @@ void TagFetcher::cancel() {
}
}

void TagFetcher::terminate() {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
m_pTrack.reset();

m_fingerprintWatcher.disconnect(this);
m_fingerprintWatcher.cancel();

if (m_pAcoustIdTask) {
m_pAcoustIdTask->disconnect(this);
m_pAcoustIdTask->deleteLater();
m_pAcoustIdTask = nullptr;
}

if (m_pMusicBrainzTask) {
m_pMusicBrainzTask->disconnect(this);
m_pMusicBrainzTask->deleteLater();
m_pMusicBrainzTask = nullptr;
}
}

void TagFetcher::slotFingerprintReady() {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!m_pTrack ||
Expand Down Expand Up @@ -115,7 +135,7 @@ void TagFetcher::slotAcoustIdTaskSucceeded(

if (recordingIds.isEmpty()) {
auto pTrack = std::move(m_pTrack);
cancel();
terminate();

emit resultAvailable(
std::move(pTrack),
Expand Down Expand Up @@ -149,28 +169,14 @@ void TagFetcher::slotAcoustIdTaskSucceeded(
kMusicBrainzTimeoutMillis);
}

bool TagFetcher::onAcoustIdTaskTerminated() {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
auto* const pAcoustIdTask = m_pAcoustIdTask.get();
DEBUG_ASSERT(sender());
VERIFY_OR_DEBUG_ASSERT(pAcoustIdTask ==
qobject_cast<mixxx::AcoustIdLookupTask*>(sender())) {
return false;
}
m_pAcoustIdTask = nullptr;
const auto taskDeleter = mixxx::ScopedDeleteLater(pAcoustIdTask);
pAcoustIdTask->disconnect(this);
return true;
}

void TagFetcher::slotAcoustIdTaskFailed(
const mixxx::network::JsonWebResponse& response) {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!onAcoustIdTaskTerminated()) {
if (m_pAcoustIdTask.get() != sender()) {
// stray call from an already aborted try
return;
}

cancel();
terminate();

emit networkError(
response.statusCode(),
Expand All @@ -181,69 +187,53 @@ void TagFetcher::slotAcoustIdTaskFailed(

void TagFetcher::slotAcoustIdTaskAborted() {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!onAcoustIdTaskTerminated()) {
if (m_pAcoustIdTask.get() != sender()) {
// stray call from an already aborted try
return;
}

cancel();
terminate();
}

void TagFetcher::slotAcoustIdTaskNetworkError(
QNetworkReply::NetworkError errorCode,
const QString& errorString,
const mixxx::network::WebResponseWithContent& responseWithContent) {
Q_UNUSED(responseWithContent);
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!onAcoustIdTaskTerminated()) {
if (m_pAcoustIdTask.get() != sender()) {
// stray call from an already aborted try
return;
}

cancel();
terminate();

emit networkError(
mixxx::network::kHttpStatusCodeInvalid,
responseWithContent.statusCode(),
QStringLiteral("AcoustID"),
errorString,
errorCode);
}

bool TagFetcher::onMusicBrainzTaskTerminated() {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
auto* const pMusicBrainzTask = m_pMusicBrainzTask.get();
DEBUG_ASSERT(sender());
VERIFY_OR_DEBUG_ASSERT(pMusicBrainzTask ==
qobject_cast<mixxx::MusicBrainzRecordingsTask*>(sender())) {
return false;
}
m_pMusicBrainzTask = nullptr;
const auto taskDeleter = mixxx::ScopedDeleteLater(pMusicBrainzTask);
pMusicBrainzTask->disconnect(this);
return true;
}

void TagFetcher::slotMusicBrainzTaskAborted() {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!onMusicBrainzTaskTerminated()) {
if (m_pMusicBrainzTask.get() != sender()) {
// stray call from an already aborted try
return;
}

cancel();
terminate();
}

void TagFetcher::slotMusicBrainzTaskNetworkError(
QNetworkReply::NetworkError errorCode,
const QString& errorString,
const mixxx::network::WebResponseWithContent& responseWithContent) {
Q_UNUSED(responseWithContent);
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!onMusicBrainzTaskTerminated()) {
if (m_pMusicBrainzTask.get() != sender()) {
// stray call from an already aborted try
return;
}

cancel();
terminate();

emit networkError(
mixxx::network::kHttpStatusCodeInvalid,
responseWithContent.statusCode(),
QStringLiteral("MusicBrainz"),
errorString,
errorCode);
Expand All @@ -254,11 +244,11 @@ void TagFetcher::slotMusicBrainzTaskFailed(
int errorCode,
const QString& errorMessage) {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!onMusicBrainzTaskTerminated()) {
if (m_pMusicBrainzTask.get() != sender()) {
// stray call from an already aborted try
return;
}

cancel();
terminate();

emit networkError(
response.statusCode(),
Expand All @@ -270,12 +260,12 @@ void TagFetcher::slotMusicBrainzTaskFailed(
void TagFetcher::slotMusicBrainzTaskSucceeded(
const QList<mixxx::musicbrainz::TrackRelease>& guessedTrackReleases) {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (!onMusicBrainzTaskTerminated()) {
if (m_pMusicBrainzTask.get() != sender()) {
// stray call from an already aborted try
return;
}

auto pTrack = std::move(m_pTrack);
cancel();
auto pTrack = m_pTrack;
terminate();

emit resultAvailable(
std::move(pTrack),
Expand Down
3 changes: 1 addition & 2 deletions src/musicbrainz/tagfetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class TagFetcher : public QObject {
const mixxx::network::WebResponseWithContent& responseWithContent);

private:
bool onAcoustIdTaskTerminated();
bool onMusicBrainzTaskTerminated();
void terminate();

QNetworkAccessManager m_network;

Expand Down
Loading