1 /*  cdrdao - write audio CD-Rs in disc-at-once mode
2  *
3  *  Copyright (C) 1998, 1999  Andreas Mueller <mueller@daneb.ping.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_EDIT_H__
21 #define __TOC_EDIT_H__
22 
23 #include <string>
24 #include <list>
25 #include <sigc++/signal.h>
26 
27 #include "Toc.h"
28 #include "CdTextItem.h"
29 #include "FormatConverter.h"
30 
31 class Toc;
32 class TrackData;
33 class TrackDataScrap;
34 class SampleManager;
35 class TocEditView;
36 
37 class TocEdit {
38 public:
39   TocEdit(Toc *, const char *);
40   ~TocEdit();
41 
42   void toc(Toc *, const char *);
43   Toc *toc() const;
44 
45   SampleManager *sampleManager();
46 
47   unsigned long lengthSample() const;
48 
49   void tocDirty(bool);
tocDirty()50   bool tocDirty() const            { return tocDirty_; }
51 
52   void blockEdit();
53   void unblockEdit();
editable()54   bool editable() const            { return (editBlocked_ == 0); }
55 
56   // returns and resets update level
57   unsigned long updateLevel();
58 
59   void filename(const char *);
60   const char *filename() const;
61 
62   int readToc(const char *);
63   int saveToc();
64   int saveAsToc(const char *);
65 
66   int moveTrackMarker(int trackNr, int indexNr, long lba);
67   int addTrackMarker(long lba);
68   int removeTrackMarker(int trackNr, int indexNr);
69   int addIndexMarker(long lba);
70   int addPregap(long lba);
71 
72   // Asynchronous interface.
73   void queueConversion(const char* filename);
74   void queueAppendTrack(const char* filename);
75   void queueAppendFile(const char* filename);
76   void queueInsertFile(const char* filename, unsigned long pos);
77   void queueScan(long start, long end);
78 
79   // Abort all queued work.
80   void queueAbort();
81 
82   // Is queue active
83   bool isQueueActive();
84 
85   int appendSilence(unsigned long);
86   int insertSilence(unsigned long length, unsigned long pos);
87 
88   int removeTrackData(TocEditView *);
89   int insertTrackData(TocEditView *);
90 
91   void setTrackCopyFlag(int trackNr, int flag);
92   void setTrackPreEmphasisFlag(int trackNr, int flag);
93   void setTrackAudioType(int trackNr, int flag);
94   void setTrackIsrcCode(int trackNr, const char *);
95 
96   void setCdTextItem(int trackNr, CdTextItem::PackType, int blockNr,
97 		     const char *);
98   void setCdTextGenreItem(int blockNr, int code1, int code2,
99 			  const char *description);
100   void setCdTextLanguage(int blockNr, int langCode);
101 
102   void setCatalogNumber(const char *);
103   void setTocType(Toc::TocType);
104 
105   // Signals
106   sigc::signal0<void> signalProgressPulse;
107   sigc::signal1<void, double> signalProgressFraction;
108   sigc::signal1<void, const char*> signalStatusMessage;
109   sigc::signal0<void> signalFullView;
110   sigc::signal2<void, unsigned long, unsigned long> signalSampleSelection;
111   sigc::signal1<void, bool> signalCancelEnable;
112   sigc::signal1<void, const char*> signalError;
113 
114 private:
115   Toc *toc_;
116   SampleManager *sampleManager_;
117 
118   char *filename_;
119 
120   TrackDataScrap *trackDataScrap_;
121 
122   bool tocDirty_;
123   int  editBlocked_;
124 
125   unsigned long updateLevel_;
126 
127   class QueueJob {
128   public:
QueueJob(const char * o)129     QueueJob(const char* o) { op = o; }
~QueueJob()130     ~QueueJob() {}
131     std::string op;
132     std::string file;
133     std::string cfile;
134     long pos;
135     long end;
136     long len;
137   };
138 
139   std::list<QueueJob*> queue_;
140   QueueJob* cur_;
141   bool threadActive_;
142   enum { TE_IDLE, TE_CONVERTING, TE_CONVERTED, TE_READING } curState_;
143   FormatSupport* curConv_;
144 
145   bool curScan();
146   bool curAppendTrack();
147   bool curAppendFile();
148   bool curInsertFile();
149   int  curCreateAudioData(TrackData **);
150   void curSignalConversionError(FormatSupport::Status);
151   void activateQueue();
152   bool queueThread();
153 
154   friend class TocEditView;
155 };
156 
157 #endif
158