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 SelectedRegion & getSelectedRegion () 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 39 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 62 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 335 of file LabelTrack.cpp.

337: selectedRegion(region)
338, title(aTitle)
339{
340 updated = false;
341 width = 0;
342 x = 0;
343 x1 = 0;
344 xText = 0;
345 y = 0;
346}
int x1
Pixel position of left hand glyph.
Definition: LabelTrack.h:86
int x
width of the text in pixels.
Definition: LabelTrack.h:85
wxString title
Definition: LabelTrack.h:81
SelectedRegion selectedRegion
Definition: LabelTrack.h:80
bool updated
Pixel position of label.
Definition: LabelTrack.h:90
int width
Text of the label.
Definition: LabelTrack.h:82
int xText
Pixel position of right hand glyph.
Definition: LabelTrack.h:87
int y
Pixel position of left hand side of text box.
Definition: LabelTrack.h:88

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

351: selectedRegion(region)
352, title(aTitle)
353{
354 // Overwrite the times
355 selectedRegion.setTimes(t0, t1);
356
357 updated = false;
358 width = 0;
359 x = 0;
360 x1 = 0;
361 xText = 0;
362 y = 0;
363}
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 383 of file LabelTrack.cpp.

384{
385 updated = true;
386 if( iEdge < 0 )
387 return selectedRegion.setT0(fNewTime);
388 else
389 return selectedRegion.setT1(fNewTime);
390}
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 556 of file LabelTrack.cpp.

557{
558 switch (format) {
560 default:
561 {
562 file.AddLine(wxString::Format(wxT("%s\t%s\t%s"),
563 Internat::ToString(getT0(), FLT_DIG),
564 Internat::ToString(getT1(), FLT_DIG),
565 title
566 ));
567
568 // Do we need more lines?
569 auto f0 = selectedRegion.f0();
570 auto f1 = selectedRegion.f1();
574 return;
575
576 // Write a \ character at the start of a second line,
577 // so that earlier versions of Audacity ignore it.
578 file.AddLine(wxString::Format(wxT("\\\t%s\t%s"),
579 Internat::ToString(f0, FLT_DIG),
580 Internat::ToString(f1, FLT_DIG)
581 ));
582
583 // Additional lines in future formats should also start with '\'.
584 break;
585 }
588 {
589 // Note that the identifier is optional in WebVTT, but required in SubRip.
590 // We include it for both.
591 file.AddLine(wxString::Format(wxT("%d"), index + 1));
592
593 file.AddLine(wxString::Format(wxT("%s --> %s"),
596
597 file.AddLine(title);
598 file.AddLine(wxT(""));
599
600 break;
601 }
602 }
603}
wxT("CloseDown"))
static wxString SubRipTimestampFromDouble(double timestamp, bool webvtt)
Definition: LabelTrack.cpp:539
EnumSetting< bool > LabelStyleSetting
Definition: LabelTrack.cpp:51
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:51
double getT0() const
Definition: LabelTrack.h:50
double f0() const
double f1() const
static const int UndefinedFrequency

References SelectedRegion::f0(), SelectedRegion::f1(), anonymous_namespace{ExportPCM.cpp}::format, getT0(), getT1(), 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 49 of file LabelTrack.h.

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

48{ return selectedRegion; }

◆ getT0()

double LabelStruct::getT0 ( ) const
inline

Definition at line 50 of file LabelTrack.h.

50{ 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 51 of file LabelTrack.h.

51{ 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 420 of file LabelTrack.cpp.

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

394{
395 double fTimeSpan = getDuration();
396
397 if( iEdge < 0 )
398 {
399 selectedRegion.setTimes(fNewTime, fNewTime+fTimeSpan);
400 }
401 else
402 {
403 selectedRegion.setTimes(fNewTime-fTimeSpan, fNewTime);
404 }
405 updated = true;
406}
double getDuration() const
Definition: LabelTrack.h:49

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

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

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

◆ width

int LabelStruct::width {}
mutable

Text of the label.

Definition at line 82 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 85 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 86 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: