annotate layer/NoteLayer.h @ 1607:52d4bfba5b3d

Reduce font size when pane is very thin
author Chris Cannam
date Wed, 06 May 2020 11:44:38 +0100
parents e79731086b0f
children
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@1551 30 /**
Chris@1551 31 * Layer for displaying and editing notes, i.e. discrete events with
Chris@1551 32 * start time, duration, value that represents pitch, and optionally a
Chris@1551 33 * level that represents velocity.
Chris@1551 34 *
Chris@1551 35 * For the purposes of public API, integration with other classes, and
Chris@1551 36 * display alignment, the y-coordinate (value) of the layer always has
Chris@1551 37 * a unit of Hz. The model itself may have another unit, such as MIDI
Chris@1551 38 * pitch, but the layer always converts to and from Hz behind the
Chris@1551 39 * scenes.
Chris@1551 40 */
Chris@701 41 class NoteLayer : public SingleColourLayer,
Chris@701 42 public VerticalScaleLayer
Chris@30 43 {
Chris@30 44 Q_OBJECT
Chris@30 45
Chris@30 46 public:
Chris@44 47 NoteLayer();
Chris@30 48
Chris@1406 49 void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
Chris@30 50
Chris@1406 51 int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
Chris@1406 52 void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
Chris@692 53
Chris@1406 54 QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
Chris@30 55
Chris@1406 56 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1547 57 int &resolution,
Chris@1547 58 SnapType snap, int ycoord) const override;
Chris@30 59
Chris@1406 60 void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 61 void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 62 void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@30 63
Chris@1406 64 void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 65 void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 66 void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@335 67
Chris@1406 68 void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 69 void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 70 void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@30 71
Chris@1406 72 bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@70 73
Chris@1406 74 void moveSelection(Selection s, sv_frame_t newStartFrame) override;
Chris@1406 75 void resizeSelection(Selection s, Selection newSize) override;
Chris@1406 76 void deleteSelection(Selection s) override;
Chris@76 77
Chris@1406 78 void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
Chris@1551 79 bool paste(LayerGeometryProvider *v, const Clipboard &from,
Chris@1551 80 sv_frame_t frameOffset, bool interactive) override;
Chris@43 81
Chris@1470 82 ModelId getModel() const override { return m_model; }
Chris@1470 83 void setModel(ModelId model); // a NoteModel
Chris@30 84
Chris@1406 85 PropertyList getProperties() const override;
Chris@1406 86 QString getPropertyLabel(const PropertyName &) const override;
Chris@1406 87 PropertyType getPropertyType(const PropertyName &) const override;
Chris@1406 88 QString getPropertyGroupName(const PropertyName &) const override;
Chris@1406 89 int getPropertyRangeAndValue(const PropertyName &,
Chris@1551 90 int *min, int *max, int *deflt) const override;
Chris@1406 91 QString getPropertyValueLabel(const PropertyName &,
Chris@1551 92 int value) const override;
Chris@1406 93 void setProperty(const PropertyName &, int value) override;
Chris@30 94
Chris@30 95 enum VerticalScale {
Chris@101 96 AutoAlignScale,
Chris@101 97 LinearScale,
Chris@101 98 LogScale,
Chris@101 99 MIDIRangeScale
Chris@30 100 };
Chris@30 101
Chris@30 102 void setVerticalScale(VerticalScale scale);
Chris@30 103 VerticalScale getVerticalScale() const { return m_verticalScale; }
Chris@30 104
Chris@1406 105 bool isLayerScrollable(const LayerGeometryProvider *v) const override;
Chris@30 106
Chris@1406 107 bool isLayerEditable() const override { return true; }
Chris@30 108
Chris@1470 109 int getCompletion(LayerGeometryProvider *) const override;
Chris@30 110
Chris@1406 111 bool getValueExtents(double &min, double &max,
Chris@1551 112 bool &log, QString &unit) const override;
Chris@101 113
Chris@1406 114 bool getDisplayExtents(double &min, double &max) const override;
Chris@1406 115 bool setDisplayExtents(double min, double max) override;
Chris@439 116
Chris@1406 117 int getVerticalZoomSteps(int &defaultStep) const override;
Chris@1406 118 int getCurrentVerticalZoomStep() const override;
Chris@1406 119 void setVerticalZoomStep(int) override;
Chris@1406 120 RangeMapper *getNewVerticalZoomRangeMapper() const override;
Chris@79 121
Chris@507 122 /**
Chris@507 123 * Add a note-on. Used when recording MIDI "live". The note will
Chris@507 124 * not be finally added to the layer until the corresponding
Chris@507 125 * note-off.
Chris@507 126 */
Chris@905 127 void addNoteOn(sv_frame_t frame, int pitch, int velocity);
Chris@507 128
Chris@507 129 /**
Chris@507 130 * Add a note-off. This will cause a note to appear, if and only
Chris@507 131 * if there is a matching pending note-on.
Chris@507 132 */
Chris@905 133 void addNoteOff(sv_frame_t frame, int pitch);
Chris@507 134
Chris@507 135 /**
Chris@507 136 * Abandon all pending note-on events.
Chris@507 137 */
Chris@507 138 void abandonNoteOns();
Chris@507 139
Chris@1406 140 void toXml(QTextStream &stream, QString indent = "",
Chris@1406 141 QString extraAttributes = "") const override;
Chris@30 142
Chris@1406 143 void setProperties(const QXmlAttributes &attributes) override;
Chris@30 144
Chris@701 145 /// VerticalScaleLayer methods
Chris@1406 146 int getYForValue(LayerGeometryProvider *v, double value) const override;
Chris@1406 147 double getValueForY(LayerGeometryProvider *v, int y) const override;
Chris@1406 148 QString getScaleUnits() const override;
Chris@701 149
Chris@30 150 protected:
Chris@918 151 void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
Chris@30 152
Chris@1406 153 int getDefaultColourHint(bool dark, bool &impose) override;
Chris@287 154
Chris@1424 155 EventVector getLocalPoints(LayerGeometryProvider *v, int) const;
Chris@30 156
Chris@1424 157 bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
Chris@550 158
Chris@1551 159 double convertValueFromEventValue(float eventValue) const;
Chris@1551 160 float convertValueToEventValue(double value) const;
Chris@1551 161
Chris@1551 162 double valueOf(const Event &e) const;
Chris@1551 163 Event eventWithValue(const Event &e, double value) const;
Chris@1551 164
Chris@1470 165 ModelId m_model;
Chris@1551 166 bool m_modelUsesHz;
Chris@30 167 bool m_editing;
Chris@551 168 int m_dragPointX;
Chris@551 169 int m_dragPointY;
Chris@551 170 int m_dragStartX;
Chris@551 171 int m_dragStartY;
Chris@1424 172 Event m_originalPoint;
Chris@1424 173 Event m_editingPoint;
Chris@1427 174 ChangeEventsCommand *m_editingCommand;
Chris@1422 175 bool m_editIsOpen;
Chris@30 176 VerticalScale m_verticalScale;
Chris@376 177
Chris@1424 178 typedef std::set<Event> NoteSet;
Chris@507 179 NoteSet m_pendingNoteOns;
Chris@507 180
Chris@905 181 mutable double m_scaleMinimum;
Chris@905 182 mutable double m_scaleMaximum;
Chris@439 183
Chris@439 184 bool shouldAutoAlign() const;
Chris@439 185
Chris@1427 186 void finish(ChangeEventsCommand *command) {
Chris@376 187 Command *c = command->finish();
Chris@376 188 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@376 189 }
Chris@30 190 };
Chris@30 191
Chris@30 192 #endif
Chris@30 193