mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-26 09:08:44 +02:00
Simplify the label import routine
This commit is contained in:
parent
6062fd08dc
commit
519f4d6cf6
@ -47,6 +47,7 @@ for drawing different aspects of the label and its text box.
|
||||
#include <wx/pen.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/textfile.h>
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
#include "AudioIO.h"
|
||||
@ -2091,14 +2092,7 @@ void LabelTrack::Export(wxTextFile & f) const
|
||||
/// Import labels, handling files with or without end-times.
|
||||
void LabelTrack::Import(wxTextFile & in)
|
||||
{
|
||||
wxString currentLine;
|
||||
int i, i2,len;
|
||||
int index, lines;
|
||||
wxString s,s1;
|
||||
wxString title;
|
||||
double t0,t1;
|
||||
|
||||
lines = in.GetLineCount();
|
||||
int lines = in.GetLineCount();
|
||||
|
||||
mLabels.clear();
|
||||
mLabels.reserve(lines);
|
||||
@ -2106,66 +2100,32 @@ void LabelTrack::Import(wxTextFile & in)
|
||||
//Currently, we expect a tag file to have two values and a label
|
||||
//on each line. If the second token is not a number, we treat
|
||||
//it as a single-value label.
|
||||
for (index = 0; index < lines; index++) {
|
||||
currentLine = in.GetLine(index);
|
||||
for (int index = 0; index < lines; index++) {
|
||||
wxString currentLine = in.GetLine(index);
|
||||
|
||||
len = currentLine.Length();
|
||||
if (len == 0)
|
||||
return;
|
||||
// Assume tab is an impossible character within the exported text
|
||||
// of the label, so can be only a delimiter. But other white space may
|
||||
// be part of the label text.
|
||||
wxStringTokenizer toker { currentLine, wxT("\t") };
|
||||
|
||||
//get the timepoint of the left edge of the label.
|
||||
i = 0;
|
||||
while (i < len && currentLine.GetChar(i) != wxT(' ')
|
||||
&& currentLine.GetChar(i) != wxT('\t'))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
s = currentLine.Left(i);
|
||||
auto token = toker.GetNextToken();
|
||||
|
||||
if (!Internat::CompatibleToDouble(s, &t0))
|
||||
double t0;
|
||||
if (!Internat::CompatibleToDouble(token, &t0))
|
||||
return;
|
||||
|
||||
//Increment one letter.
|
||||
i++;
|
||||
token = toker.GetNextToken();
|
||||
|
||||
//Now, go until we find the start of the get the next token
|
||||
while (i < len
|
||||
&& (currentLine.GetChar(i) == wxT(' ')
|
||||
|| currentLine.GetChar(i) == wxT('\t')))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
//Keep track of the start of the second token
|
||||
i2=i;
|
||||
|
||||
//Now, go to the end of the second token.
|
||||
while (i < len && currentLine.GetChar(i) != wxT(' ')
|
||||
&& currentLine.GetChar(i) != wxT('\t'))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
//We are at the end of the second token.
|
||||
s1 = currentLine.Mid(i2,i-i2+1).Strip(wxString::stripType(0x3));
|
||||
if (!Internat::CompatibleToDouble(s1, &t1))
|
||||
{
|
||||
double t1;
|
||||
if (!Internat::CompatibleToDouble(token, &t1))
|
||||
//s1 is not a number.
|
||||
t1 = t0; //This is a one-sided label; t1 == t0.
|
||||
|
||||
//Because s1 is not a number, the label should be
|
||||
//The rest of the line, starting at i2;
|
||||
title = currentLine.Right(len - i2).Strip(wxString::stripType(0x3)); //0x3 indicates both
|
||||
}
|
||||
else
|
||||
{
|
||||
//s1 is a number, and it is stored correctly in t1.
|
||||
//The title should be the remainder of the line,
|
||||
//After we eat
|
||||
token = toker.GetNextToken();
|
||||
|
||||
//Get rid of spaces at either end
|
||||
title = currentLine.Right(len - i).Strip(wxString::stripType(0x3)); //0x3 indicates both.
|
||||
wxString title = token;
|
||||
|
||||
}
|
||||
// PRL: to do: import other selection fields
|
||||
LabelStruct l { SelectedRegion(t0, t1), title };
|
||||
mLabels.push_back(l);
|
||||
|
Loading…
x
Reference in New Issue
Block a user