annotate layer/NoteLayer.h @ 770:734ee80286c3 tony_integration

Merge from default branch
author Chris Cannam
date Fri, 09 May 2014 17:15:50 +0100
parents 084f65094203
children 1d526ba11a24
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@44 38 virtual void paint(View *v, QPainter &paint, QRect rect) const;
Chris@30 39
Chris@692 40 virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const;
Chris@692 41 virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const;
Chris@692 42
Chris@44 43 virtual QString getFeatureDescription(View *v, QPoint &) const;
Chris@30 44
Chris@44 45 virtual bool snapToFeatureFrame(View *v, int &frame,
Chris@30 46 size_t &resolution,
Chris@30 47 SnapType snap) const;
Chris@30 48
Chris@44 49 virtual void drawStart(View *v, QMouseEvent *);
Chris@44 50 virtual void drawDrag(View *v, QMouseEvent *);
Chris@44 51 virtual void drawEnd(View *v, QMouseEvent *);
Chris@30 52
Chris@335 53 virtual void eraseStart(View *v, QMouseEvent *);
Chris@335 54 virtual void eraseDrag(View *v, QMouseEvent *);
Chris@335 55 virtual void eraseEnd(View *v, QMouseEvent *);
Chris@335 56
Chris@44 57 virtual void editStart(View *v, QMouseEvent *);
Chris@44 58 virtual void editDrag(View *v, QMouseEvent *);
Chris@44 59 virtual void editEnd(View *v, QMouseEvent *);
Chris@30 60
Chris@255 61 virtual bool editOpen(View *v, QMouseEvent *);
Chris@70 62
Chris@43 63 virtual void moveSelection(Selection s, size_t newStartFrame);
Chris@43 64 virtual void resizeSelection(Selection s, Selection newSize);
Chris@76 65 virtual void deleteSelection(Selection s);
Chris@76 66
Chris@359 67 virtual void copy(View *v, Selection s, Clipboard &to);
Chris@359 68 virtual bool paste(View *v, const Clipboard &from, int 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@44 94 virtual bool isLayerScrollable(const View *v) const;
Chris@30 95
Chris@30 96 virtual bool isLayerEditable() const { return true; }
Chris@30 97
Chris@115 98 virtual int getCompletion(View *) const { return m_model->getCompletion(); }
Chris@30 99
Chris@101 100 virtual bool getValueExtents(float &min, float &max,
Chris@101 101 bool &log, QString &unit) const;
Chris@101 102
Chris@101 103 virtual bool getDisplayExtents(float &min, float &max) const;
Chris@439 104 virtual bool setDisplayExtents(float min, float 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@507 116 void addNoteOn(long 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@507 122 void addNoteOff(long 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@701 135 virtual int getYForValue(View *v, float value) const;
Chris@701 136 virtual float getValueForY(View *v, int y) const;
Chris@701 137 virtual QString getScaleUnits() const;
Chris@701 138
Chris@30 139 protected:
Chris@101 140 void getScaleExtents(View *, float &min, float &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@44 145 NoteModel::PointList getLocalPoints(View *v, int) const;
Chris@30 146
Chris@550 147 bool getPointToDrag(View *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@439 163 mutable float m_scaleMinimum;
Chris@439 164 mutable float 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