MuseScore/libmscore/tuplet.h

139 lines
4.8 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 __TUPLET_H__
#define __TUPLET_H__
#include "duration.h"
2017-01-18 22:41:58 +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 Text;
class Spanner;
enum class TupletNumberType : char;
enum class TupletBracketType : char;
2012-05-26 14:26:10 +02:00
//------------------------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ Tuplet
//! Example of 1/8 triplet:
//! _baseLen = 1/8
//! _actualNotes = 3
//! _normalNotes = 2 (3 notes played in the time of 2/8)
//!
//! The tuplet has a len of _baseLen * _normalNotes.
//! A tuplet note has len of _baseLen * _normalNotes / _actualNotes.
2012-05-26 14:26:10 +02:00
//------------------------------------------------------------------------
class Tuplet final : public DurationElement {
2016-11-29 09:26:43 +01:00
// the tick position of a tuplet is the tick position of its
// first element:
2012-05-26 14:26:10 +02:00
int _tick;
std::vector<DurationElement*> _elements;
Direction _direction;
TupletNumberType _numberType;
TupletBracketType _bracketType;
2018-03-16 12:08:57 +01:00
Spatium _bracketWidth;
2012-05-26 14:26:10 +02:00
bool _hasBracket;
Fraction _ratio;
TDuration _baseLen; // 1/8 for a triplet of 1/8
bool _isUp;
QPointF p1, p2;
QPointF _p1, _p2; // user offset
mutable int _id; // used during read/write
Text* _number;
QPointF bracketL[4];
QPointF bracketR[3];
public:
Tuplet(Score*);
Tuplet(const Tuplet&);
~Tuplet();
2018-03-16 12:08:57 +01:00
virtual Tuplet* clone() const override { return new Tuplet(*this); }
2017-01-18 14:16:33 +01:00
virtual ElementType type() const override { return ElementType::TUPLET; }
virtual void setTrack(int val) override;
2012-05-26 14:26:10 +02:00
virtual void add(Element*) override;
virtual void remove(Element*) override;
2012-05-26 14:26:10 +02:00
2018-03-27 14:40:34 +02:00
Text* number() const { return _number; }
virtual bool isEditable() const override;
2017-03-31 13:03:15 +02:00
virtual void startEdit(EditData&) override;
virtual void editDrag(EditData&) override;
virtual void updateGrips(EditData&) const override;
2012-05-26 14:26:10 +02:00
virtual void setSelected(bool f) override;
2012-05-26 14:26:10 +02:00
virtual Measure* measure() const override { return (Measure*)parent(); }
2012-05-26 14:26:10 +02:00
TupletNumberType numberType() const { return _numberType; }
TupletBracketType bracketType() const { return _bracketType; }
void setNumberType(TupletNumberType val) { _numberType = val; }
void setBracketType(TupletBracketType val) { _bracketType = val; }
bool hasBracket() const { return _hasBracket; }
void setHasBracket(bool b) { _hasBracket = b; }
2018-03-16 12:08:57 +01:00
Spatium bracketWidth() const { return _bracketWidth; }
void setBracketWidth(Spatium s) { _bracketWidth = s; }
2012-05-26 14:26:10 +02:00
Fraction ratio() const { return _ratio; }
void setRatio(const Fraction& r) { _ratio = r; }
2012-05-26 14:26:10 +02:00
const std::vector<DurationElement*>& elements() const { return _elements; }
void clear() { _elements.clear(); }
2012-05-26 14:26:10 +02:00
virtual void layout() override;
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
2012-05-26 14:26:10 +02:00
virtual void read(XmlReader&) override;
2016-11-19 11:51:21 +01:00
virtual void write(XmlWriter&) const override;
virtual bool readProperties(XmlReader&) override;
2012-05-26 14:26:10 +02:00
virtual void reset() override;
2012-05-26 14:26:10 +02:00
virtual void draw(QPainter*) const override;
2012-05-26 14:26:10 +02:00
int id() const { return _id; }
void setId(int i) const { _id = i; }
2014-05-07 18:09:01 +02:00
TDuration baseLen() const { return _baseLen; }
void setBaseLen(const TDuration& d) { _baseLen = d; }
2012-05-26 14:26:10 +02:00
virtual void dump() const override;
2012-05-26 14:26:10 +02:00
2016-03-02 13:20:19 +01:00
void setDirection(Direction d) { _direction = d; }
Direction direction() const { return _direction; }
2012-05-26 14:26:10 +02:00
bool isUp() const { return _isUp; }
2016-03-08 09:46:33 +01:00
virtual int tick() const override { return _tick; }
2012-05-26 14:26:10 +02:00
void setTick(int val) { _tick = val; }
Fraction elementsDuration();
void sortElements();
2012-05-26 14:26:10 +02:00
virtual void setVisible(bool f) override;
2018-03-27 14:40:34 +02:00
2018-03-27 15:36:00 +02:00
virtual QVariant getProperty(Pid propertyId) const override;
virtual bool setProperty(Pid propertyId, const QVariant& v) override;
virtual QVariant propertyDefault(Pid id) const override;
2018-03-27 14:40:34 +02:00
virtual Shape shape() const override;
void sanitizeTuplet();
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