File indexing completed on 2024-05-12 04:51:00
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef _K3B_AUDIO_DATA_SOURCE_H_ 0007 #define _K3B_AUDIO_DATA_SOURCE_H_ 0008 0009 #include "k3bmsf.h" 0010 #include "k3b_export.h" 0011 0012 #include <QIODevice> 0013 #include <QObject> 0014 0015 namespace K3b { 0016 class AudioTrack; 0017 class AudioDoc; 0018 0019 0020 /** 0021 * An AudioDataSource has an original length which represents the maximum amount of audio 0022 * sectors this source can provide (in special cases this is not true, see AudioZeroData). 0023 * 0024 * It is possible to just use a portion of that data by changing the startOffset and endOffset. 0025 * This will change the actual length of the data provided by this source through the read method. 0026 * 0027 * Sources are part of a list which can be traversed via the prev() and next() methods. This list 0028 * is part of a AudioTrack which in turn is part of a list which is owned by a AudioDoc. 0029 * 0030 * The list may be modified with the take(), moveAfter(), and moveAhead() methods. The source takes 0031 * care of fixing the list and notifying the track about the change (It is also possible to move sources 0032 * from one track to the other). 0033 * 0034 * When a source is deleted it automatically removes itself from it's list. 0035 */ 0036 class LIBK3B_EXPORT AudioDataSource : public QObject 0037 { 0038 Q_OBJECT 0039 0040 friend class AudioTrack; 0041 0042 public: 0043 AudioDataSource(); 0044 0045 /** 0046 * Create en identical copy except that the copy will not be in any list. 0047 */ 0048 AudioDataSource( const AudioDataSource& ); 0049 ~AudioDataSource() override; 0050 0051 /** 0052 * The original length of the source is the maximum data which is available 0053 * when startOffset is 0 this is the max for endOffset 0054 * 0055 * Be aware that this may change (see AudioZeroData) 0056 */ 0057 virtual Msf originalLength() const = 0; 0058 0059 /** 0060 * The default implementation returns the originalLength modified by startOffset and endOffset 0061 */ 0062 virtual Msf length() const; 0063 0064 /** 0065 * @return The index of this track (counting from 0) 0066 */ 0067 int sourceIndex() const; 0068 0069 /** 0070 * @return The raw size in pcm samples (16bit, 44800 kHz, stereo) 0071 */ 0072 KIO::filesize_t size() const { return length().audioBytes(); } 0073 0074 /** 0075 * Type of the data in readable form. 0076 */ 0077 virtual QString type() const = 0; 0078 0079 /** 0080 * The source in readable form (this is the filename for files) 0081 */ 0082 virtual QString sourceComment() const = 0; 0083 0084 /** 0085 * Used in case an error occurred. For now this is used if the 0086 * decoder was not able to decode an audiofile 0087 */ 0088 virtual bool isValid() const { return true; } 0089 0090 /** 0091 * The doc the source is currently a part of or null. 0092 */ 0093 AudioDoc* doc() const; 0094 AudioTrack* track() const { return m_track; } 0095 0096 AudioDataSource* prev() const { return m_prev; } 0097 AudioDataSource* next() const { return m_next; } 0098 0099 AudioDataSource* take(); 0100 0101 void moveAfter( AudioDataSource* track ); 0102 void moveAhead( AudioDataSource* track ); 0103 0104 /** 0105 * Set the start offset from the beginning of the source's originalLength. 0106 */ 0107 virtual void setStartOffset( const Msf& ); 0108 0109 /** 0110 * Set the end offset from the beginning of the file. The endOffset sector 0111 * is not included in the data. 0112 * The maximum value is originalLength() which means to use all data. 0113 * 0 means the same as originalLength(). 0114 * This has to be bigger than the start offset. 0115 */ 0116 virtual void setEndOffset( const Msf& ); 0117 0118 virtual const Msf& startOffset() const { return m_startOffset; } 0119 0120 /** 0121 * The end offset. It is the first sector not included in the data. 0122 * If 0 the last sector is determined by the originalLength 0123 */ 0124 virtual const Msf& endOffset() const { return m_endOffset; } 0125 0126 /** 0127 * Get the last used sector in the source. 0128 * The default implementation uses originalLength() and endOffset() 0129 */ 0130 virtual Msf lastSector() const; 0131 0132 /** 0133 * Create a copy of this source which is not part of a list 0134 */ 0135 virtual AudioDataSource* copy() const = 0; 0136 0137 /** 0138 * Split the source at position pos and return the split source 0139 * on success. 0140 * The new source will be moved after this source. 0141 * 0142 * The default implementation uses copy() to create a new source instance 0143 */ 0144 virtual AudioDataSource* split( const Msf& pos ); 0145 0146 /** 0147 * Create reader associated with the source 0148 */ 0149 virtual QIODevice* createReader( QObject* parent = 0 ) = 0; 0150 0151 Q_SIGNALS: 0152 void changed(); 0153 0154 protected: 0155 /** 0156 * Informs the parent track about changes. 0157 */ 0158 void emitChange(); 0159 0160 private: 0161 void fixupOffsets(); 0162 0163 AudioTrack* m_track; 0164 AudioDataSource* m_prev; 0165 AudioDataSource* m_next; 0166 0167 Msf m_startOffset; 0168 Msf m_endOffset; 0169 }; 0170 } 0171 0172 #endif