示例#1
0
void KeyConfigPrefs::OnSave(wxCommandEvent& event)
{
   Apply();

   wxString fName = wxT("Audacity-keys.xml");
   wxString path = gPrefs->Read(wxT("/DefaultExportPath"),
                                ::wxGetCwd());

   fName = FileSelector(_("Export Keyboard Shortcuts As:"),
                        NULL,
                        fName,
                        wxT("xml"),
                        wxT("*.xml"), wxSAVE | wxOVERWRITE_PROMPT, this);

   if (!fName)
      return;

   path = wxPathOnly(fName);
   gPrefs->Write(wxT("/DefaultExportPath"), path);

   XMLFileWriter prefFile;
   
   prefFile.Open(fName, wxT("wb"));

   if (!prefFile.IsOpened()) {
      wxMessageBox(_("Couldn't write to file: ") + fName,
                   _("Error saving keyboard shortcuts"),
                   wxOK | wxCENTRE, this);
      return;
   }

   mManager->WriteXML(prefFile);

   prefFile.Close();
}
void FFmpegPresets::ExportPresets(wxString &filename)
{
   XMLFileWriter writer;
   writer.Open(filename,wxT("wb"));
   WriteXMLHeader(writer);
   WriteXML(writer);
}
FFmpegPresets::~FFmpegPresets()
{
   XMLFileWriter writer;
   wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
   writer.Open(xmlFileName.GetFullPath(),wxT("wb"));
   WriteXMLHeader(writer);
   WriteXML(writer);
   delete mPresets;
}
示例#4
0
void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event))
{
   wxString file = wxT("Audacity-keys.xml");
   wxString path = gPrefs->Read(wxT("/DefaultExportPath"),
                                ::wxGetCwd());

   file = FileSelector(_("Export Keyboard Shortcuts As:"),
                       path,
                       file,
                       wxT("xml"),
                       _("XML files (*.xml)|*.xml|All files|*"),
                       wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
                       this);

   if (!file) {
      return;
   }

   path = wxPathOnly(file);
   gPrefs->Write(wxT("/DefaultExportPath"), path);
   gPrefs->Flush();

   XMLFileWriter prefFile;

   try
   {
      prefFile.Open(file, wxT("wb"));
      mManager->WriteXML(prefFile);
      prefFile.Close();
   }
   catch (const XMLFileWriterException &)
   {
      wxMessageBox(_("Couldn't write to file: ") + file,
                   _("Error Exporting Keyboard Shortcuts"),
                   wxOK | wxCENTRE, this);
   }
}
示例#5
0
void TagsEditor::OnSave(wxCommandEvent & event)
{
   wxString fn;

   // Refresh tags
   TransferDataFromWindow();

   // Ask the user for the real name
   fn = FileSelector(_("Save Metadata As:"),
                     FileNames::DataDir(),
                     wxT("Tags.xml"),
                     wxT("xml"),
                     wxT("*.xml"),
                     wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
                     this);

   // User canceled...
   if (fn.IsEmpty()) {
      return;
   }

   // Create/Open the file
   XMLFileWriter writer;

   try
   {
      writer.Open(fn, wxT("wb"));

      // Remember title and track in case they're read only
      wxString title = mLocal.GetTag(TAG_TITLE);
      wxString track = mLocal.GetTag(TAG_TRACK);

      // Clear title
      if (!mEditTitle) {
         mLocal.SetTag(TAG_TITLE, wxEmptyString);
      }

      // Clear track
      if (!mEditTrack) {
         mLocal.SetTag(TAG_TRACK, wxEmptyString);
      }

      // Write the metadata
      mLocal.WriteXML(writer);

      // Restore title
      if (!mEditTitle) {
         mLocal.SetTag(TAG_TITLE, title);
      }

      // Restore track
      if (!mEditTrack) {
         mLocal.SetTag(TAG_TRACK, track);
      }

      // Close the file
      writer.Close();
   }
   catch (XMLFileWriterException* pException)
   {
      wxMessageBox(wxString::Format(
         _("Couldn't write to file \"%s\": %s"),
         fn.c_str(), pException->GetMessage().c_str()),
         _("Error Saving Tags File"), wxICON_ERROR, this);

      delete pException;
   }
}
示例#6
0
void VSTEffectDialog::OnSave(wxCommandEvent & evt)
{
   int i = mProgram->GetCurrentSelection();
   wxString fn;

   // Ask the user for the real name
   fn = FileSelector(_("Save VST Program As:"),
                     FileNames::DataDir(),
                     mProgram->GetValue() + wxT(".xml"),
                     wxT("xml"),
                     wxT("*.xml"),
                     wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
                     this);

   // User canceled...
   if (fn.IsEmpty()) {
      return;
   }

   XMLFileWriter xmlFile;

   // Create/Open the file
   xmlFile.Open(fn, wxT("wb"));

   xmlFile.StartTag(wxT("vstprogrampersistence"));
   xmlFile.WriteAttr(wxT("version"), wxT("1"));

   i = mEffect->callDispatcher(effGetVendorVersion, 0, 0, NULL, 0.0);
   xmlFile.StartTag(wxT("effect"));
   xmlFile.WriteAttr(wxT("name"), mEffect->GetEffectIdentifier());
   xmlFile.WriteAttr(wxT("version"), i);

   xmlFile.StartTag(wxT("program"));
   xmlFile.WriteAttr(wxT("name"), mProgram->GetValue());

   long clen = 0;
   if (mAEffect->flags & effFlagsProgramChunks) {
      void *chunk = NULL;

      clen = mEffect->callDispatcher(effGetChunk, 1, 0, &chunk, 0.0);
      if (clen != 0) {
         xmlFile.StartTag(wxT("chunk"));
         xmlFile.WriteSubTree(b64encode(chunk, clen) + wxT('\n'));
         xmlFile.EndTag(wxT("chunk"));
      }
   }

   if (clen == 0) {
      for (i = 0; i < mAEffect->numParams; i++) {
         xmlFile.StartTag(wxT("param"));

         xmlFile.WriteAttr(wxT("index"), i);
         xmlFile.WriteAttr(wxT("name"),
                           mEffect->GetString(effGetParamName, i));
         xmlFile.WriteAttr(wxT("value"),
                           wxString::Format(wxT("%f"),
                           mEffect->callGetParameter(i)));

         xmlFile.EndTag(wxT("param"));
      }
   }

   xmlFile.EndTag(wxT("program"));

   xmlFile.EndTag(wxT("effect"));

   xmlFile.EndTag(wxT("vstprogrampersistence"));

   // Close the file
   xmlFile.Close();
}
示例#7
0
bool ConvertLegacyTrack(wxTextFile *f, XMLFileWriter &xmlFile)
{
   wxString line;
   wxString kind;

   kind = (*f)[f->GetCurrentLine()];

   if (kind == wxT("WaveTrack")) {
      xmlFile.StartTag(wxT("wavetrack"));
      xmlFile.WriteAttr(wxT("name"), f->GetNextLine());

      wxString channel = f->GetNextLine();
      if (channel == wxT("left")) {
         xmlFile.WriteAttr(wxT("channel"), 0);
         line = f->GetNextLine();
      }
      else if (channel == wxT("right")) {
         xmlFile.WriteAttr(wxT("channel"), 1);
         line = f->GetNextLine();
      }
      else if (channel == wxT("mono")) {
         xmlFile.WriteAttr(wxT("channel"), 2);
         line = f->GetNextLine();
      }
      else {
         xmlFile.WriteAttr(wxT("channel"), 2);
         line = channel;
      }

      if (line == wxT("linked")) {
         xmlFile.WriteAttr(wxT("linked"), 1);
         line = f->GetNextLine();
      }

      if (line != wxT("offset"))
         return false;
      xmlFile.WriteAttr(wxT("offset"), f->GetNextLine());

      long envLen;

      if (f->GetNextLine() != wxT("EnvNumPoints"))
         return false;
      line = f->GetNextLine();
      line.ToLong(&envLen);
      if (envLen < 0 || envLen > 10000)
         return false;

      size_t envStart = f->GetCurrentLine();
      if (f->GetLineCount() < envStart+(2*envLen)+1)
         return false;

      f->GoToLine(envStart+(2*envLen));
      if (f->GetNextLine() != wxT("EnvEnd"))
         return false;
      if (f->GetNextLine() != wxT("numSamples"))
         return false;

      wxString numSamples = f->GetNextLine();

      if (f->GetNextLine() != wxT("rate"))
         return false;

      xmlFile.WriteAttr(wxT("rate"), f->GetNextLine());

      if (envLen > 0) {
         xmlFile.StartTag(wxT("envelope"));
         xmlFile.WriteAttr(wxT("numpoints"), envLen);

         long i;
         for(i=0; i<envLen; i++) {
            xmlFile.StartTag(wxT("controlpoint"));
            xmlFile.WriteAttr(wxT("t"), f->GetLine(envStart + 2*i + 1));
            xmlFile.WriteAttr(wxT("val"), f->GetLine(envStart + 2*i + 2));
            xmlFile.EndTag(wxT("controlpoint"));
         }

         xmlFile.EndTag(wxT("envelope"));
      }

      if (f->GetNextLine() != wxT("numBlocks"))
         return false;
      long numBlocks;
      line = f->GetNextLine();
      line.ToLong(&numBlocks);

      if (numBlocks < 0 || numBlocks > 131072)
         return false;

      xmlFile.StartTag(wxT("sequence"));
      xmlFile.WriteAttr(wxT("maxsamples"), 524288);
      xmlFile.WriteAttr(wxT("sampleformat"), 131073);
      xmlFile.WriteAttr(wxT("numsamples"), numSamples);

      long b;
      for(b=0; b<numBlocks; b++) {
         wxString start;
         wxString len;
         wxString name;

         if (f->GetNextLine() != wxT("Block start"))
            return false;
         start = f->GetNextLine();
         if (f->GetNextLine() != wxT("Block len"))
            return false;
         len = f->GetNextLine(); 
         if (f->GetNextLine() != wxT("Block info"))
            return false;
         name = f->GetNextLine();

         xmlFile.StartTag(wxT("waveblock"));
         xmlFile.WriteAttr(wxT("start"), start);

         xmlFile.StartTag(wxT("legacyblockfile"));
         if (name == wxT("Alias")) {
            wxString aliasPath = f->GetNextLine();
            wxString localLen = f->GetNextLine();
            wxString aliasStart = f->GetNextLine();
            wxString aliasLen = f->GetNextLine();
            wxString aliasChannel = f->GetNextLine();
            wxString localName = f->GetNextLine();

            xmlFile.WriteAttr(wxT("name"), localName);
            xmlFile.WriteAttr(wxT("alias"), 1);
            xmlFile.WriteAttr(wxT("aliaspath"), aliasPath);
            xmlFile.WriteAttr(wxT("aliasstart"), aliasStart);
            xmlFile.WriteAttr(wxT("aliaslen"), aliasLen);
            xmlFile.WriteAttr(wxT("aliaschannel"), aliasChannel);
            xmlFile.WriteAttr(wxT("summarylen"), localLen);
            xmlFile.WriteAttr(wxT("norms"), 1);
         }
         else {
            xmlFile.WriteAttr(wxT("name"), name);
            xmlFile.WriteAttr(wxT("len"), len);
            xmlFile.WriteAttr(wxT("summarylen"), 8244);
            xmlFile.WriteAttr(wxT("norms"), 1);
         }
         xmlFile.EndTag(wxT("legacyblockfile"));

         xmlFile.EndTag(wxT("waveblock"));
      }

      xmlFile.EndTag(wxT("sequence"));
      xmlFile.EndTag(wxT("wavetrack"));
      
      return true;
   }
   else if (kind == wxT("LabelTrack")) {
      line = f->GetNextLine();
      if (line != wxT("NumMLabels"))
         return false;

      long numLabels, l;

      line = f->GetNextLine();
      line.ToLong(&numLabels);
      if (numLabels < 0 || numLabels > 1000000)
         return false;

      xmlFile.StartTag(wxT("labeltrack"));
      xmlFile.WriteAttr(wxT("name"), wxT("Labels"));
      xmlFile.WriteAttr(wxT("numlabels"), numLabels);

      for(l=0; l<numLabels; l++) {
         wxString t, title;

         t = f->GetNextLine();
         title = f->GetNextLine();

         xmlFile.StartTag(wxT("label"));
         xmlFile.WriteAttr(wxT("t"), t);
         xmlFile.WriteAttr(wxT("title"), title);
         xmlFile.EndTag(wxT("label"));
      }

      xmlFile.EndTag(wxT("labeltrack"));

      line = f->GetNextLine();
      if (line != wxT("MLabelsEnd"))
         return false;

      return true;
   }
   else if (kind == wxT("NoteTrack")) {
      // Just skip over it - they didn't even work in version 1.0!

      do {
         line = f->GetNextLine();
         if (line == wxT("WaveTrack") ||
             line == wxT("NoteTrack") ||
             line == wxT("LabelTrack") ||
             line == wxT("EndTracks")) {
            f->GoToLine(f->GetCurrentLine()-1);
            return true;
         }
      } while (f->GetCurrentLine() < f->GetLineCount());

      return false;
   }
   else
      return false;
}
示例#8
0
bool ConvertLegacyProjectFile(wxFileName filename)
{
   wxTextFile f;
   XMLFileWriter xmlFile;
   int index = 0;
   wxString backupName;

   do {
      index++;
      fflush(stdout);
      backupName = filename.GetPath() + wxFILE_SEP_PATH + filename.GetName() +
         wxT("_bak") + wxString::Format(wxT("%d"), index) + wxT(".") + filename.GetExt();
   } while(::wxFileExists(backupName));

   // This will move the original file out of the way, but 
   // move it back if we exit from this function early.
   AutoRollbackRenamer renamer(filename.GetFullPath(), backupName);
   if (!renamer.RenameSucceeded())
      return false;

   f.Open(backupName);
   if (!f.IsOpened())
      return false;

   wxString name = filename.GetFullPath();

   try
   {
      xmlFile.Open(name, wxT("wb"));
   }
   catch (XMLFileWriterException* pException)
   {
      delete pException;
      return false;
   }

   renamer.SetNewFile(xmlFile.fp());

   try
   {
      xmlFile.Write(wxT("<?xml version=\"1.0\"?>\n"));

      wxString label;
      wxString value;

      if (f.GetFirstLine() != wxT("AudacityProject"))
         return false;
      if (f.GetNextLine() != wxT("Version"))
         return false;
      if (f.GetNextLine() != wxT("0.95"))
         return false;
      if (f.GetNextLine() != wxT("projName"))
         return false;

      xmlFile.StartTag(wxT("audacityproject"));
      xmlFile.WriteAttr(wxT("projname"), f.GetNextLine());
      xmlFile.WriteAttr(wxT("version"), wxT("1.1.0"));
      xmlFile.WriteAttr(wxT("audacityversion"),AUDACITY_VERSION_STRING);

      label = f.GetNextLine();
      while (label != wxT("BeginTracks")) {
         xmlFile.WriteAttr(label, f.GetNextLine());
         label = f.GetNextLine();
      }

      label = f.GetNextLine();
      while (label != wxT("EndTracks")) {
         bool success = ConvertLegacyTrack(&f, xmlFile);
         if (!success)
            return false;
         label = f.GetNextLine();
      }

      xmlFile.EndTag(wxT("audacityproject"));
      xmlFile.Close();
   }
   catch (XMLFileWriterException* pException)
   {
      // Error writing XML file (e.g. disk full)
      delete pException;
      return false;
   }

   renamer.Finished();

   ::wxMessageBox(wxString::Format(_("Converted a 1.0 project file to the new format.\nThe old file has been saved as '%s'"), backupName.c_str()),
                  _("Opening Audacity Project"));

   return true;
}