Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7c7d7a38b2
Fetching contributors…

Cannot retrieve contributors at this time

file 338 lines (280 sloc) 13.61 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
//=============================================================================
// MuseScore
// Music Composition & Notation
// $Id: note.h 5534 2012-04-12 17:40:51Z wschweer $
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#ifndef __NOTE_H__
#define __NOTE_H__

/**
\file
Definition of classes Note and NoteHead.
*/

#include "element.h"
#include "symbol.h"
#include "durationtype.h"

class Tie;
class Chord;
class NoteEvent;
class Text;
class Score;
class Sym;
class MuseScoreView;
class Bend;
class QPainter;
class AccidentalState;
class Accidental;
class Spanner;
class NoteDot;
class Note;

//---------------------------------------------------------
// NoteVal
// helper structure
//---------------------------------------------------------

struct NoteVal {
      int pitch;
      int tpc;
      int fret;
      int string;
      int headGroup;
      NoteVal();
      };

//---------------------------------------------------------
// @@ NoteHead
//---------------------------------------------------------

class NoteHead : public Symbol {
      Q_OBJECT

   public:
      NoteHead(Score* s) : Symbol(s) {}
      NoteHead &operator=(const NoteHead&);
      virtual NoteHead* clone() const { return new NoteHead(*this); }
      virtual ElementType type() const { return NOTEHEAD; }
      virtual void write(Xml& xml) const;
      };

//---------------------------------------------------------------------------------------
// @@ Note
/// Graphic representation of a note.
//
// @P pitch int midi pitch
// @P tpc int tonal pitch class
// @P line int notehead position
// @P fret int fret number in tablature
// @P string int string number in tablature
// @P subchannel int midi subchannel (for midi articulation)
// @P ppitch int actual played midi pitch (honoring ottavas)
// @P ghost bool ghost note (guitar: death note)
// @P hidden bool hidden, not played note
// @P mirror bool mirror note head on x axis
// @P small bool small note head
// @P tuning qreal tuning offset in cent
// @P veloType enum OFFSET_VAL, USER_VAL
// @P veloOffset int
// @P onTimeOffset int
// @P onTimeUserOffset int
// @P offTimeOffset int
// @P offTimeUserOffset int
// @P userMirror enum DH_AUTO, DH_LEFT, DH_RIGHT
// @P dotPosition enum AUTO, UP, DOWN
// @P headGroup enum HEAD_NORMAL, HEAD_CROSS, HEAD_DIAMOND, HEAD_TRIANGLE, HEAD_MI, HEAD_SLASH, HEAD_XCIRCLE, HEAD_DO, HEAD_RE, HEAD_FA, HEAD_LA, HEAD_TI, HEAD_SOL, HEAD_BREVIS_ALT
// @P headType enum HEAD_AUTO, HEAD_WHOLE, HEAD_HALF, HEAD_QUARTER, HEAD_BREVIS
//---------------------------------------------------------------------------------------

class Note : public Element {
   public:
      enum NoteHeadGroup {
            HEAD_NORMAL = 0, HEAD_CROSS, HEAD_DIAMOND, HEAD_TRIANGLE, HEAD_MI,
            HEAD_SLASH, HEAD_XCIRCLE, HEAD_DO, HEAD_RE, HEAD_FA, HEAD_LA, HEAD_TI,
            HEAD_SOL,
            HEAD_BREVIS_ALT,
            HEAD_GROUPS,
            HEAD_INVALID = -1
            };
      enum NoteHeadType { HEAD_AUTO, HEAD_WHOLE, HEAD_HALF, HEAD_QUARTER, HEAD_BREVIS };

   private:
      Q_OBJECT
      Q_PROPERTY(int subchannel READ subchannel)
      Q_PROPERTY(int line READ line)
      Q_PROPERTY(int fret READ fret WRITE undoSetFret)
      Q_PROPERTY(int string READ string WRITE undoSetString)
      Q_PROPERTY(int tpc READ tpc WRITE undoSetTpc)
      Q_PROPERTY(int pitch READ pitch WRITE undoSetPitch)
      Q_PROPERTY(int ppitch READ ppitch)
      Q_PROPERTY(bool ghost READ ghost WRITE undoSetGhost)
      Q_PROPERTY(bool hidden READ hidden)
      Q_PROPERTY(bool mirror READ mirror)
      Q_PROPERTY(bool small READ small WRITE undoSetSmall)
      Q_PROPERTY(qreal tuning READ tuning WRITE undoSetTuning)
      Q_PROPERTY(MScore::ValueType veloType READ veloType WRITE undoSetVeloType)
      Q_PROPERTY(int veloOffset READ veloOffset WRITE undoSetVeloOffset)
      Q_PROPERTY(int onTimeOffset READ onTimeOffset)
      Q_PROPERTY(int onTimeUserOffset READ onTimeUserOffset WRITE undoSetOnTimeUserOffset)
      Q_PROPERTY(int offTimeOffset READ offTimeOffset)
      Q_PROPERTY(int offTimeUserOffset READ offTimeUserOffset WRITE undoSetOffTimeUserOffset)
      Q_PROPERTY(MScore::DirectionH userMirror READ userMirror WRITE undoSetUserMirror)
      Q_PROPERTY(MScore::Direction dotPosition READ dotPosition WRITE undoSetDotPosition)
      Q_PROPERTY(NoteHeadGroup headGroup READ headGroup WRITE undoSetHeadGroup)
      Q_PROPERTY(NoteHeadType headType READ headType WRITE undoSetHeadType)

      int _subchannel; ///< articulation
      int _line; ///< y-Position; 0 - top line.
      int _fret; ///< for tablature view
      int _string;
      NoteHeadGroup _headGroup;
      mutable int _tpc; ///< tonal pitch class
      mutable int _pitch; ///< Note pitch as midi value (0 - 127).
      int _ppitch; ///< played pitch (honor ottavas etc.); cached value
      bool _ghost; ///< ghost note (guitar: death note)
      bool _hidden; ///< markes this note as the hidden one if there are
                              ///< overlapping notes; hidden notes are not played
                              ///< and heads + accidentals are not shown
      bool _fretConflict; ///< used by TAB staves to mark a fretting conflict:
                              ///< two or mor enotes on the same string

      bool dragMode;
      bool _mirror; ///< True if note is mirrored at stem.
      bool _small;

      NoteHeadType _headType;
      MScore::ValueType _veloType;
      int _veloOffset; ///< velocity user offset in percent, or absolute velocity for this note

      qreal _tuning; ///< pitch offset in cent, playable only by internal synthesizer

      int _onTimeOffset; ///< start note offset in ticks
      int _onTimeUserOffset; ///< start note user offset

      int _offTimeOffset; ///< stop note offset in ticks
      int _offTimeUserOffset; ///< stop note user offset

      MScore::DirectionH _userMirror; ///< user override of mirror
      MScore::Direction _dotPosition; ///< dot position: above or below current staff line

      Accidental* _accidental;

      ElementList _el; ///< fingering, other text, symbols or images
      Tie* _tieFor;
      Tie* _tieBack;
      Bend* _bend;

      NoteDot* _dots[3];

      QList<NoteEvent*> _playEvents;

      int _lineOffset; ///< Used during mouse dragging.

      virtual QRectF drag(const EditData& s);
      void endDrag();
      void endEdit();

   public:
      Note(Score* s = 0);
      Note(const Note&);
      Note &operator=(const Note&);
      ~Note();
      Note* clone() const { return new Note(*this); }
      ElementType type() const { return NOTE; }
      QPointF pagePos() const; ///< position in page coordinates
      QPointF canvasPos() const; ///< position in page coordinates
      void layout();
      void layout2();
      void layout10(AccidentalState*);
      void scanElements(void* data, void (*func)(void*, Element*), bool all=true);
      void setTrack(int val);

      int playTicks() const;

      qreal headWidth() const;
      qreal headHeight() const;
      int noteHead() const;
      NoteHeadGroup headGroup() const { return _headGroup; }
      NoteHeadType headType() const { return _headType; }
      void setHeadGroup(NoteHeadGroup val);
      void setHeadType(NoteHeadType t) { _headType = t; }

      int pitch() const { return _pitch; }
      void setPitch(int val);
      void undoSetPitch(int val);
      void setPitch(int a, int b);
      int ppitch() const;
      qreal tuning() const { return _tuning; }
      void setTuning(qreal v) { _tuning = v; }

      int tpc() const { return _tpc; }
      void setTpc(int v);
      void undoSetTpc(int v);
      void setTpcFromPitch();

      Q_INVOKABLE Accidental* accidental() const { return _accidental; }
      void setAccidental(Accidental* a) { _accidental = a; }

      int line() const { return _line + _lineOffset; }
      void setLine(int n);

      int fret() const { return _fret; }
      void setFret(int val) { _fret = val; }
      int string() const { return _string; }
      void setString(int val);
      bool ghost() const { return _ghost; }
      void setGhost(bool val) { _ghost = val; }
      bool fretConflict() const { return _fretConflict; }
      void setFretConflict(bool val) { _fretConflict = val; }

      virtual void add(Element*);
      virtual void remove(Element*);

      bool mirror() const { return _mirror; }
      void setMirror(bool val) { _mirror = val; }

      bool small() const { return _small; }
      void setSmall(bool val) { _small = val; }

      Q_INVOKABLE Tie* tieFor() const { return _tieFor; }
      Q_INVOKABLE Tie* tieBack() const { return _tieBack; }
      void setTieFor(Tie* t) { _tieFor = t; }
      void setTieBack(Tie* t) { _tieBack = t; }

      Chord* chord() const { return (Chord*)parent(); }
      void setChord(Chord* a) { setParent((Element*)a); }

      void draw(QPainter*) const;

      void read(const QDomElement&);
      void write(Xml& xml) const;

      QPointF stemPos(bool upFlag) const; ///< Point to connect stem.

      bool acceptDrop(MuseScoreView*, const QPointF&, Element*) const;
      Element* drop(const DropData&);

      bool hidden() const { return _hidden; }
      void setHidden(bool val) { _hidden = val; }

      NoteType noteType() const;

      ElementList el() { return _el; }
      const ElementList el() const { return _el; }

      int subchannel() const { return _subchannel; }
      void setSubchannel(int val) { _subchannel = val; }

      MScore::DirectionH userMirror() const { return _userMirror; }
      void setUserMirror(MScore::DirectionH d) { _userMirror = d; }

      MScore::Direction dotPosition() const { return _dotPosition; }
      void setDotPosition(MScore::Direction d) { _dotPosition = d; }
      bool dotIsUp() const; // actual dot position

      void toDefault();
      void setMag(qreal val);

      MScore::ValueType veloType() const { return _veloType; }
      void setVeloType(MScore::ValueType v) { _veloType = v; }
      int veloOffset() const { return _veloOffset; }
      void setVeloOffset(int v) { _veloOffset = v; }

      int onTimeOffset() const { return _onTimeOffset; }
      void setOnTimeOffset(int v) { _onTimeOffset = v; }
      int onTimeUserOffset() const { return _onTimeUserOffset; }
      void setOnTimeUserOffset(int v) { _onTimeUserOffset = v; }

      int offTimeOffset() const { return _offTimeOffset; }
      void setOffTimeOffset(int v) { _offTimeOffset = v; }
      int offTimeUserOffset() const { return _offTimeUserOffset; }
      void setOffTimeUserOffset(int v) { _offTimeUserOffset = v; }

      void setBend(Bend* b) { _bend = b; }
      int customizeVelocity(int velo) const;
      Q_INVOKABLE NoteDot* dot(int n) { return _dots[n]; }
      void updateAccidental(AccidentalState*);
      void updateLine();
      void setNval(NoteVal);
      QList<NoteEvent*>& playEvents() { return _playEvents; }
      const QList<NoteEvent*>& playEvents() const { return _playEvents; }
      void setPlayEvents(const QList<NoteEvent*>& v);

      void undoSetFret(int);
      void undoSetString(int);
      void undoSetGhost(bool);
      void undoSetMirror(bool);
      void undoSetSmall(bool);
      void undoSetTuning(qreal);
      void undoSetVeloType(MScore::ValueType);
      void undoSetVeloOffset(int);
      void undoSetOnTimeUserOffset(int);
      void undoSetOffTimeUserOffset(int);
      void undoSetUserMirror(MScore::DirectionH);
      void undoSetDotPosition(MScore::Direction);
      void undoSetHeadGroup(NoteHeadGroup);
      void undoSetHeadType(NoteHeadType);

      virtual QVariant getProperty(P_ID propertyId) const;
      virtual bool setProperty(P_ID propertyId, const QVariant&);
      virtual QVariant propertyDefault(P_ID) const;
      };

Q_DECLARE_METATYPE(Note::NoteHeadGroup)
Q_DECLARE_METATYPE(Note::NoteHeadType)

extern Sym* noteHeadSym(bool up, int group, int n);
extern const int noteHeads[2][Note::HEAD_GROUPS][HEAD_TYPES];

#endif
Something went wrong with that request. Please try again.