mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-26 17:18:41 +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/pen.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#include <wx/textfile.h>
|
#include <wx/textfile.h>
|
||||||
|
#include <wx/tokenzr.h>
|
||||||
#include <wx/utils.h>
|
#include <wx/utils.h>
|
||||||
|
|
||||||
#include "AudioIO.h"
|
#include "AudioIO.h"
|
||||||
@ -2091,14 +2092,7 @@ void LabelTrack::Export(wxTextFile & f) const
|
|||||||
/// Import labels, handling files with or without end-times.
|
/// Import labels, handling files with or without end-times.
|
||||||
void LabelTrack::Import(wxTextFile & in)
|
void LabelTrack::Import(wxTextFile & in)
|
||||||
{
|
{
|
||||||
wxString currentLine;
|
int lines = in.GetLineCount();
|
||||||
int i, i2,len;
|
|
||||||
int index, lines;
|
|
||||||
wxString s,s1;
|
|
||||||
wxString title;
|
|
||||||
double t0,t1;
|
|
||||||
|
|
||||||
lines = in.GetLineCount();
|
|
||||||
|
|
||||||
mLabels.clear();
|
mLabels.clear();
|
||||||
mLabels.reserve(lines);
|
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
|
//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
|
//on each line. If the second token is not a number, we treat
|
||||||
//it as a single-value label.
|
//it as a single-value label.
|
||||||
for (index = 0; index < lines; index++) {
|
for (int index = 0; index < lines; index++) {
|
||||||
currentLine = in.GetLine(index);
|
wxString currentLine = in.GetLine(index);
|
||||||
|
|
||||||
len = currentLine.Length();
|
// Assume tab is an impossible character within the exported text
|
||||||
if (len == 0)
|
// of the label, so can be only a delimiter. But other white space may
|
||||||
return;
|
// be part of the label text.
|
||||||
|
wxStringTokenizer toker { currentLine, wxT("\t") };
|
||||||
|
|
||||||
//get the timepoint of the left edge of the label.
|
//get the timepoint of the left edge of the label.
|
||||||
i = 0;
|
auto token = toker.GetNextToken();
|
||||||
while (i < len && currentLine.GetChar(i) != wxT(' ')
|
|
||||||
&& currentLine.GetChar(i) != wxT('\t'))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
s = currentLine.Left(i);
|
|
||||||
|
|
||||||
if (!Internat::CompatibleToDouble(s, &t0))
|
double t0;
|
||||||
|
if (!Internat::CompatibleToDouble(token, &t0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Increment one letter.
|
token = toker.GetNextToken();
|
||||||
i++;
|
|
||||||
|
|
||||||
//Now, go until we find the start of the get the next token
|
double t1;
|
||||||
while (i < len
|
if (!Internat::CompatibleToDouble(token, &t1))
|
||||||
&& (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))
|
|
||||||
{
|
|
||||||
//s1 is not a number.
|
//s1 is not a number.
|
||||||
t1 = t0; //This is a one-sided label; t1 == t0.
|
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
|
else
|
||||||
{
|
token = toker.GetNextToken();
|
||||||
//s1 is a number, and it is stored correctly in t1.
|
|
||||||
//The title should be the remainder of the line,
|
|
||||||
//After we eat
|
|
||||||
|
|
||||||
//Get rid of spaces at either end
|
wxString title = token;
|
||||||
title = currentLine.Right(len - i).Strip(wxString::stripType(0x3)); //0x3 indicates both.
|
|
||||||
|
|
||||||
}
|
|
||||||
// PRL: to do: import other selection fields
|
// PRL: to do: import other selection fields
|
||||||
LabelStruct l { SelectedRegion(t0, t1), title };
|
LabelStruct l { SelectedRegion(t0, t1), title };
|
||||||
mLabels.push_back(l);
|
mLabels.push_back(l);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user