1 /* cdrdao - write audio CD-Rs in disc-at-once mode
2 *
3 * Copyright (C) 1998-2001 Andreas Mueller <andreas@daneb.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __TOC_H__
21 #define __TOC_H__
22
23 #include <iostream>
24 #include <list>
25 #include <string>
26
27 #include "Track.h"
28 #include "CdTextContainer.h"
29 #include "CdTextItem.h"
30
31 class Toc {
32 public:
33 Toc();
34 Toc(const Toc &);
35 ~Toc();
36
37 enum TocType { CD_DA, CD_ROM, CD_I, CD_ROM_XA };
38
39 // sets/returns toc type
40 void tocType(TocType);
41 TocType tocType() const;
42
firstTrackNo(int i)43 void firstTrackNo(int i) { firstTrackNo_ = i; }
firstTrackNo()44 int firstTrackNo() const { return firstTrackNo_; }
45
nofTracks()46 int nofTracks() const { return nofTracks_; }
47
length()48 Msf length() const { return length_; }
49
50 // returns mode that should be used for lead-in and gap
51 TrackData::Mode leadInMode() const;
52 // returns mode that should be used for lead-out
53 TrackData::Mode leadOutMode() const;
54
55 int append(const Track *);
56 void insert(int, const Track *);
57 void remove(int);
58
59 Track *getTrack(int trackNr);
60
61 int moveTrackMarker(int trackNr, int indexNr, long lba);
62 int removeTrackMarker(int trackNr, int indexNr);
63 int addIndexMarker(long lba);
64 int addTrackMarker(long lba);
65 int addPregap(long lba);
66
67 void appendTrack(const TrackDataList *, long *start, long *end);
68 int appendTrackData(const TrackDataList *, long *start, long *end);
69
70 int removeTrackData(unsigned long start, unsigned long end,
71 TrackDataList **);
72 int insertTrackData(unsigned long pos, const TrackDataList *list);
73
74 static Toc *read(const char *);
75 int write(const char *) const;
76 bool write(int fd, bool conversions = false) const;
77
catalogValid()78 int catalogValid() const { return catalogValid_; }
79
80 int catalog(const char *); // sets catalog number
catalog(int i)81 char catalog(int i) const { return catalog_[i]; } // BCD
82 const char *catalog() const;
83
84 void addCdTextItem(int trackNr, CdTextItem *);
85 void removeCdTextItem(int trackNr, CdTextItem::PackType, int blockNr);
86 int existCdTextBlock(int blockNr) const;
87 const CdTextItem *getCdTextItem(int trackNr, int blockNr,
88 CdTextItem::PackType) const;
89 void cdTextLanguage(int blockNr, int lang);
90 int cdTextLanguage(int blockNr) const;
91
92 void trackSummary(int *nofAudioTracks, int *nofMode1Tracks,
93 int *nofMode2Tracks) const;
94
95 // Verification methods
96 bool resolveFilenames(const char* tocFilename);
97 int check() const;
98 int checkCdTextData() const;
99
100 bool convertFilesToWav();
101 bool recomputeLength();
102
103 // if conversions is true, the TOc is printed with the converted WAV
104 // or RAW filenames instead of the original ones.
105 void print(std::ostream &, bool conversions = false) const;
106
107 void collectFiles(std::set<std::string>& list);
108 void markFileConversion(const char* src, const char* dst);
109
110 static const char *tocType2String(TocType);
111
112 private:
113 friend class TocImpl;
114 friend class TocParserGram;
115 friend class TocReader;
116 friend class TrackIterator;
117
118 struct TrackEntry {
TrackEntryTrackEntry119 TrackEntry() : absStart(0), start(0), end(0) {
120 trackNr = 0; track = 0; next = 0; pred = 0;
121 }
122
123 int trackNr;
124 Track *track;
125 Msf absStart; // absoulte track start (end of last track)
126 Msf start; // logical track start (after pre-gap)
127 Msf end;
128
129 struct TrackEntry *next;
130 struct TrackEntry *pred;
131 };
132
133 void update();
134
135 TrackEntry *findTrack(unsigned long sample) const;
136
137 TrackEntry *findTrackByNumber(int trackNr) const;
138
139 void remove(TrackEntry *);
140
141 void fixLengths();
142
143 void checkConsistency();
144
145
146 TocType tocType_; // type of TOC
147
148 int nofTracks_, firstTrackNo_;
149 TrackEntry *tracks_;
150 TrackEntry *lastTrack_;
151
152 Msf length_; // total length of disc
153
154 char catalog_[13];
155 int catalogValid_;
156
157 CdTextContainer cdtext_;
158 };
159
160
161 class TocReader {
162 public:
163 TocReader(const Toc * = 0);
164 ~TocReader();
165
166 void init(const Toc *);
167
168 int openData();
169 //long readData(long lba, char *buf, long len);
170 int seekSample(unsigned long sample);
171 long readSamples(Sample *buf, long len);
172 void closeData();
173
174 const char* curFilename();
175
176 private:
177 const Toc *toc_;
178
179 TrackReader reader;
180
181 const Toc::TrackEntry *readTrack_; // actual read track
182 long readPos_; // actual read position (blocks)
183 long readPosSample_; // actual read position (samples)
184 int open_; // != 0 indicates that toc was opened for reading data
185 };
186
187
188 class TrackIterator {
189 public:
190 TrackIterator(const Toc *);
191 ~TrackIterator();
192
193 const Track *find(int trackNr, Msf &start, Msf &end);
194 const Track *find(unsigned long sample, Msf &start, Msf &end,
195 int *trackNr);
196 const Track *first(Msf &start, Msf &end);
197 const Track *first();
198 const Track *next(Msf &start, Msf &end);
199 const Track *next();
200
201 private:
202 const Toc *toc_;
203 Toc::TrackEntry *iterator_;
204 };
205
206
207
208 inline
tocType(TocType t)209 void Toc::tocType(TocType t)
210 {
211 tocType_ = t;
212 }
213
214 inline
tocType()215 Toc::TocType Toc::tocType() const
216 {
217 return tocType_;
218 }
219
220 #endif
221