1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-30 07:08:39 +02:00

Various cleanups before fisheye project

This commit is contained in:
Paul Licameli 2015-06-11 13:47:26 -04:00
commit 9ff703bc0d
6 changed files with 442 additions and 425 deletions

View File

@ -65,6 +65,8 @@ Envelope::Envelope()
mMaxValue = 2.0;
mButton = wxMOUSE_BTN_NONE;
mSearchGuess = -1;
}
Envelope::~Envelope()
@ -1023,6 +1025,7 @@ void Envelope::SetTrackLen(double trackLen)
// Accessors
double Envelope::GetValue(double t) const
{
// t is absolute time
double temp;
GetValues(&temp, 1, t, 1.0);
@ -1037,14 +1040,38 @@ double Envelope::GetValueAtX(int x, const wxRect & r, double h, double pps)
return GetValue(t);
}
/// @param Lo returns index before this time.
/// @param Hi returns index after this time.
/// @param Lo returns last index at or before this time.
/// @param Hi returns first index after this time.
void Envelope::BinarySearchForTime( int &Lo, int &Hi, double t ) const
{
Lo = 0;
Hi = mEnv.Count() - 1;
// JC: Do we have a problem if the envelope only has one point??
wxASSERT( Hi > Lo );
wxASSERT(Hi > Lo);
// Optimizations for the usual pattern of repeated calls with
// small increases of t.
{
if (mSearchGuess >= 0 && mSearchGuess < int(mEnv.Count()) - 1) {
if (t >= mEnv[mSearchGuess]->GetT() &&
t < mEnv[1 + mSearchGuess]->GetT()) {
Lo = mSearchGuess;
Hi = 1 + mSearchGuess;
return;
}
}
++mSearchGuess;
if (mSearchGuess >= 0 && mSearchGuess < int(mEnv.Count()) - 1) {
if (t >= mEnv[mSearchGuess]->GetT() &&
t < mEnv[1 + mSearchGuess]->GetT()) {
Lo = mSearchGuess;
Hi = 1 + mSearchGuess;
return;
}
}
}
while (Hi > (Lo + 1)) {
int mid = (Lo + Hi) / 2;
if (t < mEnv[mid]->GetT())
@ -1053,6 +1080,8 @@ void Envelope::BinarySearchForTime( int &Lo, int &Hi, double t ) const
Lo = mid;
}
wxASSERT( Hi == ( Lo+1 ));
mSearchGuess = Lo;
}
/// GetInterpolationStartValueAtPoint() is used to select either the
@ -1072,6 +1101,7 @@ double Envelope::GetInterpolationStartValueAtPoint( int iPoint ) const
void Envelope::GetValues(double *buffer, int bufferLen,
double t0, double tstep) const
{
// Convert t0 from absolute to clip-relative time
t0 -= mOffset;
// JC: If bufferLen ==0 we have probably just allocated a zero sized buffer.

View File

@ -248,6 +248,8 @@ private:
double lastIntegral_t1;
double lastIntegral_result;
mutable int mSearchGuess;
};
inline double EnvPoint::ClampValue(double val)

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@
#include <wx/brush.h>
#include <wx/pen.h>
#include "Experimental.h"
#include "Sequence.h"
#include "audacity/Types.h"
class wxDC;
class wxRect;
@ -52,17 +52,17 @@ class AUDACITY_DLL_API TrackArtist {
void SetColours();
void DrawTracks(TrackList *tracks, Track *start,
wxDC & dc, wxRegion & reg,
wxRect & r, wxRect & clip, ViewInfo *viewInfo,
bool drawEnvelope, bool drawSamples, bool drawSliders);
wxRect & rect, wxRect & clip, ViewInfo *viewInfo,
bool drawEnvelope, bool bigPoints, bool drawSliders);
void DrawTrack(const Track *t,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo,
bool drawEnvelope, bool drawSamples, bool drawSliders,
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo,
bool drawEnvelope, bool bigPoints, bool drawSliders,
bool hasSolo);
void DrawVRuler(Track *t, wxDC *dc, wxRect & r);
void DrawVRuler(Track *t, wxDC *dc, wxRect & rect);
void UpdateVRuler(Track *t, wxRect & r);
void UpdateVRuler(Track *t, wxRect & rect);
void SetInset(int left, int top, int right, int bottom);
@ -90,10 +90,10 @@ class AUDACITY_DLL_API TrackArtist {
}
// Helper: draws the "sync-locked" watermark tiled to a rectangle
static void DrawSyncLockTiles(wxDC *dc, wxRect r);
static void DrawSyncLockTiles(wxDC *dc, wxRect rect);
// Helper: draws background with selection rect
static void DrawBackgroundWithSelection(wxDC *dc, const wxRect &r,
static void DrawBackgroundWithSelection(wxDC *dc, const wxRect &rect,
Track *track, wxBrush &selBrush, wxBrush &unselBrush,
double sel0, double sel1, double h, double pps);
@ -104,67 +104,67 @@ class AUDACITY_DLL_API TrackArtist {
//
void DrawWaveform(WaveTrack *track,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo,
bool drawEnvelope, bool drawSamples, bool drawSliders,
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo,
bool drawEnvelope, bool bigPoints, bool drawSliders,
bool dB, bool muted);
void DrawSpectrum(WaveTrack *track,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo);
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo);
#ifdef USE_MIDI
int GetBottom(NoteTrack *t, const wxRect &r);
int GetBottom(NoteTrack *t, const wxRect &rect);
void DrawNoteBackground(NoteTrack *track, wxDC &dc,
const wxRect &r, const wxRect &sel,
const wxRect &rect, const wxRect &sel,
const ViewInfo *viewInfo,
const wxBrush &wb, const wxPen &wp,
const wxBrush &bb, const wxPen &bp,
const wxPen &mp);
void DrawNoteTrack(NoteTrack *track,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo,
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo,
bool muted);
#endif // USE_MIDI
void DrawLabelTrack(LabelTrack *track,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo);
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo);
void DrawTimeTrack(TimeTrack *track,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo);
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo);
void DrawTimeSlider(wxDC & dc, const wxRect & r,
void DrawTimeSlider(wxDC & dc, const wxRect & rect,
bool rightwards);
void DrawClipWaveform(WaveTrack *track, WaveClip *clip,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo,
bool drawEnvelope, bool drawSamples,
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo,
bool drawEnvelope, bool bigPoints,
bool dB, bool muted);
void DrawClipSpectrum(WaveTrackCache &cache, WaveClip *clip,
wxDC & dc, const wxRect & r, const ViewInfo *viewInfo);
wxDC & dc, const wxRect & rect, const ViewInfo *viewInfo);
// Waveform utility functions
void DrawWaveformBackground(wxDC & dc, const wxRect &r, const double env[],
void DrawWaveformBackground(wxDC & dc, const wxRect &rect, const double env[],
float zoomMin, float zoomMax, bool dB,
const sampleCount where[],
const ViewInfo &viewInfo, double t0, double rate,
sampleCount ssel0, sampleCount ssel1,
bool drawEnvelope, bool bIsSyncLockSelected);
void DrawMinMaxRMS(wxDC &dc, const wxRect &r, const double env[],
void DrawMinMaxRMS(wxDC &dc, const wxRect &rect, const double env[],
float zoomMin, float zoomMax, bool dB,
const WaveDisplay &display, bool /* showProgress */, bool muted
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
, const float gain
#endif
);
void DrawIndividualSamples(wxDC & dc, const wxRect & r,
void DrawIndividualSamples(wxDC & dc, const wxRect & rect,
float zoomMin, float zoomMax, bool dB,
WaveClip *clip,
double t0, double pps, double h,
bool drawSamples, bool showPoints, bool muted);
bool bigPoints, bool showPoints, bool muted);
void DrawNegativeOffsetTrackArrows(wxDC & dc, const wxRect & r);
void DrawNegativeOffsetTrackArrows(wxDC & dc, const wxRect & rect);
void DrawEnvelope(wxDC & dc, const wxRect & r, const double env[],
void DrawEnvelope(wxDC & dc, const wxRect & rect, const double env[],
float zoomMin, float zoomMax, bool dB);
void DrawEnvLine(wxDC & dc, const wxRect & r, int x, int y, int cy, bool top);
void DrawEnvLine(wxDC & dc, const wxRect & rect, int x0, int y0, int cy, bool top);
// Preference values
float mdBrange; // "/GUI/EnvdBRange"
@ -217,7 +217,7 @@ extern int GetWaveYPos(float value, float min, float max,
int height, bool dB, bool outer, float dBr,
bool clip);
extern float FromDB(float value, double dBRange);
extern float ValueOfPixel(int y, int height, bool offset,
extern float ValueOfPixel(int yy, int height, bool offset,
bool dB, double dBRange, float zoomMin, float zoomMax);
#endif // define __AUDACITY_TRACKARTIST__

View File

@ -349,7 +349,8 @@ public:
#ifdef EXPERIMENTAL_USE_REALFFTF
#include "FFT.h"
static void ComputeSpectrumUsingRealFFTf(float *buffer, HFFT hFFT, const float *window, int len, float *out)
static void ComputeSpectrumUsingRealFFTf
(float *buffer, HFFT hFFT, const float *window, int len, float *out)
{
int i;
if(len > hFFT->Points*2)
@ -568,11 +569,11 @@ fillWhere(std::vector<sampleCount> &where, int len, double bias, double correcti
double t0, double rate, double samplesPerPixel)
{
// Be careful to make the first value non-negative
correction += 0.5 + bias;
where[0] = sampleCount(std::max(0.0, floor(correction + t0 * rate)));
const double w0 = 0.5 + correction + bias + t0 * rate;
where[0] = sampleCount(std::max(0.0, floor(w0)));
for (sampleCount x = 1; x < len + 1; x++)
where[x] = sampleCount(
floor(correction + t0 * rate + double(x) * samplesPerPixel)
floor(w0 + double(x) * samplesPerPixel)
);
}

View File

@ -79,7 +79,7 @@ array of Ruler::Label.
#include "../Prefs.h"
#include "../Snap.h"
#define max(a,b) ( (a<b)?b:a )
using std::max;
#define SELECT_TOLERANCE_PIXEL 4
#define QUICK_PLAY_SNAP_PIXEL 4 // pixel tolerance for snap guides
@ -1080,53 +1080,32 @@ void Ruler::Update(TimeTrack* timetrack)// Envelope *speedEnv, long minSpeed, lo
double sg = UPP > 0.0? 1.0: -1.0;
// Major ticks
double d, warpedD;
d = mMin - UPP/2;
if(timetrack)
warpedD = timetrack->ComputeWarpedLength(0.0, d);
else
warpedD = d;
// using ints for majorint doesn't work, as
// majorint will overflow and be negative at high zoom.
double majorInt = floor(sg * warpedD / mMajor);
i = -1;
while(i <= mLength) {
i++;
if(timetrack)
warpedD += timetrack->ComputeWarpedLength(d, d + UPP);
// Major and minor ticks
for (int jj = 0; jj < 2; ++jj) {
const double denom = jj == 0 ? mMajor : mMinor;
double d, warpedD;
d = mMin - UPP / 2;
if (timetrack)
warpedD = timetrack->ComputeWarpedLength(0.0, d);
else
warpedD += UPP;
d += UPP;
warpedD = d;
// using ints doesn't work, as
// this will overflow and be negative at high zoom.
double step = floor(sg * warpedD / denom);
i = -1;
while (i <= mLength) {
i++;
if (timetrack)
warpedD += timetrack->ComputeWarpedLength(d, d + UPP);
else
warpedD += UPP;
d += UPP;
if (floor(sg * warpedD / mMajor) > majorInt) {
majorInt = floor(sg * warpedD / mMajor);
Tick(i, sg * majorInt * mMajor, true, false);
}
}
// Minor ticks
d = mMin - UPP/2;
if(timetrack)
warpedD = timetrack->ComputeWarpedLength(0.0, d);
else
warpedD = d;
// using ints for majorint doesn't work, as
// majorint will overflow and be negative at high zoom.
// MB: I assume the same applies to minorInt
double minorInt = floor(sg * warpedD / mMinor);
i = -1;
while(i <= mLength) {
i++;
if(timetrack)
warpedD += timetrack->ComputeWarpedLength(d, d + UPP);
else
warpedD += UPP;
d += UPP;
if (floor(sg * warpedD / mMinor) > minorInt) {
minorInt = floor(sg * warpedD / mMinor);
Tick(i, sg * minorInt * mMinor, false, true);
if (floor(sg * warpedD / denom) > step) {
step = floor(sg * warpedD / denom);
bool major = jj == 0;
Tick(i, sg * step * denom, major, !major);
}
}
}