MCPcopy Create free account
hub / github.com/audacity/audacity / ReadProjectFile

Method ReadProjectFile

src/ProjectFileManager.cpp:166–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166auto ProjectFileManager::ReadProjectFile(
167 const FilePath &fileName, bool discardAutosave )
168 -> ReadProjectResults
169{
170 auto &project = mProject;
171 auto &projectFileIO = ProjectFileIO::Get( project );
172 auto &window = GetProjectFrame( project );
173
174 ///
175 /// Parse project file
176 ///
177 auto parseResult = projectFileIO.LoadProject(fileName, discardAutosave);
178 const bool bParseSuccess = parseResult.has_value();
179
180 bool err = false;
181 std::optional<TranslatableString> linkTypeChangeReason;
182
183 TranslatableString otherError;
184
185 if (bParseSuccess)
186 {
187 auto& tracks = TrackList::Get(project);
188 // By making a duplicate set of pointers to the existing blocks
189 // on disk, we add one to their reference count, guaranteeing
190 // that their reference counts will never reach zero and thus
191 // the version saved on disk will be preserved until the
192 // user selects Save().
193 // Do this before FixTracks might delete zero-length clips!
194 mLastSavedTracks = TrackList::Create( nullptr );
195 WaveTrack *leader{};
196 tracks.Any().Visit(
197 [&](WaveTrack& track) {
198 // A rare place where TrackList::Channels remains necessary, to
199 // visit the right channels of stereo tracks not yet "zipped",
200 // otherwise later, CloseLock() will be missed for some sample
201 // blocks and corrupt the project
202 for (const auto pChannel : TrackList::Channels(&track))
203 {
204 auto left = leader;
205 auto newTrack =
206 pChannel->Duplicate(Track::DuplicateOptions {}.Backup());
207 leader = left ? nullptr // now visiting the right channel
208 :
209 (pChannel->GetLinkType() == Track::LinkType::None) ?
210 nullptr // now visiting a mono channel
211 :
212 static_cast<WaveTrack*>(newTrack.get())
213 // now visiting a left channel
214 ;
215 mLastSavedTracks->Add(newTrack);
216 if (left)
217 // Zip clips allowing misalignment -- this may be a legacy
218 // project. This duplicate track will NOT be used for normal
219 // editing, but only later to visit all the sample blocks that
220 // existed at last save time.
221 left->ZipClips(false);
222 }
223 },

Callers 1

DiscardAutosaveMethod · 0.80

Calls 15

GetFunction · 0.85
CreateFunction · 0.85
ShowMessageBoxFunction · 0.85
AudacityMessageBoxFunction · 0.85
FindHelpUrlFunction · 0.85
LoadProjectMethod · 0.80
has_valueMethod · 0.80
BackupMethod · 0.80
GetLinkTypeMethod · 0.80
ZipClipsMethod · 0.80
TranslationMethod · 0.80
AutoSaveDeleteMethod · 0.80

Tested by

no test coverage detected