svgui
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _NOTE_LAYER_H_ 00017 #define _NOTE_LAYER_H_ 00018 00019 #include "SingleColourLayer.h" 00020 #include "VerticalScaleLayer.h" 00021 00022 #include "data/model/NoteModel.h" 00023 00024 #include <QObject> 00025 #include <QColor> 00026 00027 class View; 00028 class QPainter; 00029 00030 class NoteLayer : public SingleColourLayer, 00031 public VerticalScaleLayer 00032 { 00033 Q_OBJECT 00034 00035 public: 00036 NoteLayer(); 00037 00038 virtual void paint(View *v, QPainter &paint, QRect rect) const; 00039 00040 virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; 00041 virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; 00042 00043 virtual QString getFeatureDescription(View *v, QPoint &) const; 00044 00045 virtual bool snapToFeatureFrame(View *v, int &frame, 00046 int &resolution, 00047 SnapType snap) const; 00048 00049 virtual void drawStart(View *v, QMouseEvent *); 00050 virtual void drawDrag(View *v, QMouseEvent *); 00051 virtual void drawEnd(View *v, QMouseEvent *); 00052 00053 virtual void eraseStart(View *v, QMouseEvent *); 00054 virtual void eraseDrag(View *v, QMouseEvent *); 00055 virtual void eraseEnd(View *v, QMouseEvent *); 00056 00057 virtual void editStart(View *v, QMouseEvent *); 00058 virtual void editDrag(View *v, QMouseEvent *); 00059 virtual void editEnd(View *v, QMouseEvent *); 00060 00061 virtual bool editOpen(View *v, QMouseEvent *); 00062 00063 virtual void moveSelection(Selection s, int newStartFrame); 00064 virtual void resizeSelection(Selection s, Selection newSize); 00065 virtual void deleteSelection(Selection s); 00066 00067 virtual void copy(View *v, Selection s, Clipboard &to); 00068 virtual bool paste(View *v, const Clipboard &from, int frameOffset, 00069 bool interactive); 00070 00071 virtual const Model *getModel() const { return m_model; } 00072 void setModel(NoteModel *model); 00073 00074 virtual PropertyList getProperties() const; 00075 virtual QString getPropertyLabel(const PropertyName &) const; 00076 virtual PropertyType getPropertyType(const PropertyName &) const; 00077 virtual QString getPropertyGroupName(const PropertyName &) const; 00078 virtual int getPropertyRangeAndValue(const PropertyName &, 00079 int *min, int *max, int *deflt) const; 00080 virtual QString getPropertyValueLabel(const PropertyName &, 00081 int value) const; 00082 virtual void setProperty(const PropertyName &, int value); 00083 00084 enum VerticalScale { 00085 AutoAlignScale, 00086 LinearScale, 00087 LogScale, 00088 MIDIRangeScale 00089 }; 00090 00091 void setVerticalScale(VerticalScale scale); 00092 VerticalScale getVerticalScale() const { return m_verticalScale; } 00093 00094 virtual bool isLayerScrollable(const View *v) const; 00095 00096 virtual bool isLayerEditable() const { return true; } 00097 00098 virtual int getCompletion(View *) const { return m_model->getCompletion(); } 00099 00100 virtual bool getValueExtents(float &min, float &max, 00101 bool &log, QString &unit) const; 00102 00103 virtual bool getDisplayExtents(float &min, float &max) const; 00104 virtual bool setDisplayExtents(float min, float max); 00105 00106 virtual int getVerticalZoomSteps(int &defaultStep) const; 00107 virtual int getCurrentVerticalZoomStep() const; 00108 virtual void setVerticalZoomStep(int); 00109 virtual RangeMapper *getNewVerticalZoomRangeMapper() const; 00110 00116 void addNoteOn(int frame, int pitch, int velocity); 00117 00122 void addNoteOff(int frame, int pitch); 00123 00127 void abandonNoteOns(); 00128 00129 virtual void toXml(QTextStream &stream, QString indent = "", 00130 QString extraAttributes = "") const; 00131 00132 void setProperties(const QXmlAttributes &attributes); 00133 00135 virtual int getYForValue(View *v, float value) const; 00136 virtual float getValueForY(View *v, int y) const; 00137 virtual QString getScaleUnits() const; 00138 00139 protected: 00140 void getScaleExtents(View *, float &min, float &max, bool &log) const; 00141 bool shouldConvertMIDIToHz() const; 00142 00143 virtual int getDefaultColourHint(bool dark, bool &impose); 00144 00145 NoteModel::PointList getLocalPoints(View *v, int) const; 00146 00147 bool getPointToDrag(View *v, int x, int y, NoteModel::Point &) const; 00148 00149 NoteModel *m_model; 00150 bool m_editing; 00151 int m_dragPointX; 00152 int m_dragPointY; 00153 int m_dragStartX; 00154 int m_dragStartY; 00155 NoteModel::Point m_originalPoint; 00156 NoteModel::Point m_editingPoint; 00157 NoteModel::EditCommand *m_editingCommand; 00158 VerticalScale m_verticalScale; 00159 00160 typedef std::set<NoteModel::Point, NoteModel::Point::Comparator> NoteSet; 00161 NoteSet m_pendingNoteOns; 00162 00163 mutable float m_scaleMinimum; 00164 mutable float m_scaleMaximum; 00165 00166 bool shouldAutoAlign() const; 00167 00168 void finish(NoteModel::EditCommand *command) { 00169 Command *c = command->finish(); 00170 if (c) CommandHistory::getInstance()->addCommand(c, false); 00171 } 00172 }; 00173 00174 #endif 00175