~ubuntu-branches/ubuntu/lucid/cdrdao/lucid

« back to all changes in this revision

Viewing changes to trackdb/Toc.h

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Suffield
  • Date: 2004-06-24 22:33:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040624223316-534onzugaeeyq61j
Tags: upstream-1.1.9
ImportĀ upstreamĀ versionĀ 1.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "Track.h"
 
25
#include "CdTextContainer.h"
 
26
#include "CdTextItem.h"
 
27
 
 
28
class Toc {
 
29
public:
 
30
  Toc();
 
31
  Toc(const Toc &);
 
32
  ~Toc();
 
33
 
 
34
  enum TocType { CD_DA, CD_ROM, CD_I, CD_ROM_XA };
 
35
 
 
36
  // sets/returns toc type
 
37
  void tocType(TocType);
 
38
  TocType tocType() const;
 
39
 
 
40
  int nofTracks() const { return nofTracks_; }
 
41
 
 
42
  Msf length() const { return length_; }
 
43
 
 
44
  // returns mode that should be used for lead-in and gap
 
45
  TrackData::Mode leadInMode() const;
 
46
  // returns mode that should be used for lead-out
 
47
  TrackData::Mode leadOutMode() const;
 
48
 
 
49
  int append(const Track *);
 
50
  void insert(int, const Track *);
 
51
  void remove(int);
 
52
 
 
53
  Track *getTrack(int trackNr);
 
54
 
 
55
  int moveTrackMarker(int trackNr, int indexNr, long lba);
 
56
  int removeTrackMarker(int trackNr, int indexNr);
 
57
  int addIndexMarker(long lba);
 
58
  int addTrackMarker(long lba);
 
59
  int addPregap(long lba);
 
60
 
 
61
  void appendTrack(const TrackDataList *, long *start, long *end);
 
62
  int appendTrackData(const TrackDataList *, long *start, long *end);
 
63
 
 
64
  int removeTrackData(unsigned long start, unsigned long end,
 
65
                      TrackDataList **);
 
66
  int insertTrackData(unsigned long pos, const TrackDataList *list);
 
67
 
 
68
  int check() const;
 
69
 
 
70
  static Toc *read(const char *);
 
71
  int write(const char *) const;
 
72
  bool write(int fd) const;
 
73
 
 
74
  int catalogValid() const { return catalogValid_; }
 
75
 
 
76
  int catalog(const char *); // sets catalog number
 
77
  char catalog(int i) const { return catalog_[i]; } // BCD
 
78
  const char *catalog() const;
 
79
  
 
80
  void addCdTextItem(int trackNr, CdTextItem *);
 
81
  void removeCdTextItem(int trackNr, CdTextItem::PackType, int blockNr);
 
82
  int existCdTextBlock(int blockNr) const;
 
83
  const CdTextItem *getCdTextItem(int trackNr, int blockNr,
 
84
                                  CdTextItem::PackType) const;
 
85
  void cdTextLanguage(int blockNr, int lang);
 
86
  int cdTextLanguage(int blockNr) const;
 
87
  int checkCdTextData() const;
 
88
 
 
89
  void trackSummary(int *nofAudioTracks, int *nofMode1Tracks,
 
90
                    int *nofMode2Tracks) const;
 
91
 
 
92
  void print(std::ostream &) const;
 
93
 
 
94
  static const char *tocType2String(TocType);
 
95
 
 
96
private:
 
97
  friend class TocImpl;
 
98
  friend class TocParserGram;
 
99
  friend class TocReader;
 
100
  friend class TrackIterator;
 
101
 
 
102
  struct TrackEntry {
 
103
    TrackEntry() : absStart(0), start(0), end(0) {
 
104
      trackNr = 0; track = 0; next = 0; pred = 0;
 
105
    }
 
106
 
 
107
    int trackNr;
 
108
    Track *track;
 
109
    Msf absStart; // absoulte track start (end of last track)
 
110
    Msf start; // logical track start (after pre-gap)
 
111
    Msf end;
 
112
    
 
113
    struct TrackEntry *next;
 
114
    struct TrackEntry *pred;
 
115
  };
 
116
 
 
117
  void update();
 
118
 
 
119
  TrackEntry *findTrack(unsigned long sample) const;
 
120
 
 
121
  TrackEntry *findTrackByNumber(int trackNr) const;
 
122
 
 
123
  void remove(TrackEntry *);
 
124
 
 
125
  void checkConsistency();
 
126
 
 
127
 
 
128
  TocType tocType_; // type of TOC
 
129
 
 
130
  int nofTracks_;
 
131
  TrackEntry *tracks_;
 
132
  TrackEntry *lastTrack_;
 
133
 
 
134
  Msf length_; // total length of disc
 
135
 
 
136
  char catalog_[13];
 
137
  int catalogValid_;
 
138
 
 
139
  CdTextContainer cdtext_;
 
140
};
 
141
 
 
142
 
 
143
class TocReader {
 
144
public:
 
145
  TocReader(const Toc * = 0);
 
146
  ~TocReader();
 
147
 
 
148
  void init(const Toc *);
 
149
 
 
150
  int openData();
 
151
  //long readData(long lba, char *buf, long len);
 
152
  int seekSample(unsigned long sample);
 
153
  long readSamples(Sample *buf, long len);
 
154
  void closeData();
 
155
  
 
156
private:
 
157
  const Toc *toc_;
 
158
 
 
159
  TrackReader reader;
 
160
 
 
161
  const Toc::TrackEntry *readTrack_; // actual read track
 
162
  long readPos_; // actual read position (blocks)
 
163
  long readPosSample_; // actual read position (samples)
 
164
  int open_; // != 0 indicates that toc was opened for reading data
 
165
};
 
166
 
 
167
 
 
168
class TrackIterator {
 
169
public:
 
170
  TrackIterator(const Toc *);
 
171
  ~TrackIterator();
 
172
 
 
173
  const Track *find(int trackNr, Msf &start, Msf &end);
 
174
  const Track *find(unsigned long sample, Msf &start, Msf &end,
 
175
                    int *trackNr);
 
176
  const Track *first(Msf &start, Msf &end);
 
177
  const Track *first();
 
178
  const Track *next(Msf &start, Msf &end);
 
179
  const Track *next();
 
180
 
 
181
private:
 
182
  const Toc *toc_;
 
183
  Toc::TrackEntry *iterator_;
 
184
};
 
185
 
 
186
 
 
187
 
 
188
inline
 
189
void Toc::tocType(TocType t)
 
190
{
 
191
  tocType_ = t;
 
192
}
 
193
 
 
194
inline
 
195
Toc::TocType Toc::tocType() const
 
196
{
 
197
  return tocType_;
 
198
}
 
199
 
 
200
#endif