annotate layer/NoteLayer.h @ 1511:a473b73fb045 time-frequency-boxes

Introduce time-frequency box layer
author Chris Cannam
date Thu, 19 Sep 2019 15:18:28 +0100
parents 696e569ff21b
children e6362cf5ff1d
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@1362 16 #ifndef SV_NOTE_LAYER_H
Chris@1362 17 #define SV_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@1406 38 void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
Chris@30 39
Chris@1406 40 int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
Chris@1406 41 void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
Chris@692 42
Chris@1406 43 QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
Chris@30 44
Chris@1406 45 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1266 46 int &resolution,
Chris@1406 47 SnapType snap) const override;
Chris@30 48
Chris@1406 49 void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 50 void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 51 void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@30 52
Chris@1406 53 void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 54 void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 55 void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@335 56
Chris@1406 57 void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 58 void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 59 void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@30 60
Chris@1406 61 bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@70 62
Chris@1406 63 void moveSelection(Selection s, sv_frame_t newStartFrame) override;
Chris@1406 64 void resizeSelection(Selection s, Selection newSize) override;
Chris@1406 65 void deleteSelection(Selection s) override;
Chris@76 66
Chris@1406 67 void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
Chris@1406 68 bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
Chris@1406 69 bool interactive) override;
Chris@43 70
Chris@1470 71 ModelId getModel() const override { return m_model; }
Chris@1470 72 void setModel(ModelId model); // a NoteModel
Chris@30 73
Chris@1406 74 PropertyList getProperties() const override;
Chris@1406 75 QString getPropertyLabel(const PropertyName &) const override;
Chris@1406 76 PropertyType getPropertyType(const PropertyName &) const override;
Chris@1406 77 QString getPropertyGroupName(const PropertyName &) const override;
Chris@1406 78 int getPropertyRangeAndValue(const PropertyName &,
Chris@1406 79 int *min, int *max, int *deflt) const override;
Chris@1406 80 QString getPropertyValueLabel(const PropertyName &,
Chris@1406 81 int value) const override;
Chris@1406 82 void setProperty(const PropertyName &, int value) override;
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@1406 94 bool isLayerScrollable(const LayerGeometryProvider *v) const override;
Chris@30 95
Chris@1406 96 bool isLayerEditable() const override { return true; }
Chris@30 97
Chris@1470 98 int getCompletion(LayerGeometryProvider *) const override;
Chris@30 99
Chris@1406 100 bool getValueExtents(double &min, double &max,
Chris@1406 101 bool &log, QString &unit) const override;
Chris@101 102
Chris@1406 103 bool getDisplayExtents(double &min, double &max) const override;
Chris@1406 104 bool setDisplayExtents(double min, double max) override;
Chris@439 105
Chris@1406 106 int getVerticalZoomSteps(int &defaultStep) const override;
Chris@1406 107 int getCurrentVerticalZoomStep() const override;
Chris@1406 108 void setVerticalZoomStep(int) override;
Chris@1406 109 RangeMapper *getNewVerticalZoomRangeMapper() const override;
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@1406 129 void toXml(QTextStream &stream, QString indent = "",
Chris@1406 130 QString extraAttributes = "") const override;
Chris@30 131
Chris@1406 132 void setProperties(const QXmlAttributes &attributes) override;
Chris@30 133
Chris@701 134 /// VerticalScaleLayer methods
Chris@1406 135 int getYForValue(LayerGeometryProvider *v, double value) const override;
Chris@1406 136 double getValueForY(LayerGeometryProvider *v, int y) const override;
Chris@1406 137 QString getScaleUnits() const override;
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@1406 143 int getDefaultColourHint(bool dark, bool &impose) override;
Chris@287 144
Chris@1424 145 EventVector getLocalPoints(LayerGeometryProvider *v, int) const;
Chris@30 146
Chris@1424 147 bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
Chris@550 148
Chris@1470 149 ModelId 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@1424 155 Event m_originalPoint;
Chris@1424 156 Event m_editingPoint;
Chris@1427 157 ChangeEventsCommand *m_editingCommand;
Chris@1422 158 bool m_editIsOpen;
Chris@30 159 VerticalScale m_verticalScale;
Chris@376 160
Chris@1424 161 typedef std::set<Event> NoteSet;
Chris@507 162 NoteSet m_pendingNoteOns;
Chris@507 163
Chris@905 164 mutable double m_scaleMinimum;
Chris@905 165 mutable double m_scaleMaximum;
Chris@439 166
Chris@439 167 bool shouldAutoAlign() const;
Chris@439 168
Chris@1427 169 void finish(ChangeEventsCommand *command) {
Chris@376 170 Command *c = command->finish();
Chris@376 171 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@376 172 }
Chris@30 173 };
Chris@30 174
Chris@30 175 #endif
Chris@30 176