FlexiNoteLayer.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_FLEXINOTE_LAYER_H
17 #define SV_FLEXINOTE_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 class SparseTimeValueModel;
30 
32  public VerticalScaleLayer
33 {
34  Q_OBJECT
35 
36 public:
38 
39  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
40 
41  int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
42  void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
43 
44  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
45 
46  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
47  int &resolution,
48  SnapType snap, int ycoord) const override;
49 
50  void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
51  void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
52  void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
53 
54  void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
55  void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
56  void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
57 
58  void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
59  void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
60  void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
61 
62  void splitStart(LayerGeometryProvider *v, QMouseEvent *) override;
63  void splitEnd(LayerGeometryProvider *v, QMouseEvent *) override;
64 
65  void addNote(LayerGeometryProvider *v, QMouseEvent *e) override;
66 
67  virtual void mouseMoveEvent(LayerGeometryProvider *v, QMouseEvent *);
68 
69  bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
70 
71  void moveSelection(Selection s, sv_frame_t newStartFrame) override;
72  void resizeSelection(Selection s, Selection newSize) override;
73  void deleteSelection(Selection s) override;
74  virtual void deleteSelectionInclusive(Selection s);
75 
76  void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
77  bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
78  bool interactive) override;
79 
80  void splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame);
82  void mergeNotes(LayerGeometryProvider *v, Selection s, bool inclusive);
83 
84  ModelId getModel() const override { return m_model; }
85  void setModel(ModelId model); // a NoteModel please
86 
87  PropertyList getProperties() const override;
88  QString getPropertyLabel(const PropertyName &) const override;
89  PropertyType getPropertyType(const PropertyName &) const override;
90  QString getPropertyGroupName(const PropertyName &) const override;
91  int getPropertyRangeAndValue(const PropertyName &,
92  int *min, int *max, int *deflt) const override;
93  QString getPropertyValueLabel(const PropertyName &,
94  int value) const override;
95  void setProperty(const PropertyName &, int value) override;
96 
102  };
103 
104  //GF: Tonioni: context sensitive note edit actions (denoted clockwise from top).
105  enum EditMode {
110  };
111 
113 
114  void setVerticalScale(VerticalScale scale);
116 
117  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
118 
119  bool isLayerEditable() const override { return true; }
120 
121  int getCompletion(LayerGeometryProvider *) const override;
122 
123  bool getValueExtents(double &min, double &max,
124  bool &log, QString &unit) const override;
125 
126  bool getDisplayExtents(double &min, double &max) const override;
127  bool setDisplayExtents(double min, double max) override;
128 
129  int getVerticalZoomSteps(int &defaultStep) const override;
130  int getCurrentVerticalZoomStep() const override;
131  void setVerticalZoomStep(int) override;
132  RangeMapper *getNewVerticalZoomRangeMapper() const override;
133 
139  void addNoteOn(sv_frame_t frame, int pitch, int velocity);
140 
145  void addNoteOff(sv_frame_t frame, int pitch);
146 
150  void abandonNoteOns();
151 
152  void toXml(QTextStream &stream, QString indent = "",
153  QString extraAttributes = "") const override;
154 
155  void setProperties(const QXmlAttributes &attributes) override;
156 
158 
160  int getYForValue(LayerGeometryProvider *v, double value) const override;
161  double getValueForY(LayerGeometryProvider *v, int y) const override;
162  QString getScaleUnits() const override;
163 
164 signals:
165  void reAnalyseRegion(sv_frame_t, sv_frame_t, float, float);
166  void materialiseReAnalysis();
167 
168 protected:
169  void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
170  bool shouldConvertMIDIToHz() const;
171 
172  int getDefaultColourHint(bool dark, bool &impose) override;
173 
174  EventVector getLocalPoints(LayerGeometryProvider *v, int) const;
175 
176  bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
177  bool getNoteToEdit(LayerGeometryProvider *v, int x, int y, Event &) const;
178  void getRelativeMousePosition(LayerGeometryProvider *v, Event &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const;
180  bool updateNoteValueFromPitchCurve(LayerGeometryProvider *v, Event &note) const;
181  void splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame, QMouseEvent *e);
182 
183  ModelId m_model;
184  bool m_editing;
194  ChangeEventsCommand *m_editingCommand;
197 
198  typedef std::set<Event> NoteSet;
200 
201  mutable double m_scaleMinimum;
202  mutable double m_scaleMaximum;
203 
204  bool shouldAutoAlign() const;
205 
206  void finish(ChangeEventsCommand *command) {
207  Command *c = command->finish();
208  if (c) CommandHistory::getInstance()->addCommand(c, false);
209  }
210 };
211 
212 #endif
213 
void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
void setIntelligentActions(bool on)
void editEnd(LayerGeometryProvider *v, QMouseEvent *) override
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
bool getNoteToEdit(LayerGeometryProvider *v, int x, int y, Event &) const
int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override
int getDefaultColourHint(bool dark, bool &impose) override
void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override
void splitStart(LayerGeometryProvider *v, QMouseEvent *) override
bool setDisplayExtents(double min, double max) override
Set the displayed minimum and maximum values for the y axis to the given range, if supported...
QString getPropertyValueLabel(const PropertyName &, int value) const override
void setVerticalRangeToNoteRange(LayerGeometryProvider *v)
void setProperty(const PropertyName &, int value) override
void setModel(ModelId model)
void moveSelection(Selection s, sv_frame_t newStartFrame) override
void addCommand(Command *command)
Add a command to the command history.
bool shouldConvertMIDIToHz() const
QString getPropertyGroupName(const PropertyName &) const override
void setVerticalScale(VerticalScale scale)
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...
virtual void deleteSelectionInclusive(Selection s)
PropertyList getProperties() const override
void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override
void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override
void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override
void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override
sv_frame_t m_greatestLeftNeighbourFrame
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.
void deleteSelection(Selection s) override
int getVerticalZoomSteps(int &defaultStep) const override
Get the number of vertical zoom steps available for this layer.
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.
Interface for layers in which the Y axis represents (or can sometimes represent, depending on the dis...
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...
bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override
Open an editor on the item under the mouse (e.g.
void splitEnd(LayerGeometryProvider *v, QMouseEvent *) override
void finish(ChangeEventsCommand *command)
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
int getCurrentVerticalZoomStep() const override
Get the current vertical zoom step.
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
ModelId getModel() const override
Return the ID of the model represented in this layer.
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.
void snapSelectedNotesToPitchTrack(LayerGeometryProvider *v, Selection s)
void addNote(LayerGeometryProvider *v, QMouseEvent *e) override
bool shouldAutoAlign() const
SnapType
Definition: Layer.h:195
static CommandHistory * getInstance()
QString getPropertyLabel(const PropertyName &) const override
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.
VerticalScale m_verticalScale
void abandonNoteOns()
Abandon all pending note-on events.
bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const
void editStart(LayerGeometryProvider *v, QMouseEvent *) override
double getValueForY(LayerGeometryProvider *v, int y) const override
void setVerticalZoomStep(int) override
!! lots of duplication with TimeValueLayer
sv_frame_t m_smallestRightNeighbourFrame
void splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame)
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
ModelId getAssociatedPitchModel(LayerGeometryProvider *v) const
void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override
void reAnalyseRegion(sv_frame_t, sv_frame_t, float, float)
virtual void mouseMoveEvent(LayerGeometryProvider *v, QMouseEvent *)
EditMode m_editMode
void editDrag(LayerGeometryProvider *v, QMouseEvent *) override
ChangeEventsCommand * m_editingCommand
void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const
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...
QString getScaleUnits() const override
void drawStart(LayerGeometryProvider *v, QMouseEvent *) override
void resizeSelection(Selection s, Selection newSize) override
std::set< Event > NoteSet
int getYForValue(LayerGeometryProvider *v, double value) const override
VerticalScaleLayer methods.
void addNoteOff(sv_frame_t frame, int pitch)
Add a note-off.
EventVector getLocalPoints(LayerGeometryProvider *v, int) const
NoteSet m_pendingNoteOns
void addNoteOn(sv_frame_t frame, int pitch, int velocity)
Add a note-on.
VerticalScale getVerticalScale() const
bool updateNoteValueFromPitchCurve(LayerGeometryProvider *v, Event &note) const
PropertyType getPropertyType(const PropertyName &) const override
bool isLayerEditable() const override
This should return true if the layer can be edited by the user.
RangeMapper * getNewVerticalZoomRangeMapper() const override
Create and return a range mapper for vertical zoom step values.
void mergeNotes(LayerGeometryProvider *v, Selection s, bool inclusive)
void materialiseReAnalysis()
void getRelativeMousePosition(LayerGeometryProvider *v, Event &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const