| 1 |
/********************************************************************** |
| 2 |
|
| 3 |
Audacity: A Digital Audio Editor |
| 4 |
|
| 5 |
StretchHandle.h |
| 6 |
|
| 7 |
Paul Licameli split from TrackPanel.cpp |
| 8 |
|
| 9 |
**********************************************************************/ |
| 10 |
|
| 11 |
#ifndef __AUDACITY_STRETCH_HANDLE__ |
| 12 |
#define __AUDACITY_STRETCH_HANDLE__ |
| 13 |
|
| 14 |
#include "../../../../UIHandle.h" |
| 15 |
|
| 16 |
class Alg_seq; |
| 17 |
class Channel; |
| 18 |
class NoteTrack; |
| 19 |
class Track; |
| 20 |
class ViewInfo; |
| 21 |
|
| 22 |
class StretchHandle : public UIHandle |
| 23 |
{ |
| 24 |
public: |
| 25 |
enum StretchEnum { |
| 26 |
stretchNone = 0, // false value! |
| 27 |
stretchLeft, |
| 28 |
stretchCenter, |
| 29 |
stretchRight |
| 30 |
}; |
| 31 |
|
| 32 |
// Stretching applies to a selected region after quantizing the |
| 33 |
// region to beat boundaries (subbeat stretching is not supported, |
| 34 |
// but maybe it should be enabled with shift or ctrl or something) |
| 35 |
// Stretching can drag the left boundary (the right stays fixed), |
| 36 |
// the right boundary (the left stays fixed), or the center (splits |
| 37 |
// the selection into two parts: when left part grows, the right |
| 38 |
// part shrinks, keeping the leftmost and rightmost boundaries |
| 39 |
// fixed. |
| 40 |
struct StretchState { |
| 41 |
StretchEnum mMode { stretchCenter }; // remembers what to drag |
| 42 |
|
| 43 |
using QuantizedTimeAndBeat = std::pair< double, double >; |
| 44 |
|
| 45 |
QuantizedTimeAndBeat mBeatCenter { 0, 0 }; |
| 46 |
QuantizedTimeAndBeat mBeat0 { 0, 0 }; |
| 47 |
QuantizedTimeAndBeat mBeat1 { 0, 0 }; |
| 48 |
double mLeftBeats {}; // how many beats from left to cursor |
| 49 |
double mRightBeats {}; // how many beats from cursor to right |
| 50 |
|
| 51 |
double mOrigSel0Quantized { -1 }, mOrigSel1Quantized { -1 }; |
| 52 |
}; |
| 53 |
|
| 54 |
private: |
| 55 |
StretchHandle(const StretchHandle&); |
| 56 |
static HitTestPreview HitPreview(StretchEnum stretchMode, bool unsafe); |
| 57 |
|
| 58 |
public: |
| 59 |
explicit StretchHandle |
| 60 |
( const std::shared_ptr<NoteTrack> &pTrack, |
| 61 |
const StretchState &stretchState ); |
| 62 |
|
| 63 |
StretchHandle &operator=(const StretchHandle&) = default; |
| 64 |
|
| 65 |
static UIHandlePtr HitTest |
| 66 |
(std::weak_ptr<StretchHandle> &holder, |
| 67 |
const TrackPanelMouseState &state, const AudacityProject *pProject, |
| 68 |
const std::shared_ptr<NoteTrack> &pTrack ); |
| 69 |
|
| 70 |
virtual ~StretchHandle(); |
| 71 |
|
| 72 |
std::shared_ptr<const Track> FindTrack() const override; |
| 73 |
|
| 74 |
Result Click |
| 75 |
(const TrackPanelMouseEvent &event, AudacityProject *pProject) override; |
| 76 |
|
| 77 |
Result Drag |
| 78 |
(const TrackPanelMouseEvent &event, AudacityProject *pProject) override; |
| 79 |
|
| 80 |
HitTestPreview Preview |
| 81 |
(const TrackPanelMouseState &state, AudacityProject *pProject) |
| 82 |
override; |
| 83 |
|
| 84 |
Result Release |
| 85 |
(const TrackPanelMouseEvent &event, AudacityProject *pProject, |
| 86 |
wxWindow *pParent) override; |
| 87 |
|
| 88 |
Result Cancel(AudacityProject *pProject) override; |
| 89 |
|
| 90 |
bool StopsOnKeystroke() override { return true; } |
| 91 |
|
| 92 |
private: |
| 93 |
static double GetT0(const Track &track, const ViewInfo &viewInfo); |
| 94 |
static double GetT1(const Track &track, const ViewInfo &viewInfo); |
| 95 |
|
| 96 |
void Stretch(AudacityProject *pProject, int mouseXCoordinate, |
| 97 |
int trackLeftEdge, Channel *pChannel); |
| 98 |
|
| 99 |
std::shared_ptr<NoteTrack> mpTrack{}; |
| 100 |
int mLeftEdge{ -1 }; |
| 101 |
|
| 102 |
StretchState mStretchState{}; |
| 103 |
}; |
| 104 |
|
| 105 |
#endif |