svgui  1.9
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 _NOTE_LAYER_H_
17 #define _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 
31  public VerticalScaleLayer
32 {
33  Q_OBJECT
34 
35 public:
36  NoteLayer();
37 
38  virtual void paint(View *v, QPainter &paint, QRect rect) const;
39 
40  virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const;
41  virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const;
42 
43  virtual QString getFeatureDescription(View *v, QPoint &) const;
44 
45  virtual bool snapToFeatureFrame(View *v, int &frame,
46  int &resolution,
47  SnapType snap) const;
48 
49  virtual void drawStart(View *v, QMouseEvent *);
50  virtual void drawDrag(View *v, QMouseEvent *);
51  virtual void drawEnd(View *v, QMouseEvent *);
52 
53  virtual void eraseStart(View *v, QMouseEvent *);
54  virtual void eraseDrag(View *v, QMouseEvent *);
55  virtual void eraseEnd(View *v, QMouseEvent *);
56 
57  virtual void editStart(View *v, QMouseEvent *);
58  virtual void editDrag(View *v, QMouseEvent *);
59  virtual void editEnd(View *v, QMouseEvent *);
60 
61  virtual bool editOpen(View *v, QMouseEvent *);
62 
63  virtual void moveSelection(Selection s, int newStartFrame);
64  virtual void resizeSelection(Selection s, Selection newSize);
65  virtual void deleteSelection(Selection s);
66 
67  virtual void copy(View *v, Selection s, Clipboard &to);
68  virtual bool paste(View *v, const Clipboard &from, int frameOffset,
69  bool interactive);
70 
71  virtual const Model *getModel() const { return m_model; }
72  void setModel(NoteModel *model);
73 
74  virtual PropertyList getProperties() const;
75  virtual QString getPropertyLabel(const PropertyName &) const;
76  virtual PropertyType getPropertyType(const PropertyName &) const;
77  virtual QString getPropertyGroupName(const PropertyName &) const;
78  virtual int getPropertyRangeAndValue(const PropertyName &,
79  int *min, int *max, int *deflt) const;
80  virtual QString getPropertyValueLabel(const PropertyName &,
81  int value) const;
82  virtual void setProperty(const PropertyName &, int value);
83 
89  };
90 
91  void setVerticalScale(VerticalScale scale);
93 
94  virtual bool isLayerScrollable(const View *v) const;
95 
96  virtual bool isLayerEditable() const { return true; }
97 
98  virtual int getCompletion(View *) const { return m_model->getCompletion(); }
99 
100  virtual bool getValueExtents(float &min, float &max,
101  bool &log, QString &unit) const;
102 
103  virtual bool getDisplayExtents(float &min, float &max) const;
104  virtual bool setDisplayExtents(float min, float max);
105 
106  virtual int getVerticalZoomSteps(int &defaultStep) const;
107  virtual int getCurrentVerticalZoomStep() const;
108  virtual void setVerticalZoomStep(int);
109  virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
110 
116  void addNoteOn(int frame, int pitch, int velocity);
117 
122  void addNoteOff(int frame, int pitch);
123 
127  void abandonNoteOns();
128 
129  virtual void toXml(QTextStream &stream, QString indent = "",
130  QString extraAttributes = "") const;
131 
132  void setProperties(const QXmlAttributes &attributes);
133 
135  virtual int getYForValue(View *v, float value) const;
136  virtual float getValueForY(View *v, int y) const;
137  virtual QString getScaleUnits() const;
138 
139 protected:
140  void getScaleExtents(View *, float &min, float &max, bool &log) const;
141  bool shouldConvertMIDIToHz() const;
142 
143  virtual int getDefaultColourHint(bool dark, bool &impose);
144 
145  NoteModel::PointList getLocalPoints(View *v, int) const;
146 
147  bool getPointToDrag(View *v, int x, int y, NoteModel::Point &) const;
148 
149  NoteModel *m_model;
150  bool m_editing;
155  NoteModel::Point m_originalPoint;
156  NoteModel::Point m_editingPoint;
157  NoteModel::EditCommand *m_editingCommand;
159 
160  typedef std::set<NoteModel::Point, NoteModel::Point::Comparator> NoteSet;
162 
163  mutable float m_scaleMinimum;
164  mutable float m_scaleMaximum;
165 
166  bool shouldAutoAlign() const;
167 
168  void finish(NoteModel::EditCommand *command) {
169  Command *c = command->finish();
170  if (c) CommandHistory::getInstance()->addCommand(c, false);
171  }
172 };
173 
174 #endif
175 
virtual void editDrag(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:1011
void finish(NoteModel::EditCommand *command)
Definition: NoteLayer.h:168
virtual void copy(View *v, Selection s, Clipboard &to)
Definition: NoteLayer.cpp:1196
void getScaleExtents(View *, float &min, float &max, bool &log) const
Definition: NoteLayer.cpp:622
virtual QString getPropertyGroupName(const PropertyName &) const
Definition: NoteLayer.cpp:108
virtual const Model * getModel() const
Definition: NoteLayer.h:71
virtual void eraseDrag(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:963
int m_dragPointX
Definition: NoteLayer.h:151
virtual int getCompletion(View *) const
Return the proportion of background work complete in drawing this view, as a percentage – in most cas...
Definition: NoteLayer.h:98
bool shouldAutoAlign() const
Definition: NoteLayer.cpp:737
virtual bool getValueExtents(float &min, float &max, bool &log, QString &unit) const
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
Definition: NoteLayer.cpp:212
virtual bool editOpen(View *v, QMouseEvent *)
Open an editor on the item under the mouse (e.g.
Definition: NoteLayer.cpp:1068
int m_dragPointY
Definition: NoteLayer.h:152
virtual void moveSelection(Selection s, int newStartFrame)
Definition: NoteLayer.cpp:1110
VerticalScale getVerticalScale() const
Definition: NoteLayer.h:92
NoteModel::Point m_editingPoint
Definition: NoteLayer.h:156
void addCommand(Command *command)
Add a command to the command history.
void addNoteOn(int frame, int pitch, int velocity)
Add a note-on.
Definition: NoteLayer.cpp:1295
virtual PropertyList getProperties() const
Definition: NoteLayer.cpp:83
bool getPointToDrag(View *v, int x, int y, NoteModel::Point &) const
Definition: NoteLayer.cpp:435
std::set< NoteModel::Point, NoteModel::Point::Comparator > NoteSet
Definition: NoteLayer.h:160
virtual void setProperty(const PropertyName &, int value)
Definition: NoteLayer.cpp:170
virtual void setVerticalZoomStep(int)
!! lots of duplication with TimeValueLayer
Definition: NoteLayer.cpp:318
NoteModel::EditCommand * m_editingCommand
Definition: NoteLayer.h:157
NoteModel::Point m_originalPoint
Definition: NoteLayer.h:155
virtual void drawEnd(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:938
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
Definition: NoteLayer.cpp:124
VerticalScale m_verticalScale
Definition: NoteLayer.h:158
void addNoteOff(int frame, int pitch)
Add a note-off.
Definition: NoteLayer.cpp:1301
virtual RangeMapper * getNewVerticalZoomRangeMapper() const
Create and return a range mapper for vertical zoom step values.
Definition: NoteLayer.cpp:369
virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const
Definition: NoteLayer.cpp:847
virtual void deleteSelection(Selection s)
Definition: NoteLayer.cpp:1174
void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
Definition: NoteLayer.cpp:1346
virtual void resizeSelection(Selection s, Selection newSize)
Definition: NoteLayer.cpp:1135
virtual bool getDisplayExtents(float &min, float &max) const
Return the minimum and maximum values within the displayed range for the y axis, if only a subset of ...
Definition: NoteLayer.cpp:232
NoteSet m_pendingNoteOns
Definition: NoteLayer.h:161
virtual QString getFeatureDescription(View *v, QPoint &) const
Definition: NoteLayer.cpp:463
int m_dragStartX
Definition: NoteLayer.h:153
virtual void editStart(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:988
void setModel(NoteModel *model)
Definition: NoteLayer.cpp:67
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
Definition: NoteLayer.cpp:1335
virtual void editEnd(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:1040
virtual int getCurrentVerticalZoomStep() const
Get the current vertical zoom step.
Definition: NoteLayer.cpp:297
float m_scaleMaximum
Definition: NoteLayer.h:164
virtual bool setDisplayExtents(float min, float max)
Set the displayed minimum and maximum values for the y axis to the given range, if supported.
Definition: NoteLayer.cpp:263
float m_scaleMinimum
Definition: NoteLayer.h:163
virtual PropertyType getPropertyType(const PropertyName &) const
Definition: NoteLayer.cpp:100
virtual QString getPropertyLabel(const PropertyName &) const
Definition: NoteLayer.cpp:92
virtual void eraseStart(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:948
SnapType
Definition: Layer.h:157
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
Definition: NoteLayer.cpp:154
static CommandHistory * getInstance()
void abandonNoteOns()
Abandon all pending note-on events.
Definition: NoteLayer.cpp:1321
virtual bool snapToFeatureFrame(View *v, int &frame, int &resolution, SnapType snap) const
Adjust the given frame to snap to the nearest feature, if possible.
Definition: NoteLayer.cpp:550
virtual bool isLayerScrollable(const View *v) const
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
Definition: NoteLayer.cpp:194
virtual void drawStart(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:885
virtual void drawDrag(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:909
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
virtual QString getScaleUnits() const
Definition: NoteLayer.cpp:117
virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const
Definition: NoteLayer.cpp:833
int m_dragStartY
Definition: NoteLayer.h:154
NoteModel::PointList getLocalPoints(View *v, int) const
Definition: NoteLayer.cpp:392
virtual float getValueForY(View *v, int y) const
Definition: NoteLayer.cpp:715
bool m_editing
Definition: NoteLayer.h:150
bool shouldConvertMIDIToHz() const
Definition: NoteLayer.cpp:201
void setVerticalScale(VerticalScale scale)
Definition: NoteLayer.cpp:186
virtual bool isLayerEditable() const
This should return true if the layer can be edited by the user.
Definition: NoteLayer.h:96
virtual int getDefaultColourHint(bool dark, bool &impose)
Definition: NoteLayer.cpp:1327
NoteModel * m_model
Definition: NoteLayer.h:149
virtual int getVerticalZoomSteps(int &defaultStep) const
Get the number of vertical zoom steps available for this layer.
Definition: NoteLayer.cpp:287
virtual void paint(View *v, QPainter &paint, QRect rect) const
Paint the given rectangle of this layer onto the given view using the given painter,...
Definition: NoteLayer.cpp:744
virtual bool paste(View *v, const Clipboard &from, int frameOffset, bool interactive)
Paste from the given clipboard onto the layer at the given frame offset.
Definition: NoteLayer.cpp:1214
virtual void eraseEnd(View *v, QMouseEvent *)
Definition: NoteLayer.cpp:968
virtual int getYForValue(View *v, float value) const
VerticalScaleLayer methods.
Definition: NoteLayer.cpp:680