2012-05-26 14:26:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2008-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
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "duration.h"
|
2018-06-02 20:41:28 +02:00
|
|
|
#include "measure.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
#include "tuplet.h"
|
|
|
|
#include "score.h"
|
|
|
|
#include "undo.h"
|
|
|
|
#include "staff.h"
|
2014-04-09 16:09:21 +02:00
|
|
|
#include "xml.h"
|
2015-02-16 09:44:21 +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
|
|
|
//---------------------------------------------------------
|
|
|
|
// DurationElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 14:40:34 +02:00
|
|
|
DurationElement::DurationElement(Score* s, ElementFlags f)
|
|
|
|
: Element(s, f)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
|
|
|
_tuplet = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// DurationElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
DurationElement::DurationElement(const DurationElement& e)
|
|
|
|
: Element(e)
|
|
|
|
{
|
2014-09-28 11:10:18 +02:00
|
|
|
_tuplet = 0; // e._tuplet;
|
2012-05-26 14:26:10 +02:00
|
|
|
_duration = e._duration;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:50:50 +01:00
|
|
|
//---------------------------------------------------------
|
2019-03-19 13:48:38 +01:00
|
|
|
// ~DurationElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
DurationElement::~DurationElement()
|
|
|
|
{
|
|
|
|
if (_tuplet && _tuplet->contains(this)) {
|
|
|
|
while (Tuplet* t = topTuplet()) // delete tuplets from top to bottom
|
|
|
|
delete t; // Tuplet destructor removes references to the deleted object
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2016-11-29 16:50:50 +01:00
|
|
|
// topTuplet
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Tuplet* DurationElement::topTuplet() const
|
|
|
|
{
|
|
|
|
Tuplet* t = tuplet();
|
|
|
|
if (t) {
|
|
|
|
while (t->tuplet())
|
|
|
|
t = t->tuplet();
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
2019-01-30 15:13:54 +01:00
|
|
|
// globalTicks
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2019-01-30 15:13:54 +01:00
|
|
|
Fraction DurationElement::globalTicks() const
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
|
|
|
Fraction f(_duration);
|
|
|
|
for (Tuplet* t = tuplet(); t; t = t->tuplet())
|
|
|
|
f /= t->ratio();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2019-01-30 15:13:54 +01:00
|
|
|
// actualTicks
|
2018-06-02 20:41:28 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2019-01-30 15:13:54 +01:00
|
|
|
Fraction DurationElement::actualTicks() const
|
2018-06-02 20:41:28 +02:00
|
|
|
{
|
2019-01-30 15:13:54 +01:00
|
|
|
return globalTicks() / staff()->timeStretch(tick());
|
2018-07-13 03:13:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
2018-06-09 06:19:36 +02:00
|
|
|
// readAddTuplet
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-06-09 06:19:36 +02:00
|
|
|
void DurationElement::readAddTuplet(Tuplet* t)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2019-01-30 15:13:54 +01:00
|
|
|
setTuplet(t);
|
|
|
|
if (!score()->undoStack()->active()) // HACK, also added in Undo::AddElement()
|
|
|
|
t->add(this);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2018-06-09 06:19:36 +02:00
|
|
|
// writeTupletStart
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-06-09 06:19:36 +02:00
|
|
|
void DurationElement::writeTupletStart(XmlWriter& xml) const
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2018-06-09 06:19:36 +02:00
|
|
|
if (tuplet() && tuplet()->elements().front() == this) {
|
|
|
|
tuplet()->writeTupletStart(xml); // recursion
|
|
|
|
tuplet()->write(xml);
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2018-06-09 06:19:36 +02:00
|
|
|
// writeTupletEnd
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-06-09 06:19:36 +02:00
|
|
|
void DurationElement::writeTupletEnd(XmlWriter& xml) const
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2018-06-09 06:19:36 +02:00
|
|
|
if (tuplet() && tuplet()->elements().back() == this) {
|
|
|
|
xml.tagE("endTuplet");
|
|
|
|
tuplet()->writeTupletEnd(xml); // recursion
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-16 09:44:21 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// getProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
QVariant DurationElement::getProperty(Pid propertyId) const
|
2015-02-16 09:44:21 +01:00
|
|
|
{
|
|
|
|
switch (propertyId) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::DURATION:
|
2015-02-16 09:44:21 +01:00
|
|
|
return QVariant::fromValue(_duration);
|
|
|
|
default:
|
|
|
|
return Element::getProperty(propertyId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
bool DurationElement::setProperty(Pid propertyId, const QVariant& v)
|
2015-02-16 09:44:21 +01:00
|
|
|
{
|
|
|
|
switch (propertyId) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::DURATION: {
|
2015-02-16 09:44:21 +01:00
|
|
|
Fraction f(v.value<Fraction>());
|
2019-01-30 15:13:54 +01:00
|
|
|
setTicks(f);
|
2019-10-24 20:38:31 +02:00
|
|
|
triggerLayout();
|
2015-02-16 09:44:21 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Element::setProperty(propertyId, v);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|