Audacity 3.2.0
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 1123 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 678 of file WaveformView.cpp.

685{
686 auto &dc = context.dc;
687 const auto artist = TrackArtist::Get( context );
688 const auto &selectedRegion = *artist->pSelectedRegion;
689 const auto &zoomInfo = *artist->pZoomInfo;
690
692
693 bool highlightEnvelope = false;
694#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
695 auto target = dynamic_cast<EnvelopeHandle*>(context.target.get());
696 highlightEnvelope = target && target->GetEnvelope() == clip->GetEnvelope();
697#endif
698
699 //If clip is "too small" draw a placeholder instead of
700 //attempting to fit the contents into a few pixels
701 if (!WaveTrackView::ClipDetailsVisible(*clip, zoomInfo, rect))
702 {
703 auto clipRect = ClipParameters::GetClipRect(*clip, zoomInfo, rect);
704 TrackArt::DrawClipFolded(dc, clipRect);
705 return;
706 }
707
709 false, track, clip, rect, selectedRegion, zoomInfo };
710 const wxRect &hiddenMid = params.hiddenMid;
711 // The "hiddenMid" rect contains the part of the display actually
712 // containing the waveform, as it appears without the fisheye. If it's empty, we're done.
713 if (hiddenMid.width <= 0) {
714 return;
715 }
716
717 const double &t0 = params.t0;
718 const double &tOffset = params.tOffset;
719 const double &h = params.h;
720 const double &tpre = params.tpre;
721 const double &tpost = params.tpost;
722 const double &t1 = params.t1;
723 const double &averagePixelsPerSample = params.averagePixelsPerSample;
724 const double &rate = params.rate;
725 double leftOffset = params.leftOffset;
726 const wxRect &mid = params.mid;
727
728 auto &settings = WaveformSettings::Get(*track);
729 const float dBRange = settings.dBRange;
730
731 dc.SetPen(*wxTRANSPARENT_PEN);
732 int iColorIndex = clip->GetColourIndex();
733 artist->SetColours( iColorIndex );
734
735 // The bounds (controlled by vertical zooming; -1.0...1.0
736 // by default)
737 float zoomMin, zoomMax;
738 auto &cache = WaveformScale::Get(*track);
739 cache.GetDisplayBounds(zoomMin, zoomMax);
740
741 std::vector<double> vEnv(mid.width);
742 double *const env = &vEnv[0];
744 tOffset,
745
746 // PRL: change back to make envelope evaluate only at sample times
747 // and then interpolate the display
748 0, // 1.0 / rate,
749
750 env, mid.width, leftOffset, zoomInfo );
751
752 // Draw the background of the track, outlining the shape of
753 // the envelope and using a colored pen for the selected
754 // part of the waveform
755 {
756 double tt0, tt1;
758 tt0 = track->LongSamplesToTime(track->TimeToLongSamples(selectedRegion.t0())),
759 tt1 = track->LongSamplesToTime(track->TimeToLongSamples(selectedRegion.t1()));
760 }
761 else
762 tt0 = tt1 = 0.0;
763 DrawWaveformBackground(context, leftOffset, mid,
764 env,
765 zoomMin, zoomMax,
766 cache.ZeroLevelYCoordinate(mid),
767 dB, dBRange,
768 tt0, tt1,
769 !track->GetSelected(), highlightEnvelope);
770 }
771
772 WaveDisplay display(hiddenMid.width);
773
774 const double pps =
775 averagePixelsPerSample * rate;
776
777 // For each portion separately, we will decide to draw
778 // it as min/max/rms or as individual samples.
779 std::vector<WavePortion> portions;
780 FindWavePortions(portions, rect, zoomInfo, params);
781 const unsigned nPortions = portions.size();
782
783 // Require at least 1/2 pixel per sample for drawing individual samples.
784 const double threshold1 = 0.5 * rate;
785 // Require at least 3 pixels per sample for drawing the draggable points.
786 const double threshold2 = 3 * rate;
787
788 auto &clipCache = WaveClipWaveformCache::Get(*clip);
789
790 {
791 bool showIndividualSamples = false;
792 for (unsigned ii = 0; !showIndividualSamples && ii < nPortions; ++ii) {
793 const WavePortion &portion = portions[ii];
794 showIndividualSamples =
795 !portion.inFisheye && portion.averageZoom > threshold1;
796 }
797
798 if (!showIndividualSamples) {
799 // The WaveClip class handles the details of computing the shape
800 // of the waveform. The only way GetWaveDisplay will fail is if
801 // there's a serious error, like some of the waveform data can't
802 // be loaded. So if the function returns false, we can just exit.
803
804 // Note that we compute the full width display even if there is a
805 // fisheye hiding part of it, because of the caching. If the
806 // fisheye moves over the background, there is then less to do when
807 // redrawing.
808
809 if (!clipCache.GetWaveDisplay( *clip, display,
810 t0, pps))
811 return;
812 }
813 }
814
815 // TODO Add a comment to say what this loop does.
816 // Possibly make it into a subroutine.
817 for (unsigned ii = 0; ii < nPortions; ++ii) {
818 WavePortion &portion = portions[ii];
819 const bool showIndividualSamples = portion.averageZoom > threshold1;
820 const bool showPoints = portion.averageZoom > threshold2;
821 wxRect& rectPortion = portion.rect;
822 rectPortion.Intersect(mid);
823 wxASSERT(rectPortion.width >= 0);
824
825 float *useMin = 0, *useMax = 0, *useRms = 0;
826 int *useBl = 0;
827 WaveDisplay fisheyeDisplay(rectPortion.width);
828 int skipped = 0, skippedLeft = 0, skippedRight = 0;
829 if (portion.inFisheye) {
830 if (!showIndividualSamples) {
831 fisheyeDisplay.Allocate();
832 const auto numSamples = clip->GetPlaySamplesCount();
833 // Get wave display data for different magnification
834 int jj = 0;
835 for (; jj < rectPortion.width; ++jj) {
836 const double time =
837 zoomInfo.PositionToTime(jj, -leftOffset) - tOffset;
838 const auto sample = (sampleCount)floor(time * rate + 0.5);
839 if (sample < 0) {
840 ++rectPortion.x;
841 ++skippedLeft;
842 continue;
843 }
844 if (sample >= numSamples)
845 break;
846 fisheyeDisplay.where[jj - skippedLeft] = sample;
847 }
848
849 skippedRight = rectPortion.width - jj;
850 skipped = skippedRight + skippedLeft;
851 rectPortion.width -= skipped;
852
853 // where needs a sentinel
854 if (jj > 0)
855 fisheyeDisplay.where[jj - skippedLeft] =
856 1 + fisheyeDisplay.where[jj - skippedLeft - 1];
857 fisheyeDisplay.width -= skipped;
858 // Get a wave display for the fisheye, uncached.
859 if (rectPortion.width > 0)
860 if (!clipCache.GetWaveDisplay( *clip,
861 fisheyeDisplay, t0, -1.0)) // ignored
862 continue; // serious error. just don't draw??
863 useMin = fisheyeDisplay.min;
864 useMax = fisheyeDisplay.max;
865 useRms = fisheyeDisplay.rms;
866 useBl = fisheyeDisplay.bl;
867 }
868 }
869 else {
870 const int pos = leftOffset - params.hiddenLeftOffset;
871 useMin = display.min + pos;
872 useMax = display.max + pos;
873 useRms = display.rms + pos;
874 useBl = display.bl + pos;
875 }
876
877 leftOffset += skippedLeft;
878
879 if (rectPortion.width > 0) {
880 if (!showIndividualSamples) {
881 std::vector<double> vEnv2(rectPortion.width);
882 double *const env2 = &vEnv2[0];
884 tOffset,
885
886 // PRL: change back to make envelope evaluate only at sample times
887 // and then interpolate the display
888 0, // 1.0 / rate,
889
890 env2, rectPortion.width, leftOffset, zoomInfo );
891
892 DrawMinMaxRMS( context, rectPortion, env2,
893 zoomMin, zoomMax,
894 dB, dBRange,
895 useMin, useMax, useRms, useBl, muted );
896 }
897 else {
898 bool highlight = false;
899#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
900 auto target = dynamic_cast<SampleHandle*>(context.target.get());
901 highlight = target && target->GetTrack().get() == track;
902#endif
904 context, leftOffset, rectPortion, zoomMin, zoomMax,
905 dB, dBRange,
906 clip,
907 showPoints, muted, highlight );
908 }
909 }
910
911 leftOffset += rectPortion.width + skippedRight;
912 }
913
914 const auto drawEnvelope = artist->drawEnvelope;
915 if (drawEnvelope) {
917 context, mid, env, zoomMin, zoomMax, dB, dBRange, highlightEnvelope );
919 context, mid, dB, dBRange, zoomMin, zoomMax, true, rect.x - mid.x );
920 }
921
922 // Draw arrows on the left side if the track extends to the left of the
923 // beginning of time. :)
924 if (h == 0.0 && tOffset < 0.0) {
926 }
927 {
928 auto clipRect = ClipParameters::GetClipRect(*clip, zoomInfo, rect);
929 TrackArt::DrawClipEdges(dc, clipRect, selected);
930 }
931}
EffectDistortionSettings params
Definition: Distortion.cpp:77
static Settings & settings()
Definition: TrackInfo.cpp:83
static void GetEnvelopeValues(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.
static void DrawPoints(const Envelope &env, TrackPanelDrawingContext &context, const wxRect &r, bool dB, double dBRange, float zoomMin, float zoomMax, bool mirrored, int origin=0)
Envelope * GetEnvelope() const
@ WaveformView
Time required to draw a single clip.
static Stopwatch CreateStopwatch(SectionID section) noexcept
Create a Stopwatch for the section specified.
std::shared_ptr< WaveTrack > GetTrack() const
Definition: SampleHandle.h:45
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:48
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:43
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
bool GetSelected() const
Selectedness is always the same for all channels of a group.
Definition: Track.cpp:82
Envelope * GetEnvelope()
Definition: WaveClip.h:219
sampleCount GetPlaySamplesCount() const
Definition: WaveClip.cpp:921
int GetColourIndex() const
Definition: WaveClip.h:150
static bool ClipDetailsVisible(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
static WaveformScale & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
static WaveformSettings & Get(const WaveTrack &track)
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
static sampleCount min()
Definition: SampleCount.h:68
static sampleCount max()
Definition: SampleCount.h:69
AUDACITY_DLL_API void DrawClipFolded(wxDC &dc, const wxRect &rect)
Definition: TrackArt.cpp:293
AUDACITY_DLL_API void DrawClipEdges(wxDC &dc, const wxRect &clipRect, bool selected=false)
Definition: TrackArt.cpp:256
AUDACITY_DLL_API void DrawNegativeOffsetTrackArrows(TrackPanelDrawingContext &context, const wxRect &rect)
Definition: TrackArt.cpp:123
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 DrawEnvelope(TrackPanelDrawingContext &context, const wxRect &rect, const double env[], float zoomMin, float zoomMax, bool dB, float dBRange, bool highlight)
void FindWavePortions(std::vector< WavePortion > &portions, const wxRect &rect, const ZoomInfo &zoomInfo, const ClipParameters &params)
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)
static wxRect GetClipRect(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)
static WaveClipWaveformCache & Get(const WaveClip &clip)

References WaveDisplay::Allocate(), anonymous_namespace{WaveformView.cpp}::WavePortion::averageZoom, WaveDisplay::bl, WaveTrackView::ClipDetailsVisible(), FrameStatistics::CreateStopwatch(), TrackPanelDrawingContext::dc, TrackArt::DrawClipEdges(), TrackArt::DrawClipFolded(), DrawEnvelope(), DrawIndividualSamples(), DrawMinMaxRMS(), TrackArt::DrawNegativeOffsetTrackArrows(), EnvelopeEditor::DrawPoints(), DrawWaveformBackground(), FindWavePortions(), WaveClipWaveformCache::Get(), WaveformSettings::Get(), WaveformScale::Get(), TrackArtist::Get(), ClipParameters::GetClipRect(), WaveClip::GetColourIndex(), WaveClip::GetEnvelope(), EnvelopeHandle::GetEnvelope(), CommonTrackView::GetEnvelopeValues(), WaveClip::GetPlaySamplesCount(), Track::GetSelected(), SampleHandle::GetTrack(), anonymous_namespace{WaveformView.cpp}::WavePortion::inFisheye, SyncLock::IsSelectedOrSyncLockSelected(), SampleTrack::LongSamplesToTime(), WaveDisplay::max, WaveDisplay::min, params, anonymous_namespace{WaveformView.cpp}::WavePortion::rect, WaveDisplay::rms, settings(), TrackPanelDrawingContext::target, SampleTrack::TimeToLongSamples(), FrameStatistics::WaveformView, WaveDisplay::where, and WaveDisplay::width.

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 638 of file WaveformView.cpp.

642{
643 auto &dc = context.dc;
644
645 int h = rect.height;
646
647 auto &pen = highlight ? AColor::uglyPen : AColor::envelopePen;
648 dc.SetPen( pen );
649
650 for (int x0 = 0; x0 < rect.width; ++x0) {
651 int cenvTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
652 h, dB, true, dBRange, true);
653
654 int cenvBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
655 h, dB, true, dBRange, true);
656
657 int envTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
658 h, dB, true, dBRange, false);
659
660 int envBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
661 h, dB, true, dBRange, false);
662
663 // Make the collision at zero actually look solid
664 if (cenvBot - cenvTop < 9) {
665 int value = (int)((zoomMax / (zoomMax - zoomMin)) * h);
666 cenvTop = value - 4;
667 cenvBot = value + 4;
668 }
669
670 DrawEnvLine( context, rect, x0, envTop, cenvTop, true );
671 DrawEnvLine( context, rect, x0, envBot, cenvBot, false );
672 }
673}
int GetWaveYPos(float value, float min, float max, int height, bool dB, bool outer, float dBr, bool clip)
Definition: TrackArt.cpp:46
static wxPen uglyPen
Definition: AColor.h:141
static wxPen envelopePen
Definition: AColor.h:115
void DrawEnvLine(TrackPanelDrawingContext &context, const wxRect &rect, int x0, int y0, int cy, bool top)

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 609 of file WaveformView.cpp.

612{
613 auto &dc = context.dc;
614
615 int xx = rect.x + x0;
616 int yy = rect.y + cy;
617
618 if (y0 < 0) {
619 if (x0 % 4 != 3) {
620 AColor::Line(dc, xx, yy, xx, yy + 3);
621 }
622 }
623 else if (y0 > rect.height) {
624 if (x0 % 4 != 3) {
625 AColor::Line(dc, xx, yy - 3, xx, yy);
626 }
627 }
628 else {
629 if (top) {
630 AColor::Line(dc, xx, yy, xx, yy + 3);
631 }
632 else {
633 AColor::Line(dc, xx, yy - 3, xx, yy);
634 }
635 }
636}
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187

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 483 of file WaveformView.cpp.

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

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 331 of file WaveformView.cpp.

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

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 933 of file WaveformView.cpp.

936{
937 auto &dc = context.dc;
938
939 const int border = 3; // 3 pixels all round.
940 const int width = 6; // width of the drag box.
941 const int taper = 6; // how much the box tapers by.
942 const int barSpacing = 4; // how far apart the bars are.
943 const int barWidth = 3;
944 const int xFlat = 3;
945
946 //Enough space to draw in?
947 if (rect.height <= ((taper+border + barSpacing) * 2)) {
948 return;
949 }
950 if (rect.width <= (width * 2 + border * 3)) {
951 return;
952 }
953
954 // The draggable box is tapered towards the direction you drag it.
955 int leftTaper = rightwards ? 0 : 6;
956 int rightTaper = rightwards ? 6 : 0;
957
958 int xLeft = rightwards ? (rect.x + border - 2)
959 : (rect.x + rect.width + 1 - (border + width));
960 int yTop = rect.y + border;
961 int yBot = rect.y + rect.height - border - 1;
962
963 AColor::Light(&dc, false, highlight);
964 AColor::Line(dc, xLeft, yBot - leftTaper, xLeft, yTop + leftTaper);
965 AColor::Line(dc, xLeft, yTop + leftTaper, xLeft + xFlat, yTop);
966 AColor::Line(dc, xLeft + xFlat, yTop, xLeft + width, yTop + rightTaper);
967
968 AColor::Dark(&dc, false, highlight);
969 AColor::Line(dc, xLeft + width, yTop + rightTaper, xLeft + width, yBot - rightTaper);
970 AColor::Line(dc, xLeft + width, yBot - rightTaper, xLeft + width-xFlat, yBot);
971 AColor::Line(dc, xLeft + width - xFlat, yBot, xLeft, yBot - leftTaper);
972
973 int firstBar = yTop + taper + taper / 2;
974 int nBars = (yBot - yTop - taper * 3) / barSpacing + 1;
975 xLeft += (width - barWidth + 1) / 2;
976 int yy;
977 int i;
978
979 AColor::Light(&dc, false, highlight);
980 for (i = 0;i < nBars; i++) {
981 yy = firstBar + barSpacing * i;
982 AColor::Line(dc, xLeft, yy, xLeft + barWidth, yy);
983 }
984 AColor::Dark(&dc, false, highlight);
985 for(i = 0;i < nBars; i++){
986 yy = firstBar + barSpacing * i + 1;
987 AColor::Line(dc, xLeft, yy, xLeft + barWidth, yy);
988 }
989}
static void Light(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:413
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:443

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 150 of file WaveformView.cpp.

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

References PackedArray::begin(), TrackPanelDrawingContext::dc, TrackArt::DrawSyncLockTiles(), PackedArray::end(), 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 301 of file WaveformView.cpp.

304{
305 // If there is no fisheye, then only one rectangle has nonzero width.
306 // If there is a fisheye, make rectangles for before and after
307 // (except when they are squeezed to zero width), and at least one for inside
308 // the fisheye.
309
310 ZoomInfo::Intervals intervals;
311 zoomInfo.FindIntervals(params.rate, intervals, rect.width, rect.x);
312 ZoomInfo::Intervals::const_iterator it = intervals.begin(), end = intervals.end(), prev;
313 wxASSERT(it != end && it->position == rect.x);
314 const int rightmost = rect.x + rect.width;
315 for (int left = rect.x; left < rightmost;) {
316 while (it != end && it->position <= left)
317 prev = it++;
318 if (it == end)
319 break;
320 const int right = std::max(left, (int)(it->position));
321 const int width = right - left;
322 if (width > 0)
323 portions.push_back(
324 WavePortion(left, rect.y, width, rect.height,
325 prev->averageZoom, prev->inFisheye)
326 );
327 left = right;
328 }
329}
void FindIntervals(double rate, Intervals &results, int64 width, int64 origin=0) const
Definition: ZoomInfo.cpp:104
std::vector< Interval > Intervals
Definition: ZoomInfo.h:136

References PackedArray::end(), 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 1125 of file WaveformView.cpp.

1126{
1127 return XXO("Instrument %i").Format( colorIndex+1 );
1128}
XXO("&Cut/Copy/Paste Toolbar")

References XXO().

Referenced by WaveColorMenuTable::OnWaveColorChange().

Here is the call graph for this function:
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;
} ) )
}
WaveTrackPopupMenuTable & GetWaveTrackMenuTable()
static WaveTrackView & Get(WaveTrack &track)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
std::unique_ptr< BaseItem > BaseItemPtr
Definition: Registry.h:73
std::unique_ptr< IndirectItem > Indirect(const BaseItemSharedPtr &ptr)
A convenience function.
Definition: Registry.h:97
static WaveColorMenuTable & Instance()
WaveTrack & FindWaveTrack() const
PlayableTrackControls::InitMenuData * mpData

Definition at line 1192 of file WaveformView.cpp.