File indexing completed on 2024-04-28 04:50:21
0001 /* 0002 SPDX-FileCopyrightText: 2011 Michal Malek <michalm@jabster.pl> 0003 SPDX-FileCopyrightText: 1998-2010 Sebastian Trueg <trueg@k3b.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef K3BMASSAUDIOENCODINGJOB_H 0009 #define K3BMASSAUDIOENCODINGJOB_H 0010 0011 #include "k3bmsf.h" 0012 #include "k3bthreadjob.h" 0013 0014 #include <QHash> 0015 #include <QMultiMap> 0016 #include <QScopedPointer> 0017 #include <QString> 0018 0019 class QIODevice; 0020 0021 namespace KCDDB { 0022 class CDInfo; 0023 } 0024 0025 namespace K3b { 0026 class AudioEncoder; 0027 0028 class MassAudioEncodingJob : public ThreadJob 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 /** 0034 * Maps filenames to track 1-based track indexes 0035 * When multiple tracks are associated with one filename 0036 * they are merged and encoded into one file. 0037 */ 0038 typedef QMultiMap<QString,int> Tracks; 0039 0040 public: 0041 MassAudioEncodingJob( bool bigEndian, JobHandler* jobHandler, QObject* parent ); 0042 ~MassAudioEncodingJob() override; 0043 0044 /** 0045 * Sets CDDB information for the list of track 0046 */ 0047 void setCddbEntry( const KCDDB::CDInfo& cddbEntry ); 0048 const KCDDB::CDInfo& cddbEntry() const; 0049 0050 /** 0051 * Sets audio encoder the tracks will be encoded with. 0052 * If encoder=0 (default) wave files are created 0053 */ 0054 void setEncoder( AudioEncoder* encoder ); 0055 AudioEncoder* encoder() const; 0056 0057 /** 0058 * Sets additional file format information 0059 * used for encoders that support multiple formats 0060 */ 0061 void setFileType( const QString& fileType ); 0062 const QString& fileType() const; 0063 0064 /** 0065 * Sets list of files to encode 0066 */ 0067 void setTrackList( const Tracks& tracks ); 0068 const Tracks& trackList() const; 0069 0070 /** 0071 * Enables creating plyalist for encoded tracks 0072 */ 0073 void setWritePlaylist( const QString& filename, bool relativePaths ); 0074 0075 /** 0076 * Enables writing CUE file for encoded tracks 0077 */ 0078 void setWriteCueFile( bool writeCueFile ); 0079 0080 QString jobDetails() const override; 0081 QString jobTarget() const override; 0082 0083 protected: 0084 /** 0085 * Initializes the job, shows information etc. Runs just before 0086 * actual encoding loop. By default does nothing and returns true. 0087 * @return true on success, false on failure 0088 */ 0089 virtual bool init(); 0090 0091 /** 0092 * Performs cleanup just before leaving run() function. 0093 */ 0094 virtual void cleanup(); 0095 0096 /** 0097 * @param trackIndex 1-based track index 0098 * @returns track length 0099 */ 0100 virtual Msf trackLength( int trackIndex ) const = 0; 0101 0102 /** 0103 * Creates reader for a given track 0104 */ 0105 virtual QIODevice* createReader( int trackIndex ) const = 0; 0106 0107 /** 0108 * Prints information about currently processed track 0109 */ 0110 virtual void trackStarted( int trackIndex ) = 0; 0111 0112 /** 0113 * Prints information about previously processed track 0114 */ 0115 virtual void trackFinished( int trackIndex, const QString& filename ) = 0; 0116 0117 private: 0118 bool run() override; 0119 0120 /** 0121 * Reads data from source and encode it to provided filename 0122 * \param trackIndex 1-based track index 0123 * \param filename path to the target file 0124 * \param filename path to previously encoded file 0125 */ 0126 bool encodeTrack( int trackIndex, const QString& filename, const QString& prevFilename ); 0127 0128 /** 0129 * Writes a playlist file for previously specified tracks 0130 */ 0131 bool writePlaylist(); 0132 0133 /** 0134 * Writes a CUE file for previously specified track(s) 0135 */ 0136 bool writeCueFile(); 0137 0138 private: 0139 class Private; 0140 QScopedPointer<Private> d; 0141 }; 0142 0143 } // namespace K3b 0144 0145 #endif // K3BMASSAUDIOENCODERJOB_H