annotate layer/NoteLayer.h @ 1023:74755fa6ea9e colourschemes

Avoid reusing a large paint width if the zoom level has changed (in case it has changed dramatically, as for example when the user hits the F key). Also some tidying and adjustment to timing stuff
author Chris Cannam
date Fri, 22 Jan 2016 18:12:41 +0000
parents 4fe7a09be0fe
children a34a2a25907c
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@30 2
Chris@30 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@59 7 This file copyright 2006 Chris Cannam.
Chris@30 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@30 14 */
Chris@30 15
Chris@30 16 #ifndef _NOTE_LAYER_H_
Chris@30 17 #define _NOTE_LAYER_H_
Chris@30 18
Chris@287 19 #include "SingleColourLayer.h"
Chris@701 20 #include "VerticalScaleLayer.h"
Chris@701 21
Chris@128 22 #include "data/model/NoteModel.h"
Chris@30 23
Chris@30 24 #include <QObject>
Chris@30 25 #include <QColor>
Chris@30 26
Chris@30 27 class View;
Chris@30 28 class QPainter;
Chris@30 29
Chris@701 30 class NoteLayer : public SingleColourLayer,
Chris@701 31 public VerticalScaleLayer
Chris@30 32 {
Chris@30 33 Q_OBJECT
Chris@30 34
Chris@30 35 public:
Chris@44 36 NoteLayer();
Chris@30 37
Chris@916 38 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@30 39
Chris@918 40 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const;
Chris@918 41 virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const;
Chris@692 42
Chris@918 43 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
Chris@30 44
Chris@918 45 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@805 46 int &resolution,
Chris@30 47 SnapType snap) const;
Chris@30 48
Chris@918 49 virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 50 virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 51 virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *);
Chris@30 52
Chris@918 53 virtual void eraseStart(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 54 virtual void eraseDrag(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 55 virtual void eraseEnd(LayerGeometryProvider *v, QMouseEvent *);
Chris@335 56
Chris@918 57 virtual void editStart(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 58 virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 59 virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *);
Chris@30 60
Chris@918 61 virtual bool editOpen(LayerGeometryProvider *v, QMouseEvent *);
Chris@70 62
Chris@905 63 virtual void moveSelection(Selection s, sv_frame_t newStartFrame);
Chris@43 64 virtual void resizeSelection(Selection s, Selection newSize);
Chris@76 65 virtual void deleteSelection(Selection s);
Chris@76 66
Chris@918 67 virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to);
Chris@918 68 virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
Chris@125 69 bool interactive);
Chris@43 70
Chris@30 71 virtual const Model *getModel() const { return m_model; }
Chris@30 72 void setModel(NoteModel *model);
Chris@30 73
Chris@30 74 virtual PropertyList getProperties() const;
Chris@87 75 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@30 76 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@198 77 virtual QString getPropertyGroupName(const PropertyName &) const;
Chris@30 78 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@216 79 int *min, int *max, int *deflt) const;
Chris@30 80 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@30 81 int value) const;
Chris@30 82 virtual void setProperty(const PropertyName &, int value);
Chris@30 83
Chris@30 84 enum VerticalScale {
Chris@101 85 AutoAlignScale,
Chris@101 86 LinearScale,
Chris@101 87 LogScale,
Chris@101 88 MIDIRangeScale
Chris@30 89 };
Chris@30 90
Chris@30 91 void setVerticalScale(VerticalScale scale);
Chris@30 92 VerticalScale getVerticalScale() const { return m_verticalScale; }
Chris@30 93
Chris@918 94 virtual bool isLayerScrollable(const LayerGeometryProvider *v) const;
Chris@30 95
Chris@30 96 virtual bool isLayerEditable() const { return true; }
Chris@30 97
Chris@918 98 virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); }
Chris@30 99
Chris@905 100 virtual bool getValueExtents(double &min, double &max,
Chris@101 101 bool &log, QString &unit) const;
Chris@101 102
Chris@905 103 virtual bool getDisplayExtents(double &min, double &max) const;
Chris@905 104 virtual bool setDisplayExtents(double min, double max);
Chris@439 105
Chris@439 106 virtual int getVerticalZoomSteps(int &defaultStep) const;
Chris@439 107 virtual int getCurrentVerticalZoomStep() const;
Chris@439 108 virtual void setVerticalZoomStep(int);
Chris@439 109 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
Chris@79 110
Chris@507 111 /**
Chris@507 112 * Add a note-on. Used when recording MIDI "live". The note will
Chris@507 113 * not be finally added to the layer until the corresponding
Chris@507 114 * note-off.
Chris@507 115 */
Chris@905 116 void addNoteOn(sv_frame_t frame, int pitch, int velocity);
Chris@507 117
Chris@507 118 /**
Chris@507 119 * Add a note-off. This will cause a note to appear, if and only
Chris@507 120 * if there is a matching pending note-on.
Chris@507 121 */
Chris@905 122 void addNoteOff(sv_frame_t frame, int pitch);
Chris@507 123
Chris@507 124 /**
Chris@507 125 * Abandon all pending note-on events.
Chris@507 126 */
Chris@507 127 void abandonNoteOns();
Chris@507 128
Chris@316 129 virtual void toXml(QTextStream &stream, QString indent = "",
Chris@316 130 QString extraAttributes = "") const;
Chris@30 131
Chris@30 132 void setProperties(const QXmlAttributes &attributes);
Chris@30 133
Chris@701 134 /// VerticalScaleLayer methods
Chris@918 135 virtual int getYForValue(LayerGeometryProvider *v, double value) const;
Chris@918 136 virtual double getValueForY(LayerGeometryProvider *v, int y) const;
Chris@701 137 virtual QString getScaleUnits() const;
Chris@701 138
Chris@30 139 protected:
Chris@918 140 void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
Chris@101 141 bool shouldConvertMIDIToHz() const;
Chris@30 142
Chris@287 143 virtual int getDefaultColourHint(bool dark, bool &impose);
Chris@287 144
Chris@918 145 NoteModel::PointList getLocalPoints(LayerGeometryProvider *v, int) const;
Chris@30 146
Chris@918 147 bool getPointToDrag(LayerGeometryProvider *v, int x, int y, NoteModel::Point &) const;
Chris@550 148
Chris@30 149 NoteModel *m_model;
Chris@30 150 bool m_editing;
Chris@551 151 int m_dragPointX;
Chris@551 152 int m_dragPointY;
Chris@551 153 int m_dragStartX;
Chris@551 154 int m_dragStartY;
Chris@30 155 NoteModel::Point m_originalPoint;
Chris@30 156 NoteModel::Point m_editingPoint;
Chris@30 157 NoteModel::EditCommand *m_editingCommand;
Chris@30 158 VerticalScale m_verticalScale;
Chris@376 159
Chris@507 160 typedef std::set<NoteModel::Point, NoteModel::Point::Comparator> NoteSet;
Chris@507 161 NoteSet m_pendingNoteOns;
Chris@507 162
Chris@905 163 mutable double m_scaleMinimum;
Chris@905 164 mutable double m_scaleMaximum;
Chris@439 165
Chris@439 166 bool shouldAutoAlign() const;
Chris@439 167
Chris@376 168 void finish(NoteModel::EditCommand *command) {
Chris@376 169 Command *c = command->finish();
Chris@376 170 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@376 171 }
Chris@30 172 };
Chris@30 173
Chris@30 174 #endif
Chris@30 175