MuseScore/libmscore/chord.h

220 lines
7.5 KiB
C
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// 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 __CHORD_H__
#define __CHORD_H__
/**
\file
Definition of classes Chord, HelpLine and NoteList.
*/
2013-03-25 16:27:20 +01:00
#include <functional>
2012-05-26 14:26:10 +02:00
#include "chordrest.h"
2012-11-20 20:51:18 +01:00
#include "noteevent.h"
#include <vector>
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
class QPainter;
namespace Ms {
2012-05-26 14:26:10 +02:00
class Note;
class Hook;
class Arpeggio;
class Tremolo;
class Chord;
class Glissando;
class Stem;
class Chord;
class StemSlash;
class LedgerLine;
2013-06-10 21:13:04 +02:00
class AccidentalState;
2012-05-26 14:26:10 +02:00
enum class TremoloChordType : char { TremoloSingle, TremoloFirstNote, TremoloSecondNote };
enum class PlayEventType : char {
Auto, // Play events for all notes are calculated by MuseScore.
User, // Some play events are modified by user. The events must be written into the mscx file.
InvalidUser // The user modified play events must be replaced by MuseScore generated ones on
// next recalculation. The actual play events must be saved on the undo stack.
};
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2012-07-11 21:29:42 +02:00
// @@ Chord
2012-07-25 11:49:34 +02:00
/// Graphic representation of a chord.
/// Single notes are handled as degenerated chords.
//
// @P notes array[Note] the list of notes (read only)
2012-11-26 15:54:08 +01:00
// @P lyrics array[Lyrics] the list of lyrics (read only)
2013-09-23 12:40:23 +02:00
// @P graceNotes array[Chord] the list of grace note chords (read only)
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class Chord : public ChordRest {
Q_OBJECT
struct LedgerLineData {
int line;
qreal minX, maxX;
bool visible;
bool accidental;
};
2013-05-16 17:06:31 +02:00
Q_PROPERTY(QQmlListProperty<Ms::Note> notes READ qmlNotes)
Q_PROPERTY(QQmlListProperty<Ms::Lyrics> lyrics READ qmlLyrics)
2013-09-23 12:40:23 +02:00
Q_PROPERTY(QQmlListProperty<Ms::Chord> graceNotes READ qmlGraceNotes)
2013-07-15 14:36:51 +02:00
QList<Note*> _notes; // sorted to decreasing line step
LedgerLine* _ledgerLines; // single linked list
2012-05-26 14:26:10 +02:00
Stem* _stem;
Hook* _hook;
2013-06-10 21:13:04 +02:00
StemSlash* _stemSlash; // for acciacatura
2013-03-25 16:27:20 +01:00
2012-05-26 14:26:10 +02:00
Arpeggio* _arpeggio;
Tremolo* _tremolo;
Glissando* _glissando;
2013-06-20 17:23:24 +02:00
ElementList _el; ///< chordline, slur
2013-09-23 12:40:23 +02:00
QList<Chord*> _graceNotes;
2013-06-16 23:33:37 +02:00
int _graceIndex; ///< if this is a grace note, index in parent list
2012-05-26 14:26:10 +02:00
2013-06-10 21:13:04 +02:00
MScore::Direction _stemDirection;
TremoloChordType _tremoloChordType;
NoteType _noteType; ///< mark grace notes: acciaccatura and appoggiatura
bool _noStem;
PlayEventType _playEventType; ///< play events were modified by user
2012-05-26 14:26:10 +02:00
virtual qreal upPos() const;
virtual qreal downPos() const;
virtual qreal centerX() const;
void createLedgerLines(int track, std::vector<LedgerLineData> &vecLines, bool visible);
void addLedgerLines(int move);
2013-03-25 16:27:20 +01:00
void processSiblings(std::function<void(Element*)> func);
2013-06-16 23:33:37 +02:00
void layoutPitched();
2013-05-23 15:39:14 +02:00
void layoutTablature();
2012-05-26 14:26:10 +02:00
public:
Chord(Score* s = 0);
Chord(const Chord&);
~Chord();
Chord &operator=(const Chord&);
virtual Chord* clone() const { return new Chord(*this); }
virtual Chord* linkedClone();
virtual void setScore(Score* s);
virtual ElementType type() const { return CHORD; }
2013-05-28 15:42:02 +02:00
virtual qreal mag() const;
2012-05-26 14:26:10 +02:00
virtual void write(Xml& xml) const;
2013-01-11 18:10:18 +01:00
virtual void read(XmlReader&);
2012-05-26 14:26:10 +02:00
virtual void setSelected(bool f);
virtual Element* drop(const DropData&);
2012-08-04 15:46:43 +02:00
void setStemDirection(MScore::Direction d) { _stemDirection = d; }
MScore::Direction stemDirection() const { return _stemDirection; }
2012-05-26 14:26:10 +02:00
LedgerLine* ledgerLines() { return _ledgerLines; }
2012-05-26 14:26:10 +02:00
2013-01-02 14:33:23 +01:00
void layoutStem1();
2013-07-11 12:25:25 +02:00
void layoutHook1(); // create hook if required
2013-01-02 14:33:23 +01:00
void layoutStem();
2012-05-26 14:26:10 +02:00
void layoutArpeggio2();
QQmlListProperty<Ms::Note> qmlNotes() { return QQmlListProperty<Ms::Note>(this, _notes); }
QQmlListProperty<Ms::Lyrics> qmlLyrics() { return QQmlListProperty<Ms::Lyrics>(this, _lyricsList); }
QQmlListProperty<Ms::Chord> qmlGraceNotes() { return QQmlListProperty<Ms::Chord>(this, _graceNotes); }
QList<Note*>& notes() { return _notes; }
const QList<Note*>& notes() const { return _notes; }
2012-05-26 14:26:10 +02:00
2013-01-02 20:13:58 +01:00
// Chord has at least one Note
Note* upNote() const;
Note* downNote() const;
2012-05-26 14:26:10 +02:00
virtual int upLine() const;
virtual int downLine() const;
virtual int upString() const;
virtual int downString() const;
2012-05-26 14:26:10 +02:00
2013-09-02 19:07:39 +02:00
qreal maxHeadWidth() const;
2012-05-26 14:26:10 +02:00
Note* findNote(int pitch) const;
Stem* stem() const { return _stem; }
void setStem(Stem* s);
Arpeggio* arpeggio() const { return _arpeggio; }
Tremolo* tremolo() const { return _tremolo; }
void setTremolo(Tremolo* t) { _tremolo = t; }
Glissando* glissando() const { return _glissando; }
StemSlash* stemSlash() const { return _stemSlash; }
2013-01-02 09:29:17 +01:00
void setStemSlash(StemSlash* s);
2012-05-26 14:26:10 +02:00
2013-09-23 12:40:23 +02:00
const QList<Chord*>& graceNotes() const { return _graceNotes; }
QList<Chord*>& graceNotes() { return _graceNotes; }
2013-06-16 23:33:37 +02:00
int graceIndex() const { return _graceIndex; }
void setGraceIndex(int val) { _graceIndex = val; }
2013-06-10 21:13:04 +02:00
2013-01-02 14:33:23 +01:00
virtual QPointF stemPos() const; ///< page coordinates
2013-07-29 11:12:32 +02:00
virtual qreal stemPosX() const;
2013-01-02 14:33:23 +01:00
QPointF stemPosBeam() const; ///< page coordinates
2012-05-26 14:26:10 +02:00
Hook* hook() const { return _hook; }
Q_INVOKABLE virtual void add(Ms::Element*);
Q_INVOKABLE virtual void remove(Ms::Element*);
2012-05-26 14:26:10 +02:00
Note* selectedNote() const;
virtual void layout();
void layout2();
2013-06-10 21:13:04 +02:00
void layout10(AccidentalState*);
2012-05-26 14:26:10 +02:00
2012-11-19 09:29:46 +01:00
NoteType noteType() const { return _noteType; }
void setNoteType(NoteType t) { _noteType = t; }
bool isGrace() const { return _noteType != NOTE_NORMAL; }
2012-05-26 14:26:10 +02:00
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true);
virtual void setTrack(int val);
void computeUp();
2012-11-19 09:29:46 +01:00
2012-05-26 14:26:10 +02:00
qreal dotPosX() const;
2012-11-19 09:29:46 +01:00
bool noStem() const { return _noStem; }
void setNoStem(bool val) { _noStem = val; }
2012-11-19 09:29:46 +01:00
PlayEventType playEventType() const { return _playEventType; }
void setPlayEventType(PlayEventType v) { _playEventType = v; }
2012-11-19 09:29:46 +01:00
2013-07-15 14:36:51 +02:00
void lineChanged();
TremoloChordType tremoloChordType() const { return _tremoloChordType; }
void setTremoloChordType(TremoloChordType t) { _tremoloChordType = t; }
2012-05-26 14:26:10 +02:00
2012-11-19 09:29:46 +01:00
ElementList& el() { return _el; }
const ElementList& el() const { return _el; }
2012-05-26 14:26:10 +02:00
QPointF layoutArticulation(Articulation*);
2013-05-12 12:51:42 +02:00
virtual void crossMeasureSetup(bool on);
2012-05-26 14:26:10 +02:00
virtual QVariant getProperty(P_ID propertyId) const;
virtual bool setProperty(P_ID propertyId, const QVariant&);
2013-03-14 13:30:25 +01:00
virtual QVariant propertyDefault(P_ID) const;
2012-11-19 10:08:15 +01:00
virtual void reset();
2013-06-10 21:13:04 +02:00
virtual Segment* segment() const;
virtual Measure* measure() const;
2012-05-26 14:26:10 +02:00
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif