comparison layer/FlexiNoteLayer.h @ 619:aa141d619142 tonioni

simply copied NoteLayer to FlexiNotelayer (cpp and h files)
author matthiasm
date Tue, 26 Mar 2013 13:58:08 +0000
parents layer/NoteLayer.h@5b72899d692b
children fde7e2fae256
comparison
equal deleted inserted replaced
618:54f97c0afeec 619:aa141d619142
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 "data/model/NoteModel.h"
21
22 #include <QObject>
23 #include <QColor>
24
25 class View;
26 class QPainter;
27
28 class NoteLayer : public SingleColourLayer
29 {
30 Q_OBJECT
31
32 public:
33 NoteLayer();
34
35 virtual void paint(View *v, QPainter &paint, QRect rect) const;
36
37 virtual QString getFeatureDescription(View *v, QPoint &) const;
38
39 virtual bool snapToFeatureFrame(View *v, int &frame,
40 size_t &resolution,
41 SnapType snap) const;
42
43 virtual void drawStart(View *v, QMouseEvent *);
44 virtual void drawDrag(View *v, QMouseEvent *);
45 virtual void drawEnd(View *v, QMouseEvent *);
46
47 virtual void eraseStart(View *v, QMouseEvent *);
48 virtual void eraseDrag(View *v, QMouseEvent *);
49 virtual void eraseEnd(View *v, QMouseEvent *);
50
51 virtual void editStart(View *v, QMouseEvent *);
52 virtual void editDrag(View *v, QMouseEvent *);
53 virtual void editEnd(View *v, QMouseEvent *);
54
55 virtual bool editOpen(View *v, QMouseEvent *);
56
57 virtual void moveSelection(Selection s, size_t newStartFrame);
58 virtual void resizeSelection(Selection s, Selection newSize);
59 virtual void deleteSelection(Selection s);
60
61 virtual void copy(View *v, Selection s, Clipboard &to);
62 virtual bool paste(View *v, const Clipboard &from, int frameOffset,
63 bool interactive);
64
65 virtual const Model *getModel() const { return m_model; }
66 void setModel(NoteModel *model);
67
68 virtual PropertyList getProperties() const;
69 virtual QString getPropertyLabel(const PropertyName &) const;
70 virtual PropertyType getPropertyType(const PropertyName &) const;
71 virtual QString getPropertyGroupName(const PropertyName &) const;
72 virtual int getPropertyRangeAndValue(const PropertyName &,
73 int *min, int *max, int *deflt) const;
74 virtual QString getPropertyValueLabel(const PropertyName &,
75 int value) const;
76 virtual void setProperty(const PropertyName &, int value);
77
78 enum VerticalScale {
79 AutoAlignScale,
80 LinearScale,
81 LogScale,
82 MIDIRangeScale
83 };
84
85 void setVerticalScale(VerticalScale scale);
86 VerticalScale getVerticalScale() const { return m_verticalScale; }
87
88 virtual bool isLayerScrollable(const View *v) const;
89
90 virtual bool isLayerEditable() const { return true; }
91
92 virtual int getCompletion(View *) const { return m_model->getCompletion(); }
93
94 virtual bool getValueExtents(float &min, float &max,
95 bool &log, QString &unit) const;
96
97 virtual bool getDisplayExtents(float &min, float &max) const;
98 virtual bool setDisplayExtents(float min, float max);
99
100 virtual int getVerticalZoomSteps(int &defaultStep) const;
101 virtual int getCurrentVerticalZoomStep() const;
102 virtual void setVerticalZoomStep(int);
103 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
104
105 virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; }
106
107 /**
108 * Add a note-on. Used when recording MIDI "live". The note will
109 * not be finally added to the layer until the corresponding
110 * note-off.
111 */
112 void addNoteOn(long frame, int pitch, int velocity);
113
114 /**
115 * Add a note-off. This will cause a note to appear, if and only
116 * if there is a matching pending note-on.
117 */
118 void addNoteOff(long frame, int pitch);
119
120 /**
121 * Abandon all pending note-on events.
122 */
123 void abandonNoteOns();
124
125 virtual void toXml(QTextStream &stream, QString indent = "",
126 QString extraAttributes = "") const;
127
128 void setProperties(const QXmlAttributes &attributes);
129
130 protected:
131 void getScaleExtents(View *, float &min, float &max, bool &log) const;
132 int getYForValue(View *v, float value) const;
133 float getValueForY(View *v, int y) const;
134 bool shouldConvertMIDIToHz() const;
135
136 virtual int getDefaultColourHint(bool dark, bool &impose);
137
138 NoteModel::PointList getLocalPoints(View *v, int) const;
139
140 bool getPointToDrag(View *v, int x, int y, NoteModel::Point &) const;
141
142 NoteModel *m_model;
143 bool m_editing;
144 int m_dragPointX;
145 int m_dragPointY;
146 int m_dragStartX;
147 int m_dragStartY;
148 NoteModel::Point m_originalPoint;
149 NoteModel::Point m_editingPoint;
150 NoteModel::EditCommand *m_editingCommand;
151 VerticalScale m_verticalScale;
152
153 typedef std::set<NoteModel::Point, NoteModel::Point::Comparator> NoteSet;
154 NoteSet m_pendingNoteOns;
155
156 mutable float m_scaleMinimum;
157 mutable float m_scaleMaximum;
158
159 bool shouldAutoAlign() const;
160
161 void finish(NoteModel::EditCommand *command) {
162 Command *c = command->finish();
163 if (c) CommandHistory::getInstance()->addCommand(c, false);
164 }
165 };
166
167 #endif
168