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