Import Label Text

Quite often I will have a text file which has all the track titles:

First song name
second song name
third song name

I have used an Analyzer or my own senses to put a blank label at the beginning of each song. It would be nice to automatically insert the title from the text file right into the labels. As a turns out this is a trivial bit of programming:
In file LabelDialog.h, at or near line number 59:

   void OnImport(wxCommandEvent &event);
   void OnTextImport(wxCommandEvent &WXUNUSED(pEvent));//efm5
   void OnExport(wxCommandEvent &event);

add the new line labeled with //efm5
in the file LabelDialog.cpp, at or near line number 76:

   ID_REMOVE,
   ID_TEXTIMPORT,//efm5
   ID_IMPORT,

add the new line labeled with //efm5
At or near line number 87:

   EVT_BUTTON(ID_REMOVE,  LabelDialog::OnRemove)
   EVT_BUTTON(ID_TEXTIMPORT,  LabelDialog::OnTextImport)//efm5
   EVT_BUTTON(ID_IMPORT,  LabelDialog::OnImport)

add the new line labeled with //efm5
at or near line number 134:

   hs->Add(new wxButton(this, ID_REMOVE,  _("&Remove")), 1, wxCENTER | wxALL, 5);
   //efm5  start 
   hs->Add(new wxButton(this, ID_TEXTIMPORT,  _("Import Label Texts...")), 1, wxCENTER | wxALL, 5);
   hs->Add(new wxButton(this, ID_IMPORT,  _("&Import Labels...")), 1, wxCENTER | wxALL, 5);
   //efm5  end 
   hs->Add(new wxButton(this, ID_EXPORT,  _("&Export...")), 1, wxCENTER | wxALL, 5);

add the first line (with ID_TEXTIMPORT, _(“Import Label Texts…”)
And modify the second line so that we know that we are importing labels not label text (between the comments //efm5 start & //efm5 end )
at or near line number 529 add the new function which does all the work:

//efm5  start 
void LabelDialog::OnTextImport(wxCommandEvent &WXUNUSED(pEvent))
{
   wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd());

   // Ask user for a filename
   wxString fileName =
       FileSelector(_("Select a text file containing label texts..."),
                    path,     // Path
                    wxT(""),       // Name
                    wxT(".txt"),   // Extension
                    _("Text files (*.txt)|*.txt|All files (*.*)|*.*"),
                    wxRESIZE_BORDER, // Flags
                    this);    // Parent

   // They gave us one...
   if (fileName != wxT("")) {
      //efm5 start
      fileName.Replace(wxT("|"), wxT("\"));
      if (fileName.Last() == '\') fileName = fileName.BeforeLast('\');
      //efm5 end
      path =::wxPathOnly(fileName);
      gPrefs->Write(wxT("/DefaultOpenPath"), path);

      wxTextFile textFile;

      // Get at the data
      textFile.Open(fileName);
      if (!textFile.IsOpened()) {
         wxMessageBox(_("Could not open file: ") + fileName);
      }
      else {
         size_t numberOfLabels = mData.GetCount();
         size_t linesInFile = textFile.GetLineCount();
         if (linesInFile == numberOfLabels) {
            for (size_t i = 0; i < linesInFile; i++) {
               wxString fileString = textFile.GetLine(i);
               RowData * rowData = mData.Item(i);
               rowData->title = fileString;
            }
         }
         else if (linesInFile > numberOfLabels) {
            wxMessageBox(_("The number of lines in the filenis greater than the number of labels."));
         }
         else { //linesInFile < numberOfLabels
            wxMessageBox(_("The number of lines in the filenis less than the number of labels."));
         }
     }

      // Repopulate the grid
      TransferDataToWindow();
   }
}
//efm5  end

LT.png

Hi Ed,
My new Album Track Marker is starting to look like it could be accurate enough, at least on “non-difficult” albums, to be able to provide something useful in relation to this.

What I’m thinking, is for a version of Album Track Marker (optional download) that allows pasting plain text into a text box in the plug-in GUI that contains a list of track labels. The ATM would then look for the specified number of tracks in the recording and insert the appropriate label text into each label.

The pasted text would need to be appropriately formatted so that the plug-in knows where one label ends and the next one starts. Probably the simplest way would be as a line separated list, thus you could prepare the list in the form:

Track 1. blah blah blah...
Track 2. blah blah blah...
Track 3. blah blah blah...
The text does not matter but this is a new line so it is a new label.

Normal characters should be no problem, but there may be some limitations regarding Unicode characters and escape characters.

A really simple (to code) alternative that could work 100% reliably (but with the same limitations for Unicode and escape characters), would be if you knew the precise time positions of the labels and included that in the pasted text file. For example:

0
Track 1. blah blah blah...
3 12
2nd trackk blah blah blah...
324.5
Next track blah blah...

where the time is entered in seconds or minutes and seconds.
I’ve used space separated values in the example above because space separated values are easiest for Nyquist to read, but other formats would be possible.

If you think that either of these ideas would be useful, I’ll code something up for you to try.
The “Album Track Marker” is not quite accurate enough for this yet, but it is getting very close. Also, I’ve only worked on splitting vinyl recordings so far - CD and tape transfers to follow eventually.

Sometimes you need an ax, sometimes an hatchet sometimes a chainsaw. I find my solution incredibly useful for my needs but I have not tried ATM in its current implementation - eagerly awaiting the next beta!

I’m on alpha versions at the moment (no error checking, possible bugs, and a failure just fails with no explanation unless you can work out the cryptic debug info), but the next alpha should be pretty effective.

Ed,

is this a feature you are thinking of adding?

Or a proposal you are thinking of writing?

I doesn’t really look like something I can just transfer over usefully to Wiki>PFR

I can archive it here 0 or move it to say Audio Processing??

Peter.

Its a feature I’ve been using now for a while in my highly personalized custom version of Audacity. It is only a few lines of code and all of the code was included in my original post. A proposal written by me would be a death knell .

I must admit I’m completely baffled about why y’all insist on removing feature requests – especially those with code attached – from the forum; I’m even more baffled why y’all seem to think they belong in Audio Processing which has nothing to do with GUI interface feature request (when the offering does).

Do with it whatever you feel is appropriate.