TEST_F(SoundSourceProxyTest, readArtist) { SoundSourceProxy proxy( QDir::currentPath().append("/src/test/id3-test-data/artist.mp3")); Mixxx::TrackMetadata trackMetadata; EXPECT_EQ(OK, proxy.parseTrackMetadataAndCoverArt(&trackMetadata, NULL)); EXPECT_EQ("Test Artist", trackMetadata.getArtist()); }
TEST_F(SoundSourceProxyTest, readArtist) { TrackPointer pTrack(new TrackInfoObject( QDir::currentPath().append("/src/test/id3-test-data/artist.mp3"))); SoundSourceProxy proxy(pTrack); Mixxx::TrackMetadata trackMetadata; EXPECT_EQ(OK, proxy.parseTrackMetadata(&trackMetadata)); EXPECT_EQ("Test Artist", trackMetadata.getArtist()); }
TEST_F(SoundSourceProxyTest, readArtist) { TrackPointer pTrack(Track::newTemporary( kTestDir.absoluteFilePath("artist.mp3"))); SoundSourceProxy proxy(pTrack); Mixxx::TrackMetadata trackMetadata; EXPECT_EQ(OK, proxy.parseTrackMetadata(&trackMetadata)); EXPECT_EQ("Test Artist", trackMetadata.getArtist()); }
TEST_F(SoundSourceProxyTest, TOAL_TPE2) { SoundSourceProxy proxy( QDir::currentPath().append("/src/test/id3-test-data/TOAL_TPE2.mp3")); Mixxx::TrackMetadata trackMetadata; EXPECT_EQ(OK, proxy.parseTrackMetadataAndCoverArt(&trackMetadata, NULL)); EXPECT_EQ("TITLE2", trackMetadata.getArtist()); EXPECT_EQ("ARTIST", trackMetadata.getAlbum()); EXPECT_EQ("TITLE", trackMetadata.getAlbumArtist()); }
TEST_F(SoundSourceProxyTest, TOAL_TPE2) { TrackPointer pTrack(new TrackInfoObject( QDir::currentPath().append("/src/test/id3-test-data/TOAL_TPE2.mp3"))); SoundSourceProxy proxy(pTrack); Mixxx::TrackMetadata trackMetadata; EXPECT_EQ(OK, proxy.parseTrackMetadata(&trackMetadata)); EXPECT_EQ("TITLE2", trackMetadata.getArtist()); EXPECT_EQ("ARTIST", trackMetadata.getAlbum()); EXPECT_EQ("TITLE", trackMetadata.getAlbumArtist()); }
TEST_F(SoundSourceProxyTest, TOAL_TPE2) { TrackPointer pTrack(Track::newTemporary( kTestDir.absoluteFilePath("TOAL_TPE2.mp3"))); SoundSourceProxy proxy(pTrack); Mixxx::TrackMetadata trackMetadata; EXPECT_EQ(OK, proxy.parseTrackMetadata(&trackMetadata)); EXPECT_EQ("TITLE2", trackMetadata.getArtist()); EXPECT_EQ("ARTIST", trackMetadata.getAlbum()); EXPECT_EQ("TITLE", trackMetadata.getAlbumArtist()); }
void SoundSourceProxy::loadTrackMetadataAndCoverArt( bool withCoverArt, bool reloadFromFile) const { DEBUG_ASSERT(!m_pTrack.isNull()); if (m_pSoundSource.isNull()) { // Silently ignore requests for unsupported files qDebug() << "Unable to parse file tags without a SoundSource" << getUrl(); return; } bool parsedFromFile = m_pTrack->getHeaderParsed(); if (parsedFromFile && !reloadFromFile) { qDebug() << "Skip parsing of track metadata from file" << getUrl(); return; // do not reload from file } // Use the existing trackMetadata as default values. Otherwise // existing values in the library will be overwritten with // empty values if the corresponding file tags are missing. // Depending on the file type some kind of tags might even // not be supported at all and those would get lost! Mixxx::TrackMetadata trackMetadata; m_pTrack->getMetadata(&trackMetadata); CoverArt coverArt(m_pTrack->getCoverArt()); // If parsing of the cover art image should be omitted the // 2nd output parameter must be set to nullptr. Cover art // is not reloaded from file once the metadata has been parsed! QImage* pCoverImg = (withCoverArt && !parsedFromFile) ? &coverArt.image : nullptr; // Parse the tags stored in the audio file. if (m_pSoundSource->parseTrackMetadataAndCoverArt(&trackMetadata, pCoverImg) == OK) { parsedFromFile = true; } else { qWarning() << "Failed to parse track metadata from file" << getUrl(); if (parsedFromFile) { // Don't overwrite any existing metadata that once has // been parsed successfully from file. return; } } // If Artist or title fields are blank try to parse them // from the file name. // TODO(rryan): Should we re-visit this decision? if (trackMetadata.getArtist().isEmpty() || trackMetadata.getTitle().isEmpty()) { parseMetadataFromFileName(&trackMetadata, m_pTrack->getFileInfo().fileName()); } // Dump the trackMetadata extracted from the file back into the track. m_pTrack->setMetadata(trackMetadata); m_pTrack->setHeaderParsed(parsedFromFile); if (parsedFromFile && (nullptr != pCoverImg) && !pCoverImg->isNull()) { CoverArt coverArt; coverArt.image = *pCoverImg; coverArt.info.hash = CoverArtUtils::calculateHash( coverArt.image); coverArt.info.coverLocation = QString(); coverArt.info.type = CoverInfo::METADATA; coverArt.info.source = CoverInfo::GUESSED; m_pTrack->setCoverArt(coverArt); } }
bool BrowseTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { Q_UNUSED(role); if (!index.isValid()) { return false; } qDebug() << "BrowseTableModel::setData(" << index.data() << ")"; int row = index.row(); int col = index.column(); Mixxx::TrackMetadata trackMetadata; // set tagger information trackMetadata.setArtist(this->index(row, COLUMN_ARTIST).data().toString()); trackMetadata.setTitle(this->index(row, COLUMN_TITLE).data().toString()); trackMetadata.setAlbum(this->index(row, COLUMN_ALBUM).data().toString()); trackMetadata.setKey(this->index(row, COLUMN_KEY).data().toString()); trackMetadata.setBpm(Mixxx::Bpm(this->index(row, COLUMN_BPM).data().toDouble())); trackMetadata.setComment(this->index(row, COLUMN_COMMENT).data().toString()); trackMetadata.setTrackNumber(this->index(row, COLUMN_TRACK_NUMBER).data().toString()); trackMetadata.setYear(this->index(row, COLUMN_YEAR).data().toString()); trackMetadata.setGenre(this->index(row, COLUMN_GENRE).data().toString()); trackMetadata.setComposer(this->index(row, COLUMN_COMPOSER).data().toString()); trackMetadata.setAlbumArtist(this->index(row, COLUMN_ALBUMARTIST).data().toString()); trackMetadata.setGrouping(this->index(row, COLUMN_GROUPING).data().toString()); // check if one the item were edited if (col == COLUMN_ARTIST) { trackMetadata.setArtist(value.toString()); } else if (col == COLUMN_TITLE) { trackMetadata.setTitle(value.toString()); } else if (col == COLUMN_ALBUM) { trackMetadata.setAlbum(value.toString()); } else if (col == COLUMN_BPM) { trackMetadata.setBpm(Mixxx::Bpm(value.toDouble())); } else if (col == COLUMN_KEY) { trackMetadata.setKey(value.toString()); } else if (col == COLUMN_TRACK_NUMBER) { trackMetadata.setTrackNumber(value.toString()); } else if (col == COLUMN_COMMENT) { trackMetadata.setComment(value.toString()); } else if (col == COLUMN_GENRE) { trackMetadata.setGenre(value.toString()); } else if (col == COLUMN_COMPOSER) { trackMetadata.setComposer(value.toString()); } else if (col == COLUMN_YEAR) { trackMetadata.setYear(value.toString()); } else if (col == COLUMN_ALBUMARTIST) { trackMetadata.setAlbumArtist(value.toString()); } else if (col == COLUMN_GROUPING) { trackMetadata.setGrouping(value.toString()); } else { qWarning() << "BrowseTableModel::setData(): no tagger column"; return false; } QStandardItem* item = itemFromIndex(index); QString track_location(getTrackLocation(index)); if (OK == writeTrackMetadataIntoFile(trackMetadata, track_location)) { // Modify underlying interalPointer object item->setText(value.toString()); item->setToolTip(item->text()); return true; } else { // reset to old value in error item->setText(index.data().toString()); item->setToolTip(item->text()); QMessageBox::critical( 0, tr("Mixxx Library"), tr("Could not update file metadata.") + "\n" +track_location); return false; } }