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(), AudacityProject::GetDefaultFormat(), and SAMPLE_SIZE.

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 }
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
static void GetAllSeqBlocks(AudacityProject *project, BlockPtrArray *outBlocks)
std::vector< SeqBlock * > BlockPtrArray
Definition: Sequence.h:52
const wxFileName & GetAliasedFileName() const
Definition: BlockFile.h:278
int format
Definition: ExportPCM.cpp:56
std::unordered_map< wxString, AliasedFile * > AliasedFileHash
sampleFormat
Definition: Types.h:188
std::unordered_map< BlockFile *, bool > BoolBlockFileHash
sampleFormat GetDefaultFormat()
Definition: Project.h:197
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:251
bool ShowDependencyDialogIfNeeded ( AudacityProject project,
bool  isSaving 
)

Definition at line 597 of file Dependencies.cpp.

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

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

599 {
600  AliasedFileArray aliasedFiles;
601  FindDependencies(project, aliasedFiles);
602 
603  if (aliasedFiles.empty()) {
604  if (!isSaving)
605  {
606  wxString msg =
607 _("Your project is currently self-contained; it does not depend on any external audio files. \
608 \n\nIf you change the project to a state that has external dependencies on imported \
609 files, it will no longer be self-contained. If you then Save without copying those files in, \
610 you may lose data.");
611  AudacityMessageBox(msg,
612  _("Dependency Check"),
613  wxOK | wxICON_INFORMATION,
614  project);
615  }
616  return true; // Nothing to do.
617  }
618 
619  if (isSaving)
620  {
621  wxString action =
622  gPrefs->Read(
623  wxT("/FileFormats/SaveProjectWithDependencies"),
624  wxT("ask"));
625  if (action == wxT("copy"))
626  {
627  // User always wants to remove dependencies
628  RemoveDependencies(project, aliasedFiles);
629  return true;
630  }
631  if (action == wxT("never"))
632  // User never wants to remove dependencies
633  return true;
634  }
635 
636  DependencyDialog dlog(project, -1, project, aliasedFiles, isSaving);
637  int returnCode = dlog.ShowModal();
638  if (returnCode == wxID_CANCEL)
639  return false;
640  else if (returnCode == wxID_YES)
641  RemoveDependencies(project, aliasedFiles);
642 
643  return true;
644 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
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
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")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand