Audacity 3.2.0
Functions
Legacy.cpp File Reference

Converts old Audacity file types. Implements AutoRollbackRenamer. More...

#include "Legacy.h"
#include <stdlib.h>
#include <string.h>
#include <wx/defs.h>
#include <wx/ffile.h>
#include <wx/filefn.h>
#include <wx/textfile.h>
#include "AudacityMessageBox.h"
#include "XMLWriter.h"
Include dependency graph for Legacy.cpp:

Go to the source code of this file.

Functions

static bool ConvertLegacyTrack (wxTextFile *f, XMLFileWriter &xmlFile)
 
bool ConvertLegacyProjectFile (const wxFileName &filename)
 Update Audacity 1.0 file in-place to XML format. More...
 

Detailed Description

Converts old Audacity file types. Implements AutoRollbackRenamer.

These routines convert Audacity project files from the 0.98...1.0 format into an XML format that's compatible with Audacity 1.2.0 and newer.

Definition in file Legacy.cpp.

Function Documentation

◆ ConvertLegacyProjectFile()

bool ConvertLegacyProjectFile ( const wxFileName &  filename)

Update Audacity 1.0 file in-place to XML format.

Returns
true if successful, else no effect on the file
Exception safety guarantee:
Strong

Definition at line 249 of file Legacy.cpp.

250{
251 wxTextFile f;
252
253 const wxString name = filename.GetFullPath();
254 f.Open( name );
255 if (!f.IsOpened())
256 return false;
257
258 return GuardedCall< bool >( [&] {
259 XMLFileWriter xmlFile{ name, XO("Error Converting Legacy Project File") };
260
261 xmlFile.Write(wxT("<?xml version=\"1.0\"?>\n"));
262
263 wxString label;
264 wxString value;
265
266 if (f.GetFirstLine() != wxT("AudacityProject"))
267 return false;
268 if (f.GetNextLine() != wxT("Version"))
269 return false;
270 if (f.GetNextLine() != wxT("0.95"))
271 return false;
272 if (f.GetNextLine() != wxT("projName"))
273 return false;
274
275 xmlFile.StartTag(wxT("audacityproject"));
276 xmlFile.WriteAttr(wxT("projname"), f.GetNextLine());
277 xmlFile.WriteAttr(wxT("version"), wxT("1.1.0"));
278 xmlFile.WriteAttr(wxT("audacityversion"),AUDACITY_VERSION_STRING);
279
280 label = f.GetNextLine();
281 while (label != wxT("BeginTracks")) {
282 xmlFile.WriteAttr(label, f.GetNextLine());
283 label = f.GetNextLine();
284 }
285
286 label = f.GetNextLine();
287 while (label != wxT("EndTracks")) {
288 bool success = ConvertLegacyTrack(&f, xmlFile);
289 if (!success)
290 return false;
291 label = f.GetNextLine();
292 }
293
294 // Close original before Commit() tries to overwrite it.
295 f.Close();
296
297 xmlFile.EndTag(wxT("audacityproject"));
298 xmlFile.Commit();
299
301 XO(
302"Converted a 1.0 project file to the new format.\nThe old file has been saved as '%s'")
303 .Format( xmlFile.GetBackupName() ),
304 XO("Opening Audacity Project"));
305
306 return true;
307 } );
308}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XO("Cut/Copy/Paste")
static bool ConvertLegacyTrack(wxTextFile *f, XMLFileWriter &xmlFile)
Definition: Legacy.cpp:43
wxString name
Definition: TagsEditor.cpp:166
TranslatableString label
Definition: TagsEditor.cpp:165
Abstract base class used in importing a file.
Wrapper to output XML data to files.
Definition: XMLWriter.h:84

References AudacityMessageBox(), ConvertLegacyTrack(), label, name, wxT(), and XO().

Here is the call graph for this function:

◆ ConvertLegacyTrack()

static bool ConvertLegacyTrack ( wxTextFile *  f,
XMLFileWriter xmlFile 
)
static

Definition at line 43 of file Legacy.cpp.

45{
46 wxString line;
47 wxString kind;
48
49 kind = (*f)[f->GetCurrentLine()];
50
51 if (kind == wxT("WaveTrack")) {
52 xmlFile.StartTag(wxT("wavetrack"));
53 xmlFile.WriteAttr(wxT("name"), f->GetNextLine());
54
55 wxString channel = f->GetNextLine();
56 if (channel == wxT("left")) {
57 xmlFile.WriteAttr(wxT("channel"), 0);
58 line = f->GetNextLine();
59 }
60 else if (channel == wxT("right")) {
61 xmlFile.WriteAttr(wxT("channel"), 1);
62 line = f->GetNextLine();
63 }
64 else if (channel == wxT("mono")) {
65 xmlFile.WriteAttr(wxT("channel"), 2);
66 line = f->GetNextLine();
67 }
68 else {
69 xmlFile.WriteAttr(wxT("channel"), 2);
70 line = channel;
71 }
72
73 if (line == wxT("linked")) {
74 xmlFile.WriteAttr(wxT("linked"), 1);
75 line = f->GetNextLine();
76 }
77
78 if (line != wxT("offset"))
79 return false;
80 xmlFile.WriteAttr(wxT("offset"), f->GetNextLine());
81
82 long envLen;
83
84 if (f->GetNextLine() != wxT("EnvNumPoints"))
85 return false;
86 line = f->GetNextLine();
87 line.ToLong(&envLen);
88 if (envLen < 0 || envLen > 10000)
89 return false;
90
91 size_t envStart = f->GetCurrentLine();
92 if (f->GetLineCount() < envStart+(2*envLen)+1)
93 return false;
94
95 f->GoToLine(envStart+(2*envLen));
96 if (f->GetNextLine() != wxT("EnvEnd"))
97 return false;
98 if (f->GetNextLine() != wxT("numSamples"))
99 return false;
100
101 wxString numSamples = f->GetNextLine();
102
103 if (f->GetNextLine() != wxT("rate"))
104 return false;
105
106 xmlFile.WriteAttr(wxT("rate"), f->GetNextLine());
107
108 if (envLen > 0) {
109 xmlFile.StartTag(wxT("envelope"));
110 xmlFile.WriteAttr(wxT("numpoints"), envLen);
111
112 long i;
113 for(i=0; i<envLen; i++) {
114 xmlFile.StartTag(wxT("controlpoint"));
115 xmlFile.WriteAttr(wxT("t"), f->GetLine(envStart + 2*i + 1));
116 xmlFile.WriteAttr(wxT("val"), f->GetLine(envStart + 2*i + 2));
117 xmlFile.EndTag(wxT("controlpoint"));
118 }
119
120 xmlFile.EndTag(wxT("envelope"));
121 }
122
123 if (f->GetNextLine() != wxT("numBlocks"))
124 return false;
125 long numBlocks;
126 line = f->GetNextLine();
127 line.ToLong(&numBlocks);
128
129 if (numBlocks < 0 || numBlocks > 131072)
130 return false;
131
132 xmlFile.StartTag(wxT("sequence"));
133 xmlFile.WriteAttr(wxT("maxsamples"), 524288);
134 xmlFile.WriteAttr(wxT("sampleformat"), 131073);
135 xmlFile.WriteAttr(wxT("numsamples"), numSamples);
136
137 long b;
138 for(b=0; b<numBlocks; b++) {
139 wxString start;
140 wxString len;
141 wxString name;
142
143 if (f->GetNextLine() != wxT("Block start"))
144 return false;
145 start = f->GetNextLine();
146 if (f->GetNextLine() != wxT("Block len"))
147 return false;
148 len = f->GetNextLine();
149 if (f->GetNextLine() != wxT("Block info"))
150 return false;
151 name = f->GetNextLine();
152
153 xmlFile.StartTag(wxT("waveblock"));
154 xmlFile.WriteAttr(wxT("start"), start);
155
156 xmlFile.StartTag(wxT("legacyblockfile"));
157 if (name == wxT("Alias")) {
158 wxString aliasPath = f->GetNextLine();
159 wxString localLen = f->GetNextLine();
160 wxString aliasStart = f->GetNextLine();
161 wxString aliasLen = f->GetNextLine();
162 wxString aliasChannel = f->GetNextLine();
163 wxString localName = f->GetNextLine();
164
165 xmlFile.WriteAttr(wxT("name"), localName);
166 xmlFile.WriteAttr(wxT("alias"), 1);
167 xmlFile.WriteAttr(wxT("aliaspath"), aliasPath);
168
169 // This was written but not read again?
170 xmlFile.WriteAttr(wxT("aliasstart"), aliasStart);
171
172 xmlFile.WriteAttr(wxT("aliaslen"), aliasLen);
173 xmlFile.WriteAttr(wxT("aliaschannel"), aliasChannel);
174 xmlFile.WriteAttr(wxT("summarylen"), localLen);
175 xmlFile.WriteAttr(wxT("norms"), 1);
176 }
177 else {
178 xmlFile.WriteAttr(wxT("name"), name);
179 xmlFile.WriteAttr(wxT("len"), len);
180 xmlFile.WriteAttr(wxT("summarylen"), 8244);
181 xmlFile.WriteAttr(wxT("norms"), 1);
182 }
183 xmlFile.EndTag(wxT("legacyblockfile"));
184
185 xmlFile.EndTag(wxT("waveblock"));
186 }
187
188 xmlFile.EndTag(wxT("sequence"));
189 xmlFile.EndTag(wxT("wavetrack"));
190
191 return true;
192 }
193 else if (kind == wxT("LabelTrack")) {
194 line = f->GetNextLine();
195 if (line != wxT("NumMLabels"))
196 return false;
197
198 long numLabels, l;
199
200 line = f->GetNextLine();
201 line.ToLong(&numLabels);
202 if (numLabels < 0 || numLabels > 1000000)
203 return false;
204
205 xmlFile.StartTag(wxT("labeltrack"));
206 xmlFile.WriteAttr(wxT("name"), wxT("Labels"));
207 xmlFile.WriteAttr(wxT("numlabels"), numLabels);
208
209 for(l=0; l<numLabels; l++) {
210 wxString t, title;
211
212 t = f->GetNextLine();
213 title = f->GetNextLine();
214
215 xmlFile.StartTag(wxT("label"));
216 xmlFile.WriteAttr(wxT("t"), t);
217 xmlFile.WriteAttr(wxT("title"), title);
218 xmlFile.EndTag(wxT("label"));
219 }
220
221 xmlFile.EndTag(wxT("labeltrack"));
222
223 line = f->GetNextLine();
224 if (line != wxT("MLabelsEnd"))
225 return false;
226
227 return true;
228 }
229 else if (kind == wxT("NoteTrack")) {
230 // Just skip over it - they didn't even work in version 1.0!
231
232 do {
233 line = f->GetNextLine();
234 if (line == wxT("WaveTrack") ||
235 line == wxT("NoteTrack") ||
236 line == wxT("LabelTrack") ||
237 line == wxT("EndTracks")) {
238 f->GoToLine(f->GetCurrentLine()-1);
239 return true;
240 }
241 } while (f->GetCurrentLine() < f->GetLineCount());
242
243 return false;
244 }
245 else
246 return false;
247}
static const auto title
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

References XMLWriter::EndTag(), name, XMLWriter::StartTag(), title, XMLWriter::WriteAttr(), and wxT().

Referenced by ConvertLegacyProjectFile().

Here is the call graph for this function:
Here is the caller graph for this function: