comparison layer/NoteLayer.h @ 1551:e79731086b0f

Fixes to NoteLayer, particularly to calculation of vertical scale when model unit is not Hz. To avoid inconsistency we now behave as if the unit is always Hz from the point of view of the external API and display, converting at the point where we obtain values from the events themselves. Also various fixes to editing.
author Chris Cannam
date Thu, 21 Nov 2019 14:02:57 +0000
parents e6362cf5ff1d
children
comparison
equal deleted inserted replaced
1548:bd6af89982d7 1551:e79731086b0f
25 #include <QColor> 25 #include <QColor>
26 26
27 class View; 27 class View;
28 class QPainter; 28 class QPainter;
29 29
30 /**
31 * Layer for displaying and editing notes, i.e. discrete events with
32 * start time, duration, value that represents pitch, and optionally a
33 * level that represents velocity.
34 *
35 * For the purposes of public API, integration with other classes, and
36 * display alignment, the y-coordinate (value) of the layer always has
37 * a unit of Hz. The model itself may have another unit, such as MIDI
38 * pitch, but the layer always converts to and from Hz behind the
39 * scenes.
40 */
30 class NoteLayer : public SingleColourLayer, 41 class NoteLayer : public SingleColourLayer,
31 public VerticalScaleLayer 42 public VerticalScaleLayer
32 { 43 {
33 Q_OBJECT 44 Q_OBJECT
34 45
63 void moveSelection(Selection s, sv_frame_t newStartFrame) override; 74 void moveSelection(Selection s, sv_frame_t newStartFrame) override;
64 void resizeSelection(Selection s, Selection newSize) override; 75 void resizeSelection(Selection s, Selection newSize) override;
65 void deleteSelection(Selection s) override; 76 void deleteSelection(Selection s) override;
66 77
67 void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override; 78 void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
68 bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, 79 bool paste(LayerGeometryProvider *v, const Clipboard &from,
69 bool interactive) override; 80 sv_frame_t frameOffset, bool interactive) override;
70 81
71 ModelId getModel() const override { return m_model; } 82 ModelId getModel() const override { return m_model; }
72 void setModel(ModelId model); // a NoteModel 83 void setModel(ModelId model); // a NoteModel
73 84
74 PropertyList getProperties() const override; 85 PropertyList getProperties() const override;
75 QString getPropertyLabel(const PropertyName &) const override; 86 QString getPropertyLabel(const PropertyName &) const override;
76 PropertyType getPropertyType(const PropertyName &) const override; 87 PropertyType getPropertyType(const PropertyName &) const override;
77 QString getPropertyGroupName(const PropertyName &) const override; 88 QString getPropertyGroupName(const PropertyName &) const override;
78 int getPropertyRangeAndValue(const PropertyName &, 89 int getPropertyRangeAndValue(const PropertyName &,
79 int *min, int *max, int *deflt) const override; 90 int *min, int *max, int *deflt) const override;
80 QString getPropertyValueLabel(const PropertyName &, 91 QString getPropertyValueLabel(const PropertyName &,
81 int value) const override; 92 int value) const override;
82 void setProperty(const PropertyName &, int value) override; 93 void setProperty(const PropertyName &, int value) override;
83 94
84 enum VerticalScale { 95 enum VerticalScale {
85 AutoAlignScale, 96 AutoAlignScale,
86 LinearScale, 97 LinearScale,
96 bool isLayerEditable() const override { return true; } 107 bool isLayerEditable() const override { return true; }
97 108
98 int getCompletion(LayerGeometryProvider *) const override; 109 int getCompletion(LayerGeometryProvider *) const override;
99 110
100 bool getValueExtents(double &min, double &max, 111 bool getValueExtents(double &min, double &max,
101 bool &log, QString &unit) const override; 112 bool &log, QString &unit) const override;
102 113
103 bool getDisplayExtents(double &min, double &max) const override; 114 bool getDisplayExtents(double &min, double &max) const override;
104 bool setDisplayExtents(double min, double max) override; 115 bool setDisplayExtents(double min, double max) override;
105 116
106 int getVerticalZoomSteps(int &defaultStep) const override; 117 int getVerticalZoomSteps(int &defaultStep) const override;
136 double getValueForY(LayerGeometryProvider *v, int y) const override; 147 double getValueForY(LayerGeometryProvider *v, int y) const override;
137 QString getScaleUnits() const override; 148 QString getScaleUnits() const override;
138 149
139 protected: 150 protected:
140 void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const; 151 void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
141 bool shouldConvertMIDIToHz() const;
142 152
143 int getDefaultColourHint(bool dark, bool &impose) override; 153 int getDefaultColourHint(bool dark, bool &impose) override;
144 154
145 EventVector getLocalPoints(LayerGeometryProvider *v, int) const; 155 EventVector getLocalPoints(LayerGeometryProvider *v, int) const;
146 156
147 bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const; 157 bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
148 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
149 ModelId m_model; 165 ModelId m_model;
166 bool m_modelUsesHz;
150 bool m_editing; 167 bool m_editing;
151 int m_dragPointX; 168 int m_dragPointX;
152 int m_dragPointY; 169 int m_dragPointY;
153 int m_dragStartX; 170 int m_dragStartX;
154 int m_dragStartY; 171 int m_dragStartY;