MuseScore/libmscore/beam.h

163 lines
5.2 KiB
C
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2012 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 __BEAM_H__
#define __BEAM_H__
#include "element.h"
#include "durationtype.h"
2018-03-19 16:59:31 +01:00
#include "property.h"
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
class ChordRest;
class MuseScoreView;
class Chord;
2014-07-09 18:05:58 +02:00
class System;
class Skyline;
2017-07-19 17:53:45 +02:00
enum class SpannerSegmentType;
2012-05-26 14:26:10 +02:00
struct BeamFragment;
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ Beam
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class Beam final : public Element {
2016-03-19 11:41:38 +01:00
QVector<ChordRest*> _elements; // must be sorted by tick
QVector<QLineF*> beamSegments;
2016-03-02 13:20:19 +01:00
Direction _direction;
2013-08-13 16:52:34 +02:00
2012-05-26 14:26:10 +02:00
bool _up;
bool _distribute; // equal spacing of elements
2013-08-13 16:52:34 +02:00
bool _noSlope;
bool _userModified[2]; // 0: auto/down 1: up
2014-10-28 13:45:35 +01:00
bool _isGrace;
bool _cross;
2013-08-13 16:52:34 +02:00
2012-05-26 14:26:10 +02:00
qreal _grow1; // define "feather" beams
qreal _grow2;
qreal _beamDist;
2016-03-19 11:41:38 +01:00
QVector<BeamFragment*> fragments; // beam splits across systems
2012-05-26 14:26:10 +02:00
mutable int _id; // used in read()/write()
int minMove; // set in layout1()
int maxMove;
TDuration maxDuration;
qreal slope { 0.0 };
2012-05-26 14:26:10 +02:00
2016-03-19 11:41:38 +01:00
void layout2(std::vector<ChordRest*>, SpannerSegmentType, int frag);
2012-05-26 14:26:10 +02:00
bool twoBeamedNotes();
2016-03-19 11:41:38 +01:00
void computeStemLen(const std::vector<ChordRest*>& crl, qreal& py1, int beamLevels);
bool slopeZero(const std::vector<ChordRest*>& crl);
2013-08-13 16:52:34 +02:00
bool hasNoSlope();
void addChordRest(ChordRest* a);
void removeChordRest(ChordRest* a);
2012-05-26 14:26:10 +02:00
public:
enum class Mode : signed char {
AUTO, BEGIN, MID, END, NONE, BEGIN32, BEGIN64, INVALID = -1
};
2015-04-03 18:23:51 +02:00
Q_ENUMS(Mode)
Beam(Score* = 0);
2012-05-26 14:26:10 +02:00
Beam(const Beam&);
~Beam();
2013-08-13 16:52:34 +02:00
virtual Beam* clone() const override { return new Beam(*this); }
virtual ElementType type() const override { return ElementType::BEAM; }
2013-08-13 16:52:34 +02:00
virtual QPointF pagePos() const override; ///< position in page coordinates
virtual QPointF canvasPos() const override; ///< position in page coordinates
2012-05-26 14:26:10 +02:00
2013-08-13 16:52:34 +02:00
virtual bool isEditable() const override { return true; }
2017-03-31 13:03:15 +02:00
virtual void startEdit(EditData&) override;
virtual void endEdit(EditData&) override;
virtual void editDrag(EditData&) override;
virtual void updateGrips(EditData&) const override;
2012-05-26 14:26:10 +02:00
2017-03-14 17:00:38 +01:00
virtual int tick() const override;
virtual int rtick() const override;
2016-11-19 11:51:21 +01:00
virtual void write(XmlWriter& xml) const override;
2013-08-13 16:52:34 +02:00
virtual void read(XmlReader&) override;
virtual void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/) override;
2012-05-26 14:26:10 +02:00
2013-08-13 16:52:34 +02:00
virtual void reset() override;
2012-05-26 14:26:10 +02:00
System* system() const { return (System*)parent(); }
void layout1();
2013-06-16 23:33:37 +02:00
void layoutGraceNotes();
2012-05-26 14:26:10 +02:00
void layout();
2016-03-19 11:41:38 +01:00
const QVector<ChordRest*>& elements() { return _elements; }
2012-05-26 14:26:10 +02:00
void clear() { _elements.clear(); }
2016-02-06 22:03:43 +01:00
bool empty() const { return _elements.empty(); }
2013-08-13 16:52:34 +02:00
virtual void add(Element*) override;
virtual void remove(Element*) override;
2013-08-13 16:52:34 +02:00
2015-05-08 08:57:24 +02:00
virtual void move(const QPointF&) override;
2013-08-13 16:52:34 +02:00
virtual void draw(QPainter*) const override;
2012-05-26 14:26:10 +02:00
bool up() const { return _up; }
void setUp(bool v) { _up = v; }
void setId(int i) const { _id = i; }
int id() const { return _id; }
2013-08-13 16:52:34 +02:00
bool noSlope() const { return _noSlope; }
void setNoSlope(bool val) { _noSlope = val; }
2012-05-26 14:26:10 +02:00
2016-03-02 13:20:19 +01:00
void setBeamDirection(Direction d);
Direction beamDirection() const { return _direction; }
2012-05-26 14:26:10 +02:00
2017-03-31 13:03:15 +02:00
virtual bool acceptDrop(EditData&) const override;
virtual Element* drop(EditData&) override;
2012-05-26 14:26:10 +02:00
qreal growLeft() const { return _grow1; }
qreal growRight() const { return _grow2; }
void setGrowLeft(qreal val) { _grow1 = val; }
void setGrowRight(qreal val) { _grow2 = val; }
bool distribute() const { return _distribute; }
void setDistribute(bool val) { _distribute = val; }
bool userModified() const;
void setUserModified(bool val);
QPointF beamPos() const;
void setBeamPos(const QPointF& bp);
2016-01-04 14:48:58 +01:00
qreal beamDist() const { return _beamDist; }
2012-05-26 14:26:10 +02:00
2018-03-27 15:36:00 +02:00
virtual QVariant getProperty(Pid propertyId) const override;
virtual bool setProperty(Pid propertyId, const QVariant&) override;
virtual QVariant propertyDefault(Pid id) const override;
2014-10-28 13:45:35 +01:00
bool isGrace() const { return _isGrace; } // for debugger
bool cross() const { return _cross; }
void addSkyline(Skyline&);
virtual void triggerLayout() const override;
2012-05-26 14:26:10 +02:00
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
Q_DECLARE_METATYPE(Ms::Beam::Mode);
2012-05-26 14:26:10 +02:00
#endif