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
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "chordrest.h"
|
|
|
|
#include "chord.h"
|
|
|
|
#include "xml.h"
|
|
|
|
#include "style.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "measure.h"
|
|
|
|
#include "staff.h"
|
|
|
|
#include "tuplet.h"
|
|
|
|
#include "score.h"
|
|
|
|
#include "sym.h"
|
|
|
|
#include "slur.h"
|
|
|
|
#include "beam.h"
|
|
|
|
#include "breath.h"
|
|
|
|
#include "barline.h"
|
|
|
|
#include "articulation.h"
|
|
|
|
#include "tempo.h"
|
|
|
|
#include "tempotext.h"
|
|
|
|
#include "note.h"
|
|
|
|
#include "arpeggio.h"
|
|
|
|
#include "dynamic.h"
|
|
|
|
#include "stafftext.h"
|
|
|
|
#include "sig.h"
|
|
|
|
#include "clef.h"
|
|
|
|
#include "lyrics.h"
|
|
|
|
#include "segment.h"
|
|
|
|
#include "stafftype.h"
|
|
|
|
#include "undo.h"
|
|
|
|
#include "stem.h"
|
|
|
|
#include "harmony.h"
|
|
|
|
#include "figuredbass.h"
|
|
|
|
#include "icon.h"
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// hasArticulation
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Articulation* ChordRest::hasArticulation(const Articulation* aa)
|
|
|
|
{
|
2013-03-05 20:23:59 +01:00
|
|
|
ArticulationType idx = aa->articulationType();
|
2012-11-20 20:51:18 +01:00
|
|
|
foreach(Articulation* a, _articulations) {
|
2013-03-05 20:23:59 +01:00
|
|
|
if (idx == a->articulationType())
|
2012-05-26 14:26:10 +02:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// ChordRest
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ChordRest::ChordRest(Score* s)
|
|
|
|
: DurationElement(s)
|
|
|
|
{
|
2013-01-03 16:56:56 +01:00
|
|
|
_beam = 0;
|
|
|
|
_small = false;
|
2013-03-05 20:23:59 +01:00
|
|
|
_beamMode = BeamMode::AUTO;
|
2013-01-03 16:56:56 +01:00
|
|
|
_up = true;
|
|
|
|
_staffMove = 0;
|
|
|
|
_tabDur = 0;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ChordRest::ChordRest(const ChordRest& cr)
|
|
|
|
: DurationElement(cr)
|
|
|
|
{
|
|
|
|
_durationType = cr._durationType;
|
|
|
|
_staffMove = cr._staffMove;
|
|
|
|
_tabDur = 0; // tab sur. symb. depends upon context: can't be
|
|
|
|
// simply copied from another CR
|
|
|
|
|
2012-11-20 20:51:18 +01:00
|
|
|
foreach(Articulation* a, cr._articulations) { // make deep copy
|
2012-05-26 14:26:10 +02:00
|
|
|
Articulation* na = new Articulation(*a);
|
|
|
|
na->setParent(this);
|
|
|
|
na->setTrack(track());
|
2012-11-20 20:51:18 +01:00
|
|
|
_articulations.append(na);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_beam = 0;
|
|
|
|
_beamMode = cr._beamMode;
|
|
|
|
_up = cr._up;
|
|
|
|
_small = cr._small;
|
|
|
|
_space = cr._space;
|
|
|
|
|
|
|
|
foreach(Lyrics* l, cr._lyricsList) { // make deep copy
|
2012-07-20 16:29:24 +02:00
|
|
|
if (l == 0)
|
|
|
|
continue;
|
2012-05-26 14:26:10 +02:00
|
|
|
Lyrics* nl = new Lyrics(*l);
|
|
|
|
nl->setParent(this);
|
|
|
|
nl->setTrack(track());
|
|
|
|
_lyricsList.append(nl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// ChordRest
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ChordRest::~ChordRest()
|
|
|
|
{
|
2013-06-10 11:03:34 +02:00
|
|
|
foreach (Articulation* a, _articulations)
|
2012-05-26 14:26:10 +02:00
|
|
|
delete a;
|
2013-06-10 11:03:34 +02:00
|
|
|
foreach (Lyrics* l, _lyricsList)
|
2012-05-26 14:26:10 +02:00
|
|
|
delete l;
|
2013-06-10 11:03:34 +02:00
|
|
|
if (_tabDur)
|
2012-09-08 01:22:36 +02:00
|
|
|
delete _tabDur;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// scanElements
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::scanElements(void* data, void (*func)(void*, Element*), bool all)
|
|
|
|
{
|
|
|
|
if (_beam && (_beam->elements().front() == this))
|
|
|
|
_beam->scanElements(data, func, all);
|
2012-11-20 20:51:18 +01:00
|
|
|
foreach(Articulation* a, _articulations)
|
2012-05-26 14:26:10 +02:00
|
|
|
func(data, a);
|
|
|
|
foreach(Lyrics* l, _lyricsList) {
|
|
|
|
if (l)
|
|
|
|
l->scanElements(data, func, all);
|
|
|
|
}
|
|
|
|
DurationElement* de = this;
|
|
|
|
while (de->tuplet() && de->tuplet()->elements().front() == de) {
|
|
|
|
func(data, de->tuplet());
|
|
|
|
de = de->tuplet();
|
|
|
|
}
|
|
|
|
if (_tabDur)
|
|
|
|
func(data, _tabDur);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// writeProperties
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::writeProperties(Xml& xml) const
|
|
|
|
{
|
|
|
|
DurationElement::writeProperties(xml);
|
|
|
|
|
|
|
|
//
|
|
|
|
// BeamMode default:
|
2013-03-26 23:11:24 +01:00
|
|
|
// REST - BeamMode::NONE
|
2013-03-05 20:23:59 +01:00
|
|
|
// CHORD - BeamMode::AUTO
|
2012-05-26 14:26:10 +02:00
|
|
|
//
|
2013-03-26 23:11:24 +01:00
|
|
|
if ((type() == REST && _beamMode != BeamMode::NONE)
|
2013-03-05 20:23:59 +01:00
|
|
|
|| (type() == CHORD && _beamMode != BeamMode::AUTO)) {
|
2012-05-26 14:26:10 +02:00
|
|
|
QString s;
|
|
|
|
switch(_beamMode) {
|
2013-03-05 20:23:59 +01:00
|
|
|
case BeamMode::AUTO: s = "auto"; break;
|
|
|
|
case BeamMode::BEGIN: s = "begin"; break;
|
|
|
|
case BeamMode::MID: s = "mid"; break;
|
|
|
|
case BeamMode::END: s = "end"; break;
|
2013-03-26 23:11:24 +01:00
|
|
|
case BeamMode::NONE: s = "no"; break;
|
2013-03-05 20:23:59 +01:00
|
|
|
case BeamMode::BEGIN32: s = "begin32"; break;
|
|
|
|
case BeamMode::BEGIN64: s = "begin64"; break;
|
|
|
|
case BeamMode::INVALID: s = "?"; break;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
xml.tag("BeamMode", s);
|
|
|
|
}
|
2012-08-12 11:44:36 +02:00
|
|
|
writeProperty(xml, P_SMALL);
|
2013-05-12 12:51:42 +02:00
|
|
|
if (actualDurationType().dots())
|
|
|
|
xml.tag("dots", actualDurationType().dots());
|
2012-05-26 14:26:10 +02:00
|
|
|
if (_staffMove)
|
|
|
|
xml.tag("move", _staffMove);
|
2013-05-12 12:51:42 +02:00
|
|
|
if (actualDurationType().isValid())
|
|
|
|
xml.tag("durationType", actualDurationType().name());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2013-05-12 12:51:42 +02:00
|
|
|
if (!duration().isZero() && (!actualDurationType().fraction().isValid()
|
|
|
|
|| (actualDurationType().fraction() != duration())))
|
2012-05-26 14:26:10 +02:00
|
|
|
xml.fTag("duration", duration());
|
2012-11-20 20:51:18 +01:00
|
|
|
foreach(const Articulation* a, _articulations)
|
2012-05-26 14:26:10 +02:00
|
|
|
a->write(xml);
|
|
|
|
#ifndef NDEBUG
|
2013-03-28 11:09:31 +01:00
|
|
|
if (_beam && (MScore::testMode || !_beam->generated()))
|
2012-05-26 14:26:10 +02:00
|
|
|
xml.tag("Beam", _beam->id());
|
|
|
|
#else
|
|
|
|
if (!xml.clipboardmode && _beam && !_beam->generated())
|
|
|
|
xml.tag("Beam", _beam->id());
|
|
|
|
#endif
|
|
|
|
foreach(Lyrics* lyrics, _lyricsList) {
|
|
|
|
if (lyrics)
|
|
|
|
lyrics->write(xml);
|
|
|
|
}
|
|
|
|
Fraction t(globalDuration());
|
|
|
|
if (staff())
|
|
|
|
t *= staff()->timeStretch(xml.curTick);
|
|
|
|
xml.curTick += t.ticks();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// readProperties
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
bool ChordRest::readProperties(XmlReader& e)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2013-01-08 11:00:53 +01:00
|
|
|
if (DurationElement::readProperties(e))
|
2012-05-26 14:26:10 +02:00
|
|
|
return true;
|
2013-01-11 18:10:18 +01:00
|
|
|
const QStringRef& tag(e.name());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2013-05-29 10:31:26 +02:00
|
|
|
if (tag == "durationType") {
|
|
|
|
setDurationType(e.readElementText());
|
|
|
|
if (actualDurationType().type() != TDuration::V_MEASURE) {
|
|
|
|
if ((type() == REST) &&
|
|
|
|
// for backward compatibility, convert V_WHOLE rests to V_MEASURE
|
|
|
|
// if long enough to fill a measure.
|
|
|
|
// OTOH, freshly created (un-initialized) rests have numerator == 0 (< 4/4)
|
|
|
|
// (see Fraction() constructor in fraction.h; this happens for instance
|
|
|
|
// when pasting selection from clipboard): they should not be converted
|
|
|
|
duration().numerator() != 0 &&
|
|
|
|
// rest durations are initialized to full measure duration when
|
|
|
|
// created upon reading the <Rest> tag (see Measure::read() )
|
|
|
|
// so a V_WHOLE rest in a measure of 4/4 or less => V_MEASURE
|
|
|
|
(actualDurationType()==TDuration::V_WHOLE && duration() <= Fraction(4, 4)) ) {
|
|
|
|
// old pre 2.0 scores: convert
|
|
|
|
setDurationType(TDuration::V_MEASURE);
|
|
|
|
}
|
|
|
|
else // not from old score: set duration fraction from duration type
|
|
|
|
setDuration(actualDurationType().fraction());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (score()->mscVersion() < 115) {
|
|
|
|
SigEvent event = score()->sigmap()->timesig(e.tick());
|
|
|
|
setDuration(event.timesig());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (tag == "BeamMode") {
|
2013-01-11 18:10:18 +01:00
|
|
|
QString val(e.readElementText());
|
2013-03-05 20:23:59 +01:00
|
|
|
BeamMode bm = BeamMode::AUTO;
|
2012-05-26 14:26:10 +02:00
|
|
|
if (val == "auto")
|
2013-03-05 20:23:59 +01:00
|
|
|
bm = BeamMode::AUTO;
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (val == "begin")
|
2013-03-05 20:23:59 +01:00
|
|
|
bm = BeamMode::BEGIN;
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (val == "mid")
|
2013-03-05 20:23:59 +01:00
|
|
|
bm = BeamMode::MID;
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (val == "end")
|
2013-03-05 20:23:59 +01:00
|
|
|
bm = BeamMode::END;
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (val == "no")
|
2013-03-26 23:11:24 +01:00
|
|
|
bm = BeamMode::NONE;
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (val == "begin32")
|
2013-03-05 20:23:59 +01:00
|
|
|
bm = BeamMode::BEGIN32;
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (val == "begin64")
|
2013-03-05 20:23:59 +01:00
|
|
|
bm = BeamMode::BEGIN64;
|
2012-05-26 14:26:10 +02:00
|
|
|
else
|
|
|
|
bm = BeamMode(val.toInt());
|
|
|
|
_beamMode = BeamMode(bm);
|
|
|
|
}
|
|
|
|
else if (tag == "Attribute" || tag == "Articulation") { // obsolete: "Attribute"
|
|
|
|
Articulation* atr = new Articulation(score());
|
|
|
|
atr->read(e);
|
|
|
|
add(atr);
|
|
|
|
}
|
|
|
|
else if (tag == "leadingSpace") {
|
2013-01-11 18:10:18 +01:00
|
|
|
qDebug("ChordRest: leadingSpace obsolete"); // _extraLeadingSpace = Spatium(val.toDouble());
|
2013-01-22 21:53:45 +01:00
|
|
|
e.skipCurrentElement();
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
else if (tag == "trailingSpace") {
|
2013-01-11 18:10:18 +01:00
|
|
|
qDebug("ChordRest: trailingSpace obsolete"); // _extraTrailingSpace = Spatium(val.toDouble());
|
2013-01-22 21:53:45 +01:00
|
|
|
e.skipCurrentElement();
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
else if (tag == "Beam") {
|
2013-01-11 18:10:18 +01:00
|
|
|
int id = e.readInt();
|
2013-01-21 20:21:41 +01:00
|
|
|
Beam* beam = e.findBeam(id);
|
2012-05-26 14:26:10 +02:00
|
|
|
if (beam)
|
|
|
|
beam->add(this); // also calls this->setBeam(beam)
|
|
|
|
else
|
2013-01-11 18:10:18 +01:00
|
|
|
qDebug("Beam id %d not found", id);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
else if (tag == "small")
|
2013-01-11 18:10:18 +01:00
|
|
|
_small = e.readInt();
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (tag == "Slur") {
|
2013-01-11 18:10:18 +01:00
|
|
|
int id = e.intAttribute("number");
|
|
|
|
QString type(e.attribute("type"));
|
2013-06-10 11:03:34 +02:00
|
|
|
Slur* slur = static_cast<Slur*>(score()->findSpanner(id));
|
2013-01-08 11:00:53 +01:00
|
|
|
if (!slur)
|
|
|
|
qDebug("ChordRest::read(): Slur id %d not found", id);
|
|
|
|
else {
|
2013-06-10 21:13:04 +02:00
|
|
|
if (type == "start") {
|
2013-06-10 11:03:34 +02:00
|
|
|
slur->setTick(e.tick());
|
2013-06-10 21:13:04 +02:00
|
|
|
slur->setTrack(e.track());
|
|
|
|
}
|
2013-06-10 11:03:34 +02:00
|
|
|
else if (type == "stop")
|
|
|
|
slur->setTickLen(e.tick() - slur->tick());
|
2013-01-08 11:00:53 +01:00
|
|
|
else
|
|
|
|
qDebug("ChordRest::read(): unknown Slur type <%s>", qPrintable(type));
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
2013-01-11 18:10:18 +01:00
|
|
|
e.readNext();
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
else if (tag == "duration")
|
2013-01-11 18:10:18 +01:00
|
|
|
setDuration(e.readFraction());
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (tag == "ticklen") { // obsolete (version < 1.12)
|
2013-01-21 20:21:41 +01:00
|
|
|
int mticks = score()->sigmap()->timesig(e.tick()).timesig().ticks();
|
2013-01-11 18:10:18 +01:00
|
|
|
int i = e.readInt();
|
2012-05-26 14:26:10 +02:00
|
|
|
if (i == 0)
|
|
|
|
i = mticks;
|
|
|
|
if ((type() == REST) && (mticks == i)) {
|
|
|
|
setDurationType(TDuration::V_MEASURE);
|
|
|
|
setDuration(Fraction::fromTicks(i));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Fraction f = Fraction::fromTicks(i);
|
|
|
|
setDuration(f);
|
|
|
|
setDurationType(TDuration(f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (tag == "dots")
|
2013-01-11 18:10:18 +01:00
|
|
|
setDots(e.readInt());
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (tag == "move")
|
2013-01-11 18:10:18 +01:00
|
|
|
_staffMove = e.readInt();
|
2012-05-26 14:26:10 +02:00
|
|
|
else if (tag == "Lyrics" /*|| tag == "FiguredBass"*/) {
|
2013-01-18 10:55:52 +01:00
|
|
|
Element* element = Element::name2Element(tag, score());
|
2013-01-21 20:21:41 +01:00
|
|
|
element->setTrack(e.track());
|
2012-05-26 14:26:10 +02:00
|
|
|
element->read(e);
|
|
|
|
add(element);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setSmall
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::setSmall(bool val)
|
|
|
|
{
|
2013-05-28 15:42:02 +02:00
|
|
|
_small = val;
|
2012-06-19 14:44:27 +02:00
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// layoutArticulations
|
|
|
|
// called from chord()->layout()
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::layoutArticulations()
|
|
|
|
{
|
2012-11-20 20:51:18 +01:00
|
|
|
if (parent() == 0 || _articulations.isEmpty())
|
2012-05-26 14:26:10 +02:00
|
|
|
return;
|
|
|
|
qreal _spatium = spatium();
|
2013-03-09 09:58:43 +01:00
|
|
|
qreal _spStaff = _spatium * staff()->lineDistance(); // scaled to staff line distance for vert. pos. within a staff
|
2012-05-26 14:26:10 +02:00
|
|
|
if (type() == CHORD) {
|
2012-11-20 20:51:18 +01:00
|
|
|
if (_articulations.size() == 1) {
|
|
|
|
static_cast<Chord*>(this)->layoutArticulation(_articulations[0]);
|
2012-05-26 14:26:10 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-11-20 20:51:18 +01:00
|
|
|
if (_articulations.size() == 2) {
|
2012-05-26 14:26:10 +02:00
|
|
|
//
|
|
|
|
// staccato | tenuto + marcato
|
|
|
|
//
|
2012-11-20 20:51:18 +01:00
|
|
|
Articulation* a1 = _articulations[0];
|
|
|
|
Articulation* a2 = _articulations[1];
|
2013-03-05 20:23:59 +01:00
|
|
|
ArticulationType st1 = a1->articulationType();
|
|
|
|
ArticulationType st2 = a2->articulationType();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
if ((st2 == Articulation_Tenuto || st2 == Articulation_Staccato)
|
|
|
|
&& (st1 == Articulation_Marcato)) {
|
|
|
|
qSwap(a1, a2);
|
|
|
|
qSwap(st1, st2);
|
|
|
|
}
|
|
|
|
if ((st1 == Articulation_Tenuto || st1 == Articulation_Staccato)
|
|
|
|
&& (st2 == Articulation_Marcato)) {
|
|
|
|
QPointF pt = static_cast<Chord*>(this)->layoutArticulation(a1);
|
2013-03-09 09:58:43 +01:00
|
|
|
pt.ry() += a1->up() ? -_spStaff * .5 : _spStaff * .5;
|
2012-07-30 16:22:56 +02:00
|
|
|
a2->layout();
|
2012-05-26 14:26:10 +02:00
|
|
|
a2->setUp(a1->up());
|
|
|
|
a2->setPos(pt);
|
|
|
|
a2->adjustReadPos();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// staccato | tenuto + sforzato
|
|
|
|
//
|
|
|
|
if ((st2 == Articulation_Tenuto || st2 == Articulation_Staccato)
|
|
|
|
&& (st1 == Articulation_Sforzatoaccent)) {
|
|
|
|
qSwap(a1, a2);
|
|
|
|
qSwap(st1, st2);
|
|
|
|
}
|
|
|
|
if ((st1 == Articulation_Tenuto || st1 == Articulation_Staccato)
|
|
|
|
&& (st2 == Articulation_Sforzatoaccent)) {
|
|
|
|
QPointF pt = static_cast<Chord*>(this)->layoutArticulation(a1);
|
2013-03-09 09:58:43 +01:00
|
|
|
pt.ry() += a1->up() ? -_spStaff * .7 : _spStaff * .7;
|
2012-07-30 16:22:56 +02:00
|
|
|
a2->layout();
|
2012-05-26 14:26:10 +02:00
|
|
|
a2->setUp(a1->up());
|
|
|
|
a2->setPos(pt);
|
|
|
|
a2->adjustReadPos();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qreal x = centerX();
|
|
|
|
qreal distance0 = score()->styleS(ST_propertyDistance).val() * _spatium;
|
|
|
|
qreal distance1 = score()->styleS(ST_propertyDistanceHead).val() * _spatium;
|
|
|
|
qreal distance2 = score()->styleS(ST_propertyDistanceStem).val() * _spatium;
|
|
|
|
|
|
|
|
qreal chordTopY = upPos(); // note position of highest note
|
|
|
|
qreal chordBotY = downPos(); // note position of lowest note
|
|
|
|
|
|
|
|
qreal staffTopY = -distance2;
|
|
|
|
qreal staffBotY = staff()->height() + distance2;
|
|
|
|
|
|
|
|
// avoid collisions of staff articulations with chord notes:
|
|
|
|
// gap between note and staff articulation is distance0 + 0.5 spatium
|
|
|
|
|
|
|
|
if (type() == CHORD) {
|
|
|
|
Chord* chord = static_cast<Chord*>(this);
|
|
|
|
Stem* stem = chord->stem();
|
|
|
|
if (stem) {
|
|
|
|
qreal y = stem->pos().y() + pos().y();
|
|
|
|
if (up() && stem->stemLen() < 0.0)
|
|
|
|
y += stem->stemLen();
|
|
|
|
else if (!up() && stem->stemLen() > 0.0)
|
|
|
|
y -= stem->stemLen();
|
2013-01-02 09:29:17 +01:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
if (beam()) {
|
|
|
|
qreal bw = score()->styleS(ST_beamWidth).val() * _spatium;
|
|
|
|
y += up() ? -bw : bw;
|
|
|
|
}
|
|
|
|
if (up())
|
|
|
|
staffTopY = qMin(staffTopY, qreal(y - 0.5 * _spatium));
|
|
|
|
else
|
|
|
|
staffBotY = qMax(staffBotY, qreal(y + 0.5 * _spatium));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
staffTopY = qMin(staffTopY, qreal(chordTopY - distance0 - 0.5 * _spatium));
|
|
|
|
staffBotY = qMax(staffBotY, qreal(chordBotY + distance0 + 0.5 * _spatium));
|
|
|
|
|
|
|
|
qreal dy = 0.0;
|
|
|
|
|
2013-01-02 09:29:17 +01:00
|
|
|
int n = _articulations.size();
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
Articulation* a = _articulations.at(i);
|
2012-05-26 14:26:10 +02:00
|
|
|
//
|
|
|
|
// determine Direction
|
|
|
|
//
|
2012-08-04 15:46:43 +02:00
|
|
|
if (a->direction() != MScore::AUTO) {
|
|
|
|
a->setUp(a->direction() == MScore::UP);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (a->anchor() == A_CHORD)
|
|
|
|
a->setUp(!up());
|
|
|
|
else
|
|
|
|
a->setUp(a->anchor() == A_TOP_STAFF || a->anchor() == A_TOP_CHORD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// pass 1
|
|
|
|
// place tenuto and staccato
|
|
|
|
//
|
|
|
|
|
2013-01-02 09:29:17 +01:00
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
Articulation* a = _articulations.at(i);
|
2012-05-26 14:26:10 +02:00
|
|
|
a->layout();
|
|
|
|
ArticulationAnchor aa = a->anchor();
|
|
|
|
|
2013-03-05 20:23:59 +01:00
|
|
|
if ((a->articulationType() != Articulation_Tenuto)
|
|
|
|
&& (a->articulationType() != Articulation_Staccato))
|
2012-05-26 14:26:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (aa != A_CHORD && aa != A_TOP_CHORD && aa != A_BOTTOM_CHORD)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool bottom;
|
|
|
|
if ((aa == A_CHORD) && measure()->hasVoices(a->staffIdx()))
|
|
|
|
bottom = !up();
|
|
|
|
else
|
|
|
|
bottom = (aa == A_BOTTOM_CHORD) || (aa == A_CHORD && up());
|
|
|
|
bool headSide = bottom == up();
|
|
|
|
|
|
|
|
dy += distance1;
|
|
|
|
qreal y;
|
|
|
|
Chord* chord = static_cast<Chord*>(this);
|
|
|
|
if (bottom) {
|
|
|
|
int line = downLine();
|
|
|
|
y = chordBotY + dy;
|
|
|
|
if (!headSide && type() == CHORD && chord->stem()) {
|
|
|
|
Stem* stem = chord->stem();
|
|
|
|
y = chordTopY + stem->stemLen();
|
|
|
|
if (chord->beam())
|
|
|
|
y += score()->styleS(ST_beamWidth).val() * _spatium * .5;
|
|
|
|
x = stem->pos().x();
|
|
|
|
int line = lrint((y+0.5*_spatium) / _spatium);
|
|
|
|
if (line <= 4) // align between staff lines
|
|
|
|
y = line * _spatium + _spatium * .5;
|
|
|
|
else
|
|
|
|
y += _spatium;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int lines = (staff()->lines() - 1) * 2;
|
|
|
|
if (line < lines)
|
|
|
|
y = (line & ~1) + 3;
|
|
|
|
else
|
|
|
|
y = line + 2;
|
|
|
|
y *= _spatium * .5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int line = upLine();
|
|
|
|
y = chordTopY - dy;
|
|
|
|
if (!headSide && type() == CHORD && chord->stem()) {
|
|
|
|
Stem* stem = chord->stem();
|
|
|
|
y = chordBotY + stem->stemLen();
|
|
|
|
if (chord->beam())
|
|
|
|
y -= score()->styleS(ST_beamWidth).val() * _spatium * .5;
|
|
|
|
x = stem->pos().x();
|
|
|
|
int line = lrint((y-0.5*_spatium) / _spatium);
|
|
|
|
if (line >= 0) // align between staff lines
|
|
|
|
y = line * _spatium - _spatium * .5;
|
|
|
|
else
|
|
|
|
y -= _spatium;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (line > 0)
|
|
|
|
y = ((line+1) & ~1) - 3;
|
|
|
|
else
|
|
|
|
y = line - 2;
|
|
|
|
y *= _spatium * .5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dy += _spatium * .5;
|
|
|
|
a->setPos(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// reserve space for slur
|
|
|
|
bool botGap = false;
|
|
|
|
bool topGap = false;
|
2013-01-02 09:29:17 +01:00
|
|
|
|
2013-06-10 11:03:34 +02:00
|
|
|
#if 0 // TODO-S
|
2013-01-03 16:56:56 +01:00
|
|
|
for (Spanner* sp = _spannerFor; sp; sp = sp->next()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
if (sp->type() != SLUR)
|
|
|
|
continue;
|
|
|
|
Slur* s = static_cast<Slur*>(sp);
|
|
|
|
if (s->up())
|
|
|
|
topGap = true;
|
|
|
|
else
|
|
|
|
botGap = true;
|
|
|
|
}
|
2013-01-03 16:56:56 +01:00
|
|
|
for (Spanner* sp = _spannerBack; sp; sp = sp->next()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
if (sp->type() != SLUR)
|
|
|
|
continue;
|
|
|
|
Slur* s = static_cast<Slur*>(sp);
|
|
|
|
if (s->up())
|
|
|
|
topGap = true;
|
|
|
|
else
|
|
|
|
botGap = true;
|
|
|
|
}
|
2013-06-10 11:03:34 +02:00
|
|
|
#endif
|
2012-05-26 14:26:10 +02:00
|
|
|
if (botGap)
|
|
|
|
chordBotY += _spatium;
|
|
|
|
if (topGap)
|
|
|
|
chordTopY -= _spatium;
|
|
|
|
|
|
|
|
//
|
|
|
|
// pass 2
|
|
|
|
// place all articulations with anchor at chord/rest
|
|
|
|
//
|
2013-01-02 09:29:17 +01:00
|
|
|
n = _articulations.size();
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
Articulation* a = _articulations.at(i);
|
2012-05-26 14:26:10 +02:00
|
|
|
a->layout();
|
|
|
|
ArticulationAnchor aa = a->anchor();
|
2013-03-05 20:23:59 +01:00
|
|
|
if ((a->articulationType() == Articulation_Tenuto)
|
|
|
|
|| (a->articulationType() == Articulation_Staccato))
|
2012-05-26 14:26:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (aa != A_CHORD && aa != A_TOP_CHORD && aa != A_BOTTOM_CHORD)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// for tenuto and staccate check for staff line collision
|
2013-03-05 20:23:59 +01:00
|
|
|
bool staffLineCT = a->articulationType() == Articulation_Tenuto
|
|
|
|
|| a->articulationType() == Articulation_Staccato;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
// qreal sh = a->bbox().height() * mag();
|
|
|
|
bool bottom = (aa == A_BOTTOM_CHORD) || (aa == A_CHORD && up());
|
|
|
|
|
|
|
|
dy += distance1;
|
|
|
|
if (bottom) {
|
|
|
|
qreal y = chordBotY + dy;
|
|
|
|
if (staffLineCT && (y <= staffBotY -.1 - dy)) {
|
|
|
|
qreal l = y / _spatium;
|
|
|
|
qreal delta = fabs(l - round(l));
|
|
|
|
if (delta < 0.4) {
|
|
|
|
y += _spatium * .5;
|
|
|
|
dy += _spatium * .5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a->setPos(x, y); // - a->bbox().y() + a->bbox().height() * .5);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qreal y = chordTopY - dy;
|
|
|
|
if (staffLineCT && (y >= (staffTopY +.1 + dy))) {
|
|
|
|
qreal l = y / _spatium;
|
|
|
|
qreal delta = fabs(l - round(l));
|
|
|
|
if (delta < 0.4) {
|
|
|
|
y -= _spatium * .5;
|
|
|
|
dy += _spatium * .5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a->setPos(x, y); // + a->bbox().y() - a->bbox().height() * .5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// pass 3
|
|
|
|
// now place all articulations with staff top or bottom anchor
|
|
|
|
//
|
|
|
|
qreal dyTop = staffTopY;
|
|
|
|
qreal dyBot = staffBotY;
|
|
|
|
|
|
|
|
/* if ((upPos() - _spatium) < dyTop)
|
|
|
|
dyTop = upPos() - _spatium;
|
|
|
|
if ((downPos() + _spatium) > dyBot)
|
|
|
|
dyBot = downPos() + _spatium;
|
|
|
|
*/
|
2013-01-02 09:29:17 +01:00
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
Articulation* a = _articulations.at(i);
|
2012-05-26 14:26:10 +02:00
|
|
|
ArticulationAnchor aa = a->anchor();
|
|
|
|
if (aa == A_TOP_STAFF || aa == A_BOTTOM_STAFF) {
|
|
|
|
if (a->up()) {
|
|
|
|
a->setPos(x, dyTop);
|
|
|
|
dyTop -= distance0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a->setPos(x, dyBot);
|
|
|
|
dyBot += distance0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a->adjustReadPos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// drop
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Element* ChordRest::drop(const DropData& data)
|
|
|
|
{
|
|
|
|
Element* e = data.element;
|
|
|
|
Measure* m = measure();
|
|
|
|
switch (e->type()) {
|
|
|
|
case BREATH:
|
|
|
|
{
|
|
|
|
Breath* b = static_cast<Breath*>(e);
|
|
|
|
b->setTrack(staffIdx() * VOICES);
|
|
|
|
|
|
|
|
// TODO: insert automatically in all staves?
|
|
|
|
|
2012-08-03 15:54:02 +02:00
|
|
|
Segment* seg = m->undoGetSegment(Segment::SegBreath, tick());
|
2012-05-26 14:26:10 +02:00
|
|
|
b->setParent(seg);
|
|
|
|
score()->undoAddElement(b);
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
|
|
|
|
case BAR_LINE:
|
|
|
|
{
|
|
|
|
BarLine* bl = static_cast<BarLine*>(e);
|
|
|
|
bl->setTrack(staffIdx() * VOICES);
|
|
|
|
|
|
|
|
if (tick() == m->tick())
|
|
|
|
return m->drop(data);
|
|
|
|
|
2012-08-03 15:54:02 +02:00
|
|
|
Segment* seg = m->undoGetSegment(Segment::SegBarLine, tick());
|
2012-05-26 14:26:10 +02:00
|
|
|
bl->setParent(seg);
|
|
|
|
score()->undoAddElement(bl);
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
|
|
|
|
case CLEF:
|
|
|
|
score()->undoChangeClef(staff(), segment(), static_cast<Clef*>(e)->clefType());
|
|
|
|
delete e;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEMPO_TEXT:
|
|
|
|
{
|
|
|
|
TempoText* tt = static_cast<TempoText*>(e);
|
|
|
|
tt->setParent(segment());
|
2012-10-25 16:21:07 +02:00
|
|
|
int st = tt->textStyleType();
|
|
|
|
if (st != TEXT_STYLE_UNKNOWN)
|
2013-04-11 13:30:34 +02:00
|
|
|
tt->setTextStyleType(st);
|
2012-05-26 14:26:10 +02:00
|
|
|
score()->undoAddElement(tt);
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
|
|
|
|
case DYNAMIC:
|
2012-07-30 21:41:48 +02:00
|
|
|
case FRET_DIAGRAM:
|
2012-08-12 11:44:36 +02:00
|
|
|
case SYMBOL:
|
2012-05-26 14:26:10 +02:00
|
|
|
e->setTrack(track());
|
|
|
|
e->setParent(segment());
|
|
|
|
score()->undoAddElement(e);
|
|
|
|
return e;
|
|
|
|
|
|
|
|
case NOTE:
|
|
|
|
{
|
|
|
|
Note* note = static_cast<Note*>(e);
|
|
|
|
NoteVal nval;
|
|
|
|
nval.pitch = note->pitch();
|
|
|
|
nval.headGroup = note->headGroup();
|
2012-08-04 15:46:43 +02:00
|
|
|
score()->setNoteRest(segment(), track(), nval, data.duration, MScore::AUTO);
|
2012-05-26 14:26:10 +02:00
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HARMONY:
|
|
|
|
static_cast<Harmony*>(e)->render();
|
|
|
|
// fall through
|
|
|
|
case TEXT:
|
|
|
|
case STAFF_TEXT:
|
|
|
|
case STAFF_STATE:
|
|
|
|
case INSTRUMENT_CHANGE:
|
|
|
|
case REHEARSAL_MARK:
|
|
|
|
e->setParent(segment());
|
|
|
|
e->setTrack((track() / VOICES) * VOICES);
|
2012-10-25 16:21:07 +02:00
|
|
|
{
|
|
|
|
Text* f = static_cast<Text*>(e);
|
|
|
|
int st = f->textStyleType();
|
2013-05-18 15:02:47 +02:00
|
|
|
if (st >= TEXT_STYLE_DEFAULT)
|
2013-04-11 13:30:34 +02:00
|
|
|
f->setTextStyleType(st);
|
2012-10-25 16:21:07 +02:00
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
score()->undoAddElement(e);
|
|
|
|
return e;
|
|
|
|
|
|
|
|
case FIGURED_BASS:
|
|
|
|
{
|
|
|
|
bool bNew;
|
|
|
|
FiguredBass * fb = static_cast<FiguredBass *>(e);
|
|
|
|
fb->setParent( segment() );
|
|
|
|
fb->setTrack( (track() / VOICES) * VOICES );
|
|
|
|
fb->setTicks( duration().ticks() );
|
|
|
|
fb->setOnNote(true);
|
2013-05-18 15:02:47 +02:00
|
|
|
FiguredBass::addFiguredBassToSegment(segment(),
|
2012-05-26 14:26:10 +02:00
|
|
|
fb->track(), fb->ticks(), &bNew);
|
|
|
|
if (bNew)
|
|
|
|
score()->undoAddElement(e);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IMAGE:
|
|
|
|
e->setParent(segment());
|
|
|
|
score()->undoAddElement(e);
|
|
|
|
return e;
|
|
|
|
|
|
|
|
case ICON:
|
|
|
|
{
|
2013-03-05 20:23:59 +01:00
|
|
|
switch(static_cast<Icon*>(e)->iconType()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
case ICON_SBEAM:
|
2013-03-05 20:23:59 +01:00
|
|
|
score()->undoChangeProperty(this, P_BEAM_MODE, int(BeamMode::BEGIN));
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
|
|
|
case ICON_MBEAM:
|
2013-03-05 20:23:59 +01:00
|
|
|
score()->undoChangeProperty(this, P_BEAM_MODE, int(BeamMode::MID));
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
|
|
|
case ICON_NBEAM:
|
2013-03-26 23:11:24 +01:00
|
|
|
score()->undoChangeProperty(this, P_BEAM_MODE, int(BeamMode::NONE));
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
|
|
|
case ICON_BEAM32:
|
2013-03-05 20:23:59 +01:00
|
|
|
score()->undoChangeProperty(this, P_BEAM_MODE, int(BeamMode::BEGIN32));
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
|
|
|
case ICON_BEAM64:
|
2013-03-05 20:23:59 +01:00
|
|
|
score()->undoChangeProperty(this, P_BEAM_MODE, int(BeamMode::BEGIN64));
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
|
|
|
case ICON_AUTOBEAM:
|
2013-03-05 20:23:59 +01:00
|
|
|
score()->undoChangeProperty(this, P_BEAM_MODE, int(BeamMode::AUTO));
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete e;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
qDebug("cannot drop %s", e->name());
|
|
|
|
delete e;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setBeam
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::setBeam(Beam* b)
|
|
|
|
{
|
|
|
|
_beam = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setDurationType
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::setDurationType(TDuration::DurationType t)
|
|
|
|
{
|
|
|
|
_durationType.setType(t);
|
2013-05-12 12:51:42 +02:00
|
|
|
_crossMeasure = CROSSMEASURE_UNKNOWN;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChordRest::setDurationType(const QString& s)
|
|
|
|
{
|
|
|
|
_durationType.setType(s);
|
2013-05-12 12:51:42 +02:00
|
|
|
_crossMeasure = CROSSMEASURE_UNKNOWN;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChordRest::setDurationType(int ticks)
|
|
|
|
{
|
|
|
|
_durationType.setVal(ticks);
|
2013-05-12 12:51:42 +02:00
|
|
|
_crossMeasure = CROSSMEASURE_UNKNOWN;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChordRest::setDurationType(const TDuration& v)
|
|
|
|
{
|
|
|
|
_durationType = v;
|
2013-05-12 12:51:42 +02:00
|
|
|
_crossMeasure = CROSSMEASURE_UNKNOWN;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setTrack
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::setTrack(int val)
|
|
|
|
{
|
2012-11-20 20:51:18 +01:00
|
|
|
foreach(Articulation* a, _articulations)
|
2012-05-26 14:26:10 +02:00
|
|
|
a->setTrack(val);
|
|
|
|
Element::setTrack(val);
|
|
|
|
if (type() == CHORD) {
|
|
|
|
foreach(Note* n, static_cast<Chord*>(this)->notes())
|
|
|
|
n->setTrack(val);
|
|
|
|
}
|
|
|
|
if (_beam)
|
|
|
|
_beam->setTrack(val);
|
2012-09-24 10:54:08 +02:00
|
|
|
foreach(Lyrics* l, _lyricsList) {
|
|
|
|
if (l)
|
|
|
|
l->setTrack(val);
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
if (tuplet())
|
|
|
|
tuplet()->setTrack(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// tick
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
int ChordRest::tick() const
|
|
|
|
{
|
|
|
|
return segment() ? segment()->tick() : -1;
|
|
|
|
}
|
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// rtick
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
int ChordRest::rtick() const
|
|
|
|
{
|
|
|
|
return segment() ? segment()->rtick() : -1;
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// add
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::add(Element* e)
|
|
|
|
{
|
|
|
|
e->setParent(this);
|
|
|
|
e->setTrack(track());
|
|
|
|
switch(e->type()) {
|
|
|
|
case ARTICULATION:
|
|
|
|
{
|
|
|
|
Articulation* a = static_cast<Articulation*>(e);
|
2012-11-20 20:51:18 +01:00
|
|
|
_articulations.push_back(a);
|
2013-06-03 14:39:59 +02:00
|
|
|
if (a->timeStretch() != 1.0)
|
|
|
|
score()->fixTicks(); // update tempo map
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LYRICS:
|
|
|
|
{
|
|
|
|
Lyrics* l = static_cast<Lyrics*>(e);
|
|
|
|
int size = _lyricsList.size();
|
|
|
|
if (l->no() >= size) {
|
|
|
|
for (int i = size-1; i < l->no(); ++i)
|
|
|
|
_lyricsList.append(0);
|
|
|
|
}
|
|
|
|
_lyricsList[l->no()] = l;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug("ChordRest::add: unknown element %s", e->name());
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// remove
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::remove(Element* e)
|
|
|
|
{
|
2013-02-21 14:28:16 +01:00
|
|
|
switch (e->type()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
case ARTICULATION:
|
|
|
|
{
|
|
|
|
Articulation* a = static_cast<Articulation*>(e);
|
2012-11-20 20:51:18 +01:00
|
|
|
if (!_articulations.removeOne(a))
|
2012-05-26 14:26:10 +02:00
|
|
|
qDebug("ChordRest::remove(): articulation not found");
|
2013-06-03 14:39:59 +02:00
|
|
|
if (a->timeStretch() != 1.0)
|
|
|
|
score()->fixTicks(); // update tempo map
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LYRICS:
|
|
|
|
{
|
|
|
|
for (int i = 0; i < _lyricsList.size(); ++i) {
|
|
|
|
if (_lyricsList[i] != e)
|
|
|
|
continue;
|
|
|
|
_lyricsList[i] = 0;
|
|
|
|
while (!_lyricsList.isEmpty() && _lyricsList.back() == 0)
|
|
|
|
_lyricsList.takeLast();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qDebug("ChordRest::remove: %s %p not found", e->name(), e);
|
|
|
|
break;
|
|
|
|
default:
|
2013-03-08 14:59:16 +01:00
|
|
|
qDebug("ChordRest::remove: unknown element <%s>", e->name());
|
|
|
|
abort();
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// removeDeleteBeam
|
|
|
|
// remove ChordRest from beam
|
|
|
|
// delete beam if empty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::removeDeleteBeam()
|
|
|
|
{
|
|
|
|
if (_beam) {
|
|
|
|
Beam* b = _beam;
|
2013-05-22 15:20:14 +02:00
|
|
|
_beam->remove(this);
|
|
|
|
if (b->isEmpty())
|
|
|
|
score()->undoRemoveElement(b);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 10:07:27 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// undoSetBeamMode
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ChordRest::undoSetBeamMode(BeamMode mode)
|
|
|
|
{
|
|
|
|
undoChangeProperty(P_BEAM_MODE, int(mode));
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// getProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QVariant ChordRest::getProperty(P_ID propertyId) const
|
|
|
|
{
|
|
|
|
switch(propertyId) {
|
|
|
|
case P_SMALL: return QVariant(small());
|
|
|
|
case P_BEAM_MODE: return int(beamMode());
|
2012-08-12 11:44:36 +02:00
|
|
|
default: return DurationElement::getProperty(propertyId);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool ChordRest::setProperty(P_ID propertyId, const QVariant& v)
|
|
|
|
{
|
|
|
|
switch(propertyId) {
|
|
|
|
case P_SMALL: setSmall(v.toBool()); break;
|
|
|
|
case P_BEAM_MODE: setBeamMode(BeamMode(v.toInt())); break;
|
2012-08-12 11:44:36 +02:00
|
|
|
default: return DurationElement::setProperty(propertyId, v);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
score()->setLayoutAll(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-12 11:44:36 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// propertyDefault
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QVariant ChordRest::propertyDefault(P_ID propertyId) const
|
|
|
|
{
|
|
|
|
switch(propertyId) {
|
|
|
|
case P_SMALL: return false;
|
2013-03-05 20:23:59 +01:00
|
|
|
case P_BEAM_MODE: return int(BeamMode::AUTO);
|
2012-08-12 11:44:36 +02:00
|
|
|
default: return DurationElement::propertyDefault(propertyId);
|
|
|
|
}
|
|
|
|
score()->setLayoutAll(true);
|
|
|
|
}
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|