svgui  1.9
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 _FLEXINOTE_LAYER_H_
17 #define _FLEXINOTE_LAYER_H_
18 
19 #define NOTE_HEIGHT 16
20 
21 #include "SingleColourLayer.h"
22 #include "VerticalScaleLayer.h"
23 
24 #include "data/model/FlexiNoteModel.h"
25 
26 #include <QObject>
27 #include <QColor>
28 
29 class View;
30 class QPainter;
31 class SparseTimeValueModel;
32 
34  public VerticalScaleLayer
35 {
36  Q_OBJECT
37 
38 public:
40 
41  virtual void paint(View *v, QPainter &paint, QRect rect) const;
42 
43  virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const;
44  virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const;
45 
46  virtual QString getFeatureDescription(View *v, QPoint &) const;
47 
48  virtual bool snapToFeatureFrame(View *v, int &frame,
49  int &resolution,
50  SnapType snap) const;
51 
52  virtual void drawStart(View *v, QMouseEvent *);
53  virtual void drawDrag(View *v, QMouseEvent *);
54  virtual void drawEnd(View *v, QMouseEvent *);
55 
56  virtual void eraseStart(View *v, QMouseEvent *);
57  virtual void eraseDrag(View *v, QMouseEvent *);
58  virtual void eraseEnd(View *v, QMouseEvent *);
59 
60  virtual void editStart(View *v, QMouseEvent *);
61  virtual void editDrag(View *v, QMouseEvent *);
62  virtual void editEnd(View *v, QMouseEvent *);
63 
64  virtual void splitStart(View *v, QMouseEvent *);
65  virtual void splitEnd(View *v, QMouseEvent *);
66 
67  virtual void addNote(View *v, QMouseEvent *e);
68 
69  virtual void mouseMoveEvent(View *v, QMouseEvent *);
70 
71  virtual bool editOpen(View *v, QMouseEvent *);
72 
73  virtual void moveSelection(Selection s, int newStartFrame);
74  virtual void resizeSelection(Selection s, Selection newSize);
75  virtual void deleteSelection(Selection s);
76  virtual void deleteSelectionInclusive(Selection s);
77 
78  virtual void copy(View *v, Selection s, Clipboard &to);
79  virtual bool paste(View *v, const Clipboard &from, int frameOffset,
80  bool interactive);
81 
82  void splitNotesAt(View *v, int frame);
83  void snapSelectedNotesToPitchTrack(View *v, Selection s);
84  void mergeNotes(View *v, Selection s, bool inclusive);
85 
86  virtual const Model *getModel() const { return m_model; }
87  void setModel(FlexiNoteModel *model);
88 
89  virtual PropertyList getProperties() const;
90  virtual QString getPropertyLabel(const PropertyName &) const;
91  virtual PropertyType getPropertyType(const PropertyName &) const;
92  virtual QString getPropertyGroupName(const PropertyName &) const;
93  virtual int getPropertyRangeAndValue(const PropertyName &,
94  int *min, int *max, int *deflt) const;
95  virtual QString getPropertyValueLabel(const PropertyName &,
96  int value) const;
97  virtual void setProperty(const PropertyName &, int value);
98 
104  };
105 
106  //GF: Tonioni: context sensitive note edit actions (denoted clockwise from top).
107  enum EditMode {
112  };
113 
115 
116  void setVerticalScale(VerticalScale scale);
118 
119  virtual bool isLayerScrollable(const View *v) const;
120 
121  virtual bool isLayerEditable() const { return true; }
122 
123  virtual int getCompletion(View *) const { return m_model->getCompletion(); }
124 
125  virtual bool getValueExtents(float &min, float &max,
126  bool &log, QString &unit) const;
127 
128  virtual bool getDisplayExtents(float &min, float &max) const;
129  virtual bool setDisplayExtents(float min, float max);
130 
131  virtual int getVerticalZoomSteps(int &defaultStep) const;
132  virtual int getCurrentVerticalZoomStep() const;
133  virtual void setVerticalZoomStep(int);
134  virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
135 
141  void addNoteOn(int frame, int pitch, int velocity);
142 
147  void addNoteOff(int frame, int pitch);
148 
152  void abandonNoteOns();
153 
154  virtual void toXml(QTextStream &stream, QString indent = "",
155  QString extraAttributes = "") const;
156 
157  void setProperties(const QXmlAttributes &attributes);
158 
160 
162  virtual int getYForValue(View *v, float value) const;
163  virtual float getValueForY(View *v, int y) const;
164  virtual QString getScaleUnits() const;
165 
166 protected:
167  void getScaleExtents(View *, float &min, float &max, bool &log) const;
168  bool shouldConvertMIDIToHz() const;
169 
170  virtual int getDefaultColourHint(bool dark, bool &impose);
171 
172  FlexiNoteModel::PointList getLocalPoints(View *v, int) const;
173 
174  bool getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &) const;
175  bool getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &) const;
176  void getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const;
177  SparseTimeValueModel *getAssociatedPitchModel(View *v) const;
178  bool updateNoteValue(View *v, FlexiNoteModel::Point &note) const;
179  void splitNotesAt(View *v, int frame, QMouseEvent *e);
180 
181  FlexiNoteModel *m_model;
182  bool m_editing;
188  FlexiNoteModel::Point m_originalPoint;
189  FlexiNoteModel::Point m_editingPoint;
192  FlexiNoteModel::EditCommand *m_editingCommand;
195 
196  typedef std::set<FlexiNoteModel::Point, FlexiNoteModel::Point::Comparator> FlexiNoteSet;
198 
199  mutable float m_scaleMinimum;
200  mutable float m_scaleMaximum;
201 
202  bool shouldAutoAlign() const;
203 
204  void finish(FlexiNoteModel::EditCommand *command) {
205  Command *c = command->finish();
206  if (c) CommandHistory::getInstance()->addCommand(c, false);
207  }
208 };
209 
210 #endif
211 
virtual QString getScaleUnits() const
virtual QString getPropertyGroupName(const PropertyName &) const
virtual RangeMapper * getNewVerticalZoomRangeMapper() const
Create and return a range mapper for vertical zoom step values.
void setIntelligentActions(bool on)
virtual void setProperty(const PropertyName &, int value)
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.
virtual void drawStart(View *v, QMouseEvent *)
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...
VerticalScale getVerticalScale() const
int m_smallestRightNeighbourFrame
virtual QString getPropertyLabel(const PropertyName &) const
virtual int getYForValue(View *v, float value) const
VerticalScaleLayer methods.
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
bool getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &) const
virtual float getValueForY(View *v, int y) const
virtual void eraseEnd(View *v, QMouseEvent *)
bool shouldConvertMIDIToHz() const
virtual void editEnd(View *v, QMouseEvent *)
virtual void copy(View *v, Selection s, Clipboard &to)
virtual int getCurrentVerticalZoomStep() const
Get the current vertical zoom step.
void addCommand(Command *command)
Add a command to the command history.
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 ...
FlexiNoteModel::Point m_editingPoint
virtual bool editOpen(View *v, QMouseEvent *)
Open an editor on the item under the mouse (e.g.
bool shouldAutoAlign() const
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...
void setVerticalScale(VerticalScale scale)
virtual int getVerticalZoomSteps(int &defaultStep) const
Get the number of vertical zoom steps available for this layer.
virtual void deleteSelectionInclusive(Selection s)
virtual void eraseDrag(View *v, QMouseEvent *)
virtual const Model * getModel() const
virtual void moveSelection(Selection s, int newStartFrame)
virtual QString getFeatureDescription(View *v, QPoint &) const
virtual bool isLayerEditable() const
This should return true if the layer can be edited by the user.
virtual bool setDisplayExtents(float min, float max)
Set the displayed minimum and maximum values for the y axis to the given range, if supported.
void addNoteOff(int frame, int pitch)
Add a note-off.
virtual void splitEnd(View *v, QMouseEvent *)
void setModel(FlexiNoteModel *model)
FlexiNoteModel::Point m_originalPoint
void getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const
virtual void deleteSelection(Selection s)
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,...
std::set< FlexiNoteModel::Point, FlexiNoteModel::Point::Comparator > FlexiNoteSet
virtual void editStart(View *v, QMouseEvent *)
virtual void addNote(View *v, QMouseEvent *e)
FlexiNoteSet m_pendingNoteOns
void mergeNotes(View *v, Selection s, bool inclusive)
virtual void editDrag(View *v, QMouseEvent *)
SnapType
Definition: Layer.h:157
static CommandHistory * getInstance()
virtual void eraseStart(View *v, QMouseEvent *)
FlexiNoteModel * m_model
VerticalScale m_verticalScale
virtual bool snapToFeatureFrame(View *v, int &frame, int &resolution, SnapType snap) const
Adjust the given frame to snap to the nearest feature, if possible.
FlexiNoteModel::PointList getLocalPoints(View *v, int) const
void abandonNoteOns()
Abandon all pending note-on events.
void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
virtual void setVerticalZoomStep(int)
!! lots of duplication with TimeValueLayer
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.
void finish(FlexiNoteModel::EditCommand *command)
bool getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &) const
void snapSelectedNotesToPitchTrack(View *v, Selection s)
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
bool updateNoteValue(View *v, FlexiNoteModel::Point &note) const
virtual int getCompletion(View *) const
Return the proportion of background work complete in drawing this view, as a percentage – in most cas...
FlexiNoteModel::EditCommand * m_editingCommand
SparseTimeValueModel * getAssociatedPitchModel(View *v) const
virtual void mouseMoveEvent(View *v, QMouseEvent *)
virtual int getDefaultColourHint(bool dark, bool &impose)
virtual void resizeSelection(Selection s, Selection newSize)
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
void setVerticalRangeToNoteRange(View *v)
EditMode m_editMode
virtual void drawEnd(View *v, QMouseEvent *)
virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const
void splitNotesAt(View *v, int frame)
virtual PropertyList getProperties() const
virtual void drawDrag(View *v, QMouseEvent *)
virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const
virtual PropertyType getPropertyType(const PropertyName &) const
virtual void splitStart(View *v, QMouseEvent *)
void getScaleExtents(View *, float &min, float &max, bool &log) const
int m_greatestLeftNeighbourFrame
void addNoteOn(int frame, int pitch, int velocity)
Add a note-on.