Audacity  3.0.3
Public Member Functions | Private Member Functions | Private Attributes | List of all members
NoteTrackVRulerControls Class Referencefinal

#include <NoteTrackVRulerControls.h>

Inheritance diagram for NoteTrackVRulerControls:
[legend]
Collaboration diagram for NoteTrackVRulerControls:
[legend]

Public Member Functions

 NoteTrackVRulerControls (const std::shared_ptr< TrackView > &pTrackView)
 
 ~NoteTrackVRulerControls ()
 
std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject) override
 
unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
- Public Member Functions inherited from TrackVRulerControls
 TrackVRulerControls (const std::shared_ptr< TrackView > &pTrackView)
 
virtual ~TrackVRulerControls ()=0
 
std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject) override
 
- Public Member Functions inherited from CommonTrackPanelCell
 CommonTrackPanelCell ()
 
virtual ~CommonTrackPanelCell ()=0
 
HitTestPreview DefaultPreview (const TrackPanelMouseState &, const AudacityProject *) override
 
std::shared_ptr< TrackFindTrack ()
 
std::shared_ptr< const TrackFindTrack () const
 
virtual std::vector< MenuItemGetMenuItems (const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
 Return a list of items for DoContextMenu() (empties for separators) More...
 
- Public Member Functions inherited from TrackPanelCell
 TrackPanelCell ()=default
 
 TrackPanelCell (const TrackPanelCell &) PROHIBITED
 
TrackPanelCelloperator= (const TrackPanelCell &) PROHIBITED
 
virtual ~TrackPanelCell ()=0
 
virtual std::shared_ptr< TrackPanelCellContextMenuDelegate ()
 
virtual unsigned CaptureKey (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned KeyDown (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned KeyUp (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned Char (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned LoseFocus (AudacityProject *project)
 
- Public Member Functions inherited from TrackPanelNode
 TrackPanelNode ()
 
virtual ~TrackPanelNode ()=0
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 

Private Member Functions

 NoteTrackVRulerControls (const NoteTrackVRulerControls &)=delete
 
NoteTrackVRulerControlsoperator= (const NoteTrackVRulerControls &)=delete
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
void UpdateRuler (const wxRect &rect) override
 

Private Attributes

std::weak_ptr< NoteTrackVZoomHandlemVZoomHandle
 

Additional Inherited Members

- Public Types inherited from CommonTrackPanelCell
using Hook = std::function< unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject) >
 
- Static Public Member Functions inherited from TrackVRulerControls
static TrackVRulerControlsGet (TrackView &)
 
static const TrackVRulerControlsGet (const TrackView &)
 
static void DrawZooming (TrackPanelDrawingContext &context, const wxRect &rect, int zoomStart, int zoomEnd)
 
static wxRect ZoomingArea (const wxRect &rect, const wxRect &panelRect)
 
- Static Public Member Functions inherited from CommonTrackPanelCell
static Hook InstallMouseWheelHook (const Hook &hook)
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 
- Protected Member Functions inherited from TrackVRulerControls
std::shared_ptr< TrackDoFindTrack () override
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
 
TrackGetTrack () const
 
- Protected Member Functions inherited from CommonTrackPanelCell
unsigned DoContextMenu (const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject) override
 
unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
- Protected Attributes inherited from TrackVRulerControls
std::weak_ptr< TrackViewmwTrackView
 

Detailed Description

Definition at line 18 of file NoteTrackVRulerControls.h.

Constructor & Destructor Documentation

◆ NoteTrackVRulerControls() [1/2]

NoteTrackVRulerControls::NoteTrackVRulerControls ( const NoteTrackVRulerControls )
privatedelete

◆ NoteTrackVRulerControls() [2/2]

NoteTrackVRulerControls::NoteTrackVRulerControls ( const std::shared_ptr< TrackView > &  pTrackView)
inlineexplicit

Definition at line 25 of file NoteTrackVRulerControls.h.

26  : TrackVRulerControls( pTrackView ) {}

◆ ~NoteTrackVRulerControls()

NoteTrackVRulerControls::~NoteTrackVRulerControls ( )

Definition at line 32 of file NoteTrackVRulerControls.cpp.

33 {
34 }

Member Function Documentation

◆ Draw()

void NoteTrackVRulerControls::Draw ( TrackPanelDrawingContext context,
const wxRect &  rect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 95 of file NoteTrackVRulerControls.cpp.

98 {
99  TrackVRulerControls::Draw( context, rect_, iPass );
100 
101  // Draw on a later pass like other vertical rulers,
102  // although the bevel is done a little differently
103 
104  if ( iPass == TrackArtist::PassControls ) {
105  // The note track draws a vertical keyboard to label pitches
106  auto track = std::static_pointer_cast<NoteTrack>( FindTrack() );
107  if ( !track )
108  return;
109 
110  auto rect = rect_;
111  --rect.width;
112  --rect.height;
113 
114  bool highlight = false;
115 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
116  highlight = rect.Contains(context.lastState.GetPosition());
117 #endif
118 
119  const auto artist = TrackArtist::Get( context );
120  UpdateRuler(rect);
121 
122  auto dc = &context.dc;
123 
124  dc->SetPen(highlight ? AColor::uglyPen : *wxTRANSPARENT_PEN);
125  dc->SetBrush(*wxWHITE_BRUSH);
126  wxRect bev = rect;
127  bev.x++;
128  bev.width--;
129  dc->DrawRectangle(bev);
130 
131  rect.y += 1;
132  rect.height -= 1;
133 
134  NoteTrackDisplayData data{ track.get(), rect };
135 
136  wxPen hilitePen;
137  hilitePen.SetColour(120, 120, 120);
138  wxBrush blackKeyBrush;
139  blackKeyBrush.SetColour(70, 70, 70);
140 
141  dc->SetBrush(blackKeyBrush);
142 
143  int fontSize = 10;
144 #ifdef __WXMSW__
145  fontSize = 8;
146 #endif
147 
148  wxFont labelFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
149  dc->SetFont(labelFont);
150 
151  int octave = 0;
152  int obottom = data.GetOctaveBottom(octave);
153  int marg = data.GetNoteMargin();
154 
155  while (obottom >= rect.y) {
156  dc->SetPen(*wxBLACK_PEN);
157  for (int white = 0; white < 7; white++) {
158  int pos = data.GetWhitePos(white);
159  if (obottom - pos > rect.y + marg + 1 &&
160  // don't draw too close to margin line -- it's annoying
161  obottom - pos < rect.y + rect.height - marg - 3)
162  AColor::Line(*dc, rect.x, obottom - pos,
163  rect.x + rect.width, obottom - pos);
164  }
165  wxRect br = rect;
166  br.height = data.GetPitchHeight(1);
167  br.x++;
168  br.width = 17;
169  for (int black = 0; black < 5; black++) {
170  br.y = obottom - data.GetBlackPos(black);
171  if (br.y > rect.y + marg - 2 && br.y + br.height < rect.y + rect.height - marg) {
172  dc->SetPen(hilitePen);
173  dc->DrawRectangle(br);
174  dc->SetPen(*wxBLACK_PEN);
175  AColor::Line(*dc,
176  br.x + 1, br.y + br.height - 1,
177  br.x + br.width - 1, br.y + br.height - 1);
178  AColor::Line(*dc,
179  br.x + br.width - 1, br.y + 1,
180  br.x + br.width - 1, br.y + br.height - 1);
181  }
182  }
183 
184  if (octave >= 1 && octave <= 10) {
185  wxString s;
186  // ISO standard: A440 is in the 4th octave, denoted
187  // A4 <- the "4" should be a subscript.
188  s.Printf(wxT("C%d"), octave - 1);
189  wxCoord width, height;
190  dc->GetTextExtent(s, &width, &height);
191  if (obottom - height + 4 > rect.y &&
192  obottom + 4 < rect.y + rect.height) {
193  dc->SetTextForeground(wxColour(60, 60, 255));
194  dc->DrawText(s, rect.x + rect.width - width,
195  obottom - height + 2);
196  }
197  }
198  obottom = data.GetOctaveBottom(++octave);
199  }
200  // draw lines delineating the out-of-bounds margins
201  dc->SetPen(*wxBLACK_PEN);
202  // you would think the -1 offset here should be -2 to match the
203  // adjustment to rect.y (see above), but -1 produces correct output
204  AColor::Line(*dc, rect.x, rect.y + marg - 1, rect.x + rect.width, rect.y + marg - 1);
205  // since the margin gives us the bottom of the line,
206  // the extra -1 gets us to the top
207  AColor::Line(*dc, rect.x, rect.y + rect.height - marg - 1,
208  rect.x + rect.width, rect.y + rect.height - marg - 1);
209 
210  }
211 }

References TrackPanelDrawingContext::dc, TrackVRulerControls::Draw(), CommonTrackPanelCell::FindTrack(), TrackArtist::Get(), TrackPanelDrawingContext::lastState, AColor::Line(), TrackArtist::PassControls, AColor::uglyPen, and UpdateRuler().

Here is the call graph for this function:

◆ HandleWheelRotation()

unsigned NoteTrackVRulerControls::HandleWheelRotation ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Reimplemented from TrackPanelCell.

Definition at line 57 of file NoteTrackVRulerControls.cpp.

59 {
60  using namespace RefreshCode;
61  const wxMouseEvent &event = evt.event;
62 
63  if (!(event.ShiftDown() || event.CmdDown()))
64  return RefreshNone;
65 
66  // Always stop propagation even if the ruler didn't change. The ruler
67  // is a narrow enough target.
68  evt.event.Skip(false);
69 
70  const auto pTrack = FindTrack();
71  if (!pTrack)
72  return RefreshNone;
73 
74  auto steps = evt.steps;
75  const auto nt = static_cast<NoteTrack*>(pTrack.get());
76 
77  if (event.CmdDown() && !event.ShiftDown()) {
78  if (steps > 0)
79  nt->ZoomIn(evt.rect, evt.event.m_y);
80  else
81  nt->ZoomOut(evt.rect, evt.event.m_y);
82  } else if (!event.CmdDown() && event.ShiftDown()) {
83  // Scroll some fixed number of notes, independent of zoom level or track height:
84  static const int movement = 6; // 6 semitones is half an octave
85  nt->ShiftNoteRange((int) (steps * movement));
86  } else {
87  return RefreshNone;
88  }
89 
90  ProjectHistory::Get( *pProject ).ModifyState(false);
91 
92  return RefreshCell | UpdateVRuler;
93 }

References TrackPanelMouseEvent::event, CommonTrackPanelCell::FindTrack(), ProjectHistory::Get(), ProjectHistory::ModifyState(), TrackPanelMouseEvent::rect, RefreshCode::RefreshCell, RefreshCode::RefreshNone, TrackPanelMouseEvent::steps, RefreshCode::UpdateVRuler, and NoteTrack::ZoomIn().

Here is the call graph for this function:

◆ HitTest()

std::vector< UIHandlePtr > NoteTrackVRulerControls::HitTest ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual

Implements TrackPanelCell.

Definition at line 36 of file NoteTrackVRulerControls.cpp.

39 {
40  std::vector<UIHandlePtr> results;
41  UIHandlePtr result;
42 
43  if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
44  auto track = std::static_pointer_cast<NoteTrack>(FindTrack());
46  mVZoomHandle, st.state, track, st.rect);
47  if (result)
48  results.push_back(result);
49  }
50 
51  auto more = TrackVRulerControls::HitTest(st, pProject);
52  std::copy(more.begin(), more.end(), std::back_inserter(results));
53 
54  return results;
55 }

References CommonTrackPanelCell::FindTrack(), TrackVRulerControls::HitTest(), NoteTrackVZoomHandle::HitTest(), kGuard, mVZoomHandle, TrackPanelMouseState::rect, and TrackPanelMouseState::state.

Here is the call graph for this function:

◆ operator=()

NoteTrackVRulerControls& NoteTrackVRulerControls::operator= ( const NoteTrackVRulerControls )
privatedelete

◆ UpdateRuler()

void NoteTrackVRulerControls::UpdateRuler ( const wxRect &  rect)
overrideprivatevirtual

Implements TrackVRulerControls.

Definition at line 214 of file NoteTrackVRulerControls.cpp.

215 {
216  // The note track isn't drawing a ruler at all!
217  // But it needs to!
218 
219  const auto nt = std::static_pointer_cast< NoteTrack >( FindTrack() );
220  if (!nt)
221  return;
222 
223  static Ruler ruler;
224  const auto vruler = &ruler;
225 
226  vruler->SetBounds(rect.x, rect.y, rect.x + 1, rect.y + rect.height-1);
227  vruler->SetOrientation(wxVERTICAL);
228 
229  vruler->GetMaxSize( &nt->vrulerSize.x, &nt->vrulerSize.y );
230 }

References CommonTrackPanelCell::FindTrack(), anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler(), and Ruler::SetBounds().

Referenced by Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mVZoomHandle

std::weak_ptr<NoteTrackVZoomHandle> NoteTrackVRulerControls::mVZoomHandle
private

Definition at line 46 of file NoteTrackVRulerControls.h.

Referenced by HitTest().


The documentation for this class was generated from the following files:
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
NoteTrackVZoomHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< NoteTrackVZoomHandle > &holder, const wxMouseState &state, const std::shared_ptr< NoteTrack > &pTrack, const wxRect &rect)
Definition: NoteTrackVZoomHandle.cpp:91
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
TrackVRulerControls::TrackVRulerControls
TrackVRulerControls(const std::shared_ptr< TrackView > &pTrackView)
Definition: TrackVRulerControls.cpp:26
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:109
NoteTrackVRulerControls::mVZoomHandle
std::weak_ptr< NoteTrackVZoomHandle > mVZoomHandle
Definition: NoteTrackVRulerControls.h:46
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler
Ruler & ruler()
Definition: TimeTrackVRulerControls.cpp:34
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:79
NoteTrackDisplayData
Data used to display a note track.
Definition: NoteTrack.h:231
NoteTrackVRulerControls::UpdateRuler
void UpdateRuler(const wxRect &rect) override
Definition: NoteTrackVRulerControls.cpp:214
Ruler
Used to display a Ruler.
Definition: Ruler.h:26
TrackPanelDrawingContext::lastState
wxMouseState lastState
Definition: TrackPanelDrawingContext.h:25
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
TrackArtist::PassControls
@ PassControls
Definition: TrackArtist.h:84
RefreshCode::UpdateVRuler
@ UpdateVRuler
Definition: RefreshCode.h:30
AColor::uglyPen
static wxPen uglyPen
Definition: AColor.h:130
RefreshCode::RefreshCell
@ RefreshCell
Definition: RefreshCode.h:24
kGuard
const int kGuard
Definition: TrackVRulerControls.h:20
TrackVRulerControls::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
Definition: TrackVRulerControls.cpp:55
TrackVRulerControls::Draw
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Definition: TrackVRulerControls.cpp:97
NoteTrack::ZoomIn
void ZoomIn(const wxRect &rect, int y)
Zooms in a constant factor (subject to zoom limits)
Definition: NoteTrack.h:140
Ruler::SetBounds
void SetBounds(int left, int top, int right, int bottom)
Definition: Ruler.cpp:332
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
NoteTrack
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:67