Audacity 3.2.0
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 28 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 51 of file LabelTrack.h.

Constructor & Destructor Documentation

◆ LabelStruct() [1/3]

LabelStruct::LabelStruct ( )
default

◆ LabelStruct() [2/3]

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

Definition at line 306 of file LabelTrack.cpp.

308: selectedRegion(region)
309, title(aTitle)
310{
311 updated = false;
312 width = 0;
313 x = 0;
314 x1 = 0;
315 xText = 0;
316 y = 0;
317}
int x1
Pixel position of left hand glyph.
Definition: LabelTrack.h:75
int x
width of the text in pixels.
Definition: LabelTrack.h:74
wxString title
Definition: LabelTrack.h:70
SelectedRegion selectedRegion
Definition: LabelTrack.h:69
bool updated
Pixel position of label.
Definition: LabelTrack.h:79
int width
Text of the label.
Definition: LabelTrack.h:71
int xText
Pixel position of right hand glyph.
Definition: LabelTrack.h:76
int y
Pixel position of left hand side of text box.
Definition: LabelTrack.h:77

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

322: selectedRegion(region)
323, title(aTitle)
324{
325 // Overwrite the times
326 selectedRegion.setTimes(t0, t1);
327
328 updated = false;
329 width = 0;
330 x = 0;
331 x1 = 0;
332 xText = 0;
333 y = 0;
334}
bool setTimes(double t0, double t1)

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

356{
357 updated = true;
358 if( iEdge < 0 )
359 return selectedRegion.setT0(fNewTime);
360 else
361 return selectedRegion.setT1(fNewTime);
362}
bool setT0(double t, bool maySwap=true)
bool setT1(double t, bool maySwap=true)

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

494{
495 file.AddLine(wxString::Format(wxT("%s\t%s\t%s"),
496 Internat::ToString(getT0(), FLT_DIG),
497 Internat::ToString(getT1(), FLT_DIG),
498 title
499 ));
500
501 // Do we need more lines?
502 auto f0 = selectedRegion.f0();
503 auto f1 = selectedRegion.f1();
507 return;
508
509 // Write a \ character at the start of a second line,
510 // so that earlier versions of Audacity ignore it.
511 file.AddLine(wxString::Format(wxT("\\\t%s\t%s"),
512 Internat::ToString(f0, FLT_DIG),
513 Internat::ToString(f1, FLT_DIG)
514 ));
515
516 // Additional lines in future formats should also start with '\'.
517}
wxT("CloseDown"))
Enum ReadEnum() const
Definition: Prefs.h:532
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
double getT1() const
Definition: LabelTrack.h:40
double getT0() const
Definition: LabelTrack.h:39
static const int UndefinedFrequency
static EnumSetting< bool > LabelStyleSetting
Definition: LabelTrack.cpp:384

References getT0(), getT1(), anonymous_namespace{LabelTrack.cpp}::LabelStyleSetting, EnumSetting< Enum >::ReadEnum(), selectedRegion, title, Internat::ToString(), SelectedRegion::UndefinedFrequency, and wxT().

Here is the call graph for this function:

◆ getDuration()

double LabelStruct::getDuration ( ) const
inline

Definition at line 38 of file LabelTrack.h.

38{ return selectedRegion.duration(); }
double duration() const

Referenced by MoveLabel().

Here is the caller graph for this function:

◆ getSelectedRegion()

const SelectedRegion & LabelStruct::getSelectedRegion ( ) const
inline

Definition at line 37 of file LabelTrack.h.

37{ return selectedRegion; }

◆ getT0()

double LabelStruct::getT0 ( ) const
inline

Definition at line 39 of file LabelTrack.h.

39{ return selectedRegion.t0(); }
double t0() const

Referenced by 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 40 of file LabelTrack.h.

40{ return selectedRegion.t1(); }
double t1() const

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

422{
424 wxString title;
425 static const wxString continuation{ wxT("\\") };
426
427 wxString firstLine = file.GetLine(index++);
428
429 {
430 // Assume tab is an impossible character within the exported text
431 // of the label, so can be only a delimiter. But other white space may
432 // be part of the label text.
433 wxStringTokenizer toker { firstLine, wxT("\t") };
434
435 //get the timepoint of the left edge of the label.
436 auto token = toker.GetNextToken();
437
438 double t0;
439 if (!Internat::CompatibleToDouble(token, &t0))
440 throw BadFormatException{};
441
442 token = toker.GetNextToken();
443
444 double t1;
445 if (!Internat::CompatibleToDouble(token, &t1))
446 //s1 is not a number.
447 t1 = t0; //This is a one-sided label; t1 == t0.
448 else
449 token = toker.GetNextToken();
450
451 sr.setTimes( t0, t1 );
452
453 title = token;
454 }
455
456 // Newer selection fields are written on additional lines beginning with
457 // '\' which is an impossible numerical character that older versions of
458 // audacity will ignore. Test for the presence of such a line and then
459 // parse it if we can.
460
461 // There may also be additional continuation lines from future formats that
462 // we ignore.
463
464 // Advance index over all continuation lines first, before we might throw
465 // any exceptions.
466 int index2 = index;
467 while (index < (int)file.GetLineCount() &&
468 file.GetLine(index).StartsWith(continuation))
469 ++index;
470
471 if (index2 < index) {
472 wxStringTokenizer toker { file.GetLine(index2++), wxT("\t") };
473 auto token = toker.GetNextToken();
474 if (token != continuation)
475 throw BadFormatException{};
476
477 token = toker.GetNextToken();
478 double f0;
479 if (!Internat::CompatibleToDouble(token, &f0))
480 throw BadFormatException{};
481
482 token = toker.GetNextToken();
483 double f1;
484 if (!Internat::CompatibleToDouble(token, &f1))
485 throw BadFormatException{};
486
487 sr.setFrequencies(f0, f1);
488 }
489
490 return LabelStruct{ sr, title };
491}
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:133
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:29
Defines a selected portion of a project.

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

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

366{
367 double fTimeSpan = getDuration();
368
369 if( iEdge < 0 )
370 {
371 selectedRegion.setTimes(fNewTime, fNewTime+fTimeSpan);
372 }
373 else
374 {
375 selectedRegion.setTimes(fNewTime-fTimeSpan, fNewTime);
376 }
377 updated = true;
378}
double getDuration() const
Definition: LabelTrack.h:38

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

522{
523 bool retainLabels = false;
524
525 wxASSERT(reg_t0 <= reg_t1);
526 gPrefs->Read(wxT("/GUI/RetainLabels"), &retainLabels);
527
528 if(retainLabels) {
529
530 // Desired behavior for edge cases: The length of the selection is smaller
531 // than the length of the label if the selection is within the label or
532 // matching exactly a (region) label.
533
534 if (reg_t0 < getT0() && reg_t1 > getT1())
535 return SURROUNDS_LABEL;
536 else if (reg_t1 < getT0())
537 return BEFORE_LABEL;
538 else if (reg_t0 > getT1())
539 return AFTER_LABEL;
540
541 else if (reg_t0 >= getT0() && reg_t0 <= getT1() &&
542 reg_t1 >= getT0() && reg_t1 <= getT1())
543 return WITHIN_LABEL;
544
545 else if (reg_t0 >= getT0() && reg_t0 <= getT1())
546 return BEGINS_IN_LABEL;
547 else
548 return ENDS_IN_LABEL;
549
550 } else {
551
552 // AWD: Desired behavior for edge cases: point labels bordered by the
553 // selection are included within it. Region labels are included in the
554 // selection to the extent that the selection covers them; specifically,
555 // they're not included at all if the selection borders them, and they're
556 // fully included if the selection covers them fully, even if it just
557 // borders their endpoints. This is just one of many possible schemes.
558
559 // The first test catches bordered point-labels and selected-through
560 // region-labels; move it to third and selection edges become inclusive
561 // WRT point-labels.
562 if (reg_t0 <= getT0() && reg_t1 >= getT1())
563 return SURROUNDS_LABEL;
564 else if (reg_t1 <= getT0())
565 return BEFORE_LABEL;
566 else if (reg_t0 >= getT1())
567 return AFTER_LABEL;
568
569 // At this point, all point labels should have returned.
570
571 else if (reg_t0 > getT0() && reg_t0 < getT1() &&
572 reg_t1 > getT0() && reg_t1 < getT1())
573 return WITHIN_LABEL;
574
575 // Knowing that none of the other relations match simplifies remaining
576 // tests
577 else if (reg_t0 > getT0() && reg_t0 < getT1())
578 return BEGINS_IN_LABEL;
579 else
580 return ENDS_IN_LABEL;
581
582 }
583}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
virtual bool Read(const wxString &key, bool *value) const =0

References gPrefs, audacity::BasicSettings::Read(), and wxT().

Here is the call graph for this function:

Member Data Documentation

◆ selectedRegion

SelectedRegion LabelStruct::selectedRegion

◆ title

wxString LabelStruct::title

◆ updated

bool LabelStruct::updated {}

Pixel position of label.

Definition at line 79 of file LabelTrack.h.

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

◆ width

int LabelStruct::width {}
mutable

Text of the label.

Definition at line 71 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 74 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 75 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: