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 AudacityProject &project) 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

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 489 of file TrackArt.cpp.

Constructor & Destructor Documentation

◆ BeatsGridlinePainter()

anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::BeatsGridlinePainter ( const ZoomInfo zoomInfo,
const AudacityProject project 
)
inlinenoexcept

Definition at line 507 of file TrackArt.cpp.

509 : zoomInfo { zoomInfo }
514 , minorTick { GetMinorTick() }
518 {
519 }
const auto project
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

Member Function Documentation

◆ CalculateNotesInBeat()

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

Definition at line 581 of file TrackArt.cpp.

582 {
584 return minorTick.lower / 4;
585
586 return 1;
587 }

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 541 of file TrackArt.cpp.

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

◆ DrawSeparators()

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

Definition at line 521 of file TrackArt.cpp.

523{
524 dc.SetPen (beatSepearatorPen);
525
526 const auto [firstNote, lastNote] = GetBoundaries(
527 rect, rect, noteWidth);
528
529 for (auto noteIndex = firstNote; noteIndex < lastNote; ++noteIndex)
530 {
531 const auto position = GetPositionInRect (noteIndex, rect, noteDuration);
532
533 if (position < rect.GetLeft () || position >= rect.GetRight ())
534 continue;
535
536 dc.SetPen(IsFirstInMajorTick(noteIndex) ? barSeparatorPen : beatSepearatorPen);
537 dc.DrawLine (position, rect.GetTop (), position, rect.GetBottom ());
538 }
539}

◆ 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 610 of file TrackArt.cpp.

611 {
612 const auto offset = subRect.x - fullRect.x;
613
614 return { std::floor(zoomInfo.GetAbsoluteOffset(offset) / width),
615 std::ceil(
616 zoomInfo.GetAbsoluteOffset(offset + subRect.GetWidth()) /
617 width) };
618 }
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 620 of file TrackArt.cpp.

621 {
622 const auto& subdivision = beatsRulerFormat.GetSubdivision();
623
624 auto tick = subdivision.minorMinor;
625
626 auto minorMinorLength =
627 zoomInfo.TimeRangeToPixelWidth(subdivision.minorMinor.duration);
628
629 const auto nextSubdivision = subdivision.minor.duration == 0.0 ?
630 subdivision.major :
631 subdivision.minor;
632
633 while (minorMinorLength <= minSubdivisionWidth)
634 {
635 tick.lower /= 2;
636 tick.duration *= 2.0;
637 minorMinorLength *= 2.0;
638
639 if (nextSubdivision.lower >= tick.lower)
640 return nextSubdivision;
641 }
642
643 return tick;
644 }
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 605 of file TrackArt.cpp.

606 {
607 return zoomInfo.TimeToPosition(index * duration) + rect.x;
608 }
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:

◆ IsFirstInMajorTick()

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

Definition at line 589 of file TrackArt.cpp.

590 {
591 const auto notesInMajorTick =
593
594 if (notesInMajorTick == 0)
595 return false;
596
597 return noteIndex % notesInMajorTick == 0;
598 }

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

◆ UseAlternatingColors()

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

Definition at line 600 of file TrackArt.cpp.

601 {
602 return minorTick.lower >= 4 && minorTick.upper == 1;
603 }

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

Member Data Documentation

◆ beatsRulerFormat

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

Definition at line 494 of file TrackArt.cpp.

◆ enabled

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

Definition at line 492 of file TrackArt.cpp.

◆ majorTick

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

Definition at line 496 of file TrackArt.cpp.

◆ minorTick

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

Definition at line 497 of file TrackArt.cpp.

◆ noteDuration

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

Definition at line 500 of file TrackArt.cpp.

◆ notesInBeat

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

Definition at line 504 of file TrackArt.cpp.

◆ noteWidth

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

Definition at line 502 of file TrackArt.cpp.

◆ zoomInfo

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

Definition at line 491 of file TrackArt.cpp.


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