diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index 9e6241cc3..f6c6571cd 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -273,6 +273,7 @@ TrackArtist::TrackArtist() mdBrange = ENV_DB_RANGE; mShowClipping = false; + mSampleDisplay = 0; UpdatePrefs(); SetColours(); @@ -1362,15 +1363,8 @@ void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect & rect.height, dB, true, dBRange, false))); } - // Draw lines - for (decltype(slen) s = 0; s < slen - 1; s++) { - AColor::Line(dc, - rect.x + xpos[s], rect.y + ypos[s], - rect.x + xpos[s + 1], rect.y + ypos[s + 1]); - } - if (showPoints) - { + if (showPoints) { // Draw points where spacing is enough const int tickSize = bigPoints ? 4 : 3;// Bigger ellipses when draggable. wxRect pr; @@ -1387,6 +1381,28 @@ void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect & } } + if (showPoints && (mSampleDisplay == (int) WaveTrack::StemPlot)) { + // Draw vertical lines + int yZero = rect.y + + std::max(-1, + std::min(rect.height, + GetWaveYPos(0.0, zoomMin, zoomMax, + rect.height, dB, true, dBRange, false))); + for (decltype(slen) s = 0; s < slen; s++) { + AColor::Line(dc, + rect.x + xpos[s], rect.y + ypos[s], + rect.x + xpos[s], yZero); + } + } + else { + // Connect samples with straight lines + for (decltype(slen) s = 0; s < slen - 1; s++) { + AColor::Line(dc, + rect.x + xpos[s], rect.y + ypos[s], + rect.x + xpos[s + 1], rect.y + ypos[s + 1]); + } + } + // Draw clipping if (clipcnt) { dc.SetPen(muted ? muteClippedPen : clippedPen); @@ -3202,6 +3218,7 @@ void TrackArtist::UpdatePrefs() { mdBrange = gPrefs->Read(ENV_DB_KEY, mdBrange); mShowClipping = gPrefs->Read(wxT("/GUI/ShowClipping"), mShowClipping); + gPrefs->Read(wxT("/GUI/SampleView"), &mSampleDisplay, 0); SetColours(); } diff --git a/src/TrackArtist.h b/src/TrackArtist.h index f5c76ae4e..4351ec1db 100644 --- a/src/TrackArtist.h +++ b/src/TrackArtist.h @@ -172,6 +172,7 @@ class AUDACITY_DLL_API TrackArtist { // Preference values float mdBrange; // "/GUI/EnvdBRange" long mShowClipping; // "/GUI/ShowClipping" + int mSampleDisplay; // "/GUI/SampleView" bool mbShowTrackNameInWaveform; // "/GUI/ShowTrackNameInWaveform" int mInsetLeft; diff --git a/src/WaveTrack.h b/src/WaveTrack.h index 12e0006b1..bbe74f972 100644 --- a/src/WaveTrack.h +++ b/src/WaveTrack.h @@ -547,6 +547,13 @@ class AUDACITY_DLL_API WaveTrack final : public PlayableTrack { NoDisplay, // Preview track has no display }; + // Only two types of sample display for now, but + // others (eg sinc interpolation) may be added later. + enum SampleDisplay { + LinarInterpolate = 0, + StemPlot + }; + // Read appropriate value from preferences static WaveTrackDisplay FindDefaultViewMode(); diff --git a/src/prefs/TracksPrefs.cpp b/src/prefs/TracksPrefs.cpp index 0957ba3e9..1ea1b76fd 100644 --- a/src/prefs/TracksPrefs.cpp +++ b/src/prefs/TracksPrefs.cpp @@ -89,6 +89,15 @@ void TracksPrefs::Populate() mViewChoices.Add(_("Spectrogram")); mViewCodes.Add(WaveTrack::Spectrum); + + // How samples are displayed when zoomed in: + + mSampleDisplayChoice.Add(_("Connect dots")); + mSampleDisplayCodes.Add((int) WaveTrack::LinarInterpolate); + + mSampleDisplayChoice.Add(_("Stem plot")); + mSampleDisplayCodes.Add((int) WaveTrack::StemPlot); + //------------------------- Main section -------------------- // Now construct the GUI itself. // Use 'eIsCreatingFromPrefs' so that the GUI is @@ -125,6 +134,13 @@ void TracksPrefs::PopulateOrExchange(ShuttleGui & S) mViewCodes); S.SetSizeHints(mViewChoices); + S.TieChoice(_("Display samples:"), + wxT("/GUI/SampleView"), + 0, + mSampleDisplayChoice, + mSampleDisplayCodes); + S.SetSizeHints(mSampleDisplayChoice); + S.TieTextBox(_("Default audio track &name:"), wxT("/GUI/TrackNames/DefaultTrackName"), _("Audio Track"), diff --git a/src/prefs/TracksPrefs.h b/src/prefs/TracksPrefs.h index 7a2b46ab3..0fc11b723 100644 --- a/src/prefs/TracksPrefs.h +++ b/src/prefs/TracksPrefs.h @@ -43,6 +43,8 @@ class TracksPrefs final : public PrefsPanel wxArrayString mSoloChoices; wxArrayInt mViewCodes; wxArrayString mViewChoices; + wxArrayInt mSampleDisplayCodes; + wxArrayString mSampleDisplayChoice; }; class TracksPrefsFactory final : public PrefsPanelFactory