コード例 #1
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
// Adds one to the reference count of the block file,
// UNLESS it is "locked", then it makes a new copy of
// the BlockFile.
BlockFile *DirManager::CopyBlockFile(BlockFile *b)
{
   if (!b->IsLocked()) {
      b->Ref();
      return b;
   }

   wxString dir = (projFull != ""? projFull: temp);
   wxFileName newFile = MakeBlockFileName(dir);

   // We assume that the new file should have the same extension
   // as the existing file
   newFile.SetExt(b->GetFileName().GetExt());

   if( !wxCopyFile(b->GetFileName().GetFullPath(), newFile.GetFullPath()) )
      return NULL;

   BlockFile *b2 = b->Copy(newFile);

   if (b2 == NULL)
      return NULL;

   blockFileHash->Put(newFile.GetName(), (wxObject *) b2);
   aliasList.Add(newFile.GetFullPath());

   CheckHashTableSize();

   return b2;
}
コード例 #2
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
// Adds one to the reference count of the block file,
// UNLESS it is "locked", then it makes a new copy of
// the BlockFile.
BlockFile *DirManager::CopyBlockFile(BlockFile *b)
{
   if (!b->IsLocked()) {
      b->Ref();
      return b;
   }

   wxString theFileName;
   wxString thePathName;
   wxString dir = (projFull != ""? projFull: temp);
   MakeBlockFileName(dir, theFileName, thePathName);

   bool ok = wxCopyFile(b->mFullPath, thePathName);
   if (!ok)
      return NULL;

   BlockFile *b2;
   if (b->IsAlias()) {
      b2 = new BlockFile(theFileName, thePathName,
                         b->mLocalLen,
                         b->mAliasFullPath,
                         b->mStart, b->mLen,
                         b->mChannel);
   }
   else {
      b2 = new BlockFile(theFileName, thePathName);
   }

   blockFileHash->Put(theFileName, (wxObject *) b2);
   aliasList.Add(thePathName);

   CheckHashTableSize();

   return b2;
}
コード例 #3
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::NewAliasBlockFile(int localLen,
                                         wxString fullPath,
                                         sampleCount start,
                                         sampleCount len, int channel)
{
   if (projFull == "")
      return NewTempAliasBlockFile(localLen, fullPath, start, len,
                                   channel);

   wxString theFileName;
   wxString thePathName;
   MakeBlockFileName(projFull, theFileName, thePathName);

   BlockFile *newBlockFile = new BlockFile(theFileName, thePathName,
                                           localLen,
                                           fullPath,
                                           start, len, channel);

   blockFileHash->Put(theFileName, (wxObject *) newBlockFile);
   aliasList.Add(fullPath);

   CheckHashTableSize();

   return newBlockFile;
}
コード例 #4
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::LoadBlockFile(wxTextFile * in, sampleFormat format)
{
   wxASSERT(projFull != "");

   long summaryLen;

   if (!(in->GetNextLine().ToLong(&summaryLen)))
      return NULL;

   wxString blockName = in->GetNextLine();

   bool alias = false;
   wxString aliasFullPath;
   long localLen, start, len, channel;

   if (blockName == "Alias") {
      alias = true;
      aliasFullPath = in->GetNextLine();
      
      //if (!(in->GetNextLine().ToLong(&localLen)))
      //   return NULL;

      if (!(in->GetNextLine().ToLong(&start)))
         return NULL;
      if (!(in->GetNextLine().ToLong(&len)))
         return NULL;
      if (!(in->GetNextLine().ToLong(&channel)))
         return NULL;

      blockName = in->GetNextLine();
   }

   wxString pathName = projFull + wxFILE_SEP_PATH + blockName;
   BlockFile *retrieved = (BlockFile *) blockFileHash->Get(blockName);
   if (retrieved) {
      wxASSERT(retrieved->IsAlias() == alias);
      retrieved->Ref();
      return retrieved;
   } else {
      BlockFile *newBlockFile =
         new BlockFile(blockName, pathName, summaryLen);

      if (alias) {
         newBlockFile->SetAliasedData(aliasFullPath, start, len, channel);
         aliasList.Add(aliasFullPath);
      }

      newBlockFile->mSampleFormat = format;

      blockFileHash->Put(blockName, (wxObject *) newBlockFile);

      CheckHashTableSize();

      if (!wxFileExists(pathName))
         return 0;
      return newBlockFile;
   }
}
コード例 #5
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::LoadBlockFile(wxTextFile * in)
{
   wxASSERT(projFull != "");

   wxString blockName = in->GetNextLine();

   bool alias = false;
   wxString aliasFullPath;
   long localLen, start, len, channel;

   if (blockName == "Alias") {
      alias = true;
      aliasFullPath = in->GetNextLine();
      if (!(in->GetNextLine().ToLong(&localLen)))
         return NULL;
      if (!(in->GetNextLine().ToLong(&start)))
         return NULL;
      if (!(in->GetNextLine().ToLong(&len)))
         return NULL;
      if (!(in->GetNextLine().ToLong(&channel)))
         return NULL;

      blockName = in->GetNextLine();
   }

   wxString pathName = projFull + pathChar + blockName;
   BlockFile *retrieved = (BlockFile *) blockFileHash->Get(blockName);
   if (retrieved) {
      wxASSERT(retrieved->IsAlias() == alias);
      retrieved->Ref();
      return retrieved;
   } else {
      BlockFile *newBlockFile;

      if (alias) {
         newBlockFile = new BlockFile(blockName, pathName,
                                      localLen,
                                      aliasFullPath, start, len, channel);

         aliasList.Add(aliasFullPath);
      }
      else
         newBlockFile = new BlockFile(blockName, pathName);

      blockFileHash->Put(blockName, (wxObject *) newBlockFile);

      CheckHashTableSize();

      if (!wxFileExists(pathName))
         return 0;
      return newBlockFile;
   }
}
コード例 #6
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::NewTempBlockFile()
{
   wxString theFileName;
   wxString thePathName;
   MakeBlockFileName(temp, theFileName, thePathName);

   BlockFile *newBlockFile = new BlockFile(theFileName, thePathName);

   blockFileHash->Put(theFileName, (wxObject *) newBlockFile);

   CheckHashTableSize();

   return newBlockFile;
}
コード例 #7
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::NewSimpleBlockFile(
                                 samplePtr sampleData, sampleCount sampleLen,
                                 sampleFormat format)
{
   wxString loc = (projFull != ""? projFull: temp);
   wxFileName fileName = MakeBlockFileName(loc);

   BlockFile *newBlockFile =
       new SimpleBlockFile(fileName, sampleData, sampleLen, format);

   blockFileHash->Put(fileName.GetName(), (wxObject *) newBlockFile);

   CheckHashTableSize();

   return newBlockFile;
}
コード例 #8
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::NewTempBlockFile()
{
  wxString theFileName;
  wxString thePathName;
  do {
    theFileName.Printf("b%05d.vaf",fileIndex++);
    thePathName = temp + pathChar + theFileName;
  } while (wxFileExists(thePathName));

  BlockFile *newBlockFile = new BlockFile(theFileName, thePathName);

  blockFileHash->Put(theFileName, (wxObject *)newBlockFile);

  CheckHashTableSize();

  return newBlockFile;
}
コード例 #9
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::NewAliasBlockFile(
                                 wxString aliasedFile, sampleCount aliasStart,
                                 sampleCount aliasLen, int aliasChannel)
{
   wxString loc = (projFull != ""? projFull: temp);
   wxFileName fileName = MakeBlockFileName(loc);

   BlockFile *newBlockFile =
       new PCMAliasBlockFile(fileName,
                             aliasedFile, aliasStart, aliasLen, aliasChannel);

   blockFileHash->Put(fileName.GetName(), (wxObject *) newBlockFile);
   aliasList.Add(aliasedFile);

   CheckHashTableSize();

   return newBlockFile;
}
コード例 #10
0
ファイル: DirManager.cpp プロジェクト: ruthmagnus/audacity
BlockFile *DirManager::GetBlockFile(wxString &blockName)
{
  wxASSERT(projFull != "");

  wxString pathName = projFull + pathChar + blockName;
  BlockFile *retrieved = (BlockFile *)blockFileHash->Get(blockName);
  if (retrieved) {
    retrieved->Ref();
    return retrieved;
  }
  else {
    BlockFile *newBlockFile = new BlockFile(blockName, pathName);

    blockFileHash->Put(blockName, (wxObject *)newBlockFile); 

    CheckHashTableSize();

    if (!wxFileExists(pathName))
      return 0;
    return newBlockFile;
  }
}
コード例 #11
0
bool DirManager::HandleXMLTag(const char *tag, const char **attrs)
{
    if( mLoadingTarget == NULL )
        return false;

    if( !wxStricmp(tag, "silentblockfile") ) {
        // Silent blocks don't actually have a file associated, so
        // we don't need to worry about the hash table at all
        *mLoadingTarget = SilentBlockFile::BuildFromXML(projFull, attrs);
        return true;
    }

    else if ( !wxStricmp(tag, "simpleblockfile") )
        *mLoadingTarget = SimpleBlockFile::BuildFromXML(projFull, attrs);
    else if( !wxStricmp(tag, "pcmaliasblockfile") )
        *mLoadingTarget = PCMAliasBlockFile::BuildFromXML(projFull, attrs);
    else if( !wxStricmp(tag, "blockfile") ||
             !wxStricmp(tag, "legacyblockfile") ) {
        // Support Audacity version 1.1.1 project files

        int i=0;
        bool alias = false;

        while(attrs[i]) {
            if (!wxStricmp(attrs[i], "alias")) {
                if (atoi(attrs[i+1])==1)
                    alias = true;
            }
            i++;
            if (attrs[i])
                i++;
        }

        if (alias)
            *mLoadingTarget = LegacyAliasBlockFile::BuildFromXML(projFull, attrs);
        else
            *mLoadingTarget = LegacyBlockFile::BuildFromXML(projFull, attrs,
                              mLoadingBlockLen,
                              mLoadingFormat);
    }
    else
        return false;

    //
    // If the block we loaded is already in the hash table, then the
    // object we just loaded is a duplicate, so we delete it and
    // return a reference to the existing object instead.
    //

    wxString name = (*mLoadingTarget)->GetFileName().GetName();
    BlockFile *retrieved = (BlockFile *) blockFileHash->Get(name);
    if (retrieved) {
        // Lock it in order to delete it safely, i.e. without having
        // it delete the file, too...
        (*mLoadingTarget)->Lock();
        delete (*mLoadingTarget);

        Ref(retrieved); // Add one to its reference count
        *mLoadingTarget = retrieved;
        return true;
    }

    // This is a new object
    blockFileHash->Put( name, (wxObject*) *mLoadingTarget );
    CheckHashTableSize();

    return true;
}