Audacity  2.2.2
Classes | Typedefs | Functions
Dependencies.h File Reference
#include <list>
#include <wx/filename.h>
#include "MemoryX.h"
#include "wxFileNameWrapper.h"

Go to the source code of this file.

Classes

class  AliasedFile
 An audio file that is referenced (pointed into) directly from an Audacity .aup file rather thna Audacity having its own copies of the data. More...
 

Typedefs

using AliasedFileArray = std::list< AliasedFile >
 

Functions

bool ShowDependencyDialogIfNeeded (AudacityProject *project, bool isSaving)
 
void FindDependencies (AudacityProject *project, AliasedFileArray &outAliasedFiles)
 

Typedef Documentation

using AliasedFileArray = std::list<AliasedFile>

Definition at line 53 of file Dependencies.h.

Function Documentation

void FindDependencies ( AudacityProject project,
AliasedFileArray outAliasedFiles 
)

Definition at line 113 of file Dependencies.cpp.

References format, AliasBlockFile::GetAliasedFileName(), GetAllSeqBlocks(), and AudacityProject::GetDefaultFormat().

Referenced by Exporter::GetFilename(), and ShowDependencyDialogIfNeeded().

115 {
116  sampleFormat format = project->GetDefaultFormat();
117 
118  BlockPtrArray blocks;
119  GetAllSeqBlocks(project, &blocks);
120 
121  AliasedFileHash aliasedFileHash;
122  BoolBlockFileHash blockFileHash;
123 
124  for (const auto &blockFile : blocks) {
125  const auto &f = blockFile->f;
126  if (f->IsAlias() && (blockFileHash.count( &*f ) == 0))
127  {
128  // f is an alias block we have not yet counted.
129  blockFileHash[ &*f ] = true; // Don't count the same blockfile twice.
130  auto aliasBlockFile = static_cast<AliasBlockFile*>( &*f );
131  const wxFileName &fileName = aliasBlockFile->GetAliasedFileName();
132 
133  // In DirManager::ProjectFSCK(), if the user has chosen to
134  // "Replace missing audio with silence", the code there puts in an empty wxFileName.
135  // Don't count those in dependencies.
136  if (!fileName.IsOk())
137  continue;
138 
139  const wxString &fileNameStr = fileName.GetFullPath();
140  auto blockBytes = (SAMPLE_SIZE(format) *
141  aliasBlockFile->GetLength());
142  if (aliasedFileHash.count(fileNameStr) > 0)
143  // Already put this AliasBlockFile in aliasedFileHash.
144  // Update block count.
145  aliasedFileHash[fileNameStr]->mByteCount += blockBytes;
146  else
147  {
148  // Haven't counted this AliasBlockFile yet.
149  // Add to return array and internal hash.
150 
151  // PRL: do this in two steps so that we move instead of copying.
152  // We don't have a moving push_back in all compilers.
153  outAliasedFiles.push_back(AliasedFile{});
154  outAliasedFiles.back() =
155  AliasedFile {
156  wxFileNameWrapper { fileName },
157  wxLongLong(blockBytes), fileName.FileExists()
158  };
159  aliasedFileHash[fileNameStr] = &outAliasedFiles.back();
160  }
161  }
162  }
163 }
static void GetAllSeqBlocks(AudacityProject *project, BlockPtrArray *outBlocks)
std::vector< SeqBlock * > BlockPtrArray
Definition: Sequence.h:52
const wxFileName & GetAliasedFileName() const
Definition: BlockFile.h:286
int format
Definition: ExportPCM.cpp:56
std::unordered_map< wxString, AliasedFile * > AliasedFileHash
std::unordered_map< BlockFile *, bool > BoolBlockFileHash
sampleFormat GetDefaultFormat()
Definition: Project.h:179
An audio file that is referenced (pointed into) directly from an Audacity .aup file rather thna Audac...
Definition: Dependencies.h:24
A BlockFile that refers to data in an existing file.
Definition: BlockFile.h:259
bool ShowDependencyDialogIfNeeded ( AudacityProject project,
bool  isSaving 
)

Definition at line 560 of file Dependencies.cpp.

References _(), AudacityMessageBox(), FindDependencies(), gPrefs, and RemoveDependencies().

Referenced by AudacityProject::DoSave(), and AudacityProject::OnCheckDependencies().

562 {
563  AliasedFileArray aliasedFiles;
564  FindDependencies(project, aliasedFiles);
565 
566  if (aliasedFiles.empty()) {
567  if (!isSaving)
568  {
569  wxString msg =
570 _("Your project is currently self-contained; it does not depend on any external audio files. \
571 \n\nIf you change the project to a state that has external dependencies on imported \
572 files, it will no longer be self-contained. If you then Save without copying those files in, \
573 you may lose data.");
574  AudacityMessageBox(msg,
575  _("Dependency Check"),
576  wxOK | wxICON_INFORMATION,
577  project);
578  }
579  return true; // Nothing to do.
580  }
581 
582  if (isSaving)
583  {
584  wxString action =
585  gPrefs->Read(
586  wxT("/FileFormats/SaveProjectWithDependencies"),
587  wxT("ask"));
588  if (action == wxT("copy"))
589  {
590  // User always wants to remove dependencies
591  RemoveDependencies(project, aliasedFiles);
592  return true;
593  }
594  if (action == wxT("never"))
595  // User never wants to remove dependencies
596  return true;
597  }
598 
599  DependencyDialog dlog(project, -1, project, aliasedFiles, isSaving);
600  int returnCode = dlog.ShowModal();
601  if (returnCode == wxID_CANCEL)
602  return false;
603  else if (returnCode == wxID_YES)
604  RemoveDependencies(project, aliasedFiles);
605 
606  return true;
607 }
void FindDependencies(AudacityProject *project, AliasedFileArray &outAliasedFiles)
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
static void RemoveDependencies(AudacityProject *project, AliasedFileArray &aliasedFiles)
std::list< AliasedFile > AliasedFileArray
Definition: Dependencies.h:53
DependencyDialog shows dependencies of an AudacityProject on AliasedFile s.
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)