Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/trackinfoobject.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           trackinfoobject.h  -  description
00003                              -------------------
00004     begin                : 10 02 2003
00005     copyright            : (C) 2003 by Tue & Ken Haste Andersen
00006     email                : haste@diku.dk
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef TRACKINFOOBJECT_H
00019 #define TRACKINFOOBJECT_H
00020 
00021 #include <QList>
00022 #include <QDateTime>
00023 #include <QObject>
00024 #include <QFileInfo>
00025 #include <QMutex>
00026 #include <QVector>
00027 #include <QSharedPointer>
00028 #include <QWeakPointer>
00029 
00030 #include "defs.h"
00031 #include "track/beats.h"
00032 #include "library/dao/cue.h"
00033 
00034 class QString;
00035 class QDomElement;
00036 class QDomDocument;
00037 class QDomNode;
00038 class ControlObject;
00039 class TrackPlaylist;
00040 class Cue;
00041 
00042 class TrackInfoObject;
00043 
00044 typedef QSharedPointer<TrackInfoObject> TrackPointer;
00045 typedef QWeakPointer<TrackInfoObject> TrackWeakPointer;
00046 
00047 #include "segmentation.h"
00048 
00049 class TrackInfoObject : public QObject
00050 {
00051     Q_OBJECT
00052 public:
00054     TrackInfoObject(const QString sLocation="", bool parseHeader=true);
00055     // Initialize track with a QFileInfo class
00056     TrackInfoObject(QFileInfo& fileInfo, bool parseHeader=true);
00058     TrackInfoObject(const QDomNode &);
00059     virtual ~TrackInfoObject();
00060 
00062     bool isValid() const;
00063     int parse();
00064     void writeToXML( QDomDocument &, QDomElement & );
00065 
00067     int getDuration() const;
00069     void setDuration(int);
00071     QString getDurationStr() const;
00072 
00073     // Accessors for various stats of the file on disk. These are auto-populated
00074     // when the TIO is constructed, or when setLocation() is called.
00075 
00076     Q_PROPERTY(QString artist READ getArtist WRITE setArtist)
00077     Q_PROPERTY(QString title READ getTitle WRITE setTitle)
00078     Q_PROPERTY(QString album READ getAlbum WRITE setAlbum)
00079     Q_PROPERTY(QString genre READ getGenre WRITE setGenre)
00080     Q_PROPERTY(QString year READ getYear WRITE setYear)
00081     Q_PROPERTY(QString track_number READ getTrackNumber WRITE setTrackNumber)
00082     Q_PROPERTY(int times_played READ getTimesPlayed)
00083     Q_PROPERTY(QString comment READ getComment WRITE setComment)
00084     Q_PROPERTY(float bpm READ getBpm WRITE setBpm)
00085     Q_PROPERTY(QString bpmFormatted READ getBpmStr STORED false)
00086     Q_PROPERTY(int duration READ getDuration WRITE setDuration)
00087     Q_PROPERTY(QString durationFormatted READ getDurationStr STORED false)
00088 
00089 
00090     // Returns absolute path to the file, including the filename.
00091     QString getLocation() const;
00092     // Returns the absolute path to the directory containing the file
00093     QString getDirectory() const;
00094     // Returns the filename of the file.
00095     QString getFilename() const;
00096     // Returns file creation date
00097     QDateTime getCreateDate() const;
00098     // Returns the length of the file in bytes
00099     int getLength() const;
00100     // Returns whether the file exists on disk or not. Updated as of the time
00101     // the TrackInfoObject is created, or when setLocation() is called.
00102     bool exists() const;
00103 
00104 
00105 
00107     float getReplayGain() const;
00109     void setReplayGain(float);
00111     float getBpm() const;
00113     void setBpm(float);
00115     QString getBpmStr() const;
00117     bool getBpmConfirm() const;
00119     void setBpmConfirm(bool confirm=true);
00120     bool getHeaderParsed() const;
00121     void setHeaderParsed(bool parsed = true);
00123     QString getComment() const;
00125     void setComment(QString);
00127     QString getType() const;
00129     void setType(QString);
00131     int getBitrate() const;
00133     QString getBitrateStr() const;
00135     void setBitrate(int);
00137     void setBeatFirst(float);
00139     float getBeatFirst() const;
00141     void setSampleRate(int iSampleRate);
00143     int getSampleRate() const;
00145     void setChannels(int iChannels);
00147     int getChannels() const;
00149     QString getInfo() const;
00150 
00151     QDateTime getDateAdded() const;
00152     void setDateAdded(QDateTime dateAdded);
00153 
00156     QString getTitle() const;
00158     void setTitle(QString);
00160     QString getArtist() const;
00162     void setArtist(QString);
00164     QString getAlbum() const;
00166     void setAlbum(QString);
00168     QString getYear() const;
00170     void setYear(QString);
00172     QString getGenre() const;
00174     void setGenre(QString);
00176     QString getTrackNumber() const;
00178     void setTrackNumber(QString);
00180     int getTimesPlayed() const;
00182     void setTimesPlayed(int t);
00184     void incTimesPlayed();
00186     bool getPlayed() const;
00188     void setPlayed(bool);
00189 
00190     int getId() const;
00191 
00193     int getRating() const;
00195     void setRating(int);
00196 
00198     QString getKey() const;
00200     void setKey(QString);
00201 
00203     QString getURL();
00205     void setURL(QString url);
00207     void setVisualWaveform(QVector<float> *pWave);
00209     QVector<float> * getVisualWaveform();
00210 
00212     void setVisualResampleRate(double dVisualResampleRate);
00213     double getVisualResampleRate();
00214 
00216     void setWaveSummary(const QByteArray* pWave, bool updateUI = true);
00217 
00219     const QByteArray* getWaveSummary();
00220 
00222     void setBpmControlObject(ControlObject *p);
00223 
00225     void setCuePoint(float cue);
00227     float getCuePoint();
00228 
00229     // Calls for managing the track's cue points
00230     Cue* addCue();
00231     void removeCue(Cue* cue);
00232     const QList<Cue*>& getCuePoints();
00233     void setCuePoints(QList<Cue*> cuePoints);
00234 
00235     bool isDirty();
00236 
00237     // Signals to the creator of this TrackInfoObject to save the Track as it
00238     // may be deleted.
00239     void doSave();
00240 
00241     // Returns true if the track location has changed
00242     bool locationChanged();
00243 
00245     void setLocation(QString location);
00246 
00247     // Get the track's Beats list
00248     BeatsPointer getBeats() const;
00249 
00250     // Set the track's Beats
00251     void setBeats(BeatsPointer beats);
00252 
00253     const Segmentation<QString>* getChordData();
00254     void setChordData(Segmentation<QString> cd);
00255 
00256   public slots:
00257     void slotCueUpdated();
00258 
00259   signals:
00260     void wavesummaryUpdated(TrackInfoObject*);
00261     void bpmUpdated(double bpm);
00262     void beatsUpdated();
00263     void ReplayGainUpdated(double replaygain);
00264     void cuesUpdated();
00265     void changed(TrackInfoObject* pTrack);
00266     void dirty(TrackInfoObject* pTrack);
00267     void clean(TrackInfoObject* pTrack);
00268     void save(TrackInfoObject* pTrack);
00269 
00270   private slots:
00271     void slotBeatsUpdated();
00272 
00273   private:
00274 
00275     // Common initialization function between all TIO constructors.
00276     void initialize(bool parseHeader);
00277 
00278     // Initialize all the location variables.
00279     void populateLocation(QFileInfo& fileInfo);
00280 
00281     // Method for parsing information from knowing only the file name.  It
00282     // assumes that the filename is written like: "artist - trackname.xxx"
00283     void parseFilename();
00284 
00285     // Set whether the TIO is dirty not. This should never be called except by
00286     // TIO local methods or the TrackDAO.
00287     void setDirty(bool bDirty);
00288 
00289     // Set a unique identifier for the track. Only used by services like
00290     // TrackDAO
00291     void setId(int iId);
00292 
00293     // Flag that indicates whether or not the TIO has changed. This is used by
00294     // TrackDAO to determine whether or not to write the Track back.
00295     bool m_bDirty;
00296 
00297     // Special flag for telling if the track location was changed.
00298     bool m_bLocationChanged;
00299 
00300     // The filename
00301     QString m_sFilename;
00302     // The full path to the file, including the filename.
00303     QString m_sLocation;
00304     // The full path to the directory containing the file.
00305     QString m_sDirectory;
00306     // Length of track in bytes
00307     int m_iLength;
00308     // Flag which indicates whether the file exists or not.
00309     bool m_bExists;
00310 
00313     QString m_sAlbum;
00315     QString m_sArtist;
00317     QString m_sTitle;
00319     QString m_sGenre;
00321     QString m_sYear;
00323     QString m_sTrackNumber;
00324 
00326     QString m_sType;
00328     QString m_sComment;
00330     QString m_sURL;
00332     int m_iDuration;
00334     int m_iSampleRate;
00336     int m_iChannels;
00338     int m_Rating;;
00340     int m_iBitrate;
00342     int m_iTimesPlayed;
00344     float m_fReplayGain;
00346     bool m_bPlayed;
00348     float m_fBpm;
00350     float m_fMinBpm;
00352     float m_fMaxBpm;
00354     bool m_bBpmConfirm;
00356     bool m_bHeaderParsed;
00358     float m_fBeatFirst;
00360     int m_iId;
00362     float m_fCuePoint;
00364     QDateTime m_dCreateDate;
00365     // Date the track was added to the library
00366     QDateTime m_dateAdded;
00367 
00368     QString m_key;
00369 
00370     // The list of cue points for the track
00371     QList<Cue*> m_cuePoints;
00372 
00374     QVector<float> *m_pVisualWave;
00376     QByteArray m_waveSummary;
00377 
00379     mutable QMutex m_qMutex;
00380 
00382     bool m_bIsValid;
00383 
00384     double m_dVisualResampleRate;
00385     Segmentation<QString> m_chordData;
00386 
00387     // Storage for the track's beats
00388     BeatsPointer m_pBeats;
00389 
00390     friend class TrackDAO;
00391 };
00392 
00393 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines