Audacity  3.0.3
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
LabelStruct Class Reference

A LabelStruct holds information for ONE label in a LabelTrack. More...

#include <LabelTrack.h>

Collaboration diagram for LabelStruct:
[legend]

Classes

struct  BadFormatException
 

Public Types

enum  TimeRelations {
  BEFORE_LABEL, AFTER_LABEL, SURROUNDS_LABEL, WITHIN_LABEL,
  BEGINS_IN_LABEL, ENDS_IN_LABEL
}
 Relationships between selection region and labels. More...
 

Public Member Functions

 LabelStruct ()=default
 
 LabelStruct (const SelectedRegion &region, const wxString &aTitle)
 
 LabelStruct (const SelectedRegion &region, double t0, double t1, const wxString &aTitle)
 
const SelectedRegiongetSelectedRegion () const
 
double getDuration () const
 
double getT0 () const
 
double getT1 () const
 
bool AdjustEdge (int iEdge, double fNewTime)
 
void MoveLabel (int iEdge, double fNewTime)
 
void Export (wxTextFile &file) const
 
TimeRelations RegionRelation (double reg_t0, double reg_t1, const LabelTrack *parent=NULL) const
 

Static Public Member Functions

static LabelStruct Import (wxTextFile &file, int &index)
 

Public Attributes

SelectedRegion selectedRegion
 
wxString title
 
int width {}
 Text of the label. More...
 
int x {}
 width of the text in pixels. More...
 
int x1 {}
 Pixel position of left hand glyph. More...
 
int xText {}
 Pixel position of right hand glyph. More...
 
int y {}
 Pixel position of left hand side of text box. More...
 
bool updated {}
 Pixel position of label. More...
 

Detailed Description

A LabelStruct holds information for ONE label in a LabelTrack.

LabelStruct also has label specific functions, mostly functions for drawing different aspects of the label and its text box.

Definition at line 29 of file LabelTrack.h.

Member Enumeration Documentation

◆ TimeRelations

Relationships between selection region and labels.

Enumerator
BEFORE_LABEL 
AFTER_LABEL 
SURROUNDS_LABEL 
WITHIN_LABEL 
BEGINS_IN_LABEL 
ENDS_IN_LABEL 

Definition at line 52 of file LabelTrack.h.

53  {
60  };

Constructor & Destructor Documentation

◆ LabelStruct() [1/3]

LabelStruct::LabelStruct ( )
default

◆ LabelStruct() [2/3]

LabelStruct::LabelStruct ( const SelectedRegion region,
const wxString &  aTitle 
)

Definition at line 268 of file LabelTrack.cpp.

270 : selectedRegion(region)
271 , title(aTitle)
272 {
273  updated = false;
274  width = 0;
275  x = 0;
276  x1 = 0;
277  xText = 0;
278  y = 0;
279 }

References updated, width, x, x1, xText, and y.

◆ LabelStruct() [3/3]

LabelStruct::LabelStruct ( const SelectedRegion region,
double  t0,
double  t1,
const wxString &  aTitle 
)

Definition at line 281 of file LabelTrack.cpp.

284 : selectedRegion(region)
285 , title(aTitle)
286 {
287  // Overwrite the times
288  selectedRegion.setTimes(t0, t1);
289 
290  updated = false;
291  width = 0;
292  x = 0;
293  x1 = 0;
294  xText = 0;
295  y = 0;
296 }

References selectedRegion, SelectedRegion::setTimes(), updated, width, x, x1, xText, and y.

Here is the call graph for this function:

Member Function Documentation

◆ AdjustEdge()

bool LabelStruct::AdjustEdge ( int  iEdge,
double  fNewTime 
)

Definition at line 346 of file LabelTrack.cpp.

347 {
348  updated = true;
349  if( iEdge < 0 )
350  return selectedRegion.setT0(fNewTime);
351  else
352  return selectedRegion.setT1(fNewTime);
353 }

References selectedRegion, SelectedRegion::setT0(), SelectedRegion::setT1(), and updated.

Here is the call graph for this function:

◆ Export()

void LabelStruct::Export ( wxTextFile &  file) const

Definition at line 443 of file LabelTrack.cpp.

444 {
445  file.AddLine(wxString::Format(wxT("%s\t%s\t%s"),
446  Internat::ToString(getT0(), FLT_DIG),
447  Internat::ToString(getT1(), FLT_DIG),
448  title
449  ));
450 
451  // Do we need more lines?
452  auto f0 = selectedRegion.f0();
453  auto f1 = selectedRegion.f1();
457  return;
458 
459  // Write a \ character at the start of a second line,
460  // so that earlier versions of Audacity ignore it.
461  file.AddLine(wxString::Format(wxT("\\\t%s\t%s"),
462  Internat::ToString(f0, FLT_DIG),
463  Internat::ToString(f1, FLT_DIG)
464  ));
465 
466  // Additional lines in future formats should also start with '\'.
467 }

References getT0(), getT1(), ImportExportPrefs::LabelStyleSetting, selectedRegion, title, Internat::ToString(), and SelectedRegion::UndefinedFrequency.

Here is the call graph for this function:

◆ getDuration()

double LabelStruct::getDuration ( ) const
inline

Definition at line 39 of file LabelTrack.h.

39 { return selectedRegion.duration(); }

Referenced by MoveLabel().

Here is the caller graph for this function:

◆ getSelectedRegion()

const SelectedRegion& LabelStruct::getSelectedRegion ( ) const
inline

Definition at line 38 of file LabelTrack.h.

38 { return selectedRegion; }

◆ getT0()

double LabelStruct::getT0 ( ) const
inline

Definition at line 40 of file LabelTrack.h.

40 { return selectedRegion.t0(); }

Referenced by LyricsPanel::AddLabels(), LabelTrackView::DrawLines(), Export(), and anonymous_namespace{LabelMenus.cpp}::GetRegionsByLabel().

Here is the caller graph for this function:

◆ getT1()

double LabelStruct::getT1 ( ) const
inline

Definition at line 41 of file LabelTrack.h.

41 { return selectedRegion.t1(); }

Referenced by LabelTrackView::DrawLines(), Export(), and anonymous_namespace{LabelMenus.cpp}::GetRegionsByLabel().

Here is the caller graph for this function:

◆ Import()

LabelStruct LabelStruct::Import ( wxTextFile &  file,
int &  index 
)
static

Definition at line 371 of file LabelTrack.cpp.

372 {
373  SelectedRegion sr;
374  wxString title;
375  static const wxString continuation{ wxT("\\") };
376 
377  wxString firstLine = file.GetLine(index++);
378 
379  {
380  // Assume tab is an impossible character within the exported text
381  // of the label, so can be only a delimiter. But other white space may
382  // be part of the label text.
383  wxStringTokenizer toker { firstLine, wxT("\t") };
384 
385  //get the timepoint of the left edge of the label.
386  auto token = toker.GetNextToken();
387 
388  double t0;
389  if (!Internat::CompatibleToDouble(token, &t0))
390  throw BadFormatException{};
391 
392  token = toker.GetNextToken();
393 
394  double t1;
395  if (!Internat::CompatibleToDouble(token, &t1))
396  //s1 is not a number.
397  t1 = t0; //This is a one-sided label; t1 == t0.
398  else
399  token = toker.GetNextToken();
400 
401  sr.setTimes( t0, t1 );
402 
403  title = token;
404  }
405 
406  // Newer selection fields are written on additional lines beginning with
407  // '\' which is an impossible numerical character that older versions of
408  // audacity will ignore. Test for the presence of such a line and then
409  // parse it if we can.
410 
411  // There may also be additional continuation lines from future formats that
412  // we ignore.
413 
414  // Advance index over all continuation lines first, before we might throw
415  // any exceptions.
416  int index2 = index;
417  while (index < (int)file.GetLineCount() &&
418  file.GetLine(index).StartsWith(continuation))
419  ++index;
420 
421  if (index2 < index) {
422  wxStringTokenizer toker { file.GetLine(index2++), wxT("\t") };
423  auto token = toker.GetNextToken();
424  if (token != continuation)
425  throw BadFormatException{};
426 
427  token = toker.GetNextToken();
428  double f0;
429  if (!Internat::CompatibleToDouble(token, &f0))
430  throw BadFormatException{};
431 
432  token = toker.GetNextToken();
433  double f1;
434  if (!Internat::CompatibleToDouble(token, &f1))
435  throw BadFormatException{};
436 
437  sr.setFrequencies(f0, f1);
438  }
439 
440  return LabelStruct{ sr, title };
441 }

References Internat::CompatibleToDouble(), SelectedRegion::setTimes(), and title.

Referenced by LabelTrack::Import().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MoveLabel()

void LabelStruct::MoveLabel ( int  iEdge,
double  fNewTime 
)

Definition at line 356 of file LabelTrack.cpp.

357 {
358  double fTimeSpan = getDuration();
359 
360  if( iEdge < 0 )
361  {
362  selectedRegion.setTimes(fNewTime, fNewTime+fTimeSpan);
363  }
364  else
365  {
366  selectedRegion.setTimes(fNewTime-fTimeSpan, fNewTime);
367  }
368  updated = true;
369 }

References getDuration(), selectedRegion, SelectedRegion::setTimes(), and updated.

Here is the call graph for this function:

◆ RegionRelation()

auto LabelStruct::RegionRelation ( double  reg_t0,
double  reg_t1,
const LabelTrack parent = NULL 
) const

Returns relationship between a region described and this label; if parent is set, it will consider point labels at the very beginning and end of parent to be within a region that borders them (this makes it possible to DELETE capture all labels with a Select All).

Definition at line 469 of file LabelTrack.cpp.

472 {
473  bool retainLabels = false;
474 
475  wxASSERT(reg_t0 <= reg_t1);
476  gPrefs->Read(wxT("/GUI/RetainLabels"), &retainLabels);
477 
478  if(retainLabels) {
479 
480  // Desired behavior for edge cases: The length of the selection is smaller
481  // than the length of the label if the selection is within the label or
482  // matching exactly a (region) label.
483 
484  if (reg_t0 < getT0() && reg_t1 > getT1())
485  return SURROUNDS_LABEL;
486  else if (reg_t1 < getT0())
487  return BEFORE_LABEL;
488  else if (reg_t0 > getT1())
489  return AFTER_LABEL;
490 
491  else if (reg_t0 >= getT0() && reg_t0 <= getT1() &&
492  reg_t1 >= getT0() && reg_t1 <= getT1())
493  return WITHIN_LABEL;
494 
495  else if (reg_t0 >= getT0() && reg_t0 <= getT1())
496  return BEGINS_IN_LABEL;
497  else
498  return ENDS_IN_LABEL;
499 
500  } else {
501 
502  // AWD: Desired behavior for edge cases: point labels bordered by the
503  // selection are included within it. Region labels are included in the
504  // selection to the extent that the selection covers them; specifically,
505  // they're not included at all if the selection borders them, and they're
506  // fully included if the selection covers them fully, even if it just
507  // borders their endpoints. This is just one of many possible schemes.
508 
509  // The first test catches bordered point-labels and selected-through
510  // region-labels; move it to third and selection edges become inclusive
511  // WRT point-labels.
512  if (reg_t0 <= getT0() && reg_t1 >= getT1())
513  return SURROUNDS_LABEL;
514  else if (reg_t1 <= getT0())
515  return BEFORE_LABEL;
516  else if (reg_t0 >= getT1())
517  return AFTER_LABEL;
518 
519  // At this point, all point labels should have returned.
520 
521  else if (reg_t0 > getT0() && reg_t0 < getT1() &&
522  reg_t1 > getT0() && reg_t1 < getT1())
523  return WITHIN_LABEL;
524 
525  // Knowing that none of the other relations match simplifies remaining
526  // tests
527  else if (reg_t0 > getT0() && reg_t0 < getT1())
528  return BEGINS_IN_LABEL;
529  else
530  return ENDS_IN_LABEL;
531 
532  }
533 }

References gPrefs.

Member Data Documentation

◆ selectedRegion

SelectedRegion LabelStruct::selectedRegion

◆ title

wxString LabelStruct::title

◆ updated

bool LabelStruct::updated {}

Pixel position of label.

Definition at line 80 of file LabelTrack.h.

Referenced by AdjustEdge(), LabelStruct(), and MoveLabel().

◆ width

int LabelStruct::width {}
mutable

Text of the label.

Definition at line 72 of file LabelTrack.h.

Referenced by LabelTrackView::DrawText(), LabelTrackView::DrawTextBox(), LabelStruct(), and LabelTrackView::OverTextBox().

◆ x

int LabelStruct::x {}
mutable

width of the text in pixels.

Definition at line 75 of file LabelTrack.h.

Referenced by LabelTrackView::DrawGlyphs(), LabelTrackView::DrawLines(), LabelTrackView::DrawTextBox(), and LabelStruct().

◆ x1

int LabelStruct::x1 {}
mutable

Pixel position of left hand glyph.

Definition at line 76 of file LabelTrack.h.

Referenced by LabelTrackView::DrawGlyphs(), LabelTrackView::DrawLines(), LabelTrackView::DrawTextBox(), and LabelStruct().

◆ xText

int LabelStruct::xText {}
mutable

◆ y

int LabelStruct::y {}
mutable

The documentation for this class was generated from the following files:
LabelStruct::x1
int x1
Pixel position of left hand glyph.
Definition: LabelTrack.h:76
LabelStruct::getDuration
double getDuration() const
Definition: LabelTrack.h:39
LabelStruct::ENDS_IN_LABEL
@ ENDS_IN_LABEL
Definition: LabelTrack.h:59
LabelStruct::width
int width
Text of the label.
Definition: LabelTrack.h:72
LabelStruct::title
wxString title
Definition: LabelTrack.h:71
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:68
LabelStruct::x
int x
width of the text in pixels.
Definition: LabelTrack.h:75
SelectedRegion::t1
double t1() const
Definition: SelectedRegion.h:95
SelectedRegion::setTimes
bool setTimes(double t0, double t1)
Definition: SelectedRegion.h:139
SelectedRegion::UndefinedFrequency
static const int UndefinedFrequency
Definition: SelectedRegion.h:44
LabelStruct
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:30
LabelStruct::WITHIN_LABEL
@ WITHIN_LABEL
Definition: LabelTrack.h:57
LabelStruct::y
int y
Pixel position of left hand side of text box.
Definition: LabelTrack.h:78
SelectedRegion::setT0
bool setT0(double t, bool maySwap=true)
Definition: SelectedRegion.h:115
LabelStruct::selectedRegion
SelectedRegion selectedRegion
Definition: LabelTrack.h:70
LabelStruct::getT0
double getT0() const
Definition: LabelTrack.h:40
LabelStruct::BEFORE_LABEL
@ BEFORE_LABEL
Definition: LabelTrack.h:54
LabelStruct::BEGINS_IN_LABEL
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:58
SelectedRegion::duration
double duration() const
Definition: SelectedRegion.h:96
SelectedRegion::t0
double t0() const
Definition: SelectedRegion.h:94
LabelStruct::updated
bool updated
Pixel position of label.
Definition: LabelTrack.h:80
LabelStruct::AFTER_LABEL
@ AFTER_LABEL
Definition: LabelTrack.h:55
ImportExportPrefs::LabelStyleSetting
static EnumSetting< bool > LabelStyleSetting
Definition: ImportExportPrefs.h:30
LabelStruct::xText
int xText
Pixel position of right hand glyph.
Definition: LabelTrack.h:77
LabelStruct::SURROUNDS_LABEL
@ SURROUNDS_LABEL
Definition: LabelTrack.h:56
Internat::ToString
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:150
LabelStruct::getT1
double getT1() const
Definition: LabelTrack.h:41
SelectedRegion::setT1
bool setT1(double t, bool maySwap=true)
Definition: SelectedRegion.h:127
Internat::CompatibleToDouble
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:134
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:38