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

296: selectedRegion(region)
297, title(aTitle)
298{
299 updated = false;
300 width = 0;
301 x = 0;
302 x1 = 0;
303 xText = 0;
304 y = 0;
305}
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 307 of file LabelTrack.cpp.

310: selectedRegion(region)
311, title(aTitle)
312{
313 // Overwrite the times
314 selectedRegion.setTimes(t0, t1);
315
316 updated = false;
317 width = 0;
318 x = 0;
319 x1 = 0;
320 xText = 0;
321 y = 0;
322}
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 371 of file LabelTrack.cpp.

372{
373 updated = true;
374 if( iEdge < 0 )
375 return selectedRegion.setT0(fNewTime);
376 else
377 return selectedRegion.setT1(fNewTime);
378}
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 468 of file LabelTrack.cpp.

469{
470 file.AddLine(wxString::Format(wxT("%s\t%s\t%s"),
471 Internat::ToString(getT0(), FLT_DIG),
472 Internat::ToString(getT1(), FLT_DIG),
473 title
474 ));
475
476 // Do we need more lines?
477 auto f0 = selectedRegion.f0();
478 auto f1 = selectedRegion.f1();
482 return;
483
484 // Write a \ character at the start of a second line,
485 // so that earlier versions of Audacity ignore it.
486 file.AddLine(wxString::Format(wxT("\\\t%s\t%s"),
487 Internat::ToString(f0, FLT_DIG),
488 Internat::ToString(f1, FLT_DIG)
489 ));
490
491 // Additional lines in future formats should also start with '\'.
492}
wxT("CloseDown"))
static EnumSetting< bool > LabelStyleSetting
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

References getT0(), getT1(), ImportExportPrefs::LabelStyleSetting, 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 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 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 396 of file LabelTrack.cpp.

397{
399 wxString title;
400 static const wxString continuation{ wxT("\\") };
401
402 wxString firstLine = file.GetLine(index++);
403
404 {
405 // Assume tab is an impossible character within the exported text
406 // of the label, so can be only a delimiter. But other white space may
407 // be part of the label text.
408 wxStringTokenizer toker { firstLine, wxT("\t") };
409
410 //get the timepoint of the left edge of the label.
411 auto token = toker.GetNextToken();
412
413 double t0;
414 if (!Internat::CompatibleToDouble(token, &t0))
415 throw BadFormatException{};
416
417 token = toker.GetNextToken();
418
419 double t1;
420 if (!Internat::CompatibleToDouble(token, &t1))
421 //s1 is not a number.
422 t1 = t0; //This is a one-sided label; t1 == t0.
423 else
424 token = toker.GetNextToken();
425
426 sr.setTimes( t0, t1 );
427
428 title = token;
429 }
430
431 // Newer selection fields are written on additional lines beginning with
432 // '\' which is an impossible numerical character that older versions of
433 // audacity will ignore. Test for the presence of such a line and then
434 // parse it if we can.
435
436 // There may also be additional continuation lines from future formats that
437 // we ignore.
438
439 // Advance index over all continuation lines first, before we might throw
440 // any exceptions.
441 int index2 = index;
442 while (index < (int)file.GetLineCount() &&
443 file.GetLine(index).StartsWith(continuation))
444 ++index;
445
446 if (index2 < index) {
447 wxStringTokenizer toker { file.GetLine(index2++), wxT("\t") };
448 auto token = toker.GetNextToken();
449 if (token != continuation)
450 throw BadFormatException{};
451
452 token = toker.GetNextToken();
453 double f0;
454 if (!Internat::CompatibleToDouble(token, &f0))
455 throw BadFormatException{};
456
457 token = toker.GetNextToken();
458 double f1;
459 if (!Internat::CompatibleToDouble(token, &f1))
460 throw BadFormatException{};
461
462 sr.setFrequencies(f0, f1);
463 }
464
465 return LabelStruct{ sr, title };
466}
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 381 of file LabelTrack.cpp.

382{
383 double fTimeSpan = getDuration();
384
385 if( iEdge < 0 )
386 {
387 selectedRegion.setTimes(fNewTime, fNewTime+fTimeSpan);
388 }
389 else
390 {
391 selectedRegion.setTimes(fNewTime-fTimeSpan, fNewTime);
392 }
393 updated = true;
394}
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 494 of file LabelTrack.cpp.

497{
498 bool retainLabels = false;
499
500 wxASSERT(reg_t0 <= reg_t1);
501 gPrefs->Read(wxT("/GUI/RetainLabels"), &retainLabels);
502
503 if(retainLabels) {
504
505 // Desired behavior for edge cases: The length of the selection is smaller
506 // than the length of the label if the selection is within the label or
507 // matching exactly a (region) label.
508
509 if (reg_t0 < getT0() && reg_t1 > getT1())
510 return SURROUNDS_LABEL;
511 else if (reg_t1 < getT0())
512 return BEFORE_LABEL;
513 else if (reg_t0 > getT1())
514 return AFTER_LABEL;
515
516 else if (reg_t0 >= getT0() && reg_t0 <= getT1() &&
517 reg_t1 >= getT0() && reg_t1 <= getT1())
518 return WITHIN_LABEL;
519
520 else if (reg_t0 >= getT0() && reg_t0 <= getT1())
521 return BEGINS_IN_LABEL;
522 else
523 return ENDS_IN_LABEL;
524
525 } else {
526
527 // AWD: Desired behavior for edge cases: point labels bordered by the
528 // selection are included within it. Region labels are included in the
529 // selection to the extent that the selection covers them; specifically,
530 // they're not included at all if the selection borders them, and they're
531 // fully included if the selection covers them fully, even if it just
532 // borders their endpoints. This is just one of many possible schemes.
533
534 // The first test catches bordered point-labels and selected-through
535 // region-labels; move it to third and selection edges become inclusive
536 // WRT point-labels.
537 if (reg_t0 <= getT0() && reg_t1 >= getT1())
538 return SURROUNDS_LABEL;
539 else if (reg_t1 <= getT0())
540 return BEFORE_LABEL;
541 else if (reg_t0 >= getT1())
542 return AFTER_LABEL;
543
544 // At this point, all point labels should have returned.
545
546 else if (reg_t0 > getT0() && reg_t0 < getT1() &&
547 reg_t1 > getT0() && reg_t1 < getT1())
548 return WITHIN_LABEL;
549
550 // Knowing that none of the other relations match simplifies remaining
551 // tests
552 else if (reg_t0 > getT0() && reg_t0 < getT1())
553 return BEGINS_IN_LABEL;
554 else
555 return ENDS_IN_LABEL;
556
557 }
558}
FileConfig * gPrefs
Definition: Prefs.cpp:70

References gPrefs, 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: