File indexing completed on 2025-03-16 04:29:58
0001 /* 0002 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "k3btrack.h" 0007 0008 #include <QSharedData> 0009 0010 class K3b::Device::Track::Private : public QSharedData 0011 { 0012 public: 0013 Private( const K3b::Msf& fs = K3b::Msf(), 0014 const K3b::Msf& ls = K3b::Msf(), 0015 TrackType t = TYPE_UNKNOWN, 0016 DataMode m = UNKNOWN ) 0017 : firstSector( fs ), 0018 lastSector( ls ), 0019 type( t ), 0020 mode( m ), 0021 copyPermitted(true), 0022 preEmphasis(false), 0023 session(0) { 0024 } 0025 0026 K3b::Msf firstSector; 0027 K3b::Msf lastSector; 0028 K3b::Msf index0; 0029 0030 K3b::Msf nextWritableAddress; 0031 K3b::Msf freeBlocks; 0032 0033 TrackType type; 0034 DataMode mode; 0035 bool copyPermitted; 0036 bool preEmphasis; 0037 0038 int session; 0039 0040 QList<K3b::Msf> indices; 0041 0042 QByteArray isrc; 0043 }; 0044 0045 0046 K3b::Device::Track::Track() 0047 : d( new Private() ) 0048 { 0049 } 0050 0051 0052 K3b::Device::Track::Track( const Track& track ) 0053 { 0054 d = track.d; 0055 } 0056 0057 0058 K3b::Device::Track::Track( const K3b::Msf& firstSector, 0059 const K3b::Msf& lastSector, 0060 TrackType type, 0061 DataMode mode ) 0062 : d( new Private( firstSector, 0063 lastSector, 0064 type, 0065 mode ) ) 0066 { 0067 } 0068 0069 0070 K3b::Device::Track::~Track() 0071 { 0072 } 0073 0074 0075 K3b::Device::Track& K3b::Device::Track::operator=( const Track& track ) 0076 { 0077 d = track.d; 0078 return *this; 0079 } 0080 0081 0082 K3b::Msf K3b::Device::Track::length() const 0083 { 0084 // +1 since the last sector is included 0085 return d->lastSector - d->firstSector + 1; 0086 } 0087 0088 0089 K3b::Device::Track::TrackType K3b::Device::Track::type() const 0090 { 0091 return d->type; 0092 } 0093 0094 0095 void K3b::Device::Track::setType( TrackType t ) 0096 { 0097 d->type = t; 0098 } 0099 0100 0101 K3b::Device::Track::DataMode K3b::Device::Track::mode() const 0102 { 0103 return d->mode; 0104 } 0105 0106 0107 void K3b::Device::Track::setMode( DataMode m ) 0108 { 0109 d->mode = m; 0110 } 0111 0112 0113 bool K3b::Device::Track::copyPermitted() const 0114 { 0115 return d->copyPermitted; 0116 } 0117 0118 0119 void K3b::Device::Track::setCopyPermitted( bool b ) 0120 { 0121 d->copyPermitted = b; 0122 } 0123 0124 0125 bool K3b::Device::Track::preEmphasis() const 0126 { 0127 return d->preEmphasis; 0128 } 0129 0130 0131 void K3b::Device::Track::setPreEmphasis( bool b ) 0132 { 0133 d->preEmphasis = b; 0134 } 0135 0136 0137 bool K3b::Device::Track::recordedIncremental() const 0138 { 0139 return d->preEmphasis; 0140 } 0141 0142 0143 bool K3b::Device::Track::recordedUninterrupted() const 0144 { 0145 return !recordedIncremental(); 0146 } 0147 0148 0149 QByteArray K3b::Device::Track::isrc() const 0150 { 0151 return d->isrc; 0152 } 0153 0154 0155 void K3b::Device::Track::setIsrc( const QByteArray& s ) 0156 { 0157 d->isrc = s; 0158 } 0159 0160 0161 K3b::Msf K3b::Device::Track::firstSector() const 0162 { 0163 return d->firstSector; 0164 } 0165 0166 0167 K3b::Msf K3b::Device::Track::lastSector() const 0168 { 0169 return d->lastSector; 0170 } 0171 0172 0173 void K3b::Device::Track::setFirstSector( const K3b::Msf& msf ) 0174 { 0175 d->firstSector = msf; 0176 } 0177 0178 0179 void K3b::Device::Track::setLastSector( const K3b::Msf& msf ) 0180 { 0181 d->lastSector = msf; 0182 } 0183 0184 0185 K3b::Msf K3b::Device::Track::nextWritableAddress() const 0186 { 0187 return d->nextWritableAddress; 0188 } 0189 0190 0191 void K3b::Device::Track::setNextWritableAddress( const K3b::Msf& m ) 0192 { 0193 d->nextWritableAddress = m; 0194 } 0195 0196 0197 void K3b::Device::Track::setFreeBlocks( const K3b::Msf& m ) 0198 { 0199 d->freeBlocks = m; 0200 } 0201 0202 0203 K3b::Msf K3b::Device::Track::freeBlocks() const 0204 { 0205 return d->freeBlocks; 0206 } 0207 0208 0209 K3b::Msf K3b::Device::Track::realAudioLength() const 0210 { 0211 if( index0() > 0 ) 0212 return index0(); 0213 else 0214 return length(); 0215 } 0216 0217 0218 int K3b::Device::Track::session() const 0219 { 0220 return d->session; 0221 } 0222 0223 0224 void K3b::Device::Track::setSession( int s ) 0225 { 0226 d->session = s; 0227 } 0228 0229 0230 K3b::Msf K3b::Device::Track::index0() const 0231 { 0232 return d->index0; 0233 } 0234 0235 0236 QList<K3b::Msf> K3b::Device::Track::indices() const 0237 { 0238 return d->indices; 0239 } 0240 0241 0242 void K3b::Device::Track::setIndices( const QList<K3b::Msf>& il ) 0243 { 0244 d->indices = il; 0245 } 0246 0247 0248 void K3b::Device::Track::setIndex0( const K3b::Msf& msf ) 0249 { 0250 if( msf <= d->lastSector-d->firstSector ) 0251 d->index0 = msf; 0252 } 0253 0254 0255 int K3b::Device::Track::indexCount() const 0256 { 0257 return d->indices.count()-1; 0258 } 0259 0260 0261 bool K3b::Device::Track::operator==( const Track& other ) const 0262 { 0263 return( d->firstSector == other.d->firstSector && 0264 d->lastSector == other.d->lastSector && 0265 d->index0 == other.d->index0 && 0266 d->nextWritableAddress == other.d->nextWritableAddress && 0267 d->freeBlocks == other.d->freeBlocks && 0268 d->type == other.d->type && 0269 d->mode == other.d->mode && 0270 d->copyPermitted == other.d->copyPermitted && 0271 d->preEmphasis == other.d->preEmphasis && 0272 d->session == other.d->session && 0273 d->indices == other.d->indices && 0274 d->isrc == other.d->isrc ); 0275 } 0276 0277 0278 bool K3b::Device::Track::operator!=( const Track& other ) const 0279 { 0280 return !operator==( other ); 0281 } 0282 0283 0284 QDebug operator<<( QDebug s, const K3b::Device::Track& track ) 0285 { 0286 s.nospace() << ( track.type() == K3b::Device::Track::TYPE_AUDIO ? " AUDIO" : " DATA" ) 0287 << " " << track.firstSector().lba() << " - " << track.lastSector().lba() 0288 << " (" << track.length().lba() << ")"; 0289 return s; 0290 } 0291 0292 0293 uint qHash( const K3b::Device::Track& key ) 0294 { 0295 // this is a dummy implementation to make it compile on windows 0296 return qHash((long)&key); 0297 }