Audacity 3.2.0
Public Member Functions | Public Attributes | Private Member Functions | List of all members
anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter Struct Referencefinal
Collaboration diagram for anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter:
[legend]

Public Member Functions

 BeatsGridlinePainter (const ZoomInfo &zoomInfo, const Track &track) noexcept
 
void DrawSeparators (wxDC &dc, const wxRect &rect, const wxPen &beatSepearatorPen, const wxPen &barSeparatorPen) const
 
void DrawBackground (wxDC &dc, const wxRect &subRect, const wxRect &fullRect, const wxBrush &strongBeatBrush, const wxBrush &weakBeatBrush) const
 

Public Attributes

const ZoomInfozoomInfo
 
const bool enabled
 
const BeatsFormatbeatsRulerFormat
 
const BeatsFormat::Tick majorTick
 
const BeatsFormat::Tick minorTick
 
const double noteDuration
 
const double noteWidth
 
const int64_t notesInBeat
 

Private Member Functions

const AudacityProjectGetProject (const Track &track) const
 
int64_t CalculateNotesInBeat () const
 
bool IsFirstInMajorTick (int64_t noteIndex) const
 
bool UseAlternatingColors () const
 
double GetPositionInRect (int64_t index, const wxRect &rect, double duration) const
 
std::pair< int64_t, int64_t > GetBoundaries (const wxRect &subRect, const wxRect &fullRect, double width) const
 
BeatsFormat::Tick GetMinorTick () const
 

Detailed Description

Definition at line 479 of file TrackArt.cpp.

Constructor & Destructor Documentation

◆ BeatsGridlinePainter()

anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::BeatsGridlinePainter ( const ZoomInfo zoomInfo,
const Track track 
)
inlinenoexcept

Definition at line 497 of file TrackArt.cpp.

498 : zoomInfo { zoomInfo }
502 .GetBeatsFormat() }
504 , minorTick { GetMinorTick() }
508 {
509 }
TimeDisplayModeSetting TimeDisplayModePreference
const Ticks & GetSubdivision() const
Enum ReadEnum() const
Definition: Prefs.h:534
static ProjectTimeRuler & Get(AudacityProject &project)
BeatsFormat & GetBeatsFormat()
double TimeRangeToPixelWidth(double timeRange) const
Definition: ZoomInfo.cpp:60
const AudacityProject & GetProject(const Track &track) const
Definition: TrackArt.cpp:574

Member Function Documentation

◆ CalculateNotesInBeat()

int64_t anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::CalculateNotesInBeat ( ) const
inlineprivate

Definition at line 584 of file TrackArt.cpp.

585 {
587 return minorTick.lower / 4;
588
589 return 1;
590 }

References BeatsFormat::Tick::lower.

◆ DrawBackground()

void anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::DrawBackground ( wxDC &  dc,
const wxRect &  subRect,
const wxRect &  fullRect,
const wxBrush &  strongBeatBrush,
const wxBrush &  weakBeatBrush 
) const
inline

Definition at line 534 of file TrackArt.cpp.

537{
538 if (!UseAlternatingColors ())
539 {
540 dc.SetBrush(strongBeatBrush);
541 dc.DrawRectangle(subRect);
542 return;
543 }
544
545 auto [firstIndex, lastIndex] =
546 GetBoundaries (subRect, fullRect, noteWidth);
547
548 // Make first index to be on notesInBeatBoundary
549 firstIndex = (firstIndex / notesInBeat) * notesInBeat;
550
551 const auto beatDuration = noteDuration;
552
553 const auto top = fullRect.GetTop ();
554 const auto height = fullRect.GetHeight ();
555
556 bool strongBeat = (firstIndex / notesInBeat) % 2 == 0;
557 for (auto index = firstIndex; index < lastIndex; index += notesInBeat, strongBeat = !strongBeat)
558 {
559 const auto left = std::max<int> (
560 GetPositionInRect(index, fullRect, beatDuration),
561 subRect.GetLeft());
562 const auto right = std::min<int> (
563 GetPositionInRect(index + notesInBeat, fullRect, beatDuration),
564 subRect.GetRight());
565
566 const auto& brush = strongBeat ? strongBeatBrush : weakBeatBrush;
567
568 dc.SetBrush (brush);
569 dc.DrawRectangle (left, top, right - left + 1, height);
570 }
571}
std::pair< int64_t, int64_t > GetBoundaries(const wxRect &subRect, const wxRect &fullRect, double width) const
Definition: TrackArt.cpp:613
double GetPositionInRect(int64_t index, const wxRect &rect, double duration) const
Definition: TrackArt.cpp:608

◆ DrawSeparators()

void anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::DrawSeparators ( wxDC &  dc,
const wxRect &  rect,
const wxPen &  beatSepearatorPen,
const wxPen &  barSeparatorPen 
) const
inline

Definition at line 511 of file TrackArt.cpp.

513{
514 dc.SetPen (beatSepearatorPen);
515
517 const auto minorTick = GetMinorTick();
518
519 const auto [firstNote, lastNote] = GetBoundaries(
520 rect, rect, noteWidth);
521
522 for (auto noteIndex = firstNote; noteIndex < lastNote; ++noteIndex)
523 {
524 const auto position = GetPositionInRect (noteIndex, rect, noteDuration);
525
526 if (position < rect.GetLeft () || position >= rect.GetRight ())
527 continue;
528
529 dc.SetPen(IsFirstInMajorTick(noteIndex) ? barSeparatorPen : beatSepearatorPen);
530 dc.DrawLine (position, rect.GetTop (), position, rect.GetBottom () + 1);
531 }
532}

References BeatsFormat::GetSubdivision(), and BeatsFormat::Ticks::major.

Here is the call graph for this function:

◆ GetBoundaries()

std::pair< int64_t, int64_t > anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::GetBoundaries ( const wxRect &  subRect,
const wxRect &  fullRect,
double  width 
) const
inlineprivate

Definition at line 613 of file TrackArt.cpp.

614 {
615 const auto offset = subRect.x - fullRect.x;
616
617 return { std::floor(zoomInfo.GetAbsoluteOffset(offset) / width),
618 std::ceil(
619 zoomInfo.GetAbsoluteOffset(offset + subRect.GetWidth()) /
620 width) };
621 }
double GetAbsoluteOffset(double offset) const
Definition: ZoomInfo.cpp:77

References ZoomInfo::GetAbsoluteOffset().

Here is the call graph for this function:

◆ GetMinorTick()

BeatsFormat::Tick anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::GetMinorTick ( ) const
inlineprivate

Definition at line 623 of file TrackArt.cpp.

624 {
625 const auto& subdivision = beatsRulerFormat.GetSubdivision();
626
627 auto tick = subdivision.minorMinor;
628
629 auto minorMinorLength =
630 zoomInfo.TimeRangeToPixelWidth(subdivision.minorMinor.duration);
631
632 const auto nextSubdivision = subdivision.minor.duration == 0.0 ?
633 subdivision.major :
634 subdivision.minor;
635
636 while (minorMinorLength <= minSubdivisionWidth)
637 {
638 tick.lower /= 2;
639 tick.duration *= 2.0;
640 minorMinorLength *= 2.0;
641
642 if (nextSubdivision.lower >= tick.lower)
643 return nextSubdivision;
644 }
645
646 return tick;
647 }
constexpr double minSubdivisionWidth
Definition: TrackArt.cpp:477

References BeatsFormat::GetSubdivision(), BeatsFormat::Ticks::minorMinor, anonymous_namespace{TrackArt.cpp}::minSubdivisionWidth, and ZoomInfo::TimeRangeToPixelWidth().

Here is the call graph for this function:

◆ GetPositionInRect()

double anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::GetPositionInRect ( int64_t  index,
const wxRect &  rect,
double  duration 
) const
inlineprivate

Definition at line 608 of file TrackArt.cpp.

609 {
610 return zoomInfo.TimeToPosition(index * duration) + rect.x + 1;
611 }
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:44

References ZoomInfo::TimeToPosition().

Here is the call graph for this function:

◆ GetProject()

const AudacityProject & anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::GetProject ( const Track track) const
inlineprivate

Definition at line 574 of file TrackArt.cpp.

575 {
576 // Track is expected to have owner
577 assert(track.GetOwner());
578 // TracList is expected to have owner
579 assert(track.GetOwner()->GetOwner());
580
581 return *track.GetOwner()->GetOwner();
582 }
std::shared_ptr< TrackList > GetOwner() const
Definition: Track.h:254

References Track::GetOwner().

Here is the call graph for this function:

◆ IsFirstInMajorTick()

bool anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::IsFirstInMajorTick ( int64_t  noteIndex) const
inlineprivate

Definition at line 592 of file TrackArt.cpp.

593 {
594 const auto notesInMajorTick =
596
597 if (notesInMajorTick == 0)
598 return false;
599
600 return noteIndex % notesInMajorTick == 0;
601 }

References BeatsFormat::Tick::lower, and BeatsFormat::Tick::upper.

◆ UseAlternatingColors()

bool anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::UseAlternatingColors ( ) const
inlineprivate

Definition at line 603 of file TrackArt.cpp.

604 {
605 return minorTick.lower >= 4 && minorTick.upper == 1;
606 }

References BeatsFormat::Tick::lower, and BeatsFormat::Tick::upper.

Member Data Documentation

◆ beatsRulerFormat

const BeatsFormat& anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::beatsRulerFormat

Definition at line 484 of file TrackArt.cpp.

◆ enabled

const bool anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::enabled

Definition at line 482 of file TrackArt.cpp.

◆ majorTick

const BeatsFormat::Tick anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::majorTick

Definition at line 486 of file TrackArt.cpp.

◆ minorTick

const BeatsFormat::Tick anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::minorTick

Definition at line 487 of file TrackArt.cpp.

◆ noteDuration

const double anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::noteDuration

Definition at line 490 of file TrackArt.cpp.

◆ notesInBeat

const int64_t anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::notesInBeat

Definition at line 494 of file TrackArt.cpp.

◆ noteWidth

const double anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::noteWidth

Definition at line 492 of file TrackArt.cpp.

◆ zoomInfo

const ZoomInfo& anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::zoomInfo

Definition at line 481 of file TrackArt.cpp.


The documentation for this struct was generated from the following file: