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

Classes

struct  WaveBitmapCacheElementWX
 
class  WaveformPainter
 
struct  WavePortion
 

Typedefs

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

Functions

graphics::Color ColorFromWXPen (const wxPen &pen)
 
graphics::Color ColorFromWXBrush (const wxBrush &brush)
 
void DrawWaveform (TrackPanelDrawingContext &context, const WaveTrack &track, const WaveChannelInterval &channelInterval, int leftOffset, double t0, double t1, const wxRect &rect, float zoomMin, float zoomMax, bool dB, float dBRange, bool muted)
 
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 DrawIndividualSamples (TrackPanelDrawingContext &context, int leftOffset, const wxRect &rect, float zoomMin, float zoomMax, bool dB, float dBRange, const WaveChannelInterval &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 WaveChannel &channel, const WaveChannelInterval &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 1100 of file WaveformView.cpp.

Function Documentation

◆ ColorFromWXBrush()

graphics::Color anonymous_namespace{WaveformView.cpp}::ColorFromWXBrush ( const wxBrush &  brush)

Definition at line 173 of file WaveformView.cpp.

174{
175 const auto c = brush.GetColour();
176 return graphics::Color(c.Red(), c.Green(), c.Blue());
177}
Class for storing color in 32-bit format.
Definition: Color.h:29

Referenced by DrawWaveform().

Here is the caller graph for this function:

◆ ColorFromWXPen()

graphics::Color anonymous_namespace{WaveformView.cpp}::ColorFromWXPen ( const wxPen &  pen)

Definition at line 167 of file WaveformView.cpp.

168{
169 const auto c = pen.GetColour();
170 return graphics::Color(c.Red(), c.Green(), c.Blue());
171}

Referenced by DrawWaveform().

Here is the caller graph for this function:

◆ DrawClipWaveform()

void anonymous_namespace{WaveformView.cpp}::DrawClipWaveform ( TrackPanelDrawingContext context,
const WaveChannel channel,
const WaveChannelInterval clip,
const wxRect &  rect,
bool  dB,
bool  muted,
bool  selected 
)

Definition at line 765 of file WaveformView.cpp.

768{
769 const Envelope &envelope = clip.GetEnvelope();
770 auto &dc = context.dc;
771 const auto artist = TrackArtist::Get(context);
772 const auto &selectedRegion = *artist->pSelectedRegion;
773 const auto &zoomInfo = *artist->pZoomInfo;
774
776
777 bool highlightEnvelope = false;
778#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
779 auto target = dynamic_cast<EnvelopeHandle*>(context.target.get());
780 highlightEnvelope = target && target->GetEnvelope() == &envelope;
781#endif
782
783 //If clip is "too small" draw a placeholder instead of
784 //attempting to fit the contents into a few pixels
785 if (!WaveChannelView::ClipDetailsVisible(clip, zoomInfo, rect))
786 {
787 auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect);
788 TrackArt::DrawClipFolded(dc, clipRect);
789 return;
790 }
791
792 const ClipParameters params { clip, rect, zoomInfo };
793 const wxRect &hiddenMid = params.hiddenMid;
794 // The "hiddenMid" rect contains the part of the display actually
795 // containing the waveform, as it appears without the fisheye. If it's empty, we're done.
796 if (hiddenMid.width <= 0) {
797 return;
798 }
799
800 const double &t0 = params.t0;
801 const double &t1 = params.t1;
802 const double playStartTime = clip.GetPlayStartTime();
803 const double &trackRectT0 = params.trackRectT0;
804 const double &averagePixelsPerSecond = params.averagePixelsPerSecond;
805 const double sampleRate = clip.GetRate();
806 const double stretchRatio = clip.GetStretchRatio();
807 double leftOffset = params.leftOffset;
808 const wxRect &mid = params.mid;
809
810 auto &settings = WaveformSettings::Get(channel);
811 const float dBRange = settings.dBRange;
812
813 dc.SetPen(*wxTRANSPARENT_PEN);
814 int iColorIndex = WaveColorAttachment::Get(clip).GetColorIndex();
815 artist->SetColours( iColorIndex );
816
817 // The bounds (controlled by vertical zooming; -1.0...1.0
818 // by default)
819 float zoomMin, zoomMax;
820 auto &cache = WaveformScale::Get(channel);
821 cache.GetDisplayBounds(zoomMin, zoomMax);
822
823 std::vector<double> vEnv(mid.width);
824 double *const env = &vEnv[0];
825 CommonChannelView::GetEnvelopeValues(envelope, playStartTime,
826
827 // PRL: change back to make envelope evaluate only at sample times
828 // and then interpolate the display
829 0, // 1.0 / sampleRate,
830
831 env, mid.width, leftOffset, zoomInfo);
832
833 // Draw the background of the track, outlining the shape of
834 // the envelope and using a colored pen for the selected
835 // part of the waveform
836 {
837 double tt0, tt1;
838 const auto &track = channel.GetTrack();
840 tt0 = track.SnapToSample(selectedRegion.t0());
841 tt1 = track.SnapToSample(selectedRegion.t1());
842 }
843 else
844 tt0 = tt1 = 0.0;
845 DrawWaveformBackground(context, leftOffset, mid,
846 env,
847 zoomMin, zoomMax,
848 cache.ZeroLevelYCoordinate(mid),
849 dB, dBRange,
850 tt0, tt1,
851 !track.GetSelected(), highlightEnvelope);
852 }
853
854 // Require at least 1/2 pixel per sample for drawing individual samples.
855 const double threshold1 = 0.5 * sampleRate / stretchRatio;
856 // Require at least 3 pixels per sample for drawing the draggable points.
857 const double threshold2 = 3 * sampleRate / stretchRatio;
858
859 bool highlight = false;
860#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
861 auto target = dynamic_cast<SampleHandle*>(context.target.get());
862 highlight = target && target->FindChannel().get() == &track;
863#endif
864
865 const bool showIndividualSamples = zoomInfo.GetZoom() > threshold1;
866 const bool showPoints = zoomInfo.GetZoom() > threshold2;
867
868 if(!showIndividualSamples)
869 {
871 context, channel.GetTrack(), clip, leftOffset, t0, t1,
872 rect, zoomMin, zoomMax, dB, dBRange, muted);
873 }
874 else
875 {
876 std::vector<WavePortion> portions;
877 FindWavePortions(portions, rect, zoomInfo, params);
878 auto offset = leftOffset;
879 for(const auto& portion : portions)
880 {
881 assert(!portion.inFisheye && portion.averageZoom > threshold1);
882 if(portion.inFisheye || portion.averageZoom <= threshold1)
883 continue;
884
885 wxRect rectPortion = portion.rect;
886 rectPortion.Intersect(mid);
888 context, offset, rectPortion, zoomMin, zoomMax, dB, dBRange, clip,
889 showPoints, muted, highlight);
890 offset += rectPortion.width;
891 }
892
893 }
894
895 const auto drawEnvelope = artist->drawEnvelope;
896 if (drawEnvelope) {
898 context, mid, env, zoomMin, zoomMax, dB, dBRange, highlightEnvelope);
900 context, mid, dB, dBRange, zoomMin, zoomMax, true, rect.x - mid.x);
901 }
902
903 // Draw arrows on the left side if the track extends to the left of the
904 // beginning of time. :)
905 if (trackRectT0 == 0.0 && playStartTime < 0.0)
906 {
908 }
909 {
910 auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect);
911 TrackArt::DrawClipEdges(dc, clipRect, selected);
912 }
913}
EffectDistortionSettings params
static Settings & settings()
Definition: TrackInfo.cpp:51
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
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
@ WaveformView
Time required to draw a single clip.
static Stopwatch CreateStopwatch(SectionID section) noexcept
Create a Stopwatch for the section specified.
static bool IsSelectedOrSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:104
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:81
WaveTrack & GetTrack()
Definition: WaveTrack.h:841
static bool ClipDetailsVisible(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
Envelope & GetEnvelope()
Definition: WaveClip.cpp:64
int GetRate() const override
Definition: WaveClip.cpp:193
double GetPlayStartTime() const override
Definition: WaveClip.cpp:198
double GetStretchRatio() const override
Definition: WaveClip.cpp:218
static WaveformScale & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
static WaveformSettings & Get(const WaveTrack &track)
double SnapToSample(double t) const
AUDACITY_DLL_API void DrawClipFolded(wxDC &dc, const wxRect &rect)
Definition: TrackArt.cpp:346
AUDACITY_DLL_API void DrawClipEdges(wxDC &dc, const wxRect &clipRect, bool selected=false)
Definition: TrackArt.cpp:309
AUDACITY_DLL_API void DrawNegativeOffsetTrackArrows(TrackPanelDrawingContext &context, const wxRect &rect)
Definition: TrackArt.cpp:143
void DrawIndividualSamples(TrackPanelDrawingContext &context, int leftOffset, const wxRect &rect, float zoomMin, float zoomMax, bool dB, float dBRange, const WaveChannelInterval &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 DrawWaveform(TrackPanelDrawingContext &context, const WaveTrack &track, const WaveChannelInterval &channelInterval, int leftOffset, double t0, double t1, const wxRect &rect, float zoomMin, float zoomMax, bool dB, float dBRange, bool muted)
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 ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)
static WaveColorAttachment & Get(WaveClip &clip)

References WaveChannelView::ClipDetailsVisible(), FrameStatistics::CreateStopwatch(), TrackPanelDrawingContext::dc, TrackArt::DrawClipEdges(), TrackArt::DrawClipFolded(), DrawEnvelope(), DrawIndividualSamples(), TrackArt::DrawNegativeOffsetTrackArrows(), EnvelopeEditor::DrawPoints(), DrawWaveform(), DrawWaveformBackground(), FindWavePortions(), WaveformSettings::Get(), WaveformScale::Get(), TrackArtist::Get(), WaveColorAttachment::Get(), ClipParameters::GetClipRect(), WaveColorAttachment::GetColorIndex(), WaveClipChannel::GetEnvelope(), EnvelopeHandle::GetEnvelope(), CommonChannelView::GetEnvelopeValues(), WaveClipChannel::GetPlayStartTime(), WaveClipChannel::GetRate(), WaveClipChannel::GetStretchRatio(), WaveChannel::GetTrack(), SyncLock::IsSelectedOrSyncLockSelected(), params, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, settings(), WideSampleSequence::SnapToSample(), TrackPanelDrawingContext::target, and FrameStatistics::WaveformView.

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

729{
730 auto &dc = context.dc;
731
732 int h = rect.height;
733
734 auto &pen = highlight ? AColor::uglyPen : AColor::envelopePen;
735 dc.SetPen( pen );
736
737 for (int x0 = 0; x0 < rect.width; ++x0) {
738 int cenvTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
739 h, dB, true, dBRange, true);
740
741 int cenvBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
742 h, dB, true, dBRange, true);
743
744 int envTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
745 h, dB, true, dBRange, false);
746
747 int envBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
748 h, dB, true, dBRange, false);
749
750 // Make the collision at zero actually look solid
751 if (cenvBot - cenvTop < 9) {
752 int value = (int)((zoomMax / (zoomMax - zoomMin)) * h);
753 cenvTop = value - 4;
754 cenvBot = value + 4;
755 }
756
757 DrawEnvLine( context, rect, x0, envTop, cenvTop, true );
758 DrawEnvLine( context, rect, x0, envBot, cenvBot, false );
759 }
760}
int GetWaveYPos(float value, float min, float max, int height, bool dB, bool outer, float dBr, bool clip)
Definition: TrackArt.cpp:66
static wxPen uglyPen
Definition: AColor.h:140
static wxPen envelopePen
Definition: AColor.h:116
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 696 of file WaveformView.cpp.

699{
700 auto &dc = context.dc;
701
702 int xx = rect.x + x0;
703 int yy = rect.y + cy;
704
705 if (y0 < 0) {
706 if (x0 % 4 != 3) {
707 AColor::Line(dc, xx, yy, xx, yy + 3);
708 }
709 }
710 else if (y0 > rect.height) {
711 if (x0 % 4 != 3) {
712 AColor::Line(dc, xx, yy - 3, xx, yy);
713 }
714 }
715 else {
716 if (top) {
717 AColor::Line(dc, xx, yy, xx, yy + 3);
718 }
719 else {
720 AColor::Line(dc, xx, yy - 3, xx, yy);
721 }
722 }
723}
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:194

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 WaveChannelInterval clip,
bool  showPoints,
bool  muted,
bool  highlight 
)

Definition at line 568 of file WaveformView.cpp.

575{
576 const Envelope &envelope = clip.GetEnvelope();
577 auto &dc = context.dc;
578 const auto artist = TrackArtist::Get(context);
579 const auto &zoomInfo = *artist->pZoomInfo;
580
581 const double toffset = clip.GetPlayStartTime();
582 const double rate = clip.GetRate() / clip.GetStretchRatio();
583 const double t0 = std::max(0.0, zoomInfo.PositionToTime(0, -leftOffset) - toffset);
584 const auto s0 = sampleCount(floor(t0 * rate));
585 const auto snSamples = clip.GetVisibleSampleCount();
586 if (s0 > snSamples)
587 return;
588
589 const double t1 = zoomInfo.PositionToTime(rect.width - 1, -leftOffset) - toffset;
590 const auto s1 = sampleCount(ceil(t1 * rate));
591
592 // Assume size_t will not overflow, else we wouldn't be here drawing the
593 // few individual samples
594 auto slen = std::min(snSamples - s0, s1 - s0 + 1).as_size_t();
595
596 if (slen <= 0)
597 return;
598
599 Floats buffer{ size_t(slen) };
600 clip.GetSamples((samplePtr)buffer.get(), floatSample, s0, slen,
601 // Suppress exceptions in this drawing operation:
602 false);
603
604 ArrayOf<int> xpos{ size_t(slen) };
605 ArrayOf<int> ypos{ size_t(slen) };
606 ArrayOf<int> clipped;
607 int clipcnt = 0;
608
609 const auto bShowClipping = ShowClippingPref().Read();
610 if (bShowClipping)
611 clipped.reinit( size_t(slen) );
612
613 const auto &muteSamplePen = artist->muteSamplePen;
614 const auto &samplePen = artist->samplePen;
615 auto &pen = highlight ? AColor::uglyPen : muted ? muteSamplePen : samplePen;
616 dc.SetPen( pen );
617
618 for (decltype(slen) s = 0; s < slen; s++) {
619 const double time = toffset + (s + s0).as_double() / rate;
620 const int xx = // An offset into the rectangle rect
621 std::max(-10000, std::min(10000,
622 (int)(zoomInfo.TimeToPosition(time, -leftOffset))));
623 xpos[s] = xx;
624
625 // Calculate sample as it would be rendered, so quantize time
626 double value = envelope.GetValue(time, 1.0 / clip.GetRate());
627 const double tt = buffer[s] * value;
628
629 if (clipped && bShowClipping && ((tt <= -MAX_AUDIO) || (tt >= MAX_AUDIO)))
630 clipped[clipcnt++] = xx;
631 ypos[s] =
632 std::max(-1,
633 std::min(rect.height,
634 GetWaveYPos(tt, zoomMin, zoomMax,
635 rect.height, dB, true, dBRange, false)));
636 }
637
638
639 if (showPoints) {
640 // Draw points where spacing is enough
641 const auto bigPoints = artist->bigPoints;
642 const int tickSize = bigPoints ? 4 : 3;// Bigger ellipses when draggable.
643 wxRect pr;
644 pr.width = tickSize;
645 pr.height = tickSize;
646 //different colour when draggable.
647 const auto &dragsampleBrush = artist->dragsampleBrush;
648 const auto &sampleBrush = artist->sampleBrush;
649 auto &brush = highlight
651 : bigPoints ? dragsampleBrush : sampleBrush;
652 dc.SetBrush( brush );
653 for (decltype(slen) s = 0; s < slen; s++) {
654 if (ypos[s] >= 0 && ypos[s] < rect.height) {
655 pr.x = rect.x + xpos[s] - tickSize/2;
656 pr.y = rect.y + ypos[s] - tickSize/2;
657 dc.DrawEllipse(pr);
658 }
659 }
660 }
661
662 const auto sampleDisplay = artist->mSampleDisplay;
663 if (showPoints &&
664 (sampleDisplay == (int) WaveChannelViewConstants::StemPlot)
665 ){
666 // Draw vertical lines
667 int yZero = GetWaveYPos(0.0, zoomMin, zoomMax, rect.height, dB, true, dBRange, false);
668 yZero = rect.y + std::max(-1, std::min(rect.height, yZero));
669 for (decltype(slen) s = 0; s < slen; s++) {
670 AColor::Line(dc,
671 rect.x + xpos[s], rect.y + ypos[s],
672 rect.x + xpos[s], yZero);
673 }
674 }
675 else {
676 // Connect samples with straight lines
677 for (decltype(slen) s = 0; s < slen - 1; s++) {
678 AColor::Line(dc,
679 rect.x + xpos[s], rect.y + ypos[s],
680 rect.x + xpos[s + 1], rect.y + ypos[s + 1]);
681 }
682 }
683
684 // Draw clipping
685 if (clipcnt) {
686 const auto &muteClippedPen = artist->muteClippedPen;
687 const auto &clippedPen = artist->clippedPen;
688 dc.SetPen(muted ? muteClippedPen : clippedPen);
689 while (--clipcnt >= 0) {
690 auto s = clipped[clipcnt];
691 AColor::Line(dc, rect.x + s, rect.y, rect.x + s, rect.y + rect.height);
692 }
693 }
694}
int min(int a, int b)
BoolSetting & ShowClippingPref()
Definition: GUIPrefs.cpp:196
#define MAX_AUDIO
Definition: MemoryX.h:341
constexpr sampleFormat floatSample
Definition: SampleFormat.h:45
char * samplePtr
Definition: SampleFormat.h:57
static wxBrush uglyBrush
Definition: AColor.h:141
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:59
double GetValue(double t, double sampleDur=0) const
Get envelope value at time t.
Definition: Envelope.cpp:880
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
sampleCount GetVisibleSampleCount() const override
Definition: WaveClip.cpp:188
bool GetSamples(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
Definition: WaveClip.cpp:115
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19

References TrackPanelDrawingContext::dc, floatSample, TrackArtist::Get(), WaveClipChannel::GetEnvelope(), WaveClipChannel::GetPlayStartTime(), WaveClipChannel::GetRate(), WaveClipChannel::GetSamples(), WaveClipChannel::GetStretchRatio(), Envelope::GetValue(), WaveClipChannel::GetVisibleSampleCount(), GetWaveYPos(), AColor::Line(), MAX_AUDIO, min(), Setting< T >::Read(), ArrayOf< X >::reinit(), ShowClippingPref(), WaveChannelViewConstants::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:

◆ DrawTimeSlider()

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

Definition at line 915 of file WaveformView.cpp.

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

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:

◆ DrawWaveform()

void anonymous_namespace{WaveformView.cpp}::DrawWaveform ( TrackPanelDrawingContext context,
const WaveTrack track,
const WaveChannelInterval channelInterval,
int  leftOffset,
double  t0,
double  t1,
const wxRect &  rect,
float  zoomMin,
float  zoomMax,
bool  dB,
float  dBRange,
bool  muted 
)

Definition at line 335 of file WaveformView.cpp.

340{
341 auto& clip = channelInterval.GetClip();
342 const auto channelIndex = channelInterval.GetChannelIndex();
343
344 const auto artist = TrackArtist::Get(context);
345 const ZoomInfo zoomInfo(0.0, artist->pZoomInfo->GetZoom());
346
347 auto& clipPainter = WaveformPainter::Get(clip);
348
349 const auto trimLeft = clip.GetTrimLeft();
350 const auto sequenceStartTime = clip.GetSequenceStartTime();
351
352 WavePaintParameters paintParameters;
353
354 paintParameters
356 rect.GetHeight(), zoomMin, zoomMax, ShowClippingPref().Read())
357 .SetDBParameters(dBRange, dB)
358 .SetBlankColor(ColorFromWXBrush(artist->blankBrush))
360 .SetShowRMS(ShowRMSPref().Read())
362 ColorFromWXPen(muted ? artist->muteSamplePen : artist->samplePen),
363 ColorFromWXPen(muted ? artist->muteSamplePen : artist->samplePen))
365 ColorFromWXPen(muted ? artist->muteRmsPen : artist->rmsPen),
366 ColorFromWXPen(muted ? artist->muteRmsPen : artist->rmsPen))
368 ColorFromWXBrush(artist->unselectedBrush),
369 ColorFromWXBrush(artist->selectedBrush))
371 ColorFromWXPen(muted ? artist->muteClippedPen : artist->clippedPen),
372 ColorFromWXPen(muted ? artist->muteClippedPen : artist->clippedPen))
373 .SetEnvelope(clip.GetEnvelope());
374
375 clipPainter.SetSelection(
376 zoomInfo, artist->pSelectedRegion->t0() - sequenceStartTime,
377 artist->pSelectedRegion->t1() - sequenceStartTime,
379
380 clipPainter.Draw(
381 channelIndex, context.dc, paintParameters, zoomInfo, rect, leftOffset,
382 t0 + trimLeft, t1 + trimLeft);
383}
BoolSetting & ShowRMSPref()
Definition: GUIPrefs.cpp:190
WaveClip & GetClip()
Definition: WaveClip.h:96
size_t GetChannelIndex() const
Definition: WaveClip.h:99
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
graphics::Color ColorFromWXPen(const wxPen &pen)
graphics::Color ColorFromWXBrush(const wxBrush &brush)
constexpr Color Black
Opaque black color constant.
Definition: Color.h:283
Parameters for the waveform painting.
WavePaintParameters & SetBlankColor(graphics::Color color) noexcept
Sets the blank color.
WavePaintParameters & SetShowRMS(bool showRMS) noexcept
Sets the ShowRMS flag.
WavePaintParameters & SetBackgroundColors(graphics::Color normal, graphics::Color selected) noexcept
Sets the background colors.
WavePaintParameters & SetZeroLineColor(graphics::Color color) noexcept
Sets the horizontal zero line color.
WavePaintParameters & SetDBParameters(double dbRange, bool dbScale) noexcept
Sets the dB scale parameters.
WavePaintParameters & SetClippingColors(graphics::Color normal, graphics::Color selected) noexcept
Sets the clipping colors.
WavePaintParameters & SetSampleColors(graphics::Color normal, graphics::Color selected) noexcept
Sets the sample colors.
WavePaintParameters & SetDisplayParameters(int height, double zoomMin, double zoomMax, bool showClipping) noexcept
Sets the basic painting parameters.
WavePaintParameters & SetEnvelope(const Envelope &envelope) noexcept
Sets volume envelope.
WavePaintParameters & SetRMSColors(graphics::Color normal, graphics::Color selected) noexcept
Sets the RMS colors.

References graphics::Colors::Black, ColorFromWXBrush(), ColorFromWXPen(), TrackPanelDrawingContext::dc, BasicUI::Get(), TrackArtist::Get(), WaveClipChannel::GetChannelIndex(), WaveClipChannel::GetClip(), SyncLock::IsSelectedOrSyncLockSelected(), WavePaintParameters::SetBackgroundColors(), WavePaintParameters::SetBlankColor(), WavePaintParameters::SetClippingColors(), WavePaintParameters::SetDBParameters(), WavePaintParameters::SetDisplayParameters(), WavePaintParameters::SetEnvelope(), WavePaintParameters::SetRMSColors(), WavePaintParameters::SetSampleColors(), WavePaintParameters::SetShowRMS(), WavePaintParameters::SetZeroLineColor(), ShowClippingPref(), and ShowRMSPref().

Referenced by DrawClipWaveform().

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

396{
397 auto &dc = context.dc;
398 const auto artist = TrackArtist::Get( context );
399 const auto &zoomInfo = *artist->pZoomInfo;
400
401 // Visually (one vertical slice of the waveform background, on its side;
402 // the "*" is the actual waveform background we're drawing
403 //
404 //1.0 0.0 -1.0
405 // |--------------------------------|--------------------------------|
406 // *************** ***************
407 // | | | |
408 // maxtop maxbot mintop minbot
409
410 int h = rect.height;
411 int halfHeight = wxMax(h / 2, 1);
412 int maxtop, lmaxtop = 0;
413 int mintop, lmintop = 0;
414 int maxbot, lmaxbot = 0;
415 int minbot, lminbot = 0;
416 bool sel, lsel = false;
417 int xx, lx = 0;
418 int l, w;
419
420 const auto &blankBrush = artist->blankBrush;
421 const auto &selectedBrush = artist->selectedBrush;
422 const auto &unselectedBrush = artist->unselectedBrush;
423 const auto &envelopeBackgroundBrush = artist->envelopeBackgroundBrush;
424
425 dc.SetPen(*wxTRANSPARENT_PEN);
426 dc.SetBrush(envelopeBackgroundBrush);
427 dc.DrawRectangle(rect);
428
429 // Bug 2389 - always draw at least one pixel of selection.
430 int selectedX = zoomInfo.TimeToPosition(t0, -leftOffset);
431
432 double time = zoomInfo.PositionToTime(0, -leftOffset), nextTime;
433 for (xx = 0; xx < rect.width; ++xx, time = nextTime) {
434 nextTime = zoomInfo.PositionToTime(xx + 1, -leftOffset);
435 // First we compute the truncated shape of the waveform background.
436 // If drawEnvelope is true, then we compute the lower border of the
437 // envelope.
438
439 maxtop = GetWaveYPos(env[xx], zoomMin, zoomMax,
440 h, dB, true, dBRange, true);
441 maxbot = GetWaveYPos(env[xx], zoomMin, zoomMax,
442 h, dB, false, dBRange, true);
443
444 mintop = GetWaveYPos(-env[xx], zoomMin, zoomMax,
445 h, dB, false, dBRange, true);
446 minbot = GetWaveYPos(-env[xx], zoomMin, zoomMax,
447 h, dB, true, dBRange, true);
448
449 // Make sure it's odd so that a that max and min mirror each other
450 mintop +=1;
451 minbot +=1;
452
453 const auto drawEnvelope = artist->drawEnvelope;
454 if (!drawEnvelope || maxbot > mintop) {
455 maxbot = halfHeight;
456 mintop = halfHeight;
457 }
458
459 sel = (t0 <= time && nextTime < t1);
460 sel = sel || (xx == selectedX);
461 // We don't draw selection color for sync-lock selected tracks.
462 sel = sel && !bIsSyncLockSelected;
463
464 if (lmaxtop == maxtop &&
465 lmintop == mintop &&
466 lmaxbot == maxbot &&
467 lminbot == minbot &&
468 lsel == sel) {
469 continue;
470 }
471
472 dc.SetBrush(lsel ? selectedBrush : unselectedBrush);
473
474 l = rect.x + lx;
475 w = xx - lx;
476 if (lmaxbot < lmintop - 1) {
477 dc.DrawRectangle(l, rect.y + lmaxtop, w, lmaxbot - lmaxtop);
478 dc.DrawRectangle(l, rect.y + lmintop, w, lminbot - lmintop);
479 }
480 else {
481 dc.DrawRectangle(l, rect.y + lmaxtop, w, lminbot - lmaxtop);
482 }
483
484 if (highlightEnvelope && lmaxbot < lmintop - 1) {
485 dc.SetBrush( AColor::uglyBrush );
486 dc.DrawRectangle(l, rect.y + lmaxbot, w, lmintop - lmaxbot);
487 }
488
489 lmaxtop = maxtop;
490 lmintop = mintop;
491 lmaxbot = maxbot;
492 lminbot = minbot;
493 lsel = sel;
494 lx = xx;
495 }
496
497 dc.SetBrush(lsel ? selectedBrush : unselectedBrush);
498 l = rect.x + lx;
499 w = xx - lx;
500 if (lmaxbot < lmintop - 1) {
501 dc.DrawRectangle(l, rect.y + lmaxtop, w, lmaxbot - lmaxtop);
502 dc.DrawRectangle(l, rect.y + lmintop, w, lminbot - lmintop);
503 }
504 else {
505 dc.DrawRectangle(l, rect.y + lmaxtop, w, lminbot - lmaxtop);
506 }
507 if (highlightEnvelope && lmaxbot < lmintop - 1) {
508 dc.SetBrush( AColor::uglyBrush );
509 dc.DrawRectangle(l, rect.y + lmaxbot, w, lmintop - lmaxbot);
510 }
511
512 // If sync-lock selected, draw in linked graphics.
513 if (bIsSyncLockSelected && t0 < t1) {
514 const int begin = std::max(0, std::min(rect.width, (int)(zoomInfo.TimeToPosition(t0, -leftOffset))));
515 const int end = std::max(0, std::min(rect.width, (int)(zoomInfo.TimeToPosition(t1, -leftOffset))));
517 { rect.x + begin, rect.y, end - 1 - begin, rect.height } );
518 }
519
520 //OK, the display bounds are between min and max, which
521 //is spread across rect.height. Draw the line at the proper place.
522 if (zeroLevelYCoordinate >= rect.GetTop() &&
523 zeroLevelYCoordinate <= rect.GetBottom()) {
524 dc.SetPen(*wxBLACK_PEN);
525 AColor::Line(dc, rect.x, zeroLevelYCoordinate,
526 rect.x + rect.width - 1, zeroLevelYCoordinate);
527 }
528}
AUDACITY_DLL_API void DrawSyncLockTiles(TrackPanelDrawingContext &context, const wxRect &rect)
Definition: TrackArt.cpp:365
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

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

542{
543 // If there is no fisheye, then only one rectangle has nonzero width.
544 // If there is a fisheye, make rectangles for before and after
545 // (except when they are squeezed to zero width), and at least one for inside
546 // the fisheye.
547
548 const auto intervals = zoomInfo.FindIntervals(rect.width, rect.x);
549 ZoomInfo::Intervals::const_iterator it = intervals.begin(), end = intervals.end(), prev;
550 wxASSERT(it != end && it->position == rect.x);
551 const int rightmost = rect.x + rect.width;
552 for (int left = rect.x; left < rightmost;) {
553 while (it != end && it->position <= left)
554 prev = it++;
555 if (it == end)
556 break;
557 const int right = std::max(left, (int)(it->position));
558 const int width = right - left;
559 if (width > 0)
560 portions.push_back(
561 WavePortion(left, rect.y, width, rect.height,
562 prev->averageZoom, prev->inFisheye)
563 );
564 left = right;
565 }
566}
Intervals FindIntervals(int64 width, int64 origin=0) const
Definition: ZoomInfo.cpp:99

References details::end(), and ZoomInfo::FindIntervals().

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

1103{
1104 return XXO("Instrument %i").Format( colorIndex+1 );
1105}
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::Adapt<WaveTrackPopupMenuTable>(
const auto pTrack = &table.FindWaveTrack();
const auto &view = WaveChannelView::GetFirst(*pTrack);
const auto displays = view.GetDisplays();
bool hasWaveform = (displays.end() != std::find(
displays.begin(), displays.end(),
WaveChannelViewConstants::Waveform, {} }
) );
return hasWaveform
.Get(table.mpData))
: nullptr;
} ) )
}
WaveTrackPopupMenuTable & GetWaveTrackMenuTable()
static WaveChannelView & GetFirst(WaveTrack &wt)
Get the view of the first channel.
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175
static WaveColorMenuTable & Instance()
WaveTrack & FindWaveTrack() const
PlayableTrackControls::InitMenuData * mpData

Definition at line 1169 of file WaveformView.cpp.