comparison layer/FlexiNoteLayer.h @ 718:e5f4385615ac tony_integration

Merge from tonioni branch
author Chris Cannam
date Tue, 28 Jan 2014 15:02:09 +0000
parents ceb9a2992d96
children d50f91fe374e
comparison
equal deleted inserted replaced
704:b81f21f2c4c3 718:e5f4385615ac
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
32
33 class FlexiNoteLayer : public SingleColourLayer,
34 public VerticalScaleLayer
35 {
36 Q_OBJECT
37
38 public:
39 FlexiNoteLayer();
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 size_t &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, size_t newStartFrame);
74 virtual void resizeSelection(Selection s, Selection newSize);
75 virtual void deleteSelection(Selection s);
76
77 virtual void copy(View *v, Selection s, Clipboard &to);
78 virtual bool paste(View *v, const Clipboard &from, int frameOffset,
79 bool interactive);
80
81 virtual const Model *getModel() const { return m_model; }
82 void setModel(FlexiNoteModel *model);
83
84 virtual PropertyList getProperties() const;
85 virtual QString getPropertyLabel(const PropertyName &) const;
86 virtual PropertyType getPropertyType(const PropertyName &) const;
87 virtual QString getPropertyGroupName(const PropertyName &) const;
88 virtual int getPropertyRangeAndValue(const PropertyName &,
89 int *min, int *max, int *deflt) const;
90 virtual QString getPropertyValueLabel(const PropertyName &,
91 int value) const;
92 virtual void setProperty(const PropertyName &, int value);
93
94 enum VerticalScale {
95 AutoAlignScale,
96 LinearScale,
97 LogScale,
98 MIDIRangeScale
99 };
100
101 //GF: Tonioni: context sensitive note edit actions (denoted clockwise from top).
102 enum EditMode {
103 DragNote,
104 RightBoundary,
105 SplitNote,
106 LeftBoundary
107 };
108
109 void setIntelligentActions(bool on) { m_intelligentActions=on; }
110
111 void setVerticalScale(VerticalScale scale);
112 VerticalScale getVerticalScale() const { return m_verticalScale; }
113
114 virtual bool isLayerScrollable(const View *v) const;
115
116 virtual bool isLayerEditable() const { return true; }
117
118 virtual int getCompletion(View *) const { return m_model->getCompletion(); }
119
120 virtual bool getValueExtents(float &min, float &max,
121 bool &log, QString &unit) const;
122
123 virtual bool getDisplayExtents(float &min, float &max) const;
124 virtual bool setDisplayExtents(float min, float max);
125
126 virtual int getVerticalZoomSteps(int &defaultStep) const;
127 virtual int getCurrentVerticalZoomStep() const;
128 virtual void setVerticalZoomStep(int);
129 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
130
131 /**
132 * Add a note-on. Used when recording MIDI "live". The note will
133 * not be finally added to the layer until the corresponding
134 * note-off.
135 */
136 void addNoteOn(long frame, int pitch, int velocity);
137
138 /**
139 * Add a note-off. This will cause a note to appear, if and only
140 * if there is a matching pending note-on.
141 */
142 void addNoteOff(long frame, int pitch);
143
144 /**
145 * Abandon all pending note-on events.
146 */
147 void abandonNoteOns();
148
149 virtual void toXml(QTextStream &stream, QString indent = "",
150 QString extraAttributes = "") const;
151
152 void setProperties(const QXmlAttributes &attributes);
153
154 void setVerticalRangeToNoteRange(View *v);
155
156 /// VerticalScaleLayer methods
157 virtual int getYForValue(View *v, float value) const;
158 virtual float getValueForY(View *v, int y) const;
159 virtual QString getScaleUnits() const;
160
161 protected:
162 void getScaleExtents(View *, float &min, float &max, bool &log) const;
163 bool shouldConvertMIDIToHz() const;
164
165 virtual int getDefaultColourHint(bool dark, bool &impose);
166
167 FlexiNoteModel::PointList getLocalPoints(View *v, int) const;
168
169 bool getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &) const;
170 bool getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &) const;
171 void getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const;
172 void updateNoteValue(View *v, FlexiNoteModel::Point &note) const;
173
174 FlexiNoteModel *m_model;
175 bool m_editing;
176 bool m_intelligentActions;
177 int m_dragPointX;
178 int m_dragPointY;
179 int m_dragStartX;
180 int m_dragStartY;
181 FlexiNoteModel::Point m_originalPoint;
182 FlexiNoteModel::Point m_editingPoint;
183 long m_greatestLeftNeighbourFrame;
184 long m_smallestRightNeighbourFrame;
185 FlexiNoteModel::EditCommand *m_editingCommand;
186 VerticalScale m_verticalScale;
187 EditMode m_editMode;
188
189 typedef std::set<FlexiNoteModel::Point, FlexiNoteModel::Point::Comparator> FlexiNoteSet;
190 FlexiNoteSet m_pendingNoteOns;
191
192 mutable float m_scaleMinimum;
193 mutable float m_scaleMaximum;
194
195 bool shouldAutoAlign() const;
196
197 void finish(FlexiNoteModel::EditCommand *command) {
198 Command *c = command->finish();
199 if (c) CommandHistory::getInstance()->addCommand(c, false);
200 }
201 };
202
203 #endif
204