| 1 |
/********************************************************************** |
| 2 |
|
| 3 |
Audacity: A Digital Audio Editor |
| 4 |
|
| 5 |
NoteTrackSliderHandles.cpp |
| 6 |
|
| 7 |
Paul Licameli split from TrackPanel.cpp |
| 8 |
|
| 9 |
**********************************************************************/ |
| 10 |
#include "NoteTrackSliderHandles.h" |
| 11 |
|
| 12 |
#include "NoteTrackControls.h" |
| 13 |
#include "ProjectHistory.h" |
| 14 |
#include "../../../../RefreshCode.h" |
| 15 |
#include "../../../ui/CommonTrackInfo.h" |
| 16 |
#include "../../../../TrackPanel.h" |
| 17 |
#include "UndoManager.h" |
| 18 |
#include "NoteTrack.h" |
| 19 |
#include "ViewInfo.h" |
| 20 |
|
| 21 |
VelocitySliderHandle::VelocitySliderHandle |
| 22 |
( SliderFn sliderFn, const wxRect &rect, |
| 23 |
const std::shared_ptr<Track> &pTrack ) |
| 24 |
: SliderHandle{ sliderFn, rect, pTrack } |
| 25 |
{} |
| 26 |
|
| 27 |
VelocitySliderHandle::~VelocitySliderHandle() |
| 28 |
{ |
| 29 |
} |
| 30 |
|
| 31 |
std::shared_ptr<NoteTrack> VelocitySliderHandle::GetNoteTrack() const |
| 32 |
{ |
| 33 |
return std::static_pointer_cast<NoteTrack>(mpTrack.lock()); |
| 34 |
} |
| 35 |
|
| 36 |
float VelocitySliderHandle::GetValue() |
| 37 |
{ |
| 38 |
if (GetNoteTrack()) |
| 39 |
return GetNoteTrack()->GetVelocity(); |
| 40 |
else |
| 41 |
return 0; |
| 42 |
} |
| 43 |
|
| 44 |
UIHandle::Result VelocitySliderHandle::SetValue |
| 45 |
(AudacityProject *pProject, float newValue) |
| 46 |
{ |
| 47 |
(void)pProject;//Compiler food |
| 48 |
auto pTrack = GetNoteTrack(); |
| 49 |
|
| 50 |
if (pTrack) { |
| 51 |
pTrack->SetVelocity(newValue); |
| 52 |
} |
| 53 |
|
| 54 |
return RefreshCode::RefreshCell; |
| 55 |
} |
| 56 |
|
| 57 |
UIHandle::Result VelocitySliderHandle::CommitChanges |
| 58 |
(const wxMouseEvent &, AudacityProject *pProject) |
| 59 |
{ |
| 60 |
ProjectHistory::Get( *pProject ) |
| 61 |
.PushState(XO("Moved velocity slider"), XO("Velocity"), |
| 62 |
UndoPush::CONSOLIDATE); |
| 63 |
return RefreshCode::RefreshCell; |
| 64 |
} |
| 65 |
|
| 66 |
TranslatableString VelocitySliderHandle::Tip( |
| 67 |
const wxMouseState &, AudacityProject &project) const |
| 68 |
{ |
| 69 |
TranslatableString val; |
| 70 |
float value = 0; |
| 71 |
|
| 72 |
auto pTrack = GetNoteTrack(); |
| 73 |
if (pTrack) |
| 74 |
value = pTrack->GetVelocity(); |
| 75 |
|
| 76 |
// LLL: Can't access the slider since Tip() is a const method and getting the slider |
| 77 |
// is not, so duplicate what LWSlider does. |
| 78 |
|
| 79 |
if (value > 0.0f) |
| 80 |
// Signed |
| 81 |
val = Verbatim("%+d").Format((int)value); |
| 82 |
else |
| 83 |
// Zero, or signed negative |
| 84 |
val = Verbatim("%d").Format((int)value); |
| 85 |
|
| 86 |
/* i18n-hint: An item name followed by a value, with appropriate separating punctuation */ |
| 87 |
return XO("%s: %s").Format(XO("Velocity"), val); |
| 88 |
} |
| 89 |
|
| 90 |
UIHandlePtr VelocitySliderHandle::HitTest |
| 91 |
(std::weak_ptr<VelocitySliderHandle> &holder, |
| 92 |
const wxMouseState &state, const wxRect &rect, |
| 93 |
const std::shared_ptr<Track> &pTrack) |
| 94 |
{ |
| 95 |
if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT)) |
| 96 |
return {}; |
| 97 |
|
| 98 |
wxRect sliderRect; |
| 99 |
NoteTrackControls::GetVelocityRect(rect, sliderRect); |
| 100 |
if (CommonTrackInfo::HideTopItem( rect, sliderRect, kTrackInfoSliderAllowance)) |
| 101 |
return {}; |
| 102 |
if (sliderRect.Contains(state.m_x, state.m_y)) { |
| 103 |
auto sliderFn = |
| 104 |
[]( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) { |
| 105 |
return NoteTrackControls::VelocitySlider |
| 106 |
(sliderRect, static_cast<NoteTrack*>( pTrack ), true, |
| 107 |
&TrackPanel::Get( *pProject )); |
| 108 |
}; |
| 109 |
auto result = std::make_shared<VelocitySliderHandle>( |
| 110 |
sliderFn, sliderRect, pTrack ); |
| 111 |
result = AssignUIHandlePtr(holder, result); |
| 112 |
|
| 113 |
return result; |
| 114 |
} |
| 115 |
else |
| 116 |
return {}; |
| 117 |
} |