Audacity  3.0.3
Classes | Typedefs | Functions | Variables
anonymous_namespace{WaveformView.cpp} Namespace Reference

Classes

struct  WavePortion
 

Typedefs

using ValueFinder = std::function< int(WaveTrack &) >
 

Functions

void DrawWaveformBackground (TrackPanelDrawingContext &context, int leftOffset, const wxRect &rect, const double env[], float zoomMin, float zoomMax, int zeroLevelYCoordinate, bool dB, float dBRange, double t0, double t1, bool bIsSyncLockSelected, bool highlightEnvelope)
 
void FindWavePortions (std::vector< WavePortion > &portions, const wxRect &rect, const ZoomInfo &zoomInfo, const ClipParameters &params)
 
void DrawMinMaxRMS (TrackPanelDrawingContext &context, const wxRect &rect, const double env[], float zoomMin, float zoomMax, bool dB, float dBRange, const float *min, const float *max, const float *rms, const int *bl, bool muted)
 
void DrawIndividualSamples (TrackPanelDrawingContext &context, int leftOffset, const wxRect &rect, float zoomMin, float zoomMax, bool dB, float dBRange, const WaveClip *clip, bool showPoints, bool muted, bool highlight)
 
void DrawEnvLine (TrackPanelDrawingContext &context, const wxRect &rect, int x0, int y0, int cy, bool top)
 
void DrawEnvelope (TrackPanelDrawingContext &context, const wxRect &rect, const double env[], float zoomMin, float zoomMax, bool dB, float dBRange, bool highlight)
 
void DrawClipWaveform (TrackPanelDrawingContext &context, const WaveTrack *track, const WaveClip *clip, const wxRect &rect, bool dB, bool muted, bool selected)
 
void DrawTimeSlider (TrackPanelDrawingContext &context, const wxRect &rect, bool rightwards, bool highlight)
 
const TranslatableString GetWaveColorStr (int colorIndex)
 

Variables

PopupMenuTable::AttachedItem sAttachment
 

Typedef Documentation

◆ ValueFinder

using anonymous_namespace{WaveformView.cpp}::ValueFinder = typedef std::function< int( WaveTrack& ) >

Definition at line 1099 of file WaveformView.cpp.

Function Documentation

◆ DrawClipWaveform()

void anonymous_namespace{WaveformView.cpp}::DrawClipWaveform ( TrackPanelDrawingContext context,
const WaveTrack track,
const WaveClip clip,
const wxRect &  rect,
bool  dB,
bool  muted,
bool  selected 
)

Definition at line 668 of file WaveformView.cpp.

675 {
676  auto &dc = context.dc;
677  const auto artist = TrackArtist::Get( context );
678  const auto &selectedRegion = *artist->pSelectedRegion;
679  const auto &zoomInfo = *artist->pZoomInfo;
680 
681 #ifdef PROFILE_WAVEFORM
682  Profiler profiler;
683 #endif
684 
685  bool highlightEnvelope = false;
686 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
687  auto target = dynamic_cast<EnvelopeHandle*>(context.target.get());
688  highlightEnvelope = target && target->GetEnvelope() == clip->GetEnvelope();
689 #endif
690 
691  const ClipParameters params{
692  false, track, clip, rect, selectedRegion, zoomInfo };
693  const wxRect &hiddenMid = params.hiddenMid;
694  // The "hiddenMid" rect contains the part of the display actually
695  // containing the waveform, as it appears without the fisheye. If it's empty, we're done.
696  if (hiddenMid.width <= 0) {
697  return;
698  }
699 
700  const double &t0 = params.t0;
701  const double &tOffset = params.tOffset;
702  const double &h = params.h;
703  const double &tpre = params.tpre;
704  const double &tpost = params.tpost;
705  const double &t1 = params.t1;
706  const double &averagePixelsPerSample = params.averagePixelsPerSample;
707  const double &rate = params.rate;
708  double leftOffset = params.leftOffset;
709  const wxRect &mid = params.mid;
710 
711  const float dBRange = track->GetWaveformSettings().dBRange;
712 
713  dc.SetPen(*wxTRANSPARENT_PEN);
714  int iColorIndex = clip->GetColourIndex();
715  artist->SetColours( iColorIndex );
716 
717  // The bounds (controlled by vertical zooming; -1.0...1.0
718  // by default)
719  float zoomMin, zoomMax;
720  track->GetDisplayBounds(&zoomMin, &zoomMax);
721 
722  std::vector<double> vEnv(mid.width);
723  double *const env = &vEnv[0];
725  tOffset,
726 
727  // PRL: change back to make envelope evaluate only at sample times
728  // and then interpolate the display
729  0, // 1.0 / rate,
730 
731  env, mid.width, leftOffset, zoomInfo );
732 
733  // Draw the background of the track, outlining the shape of
734  // the envelope and using a colored pen for the selected
735  // part of the waveform
736  {
737  double tt0, tt1;
738  if (track->GetSelected() || track->IsSyncLockSelected()) {
739  tt0 = track->LongSamplesToTime(track->TimeToLongSamples(selectedRegion.t0())),
740  tt1 = track->LongSamplesToTime(track->TimeToLongSamples(selectedRegion.t1()));
741  }
742  else
743  tt0 = tt1 = 0.0;
744  DrawWaveformBackground(context, leftOffset, mid,
745  env,
746  zoomMin, zoomMax,
747  track->ZeroLevelYCoordinate(mid),
748  dB, dBRange,
749  tt0, tt1,
750  !track->GetSelected(), highlightEnvelope);
751  }
752 
753  WaveDisplay display(hiddenMid.width);
754 
755  const double pps =
756  averagePixelsPerSample * rate;
757 
758  // For each portion separately, we will decide to draw
759  // it as min/max/rms or as individual samples.
760  std::vector<WavePortion> portions;
761  FindWavePortions(portions, rect, zoomInfo, params);
762  const unsigned nPortions = portions.size();
763 
764  // Require at least 1/2 pixel per sample for drawing individual samples.
765  const double threshold1 = 0.5 * rate;
766  // Require at least 3 pixels per sample for drawing the draggable points.
767  const double threshold2 = 3 * rate;
768 
769  {
770  bool showIndividualSamples = false;
771  for (unsigned ii = 0; !showIndividualSamples && ii < nPortions; ++ii) {
772  const WavePortion &portion = portions[ii];
773  showIndividualSamples =
774  !portion.inFisheye && portion.averageZoom > threshold1;
775  }
776 
777  if (!showIndividualSamples) {
778  // The WaveClip class handles the details of computing the shape
779  // of the waveform. The only way GetWaveDisplay will fail is if
780  // there's a serious error, like some of the waveform data can't
781  // be loaded. So if the function returns false, we can just exit.
782 
783  // Note that we compute the full width display even if there is a
784  // fisheye hiding part of it, because of the caching. If the
785  // fisheye moves over the background, there is then less to do when
786  // redrawing.
787 
788  if (!clip->GetWaveDisplay(display,t0, pps))
789  return;
790  }
791  }
792 
793  // TODO Add a comment to say what this loop does.
794  // Possibly make it into a subroutine.
795  for (unsigned ii = 0; ii < nPortions; ++ii) {
796  WavePortion &portion = portions[ii];
797  const bool showIndividualSamples = portion.averageZoom > threshold1;
798  const bool showPoints = portion.averageZoom > threshold2;
799  wxRect& rectPortion = portion.rect;
800  rectPortion.Intersect(mid);
801  wxASSERT(rectPortion.width >= 0);
802 
803  float *useMin = 0, *useMax = 0, *useRms = 0;
804  int *useBl = 0;
805  WaveDisplay fisheyeDisplay(rectPortion.width);
806  int skipped = 0, skippedLeft = 0, skippedRight = 0;
807  if (portion.inFisheye) {
808  if (!showIndividualSamples) {
809  fisheyeDisplay.Allocate();
810  const auto numSamples = clip->GetPlaySamplesCount();
811  // Get wave display data for different magnification
812  int jj = 0;
813  for (; jj < rectPortion.width; ++jj) {
814  const double time =
815  zoomInfo.PositionToTime(jj, -leftOffset) - tOffset;
816  const auto sample = (sampleCount)floor(time * rate + 0.5);
817  if (sample < 0) {
818  ++rectPortion.x;
819  ++skippedLeft;
820  continue;
821  }
822  if (sample >= numSamples)
823  break;
824  fisheyeDisplay.where[jj - skippedLeft] = sample;
825  }
826 
827  skippedRight = rectPortion.width - jj;
828  skipped = skippedRight + skippedLeft;
829  rectPortion.width -= skipped;
830 
831  // where needs a sentinel
832  if (jj > 0)
833  fisheyeDisplay.where[jj - skippedLeft] =
834  1 + fisheyeDisplay.where[jj - skippedLeft - 1];
835  fisheyeDisplay.width -= skipped;
836  // Get a wave display for the fisheye, uncached.
837  if (rectPortion.width > 0)
838  if (!clip->GetWaveDisplay(
839  fisheyeDisplay, t0, -1.0)) // ignored
840  continue; // serious error. just don't draw??
841  useMin = fisheyeDisplay.min;
842  useMax = fisheyeDisplay.max;
843  useRms = fisheyeDisplay.rms;
844  useBl = fisheyeDisplay.bl;
845  }
846  }
847  else {
848  const int pos = leftOffset - params.hiddenLeftOffset;
849  useMin = display.min + pos;
850  useMax = display.max + pos;
851  useRms = display.rms + pos;
852  useBl = display.bl + pos;
853  }
854 
855  leftOffset += skippedLeft;
856 
857  if (rectPortion.width > 0) {
858  if (!showIndividualSamples) {
859  std::vector<double> vEnv2(rectPortion.width);
860  double *const env2 = &vEnv2[0];
862  tOffset,
863 
864  // PRL: change back to make envelope evaluate only at sample times
865  // and then interpolate the display
866  0, // 1.0 / rate,
867 
868  env2, rectPortion.width, leftOffset, zoomInfo );
869  DrawMinMaxRMS( context, rectPortion, env2,
870  zoomMin, zoomMax,
871  dB, dBRange,
872  useMin, useMax, useRms, useBl, muted );
873  }
874  else {
875  bool highlight = false;
876 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
877  auto target = dynamic_cast<SampleHandle*>(context.target.get());
878  highlight = target && target->GetTrack().get() == track;
879 #endif
881  context, leftOffset, rectPortion, zoomMin, zoomMax,
882  dB, dBRange,
883  clip,
884  showPoints, muted, highlight );
885  }
886  }
887 
888  leftOffset += rectPortion.width + skippedRight;
889  }
890 
891  const auto drawEnvelope = artist->drawEnvelope;
892  if (drawEnvelope) {
893  DrawEnvelope(
894  context, mid, env, zoomMin, zoomMax, dB, dBRange, highlightEnvelope );
896  context, rect, dB, dBRange, zoomMin, zoomMax, true );
897  }
898 
899  // Draw arrows on the left side if the track extends to the left of the
900  // beginning of time. :)
901  if (h == 0.0 && tOffset < 0.0) {
903  }
904  {
905  auto clipRect = ClipParameters::GetClipRect(*clip, zoomInfo, rect);
906  if (!clipRect.IsEmpty())
907  TrackArt::DrawClipEdges(dc, clipRect, selected);
908  }
909 }

References WaveDisplay::Allocate(), anonymous_namespace{WaveformView.cpp}::WavePortion::averageZoom, WaveDisplay::bl, WaveformSettings::dBRange, TrackPanelDrawingContext::dc, TrackArt::DrawClipEdges(), DrawEnvelope(), DrawIndividualSamples(), DrawMinMaxRMS(), TrackArt::DrawNegativeOffsetTrackArrows(), EnvelopeEditor::DrawPoints(), DrawWaveformBackground(), FindWavePortions(), TrackArtist::Get(), ClipParameters::GetClipRect(), WaveClip::GetColourIndex(), WaveTrack::GetDisplayBounds(), WaveClip::GetEnvelope(), EnvelopeHandle::GetEnvelope(), WaveClip::GetPlaySamplesCount(), Track::GetSelected(), SampleHandle::GetTrack(), Envelope::GetValues(), WaveClip::GetWaveDisplay(), WaveTrack::GetWaveformSettings(), anonymous_namespace{WaveformView.cpp}::WavePortion::inFisheye, Track::IsSyncLockSelected(), WaveTrack::LongSamplesToTime(), WaveDisplay::max, WaveDisplay::min, params, anonymous_namespace{WaveformView.cpp}::WavePortion::rect, WaveDisplay::rms, TrackPanelDrawingContext::target, WaveTrack::TimeToLongSamples(), WaveDisplay::where, WaveDisplay::width, and WaveTrack::ZeroLevelYCoordinate().

Referenced by WaveformView::DoDraw().

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

◆ DrawEnvelope()

void anonymous_namespace{WaveformView.cpp}::DrawEnvelope ( TrackPanelDrawingContext context,
const wxRect &  rect,
const double  env[],
float  zoomMin,
float  zoomMax,
bool  dB,
float  dBRange,
bool  highlight 
)

Definition at line 628 of file WaveformView.cpp.

632 {
633  auto &dc = context.dc;
634 
635  int h = rect.height;
636 
637  auto &pen = highlight ? AColor::uglyPen : AColor::envelopePen;
638  dc.SetPen( pen );
639 
640  for (int x0 = 0; x0 < rect.width; ++x0) {
641  int cenvTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
642  h, dB, true, dBRange, true);
643 
644  int cenvBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
645  h, dB, true, dBRange, true);
646 
647  int envTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
648  h, dB, true, dBRange, false);
649 
650  int envBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
651  h, dB, true, dBRange, false);
652 
653  // Make the collision at zero actually look solid
654  if (cenvBot - cenvTop < 9) {
655  int value = (int)((zoomMax / (zoomMax - zoomMin)) * h);
656  cenvTop = value - 4;
657  cenvBot = value + 4;
658  }
659 
660  DrawEnvLine( context, rect, x0, envTop, cenvTop, true );
661  DrawEnvLine( context, rect, x0, envBot, cenvBot, false );
662  }
663 }

References TrackPanelDrawingContext::dc, DrawEnvLine(), AColor::envelopePen, GetWaveYPos(), and AColor::uglyPen.

Referenced by DrawClipWaveform().

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

◆ DrawEnvLine()

void anonymous_namespace{WaveformView.cpp}::DrawEnvLine ( TrackPanelDrawingContext context,
const wxRect &  rect,
int  x0,
int  y0,
int  cy,
bool  top 
)

Definition at line 599 of file WaveformView.cpp.

602 {
603  auto &dc = context.dc;
604 
605  int xx = rect.x + x0;
606  int yy = rect.y + cy;
607 
608  if (y0 < 0) {
609  if (x0 % 4 != 3) {
610  AColor::Line(dc, xx, yy, xx, yy + 3);
611  }
612  }
613  else if (y0 > rect.height) {
614  if (x0 % 4 != 3) {
615  AColor::Line(dc, xx, yy - 3, xx, yy);
616  }
617  }
618  else {
619  if (top) {
620  AColor::Line(dc, xx, yy, xx, yy + 3);
621  }
622  else {
623  AColor::Line(dc, xx, yy - 3, xx, yy);
624  }
625  }
626 }

References TrackPanelDrawingContext::dc, and AColor::Line().

Referenced by DrawEnvelope().

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

◆ DrawIndividualSamples()

void anonymous_namespace{WaveformView.cpp}::DrawIndividualSamples ( TrackPanelDrawingContext context,
int  leftOffset,
const wxRect &  rect,
float  zoomMin,
float  zoomMax,
bool  dB,
float  dBRange,
const WaveClip clip,
bool  showPoints,
bool  muted,
bool  highlight 
)

Definition at line 473 of file WaveformView.cpp.

480 {
481  auto &dc = context.dc;
482  const auto artist = TrackArtist::Get( context );
483  const auto &zoomInfo = *artist->pZoomInfo;
484 
485  const double toffset = clip->GetPlayStartTime();
486  double rate = clip->GetRate();
487  const double t0 = std::max(0.0, zoomInfo.PositionToTime(0, -leftOffset) - toffset);
488  const auto s0 = sampleCount(floor(t0 * rate));
489  const auto snSamples = clip->GetPlaySamplesCount();
490  if (s0 > snSamples)
491  return;
492 
493  const double t1 = zoomInfo.PositionToTime(rect.width - 1, -leftOffset) - toffset;
494  const auto s1 = sampleCount(ceil(t1 * rate));
495 
496  // Assume size_t will not overflow, else we wouldn't be here drawing the
497  // few individual samples
498  auto slen = std::min(snSamples - s0, s1 - s0 + 1).as_size_t();
499 
500  if (slen <= 0)
501  return;
502 
503  Floats buffer{ size_t(slen) };
504  clip->GetSamples((samplePtr)buffer.get(), floatSample, s0, slen,
505  // Suppress exceptions in this drawing operation:
506  false);
507 
508  ArrayOf<int> xpos{ size_t(slen) };
509  ArrayOf<int> ypos{ size_t(slen) };
510  ArrayOf<int> clipped;
511  int clipcnt = 0;
512 
513  const auto bShowClipping = artist->mShowClipping;
514  if (bShowClipping)
515  clipped.reinit( size_t(slen) );
516 
517  const auto &muteSamplePen = artist->muteSamplePen;
518  const auto &samplePen = artist->samplePen;
519  auto &pen = highlight ? AColor::uglyPen : muted ? muteSamplePen : samplePen;
520  dc.SetPen( pen );
521 
522  for (decltype(slen) s = 0; s < slen; s++) {
523  const double time = toffset + (s + s0).as_double() / rate;
524  const int xx = // An offset into the rectangle rect
525  std::max(-10000, std::min(10000,
526  (int)(zoomInfo.TimeToPosition(time, -leftOffset))));
527  xpos[s] = xx;
528 
529  // Calculate sample as it would be rendered, so quantize time
530  double value =
531  clip->GetEnvelope()->GetValue( time, 1.0 / clip->GetRate() );
532  const double tt = buffer[s] * value;
533 
534  if (clipped && bShowClipping && ((tt <= -MAX_AUDIO) || (tt >= MAX_AUDIO)))
535  clipped[clipcnt++] = xx;
536  ypos[s] =
537  std::max(-1,
538  std::min(rect.height,
539  GetWaveYPos(tt, zoomMin, zoomMax,
540  rect.height, dB, true, dBRange, false)));
541  }
542 
543 
544  if (showPoints) {
545  // Draw points where spacing is enough
546  const auto bigPoints = artist->bigPoints;
547  const int tickSize = bigPoints ? 4 : 3;// Bigger ellipses when draggable.
548  wxRect pr;
549  pr.width = tickSize;
550  pr.height = tickSize;
551  //different colour when draggable.
552  const auto &dragsampleBrush = artist->dragsampleBrush;
553  const auto &sampleBrush = artist->sampleBrush;
554  auto &brush = highlight
556  : bigPoints ? dragsampleBrush : sampleBrush;
557  dc.SetBrush( brush );
558  for (decltype(slen) s = 0; s < slen; s++) {
559  if (ypos[s] >= 0 && ypos[s] < rect.height) {
560  pr.x = rect.x + xpos[s] - tickSize/2;
561  pr.y = rect.y + ypos[s] - tickSize/2;
562  dc.DrawEllipse(pr);
563  }
564  }
565  }
566 
567  const auto sampleDisplay = artist->mSampleDisplay;
568  if (showPoints && (sampleDisplay == (int) WaveTrackViewConstants::StemPlot)) {
569  // Draw vertical lines
570  int yZero = GetWaveYPos(0.0, zoomMin, zoomMax, rect.height, dB, true, dBRange, false);
571  yZero = rect.y + std::max(-1, std::min(rect.height, yZero));
572  for (decltype(slen) s = 0; s < slen; s++) {
573  AColor::Line(dc,
574  rect.x + xpos[s], rect.y + ypos[s],
575  rect.x + xpos[s], yZero);
576  }
577  }
578  else {
579  // Connect samples with straight lines
580  for (decltype(slen) s = 0; s < slen - 1; s++) {
581  AColor::Line(dc,
582  rect.x + xpos[s], rect.y + ypos[s],
583  rect.x + xpos[s + 1], rect.y + ypos[s + 1]);
584  }
585  }
586 
587  // Draw clipping
588  if (clipcnt) {
589  const auto &muteClippedPen = artist->muteClippedPen;
590  const auto &clippedPen = artist->clippedPen;
591  dc.SetPen(muted ? muteClippedPen : clippedPen);
592  while (--clipcnt >= 0) {
593  auto s = clipped[clipcnt];
594  AColor::Line(dc, rect.x + s, rect.y, rect.x + s, rect.y + rect.height);
595  }
596  }
597 }

References TrackPanelDrawingContext::dc, floatSample, TrackArtist::Get(), WaveClip::GetEnvelope(), WaveClip::GetPlaySamplesCount(), WaveClip::GetPlayStartTime(), WaveClip::GetRate(), WaveClip::GetSamples(), Envelope::GetValue(), GetWaveYPos(), AColor::Line(), MAX_AUDIO, min(), ArrayOf< X >::reinit(), WaveTrackViewConstants::StemPlot, AColor::uglyBrush, and AColor::uglyPen.

Referenced by DrawClipWaveform().

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

◆ DrawMinMaxRMS()

void anonymous_namespace{WaveformView.cpp}::DrawMinMaxRMS ( TrackPanelDrawingContext context,
const wxRect &  rect,
const double  env[],
float  zoomMin,
float  zoomMax,
bool  dB,
float  dBRange,
const float *  min,
const float *  max,
const float *  rms,
const int *  bl,
bool  muted 
)

Definition at line 324 of file WaveformView.cpp.

330 {
331  auto &dc = context.dc;
332 
333  // Display a line representing the
334  // min and max of the samples in this region
335  int lasth1 = std::numeric_limits<int>::max();
336  int lasth2 = std::numeric_limits<int>::min();
337  int h1;
338  int h2;
339  ArrayOf<int> r1{ size_t(rect.width) };
340  ArrayOf<int> r2{ size_t(rect.width) };
341  ArrayOf<int> clipped;
342  int clipcnt = 0;
343 
344  const auto artist = TrackArtist::Get( context );
345  const auto bShowClipping = artist->mShowClipping;
346  if (bShowClipping) {
347  clipped.reinit( size_t(rect.width) );
348  }
349 
350  long pixAnimOffset = (long)fabs((double)(wxDateTime::Now().GetTicks() * -10)) +
351  wxDateTime::Now().GetMillisecond() / 100; //10 pixels a second
352 
353  bool drawStripes = true;
354  bool drawWaveform = true;
355 
356  const auto &muteSamplePen = artist->muteSamplePen;
357  const auto &samplePen = artist->samplePen;
358 
359  dc.SetPen(muted ? muteSamplePen : samplePen);
360  for (int x0 = 0; x0 < rect.width; ++x0) {
361  int xx = rect.x + x0;
362  double v;
363  v = min[x0] * env[x0];
364  if (clipped && bShowClipping && (v <= -MAX_AUDIO))
365  {
366  if (clipcnt == 0 || clipped[clipcnt - 1] != xx) {
367  clipped[clipcnt++] = xx;
368  }
369  }
370  h1 = GetWaveYPos(v, zoomMin, zoomMax,
371  rect.height, dB, true, dBRange, true);
372 
373  v = max[x0] * env[x0];
374  if (clipped && bShowClipping && (v >= MAX_AUDIO))
375  {
376  if (clipcnt == 0 || clipped[clipcnt - 1] != xx) {
377  clipped[clipcnt++] = xx;
378  }
379  }
380  h2 = GetWaveYPos(v, zoomMin, zoomMax,
381  rect.height, dB, true, dBRange, true);
382 
383  // JKC: This adjustment to h1 and h2 ensures that the drawn
384  // waveform is continuous.
385  if (x0 > 0) {
386  if (h1 < lasth2) {
387  h1 = lasth2 - 1;
388  }
389  if (h2 > lasth1) {
390  h2 = lasth1 + 1;
391  }
392  }
393  lasth1 = h1;
394  lasth2 = h2;
395 
396  r1[x0] = GetWaveYPos(-rms[x0] * env[x0], zoomMin, zoomMax,
397  rect.height, dB, true, dBRange, true);
398  r2[x0] = GetWaveYPos(rms[x0] * env[x0], zoomMin, zoomMax,
399  rect.height, dB, true, dBRange, true);
400  // Make sure the rms isn't larger than the waveform min/max
401  if (r1[x0] > h1 - 1) {
402  r1[x0] = h1 - 1;
403  }
404  if (r2[x0] < h2 + 1) {
405  r2[x0] = h2 + 1;
406  }
407  if (r2[x0] > r1[x0]) {
408  r2[x0] = r1[x0];
409  }
410 
411  if (bl[x0] <= -1) {
412  if (drawStripes) {
413  // TODO:unify with buffer drawing.
414  dc.SetPen((bl[x0] % 2) ? muteSamplePen : samplePen);
415  for (int yy = 0; yy < rect.height / 25 + 1; ++yy) {
416  // we are drawing over the buffer, but I think DrawLine takes care of this.
417  AColor::Line(dc,
418  xx,
419  rect.y + 25 * yy + (x0 /*+pixAnimOffset*/) % 25,
420  xx,
421  rect.y + 25 * yy + (x0 /*+pixAnimOffset*/) % 25 + 6); //take the min so we don't draw past the edge
422  }
423  }
424 
425  // draw a dummy waveform - some kind of sinusoid. We want to animate it so the user knows it's a dummy. Use the second's unit of a get time function.
426  // Lets use a triangle wave for now since it's easier - I don't want to use sin() or make a wavetable just for this.
427  if (drawWaveform) {
428  int triX;
429  dc.SetPen(samplePen);
430  triX = fabs((double)((x0 + pixAnimOffset) % (2 * rect.height)) - rect.height) + rect.height;
431  for (int yy = 0; yy < rect.height; ++yy) {
432  if ((yy + triX) % rect.height == 0) {
433  dc.DrawPoint(xx, rect.y + yy);
434  }
435  }
436  }
437 
438  // Restore the pen for remaining pixel columns!
439  dc.SetPen(muted ? muteSamplePen : samplePen);
440  }
441  else {
442  AColor::Line(dc, xx, rect.y + h2, xx, rect.y + h1);
443  }
444  }
445 
446  // Stroke rms over the min-max
447  const auto &muteRmsPen = artist->muteRmsPen;
448  const auto &rmsPen = artist->rmsPen;
449 
450  dc.SetPen(muted ? muteRmsPen : rmsPen);
451  for (int x0 = 0; x0 < rect.width; ++x0) {
452  int xx = rect.x + x0;
453  if (bl[x0] <= -1) {
454  }
455  else if (r1[x0] != r2[x0]) {
456  AColor::Line(dc, xx, rect.y + r2[x0], xx, rect.y + r1[x0]);
457  }
458  }
459 
460  // Draw the clipping lines
461  if (clipcnt) {
462  const auto &muteClippedPen = artist->muteClippedPen;
463  const auto &clippedPen = artist->clippedPen;
464 
465  dc.SetPen(muted ? muteClippedPen : clippedPen);
466  while (--clipcnt >= 0) {
467  int xx = clipped[clipcnt];
468  AColor::Line(dc, xx, rect.y, xx, rect.y + rect.height);
469  }
470  }
471 }

References TrackPanelDrawingContext::dc, TrackArtist::Get(), GetWaveYPos(), AColor::Line(), MAX_AUDIO, min(), and ArrayOf< X >::reinit().

Referenced by DrawClipWaveform().

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

◆ DrawTimeSlider()

void anonymous_namespace{WaveformView.cpp}::DrawTimeSlider ( TrackPanelDrawingContext context,
const wxRect &  rect,
bool  rightwards,
bool  highlight 
)

Definition at line 911 of file WaveformView.cpp.

914 {
915  auto &dc = context.dc;
916 
917  const int border = 3; // 3 pixels all round.
918  const int width = 6; // width of the drag box.
919  const int taper = 6; // how much the box tapers by.
920  const int barSpacing = 4; // how far apart the bars are.
921  const int barWidth = 3;
922  const int xFlat = 3;
923 
924  //Enough space to draw in?
925  if (rect.height <= ((taper+border + barSpacing) * 2)) {
926  return;
927  }
928  if (rect.width <= (width * 2 + border * 3)) {
929  return;
930  }
931 
932  // The draggable box is tapered towards the direction you drag it.
933  int leftTaper = rightwards ? 0 : 6;
934  int rightTaper = rightwards ? 6 : 0;
935 
936  int xLeft = rightwards ? (rect.x + border - 2)
937  : (rect.x + rect.width + 1 - (border + width));
938  int yTop = rect.y + border;
939  int yBot = rect.y + rect.height - border - 1;
940 
941  AColor::Light(&dc, false, highlight);
942  AColor::Line(dc, xLeft, yBot - leftTaper, xLeft, yTop + leftTaper);
943  AColor::Line(dc, xLeft, yTop + leftTaper, xLeft + xFlat, yTop);
944  AColor::Line(dc, xLeft + xFlat, yTop, xLeft + width, yTop + rightTaper);
945 
946  AColor::Dark(&dc, false, highlight);
947  AColor::Line(dc, xLeft + width, yTop + rightTaper, xLeft + width, yBot - rightTaper);
948  AColor::Line(dc, xLeft + width, yBot - rightTaper, xLeft + width-xFlat, yBot);
949  AColor::Line(dc, xLeft + width - xFlat, yBot, xLeft, yBot - leftTaper);
950 
951  int firstBar = yTop + taper + taper / 2;
952  int nBars = (yBot - yTop - taper * 3) / barSpacing + 1;
953  xLeft += (width - barWidth + 1) / 2;
954  int yy;
955  int i;
956 
957  AColor::Light(&dc, false, highlight);
958  for (i = 0;i < nBars; i++) {
959  yy = firstBar + barSpacing * i;
960  AColor::Line(dc, xLeft, yy, xLeft + barWidth, yy);
961  }
962  AColor::Dark(&dc, false, highlight);
963  for(i = 0;i < nBars; i++){
964  yy = firstBar + barSpacing * i + 1;
965  AColor::Line(dc, xLeft, yy, xLeft + barWidth, yy);
966  }
967 }

References AColor::Dark(), TrackPanelDrawingContext::dc, AColor::Light(), and AColor::Line().

Referenced by WaveformView::DoDraw().

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

◆ DrawWaveformBackground()

void anonymous_namespace{WaveformView.cpp}::DrawWaveformBackground ( TrackPanelDrawingContext context,
int  leftOffset,
const wxRect &  rect,
const double  env[],
float  zoomMin,
float  zoomMax,
int  zeroLevelYCoordinate,
bool  dB,
float  dBRange,
double  t0,
double  t1,
bool  bIsSyncLockSelected,
bool  highlightEnvelope 
)

Definition at line 143 of file WaveformView.cpp.

152 {
153  auto &dc = context.dc;
154  const auto artist = TrackArtist::Get( context );
155  const auto &zoomInfo = *artist->pZoomInfo;
156 
157  // Visually (one vertical slice of the waveform background, on its side;
158  // the "*" is the actual waveform background we're drawing
159  //
160  //1.0 0.0 -1.0
161  // |--------------------------------|--------------------------------|
162  // *************** ***************
163  // | | | |
164  // maxtop maxbot mintop minbot
165 
166  int h = rect.height;
167  int halfHeight = wxMax(h / 2, 1);
168  int maxtop, lmaxtop = 0;
169  int mintop, lmintop = 0;
170  int maxbot, lmaxbot = 0;
171  int minbot, lminbot = 0;
172  bool sel, lsel = false;
173  int xx, lx = 0;
174  int l, w;
175 
176  const auto &blankBrush = artist->blankBrush;
177  const auto &selectedBrush = artist->selectedBrush;
178  const auto &unselectedBrush = artist->unselectedBrush;
179 
180  dc.SetPen(*wxTRANSPARENT_PEN);
181  dc.SetBrush(blankBrush);
182  dc.DrawRectangle(rect);
183 
184  // Bug 2389 - always draw at least one pixel of selection.
185  int selectedX = zoomInfo.TimeToPosition(t0, -leftOffset);
186 
187  double time = zoomInfo.PositionToTime(0, -leftOffset), nextTime;
188  for (xx = 0; xx < rect.width; ++xx, time = nextTime) {
189  nextTime = zoomInfo.PositionToTime(xx + 1, -leftOffset);
190  // First we compute the truncated shape of the waveform background.
191  // If drawEnvelope is true, then we compute the lower border of the
192  // envelope.
193 
194  maxtop = GetWaveYPos(env[xx], zoomMin, zoomMax,
195  h, dB, true, dBRange, true);
196  maxbot = GetWaveYPos(env[xx], zoomMin, zoomMax,
197  h, dB, false, dBRange, true);
198 
199  mintop = GetWaveYPos(-env[xx], zoomMin, zoomMax,
200  h, dB, false, dBRange, true);
201  minbot = GetWaveYPos(-env[xx], zoomMin, zoomMax,
202  h, dB, true, dBRange, true);
203 
204  // Make sure it's odd so that a that max and min mirror each other
205  mintop +=1;
206  minbot +=1;
207 
208  const auto drawEnvelope = artist->drawEnvelope;
209  if (!drawEnvelope || maxbot > mintop) {
210  maxbot = halfHeight;
211  mintop = halfHeight;
212  }
213 
214  sel = (t0 <= time && nextTime < t1);
215  sel = sel || (xx == selectedX);
216  // We don't draw selection color for sync-lock selected tracks.
217  sel = sel && !bIsSyncLockSelected;
218 
219  if (lmaxtop == maxtop &&
220  lmintop == mintop &&
221  lmaxbot == maxbot &&
222  lminbot == minbot &&
223  lsel == sel) {
224  continue;
225  }
226 
227  dc.SetBrush(lsel ? selectedBrush : unselectedBrush);
228 
229  l = rect.x + lx;
230  w = xx - lx;
231  if (lmaxbot < lmintop - 1) {
232  dc.DrawRectangle(l, rect.y + lmaxtop, w, lmaxbot - lmaxtop);
233  dc.DrawRectangle(l, rect.y + lmintop, w, lminbot - lmintop);
234  }
235  else {
236  dc.DrawRectangle(l, rect.y + lmaxtop, w, lminbot - lmaxtop);
237  }
238 
239  if (highlightEnvelope && lmaxbot < lmintop - 1) {
240  dc.SetBrush( AColor::uglyBrush );
241  dc.DrawRectangle(l, rect.y + lmaxbot, w, lmintop - lmaxbot);
242  }
243 
244  lmaxtop = maxtop;
245  lmintop = mintop;
246  lmaxbot = maxbot;
247  lminbot = minbot;
248  lsel = sel;
249  lx = xx;
250  }
251 
252  dc.SetBrush(lsel ? selectedBrush : unselectedBrush);
253  l = rect.x + lx;
254  w = xx - lx;
255  if (lmaxbot < lmintop - 1) {
256  dc.DrawRectangle(l, rect.y + lmaxtop, w, lmaxbot - lmaxtop);
257  dc.DrawRectangle(l, rect.y + lmintop, w, lminbot - lmintop);
258  }
259  else {
260  dc.DrawRectangle(l, rect.y + lmaxtop, w, lminbot - lmaxtop);
261  }
262  if (highlightEnvelope && lmaxbot < lmintop - 1) {
263  dc.SetBrush( AColor::uglyBrush );
264  dc.DrawRectangle(l, rect.y + lmaxbot, w, lmintop - lmaxbot);
265  }
266 
267  // If sync-lock selected, draw in linked graphics.
268  if (bIsSyncLockSelected && t0 < t1) {
269  const int begin = std::max(0, std::min(rect.width, (int)(zoomInfo.TimeToPosition(t0, -leftOffset))));
270  const int end = std::max(0, std::min(rect.width, (int)(zoomInfo.TimeToPosition(t1, -leftOffset))));
272  { rect.x + begin, rect.y, end - 1 - begin, rect.height } );
273  }
274 
275  //OK, the display bounds are between min and max, which
276  //is spread across rect.height. Draw the line at the proper place.
277  if (zeroLevelYCoordinate >= rect.GetTop() &&
278  zeroLevelYCoordinate <= rect.GetBottom()) {
279  dc.SetPen(*wxBLACK_PEN);
280  AColor::Line(dc, rect.x, zeroLevelYCoordinate,
281  rect.x + rect.width, zeroLevelYCoordinate);
282  }
283 }

References TrackPanelDrawingContext::dc, TrackArt::DrawSyncLockTiles(), TrackArtist::Get(), GetWaveYPos(), AColor::Line(), min(), and AColor::uglyBrush.

Referenced by DrawClipWaveform().

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

◆ FindWavePortions()

void anonymous_namespace{WaveformView.cpp}::FindWavePortions ( std::vector< WavePortion > &  portions,
const wxRect &  rect,
const ZoomInfo zoomInfo,
const ClipParameters params 
)

Definition at line 294 of file WaveformView.cpp.

297 {
298  // If there is no fisheye, then only one rectangle has nonzero width.
299  // If there is a fisheye, make rectangles for before and after
300  // (except when they are squeezed to zero width), and at least one for inside
301  // the fisheye.
302 
303  ZoomInfo::Intervals intervals;
304  zoomInfo.FindIntervals(params.rate, intervals, rect.width, rect.x);
305  ZoomInfo::Intervals::const_iterator it = intervals.begin(), end = intervals.end(), prev;
306  wxASSERT(it != end && it->position == rect.x);
307  const int rightmost = rect.x + rect.width;
308  for (int left = rect.x; left < rightmost;) {
309  while (it != end && it->position <= left)
310  prev = it++;
311  if (it == end)
312  break;
313  const int right = std::max(left, (int)(it->position));
314  const int width = right - left;
315  if (width > 0)
316  portions.push_back(
317  WavePortion(left, rect.y, width, rect.height,
318  prev->averageZoom, prev->inFisheye)
319  );
320  left = right;
321  }
322 }

References ZoomInfo::FindIntervals(), and params.

Referenced by DrawClipWaveform().

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

◆ GetWaveColorStr()

const TranslatableString anonymous_namespace{WaveformView.cpp}::GetWaveColorStr ( int  colorIndex)

Definition at line 1101 of file WaveformView.cpp.

1102 {
1103  return XXO("Instrument %i").Format( colorIndex+1 );
1104 }

References XXO.

Referenced by WaveColorMenuTable::OnWaveColorChange().

Here is the caller graph for this function:

Variable Documentation

◆ sAttachment

PopupMenuTable::AttachedItem anonymous_namespace{WaveformView.cpp}::sAttachment
Initial value:
{
{ "SubViews/Extra" },
std::make_unique<PopupMenuSection>( "WaveColor",
PopupMenuTable::Computed< WaveTrackPopupMenuTable >(
const auto pTrack = &table.FindWaveTrack();
const auto &view = WaveTrackView::Get( *pTrack );
const auto displays = view.GetDisplays();
bool hasWaveform = (displays.end() != std::find(
displays.begin(), displays.end(),
WaveTrackSubView::Type{ WaveTrackViewConstants::Waveform, {} }
) );
if( hasWaveform )
.Get( table.mpData ) );
else
return nullptr;
} ) )
}

Definition at line 1168 of file WaveformView.cpp.

anonymous_namespace{WaveformView.cpp}::FindWavePortions
void FindWavePortions(std::vector< WavePortion > &portions, const wxRect &rect, const ZoomInfo &zoomInfo, const ClipParameters &params)
Definition: WaveformView.cpp:295
EnvelopeHandle::GetEnvelope
Envelope * GetEnvelope() const
Definition: EnvelopeHandle.h:59
WaveClip::GetEnvelope
Envelope * GetEnvelope()
Definition: WaveClip.h:277
Profiler
A simple profiler to measure the average time lengths that a particular task/function takes....
Definition: Profiler.h:40
WaveClip::GetWaveDisplay
bool GetWaveDisplay(WaveDisplay &display, double t0, double pixelsPerSecond) const
Definition: WaveClip.cpp:313
WaveClip::GetPlaySamplesCount
sampleCount GetPlaySamplesCount() const
Definition: WaveClip.cpp:1821
WaveClip::GetRate
int GetRate() const
Definition: WaveClip.h:211
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:109
ArrayOf::reinit
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:57
Registry::Shared
std::unique_ptr< SharedItem > Shared(const BaseItemSharedPtr &ptr)
Definition: Registry.h:93
AColor::uglyBrush
static wxBrush uglyBrush
Definition: AColor.h:131
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
anonymous_namespace{WaveformView.cpp}::DrawWaveformBackground
void DrawWaveformBackground(TrackPanelDrawingContext &context, int leftOffset, const wxRect &rect, const double env[], float zoomMin, float zoomMax, int zeroLevelYCoordinate, bool dB, float dBRange, double t0, double t1, bool bIsSyncLockSelected, bool highlightEnvelope)
Definition: WaveformView.cpp:143
EnvelopeHandle
Definition: EnvelopeHandle.h:28
AColor::envelopePen
static wxPen envelopePen
Definition: AColor.h:104
Track::IsSyncLockSelected
bool IsSyncLockSelected() const
Definition: Track.cpp:254
GetWaveTrackMenuTable
WaveTrackPopupMenuTable & GetWaveTrackMenuTable()
Definition: WaveTrackControls.cpp:960
WaveTrack::ZeroLevelYCoordinate
int ZeroLevelYCoordinate(wxRect rect) const
Definition: WaveTrack.cpp:382
SampleHandle
Definition: SampleHandle.h:25
TrackArt::DrawSyncLockTiles
AUDACITY_DLL_API void DrawSyncLockTiles(TrackPanelDrawingContext &context, const wxRect &rect)
Definition: TrackArtist.cpp:418
floatSample
@ floatSample
Definition: SampleFormat.h:34
ClipParameters::GetClipRect
static wxRect GetClipRect(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
Definition: WaveTrackView.cpp:1448
WaveClip::GetSamples
bool GetSamples(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
Definition: WaveClip.cpp:216
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:79
XXO
#define XXO(s)
Definition: Internat.h:44
Registry::BaseItemPtr
std::unique_ptr< BaseItem > BaseItemPtr
Definition: Registry.h:71
WaveColorMenuTable::Instance
static WaveColorMenuTable & Instance()
Definition: WaveformView.cpp:1087
WaveTrackSubViewType
Definition: WaveTrackViewConstants.h:91
WaveTrack::LongSamplesToTime
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: WaveTrack.cpp:1862
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
anonymous_namespace{WaveformView.cpp}::DrawEnvLine
void DrawEnvLine(TrackPanelDrawingContext &context, const wxRect &rect, int x0, int y0, int cy, bool top)
Definition: WaveformView.cpp:599
WaveClip::GetColourIndex
int GetColourIndex() const
Definition: WaveClip.h:221
TrackArt::DrawNegativeOffsetTrackArrows
AUDACITY_DLL_API void DrawNegativeOffsetTrackArrows(TrackPanelDrawingContext &context, const wxRect &rect)
Definition: TrackArtist.cpp:213
AColor::Light
static void Light(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:321
ClipParameters
Definition: WaveTrackView.h:221
AColor::uglyPen
static wxPen uglyPen
Definition: AColor.h:130
EnvelopeEditor::DrawPoints
static void DrawPoints(const Envelope &env, TrackPanelDrawingContext &context, const wxRect &r, bool dB, double dBRange, float zoomMin, float zoomMax, bool mirrored)
Definition: EnvelopeEditor.cpp:36
WaveTrack::GetWaveformSettings
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:811
SampleHandle::GetTrack
std::shared_ptr< WaveTrack > GetTrack() const
Definition: SampleHandle.h:45
Track::GetSelected
bool GetSelected() const
Definition: Track.h:431
ZoomInfo::FindIntervals
void FindIntervals(double rate, Intervals &results, wxInt64 width, wxInt64 origin=0) const
Definition: ZoomInfo.cpp:108
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
Envelope::GetValue
double GetValue(double t, double sampleDur=0) const
Get envelope value at time t.
Definition: Envelope.cpp:827
WaveTrack::TimeToLongSamples
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1857
AColor::Dark
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:351
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
TrackArt::DrawClipEdges
AUDACITY_DLL_API void DrawClipEdges(wxDC &dc, const wxRect &clipRect, bool selected=false)
Definition: TrackArtist.cpp:368
WaveTrackView::Get
static WaveTrackView & Get(WaveTrack &track)
Definition: WaveTrackView.cpp:851
WaveTrackViewConstants::StemPlot
@ StemPlot
Definition: WaveTrackViewConstants.h:47
WaveformSettings::dBRange
int dBRange
Definition: WaveformSettings.h:68
GetWaveYPos
int GetWaveYPos(float value, float min, float max, int height, bool dB, bool outer, float dBr, bool clip)
Definition: TrackArtist.cpp:136
TrackPanelDrawingContext::target
UIHandlePtr target
Definition: TrackPanelDrawingContext.h:24
WaveTrackPopupMenuTable::FindWaveTrack
WaveTrack & FindWaveTrack() const
Definition: WaveTrackControls.cpp:89
anonymous_namespace{WaveformView.cpp}::DrawIndividualSamples
void DrawIndividualSamples(TrackPanelDrawingContext &context, int leftOffset, const wxRect &rect, float zoomMin, float zoomMax, bool dB, float dBRange, const WaveClip *clip, bool showPoints, bool muted, bool highlight)
Definition: WaveformView.cpp:473
anonymous_namespace{WaveformView.cpp}::DrawMinMaxRMS
void DrawMinMaxRMS(TrackPanelDrawingContext &context, const wxRect &rect, const double env[], float zoomMin, float zoomMax, bool dB, float dBRange, const float *min, const float *max, const float *rms, const int *bl, bool muted)
Definition: WaveformView.cpp:324
params
EffectDistortion::Params params
Definition: Distortion.cpp:99
WaveTrack::GetDisplayBounds
void GetDisplayBounds(float *min, float *max) const
Definition: WaveTrack.cpp:320
WaveTrackPopupMenuTable
Definition: WaveTrackControls.h:74
ZoomInfo::Intervals
std::vector< Interval > Intervals
Definition: ZoomInfo.h:146
anonymous_namespace{WaveformView.cpp}::DrawEnvelope
void DrawEnvelope(TrackPanelDrawingContext &context, const wxRect &rect, const double env[], float zoomMin, float zoomMax, bool dB, float dBRange, bool highlight)
Definition: WaveformView.cpp:628
WaveClip::GetPlayStartTime
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:1790
WaveTrackPopupMenuTable::mpData
PlayableTrackControls::InitMenuData * mpData
Definition: WaveTrackControls.h:76
ArrayOf< float >
MAX_AUDIO
#define MAX_AUDIO
Definition: MemoryX.h:633
Envelope::GetValues
static void GetValues(const Envelope &env, double aligned_time, double sampleDur, double *buffer, int bufferLen, int leftOffset, const ZoomInfo &zoomInfo)
Get many envelope points for pixel columns at once, but don't assume uniform time per pixel.
Definition: Envelope.cpp:1472
WaveDisplay
Definition: WaveClip.h:130