NoteLayer.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_NOTE_LAYER_H
17 #define SV_NOTE_LAYER_H
18 
19 #include "SingleColourLayer.h"
20 #include "VerticalScaleLayer.h"
21 
22 #include "data/model/NoteModel.h"
23 
24 #include <QObject>
25 #include <QColor>
26 
27 class View;
28 class QPainter;
29 
42  public VerticalScaleLayer
43 {
44  Q_OBJECT
45 
46 public:
47  NoteLayer();
48 
49  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
50 
51  int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
52  void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
53 
54  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
55 
56  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
57  int &resolution,
58  SnapType snap, int ycoord) const override;
59 
60  void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
61  void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
62  void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
63 
64  void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
65  void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
66  void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
67 
68  void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
69  void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
70  void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
71 
72  bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
73 
74  void moveSelection(Selection s, sv_frame_t newStartFrame) override;
75  void resizeSelection(Selection s, Selection newSize) override;
76  void deleteSelection(Selection s) override;
77 
78  void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
79  bool paste(LayerGeometryProvider *v, const Clipboard &from,
80  sv_frame_t frameOffset, bool interactive) override;
81 
82  ModelId getModel() const override { return m_model; }
83  void setModel(ModelId model); // a NoteModel
84 
85  PropertyList getProperties() const override;
86  QString getPropertyLabel(const PropertyName &) const override;
87  PropertyType getPropertyType(const PropertyName &) const override;
88  QString getPropertyGroupName(const PropertyName &) const override;
89  int getPropertyRangeAndValue(const PropertyName &,
90  int *min, int *max, int *deflt) const override;
91  QString getPropertyValueLabel(const PropertyName &,
92  int value) const override;
93  void setProperty(const PropertyName &, int value) override;
94 
100  };
101 
102  void setVerticalScale(VerticalScale scale);
104 
105  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
106 
107  bool isLayerEditable() const override { return true; }
108 
109  int getCompletion(LayerGeometryProvider *) const override;
110 
111  bool getValueExtents(double &min, double &max,
112  bool &log, QString &unit) const override;
113 
114  bool getDisplayExtents(double &min, double &max) const override;
115  bool setDisplayExtents(double min, double max) override;
116 
117  int getVerticalZoomSteps(int &defaultStep) const override;
118  int getCurrentVerticalZoomStep() const override;
119  void setVerticalZoomStep(int) override;
120  RangeMapper *getNewVerticalZoomRangeMapper() const override;
121 
127  void addNoteOn(sv_frame_t frame, int pitch, int velocity);
128 
133  void addNoteOff(sv_frame_t frame, int pitch);
134 
138  void abandonNoteOns();
139 
140  void toXml(QTextStream &stream, QString indent = "",
141  QString extraAttributes = "") const override;
142 
143  void setProperties(const QXmlAttributes &attributes) override;
144 
146  int getYForValue(LayerGeometryProvider *v, double value) const override;
147  double getValueForY(LayerGeometryProvider *v, int y) const override;
148  QString getScaleUnits() const override;
149 
150 protected:
151  void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
152 
153  int getDefaultColourHint(bool dark, bool &impose) override;
154 
155  EventVector getLocalPoints(LayerGeometryProvider *v, int) const;
156 
157  bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
158 
159  double convertValueFromEventValue(float eventValue) const;
160  float convertValueToEventValue(double value) const;
161 
162  double valueOf(const Event &e) const;
163  Event eventWithValue(const Event &e, double value) const;
164 
165  ModelId m_model;
167  bool m_editing;
174  ChangeEventsCommand *m_editingCommand;
177 
178  typedef std::set<Event> NoteSet;
180 
181  mutable double m_scaleMinimum;
182  mutable double m_scaleMaximum;
183 
184  bool shouldAutoAlign() const;
185 
186  void finish(ChangeEventsCommand *command) {
187  Command *c = command->finish();
188  if (c) CommandHistory::getInstance()->addCommand(c, false);
189  }
190 };
191 
192 #endif
193 
VerticalScale getVerticalScale() const
Definition: NoteLayer.h:103
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
Definition: NoteLayer.cpp:482
void moveSelection(Selection s, sv_frame_t newStartFrame) override
Definition: NoteLayer.cpp:1120
int getCurrentVerticalZoomStep() const override
Get the current vertical zoom step.
Definition: NoteLayer.cpp:341
void setProperty(const PropertyName &, int value) override
Definition: NoteLayer.cpp:189
void editDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:1010
int m_dragPointX
Definition: NoteLayer.h:168
void drawStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:873
int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override
Definition: NoteLayer.cpp:816
Event m_originalPoint
Definition: NoteLayer.h:172
std::set< Event > NoteSet
Definition: NoteLayer.h:178
bool m_editIsOpen
Definition: NoteLayer.h:175
float convertValueToEventValue(double value) const
Definition: NoteLayer.cpp:249
int m_dragPointY
Definition: NoteLayer.h:169
ModelId getModel() const override
Return the ID of the model represented in this layer.
Definition: NoteLayer.h:82
double m_scaleMaximum
Definition: NoteLayer.h:182
PropertyType getPropertyType(const PropertyName &) const override
Definition: NoteLayer.cpp:119
bool isLayerScrollable(const LayerGeometryProvider *v) const override
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
Definition: NoteLayer.cpp:215
void addCommand(Command *command)
Add a command to the command history.
double getValueForY(LayerGeometryProvider *v, int y) const override
Definition: NoteLayer.cpp:682
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
Definition: NoteLayer.cpp:69
void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:932
bool getValueExtents(double &min, double &max, bool &log, QString &unit) const override
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
Definition: NoteLayer.cpp:261
VerticalScale m_verticalScale
Definition: NoteLayer.h:176
int getVerticalZoomSteps(int &defaultStep) const override
Get the number of vertical zoom steps available for this layer.
Definition: NoteLayer.cpp:333
void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:959
double valueOf(const Event &e) const
Definition: NoteLayer.cpp:222
ChangeEventsCommand * m_editingCommand
Definition: NoteLayer.h:174
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
NoteSet m_pendingNoteOns
Definition: NoteLayer.h:179
void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override
Paint the given rectangle of this layer onto the given view using the given painter, superimposing it on top of any existing material in that view.
Definition: NoteLayer.cpp:707
Interface for layers in which the Y axis represents (or can sometimes represent, depending on the dis...
int m_dragStartX
Definition: NoteLayer.h:170
bool setDisplayExtents(double min, double max) override
Set the displayed minimum and maximum values for the y axis to the given range, if supported...
Definition: NoteLayer.cpp:309
void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const
Definition: NoteLayer.cpp:612
void addNoteOn(sv_frame_t frame, int pitch, int velocity)
Add a note-on.
Definition: NoteLayer.cpp:1286
PropertyList getProperties() const override
Definition: NoteLayer.cpp:102
QString getPropertyValueLabel(const PropertyName &, int value) const override
Definition: NoteLayer.cpp:173
Event m_editingPoint
Definition: NoteLayer.h:173
Layer for displaying and editing notes, i.e.
Definition: NoteLayer.h:41
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
Definition: NoteLayer.cpp:142
SnapType
Definition: Layer.h:195
void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:899
QString getScaleUnits() const override
Definition: NoteLayer.cpp:136
bool isLayerEditable() const override
This should return true if the layer can be edited by the user.
Definition: NoteLayer.h:107
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
Definition: NoteLayer.cpp:1347
static CommandHistory * getInstance()
bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive) override
Paste from the given clipboard onto the layer at the given frame offset.
Definition: NoteLayer.cpp:1206
void abandonNoteOns()
Abandon all pending note-on events.
Definition: NoteLayer.cpp:1322
void finish(ChangeEventsCommand *command)
Definition: NoteLayer.h:186
bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const
Definition: NoteLayer.cpp:458
void editEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:1043
Event eventWithValue(const Event &e, double value) const
Definition: NoteLayer.cpp:228
void setVerticalZoomStep(int) override
!! lots of duplication with TimeValueLayer
Definition: NoteLayer.cpp:361
void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override
Definition: NoteLayer.cpp:1192
bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override
Open an editor on the item under the mouse (e.g.
Definition: NoteLayer.cpp:1072
RangeMapper * getNewVerticalZoomRangeMapper() const override
Create and return a range mapper for vertical zoom step values.
Definition: NoteLayer.cpp:411
void addNoteOff(sv_frame_t frame, int pitch)
Add a note-off.
Definition: NoteLayer.cpp:1295
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
double m_scaleMinimum
Definition: NoteLayer.h:181
void editStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:986
bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap, int ycoord) const override
Adjust the given frame to snap to the nearest feature, if possible.
Definition: NoteLayer.cpp:573
int m_dragStartY
Definition: NoteLayer.h:171
EventVector getLocalPoints(LayerGeometryProvider *v, int) const
Definition: NoteLayer.cpp:434
bool shouldAutoAlign() const
Definition: NoteLayer.cpp:700
QString getPropertyLabel(const PropertyName &) const override
Definition: NoteLayer.cpp:111
bool getDisplayExtents(double &min, double &max) const override
Return the minimum and maximum values within the visible area for the y axis of this layer...
Definition: NoteLayer.cpp:281
bool m_editing
Definition: NoteLayer.h:167
ModelId m_model
Definition: NoteLayer.h:165
void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:943
QString getPropertyGroupName(const PropertyName &) const override
Definition: NoteLayer.cpp:127
double convertValueFromEventValue(float eventValue) const
Definition: NoteLayer.cpp:234
int getYForValue(LayerGeometryProvider *v, double value) const override
VerticalScaleLayer methods.
Definition: NoteLayer.cpp:655
void deleteSelection(Selection s) override
Definition: NoteLayer.cpp:1173
void setVerticalScale(VerticalScale scale)
Definition: NoteLayer.cpp:207
void resizeSelection(Selection s, Selection newSize) override
Definition: NoteLayer.cpp:1142
void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override
Definition: NoteLayer.cpp:834
void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: NoteLayer.cpp:964
void setModel(ModelId model)
Definition: NoteLayer.cpp:77
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
Definition: NoteLayer.cpp:1336
bool m_modelUsesHz
Definition: NoteLayer.h:166
int getDefaultColourHint(bool dark, bool &impose) override
Definition: NoteLayer.cpp:1328