File indexing completed on 2024-06-02 04:51:51

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Pulic License for more details.              *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 
0018 #ifndef CUEFILESUPPORT_H
0019 #define CUEFILESUPPORT_H
0020 
0021 #include "core/meta/forward_declarations.h"
0022 
0023 #include <QUrl>
0024 
0025 #include <QFile>
0026 #include <QSet>
0027 #include <QString>
0028 
0029 namespace MetaCue
0030 {
0031 
0032 class CueFileItem
0033 {
0034 public:
0035     CueFileItem ( const QString& title, const QString& artist, const QString& album, const int trackNumber, const long index )
0036             : m_title ( title )
0037             , m_artist ( artist )
0038             , m_album ( album )
0039             , m_trackNumber ( trackNumber )
0040             , m_index ( index )
0041             , m_length ( -1 )
0042     {}
0043 
0044     CueFileItem()
0045             : m_title( )
0046             , m_artist( )
0047             , m_album( )
0048             , m_trackNumber ( -1 )
0049             , m_index ( -1 )
0050             , m_length ( -1 )
0051     {}
0052     void setLength ( const long length )
0053     {
0054         m_length = length;
0055     }
0056     const QString title () const
0057     {
0058         return m_title;
0059     }
0060     const QString artist () const
0061     {
0062         return m_artist;
0063     }
0064     const QString album () const
0065     {
0066         return m_album;
0067     }
0068     int trackNumber () const
0069     {
0070         return m_trackNumber;
0071     }
0072     long index () const
0073     {
0074         return m_index;
0075     }
0076     long length () const
0077     {
0078         return m_length;
0079     }
0080 
0081 private:
0082     QString m_title;
0083     QString m_artist;
0084     QString m_album;
0085     int     m_trackNumber;
0086     long    m_index;
0087     long    m_length;
0088 
0089     //QSet<Meta::Observer*> observers;
0090     QUrl m_url;
0091 };
0092 
0093 typedef QMap<long, CueFileItem> CueFileItemMap;
0094 
0095 
0096 class CueFileSupport
0097 {
0098 
0099     public:
0100 
0101     enum Markers
0102     {
0103         BEGIN = 0,
0104         TRACK_FOUND, // track found, index not yet found
0105         INDEX_FOUND
0106     };
0107 
0108      static CueFileItemMap loadCueFile( const QUrl &cuefile, const Meta::TrackPtr &track );
0109      static CueFileItemMap loadCueFile( const QUrl &cuefile, const QUrl &trackUrl, qint64 trackLen );
0110 
0111      /**
0112      * Used to locate a cue sheet for a local track.
0113      * @return A QUrl containing the url for the cue sheet
0114      *         if a valid one was located
0115      */
0116     static QUrl locateCueSheet ( const QUrl &trackurl );
0117 
0118     /**
0119      * Attempts to load and parse a cue sheet.
0120      * @return true if the cue sheet is valid
0121      *         false if the cue sheet is invalid
0122      */
0123     static bool validateCueSheet ( const QString& cuefile );
0124 
0125     static Meta::TrackList generateTimeCodeTracks( Meta::TrackPtr baseTrack, CueFileItemMap itemMap );
0126 };
0127 
0128 }
0129 
0130 #endif // CUEFILESUPPORT_H