1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
//=============================================================================
// 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"
#include "measure.h"
#include "tuplet.h"
#include "score.h"
#include "undo.h"
#include "staff.h"
#include "xml.h"
#include "property.h"
namespace Ms {
//---------------------------------------------------------
// DurationElement
//---------------------------------------------------------
DurationElement::DurationElement(Score* s, ElementFlags f)
: Element(s, f)
{
_tuplet = 0;
}
//---------------------------------------------------------
// DurationElement
//---------------------------------------------------------
DurationElement::DurationElement(const DurationElement& e)
: Element(e)
{
_tuplet = 0; // e._tuplet;
_duration = e._duration;
}
//---------------------------------------------------------
// ~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
}
}
//---------------------------------------------------------
// topTuplet
//---------------------------------------------------------
Tuplet* DurationElement::topTuplet() const
{
Tuplet* t = tuplet();
if (t) {
while (t->tuplet())
t = t->tuplet();
}
return t;
}
//---------------------------------------------------------
// globalTicks
//---------------------------------------------------------
Fraction DurationElement::globalTicks() const
{
Fraction f(_duration);
for (Tuplet* t = tuplet(); t; t = t->tuplet())
f /= t->ratio();
return f;
}
//---------------------------------------------------------
// actualTicks
//---------------------------------------------------------
Fraction DurationElement::actualTicks() const
{
return globalTicks() / staff()->timeStretch(tick());
}
//---------------------------------------------------------
// readAddTuplet
//---------------------------------------------------------
void DurationElement::readAddTuplet(Tuplet* t)
{
setTuplet(t);
if (!score()->undoStack()->active()) // HACK, also added in Undo::AddElement()
t->add(this);
}
//---------------------------------------------------------
// writeTupletStart
//---------------------------------------------------------
void DurationElement::writeTupletStart(XmlWriter& xml) const
{
if (tuplet() && tuplet()->elements().front() == this) {
tuplet()->writeTupletStart(xml); // recursion
tuplet()->write(xml);
}
}
//---------------------------------------------------------
// writeTupletEnd
//---------------------------------------------------------
void DurationElement::writeTupletEnd(XmlWriter& xml) const
{
if (tuplet() && tuplet()->elements().back() == this) {
xml.tagE("endTuplet");
tuplet()->writeTupletEnd(xml); // recursion
}
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant DurationElement::getProperty(Pid propertyId) const
{
switch (propertyId) {
case Pid::DURATION:
return QVariant::fromValue(_duration);
default:
return Element::getProperty(propertyId);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool DurationElement::setProperty(Pid propertyId, const QVariant& v)
{
switch (propertyId) {
case Pid::DURATION: {
Fraction f(v.value<Fraction>());
setTicks(f);
// TODO: do we really need to re-layout all here?
score()->setLayoutAll();
}
break;
default:
return Element::setProperty(propertyId, v);
}
return true;
}
}
|