From 0b16dad50fecae5e124e3948bf49c5bc67f9c3a1 Mon Sep 17 00:00:00 2001 From: Martin Babutzka Date: Wed, 10 Jun 2015 21:23:40 +0200 Subject: [PATCH] - Fixed decoding of non-ASCII lyric texts - Lyrics can now be viewed/edited in the metadata-editor Squashed commit of the following: commit 0851f619c27348e3ceeaf31a8edc3a567ccee99c Author: Martin Babutzka Date: Wed Jun 10 21:21:50 2015 +0200 'make format' and brackets in a condition clause. commit bab7a1d07af3bc53034e3883d352ae6d4dd33e2a Author: Martin Babutzka Date: Sun Jun 7 01:51:31 2015 +0200 Added capability to SAVE lyrics frames to mp3 files in tagreader. Improved scaling properties of edittags dialog. commit 4bd71a2d6a4479a664bf8b5b3ead05c23c86e15d Author: Martin Babutzka Date: Sat Jun 6 23:33:22 2015 +0200 Updated lyrics tag buddy to lyrics commit 2ceb8967f67e76a0f78b25a7a128c4429a93bcd9 Author: Martin Babutzka Date: Sun May 17 18:52:33 2015 +0200 Add lyrics field to tag editor commit 04b65e33a83e449055659a72a283954311a12fb7 Author: Martin Babutzka Date: Fri May 8 23:24:02 2015 +0200 Using decode method to fix non-ASCII letters. --- ext/libclementine-tagreader/tagreader.cpp | 30 +- ext/libclementine-tagreader/tagreader.h | 12 +- src/ui/edittagdialog.cpp | 3 + src/ui/edittagdialog.ui | 618 ++++++++++++---------- src/widgets/nowplayingwidget.cpp | 7 +- 5 files changed, 381 insertions(+), 289 deletions(-) diff --git a/ext/libclementine-tagreader/tagreader.cpp b/ext/libclementine-tagreader/tagreader.cpp index 67f3cd2a1..b01f4dd6a 100644 --- a/ext/libclementine-tagreader/tagreader.cpp +++ b/ext/libclementine-tagreader/tagreader.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -190,10 +191,12 @@ void TagReader::ReadFile(const QString& filename, TStringToQString(map["TCMP"].front()->toString()).trimmed(); if (!map["USLT"].isEmpty()) { - lyrics = TStringToQString((map["USLT"].front())->toString()).trimmed(); - qLog(Debug) << "Read ULST lyrics " << lyrics; - } else if (!map["SYLT"].isEmpty()) - lyrics = TStringToQString((map["SYLT"].front())->toString()).trimmed(); + Decode(map["USLT"].front()->toString(), nullptr, + song->mutable_lyrics()); + } else if (!map["SYLT"].isEmpty()) { + Decode(map["SYLT"].front()->toString(), nullptr, + song->mutable_lyrics()); + } if (!map["APIC"].isEmpty()) song->set_art_automatic(kEmbeddedCover); @@ -628,7 +631,7 @@ bool TagReader::SaveFile(const QString& filename, SetTextFrame("TCOM", song.composer(), tag); SetTextFrame("TIT1", song.grouping(), tag); SetTextFrame("TOPE", song.performer(), tag); - SetTextFrame("USLT", song.lyrics(), tag); + SetUnsyncLyricsFrame(song.lyrics(), tag); // Skip TPE1 (which is the artist) here because we already set it SetTextFrame("TPE2", song.albumartist(), tag); SetTextFrame("TCMP", std::string(song.compilation() ? "1" : "0"), tag); @@ -857,6 +860,23 @@ void TagReader::SetTextFrame(const char* id, const std::string& value, tag->addFrame(frame); } +void TagReader::SetUnsyncLyricsFrame(const std::string& value, + TagLib::ID3v2::Tag* tag) const { + TagLib::ByteVector id_vector("USLT"); + + // Remove the frame if it already exists + while (tag->frameListMap().contains(id_vector) && + tag->frameListMap()[id_vector].size() != 0) { + tag->removeFrame(tag->frameListMap()[id_vector].front()); + } + + // Create and add a new frame + TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = + new TagLib::ID3v2::UnsynchronizedLyricsFrame(TagLib::String::UTF8); + frame->setText(StdStringToTaglibString(value)); + tag->addFrame(frame); +} + bool TagReader::IsMediaFile(const QString& filename) const { qLog(Debug) << "Checking for valid file" << filename; diff --git a/ext/libclementine-tagreader/tagreader.h b/ext/libclementine-tagreader/tagreader.h index 28d989803..2408aced6 100644 --- a/ext/libclementine-tagreader/tagreader.h +++ b/ext/libclementine-tagreader/tagreader.h @@ -87,12 +87,12 @@ class TagReader { void SetFMPSStatisticsVorbisComments( TagLib::Ogg::XiphComment* vorbis_comments, const pb::tagreader::SongMetadata& song) const; - void SetFMPSRatingVorbisComments(TagLib::Ogg::XiphComment* vorbis_comments, - const pb::tagreader::SongMetadata& song) - const; + void SetFMPSRatingVorbisComments( + TagLib::Ogg::XiphComment* vorbis_comments, + const pb::tagreader::SongMetadata& song) const; - pb::tagreader::SongMetadata_Type GuessFileType(TagLib::FileRef* fileref) - const; + pb::tagreader::SongMetadata_Type GuessFileType( + TagLib::FileRef* fileref) const; void SetUserTextFrame(const QString& description, const QString& value, TagLib::ID3v2::Tag* tag) const; @@ -104,6 +104,8 @@ class TagReader { TagLib::ID3v2::Tag* tag) const; void SetTextFrame(const char* id, const std::string& value, TagLib::ID3v2::Tag* tag) const; + void SetUnsyncLyricsFrame(const std::string& value, + TagLib::ID3v2::Tag* tag) const; private: static const char* kMP4_FMPS_Rating_ID; diff --git a/src/ui/edittagdialog.cpp b/src/ui/edittagdialog.cpp index a69c67fbe..2f5a88aa5 100644 --- a/src/ui/edittagdialog.cpp +++ b/src/ui/edittagdialog.cpp @@ -304,6 +304,7 @@ QVariant EditTagDialog::Data::value(const Song& song, const QString& id) { if (id == "grouping") return song.grouping(); if (id == "genre") return song.genre(); if (id == "comment") return song.comment(); + if (id == "lyrics") return song.lyrics(); if (id == "track") return song.track(); if (id == "disc") return song.disc(); if (id == "year") return song.year(); @@ -330,6 +331,8 @@ void EditTagDialog::Data::set_value(const QString& id, const QVariant& value) { current_.set_genre(value.toString()); else if (id == "comment") current_.set_comment(value.toString()); + else if (id == "lyrics") + current_.set_lyrics(value.toString()); else if (id == "track") current_.set_track(value.toInt()); else if (id == "disc") diff --git a/src/ui/edittagdialog.ui b/src/ui/edittagdialog.ui index f862236ef..fb7e30604 100644 --- a/src/ui/edittagdialog.ui +++ b/src/ui/edittagdialog.ui @@ -30,7 +30,7 @@ - 0 + 1 @@ -605,284 +605,350 @@ + + + 0 + 0 + + + + + 528 + 514 + + Edit tags - + - - - Title - - - title - - - - - - - true - - - false - - - - - - - Track - - - track - - - - - - - QAbstractSpinBox::CorrectToNearestValue - - - 9999 - - - false - - - true - - - - - - - Artist - - - artist - - - - - - - true - - - false - - - - - - - Disc - - - disc - - - - - - - QAbstractSpinBox::CorrectToNearestValue - - - 9999 - - - false - - - true - - - - - - - Album - - - album - - - - - - - true - - - false - - - - - - - Year - - - year - - - - - - - QAbstractSpinBox::CorrectToNearestValue - - - 9999 - - - false - - - true - - - - - - - Album artist - - - albumartist - - - - - - - true - - - false - - - - - - - Composer - - - composer - - - - - - - true - - - false - - - - - - - Performer - - - performer - - - - - - - true - - - false - - - - - - - Grouping - - - grouping - - - - - - - true - - - false - - - - - - - Genre - - - genre - - - - - - - true - - - false - - - - - - - Complete tags automatically - - - - :/providers/musicbrainz.png:/providers/musicbrainz.png - - - - 38 - 22 - - - - - - - - Comment - - - comment - - - - - - - true - - - false - - + + + + + + + Title + + + title + + + + + + + true + + + false + + + + + + + Track + + + track + + + + + + + QAbstractSpinBox::CorrectToNearestValue + + + 9999 + + + false + + + true + + + + + + + Artist + + + artist + + + + + + + true + + + false + + + + + + + Disc + + + disc + + + + + + + QAbstractSpinBox::CorrectToNearestValue + + + 9999 + + + false + + + true + + + + + + + Album + + + album + + + + + + + true + + + false + + + + + + + Year + + + year + + + + + + + QAbstractSpinBox::CorrectToNearestValue + + + 9999 + + + false + + + true + + + + + + + Album artist + + + albumartist + + + + + + + true + + + false + + + + + + + Composer + + + composer + + + + + + + true + + + false + + + + + + + Performer + + + performer + + + + + + + true + + + false + + + + + + + Grouping + + + grouping + + + + + + + true + + + false + + + + + + + Genre + + + genre + + + + + + + true + + + false + + + + + + + Complete tags automatically + + + + :/providers/musicbrainz.png:/providers/musicbrainz.png + + + + 38 + 22 + + + + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Lyrics + + + lyrics + + + + + + + true + + + false + + + + + + + + + + + + 100 + 0 + + + + Comment + + + comment + + + + + + + true + + + false + + + + + + @@ -890,7 +956,7 @@ - + diff --git a/src/widgets/nowplayingwidget.cpp b/src/widgets/nowplayingwidget.cpp index 25f59df47..0c5b4ce4e 100644 --- a/src/widgets/nowplayingwidget.cpp +++ b/src/widgets/nowplayingwidget.cpp @@ -99,8 +99,8 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent) CreateModeAction(LargeSongDetailsBelow, tr("Large album cover (details below)"), mode_group, mode_mapper); - CreateModeAction(LargeNoSongDetails, tr("Large album cover (no details)"), mode_group, - mode_mapper); + CreateModeAction(LargeNoSongDetails, tr("Large album cover (no details)"), + mode_group, mode_mapper); menu_->addActions(mode_group->actions()); @@ -528,7 +528,8 @@ void NowPlayingWidget::SetMode(int mode) { void NowPlayingWidget::resizeEvent(QResizeEvent* e) { if (visible_ && e->oldSize() != e->size()) { - if (mode_ == LargeSongDetails || mode_ == LargeNoSongDetails || mode_ == LargeSongDetailsBelow) { + if (mode_ == LargeSongDetails || mode_ == LargeNoSongDetails || + mode_ == LargeSongDetailsBelow) { UpdateHeight(); UpdateDetailsText(); }