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, LabelFormat format, int index) 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, LabelFormat format)
 

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 36 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 59 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 309 of file LabelTrack.cpp.

311: selectedRegion(region)
312, title(aTitle)
313{
314 updated = false;
315 width = 0;
316 x = 0;
317 x1 = 0;
318 xText = 0;
319 y = 0;
320}
int x1
Pixel position of left hand glyph.
Definition: LabelTrack.h:83
int x
width of the text in pixels.
Definition: LabelTrack.h:82
wxString title
Definition: LabelTrack.h:78
SelectedRegion selectedRegion
Definition: LabelTrack.h:77
bool updated
Pixel position of label.
Definition: LabelTrack.h:87
int width
Text of the label.
Definition: LabelTrack.h:79
int xText
Pixel position of right hand glyph.
Definition: LabelTrack.h:84
int y
Pixel position of left hand side of text box.
Definition: LabelTrack.h:85

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

325: selectedRegion(region)
326, title(aTitle)
327{
328 // Overwrite the times
329 selectedRegion.setTimes(t0, t1);
330
331 updated = false;
332 width = 0;
333 x = 0;
334 x1 = 0;
335 xText = 0;
336 y = 0;
337}
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 357 of file LabelTrack.cpp.

358{
359 updated = true;
360 if( iEdge < 0 )
361 return selectedRegion.setT0(fNewTime);
362 else
363 return selectedRegion.setT1(fNewTime);
364}
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,
LabelFormat  format,
int  index 
) const

Definition at line 575 of file LabelTrack.cpp.

576{
577 switch (format) {
579 default:
580 {
581 file.AddLine(wxString::Format(wxT("%s\t%s\t%s"),
582 Internat::ToString(getT0(), FLT_DIG),
583 Internat::ToString(getT1(), FLT_DIG),
584 title
585 ));
586
587 // Do we need more lines?
588 auto f0 = selectedRegion.f0();
589 auto f1 = selectedRegion.f1();
593 return;
594
595 // Write a \ character at the start of a second line,
596 // so that earlier versions of Audacity ignore it.
597 file.AddLine(wxString::Format(wxT("\\\t%s\t%s"),
598 Internat::ToString(f0, FLT_DIG),
599 Internat::ToString(f1, FLT_DIG)
600 ));
601
602 // Additional lines in future formats should also start with '\'.
603 break;
604 }
607 {
608 // Note that the identifier is optional in WebVTT, but required in SubRip.
609 // We include it for both.
610 file.AddLine(wxString::Format(wxT("%d"), index + 1));
611
612 file.AddLine(wxString::Format(wxT("%s --> %s"),
615
616 file.AddLine(title);
617 file.AddLine(wxT(""));
618
619 break;
620 }
621 }
622}
wxT("CloseDown"))
static wxString SubRipTimestampFromDouble(double timestamp, bool webvtt)
Definition: LabelTrack.cpp:558
Enum ReadEnum() const
Definition: Prefs.h:534
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:126
double getT1() const
Definition: LabelTrack.h:48
double getT0() const
Definition: LabelTrack.h:47
double f0() const
double f1() const
static const int UndefinedFrequency
static EnumSetting< bool > LabelStyleSetting
Definition: LabelTrack.cpp:386

References SelectedRegion::f0(), SelectedRegion::f1(), anonymous_namespace{ExportPCM.cpp}::format, getT0(), getT1(), anonymous_namespace{LabelTrack.cpp}::LabelStyleSetting, EnumSetting< Enum >::ReadEnum(), selectedRegion, SUBRIP, SubRipTimestampFromDouble(), TEXT, title, Internat::ToString(), SelectedRegion::UndefinedFrequency, WEBVTT, and wxT().

Here is the call graph for this function:

◆ getDuration()

double LabelStruct::getDuration ( ) const
inline

Definition at line 46 of file LabelTrack.h.

46{ 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 45 of file LabelTrack.h.

45{ return selectedRegion; }

◆ getT0()

double LabelStruct::getT0 ( ) const
inline

Definition at line 47 of file LabelTrack.h.

47{ 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 48 of file LabelTrack.h.

48{ 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,
LabelFormat  format 
)
static

Definition at line 439 of file LabelTrack.cpp.

440{
442 wxString title;
443
444 wxString firstLine = file.GetLine(index++);
445
446 switch (format) {
448 {
449 static const wxString continuation{ wxT("\\") };
450
451 {
452 // Assume tab is an impossible character within the exported text
453 // of the label, so can be only a delimiter. But other white space may
454 // be part of the label text.
455 wxStringTokenizer toker { firstLine, wxT("\t") };
456
457 //get the timepoint of the left edge of the label.
458 auto token = toker.GetNextToken();
459
460 double t0;
461 if (!Internat::CompatibleToDouble(token, &t0))
462 throw BadFormatException{};
463
464 token = toker.GetNextToken();
465
466 double t1;
467 if (!Internat::CompatibleToDouble(token, &t1))
468 //s1 is not a number.
469 t1 = t0; //This is a one-sided label; t1 == t0.
470 else
471 token = toker.GetNextToken();
472
473 sr.setTimes( t0, t1 );
474
475 title = token;
476 }
477
478 // Newer selection fields are written on additional lines beginning with
479 // '\' which is an impossible numerical character that older versions of
480 // audacity will ignore. Test for the presence of such a line and then
481 // parse it if we can.
482
483 // There may also be additional continuation lines from future formats that
484 // we ignore.
485
486 // Advance index over all continuation lines first, before we might throw
487 // any exceptions.
488 int index2 = index;
489 while (index < (int)file.GetLineCount() &&
490 file.GetLine(index).StartsWith(continuation))
491 ++index;
492
493 if (index2 < index) {
494 wxStringTokenizer toker { file.GetLine(index2++), wxT("\t") };
495 auto token = toker.GetNextToken();
496 if (token != continuation)
497 throw BadFormatException{};
498
499 token = toker.GetNextToken();
500 double f0;
501 if (!Internat::CompatibleToDouble(token, &f0))
502 throw BadFormatException{};
503
504 token = toker.GetNextToken();
505 double f1;
506 if (!Internat::CompatibleToDouble(token, &f1))
507 throw BadFormatException{};
508
509 sr.setFrequencies(f0, f1);
510 }
511 break;
512 }
514 {
515 if ((int)file.GetLineCount() < index + 2)
516 throw BadFormatException{};
517
518 long identifier;
519 // The first line should be a numeric counter; we can ignore it otherwise
520 if (!firstLine.ToLong(&identifier))
521 throw BadFormatException{};
522
523 wxString timestamp = file.GetLine(index++);
524 // Parsing data of the form 'HH:MM:SS,sss --> HH:MM:SS,sss'
525 // Assume that the line is in exactly that format, with no extra whitespace
526 // and less than 24 hours.
527 if (timestamp.length() != 29)
528 throw BadFormatException{};
529 if (!timestamp.substr(12, 5).IsSameAs(" --> "))
530 throw BadFormatException{};
531
532 double t0 = SubRipTimestampToDouble(timestamp.substr(0, 12));
533 double t1 = SubRipTimestampToDouble(timestamp.substr(17, 12));
534
535 sr.setTimes(t0, t1);
536
537 // Assume that if there is an empty subtitle, there still is a second
538 // blank line after it
539 title = file[index++];
540
541 // Labels in audacity should be only one line, so join multiple lines
542 // with spaces. This is not reversed on export.
543 while (index < (int)file.GetLineCount() &&
544 !file.GetLine(index).IsEmpty())
545 title += " " + file.GetLine(index);
546
547 index++; // Skip over empty line
548
549 break;
550 }
551 default:
552 throw BadFormatException{};
553 }
554
555 return LabelStruct{ sr, title };
556}
static double SubRipTimestampToDouble(const wxString &ts)
Definition: LabelTrack.cpp:427
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:109
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:37
Defines a selected portion of a project.
bool setFrequencies(double f0, double f1)

References Internat::CompatibleToDouble(), anonymous_namespace{ExportPCM.cpp}::format, SelectedRegion::setFrequencies(), SelectedRegion::setTimes(), SUBRIP, SubRipTimestampToDouble(), TEXT, 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 367 of file LabelTrack.cpp.

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

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

627{
628 bool retainLabels = false;
629
630 wxASSERT(reg_t0 <= reg_t1);
631 gPrefs->Read(wxT("/GUI/RetainLabels"), &retainLabels);
632
633 if(retainLabels) {
634
635 // Desired behavior for edge cases: The length of the selection is smaller
636 // than the length of the label if the selection is within the label or
637 // matching exactly a (region) label.
638
639 if (reg_t0 < getT0() && reg_t1 > getT1())
640 return SURROUNDS_LABEL;
641 else if (reg_t1 < getT0())
642 return BEFORE_LABEL;
643 else if (reg_t0 > getT1())
644 return AFTER_LABEL;
645
646 else if (reg_t0 >= getT0() && reg_t0 <= getT1() &&
647 reg_t1 >= getT0() && reg_t1 <= getT1())
648 return WITHIN_LABEL;
649
650 else if (reg_t0 >= getT0() && reg_t0 <= getT1())
651 return BEGINS_IN_LABEL;
652 else
653 return ENDS_IN_LABEL;
654
655 } else {
656
657 // AWD: Desired behavior for edge cases: point labels bordered by the
658 // selection are included within it. Region labels are included in the
659 // selection to the extent that the selection covers them; specifically,
660 // they're not included at all if the selection borders them, and they're
661 // fully included if the selection covers them fully, even if it just
662 // borders their endpoints. This is just one of many possible schemes.
663
664 // The first test catches bordered point-labels and selected-through
665 // region-labels; move it to third and selection edges become inclusive
666 // WRT point-labels.
667 if (reg_t0 <= getT0() && reg_t1 >= getT1())
668 return SURROUNDS_LABEL;
669 else if (reg_t1 <= getT0())
670 return BEFORE_LABEL;
671 else if (reg_t0 >= getT1())
672 return AFTER_LABEL;
673
674 // At this point, all point labels should have returned.
675
676 else if (reg_t0 > getT0() && reg_t0 < getT1() &&
677 reg_t1 > getT0() && reg_t1 < getT1())
678 return WITHIN_LABEL;
679
680 // Knowing that none of the other relations match simplifies remaining
681 // tests
682 else if (reg_t0 > getT0() && reg_t0 < getT1())
683 return BEGINS_IN_LABEL;
684 else
685 return ENDS_IN_LABEL;
686
687 }
688}
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 87 of file LabelTrack.h.

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

◆ width

int LabelStruct::width {}
mutable

Text of the label.

Definition at line 79 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 82 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 83 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: