1 /*
2     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "k3btrack.h"
7 
8 #include <QSharedData>
9 
10 class K3b::Device::Track::Private : public QSharedData
11 {
12 public:
Private(const K3b::Msf & fs=K3b::Msf (),const K3b::Msf & ls=K3b::Msf (),TrackType t=TYPE_UNKNOWN,DataMode m=UNKNOWN)13     Private( const K3b::Msf& fs = K3b::Msf(),
14              const K3b::Msf& ls = K3b::Msf(),
15              TrackType t = TYPE_UNKNOWN,
16              DataMode m = UNKNOWN )
17         : firstSector( fs ),
18           lastSector( ls ),
19           type( t ),
20           mode( m ),
21           copyPermitted(true),
22           preEmphasis(false),
23           session(0) {
24     }
25 
26     K3b::Msf firstSector;
27     K3b::Msf lastSector;
28     K3b::Msf index0;
29 
30     K3b::Msf nextWritableAddress;
31     K3b::Msf freeBlocks;
32 
33     TrackType type;
34     DataMode mode;
35     bool copyPermitted;
36     bool preEmphasis;
37 
38     int session;
39 
40     QList<K3b::Msf> indices;
41 
42     QByteArray isrc;
43 };
44 
45 
Track()46 K3b::Device::Track::Track()
47     : d( new Private() )
48 {
49 }
50 
51 
Track(const Track & track)52 K3b::Device::Track::Track( const Track& track )
53 {
54     d = track.d;
55 }
56 
57 
Track(const K3b::Msf & firstSector,const K3b::Msf & lastSector,TrackType type,DataMode mode)58 K3b::Device::Track::Track( const K3b::Msf& firstSector,
59                            const K3b::Msf& lastSector,
60                            TrackType type,
61                            DataMode mode )
62     : d( new Private( firstSector,
63                       lastSector,
64                       type,
65                       mode ) )
66 {
67 }
68 
69 
~Track()70 K3b::Device::Track::~Track()
71 {
72 }
73 
74 
operator =(const Track & track)75 K3b::Device::Track& K3b::Device::Track::operator=( const Track& track )
76 {
77     d = track.d;
78     return *this;
79 }
80 
81 
length() const82 K3b::Msf K3b::Device::Track::length() const
83 {
84     // +1 since the last sector is included
85     return d->lastSector - d->firstSector + 1;
86 }
87 
88 
type() const89 K3b::Device::Track::TrackType K3b::Device::Track::type() const
90 {
91     return d->type;
92 }
93 
94 
setType(TrackType t)95 void K3b::Device::Track::setType( TrackType t )
96 {
97     d->type = t;
98 }
99 
100 
mode() const101 K3b::Device::Track::DataMode K3b::Device::Track::mode() const
102 {
103     return d->mode;
104 }
105 
106 
setMode(DataMode m)107 void K3b::Device::Track::setMode( DataMode m )
108 {
109     d->mode = m;
110 }
111 
112 
copyPermitted() const113 bool K3b::Device::Track::copyPermitted() const
114 {
115     return d->copyPermitted;
116 }
117 
118 
setCopyPermitted(bool b)119 void K3b::Device::Track::setCopyPermitted( bool b )
120 {
121     d->copyPermitted = b;
122 }
123 
124 
preEmphasis() const125 bool K3b::Device::Track::preEmphasis() const
126 {
127     return d->preEmphasis;
128 }
129 
130 
setPreEmphasis(bool b)131 void K3b::Device::Track::setPreEmphasis( bool b )
132 {
133     d->preEmphasis = b;
134 }
135 
136 
recordedIncremental() const137 bool K3b::Device::Track::recordedIncremental() const
138 {
139     return d->preEmphasis;
140 }
141 
142 
recordedUninterrupted() const143 bool K3b::Device::Track::recordedUninterrupted() const
144 {
145     return !recordedIncremental();
146 }
147 
148 
isrc() const149 QByteArray K3b::Device::Track::isrc() const
150 {
151     return d->isrc;
152 }
153 
154 
setIsrc(const QByteArray & s)155 void K3b::Device::Track::setIsrc( const QByteArray& s )
156 {
157     d->isrc = s;
158 }
159 
160 
firstSector() const161 K3b::Msf K3b::Device::Track::firstSector() const
162 {
163     return d->firstSector;
164 }
165 
166 
lastSector() const167 K3b::Msf K3b::Device::Track::lastSector() const
168 {
169     return d->lastSector;
170 }
171 
172 
setFirstSector(const K3b::Msf & msf)173 void K3b::Device::Track::setFirstSector( const K3b::Msf& msf )
174 {
175     d->firstSector = msf;
176 }
177 
178 
setLastSector(const K3b::Msf & msf)179 void K3b::Device::Track::setLastSector( const K3b::Msf& msf )
180 {
181     d->lastSector = msf;
182 }
183 
184 
nextWritableAddress() const185 K3b::Msf K3b::Device::Track::nextWritableAddress() const
186 {
187     return d->nextWritableAddress;
188 }
189 
190 
setNextWritableAddress(const K3b::Msf & m)191 void K3b::Device::Track::setNextWritableAddress( const K3b::Msf& m )
192 {
193     d->nextWritableAddress = m;
194 }
195 
196 
setFreeBlocks(const K3b::Msf & m)197 void K3b::Device::Track::setFreeBlocks( const K3b::Msf& m )
198 {
199     d->freeBlocks = m;
200 }
201 
202 
freeBlocks() const203 K3b::Msf K3b::Device::Track::freeBlocks() const
204 {
205     return d->freeBlocks;
206 }
207 
208 
realAudioLength() const209 K3b::Msf K3b::Device::Track::realAudioLength() const
210 {
211     if( index0() > 0 )
212         return index0();
213     else
214         return length();
215 }
216 
217 
session() const218 int K3b::Device::Track::session() const
219 {
220     return d->session;
221 }
222 
223 
setSession(int s)224 void K3b::Device::Track::setSession( int s )
225 {
226     d->session = s;
227 }
228 
229 
index0() const230 K3b::Msf K3b::Device::Track::index0() const
231 {
232     return d->index0;
233 }
234 
235 
indices() const236 QList<K3b::Msf> K3b::Device::Track::indices() const
237 {
238     return d->indices;
239 }
240 
241 
setIndices(const QList<K3b::Msf> & il)242 void K3b::Device::Track::setIndices( const QList<K3b::Msf>& il )
243 {
244     d->indices = il;
245 }
246 
247 
setIndex0(const K3b::Msf & msf)248 void K3b::Device::Track::setIndex0( const K3b::Msf& msf )
249 {
250     if( msf <= d->lastSector-d->firstSector )
251         d->index0 = msf;
252 }
253 
254 
indexCount() const255 int K3b::Device::Track::indexCount() const
256 {
257     return d->indices.count()-1;
258 }
259 
260 
operator ==(const Track & other) const261 bool K3b::Device::Track::operator==( const Track& other ) const
262 {
263     return( d->firstSector == other.d->firstSector &&
264             d->lastSector == other.d->lastSector &&
265             d->index0 == other.d->index0 &&
266             d->nextWritableAddress == other.d->nextWritableAddress &&
267             d->freeBlocks == other.d->freeBlocks &&
268             d->type == other.d->type &&
269             d->mode == other.d->mode &&
270             d->copyPermitted == other.d->copyPermitted &&
271             d->preEmphasis == other.d->preEmphasis &&
272             d->session == other.d->session &&
273             d->indices == other.d->indices &&
274             d->isrc == other.d->isrc );
275 }
276 
277 
operator !=(const Track & other) const278 bool K3b::Device::Track::operator!=( const Track& other ) const
279 {
280     return !operator==( other );
281 }
282 
283 
operator <<(QDebug s,const K3b::Device::Track & track)284 QDebug operator<<( QDebug s, const K3b::Device::Track& track )
285 {
286     s.nospace() << ( track.type() == K3b::Device::Track::TYPE_AUDIO ? " AUDIO" : " DATA" )
287                 << " " << track.firstSector().lba() << " - " << track.lastSector().lba()
288                 << " (" << track.length().lba() << ")";
289     return s;
290 }
291 
292 
qHash(const K3b::Device::Track & key)293 uint qHash( const K3b::Device::Track& key )
294 {
295     // this is a dummy implementation to make it compile on windows
296 	return qHash((long)&key);
297 }
298