diff options
-rw-r--r-- | src/basetrackplayer.cpp | 5 | ||||
-rw-r--r-- | src/soundsourceproxy.cpp | 65 | ||||
-rw-r--r-- | src/soundsourceproxy.h | 6 | ||||
-rw-r--r-- | src/trackinfoobject.cpp | 61 | ||||
-rw-r--r-- | src/trackinfoobject.h | 37 |
5 files changed, 85 insertions, 89 deletions
diff --git a/src/basetrackplayer.cpp b/src/basetrackplayer.cpp index 9d87a4127f..7e5ae803fb 100644 --- a/src/basetrackplayer.cpp +++ b/src/basetrackplayer.cpp @@ -199,8 +199,9 @@ void BaseTrackPlayer::slotUnloadTrack(TrackPointer) { void BaseTrackPlayer::slotFinishLoading(TrackPointer pTrackInfoObject) { // Read the tags if required - if(!m_pLoadedTrack->getHeaderParsed()) - SoundSourceProxy::ParseHeader(m_pLoadedTrack.data()); + if (!m_pLoadedTrack->getHeaderParsed()) { + m_pLoadedTrack->parse(); + } // m_pLoadedTrack->setPlayedAndUpdatePlaycount(true); // Actually the song is loaded but not played diff --git a/src/soundsourceproxy.cpp b/src/soundsourceproxy.cpp index 955f7b0c7d..f393b2e5a0 100644 --- a/src/soundsourceproxy.cpp +++ b/src/soundsourceproxy.cpp @@ -307,69 +307,8 @@ long unsigned SoundSourceProxy::length() return m_pSoundSource->length(); } -int SoundSourceProxy::parseHeader() -{ - //TODO: Reorganize code so that the static ParseHeader isn't needed, and use this function instead? - return 0; -} - -// static -int SoundSourceProxy::ParseHeader(TrackInfoObject* p) -{ - QString qFilename = p->getLocation(); - - // Log parsing of header information in developer mode. This is useful for - // tracking down corrupt files. - if (CmdlineArgs::Instance().getDeveloper()) { - qDebug() << "SoundSourceProxy::ParseHeader()" << qFilename; - } - - SoundSource* sndsrc = initialize(qFilename); - if (sndsrc == NULL) - return ERR; - - if (sndsrc->parseHeader() == OK) { - //Dump the metadata from the soundsource into the TIO - //qDebug() << "Album:" << sndsrc->getAlbum(); //Sanity check to make sure we've actually parsed metadata and not the filename - - // If Artist, Title and Type fields are not blank, modify them. - // Otherwise, keep the values extracted by the function TrackInfoObject::parseFilename() - if (!(sndsrc->getArtist().isEmpty())) { - p->setArtist(sndsrc->getArtist()); - } - - if (!(sndsrc->getTitle().isEmpty())) { - p->setTitle(sndsrc->getTitle()); - } - - if (!(sndsrc->getType().isEmpty())) { - p->setType(sndsrc->getType()); - } - - p->setAlbum(sndsrc->getAlbum()); - p->setAlbumArtist(sndsrc->getAlbumArtist()); - p->setYear(sndsrc->getYear()); - p->setGenre(sndsrc->getGenre()); - p->setComposer(sndsrc->getComposer()); - p->setGrouping(sndsrc->getGrouping()); - p->setComment(sndsrc->getComment()); - p->setTrackNumber(sndsrc->getTrackNumber()); - p->setReplayGain(sndsrc->getReplayGain()); - p->setBpm(sndsrc->getBPM()); - p->setDuration(sndsrc->getDuration()); - p->setBitrate(sndsrc->getBitrate()); - p->setSampleRate(sndsrc->getSampleRate()); - p->setChannels(sndsrc->getChannels()); - p->setKeyText(sndsrc->getKey(), - mixxx::track::io::key::FILE_METADATA); - p->setHeaderParsed(true); - } else { - qDebug() << "SoundSourceProxy::ParseHeader() error at file " << qFilename; - p->setHeaderParsed(false); - } - delete sndsrc; - - return OK; +int SoundSourceProxy::parseHeader() { + return m_pSoundSource ? m_pSoundSource->parseHeader() : ERR; } // static diff --git a/src/soundsourceproxy.h b/src/soundsourceproxy.h index b051fb2c55..d37dc01902 100644 --- a/src/soundsourceproxy.h +++ b/src/soundsourceproxy.h @@ -49,10 +49,14 @@ public: unsigned read(unsigned long size, const SAMPLE*); long unsigned length(); int parseHeader(); - static int ParseHeader(TrackInfoObject* p); unsigned int getSampleRate(); /** Returns filename */ QString getFilename(); + + SoundSource* getProxiedSoundSource() { + return m_pSoundSource; + } + static QStringList supportedFileExtensions(); static QStringList supportedFileExtensionsByPlugins(); static QString supportedFileExtensionsString(); diff --git a/src/trackinfoobject.cpp b/src/trackinfoobject.cpp index 4f4cfc3bfd..8996468cc9 100644 --- a/src/trackinfoobject.cpp +++ b/src/trackinfoobject.cpp @@ -33,6 +33,7 @@ #include "track/keyfactory.h" #include "track/keyutils.h" #include "util/compatibility.h" +#include "util/cmdlineargs.h" #include "util/time.h" TrackInfoObject::TrackInfoObject(const QString& file, bool parseHeader) @@ -133,15 +134,65 @@ void TrackInfoObject::doSave() { emit(save(this)); } -int TrackInfoObject::parse() { - // Parse the information stored in the sound file - int result = SoundSourceProxy::ParseHeader(this); +void TrackInfoObject::parse() { + // Log parsing of header information in developer mode. This is useful for + // tracking down corrupt files. + const QString& canonicalLocation = m_fileInfo.canonicalFilePath(); + if (CmdlineArgs::Instance().getDeveloper()) { + qDebug() << "TrackInfoObject::parse()" << canonicalLocation; + } + + // Parse the information stored in the sound file. + SoundSourceProxy proxy(canonicalLocation); + Mixxx::SoundSource* pProxiedSoundSource = proxy.getProxiedSoundSource(); + if (pProxiedSoundSource != NULL && proxy.parseHeader() == OK) { + + // Dump the metadata extracted from the file into the track. + + // TODO(XXX): This involves locking the mutex for every setXXX + // method. We should figure out an optimization where there are private + // setters that don't lock the mutex. + + // If Artist, Title and Type fields are not blank, modify them. + // Otherwise, keep their current values. + // TODO(rryan): Should we re-visit this decision? + if (!(pProxiedSoundSource->getArtist().isEmpty())) { + setArtist(pProxiedSoundSource->getArtist()); + } + + if (!(pProxiedSoundSource->getTitle().isEmpty())) { + setTitle(pProxiedSoundSource->getTitle()); + } + + if (!(pProxiedSoundSource->getType().isEmpty())) { + setType(pProxiedSoundSource->getType()); + } + + setAlbum(pProxiedSoundSource->getAlbum()); + setAlbumArtist(pProxiedSoundSource->getAlbumArtist()); + setYear(pProxiedSoundSource->getYear()); + setGenre(pProxiedSoundSource->getGenre()); + setComposer(pProxiedSoundSource->getComposer()); + setGrouping(pProxiedSoundSource->getGrouping()); + setComment(pProxiedSoundSource->getComment()); + setTrackNumber(pProxiedSoundSource->getTrackNumber()); + setReplayGain(pProxiedSoundSource->getReplayGain()); + setBpm(pProxiedSoundSource->getBPM()); + setDuration(pProxiedSoundSource->getDuration()); + setBitrate(pProxiedSoundSource->getBitrate()); + setSampleRate(pProxiedSoundSource->getSampleRate()); + setChannels(pProxiedSoundSource->getChannels()); + setKeyText(pProxiedSoundSource->getKey(), + mixxx::track::io::key::FILE_METADATA); + setHeaderParsed(true); + } else { + qDebug() << "TrackInfoObject::parse() error at file" + << canonicalLocation; + setHeaderParsed(false); - if (!m_bHeaderParsed) { // Add basic information derived from the filename: parseFilename(); } - return result; // 0 = OK if Mixxx can handle this file } diff --git a/src/trackinfoobject.h b/src/trackinfoobject.h index f75bcffd0d..f1125b5955 100644 --- a/src/trackinfoobject.h +++ b/src/trackinfoobject.h @@ -52,7 +52,7 @@ class TrackInfoObject : public QObject { Q_OBJECT public: - // Initialize a new track with the filename. + // Initialize a new track with the filename. TrackInfoObject(const QString& file="", bool parseHeader=true); // Initialize track with a QFileInfo class TrackInfoObject(const QFileInfo& fileInfo, bool parseHeader=true); @@ -60,14 +60,15 @@ public: TrackInfoObject(const QDomNode &); virtual ~TrackInfoObject(); - // Returns true if the object contains valid information - int parse(); + // Parse file metadata. If no file metadata is present, attempts to extract + // artist and title information from the filename. + void parse(); - // Returns the duration in seconds + // Returns the duration in seconds int getDuration() const; - // Set duration in seconds + // Set duration in seconds void setDuration(int); - // Returns the duration as a string: H:MM:SS + // Returns the duration as a string: H:MM:SS QString getDurationStr() const; // Accessors for various stats of the file on disk. These are auto-populated @@ -107,11 +108,11 @@ public: float getReplayGain() const; // Set ReplayGain void setReplayGain(float); - // Returns BPM + // Returns BPM double getBpm() const; - // Set BPM + // Set BPM void setBpm(double); - // Returns BPM as a string + // Returns BPM as a string QString getBpmStr() const; // A track with a locked BPM will not be re-analyzed by the beats or bpm // analyzer. @@ -119,7 +120,7 @@ public: bool hasBpmLock() const; bool getHeaderParsed() const; void setHeaderParsed(bool parsed = true); - // Returns the user comment + // Returns the user comment QString getComment() const; // Sets the user commnet void setComment(const QString&); @@ -147,8 +148,8 @@ public: QDateTime getDateAdded() const; void setDateAdded(const QDateTime& dateAdded); - // Getter/Setter methods for metadata - // Return title + // Getter/Setter methods for metadata + // Return title QString getTitle() const; // Set title void setTitle(const QString&); @@ -156,7 +157,7 @@ public: QString getArtist() const; // Set artist void setArtist(const QString&); - // Return album + // Return album QString getAlbum() const; // Set album void setAlbum(const QString&); @@ -168,7 +169,7 @@ public: QString getYear() const; // Set year void setYear(const QString&); - // Return genre + // Return genre QString getGenre() const; // Set genre void setGenre(const QString&); @@ -306,10 +307,10 @@ public: // The file QFileInfo m_fileInfo; - // Metadata + // Metadata // Album QString m_sAlbum; - // Artist + // Artist QString m_sArtist; // Album Artist QString m_sAlbumArtist; @@ -346,7 +347,7 @@ public: int m_iTimesPlayed; // Replay Gain volume float m_fReplayGain; - // Has this track been played this sessions? + // Has this track been played this sessions? bool m_bPlayed; // True if header was parsed bool m_bHeaderParsed; @@ -365,7 +366,7 @@ public: // The list of cue points for the track QList<Cue*> m_cuePoints; - // Mutex protecting access to object + // Mutex protecting access to object mutable QMutex m_qMutex; // Storage for the track's beats |