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 269 of file LabelTrack.cpp.

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

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 282 of file LabelTrack.cpp.

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

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 347 of file LabelTrack.cpp.

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

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 444 of file LabelTrack.cpp.

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

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 372 of file LabelTrack.cpp.

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

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 357 of file LabelTrack.cpp.

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

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 470 of file LabelTrack.cpp.

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

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::DrawBar(), LabelTrackView::DrawGlyphs(), LabelTrackView::DrawLines(), and LabelStruct().

◆ x1

int LabelStruct::x1 {}
mutable

Pixel position of left hand glyph.

Definition at line 76 of file LabelTrack.h.

Referenced by LabelTrackView::DrawBar(), LabelTrackView::DrawGlyphs(), LabelTrackView::DrawLines(), 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:70
LabelStruct::x
int x
width of the text in pixels.
Definition: LabelTrack.h:75
SelectedRegion::t1
double t1() const
Definition: SelectedRegion.h:92
SelectedRegion::setTimes
bool setTimes(double t0, double t1)
Definition: SelectedRegion.h:136
SelectedRegion::UndefinedFrequency
static const int UndefinedFrequency
Definition: SelectedRegion.h:41
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:112
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:93
SelectedRegion::t0
double t0() const
Definition: SelectedRegion.h:91
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:151
LabelStruct::getT1
double getT1() const
Definition: LabelTrack.h:41
SelectedRegion::setT1
bool setT1(double t, bool maySwap=true)
Definition: SelectedRegion.h:124
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:35