Audacity  3.0.3
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 WaveTrack *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)
 

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 220 of file WaveTrackView.h.

Constructor & Destructor Documentation

◆ ClipParameters()

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

Definition at line 1311 of file WaveTrackView.cpp.

1314 {
1315  tOffset = clip->GetPlayStartTime();
1316  rate = clip->GetRate();
1317 
1318  h = zoomInfo.PositionToTime(0, 0
1319  , true
1320  );
1321  h1 = zoomInfo.PositionToTime(rect.width, 0
1322  , true
1323  );
1324 
1325  double sel0 = selectedRegion.t0(); //left selection bound
1326  double sel1 = selectedRegion.t1(); //right selection bound
1327 
1328  //If the track isn't selected, make the selection empty
1329  if (!track->GetSelected() &&
1330  (spectrum || !track->IsSyncLockSelected())) { // PRL: why was there a difference for spectrum?
1331  sel0 = sel1 = 0.0;
1332  }
1333 
1334  const double trackLen = clip->GetPlayEndTime() - clip->GetPlayStartTime();
1335 
1336  tpre = h - tOffset; // offset corrected time of
1337  // left edge of display
1338  tpost = h1 - tOffset; // offset corrected time of
1339  // right edge of display
1340 
1341  const double sps = 1. / rate; //seconds-per-sample
1342 
1343  // Determine whether we should show individual samples
1344  // or draw circular points as well
1345  averagePixelsPerSample = rect.width / (rate * (h1 - h));
1347 
1348  // Calculate actual selection bounds so that t0 > 0 and t1 < the
1349  // end of the track
1350  t0 = std::max(tpre, .0);
1351  t1 = std::min(tpost, trackLen - sps * .99);
1352  if (showIndividualSamples) {
1353  // adjustment so that the last circular point doesn't appear
1354  // to be hanging off the end
1355  t1 += 2. / (averagePixelsPerSample * rate);
1356  }
1357 
1358  // Make sure t1 (the right bound) is greater than 0
1359  if (t1 < 0.0) {
1360  t1 = 0.0;
1361  }
1362 
1363  // Make sure t1 is greater than t0
1364  if (t0 > t1) {
1365  t0 = t1;
1366  }
1367 
1368  // Use the WaveTrack method to show what is selected and 'should' be copied, pasted etc.
1369  ssel0 = std::max(sampleCount(0), spectrum
1370  ? sampleCount((sel0 - tOffset) * rate + .99) // PRL: why?
1371  : track->TimeToLongSamples(sel0 - tOffset)
1372  );
1373  ssel1 = std::max(sampleCount(0), spectrum
1374  ? sampleCount((sel1 - tOffset) * rate + .99) // PRL: why?
1375  : track->TimeToLongSamples(sel1 - tOffset)
1376  );
1377 
1378  //trim selection so that it only contains the actual samples
1379  if (ssel0 != ssel1 && ssel1 > (sampleCount)(0.5 + trackLen * rate)) {
1380  ssel1 = sampleCount( 0.5 + trackLen * rate );
1381  }
1382 
1383  // The variable "hiddenMid" will be the rectangle containing the
1384  // actual waveform, as opposed to any blank area before
1385  // or after the track, as it would appear without the fisheye.
1386  hiddenMid = rect;
1387 
1388  // If the left edge of the track is to the right of the left
1389  // edge of the display, then there's some unused area to the
1390  // left of the track. Reduce the "hiddenMid"
1391  hiddenLeftOffset = 0;
1392  if (tpre < 0) {
1393  // Fix Bug #1296 caused by premature conversion to (int).
1394  wxInt64 time64 = zoomInfo.TimeToPosition(tOffset, 0 , true);
1395  if( time64 < 0 )
1396  time64 = 0;
1397  hiddenLeftOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1398 
1400  hiddenMid.width -= hiddenLeftOffset;
1401  }
1402 
1403  // If the right edge of the track is to the left of the right
1404  // edge of the display, then there's some unused area to the right
1405  // of the track. Reduce the "hiddenMid" rect by the
1406  // size of the blank area.
1407  if (tpost > t1) {
1408  wxInt64 time64 = zoomInfo.TimeToPosition(tOffset+t1, 0 , true);
1409  if( time64 < 0 )
1410  time64 = 0;
1411  const int hiddenRightOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1412 
1413  hiddenMid.width = std::max(0, hiddenRightOffset - hiddenLeftOffset);
1414  }
1415  // The variable "mid" will be the rectangle containing the
1416  // actual waveform, as distorted by the fisheye,
1417  // as opposed to any blank area before or after the track.
1418  mid = rect;
1419 
1420  // If the left edge of the track is to the right of the left
1421  // edge of the display, then there's some unused area to the
1422  // left of the track. Reduce the "mid"
1423  leftOffset = 0;
1424  if (tpre < 0) {
1425  wxInt64 time64 = zoomInfo.TimeToPosition(tOffset, 0 , false);
1426  if( time64 < 0 )
1427  time64 = 0;
1428  leftOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1429 
1430  mid.x += leftOffset;
1431  mid.width -= leftOffset;
1432  }
1433 
1434  // If the right edge of the track is to the left of the right
1435  // edge of the display, then there's some unused area to the right
1436  // of the track. Reduce the "mid" rect by the
1437  // size of the blank area.
1438  if (tpost > t1) {
1439  wxInt64 time64 = zoomInfo.TimeToPosition(tOffset+t1, 0 , false);
1440  if( time64 < 0 )
1441  time64 = 0;
1442  const int distortedRightOffset = (time64 < rect.width) ? (int)time64 : rect.width;
1443 
1444  mid.width = std::max(0, distortedRightOffset - leftOffset);
1445  }
1446 }

References averagePixelsPerSample, WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), WaveClip::GetRate(), Track::GetSelected(), h, h1, hiddenLeftOffset, hiddenMid, Track::IsSyncLockSelected(), leftOffset, mid, min(), ZoomInfo::PositionToTime(), rate, showIndividualSamples, ssel0, ssel1, SelectedRegion::t0(), t0, SelectedRegion::t1(), t1, WaveTrack::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 
)
static

Definition at line 1448 of file WaveTrackView.cpp.

1449 {
1450  auto srs = 1. / static_cast<double>(clip.GetRate());
1451  //to prevent overlap left and right most samples with frame border
1452  auto margin = .25 * srs;
1453  constexpr auto edgeLeft = static_cast<wxInt64>(std::numeric_limits<int>::min());
1454  constexpr auto edgeRight = static_cast<wxInt64>(std::numeric_limits<int>::max());
1455  auto left = std::clamp(zoomInfo.TimeToPosition(clip.GetPlayStartTime() - margin, viewRect.x, true), edgeLeft, edgeRight);
1456  auto right = std::clamp(zoomInfo.TimeToPosition(clip.GetPlayEndTime() - srs + margin, viewRect.x, true), edgeLeft, edgeRight);
1457  if (right > left)
1458  {
1459  //after clamping we can expect that left and right
1460  //are small enough to be put into int
1461  return wxRect(static_cast<int>(left), viewRect.y, static_cast<int>(right - left), viewRect.height);
1462  }
1463  return wxRect();
1464 }

References WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), WaveClip::GetRate(), min(), and ZoomInfo::TimeToPosition().

Referenced by WaveTrackAffordanceControls::Draw(), anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum(), anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), WaveClipTrimHandle::HitAnywhere(), WaveTrackAffordanceControls::HitTest(), 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 239 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ h

double ClipParameters::h

Definition at line 229 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ h1

double ClipParameters::h1

Definition at line 231 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ hiddenLeftOffset

int ClipParameters::hiddenLeftOffset

Definition at line 246 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ hiddenMid

wxRect ClipParameters::hiddenMid

Definition at line 245 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ leftOffset

int ClipParameters::leftOffset

Definition at line 249 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ mid

wxRect ClipParameters::mid

Definition at line 248 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ rate

double ClipParameters::rate

Definition at line 228 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ showIndividualSamples

bool ClipParameters::showIndividualSamples

Definition at line 240 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ ssel0

sampleCount ClipParameters::ssel0

Definition at line 242 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ ssel1

sampleCount ClipParameters::ssel1

Definition at line 243 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ t0

double ClipParameters::t0

Definition at line 236 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ t1

double ClipParameters::t1

Definition at line 237 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ tOffset

double ClipParameters::tOffset

Definition at line 227 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ tpost

double ClipParameters::tpost

Definition at line 232 of file WaveTrackView.h.

Referenced by ClipParameters().

◆ tpre

double ClipParameters::tpre

Definition at line 230 of file WaveTrackView.h.

Referenced by ClipParameters().


The documentation for this struct was generated from the following files:
ClipParameters::tpost
double tpost
Definition: WaveTrackView.h:232
ClipParameters::rate
double rate
Definition: WaveTrackView.h:228
ClipParameters::averagePixelsPerSample
double averagePixelsPerSample
Definition: WaveTrackView.h:239
SelectedRegion::t1
double t1() const
Definition: SelectedRegion.h:92
WaveClip::GetRate
int GetRate() const
Definition: WaveClip.h:211
ClipParameters::h
double h
Definition: WaveTrackView.h:229
ClipParameters::hiddenLeftOffset
int hiddenLeftOffset
Definition: WaveTrackView.h:246
Track::IsSyncLockSelected
bool IsSyncLockSelected() const
Definition: Track.cpp:254
ZoomInfo::TimeToPosition
wxInt64 TimeToPosition(double time, wxInt64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:49
ClipParameters::ssel0
sampleCount ssel0
Definition: WaveTrackView.h:242
ClipParameters::hiddenMid
wxRect hiddenMid
Definition: WaveTrackView.h:245
ClipParameters::showIndividualSamples
bool showIndividualSamples
Definition: WaveTrackView.h:240
ClipParameters::ssel1
sampleCount ssel1
Definition: WaveTrackView.h:243
WaveClip::GetPlayEndTime
double GetPlayEndTime() const
Definition: WaveClip.cpp:1800
ClipParameters::tOffset
double tOffset
Definition: WaveTrackView.h:227
ClipParameters::t0
double t0
Definition: WaveTrackView.h:236
Track::GetSelected
bool GetSelected() const
Definition: Track.h:431
ClipParameters::leftOffset
int leftOffset
Definition: WaveTrackView.h:249
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
SelectedRegion::t0
double t0() const
Definition: SelectedRegion.h:91
WaveTrack::TimeToLongSamples
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1857
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
ClipParameters::h1
double h1
Definition: WaveTrackView.h:231
ClipParameters::mid
wxRect mid
Definition: WaveTrackView.h:248
ClipParameters::t1
double t1
Definition: WaveTrackView.h:237
ClipParameters::tpre
double tpre
Definition: WaveTrackView.h:230
WaveClip::GetPlayStartTime
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:1790
ZoomInfo::PositionToTime
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:39