svgui  1.9
FlexiNoteLayer.h
Go to the documentation of this file.
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 _FLEXINOTE_LAYER_H_
00017 #define _FLEXINOTE_LAYER_H_
00018 
00019 #define NOTE_HEIGHT 16
00020 
00021 #include "SingleColourLayer.h"
00022 #include "VerticalScaleLayer.h"
00023 
00024 #include "data/model/FlexiNoteModel.h"
00025 
00026 #include <QObject>
00027 #include <QColor>
00028 
00029 class View;
00030 class QPainter;
00031 class SparseTimeValueModel;
00032 
00033 class FlexiNoteLayer : public SingleColourLayer,
00034                        public VerticalScaleLayer
00035 {
00036     Q_OBJECT
00037 
00038 public:
00039     FlexiNoteLayer();
00040 
00041     virtual void paint(View *v, QPainter &paint, QRect rect) const;
00042 
00043     virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const;
00044     virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const;
00045 
00046     virtual QString getFeatureDescription(View *v, QPoint &) const;
00047 
00048     virtual bool snapToFeatureFrame(View *v, int &frame,
00049                     int &resolution,
00050                     SnapType snap) const;
00051 
00052     virtual void drawStart(View *v, QMouseEvent *);
00053     virtual void drawDrag(View *v, QMouseEvent *);
00054     virtual void drawEnd(View *v, QMouseEvent *);
00055 
00056     virtual void eraseStart(View *v, QMouseEvent *);
00057     virtual void eraseDrag(View *v, QMouseEvent *);
00058     virtual void eraseEnd(View *v, QMouseEvent *);
00059 
00060     virtual void editStart(View *v, QMouseEvent *);
00061     virtual void editDrag(View *v, QMouseEvent *);
00062     virtual void editEnd(View *v, QMouseEvent *);
00063 
00064     virtual void splitStart(View *v, QMouseEvent *);
00065     virtual void splitEnd(View *v, QMouseEvent *);
00066     
00067     virtual void addNote(View *v, QMouseEvent *e);
00068 
00069     virtual void mouseMoveEvent(View *v, QMouseEvent *);
00070 
00071     virtual bool editOpen(View *v, QMouseEvent *);
00072 
00073     virtual void moveSelection(Selection s, int newStartFrame);
00074     virtual void resizeSelection(Selection s, Selection newSize);
00075     virtual void deleteSelection(Selection s);
00076     virtual void deleteSelectionInclusive(Selection s);
00077 
00078     virtual void copy(View *v, Selection s, Clipboard &to);
00079     virtual bool paste(View *v, const Clipboard &from, int frameOffset,
00080                        bool interactive);
00081 
00082     void splitNotesAt(View *v, int frame);
00083     void snapSelectedNotesToPitchTrack(View *v, Selection s);
00084     void mergeNotes(View *v, Selection s, bool inclusive);
00085 
00086     virtual const Model *getModel() const { return m_model; }
00087     void setModel(FlexiNoteModel *model);
00088 
00089     virtual PropertyList getProperties() const;
00090     virtual QString getPropertyLabel(const PropertyName &) const;
00091     virtual PropertyType getPropertyType(const PropertyName &) const;
00092     virtual QString getPropertyGroupName(const PropertyName &) const;
00093     virtual int getPropertyRangeAndValue(const PropertyName &,
00094                                          int *min, int *max, int *deflt) const;
00095     virtual QString getPropertyValueLabel(const PropertyName &,
00096                       int value) const;
00097     virtual void setProperty(const PropertyName &, int value);
00098 
00099     enum VerticalScale {
00100         AutoAlignScale,
00101         LinearScale,
00102         LogScale,
00103         MIDIRangeScale
00104     };
00105     
00106     //GF: Tonioni: context sensitive note edit actions (denoted clockwise from top).
00107     enum EditMode {
00108         DragNote,
00109         RightBoundary,
00110         SplitNote,
00111         LeftBoundary
00112     };
00113     
00114     void setIntelligentActions(bool on) { m_intelligentActions=on; }
00115 
00116     void setVerticalScale(VerticalScale scale);
00117     VerticalScale getVerticalScale() const { return m_verticalScale; }
00118 
00119     virtual bool isLayerScrollable(const View *v) const;
00120 
00121     virtual bool isLayerEditable() const { return true; }
00122 
00123     virtual int getCompletion(View *) const { return m_model->getCompletion(); }
00124 
00125     virtual bool getValueExtents(float &min, float &max,
00126                                  bool &log, QString &unit) const;
00127 
00128     virtual bool getDisplayExtents(float &min, float &max) const;
00129     virtual bool setDisplayExtents(float min, float max);
00130 
00131     virtual int getVerticalZoomSteps(int &defaultStep) const;
00132     virtual int getCurrentVerticalZoomStep() const;
00133     virtual void setVerticalZoomStep(int);
00134     virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
00135 
00141     void addNoteOn(int frame, int pitch, int velocity);
00142     
00147     void addNoteOff(int frame, int pitch);
00148 
00152     void abandonNoteOns();
00153 
00154     virtual void toXml(QTextStream &stream, QString indent = "",
00155                        QString extraAttributes = "") const;
00156 
00157     void setProperties(const QXmlAttributes &attributes);
00158     
00159     void setVerticalRangeToNoteRange(View *v);
00160 
00162     virtual int getYForValue(View *v, float value) const;
00163     virtual float getValueForY(View *v, int y) const;
00164     virtual QString getScaleUnits() const;
00165 
00166 protected:
00167     void getScaleExtents(View *, float &min, float &max, bool &log) const;
00168     bool shouldConvertMIDIToHz() const;
00169 
00170     virtual int getDefaultColourHint(bool dark, bool &impose);
00171 
00172     FlexiNoteModel::PointList getLocalPoints(View *v, int) const;
00173 
00174     bool getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &) const;
00175     bool getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &) const;
00176     void getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const;
00177     SparseTimeValueModel *getAssociatedPitchModel(View *v) const;
00178     bool updateNoteValue(View *v, FlexiNoteModel::Point &note) const;
00179     void splitNotesAt(View *v, int frame, QMouseEvent *e);
00180 
00181     FlexiNoteModel *m_model;
00182     bool m_editing;
00183     bool m_intelligentActions;
00184     int m_dragPointX;
00185     int m_dragPointY;
00186     int m_dragStartX;
00187     int m_dragStartY;
00188     FlexiNoteModel::Point m_originalPoint;
00189     FlexiNoteModel::Point m_editingPoint;
00190     int m_greatestLeftNeighbourFrame;
00191     int m_smallestRightNeighbourFrame;
00192     FlexiNoteModel::EditCommand *m_editingCommand;
00193     VerticalScale m_verticalScale;
00194     EditMode m_editMode;
00195 
00196     typedef std::set<FlexiNoteModel::Point, FlexiNoteModel::Point::Comparator> FlexiNoteSet;
00197     FlexiNoteSet m_pendingNoteOns;
00198 
00199     mutable float m_scaleMinimum;
00200     mutable float m_scaleMaximum;
00201 
00202     bool shouldAutoAlign() const;
00203 
00204     void finish(FlexiNoteModel::EditCommand *command) {
00205         Command *c = command->finish();
00206         if (c) CommandHistory::getInstance()->addCommand(c, false);
00207     }
00208 };
00209 
00210 #endif
00211