Audacity 3.2.0
NoteTrackVRulerControls.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5NoteTrackVRulerControls.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
12
13#ifdef USE_MIDI
15
17
18#include "../../../ui/ChannelView.h"
19#include "../../../../HitTestResult.h"
20#include "../../../../NoteTrack.h"
21#include "ProjectHistory.h"
22#include "../../../../RefreshCode.h"
23#include "../../../../TrackArtist.h"
24#include "../../../../TrackPanelMouseEvent.h"
25
26#include "AColor.h"
27#include "../../../../TrackPanelDrawingContext.h"
28#include "../../../../widgets/LinearUpdater.h"
29#include "../../../../widgets/RealFormat.h"
30#include "../../../../widgets/Ruler.h"
31
32#include <wx/dc.h>
33#include <wx/event.h>
34
37{
38}
39
40std::vector<UIHandlePtr> NoteTrackVRulerControls::HitTest
41(const TrackPanelMouseState &st,
42 const AudacityProject *pProject)
43{
44 std::vector<UIHandlePtr> results;
45 UIHandlePtr result;
46
47 if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
48 auto track = std::static_pointer_cast<NoteTrack>(FindTrack());
50 mVZoomHandle, st.state, track, st.rect);
51 if (result)
52 results.push_back(result);
53 }
54
55 auto more = ChannelVRulerControls::HitTest(st, pProject);
56 std::copy(more.begin(), more.end(), std::back_inserter(results));
57
58 return results;
59}
60
62(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
63{
64 using namespace RefreshCode;
65 const wxMouseEvent &event = evt.event;
66
67 if (!(event.ShiftDown() || event.CmdDown()))
68 return RefreshNone;
69
70 // Always stop propagation even if the ruler didn't change. The ruler
71 // is a narrow enough target.
72 evt.event.Skip(false);
73
74 const auto pTrack = FindTrack();
75 if (!pTrack)
76 return RefreshNone;
77
78 auto steps = evt.steps;
79 const auto nt = static_cast<NoteTrack*>(pTrack.get());
80
81 if (event.CmdDown() && !event.ShiftDown()) {
82 if (steps > 0)
83 nt->ZoomIn(evt.rect, evt.event.m_y);
84 else
85 nt->ZoomOut(evt.rect, evt.event.m_y);
86 } else if (!event.CmdDown() && event.ShiftDown()) {
87 // Scroll some fixed number of notes, independent of zoom level or track height:
88 static const int movement = 6; // 6 semitones is half an octave
89 nt->ShiftNoteRange((int) (steps * movement));
90 } else {
91 return RefreshNone;
92 }
93
94 ProjectHistory::Get( *pProject ).ModifyState(false);
95
97}
98
101 const wxRect &rect_, unsigned iPass )
102{
103 ChannelVRulerControls::Draw(context, rect_, iPass);
104
105 // Draw on a later pass like other vertical rulers,
106 // although the bevel is done a little differently
107
108 if ( iPass == TrackArtist::PassControls ) {
109 // The note track draws a vertical keyboard to label pitches
110 auto track = std::static_pointer_cast<NoteTrack>( FindTrack() );
111 if ( !track )
112 return;
113
114 auto rect = rect_;
115 --rect.width;
116 --rect.height;
117
118 bool highlight = false;
119#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
120 highlight = rect.Contains(context.lastState.GetPosition());
121#endif
122
123 const auto artist = TrackArtist::Get( context );
124 UpdateRuler(rect);
125
126 auto dc = &context.dc;
127
128 dc->SetPen(highlight ? AColor::uglyPen : *wxTRANSPARENT_PEN);
129 dc->SetBrush(*wxWHITE_BRUSH);
130 wxRect bev = rect;
131 bev.x++;
132 bev.width--;
133 dc->DrawRectangle(bev);
134
135 rect.y += 1;
136 rect.height -= 1;
137
138 NoteTrackDisplayData data{ track.get(), rect };
139
140 wxPen hilitePen;
141 hilitePen.SetColour(120, 120, 120);
142 wxBrush blackKeyBrush;
143 blackKeyBrush.SetColour(70, 70, 70);
144
145 dc->SetBrush(blackKeyBrush);
146
147 int fontSize = 10;
148#ifdef __WXMSW__
149 fontSize = 8;
150#endif
151
152 wxFont labelFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
153 dc->SetFont(labelFont);
154
155 int octave = 0;
156 int obottom = data.GetOctaveBottom(octave);
157 int marg = data.GetNoteMargin();
158
159 while (obottom >= rect.y) {
160 dc->SetPen(*wxBLACK_PEN);
161 for (int white = 0; white < 7; white++) {
162 int pos = data.GetWhitePos(white);
163 if (obottom - pos > rect.y + marg + 1 &&
164 // don't draw too close to margin line -- it's annoying
165 obottom - pos < rect.y + rect.height - marg - 3)
166 AColor::Line(*dc, rect.x, obottom - pos,
167 rect.x + rect.width, obottom - pos);
168 }
169 wxRect br = rect;
170 br.height = data.GetPitchHeight(1);
171 br.x++;
172 br.width = 17;
173 for (int black = 0; black < 5; black++) {
174 br.y = obottom - data.GetBlackPos(black);
175 if (br.y > rect.y + marg - 2 && br.y + br.height < rect.y + rect.height - marg) {
176 dc->SetPen(hilitePen);
177 dc->DrawRectangle(br);
178 dc->SetPen(*wxBLACK_PEN);
179 AColor::Line(*dc,
180 br.x + 1, br.y + br.height - 1,
181 br.x + br.width - 1, br.y + br.height - 1);
182 AColor::Line(*dc,
183 br.x + br.width - 1, br.y + 1,
184 br.x + br.width - 1, br.y + br.height - 1);
185 }
186 }
187
188 if (octave >= 1 && octave <= 10) {
189 wxString s;
190 // ISO standard: A440 is in the 4th octave, denoted
191 // A4 <- the "4" should be a subscript.
192 s.Printf(wxT("C%d"), octave - 1);
193 wxCoord width, height;
194 dc->GetTextExtent(s, &width, &height);
195 if (obottom - height + 4 > rect.y &&
196 obottom + 4 < rect.y + rect.height) {
197 dc->SetTextForeground(wxColour(60, 60, 255));
198 dc->DrawText(s, rect.x + rect.width - width,
199 obottom - height + 2);
200 }
201 }
202 obottom = data.GetOctaveBottom(++octave);
203 }
204 // draw lines delineating the out-of-bounds margins
205 dc->SetPen(*wxBLACK_PEN);
206 // you would think the -1 offset here should be -2 to match the
207 // adjustment to rect.y (see above), but -1 produces correct output
208 AColor::Line(*dc, rect.x, rect.y + marg - 1, rect.x + rect.width, rect.y + marg - 1);
209 // since the margin gives us the bottom of the line,
210 // the extra -1 gets us to the top
211 AColor::Line(*dc, rect.x, rect.y + rect.height - marg - 1,
212 rect.x + rect.width, rect.y + rect.height - marg - 1);
213
214 }
215}
216
217
219{
220 // The note track isn't drawing a ruler at all!
221 // But it needs to!
222
223 const auto nt = std::static_pointer_cast<NoteTrack>(FindTrack());
224 if (!nt)
225 return;
226
227 static Ruler ruler{
229 const auto vruler = &ruler;
230
231 vruler->SetBounds(rect.x, rect.y, rect.x + 1, rect.y + rect.height - 1);
232 vruler->SetOrientation(wxVERTICAL);
233
234 auto &size = ChannelView::Get(*nt).vrulerSize;
235 vruler->GetMaxSize(&size.first, &size.second);
236}
237#endif
wxT("CloseDown"))
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
const int kGuard
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
static wxPen uglyPen
Definition: AColor.h:141
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
static ChannelView & Get(Channel &channel)
std::pair< int, int > vrulerSize
Definition: ChannelView.h:128
std::shared_ptr< Track > FindTrack()
static const LinearUpdater & Instance()
Data used to display a note track.
Definition: NoteTrack.h:264
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:65
void ZoomIn(const wxRect &rect, int y)
Zooms in a constant factor (subject to zoom limits)
Definition: NoteTrack.h:144
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
std::weak_ptr< NoteTrackVZoomHandle > mVZoomHandle
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
void UpdateRuler(const wxRect &rect) override
unsigned HandleWheelRotation(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
static UIHandlePtr HitTest(std::weak_ptr< NoteTrackVZoomHandle > &holder, const wxMouseState &state, const std::shared_ptr< NoteTrack > &pTrack, const wxRect &rect)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static const RealFormat & LinearInstance()
Definition: RealFormat.cpp:14
Used to display a Ruler.
Definition: Ruler.h:34
void SetBounds(int left, int top, int right, int bottom)
Definition: Ruler.cpp:304
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:31