22#include "../../ProjectSettings.h"
24#include "../../RefreshCode.h"
25#include "../../SelectUtilities.h"
27#include "../../SpectralDataManager.h"
28#include "../../TrackArtist.h"
30#include "../../TrackPanel.h"
31#include "../../TrackPanelDrawingContext.h"
32#include "../../TrackPanelMouseEvent.h"
37#include "../../../images/Cursors.h"
38#include "../playabletrack/wavetrack/ui/SpectrumView.h"
71 float minFreq, maxFreq;
75 return trackTopEdge + wxInt64((1.0 - p) * trackHeight);
82 wxInt64 mouseYCoordinate,
86 const double rate = wc.
GetRate();
98 float minFreq, maxFreq;
99 cache.GetBounds(wc, minFreq, maxFreq);
101 const double p = double(mouseYCoordinate - trackTopEdge) / trackHeight;
110 wxInt64 posTime = viewInfo.
PositionToTime(mousePosX, trackTopEdgeX);
125 const auto pChannel = pChannelView && pChannelView->
IsSpectral()
132 static auto crosshairCursor =
133 ::MakeCursor(wxCURSOR_IBEAM, CrosshairCursorXpm, 16, 16);
134 return &*crosshairCursor;
139 std::shared_ptr<StateSaver> pStateSaver,
140 const std::shared_ptr<ChannelView> &pChannelView,
143 const std::shared_ptr<SpectralData> &pSpectralData,
145) : mpStateSaver{ move(pStateSaver) }
146 , mpSpectralData(pSpectralData)
147 , mpView{ pChannelView }
149 const wxMouseState &state = st.
state;
150 auto wc = pChannelView->FindChannel<
WaveChannel>();
176 template <
class A,
class B,
class DIST >
bool within(
A a, B b, DIST d)
178 return (a > b - d) && (a < b + d);
183 const double minFrequency = 1.0;
184 const double maxFrequency = (rate / 2.0);
185 const double frequency =
187 std::max(minFrequency, center));
189 std::min(frequency / minFrequency, maxFrequency / frequency);
229 const auto pView =
mpView.lock();
233 wxMouseEvent &
event = evt.
event;
245 const auto pView =
mpView.lock();
249 wxMouseEvent &
event = evt.
event;
254 auto posXToHopNum = [&](
int x0){
255 double posTime = viewInfo.PositionToTime(x0,
mRect.x);
261 auto posYToFreqBin = [&](
int y0){
264 return static_cast<int>(
std::round(resFreqBin));
267 auto drawCircle = [&](
int h0,
int bm){
275 for (
int i = h0 - h2; i <= h0 + h2; i++)
280 for (
int i = h0 - b2; i <= h0 + b2; i++)
287 radiusError += bChange;
289 if (((radiusError << 1) + hChange) > 0)
292 radiusError += hChange;
300 int dest_xcoord = std::clamp(event.m_x,
mRect.x + 10,
mRect.x +
mRect.width);
301 int dest_ycoord = std::clamp(event.m_y,
mRect.y + 10,
mRect.y +
mRect.height);
303 int h1 = posXToHopNum(dest_xcoord);
304 int b1 = posYToFreqBin(dest_ycoord);
306 mbCtrlDown =
event.ControlDown() ||
event.AltDown();
317 int h0 = posXToHopNum(src_xcoord);
318 int b0 = posYToFreqBin(src_ycoord);
321 int dh = abs(h1-h0), sh = h0<h1 ? 1 : -1;
322 int db = -abs(b1-b0), sb = b0<b1 ? 1 : -1;
323 int err = dh+db, err2;
327 if (h0 == h1 && b0 == b1)
330 if (err2 * 2 >= db) { err += db; h0 += sh; }
331 if (err2 * 2 <= dh) { err += dh; b0 += sb; }
337 if(
auto *sView =
dynamic_cast<SpectrumView*
>(pView.get())){
341 if(resFreqBin != - 1)
350 for(
auto & bins: binsToWork)
351 drawCircle(h0, bins);
357 mpSpectralData->coordHistory.push_back(std::make_pair(dest_xcoord, dest_ycoord));
366 return { tip, pCursor };
381 XO(
"Erased selected area" ),
382 XO(
"Erased selected area" ) );
387 XO(
"Selected area using Brush Tool" ),
388 XO(
"Brush tool selection" ) );
403 const wxRect &rect,
unsigned iPass )
406 auto& dc = context.
dc;
410 dc.SetBrush( *wxTRANSPARENT_BRUSH );
411 dc.SetPen( *wxYELLOW_PEN );
418 auto pView =
mpView.lock();
@ SELECTION_RESIZE_REGION
static Settings & settings()
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
bool within(A a, B b, DIST d)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
std::shared_ptr< SelectionStateChanger > mSelectionStateChanger
std::shared_ptr< StateSaver > mpStateSaver
long long mSampleCountLowerBound
HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject) override
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
void Enter(bool forward, AudacityProject *pProject) override
bool IsDragging() const override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
BrushHandle(const BrushHandle &)
double mFreqSnappingRatio
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
void HandleHopBinData(int hopNum, int freqBinNum)
std::weak_ptr< ChannelView > mpView
double mOvertonesThreshold
Result Cancel(AudacityProject *) override
bool Escape(AudacityProject *pProject) override
std::shared_ptr< WaveChannel > FindChannel()
long long mSampleCountUpperBound
std::shared_ptr< SpectralData > mpSpectralData
std::shared_ptr< const Track > FindTrack() const override
virtual bool IsSpectral() const
auto FindChannel() -> std::shared_ptr< Subtype >
May return null.
float PositionToValue(float pp) const
float ValueToPosition(float val) const
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
Holds various per-project settings values, and sends events to the project when certain values change...
int GetBrushRadius() const
bool IsSmartSelection() const
static std::vector< int > FindHighestFrequencyBins(WaveChannel &wc, long long int startSC, int hopSize, double threshold, int targetFreqBin)
static int FindFrequencySnappingBin(const WaveChannel &channel, long long startSC, int hopSize, double threshold, int targetFreqBin)
void GetBounds(const WaveChannel &wc, float &min, float &max) const
static SpectrogramBounds & Get(WaveTrack &track)
Get either the global default settings, or the track's own if previously created.
bool SpectralSelectionEnabled() const
static SpectrogramSettings & Get(const WaveTrack &track)
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
static TrackPanel & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
static std::shared_ptr< const Track > TrackFromChannel(const std::shared_ptr< const Channel > &pChannel)
A frequent convenience in the definition of UIHandles.
static ViewInfo & Get(AudacityProject &project)
double GetRate() const override
A Track that contains audio waveform data.
sampleCount TimeToLongSamples(double t0) const
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Positions or offsets within audio files need a wide type.
long long as_long_long() const
Namespace containing an enum 'what to do on a refresh?'.
bool isSpectralSelectionView(const ChannelView *pChannelView)
double PositionToFrequency(const WaveChannel &wc, bool maySnap, wxInt64 mouseYCoordinate, wxInt64 trackTopEdge, int trackHeight)
wxCursor * CrosshairCursor()
void SetIfNotNull(T *pValue, const T Value)
long long PositionToLongSample(const WaveTrack *wt, const ViewInfo &viewInfo, int trackTopEdgeX, int mousePosX)
wxInt64 FrequencyToPosition(const WaveChannel &wc, double frequency, wxInt64 trackTopEdge, int trackHeight)
Converts a frequency to screen y position.
double findMaxRatio(double center, double rate)
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept