Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ClipParameters Struct Reference

#include <WaveTrackView.h>

Collaboration diagram for ClipParameters:
[legend]

Public Member Functions

 ClipParameters (bool spectrum, const SampleTrack *track, const WaveClip *clip, const wxRect &rect, const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo)
 

Static Public Member Functions

static wxRect GetClipRect (const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)
 

Public Attributes

double tOffset
 
double rate
 
double h
 
double tpre
 
double h1
 
double tpost
 
double t0
 
double t1
 
double averagePixelsPerSample
 
bool showIndividualSamples
 
sampleCount ssel0
 
sampleCount ssel1
 
wxRect hiddenMid
 
int hiddenLeftOffset
 
wxRect mid
 
int leftOffset
 

Detailed Description

Definition at line 240 of file WaveTrackView.h.

Constructor & Destructor Documentation

◆ ClipParameters()

ClipParameters::ClipParameters ( bool  spectrum,
const SampleTrack track,
const WaveClip clip,
const wxRect &  rect,
const SelectedRegion selectedRegion,
const ZoomInfo zoomInfo 
)

Definition at line 1498 of file WaveTrackView.cpp.

1501{
1502 tOffset = clip->GetPlayStartTime();
1503 rate = clip->GetRate();
1504
1505 h = zoomInfo.PositionToTime(0, 0
1506 , true
1507 );
1508 h1 = zoomInfo.PositionToTime(rect.width, 0
1509 , true
1510 );
1511
1512 double sel0 = selectedRegion.t0(); //left selection bound
1513 double sel1 = selectedRegion.t1(); //right selection bound
1514
1515 //If the track isn't selected, make the selection empty
1516 if (!track->GetSelected() &&
1517 (spectrum ||
1518 !SyncLock::IsSyncLockSelected(track))) { // PRL: why was there a difference for spectrum?
1519 sel0 = sel1 = 0.0;
1520 }
1521
1522 const double trackLen = clip->GetPlayEndTime() - clip->GetPlayStartTime();
1523
1524 tpre = h - tOffset; // offset corrected time of
1525 // left edge of display
1526 tpost = h1 - tOffset; // offset corrected time of
1527 // right edge of display
1528
1529 const double sps = 1. / rate; //seconds-per-sample
1530
1531 // Calculate actual selection bounds so that t0 > 0 and t1 < the
1532 // end of the track
1533 t0 = std::max(tpre, .0);
1534 t1 = std::min(tpost, trackLen - sps * .99)
1536
1537 // Make sure t1 (the right bound) is greater than 0
1538 if (t1 < 0.0) {
1539 t1 = 0.0;
1540 }
1541
1542 // Make sure t1 is greater than t0
1543 if (t0 > t1) {
1544 t0 = t1;
1545 }
1546
1547 // Use the WaveTrack method to show what is selected and 'should' be copied, pasted etc.
1548 ssel0 = std::max(sampleCount(0), spectrum
1549 ? sampleCount((sel0 - tOffset) * rate + .99) // PRL: why?
1550 : track->TimeToLongSamples(sel0 - tOffset)
1551 );
1552 ssel1 = std::max(sampleCount(0), spectrum
1553 ? sampleCount((sel1 - tOffset) * rate + .99) // PRL: why?
1554 : track->TimeToLongSamples(sel1 - tOffset)
1555 );
1556
1557 //trim selection so that it only contains the actual samples
1558 if (ssel0 != ssel1 && ssel1 > (sampleCount)(0.5 + trackLen * rate)) {
1559 ssel1 = sampleCount( 0.5 + trackLen * rate );
1560 }
1561
1562 // The variable "hiddenMid" will be the rectangle containing the
1563 // actual waveform, as opposed to any blank area before
1564 // or after the track, as it would appear without the fisheye.
1565 hiddenMid = rect;
1566
1567 // If the left edge of the track is to the right of the left
1568 // edge of the display, then there's some unused area to the
1569 // left of the track. Reduce the "hiddenMid"
1570 hiddenLeftOffset = 0;
1571 if (tpre < 0) {
1572 // Fix Bug #1296 caused by premature conversion to (int).
1573 wxInt64 time64 = zoomInfo.TimeToPosition(tOffset, 0 , true);
1574 if( time64 < 0 )
1575 time64 = 0;
1576 hiddenLeftOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1577
1579 hiddenMid.width -= hiddenLeftOffset;
1580 }
1581
1582 // If the right edge of the track is to the left of the right
1583 // edge of the display, then there's some unused area to the right
1584 // of the track. Reduce the "hiddenMid" rect by the
1585 // size of the blank area.
1586 if (tpost > t1) {
1587 wxInt64 time64 = zoomInfo.TimeToPosition(tOffset+t1, 0 , true);
1588 if( time64 < 0 )
1589 time64 = 0;
1590 const int hiddenRightOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1591
1592 hiddenMid.width = std::max(0, hiddenRightOffset - hiddenLeftOffset);
1593 }
1594 // The variable "mid" will be the rectangle containing the
1595 // actual waveform, as distorted by the fisheye,
1596 // as opposed to any blank area before or after the track.
1597 mid = rect;
1598
1599 // If the left edge of the track is to the right of the left
1600 // edge of the display, then there's some unused area to the
1601 // left of the track. Reduce the "mid"
1602 leftOffset = 0;
1603 if (tpre < 0) {
1604 wxInt64 time64 = zoomInfo.TimeToPosition(tOffset, 0 , false);
1605 if( time64 < 0 )
1606 time64 = 0;
1607 leftOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1608
1609 mid.x += leftOffset;
1610 mid.width -= leftOffset;
1611 }
1612
1613 // If the right edge of the track is to the left of the right
1614 // edge of the display, then there's some unused area to the right
1615 // of the track. Reduce the "mid" rect by the
1616 // size of the blank area.
1617 if (tpost > t1) {
1618 wxInt64 time64 = zoomInfo.TimeToPosition(tOffset+t1, 0 , false);
1619 if( time64 < 0 )
1620 time64 = 0;
1621 const int distortedRightOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1622
1623 mid.width = std::max(0, distortedRightOffset - leftOffset);
1624 }
1625}
int min(int a, int b)
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:43
double t1() const
double t0() const
static bool IsSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:82
bool GetSelected() const
Definition: Track.h:470
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:878
double GetPlayEndTime() const
Definition: WaveClip.cpp:888
int GetRate() const
Definition: WaveClip.h:140
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:35
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:45
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double CalculateAdjustmentForZoomLevel(const wxRect &viewRect, const ZoomInfo &zoomInfo, int rate, double &outAveragePPS, bool &outShowSamples)
sampleCount ssel1
sampleCount ssel0
double averagePixelsPerSample
bool showIndividualSamples

References averagePixelsPerSample, anonymous_namespace{WaveTrackView.cpp}::CalculateAdjustmentForZoomLevel(), WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), WaveClip::GetRate(), Track::GetSelected(), h, h1, hiddenLeftOffset, hiddenMid, SyncLock::IsSyncLockSelected(), leftOffset, mid, min(), ZoomInfo::PositionToTime(), rate, showIndividualSamples, ssel0, ssel1, SelectedRegion::t0(), t0, SelectedRegion::t1(), t1, SampleTrack::TimeToLongSamples(), ZoomInfo::TimeToPosition(), tOffset, tpost, and tpre.

Here is the call graph for this function:

Member Function Documentation

◆ GetClipRect()

wxRect ClipParameters::GetClipRect ( const WaveClip clip,
const ZoomInfo zoomInfo,
const wxRect &  viewRect,
bool *  outShowSamples = nullptr 
)
static

Definition at line 1627 of file WaveTrackView.cpp.

1628{
1629 auto srs = 1. / static_cast<double>(clip.GetRate());
1630 double averagePixelsPerSample{};
1631 bool showIndividualSamples{};
1632 auto clipEndingAdjustemt
1634 if (outShowSamples != nullptr)
1635 *outShowSamples = showIndividualSamples;
1636 constexpr auto edgeLeft = static_cast<ZoomInfo::int64>(std::numeric_limits<int>::min());
1637 constexpr auto edgeRight = static_cast<ZoomInfo::int64>(std::numeric_limits<int>::max());
1638 auto left = std::clamp(
1639 zoomInfo.TimeToPosition(
1640 clip.GetPlayStartTime(), viewRect.x, true
1641 ), edgeLeft, edgeRight
1642 );
1643 auto right = std::clamp(
1644 zoomInfo.TimeToPosition(
1645 clip.GetPlayEndTime() - .99 * srs + clipEndingAdjustemt, viewRect.x, true
1646 ), edgeLeft, edgeRight
1647 );
1648 if (right >= left)
1649 {
1650 //after clamping we can expect that left and right
1651 //are small enough to be put into int
1652 return wxRect(
1653 static_cast<int>(left),
1654 viewRect.y,
1655 std::max(1, static_cast<int>(right - left)),
1656 viewRect.height
1657 );
1658 }
1659 return wxRect();
1660}
std::int64_t int64
Definition: ZoomInfo.h:41

References averagePixelsPerSample, anonymous_namespace{WaveTrackView.cpp}::CalculateAdjustmentForZoomLevel(), WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), WaveClip::GetRate(), min(), showIndividualSamples, and ZoomInfo::TimeToPosition().

Referenced by WaveTrackView::ClipDetailsVisible(), WaveTrackView::ClipHitTestArea(), WaveTrackAffordanceControls::Draw(), anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum(), anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), WaveClipTrimHandle::HitAnywhere(), and WaveTrackAffordanceControls::OnAffordanceClick().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ averagePixelsPerSample

double ClipParameters::averagePixelsPerSample

Definition at line 260 of file WaveTrackView.h.

Referenced by ClipParameters(), and GetClipRect().

◆ h

double ClipParameters::h

Definition at line 250 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ h1

double ClipParameters::h1

Definition at line 252 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ hiddenLeftOffset

int ClipParameters::hiddenLeftOffset

Definition at line 267 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ hiddenMid

wxRect ClipParameters::hiddenMid

Definition at line 266 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ leftOffset

int ClipParameters::leftOffset

Definition at line 270 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ mid

wxRect ClipParameters::mid

Definition at line 269 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ rate

double ClipParameters::rate

Definition at line 249 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ showIndividualSamples

bool ClipParameters::showIndividualSamples

Definition at line 261 of file WaveTrackView.h.

Referenced by ClipParameters(), and GetClipRect().

◆ ssel0

sampleCount ClipParameters::ssel0

Definition at line 263 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ ssel1

sampleCount ClipParameters::ssel1

Definition at line 264 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ t0

double ClipParameters::t0

Definition at line 257 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ t1

double ClipParameters::t1

Definition at line 258 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ tOffset

double ClipParameters::tOffset

Definition at line 248 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ tpost

double ClipParameters::tpost

Definition at line 253 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ tpre

double ClipParameters::tpre

Definition at line 251 of file WaveTrackView.h.

Referenced by ClipParameters().


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