| 164 | } |
| 165 | |
| 166 | auto 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 | }, |
no test coverage detected