MuseScore/libmscore/chord.h

247 lines
8.9 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.
*/
2014-07-15 18:05:24 +02:00
#include <functional>
2012-05-26 14:26:10 +02:00
#include "chordrest.h"
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;
2012-05-26 14:26:10 +02:00
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
/// Graphic representation of a chord.
/// Single notes are handled as degenerated chords.
2012-07-25 11:49:34 +02:00
//
// @P beam Beam the beam of the chord if any (read only)
// @P graceNotes array[Chord] the list of grace note chords (read only)
// @P hook Hook the hook of the chord if any (read only)
// @P lyrics array[Lyrics] the list of lyrics (read only)
// @P notes array[Note] the list of notes (read only)
// @P stem Stem the stem of the chord if any (read only)
// @P stemSlash StemSlash the stem slash of the chord (acciaccatura) if any (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;
};
Q_PROPERTY(Ms::Beam* beam READ beam)
2013-09-23 12:40:23 +02:00
Q_PROPERTY(QQmlListProperty<Ms::Chord> graceNotes READ qmlGraceNotes)
Q_PROPERTY(Ms::Hook* hook READ hook)
Q_PROPERTY(QQmlListProperty<Ms::Lyrics> lyrics READ qmlLyrics)
Q_PROPERTY(QQmlListProperty<Ms::Note> notes READ qmlNotes)
Q_PROPERTY(Ms::Stem* stem READ stem)
Q_PROPERTY(Ms::StemSlash* stemSlash READ stemSlash)
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;
StemSlash* _stemSlash; // for acciacatura
2013-03-25 16:27:20 +01:00
Arpeggio* _arpeggio;
Tremolo* _tremolo;
Fixes #19155, #22861 (duplicate of the former) and #23100. __References__: Issues: https://musescore.org/en/node/19155 https://musescore.org/en/node/22861 https://musescore.org/en/node/23100 __Description__: Allows to change the start and end note to which a glissando is anchored after it has been entered. Either anchor can be changed independently. The user interface follows the current working of other 'snappable' lines. Once either the start or end grip is selected: - `[Shift]+[Left]` snaps the anchor to the previous chord, defaulting to its top note. - `[Shift]+[Right]` snaps to the next chord, defaulting to its top note. - `[Shift]+[Up]` snaps to the note above (possibly in a chord, voice or staff above the current one). - `[Shift]+[Down]` snaps to the note below (possibly in a chord, voice or staff below the current one). This permits to set the anchor points of a glissando to any note in the score, allowing several glissandi between the notes of the same two chords and other complex configurations (glissandi skipping intermediate chords, start and end notes in different voices or staves, and so on). It is possible to move the anchor to a different staff of the same instrument, but not to a different instrument; also, it is not possible to 'cross' a change of instrument in the same staff. __Known limitations__: - The `[Shift]+[Up]` and `[Shift]+[Down]` use the same note-finding functions as the `[Alt]+[Up]` and `[Alt]+[Down]`actions which move the selection cursor to the above and below note, even across voices or staves. Occasionally, in particular if the note immediately above or below is not time-aligned, the algorithm has little expected results; however, the behaviour is already known to the user. Improving the algorithm would benefit both uses. __Notes__: - Most of the added infrastructure is not specific to glissando but to any spanner anchored to notes, then it should also add after-the-fact "snap to" note support to note-anchored text line. - When moving an anchor, the algorithm usually prefers a note in the same voice/staff of the old note if it exists; if there is none, it tries other voices of the same staff. - The change of anchor is undoable. - The fix corrects the management of the `Chord::_endsGlissando` flag, taking into account that a chord can be the ending point of several glissandi and removing one of them not necessarily means the chord no longer ends a glissando (another glissando may still exists). - The fix also improved the rendering of the glissando wavy line, with better alignment with anchor notes and, with glissando text, better text-line spacing.
2015-08-06 11:11:16 +02:00
bool _endsGlissando;///< true if this chord is the ending point of a glissando (needed for layout)
ElementList _el; ///< chordline, slur
QList<Chord*> _graceNotes;
int _graceIndex; ///< if this is a grace note, index in parent list
2012-05-26 14:26:10 +02:00
MScore::Direction _stemDirection;
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
2016-01-04 14:48:58 +01:00
qreal _spaceLw;
qreal _spaceRw;
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);
2016-01-04 14:48:58 +01:00
void processSiblings(std::function<void(Element*)> func) const;
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);
2014-06-27 13:41:49 +02:00
Chord(const Chord&, bool link = false);
2012-05-26 14:26:10 +02:00
~Chord();
2014-06-27 13:41:49 +02:00
Chord &operator=(const Chord&) = delete;
2012-05-26 14:26:10 +02:00
2014-06-27 13:41:49 +02:00
virtual Chord* clone() const { return new Chord(*this, false); }
virtual Element* linkedClone() { return new Chord(*this, true); }
2014-08-07 10:55:36 +02:00
virtual void undoUnlink() override;
2012-05-26 14:26:10 +02:00
virtual void setScore(Score* s);
virtual Element::Type type() const { return Element::Type::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&);
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
qreal defaultStemLength();
2013-01-02 14:33:23 +01:00
void layoutStem1();
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;
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; }
Arpeggio* arpeggio() const { return _arpeggio; }
Tremolo* tremolo() const { return _tremolo; }
void setTremolo(Tremolo* t) { _tremolo = t; }
bool endsGlissando() const { return _endsGlissando; }
void setEndsGlissando (bool val) { _endsGlissando = val; }
Fixes #19155, #22861 (duplicate of the former) and #23100. __References__: Issues: https://musescore.org/en/node/19155 https://musescore.org/en/node/22861 https://musescore.org/en/node/23100 __Description__: Allows to change the start and end note to which a glissando is anchored after it has been entered. Either anchor can be changed independently. The user interface follows the current working of other 'snappable' lines. Once either the start or end grip is selected: - `[Shift]+[Left]` snaps the anchor to the previous chord, defaulting to its top note. - `[Shift]+[Right]` snaps to the next chord, defaulting to its top note. - `[Shift]+[Up]` snaps to the note above (possibly in a chord, voice or staff above the current one). - `[Shift]+[Down]` snaps to the note below (possibly in a chord, voice or staff below the current one). This permits to set the anchor points of a glissando to any note in the score, allowing several glissandi between the notes of the same two chords and other complex configurations (glissandi skipping intermediate chords, start and end notes in different voices or staves, and so on). It is possible to move the anchor to a different staff of the same instrument, but not to a different instrument; also, it is not possible to 'cross' a change of instrument in the same staff. __Known limitations__: - The `[Shift]+[Up]` and `[Shift]+[Down]` use the same note-finding functions as the `[Alt]+[Up]` and `[Alt]+[Down]`actions which move the selection cursor to the above and below note, even across voices or staves. Occasionally, in particular if the note immediately above or below is not time-aligned, the algorithm has little expected results; however, the behaviour is already known to the user. Improving the algorithm would benefit both uses. __Notes__: - Most of the added infrastructure is not specific to glissando but to any spanner anchored to notes, then it should also add after-the-fact "snap to" note support to note-anchored text line. - When moving an anchor, the algorithm usually prefers a note in the same voice/staff of the old note if it exists; if there is none, it tries other voices of the same staff. - The change of anchor is undoable. - The fix corrects the management of the `Chord::_endsGlissando` flag, taking into account that a chord can be the ending point of several glissandi and removing one of them not necessarily means the chord no longer ends a glissando (another glissando may still exists). - The fix also improved the rendering of the glissando wavy line, with better alignment with anchor notes and, with glissando text, better text-line spacing.
2015-08-06 11:11:16 +02:00
void updateEndsGlissando();
2012-05-26 14:26:10 +02:00
StemSlash* stemSlash() const { return _stemSlash; }
bool slash();
void setSlash(bool flag, bool stemless);
void removeMarkings(bool keepTremolo = false);
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; }
2015-02-19 10:28:25 +01:00
QList<Chord*> graceNotesBefore() const;
QList<Chord*> graceNotesAfter() const;
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
2014-05-17 15:48:18 +02:00
virtual int upLine() const;
virtual int downLine() const;
virtual QPointF stemPos() const; ///< page coordinates
virtual QPointF stemPosBeam() const; ///< page coordinates
2013-07-29 11:12:32 +02:00
virtual qreal stemPosX() const;
2014-04-23 18:07:38 +02:00
bool underBeam() const;
2012-05-26 14:26:10 +02:00
Hook* hook() const { return _hook; }
//@ add an element to the Chord
Q_INVOKABLE virtual void add(Ms::Element*);
//@ remove the element from the Chord
Q_INVOKABLE virtual void remove(Ms::Element*);
2012-05-26 14:26:10 +02:00
Note* selectedNote() const;
virtual void layout();
virtual QPointF pagePos() const override; ///< position in page coordinates
2012-05-26 14:26:10 +02:00
void layout2();
2014-04-22 17:02:03 +02:00
void cmdUpdateNotes(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; }
2014-05-27 10:35:28 +02:00
bool isGrace() const { return _noteType != NoteType::NORMAL; }
2014-04-23 18:07:38 +02:00
void toGraceAfter();
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) override;
2012-05-26 14:26:10 +02:00
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
2014-05-15 13:42:03 +02:00
TremoloChordType tremoloChordType() const;
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);
2015-01-15 14:50:50 +01:00
virtual QVariant getProperty(P_ID propertyId) const override;
virtual bool setProperty(P_ID propertyId, const QVariant&) override;
virtual QVariant propertyDefault(P_ID) const override;
2013-03-14 13:30:25 +01:00
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;
void sortNotes();
virtual Element* nextElement() override;
virtual Element* prevElement() override;
2016-02-04 17:06:32 +01:00
virtual QString accessibleExtraInfo() const override;
2016-01-04 14:48:58 +01:00
virtual Shape shape() const override;
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