Audacity 3.2.0
SpectrumView.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5SpectrumView.cpp
6
7Paul Licameli split from WaveChannelView.cpp
8
9**********************************************************************/
10
11
12#include "SpectrumView.h"
13
14#include "SpectralDataManager.h" // Cycle :-(
15#include "SpectrumCache.h"
16
17#include "Sequence.h"
18#include "Spectrum.h"
19
20#include "ClipParameters.h"
23
24#include "../../../ui/BrushHandle.h"
25
26#include "AColor.h"
27#include "PendingTracks.h"
28#include "Prefs.h"
29#include "NumberScale.h"
30#include "../../../../TrackArt.h"
31#include "../../../../TrackArtist.h"
32#include "../../../../TrackPanelDrawingContext.h"
33#include "ViewInfo.h"
34#include "WaveClip.h"
35#include "WaveTrack.h"
36#include "WaveTrackLocation.h"
37#include "WaveTrackUtilities.h"
38#include "../../../../prefs/SpectrogramSettings.h"
39
40#include <wx/dcmemory.h>
41#include <wx/graphics.h>
42
43#include "float_cast.h"
44
45class BrushHandle;
46class SpectralData;
47
50 { wxT("Spectrogram"), XXO("&Spectrogram") }
51};
52
54
56 : WaveChannelSubView(waveChannelView)
57{
58 const auto wt = FindWaveChannel();
59 mpSpectralData = std::make_shared<SpectralData>(wt->GetRate());
60 mOnBrushTool = false;
61}
62
64
66{
67 return true;
68}
69
71public:
73 : mView{ view }
74 {}
75
76 void Init( AudacityProject &project, bool clearAll ) override
77 {
79 ForAll( project, [this, clearAll](SpectrumView &view){
80 auto pOldData = view.mpSpectralData;
81 if (clearAll) {
82 auto &pNewData = view.mpBackupSpectralData =
83 std::make_shared<SpectralData>(pOldData->GetSR());
84 pNewData->CopyFrom(*pOldData);
85 pOldData->clearAllData();
86 }
87 else {
88 // Back up one view only
89 if (&mView == &view) {
90 auto &pNewData = view.mpBackupSpectralData =
91 std::make_shared<SpectralData>(pOldData->GetSR());
92 pNewData->CopyFrom( *pOldData );
93 }
94 else
95 view.mpBackupSpectralData = {};
96 }
97 });
98 }
99
101 {
102 if (mpProject)
103 ForAll( *mpProject, [this](SpectrumView &view){
104 if (mCommitted) {
105 // Discard all backups
106 view.mpBackupSpectralData = {};
107 }
108 else {
109 // Restore all
110 if (auto &pBackupData = view.mpBackupSpectralData) {
111 view.mpSpectralData->CopyFrom(*pBackupData);
112 pBackupData.reset();
113 }
114 }
115 });
116 }
117
118private:
121};
122
123// This always hits, but details of the hit vary with mouse position and
124// key state.
126 std::weak_ptr<BrushHandle> &holder,
127 const TrackPanelMouseState &st, const AudacityProject *pProject,
128 const std::shared_ptr<SpectrumView> &pChannelView,
129 const std::shared_ptr<SpectralData> &mpData)
130{
131 const auto &viewInfo = ViewInfo::Get( *pProject );
132 auto &projectSettings = ProjectSettings::Get( *pProject );
133 auto result = std::make_shared<BrushHandle>(
134 std::make_shared<SpectrumView::SpectralDataSaver>(*pChannelView),
135 pChannelView, TrackList::Get(*pProject),
136 st, viewInfo, mpData, projectSettings);
137
138 result = AssignUIHandlePtr(holder, result);
139
140 //Make sure we are within the selected track
141 const auto pChannel = pChannelView->FindWaveChannel();
142 if (!pChannel ||
143 !pChannel->GetTrack().GetSelected())
144 {
145 return result;
146 }
147
148 return result;
149}
150
152 std::function<void(SpectrumView &view)> fn )
153{
154 if (!fn)
155 return;
156 for (const auto wt : TrackList::Get(project).Any<WaveTrack>()) {
157 for (auto pChannel : wt->Channels()) {
158 if (auto pWaveChannelView =
159 dynamic_cast<WaveChannelView*>(&ChannelView::Get(*pChannel))) {
160 for (const auto &pSubView : pWaveChannelView->GetAllSubViews()) {
161 if (const auto sView = dynamic_cast<SpectrumView*>(pSubView.get()))
162 fn( *sView );
163 }
164 }
165 }
166 }
167}
168
169std::vector<UIHandlePtr> SpectrumView::DetailedHitTest(
170 const TrackPanelMouseState &state,
171 const AudacityProject *pProject, int currentTool, bool bMultiTool )
172{
173 const auto wt = FindWaveChannel();
174 std::vector<UIHandlePtr> results;
175
176#ifdef EXPERIMENTAL_BRUSH_TOOL
177 mOnBrushTool = (currentTool == ToolCodes::brushTool);
178 if(mOnBrushTool){
179 const auto result = BrushHandleHitTest(
180 mBrushHandle, state,
181 pProject, std::static_pointer_cast<SpectrumView>(shared_from_this()),
183 results.push_back(result);
184 return results;
185 }
186#endif
187
189 state, pProject, currentTool, bMultiTool, wt
190 ).second;
191}
192
193void SpectrumView::DoSetMinimized( bool minimized )
194{
195 const auto wt = FindWaveChannel();
196 if (!wt)
197 return;
198
199 bool bHalfWave;
200 gPrefs->Read(wxT("/GUI/CollapseToHalfWave"), &bHalfWave, false);
201 if( bHalfWave && minimized)
202 {
203 // It is all right to set the top of scale to a huge number,
204 // not knowing the track sampleRate here -- because when retrieving the
205 // value, then we pass in a sample rate and clamp it above to the
206 // Nyquist frequency.
207 constexpr auto max = std::numeric_limits<float>::max();
208 const bool spectrumLinear =
211 // Zoom out full
213 .SetBounds( spectrumLinear ? 0.0f : 1.0f, max );
214 }
215
217}
218
219auto SpectrumView::SubViewType() const -> const Type &
220{
221 return sType;
222}
223
224std::shared_ptr<ChannelVRulerControls> SpectrumView::DoGetVRulerControls()
225{
226 return std::make_shared<SpectrumVRulerControls>(shared_from_this());
227}
228
229std::shared_ptr<SpectralData> SpectrumView::GetSpectralData(){
230 return mpSpectralData;
231}
232
234{
235 if (const auto pDest = dynamic_cast< SpectrumView* >(destSubView)) {
236 pDest->mpSpectralData =
237 std::make_shared<SpectralData>(mpSpectralData->GetSR());
238 pDest->mpSpectralData->CopyFrom(*mpSpectralData);
239 }
240}
241
242namespace
243{
244
245static inline float findValue
246(const float *spectrum, float bin0, float bin1, unsigned nBins,
247 bool autocorrelation, int gain, int range)
248{
249 float value;
250
251
252#if 0
253 // Averaging method
254 if ((int)(bin1) == (int)(bin0)) {
255 value = spectrum[(int)(bin0)];
256 } else {
257 float binwidth= bin1 - bin0;
258 value = spectrum[(int)(bin0)] * (1.f - bin0 + (int)bin0);
259
260 bin0 = 1 + (int)(bin0);
261 while (bin0 < (int)(bin1)) {
262 value += spectrum[(int)(bin0)];
263 bin0 += 1.0;
264 }
265 // Do not reference past end of freq array.
266 if ((int)(bin1) >= (int)nBins) {
267 bin1 -= 1.0;
268 }
269
270 value += spectrum[(int)(bin1)] * (bin1 - (int)(bin1));
271 value /= binwidth;
272 }
273#else
274 // Maximum method, and no apportionment of any single bins over multiple pixel rows
275 // See Bug971
276 int index, limitIndex;
277 if (autocorrelation) {
278 // bin = 2 * nBins / (nBins - 1 - array_index);
279 // Solve for index
280 index = std::max(0.0f, std::min(float(nBins - 1),
281 (nBins - 1) - (2 * nBins) / (std::max(1.0f, bin0))
282 ));
283 limitIndex = std::max(0.0f, std::min(float(nBins - 1),
284 (nBins - 1) - (2 * nBins) / (std::max(1.0f, bin1))
285 ));
286 }
287 else {
288 index = std::min<int>(nBins - 1, (int)(floor(0.5 + bin0)));
289 limitIndex = std::min<int>(nBins, (int)(floor(0.5 + bin1)));
290 }
291 value = spectrum[index];
292 while (++index < limitIndex)
293 value = std::max(value, spectrum[index]);
294#endif
295 if (!autocorrelation) {
296 // Last step converts dB to a 0.0-1.0 range
297 value = (value + range + gain) / (double)range;
298 }
299 value = std::min(1.0f, std::max(0.0f, value));
300 return value;
301}
302
303// dashCount counts both dashes and the spaces between them.
305ChooseColorSet( float bin0, float bin1, float selBinLo,
306 float selBinCenter, float selBinHi, int dashCount, bool isSpectral )
307{
308 if (!isSpectral)
310 if ((selBinCenter >= 0) && (bin0 <= selBinCenter) &&
311 (selBinCenter < bin1))
313 if ((0 == dashCount % 2) &&
314 (((selBinLo >= 0) && (bin0 <= selBinLo) && ( selBinLo < bin1)) ||
315 ((selBinHi >= 0) && (bin0 <= selBinHi) && ( selBinHi < bin1))))
317 if ((selBinLo < 0 || selBinLo < bin1) && (selBinHi < 0 || selBinHi > bin0))
319
321}
322
323std::pair<sampleCount, sampleCount> GetSelectedSampleIndices(
324 const SelectedRegion& selectedRegion, const WaveChannelInterval& clip,
325 bool trackIsSelected)
326{
327 if (!trackIsSelected)
328 return { 0, 0 };
329 const double t0 = selectedRegion.t0(); // left selection bound
330 const double t1 = selectedRegion.t1(); // right selection bound
331 const auto startTime = clip.GetPlayStartTime();
332 const auto s0 = std::max(sampleCount(0), clip.TimeToSamples(t0 - startTime));
333 auto s1 = std::clamp(
334 clip.TimeToSamples(t1 - startTime), sampleCount { 0 },
335 clip.GetVisibleSampleCount());
336 return { s0, s1 };
337}
338
340 const WaveChannel &channel,
341 const WaveChannelInterval &clip, const wxRect &rect,
342 const std::shared_ptr<SpectralData> &mpSpectralData,
343 bool selected)
344{
345 auto &dc = context.dc;
346 const auto artist = TrackArtist::Get(context);
347 bool onBrushTool = artist->onBrushTool;
348 const auto &selectedRegion = *artist->pSelectedRegion;
349 const auto &zoomInfo = *artist->pZoomInfo;
350
351#ifdef PROFILE_WAVEFORM
352 Profiler profiler;
353#endif
354
355 //If clip is "too small" draw a placeholder instead of
356 //attempting to fit the contents into a few pixels
357 if (!WaveChannelView::ClipDetailsVisible(clip, zoomInfo, rect))
358 {
359 auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect);
360 TrackArt::DrawClipFolded(dc, clipRect);
361 return;
362 }
363
364 auto &settings = SpectrogramSettings::Get(channel);
365 const bool autocorrelation = (settings.algorithm == SpectrogramSettings::algPitchEAC);
366
367 enum { DASH_LENGTH = 10 /* pixels */ };
368
369 const ClipParameters params { clip, rect, zoomInfo };
370 const wxRect &hiddenMid = params.hiddenMid;
371 // The "hiddenMid" rect contains the part of the display actually
372 // containing the waveform, as it appears without the fisheye. If it's empty, we're done.
373 if (hiddenMid.width <= 0) {
374 return;
375 }
376
377 const double &t0 = params.t0;
378 const double playStartTime = clip.GetPlayStartTime();
379
380 const auto [ssel0, ssel1] = GetSelectedSampleIndices(selectedRegion, clip,
381 channel.GetTrack().GetSelected());
382 const double &averagePixelsPerSecond = params.averagePixelsPerSecond;
383 const double sampleRate = clip.GetRate();
384 const double stretchRatio = clip.GetStretchRatio();
385 const double &hiddenLeftOffset = params.hiddenLeftOffset;
386 const double &leftOffset = params.leftOffset;
387 const wxRect &mid = params.mid;
388
391 freqLo = selectedRegion.f0();
392 freqHi = selectedRegion.f1();
393
394 const int &colorScheme = settings.colorScheme;
395 const int &range = settings.range;
396 const int &gain = settings.gain;
397
398#ifdef EXPERIMENTAL_FIND_NOTES
399 const bool &fftFindNotes = settings.fftFindNotes;
400 const double &findNotesMinA = settings.findNotesMinA;
401 const int &numberOfMaxima = settings.numberOfMaxima;
402 const bool &findNotesQuantize = settings.findNotesQuantize;
403#endif
404#ifdef EXPERIMENTAL_FFT_Y_GRID
405 const bool &fftYGrid = settings.fftYGrid;
406#endif
407
408 dc.SetPen(*wxTRANSPARENT_PEN);
409
410 // We draw directly to a bit image in memory,
411 // and then paint this directly to our offscreen
412 // bitmap. Note that this could be optimized even
413 // more, but for now this is not bad. -dmazzoni
414 wxImage image((int)mid.width, (int)mid.height);
415 if (!image.IsOk())
416 return;
417#ifdef EXPERIMENTAL_SPECTROGRAM_OVERLAY
418 image.SetAlpha();
419 unsigned char *alpha = image.GetAlpha();
420#endif
421 unsigned char *data = image.GetData();
422
423 const auto half = settings.GetFFTLength() / 2;
424 const double binUnit = sampleRate / (2 * half);
425 const float *freq = 0;
426 const sampleCount *where = 0;
427 bool updated = WaveClipSpectrumCache::Get(clip).GetSpectrogram(
428 clip, freq, settings, where, (size_t)hiddenMid.width, t0,
429 averagePixelsPerSecond);
430 auto nBins = settings.NBins();
431
432 float minFreq, maxFreq;
433 SpectrogramBounds::Get(channel).GetBounds(channel, minFreq, maxFreq);
434
435 const SpectrogramSettings::ScaleType scaleType = settings.scaleType;
436
437 // nearest frequency to each pixel row from number scale, for selecting
438 // the desired fft bin(s) for display on that row
439 float *bins = (float*)alloca(sizeof(*bins)*(hiddenMid.height + 1));
440 {
441 const NumberScale numberScale( settings.GetScale( minFreq, maxFreq ) );
442
443 NumberScale::Iterator it = numberScale.begin(mid.height);
444 float nextBin = std::max( 0.0f, std::min( float(nBins - 1),
445 settings.findBin( *it, binUnit ) ) );
446
447 int yy;
448 for (yy = 0; yy < hiddenMid.height; ++yy) {
449 bins[yy] = nextBin;
450 nextBin = std::max( 0.0f, std::min( float(nBins - 1),
451 settings.findBin( *++it, binUnit ) ) );
452 }
453 bins[yy] = nextBin;
454 }
455
456#ifdef EXPERIMENTAL_FFT_Y_GRID
457 const float
458 log2 = logf(2.0f),
459 scale2 = (lmax - lmin) / log2,
460 lmin2 = lmin / log2;
461
462 ArrayOf<bool> yGrid{size_t(mid.height)};
463 for (int yy = 0; yy < mid.height; ++yy) {
464 float n = (float(yy) / mid.height*scale2 - lmin2) * 12;
465 float n2 = (float(yy + 1) / mid.height*scale2 - lmin2) * 12;
466 float f = float(minFreq) / (fftSkipPoints + 1)*powf(2.0f, n / 12.0f + lmin2);
467 float f2 = float(minFreq) / (fftSkipPoints + 1)*powf(2.0f, n2 / 12.0f + lmin2);
468 n = logf(f / 440) / log2 * 12;
469 n2 = logf(f2 / 440) / log2 * 12;
470 if (floor(n) < floor(n2))
471 yGrid[yy] = true;
472 else
473 yGrid[yy] = false;
474 }
475#endif //EXPERIMENTAL_FFT_Y_GRID
476
477 auto &clipCache = WaveClipSpectrumCache::Get(clip);
478 auto &specPxCache = clipCache.mSpecPxCaches[clip.GetChannelIndex()];
479 if (!updated && specPxCache &&
480 ((int)specPxCache->len == hiddenMid.height * hiddenMid.width)
481 && scaleType == specPxCache->scaleType
482 && gain == specPxCache->gain
483 && range == specPxCache->range
484 && minFreq == specPxCache->minFreq
485 && maxFreq == specPxCache->maxFreq
486#ifdef EXPERIMENTAL_FFT_Y_GRID
487 && fftYGrid==fftYGridOld
488#endif //EXPERIMENTAL_FFT_Y_GRID
489#ifdef EXPERIMENTAL_FIND_NOTES
490 && fftFindNotes == artist->fftFindNotesOld
491 && findNotesMinA == artist->findNotesMinAOld
492 && numberOfMaxima == artist->findNotesNOld
493 && findNotesQuantize == artist->findNotesQuantizeOld
494#endif
495 ) {
496 // Wave clip's spectrum cache is up to date,
497 // and so is the spectrum pixel cache
498 }
499 else {
500 // Update the spectrum pixel cache
501 specPxCache = std::make_unique<SpecPxCache>(hiddenMid.width * hiddenMid.height);
502 specPxCache->scaleType = scaleType;
503 specPxCache->gain = gain;
504 specPxCache->range = range;
505 specPxCache->minFreq = minFreq;
506 specPxCache->maxFreq = maxFreq;
507#ifdef EXPERIMENTAL_FIND_NOTES
508 artist->fftFindNotesOld = fftFindNotes;
509 artist->findNotesMinAOld = findNotesMinA;
510 artist->findNotesNOld = numberOfMaxima;
511 artist->findNotesQuantizeOld = findNotesQuantize;
512#endif
513
514#ifdef EXPERIMENTAL_FIND_NOTES
515 float log2 = logf( 2.0f ),
516 lmin = logf( minFreq ), lmax = logf( maxFreq ), scale = lmax - lmin,
517 lmins = lmin,
518 lmaxs = lmax
519 ;
520#endif //EXPERIMENTAL_FIND_NOTES
521
522#ifdef EXPERIMENTAL_FIND_NOTES
523 int maxima[128];
524 float maxima0[128], maxima1[128];
525 const float
526 f2bin = half / (sampleRate / 2.0f),
527 bin2f = 1.0f / f2bin,
528 minDistance = powf(2.0f, 2.0f / 12.0f),
529 i0 = expf(lmin) / binUnit,
530 i1 = expf(scale + lmin) / binUnit,
531 minColor = 0.0f;
532 const size_t maxTableSize = 1024;
533 ArrayOf<int> indexes{ maxTableSize };
534#endif //EXPERIMENTAL_FIND_NOTES
535
536#ifdef _OPENMP
537#pragma omp parallel for
538#endif
539 for (int xx = 0; xx < hiddenMid.width; ++xx) {
540#ifdef EXPERIMENTAL_FIND_NOTES
541 int maximas = 0;
542 const int x0 = nBins * xx;
543 if (fftFindNotes) {
544 for (int i = maxTableSize - 1; i >= 0; i--)
545 indexes[i] = -1;
546
547 // Build a table of (most) values, put the index in it.
548 for (int i = (int)(i0); i < (int)(i1); i++) {
549 float freqi = freq[x0 + (int)(i)];
550 int value = (int)((freqi + gain + range) / range*(maxTableSize - 1));
551 if (value < 0)
552 value = 0;
553 if (value >= maxTableSize)
554 value = maxTableSize - 1;
555 indexes[value] = i;
556 }
557 // Build from the indices an array of maxima.
558 for (int i = maxTableSize - 1; i >= 0; i--) {
559 int index = indexes[i];
560 if (index >= 0) {
561 float freqi = freq[x0 + index];
562 if (freqi < findNotesMinA)
563 break;
564
565 bool ok = true;
566 for (int m = 0; m < maximas; m++) {
567 // Avoid to store very close maxima.
568 float maxm = maxima[m];
569 if (maxm / index < minDistance && index / maxm < minDistance) {
570 ok = false;
571 break;
572 }
573 }
574 if (ok) {
575 maxima[maximas++] = index;
576 if (maximas >= numberOfMaxima)
577 break;
578 }
579 }
580 }
581
582// The f2pix helper macro converts a frequency into a pixel coordinate.
583#define f2pix(f) (logf(f)-lmins)/(lmaxs-lmins)*hiddenMid.height
584
585 // Possibly quantize the maxima frequencies and create the pixel block limits.
586 for (int i = 0; i < maximas; i++) {
587 int index = maxima[i];
588 float f = float(index)*bin2f;
589 if (findNotesQuantize)
590 {
591 f = expf((int)(log(f / 440) / log2 * 12 - 0.5) / 12.0f*log2) * 440;
592 maxima[i] = f*f2bin;
593 }
594 float f0 = expf((log(f / 440) / log2 * 24 - 1) / 24.0f*log2) * 440;
595 maxima0[i] = f2pix(f0);
596 float f1 = expf((log(f / 440) / log2 * 24 + 1) / 24.0f*log2) * 440;
597 maxima1[i] = f2pix(f1);
598 }
599 }
600
601 int it = 0;
602 bool inMaximum = false;
603#endif //EXPERIMENTAL_FIND_NOTES
604
605 for (int yy = 0; yy < hiddenMid.height; ++yy) {
606 const float bin = bins[yy];
607 const float nextBin = bins[yy+1];
608
610 const float value = findValue
611 (freq + nBins * xx, bin, nextBin, nBins, autocorrelation, gain, range);
612 specPxCache->values[xx * hiddenMid.height + yy] = value;
613 }
614 else {
615 float value;
616
617#ifdef EXPERIMENTAL_FIND_NOTES
618 if (fftFindNotes) {
619 if (it < maximas) {
620 float i0 = maxima0[it];
621 if (yy >= i0)
622 inMaximum = true;
623
624 if (inMaximum) {
625 float i1 = maxima1[it];
626 if (yy + 1 <= i1) {
627 value = findValue(freq + x0, bin, nextBin, nBins, autocorrelation, gain, range);
628 if (value < findNotesMinA)
629 value = minColor;
630 }
631 else {
632 it++;
633 inMaximum = false;
634 value = minColor;
635 }
636 }
637 else {
638 value = minColor;
639 }
640 }
641 else
642 value = minColor;
643 }
644 else
645#endif //EXPERIMENTAL_FIND_NOTES
646 {
647 value = findValue
648 (freq + nBins * xx, bin, nextBin, nBins, autocorrelation, gain, range);
649 }
650 specPxCache->values[xx * hiddenMid.height + yy] = value;
651 } // logF
652 } // each yy
653 } // each xx
654 } // updating cache
655
656 float selBinLo = settings.findBin( freqLo, binUnit);
657 float selBinHi = settings.findBin( freqHi, binUnit);
658 float selBinCenter = (freqLo < 0 || freqHi < 0)
659 ? -1
660 : settings.findBin( sqrt(freqLo * freqHi), binUnit );
661
662 const bool isSpectral = settings.SpectralSelectionEnabled();
663 const bool hidden = (ZoomInfo::HIDDEN == zoomInfo.GetFisheyeState());
664 const int begin = hidden
665 ? 0
666 : std::max(0, (int)(zoomInfo.GetFisheyeLeftBoundary(-leftOffset)));
667 const int end = hidden
668 ? 0
669 : std::min(mid.width, (int)(zoomInfo.GetFisheyeRightBoundary(-leftOffset)));
670 const size_t numPixels = std::max(0, end - begin);
671
672 SpecCache specCache;
673
674 // need explicit resize since specCache.where[] accessed before Populate()
675 specCache.Grow(numPixels, settings, -1, t0);
676
677 if (numPixels > 0) {
678 for (int ii = begin; ii < end; ++ii) {
679 const double time = zoomInfo.PositionToTime(ii, -leftOffset) - playStartTime;
680 specCache.where[ii - begin] =
681 sampleCount(0.5 + sampleRate / stretchRatio * time);
682 }
683 specCache.Populate(
684 settings, clip, 0, 0, numPixels,
685 0 // FIXME: PRL -- make reassignment work with fisheye
686 );
687 }
688
689 // build color gradient tables (not thread safe)
692
693 // left pixel column of the fisheye
694 int fisheyeLeft = zoomInfo.GetFisheyeLeftBoundary(-leftOffset);
695
696 // Bug 2389 - always draw at least one pixel of selection.
697 int selectedX = zoomInfo.TimeToPosition(selectedRegion.t0(), -leftOffset);
698
699#ifdef _OPENMP
700#pragma omp parallel for
701#endif
702
703 const NumberScale numberScale(settings.GetScale(minFreq, maxFreq));
704 int windowSize = mpSpectralData->GetWindowSize();
705 int hopSize = mpSpectralData->GetHopSize();
706 double sr = mpSpectralData->GetSR();
707 auto &dataHistory = mpSpectralData->dataHistory;
708
709 // Lazy way to add all hops and bins required for rendering
710 dataHistory.push_back(mpSpectralData->dataBuffer);
711
712 // Generate combined hops and bins map for rendering
713 std::map<long long, std::set<int>> hopBinMap;
714 for(auto vecIter = dataHistory.begin(); vecIter != dataHistory.end(); ++vecIter){
715 for(const auto &hopMap: *vecIter){
716 for(const auto &binNum: hopMap.second)
717 hopBinMap[hopMap.first].insert(binNum);
718 }
719 }
720
721 // Lambda for converting yy (not mouse coord!) to respective freq. bins
722 auto yyToFreqBin = [&](int yy){
723 const double p = double(yy) / hiddenMid.height;
724 float convertedFreq = numberScale.PositionToValue(p);
725 float convertedFreqBinNum = convertedFreq / (sr / windowSize);
726
727 // By default lrintf will round to nearest by default, rounding to even on tie.
728 // std::round that was used here before rounds halfway cases away from zero.
729 // However, we can probably tolerate rounding issues here, as this will only slightly affect
730 // the visuals.
731 return static_cast<int>(lrintf(convertedFreqBinNum));
732 };
733
734 for (int xx = 0; xx < mid.width; ++xx) {
735 int correctedX = xx + leftOffset - hiddenLeftOffset;
736
737 // in fisheye mode the time scale has changed, so the row values aren't cached
738 // in the loop above, and must be fetched from fft cache
739 float* uncached;
740 if (!zoomInfo.InFisheye(xx, -leftOffset)) {
741 uncached = 0;
742 }
743 else {
744 int specIndex = (xx - fisheyeLeft) * nBins;
745 wxASSERT(specIndex >= 0 && specIndex < (int)specCache.freq.size());
746 uncached = &specCache.freq[specIndex];
747 }
748
749 // zoomInfo must be queried for each column since with fisheye enabled
750 // time between columns is variable
751 const auto w0 = sampleCount(
752 0.5 + sampleRate / stretchRatio *
753 (zoomInfo.PositionToTime(xx, -leftOffset) - playStartTime));
754
755 const auto w1 = sampleCount(
756 0.5 + sampleRate / stretchRatio *
757 (zoomInfo.PositionToTime(xx + 1, -leftOffset) - playStartTime));
758
759 bool maybeSelected = ssel0 <= w0 && w1 < ssel1;
760 maybeSelected = maybeSelected || (xx == selectedX);
761
762 // In case the xx matches the hop number, it will be used as iterator for frequency bins
763 std::set<int> *pSelectedBins = nullptr;
764 std::set<int>::iterator freqBinIter;
765 auto advanceFreqBinIter = [&](int nextBinRounded){
766 while (freqBinIter != pSelectedBins->end() &&
767 *freqBinIter < nextBinRounded)
768 ++freqBinIter;
769 };
770
771 bool hitHopNum = false;
772 if (onBrushTool) {
773 int convertedHopNum = (w0.as_long_long() + hopSize / 2) / hopSize;
774 hitHopNum = (hopBinMap.find(convertedHopNum) != hopBinMap.end());
775 if(hitHopNum) {
776 pSelectedBins = &hopBinMap[convertedHopNum];
777 freqBinIter = pSelectedBins->begin();
778 advanceFreqBinIter(yyToFreqBin(0));
779 }
780 }
781
782 for (int yy = 0; yy < hiddenMid.height; ++yy) {
783 if(onBrushTool)
784 maybeSelected = false;
785 const float bin = bins[yy];
786 const float nextBin = bins[yy+1];
787 auto binRounded = yyToFreqBin(yy);
788 auto nextBinRounded = yyToFreqBin(yy + 1);
789
790 if(hitHopNum
791 && freqBinIter != pSelectedBins->end()
792 && binRounded == *freqBinIter)
793 maybeSelected = true;
794
795 if (hitHopNum)
796 advanceFreqBinIter(nextBinRounded);
797
798 // For spectral selection, determine what colour
799 // set to use. We use a darker selection if
800 // in both spectral range and time range.
801
803
804 // If we are in the time selected range, then we may use a different color set.
805 if (maybeSelected) {
806 selected =
807 ChooseColorSet(bin, nextBin, selBinLo, selBinCenter, selBinHi,
808 (xx + leftOffset - hiddenLeftOffset) / DASH_LENGTH, isSpectral);
809 if ( onBrushTool && selected != AColor::ColorGradientUnselected )
810 // use only two sets of colors
812 }
813
814 const float value = uncached
815 ? findValue(uncached, bin, nextBin, nBins, autocorrelation, gain, range)
816 : specPxCache->values[correctedX * hiddenMid.height + yy];
817
818 unsigned char rv, gv, bv;
819 GetColorGradient(value, selected, colorScheme, &rv, &gv, &bv);
820
821#ifdef EXPERIMENTAL_FFT_Y_GRID
822 if (fftYGrid && yGrid[yy]) {
823 rv /= 1.1f;
824 gv /= 1.1f;
825 bv /= 1.1f;
826 }
827#endif //EXPERIMENTAL_FFT_Y_GRID
828 int px = ((mid.height - 1 - yy) * mid.width + xx);
829#ifdef EXPERIMENTAL_SPECTROGRAM_OVERLAY
830 // More transparent the closer to zero intensity.
831 alpha[px]= wxMin( 200, (value+0.3) * 500) ;
832#endif
833 px *=3;
834 data[px++] = rv;
835 data[px++] = gv;
836 data[px] = bv;
837 } // each yy
838 } // each xx
839
840 dataHistory.pop_back();
841 wxBitmap converted = wxBitmap(image);
842
843 wxMemoryDC memDC;
844
845 memDC.SelectObject(converted);
846
847 dc.Blit(mid.x, mid.y, mid.width, mid.height, &memDC, 0, 0, wxCOPY, FALSE);
848
849 // Draw clip edges, as also in waveform view, which improves the appearance
850 // of split views
851 {
852 auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect);
853 TrackArt::DrawClipEdges(dc, clipRect, selected);
854 }
855}
856}
857
859 const WaveChannel &channel, const WaveTrack::Interval* selectedClip,
860 const wxRect & rect)
861{
862 const auto artist = TrackArtist::Get( context );
863 const auto &blankSelectedBrush = artist->blankSelectedBrush;
864 const auto &blankBrush = artist->blankBrush;
866 context, rect, channel, blankSelectedBrush, blankBrush );
867
868 for (const auto &pInterval : channel.Intervals()) {
869 bool selected = selectedClip &&
870 selectedClip == &pInterval->GetClip();
871 DrawClipSpectrum(context, channel, *pInterval, rect, mpSpectralData,
872 selected);
873 }
874
875 DrawBoldBoundaries(context, channel, rect);
876}
877
879 TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass )
880{
881 if ( iPass == TrackArtist::PassTracks ) {
882 const auto artist = TrackArtist::Get(context);
883 const auto &pendingTracks = *artist->pPendingTracks;
884
885 auto &dc = context.dc;
886
887 const auto pChannel = FindChannel();
888 if (!pChannel)
889 return;
890 const auto &wt = static_cast<const WaveChannel&>(
891 pendingTracks.SubstitutePendingChangedChannel(*pChannel));
892
893#if defined(__WXMAC__)
894 wxAntialiasMode aamode = dc.GetGraphicsContext()->GetAntialiasMode();
895 dc.GetGraphicsContext()->SetAntialiasMode(wxANTIALIAS_NONE);
896#endif
897
898 auto waveChannelView = GetWaveChannelView().lock();
899 wxASSERT(waveChannelView.use_count());
900
901 auto selectedClip = waveChannelView->GetSelectedClip();
902 DoDraw(context, wt, selectedClip.get(), rect);
903
904#if defined(__WXMAC__)
905 dc.GetGraphicsContext()->SetAntialiasMode(aamode);
906#endif
907 }
908 WaveChannelSubView::Draw(context, rect, iPass);
909}
910
912 [](WaveChannelView &view){
913 return std::make_shared<SpectrumView>(view);
914 }
915};
916
917// The following attaches the spectrogram settings item to the wave track popup
918// menu. It is appropriate only to spectrum view and so is kept in this
919// source file with the rest of the spectrum view implementation.
920#include "WaveTrackControls.h"
921#include "AudioIOBase.h"
922#include "../../../../MenuCreator.h"
923#include "ProjectHistory.h"
924#include "../../../../RefreshCode.h"
925#include "../../../../prefs/PrefsDialog.h"
926#include "../../../../prefs/SpectrumPrefs.h"
927#include "AudacityMessageBox.h"
928#include "../../../../widgets/PopupMenuTable.h"
929
930namespace {
932
935 {
936 static SpectrogramSettingsHandler instance;
937 return instance;
938 }
939
940 void OnSpectrogramSettings(wxCommandEvent &);
941
942 void InitUserData(void *pUserData) override
943 {
944 mpData = static_cast< PlayableTrackControls::InitMenuData* >(pUserData);
945 }
946};
947
948void SpectrogramSettingsHandler::OnSpectrogramSettings(wxCommandEvent &)
949{
950 class ViewSettingsDialog final : public PrefsDialog
951 {
952 public:
953 ViewSettingsDialog(wxWindow *parent, AudacityProject &project,
955 int page)
956 : PrefsDialog(parent, &project, title, factories)
957 , mPage(page)
958 {
959 }
960
961 long GetPreferredPage() override
962 {
963 return mPage;
964 }
965
966 void SavePreferredPage() override
967 {
968 }
969
970 private:
971 const int mPage;
972 };
973
974 auto gAudioIO = AudioIOBase::Get();
975 if (gAudioIO->IsBusy()){
977 XO(
978"To change Spectrogram Settings, stop any\n playing or recording first."),
979 XO("Stop the Audio First"),
980 wxOK | wxICON_EXCLAMATION | wxCENTRE);
981 return;
982 }
983
984 auto &wc = **static_cast<WaveTrack&>(mpData->track).Channels().begin();
985
986 PrefsPanel::Factories factories;
987 // factories.push_back(WaveformPrefsFactory(&track));
988 factories.push_back(SpectrumPrefsFactory(&wc));
989 const int page =
990 // (pTrack->GetDisplay() == WaveChannelViewConstants::Spectrum) ? 1 :
991 0;
992
993 auto title = XO("%s:").Format(wc.GetTrack().GetName());
994 ViewSettingsDialog dialog(
995 mpData->pParent, mpData->project, title, factories, page);
996
997 if (0 != dialog.ShowModal()) {
998 // Redraw
999 AudacityProject *const project = &mpData->project;
1000 ProjectHistory::Get( *project ).ModifyState(true);
1001 //Bug 1725 Toolbar was left greyed out.
1002 //This solution is overkill, but does fix the problem and is what the
1003 //prefs dialog normally does.
1005 mpData->result = RefreshCode::RefreshAll;
1006 }
1007}
1008
1011 { "SubViews/Extra" },
1012 std::make_unique<PopupMenuSection>( "SpectrogramSettings",
1013 // Conditionally add menu item for settings, if showing spectrum
1014 PopupMenuTable::Adapt< WaveTrackPopupMenuTable >(
1015 [](WaveTrackPopupMenuTable &table)
1016 {
1017 using Entry = PopupMenuTable::Entry;
1018 static const int OnSpectrogramSettingsID =
1020
1021 const auto pTrack = &table.FindWaveTrack();
1022 const auto &view = WaveChannelView::GetFirst(*pTrack);
1023 const auto displays = view.GetDisplays();
1024 bool hasSpectrum = (displays.end() != std::find(
1025 displays.begin(), displays.end(),
1027 WaveChannelViewConstants::Spectrum, {} }
1028 ) );
1029 return hasSpectrum
1030 // In future, we might move this to the context menu of the
1031 // Spectrum vertical ruler.
1032 // (But the latter won't be satisfactory without a means to
1033 // open that other context menu with keystrokes only, and that
1034 // would require some notion of a focused sub-view.)
1035 ? std::make_unique<Entry>("SpectrogramSettings",
1036 Entry::Item,
1037 OnSpectrogramSettingsID,
1038 XXO("S&pectrogram Settings..."),
1039 (wxCommandEventFunction)
1040 (&SpectrogramSettingsHandler::OnSpectrogramSettings),
1041 SpectrogramSettingsHandler::Instance(),
1042 []( PopupMenuHandler &handler, wxMenu &menu, int id ){
1043 // Bug 1253. Shouldn't open preferences if audio is busy.
1044 // We can't change them on the fly yet anyway.
1045 auto gAudioIO = AudioIOBase::Get();
1046 menu.Enable(id, !gAudioIO->IsBusy());
1047 } )
1048 : nullptr;
1049 } ) )
1050};
1051}
1052
1053static bool ShouldCaptureEvent(wxKeyEvent& event, SpectralData *pData)
1054{
1055 const auto keyCode = event.GetKeyCode();
1056 return
1057 (keyCode == WXK_BACK || keyCode == WXK_DELETE ||
1058 keyCode == WXK_NUMPAD_DELETE)
1059 && pData && !pData->dataHistory.empty();
1060}
1061
1063 wxKeyEvent& event, ViewInfo&, wxWindow*, AudacityProject*)
1064{
1065 bool capture = ShouldCaptureEvent(event, mpSpectralData.get());
1066 event.Skip(!capture);
1068}
1069
1070unsigned SpectrumView::KeyDown(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow*, AudacityProject* project)
1071{
1072 bool capture = ShouldCaptureEvent(event, mpSpectralData.get());
1073 event.Skip(!capture);
1075 // Not RefreshCell, because there might be effects in multiple tracks
1078}
1079
1081 wxKeyEvent &event, ViewInfo&, wxWindow*, AudacityProject* )
1082{
1083 bool capture = ShouldCaptureEvent(event, mpSpectralData.get());
1084 event.Skip(!capture);
1086}
1087
1088// Attach some related menu items
1089#include "../../../ui/SelectHandle.h"
1090#include "../../../../CommonCommandFlags.h"
1091#include "Project.h"
1092#include "../../../../SpectrumAnalyst.h"
1093#include "CommandContext.h"
1094
1095namespace {
1097{
1098 // This only ever considered the left member of a stereo pair!
1099 // TODO: account for the right hand channel too.
1100 // (How? Average corresponding bin power?)
1101
1102 auto &tracks = TrackList::Get( project );
1103 auto &viewInfo = ViewInfo::Get( project );
1104
1105 // Find the first selected wave track that is in a spectrogram view.
1106 const auto hasSpectrum = [](const WaveTrack *wt){
1107 const auto displays = WaveChannelView::GetFirst(*wt).GetDisplays();
1108 return displays.end() != std::find(
1109 displays.begin(), displays.end(),
1110 WaveChannelSubView::Type{ WaveChannelViewConstants::Spectrum, {} });
1111 };
1112 const auto range = tracks.Selected<const WaveTrack>();
1113 const auto iter = find_if(begin(range), end(range), hasSpectrum);
1114 if (iter != end(range)) {
1115 SpectrumAnalyst analyst;
1116 auto &wt = **iter;
1118 viewInfo, **wt.Channels().first, up);
1120 }
1121}
1122
1124
1125// Handler state:
1128
1130{
1131 auto &project = context.project;
1132 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1133
1134 const double f0 = selectedRegion.f0();
1135 const double f1 = selectedRegion.f1();
1136 const bool haveSpectralSelection =
1139 if (haveSpectralSelection)
1140 {
1141 mLastF0 = f0;
1142 mLastF1 = f1;
1143 selectedRegion.setFrequencies
1145 }
1146 else
1147 selectedRegion.setFrequencies(mLastF0, mLastF1);
1148
1150}
1151
1153{
1154 auto &project = context.project;
1156}
1157
1159{
1160 auto &project = context.project;
1162}
1163};
1164
1165// Handler is stateful. Needs a factory registered with
1166// AudacityProject.
1168 [](AudacityProject&) {
1169 return std::make_unique< Handler >(); } };
1170
1172 return project.AttachedObjects::Get< Handler >( key );
1173};
1174
1175using namespace MenuRegistry;
1176#define FN(X) (& Handler :: X)
1177
1179{
1180 static auto menu = std::shared_ptr{
1182 Menu( wxT("Spectral"), XXO("S&pectral"),
1183 Command( wxT("ToggleSpectralSelection"),
1184 XXO("To&ggle Spectral Selection"), FN(OnToggleSpectralSelection),
1185 TracksExistFlag(), wxT("Q") ),
1186 Command( wxT("NextHigherPeakFrequency"),
1187 XXO("Next &Higher Peak Frequency"), FN(OnNextHigherPeakFrequency),
1188 TracksExistFlag() ),
1189 Command( wxT("NextLowerPeakFrequency"),
1190 XXO("Next &Lower Peak Frequency"), FN(OnNextLowerPeakFrequency),
1191 TracksExistFlag() )
1192 ) ) };
1193 return menu;
1194}
1195
1196#undef FN
1197
1199 Placement{ wxT("Select/Basic"), { OrderingHint::After, wxT("Region") } }
1200};
1201
1202}
void GetColorGradient(float value, AColor::ColorGradientChoice selected, int colorScheme, unsigned char *__restrict red, unsigned char *__restrict green, unsigned char *__restrict blue)
Definition: AColor.h:151
wxImage(22, 22)
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
AttachedItem sAttachment2
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
wxEvtHandler CommandHandlerObject
const ReservedCommandFlag & TracksExistFlag()
int min(int a, int b)
EffectDistortionSettings params
Definition: Distortion.cpp:77
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
static const auto title
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
PrefsPanel::Factory SpectrumPrefsFactory(WaveChannel *wc)
static WaveChannelSubViewType::RegisteredType reg
static const WaveChannelSubViews::RegisteredFactory key
static WaveChannelSubView::Type sType
static bool ShouldCaptureEvent(wxKeyEvent &event, SpectralData *pData)
#define FN(X)
static UIHandlePtr BrushHandleHitTest(std::weak_ptr< BrushHandle > &holder, const TrackPanelMouseState &st, const AudacityProject *pProject, const std::shared_ptr< SpectrumView > &pChannelView, const std::shared_ptr< SpectralData > &mpData)
const auto tracks
const auto project
static Settings & settings()
Definition: TrackInfo.cpp:69
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
WaveTrackPopupMenuTable & GetWaveTrackMenuTable()
static const auto fn
ColorGradientChoice
Definition: AColor.h:28
@ ColorGradientUnselected
Definition: AColor.h:29
@ ColorGradientTimeAndFrequencySelected
Definition: AColor.h:31
@ ColorGradientEdge
Definition: AColor.h:32
@ ColorGradientTimeSelected
Definition: AColor.h:30
static void PreComputeGradient()
Definition: AColor.cpp:709
static bool gradient_inited
Definition: AColor.h:135
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:94
static ChannelView & Get(Channel &channel)
virtual void DoSetMinimized(bool isMinimized)
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
auto FindChannel() -> std::shared_ptr< Subtype >
May return null.
static void RebuildAllMenuBars()
double f0() const
Definition: ViewInfo.h:37
float PositionToValue(float pp) const
Definition: NumberScale.h:155
Iterator begin(float nPositions) const
Definition: NumberScale.h:232
PopupMenuTableEntry Entry
Dialog that shows the current PrefsPanel in a tabbed divider.
Definition: PrefsDialog.h:29
virtual void SavePreferredPage()=0
PrefsDialog(wxWindow *parent, AudacityProject *pProject, const TranslatableString &titlePrefix=XO("Preferences:"), PrefsPanel::Factories &factories=PrefsPanel::DefaultFactories())
virtual long GetPreferredPage()=0
std::vector< PrefsPanel::PrefsNode > Factories
Definition: PrefsPanel.h:72
A simple profiler to measure the average time lengths that a particular task/function takes....
Definition: Profiler.h:40
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static ProjectSettings & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
static void SnapCenterOnce(SpectrumAnalyst &analyst, ViewInfo &viewInfo, const WaveChannel &wc, bool up)
Defines a selected portion of a project.
double t1() const
double t0() const
static const int UndefinedFrequency
void Grow(size_t len_, SpectrogramSettings &settings, double samplesPerPixel, double start)
void Populate(const SpectrogramSettings &settings, const WaveChannelInterval &clip, int copyBegin, int copyEnd, size_t numPixels, double pixelsPerSecond)
std::vector< float > freq
Definition: SpectrumCache.h:68
std::vector< sampleCount > where
Definition: SpectrumCache.h:69
std::vector< HopsAndBinsMap > dataHistory
Definition: SpectrumView.h:44
static bool ProcessTracks(AudacityProject &project)
void SetBounds(float min, float max)
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.
static SpectrogramSettings & Get(const WaveTrack &track)
Used for finding the peaks, for snapping to peaks.
SpectralDataSaver(SpectrumView &view)
void Init(AudacityProject &project, bool clearAll) override
~SpectrumView() override
static void ForAll(AudacityProject &project, std::function< void(SpectrumView &view)> fn)
void DoSetMinimized(bool minimized) override
unsigned CaptureKey(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project) override
bool IsSpectral() const override
void DoDraw(TrackPanelDrawingContext &context, const WaveChannel &channel, const WaveTrack::Interval *selectedClip, const wxRect &rect)
std::shared_ptr< SpectralData > mpSpectralData
Definition: SpectrumView.h:148
std::weak_ptr< BrushHandle > mBrushHandle
Definition: SpectrumView.h:144
unsigned KeyDown(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project) override
std::shared_ptr< SpectralData > mpBackupSpectralData
Definition: SpectrumView.h:148
const Type & SubViewType() const override
unsigned Char(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project) override
std::shared_ptr< SpectralData > GetSpectralData()
SpectrumView(WaveChannelView &waveChannelView, const SpectrumView &src)=delete
std::shared_ptr< ChannelVRulerControls > DoGetVRulerControls() override
std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &state, const AudacityProject *pProject, int currentTool, bool bMultiTool) override
void CopyToSubView(WaveChannelSubView *destSubView) const override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
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:78
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
Holds a msgid for the translation catalog; may also bind format arguments.
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
WaveTrack & GetTrack()
Definition: WaveTrack.h:840
IteratorRange< IntervalIterator< WaveClipChannel > > Intervals()
Definition: WaveTrack.cpp:745
std::shared_ptr< WaveChannel > FindWaveChannel()
static void DrawBoldBoundaries(TrackPanelDrawingContext &context, const WaveChannel &channel, const wxRect &rect)
std::pair< bool, std::vector< UIHandlePtr > > DoDetailedHitTest(const TrackPanelMouseState &state, const AudacityProject *pProject, int currentTool, bool bMultiTool, const std::shared_ptr< WaveChannel > &wt)
std::weak_ptr< WaveChannelView > GetWaveChannelView() const
static bool ClipDetailsVisible(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
static WaveChannelView & GetFirst(WaveTrack &wt)
Get the view of the first channel.
std::vector< WaveChannelSubView::Type > GetDisplays() const
sampleCount GetVisibleSampleCount() const override
Definition: WaveClip.cpp:188
size_t GetChannelIndex() const
Definition: WaveClip.h:99
int GetRate() const override
Definition: WaveClip.cpp:193
double GetPlayStartTime() const override
Definition: WaveClip.cpp:198
double GetStretchRatio() const override
Definition: WaveClip.cpp:218
sampleCount TimeToSamples(double time) const override
Definition: WaveClip.cpp:213
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
@ HIDDEN
Definition: ZoomInfo.h:156
virtual bool Read(const wxString &key, bool *value) const =0
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
#define lrintf(flt)
Definition: float_cast.h:170
constexpr auto Command
Definition: MenuRegistry.h:456
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175
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 DrawBackgroundWithSelection(TrackPanelDrawingContext &context, const wxRect &rect, const Channel &channel, const wxBrush &selBrush, const wxBrush &unselBrush, bool useSelection=true)
Definition: TrackArt.cpp:651
void DoNextPeakFrequency(AudacityProject &project, bool up)
static CommandHandlerObject & findCommandHandler(AudacityProject &project)
PopupMenuTable::AttachedItem sAttachment
AColor::ColorGradientChoice ChooseColorSet(float bin0, float bin1, float selBinLo, float selBinCenter, float selBinHi, int dashCount, bool isSpectral)
static float findValue(const float *spectrum, float bin0, float bin1, unsigned nBins, bool autocorrelation, int gain, int range)
std::pair< sampleCount, sampleCount > GetSelectedSampleIndices(const SelectedRegion &selectedRegion, const WaveChannelInterval &clip, bool trackIsSelected)
void DrawClipSpectrum(TrackPanelDrawingContext &context, const WaveChannel &channel, const WaveChannelInterval &clip, const wxRect &rect, const std::shared_ptr< SpectralData > &mpSpectralData, bool selected)
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
__finl float_x4 __vecc sqrt(const float_x4 &a)
A convenient default parameter for class template Site.
Definition: ClientData.h:29
static wxRect GetClipRect(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)
bool GetSpectrogram(const WaveChannelInterval &clip, const float *&spectrogram, SpectrogramSettings &spectrogramSettings, const sampleCount *&where, size_t numPixels, double t0, double pixelsPerSecond)
static WaveClipSpectrumCache & Get(const WaveChannelInterval &clip)
WaveTrack & FindWaveTrack() const
void OnNextLowerPeakFrequency(const CommandContext &context)
void OnToggleSpectralSelection(const CommandContext &context)
void OnNextHigherPeakFrequency(const CommandContext &context)
void InitUserData(void *pUserData) override
Called before the menu items are appended.