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 "measurebase.h"
|
|
|
|
#include "measure.h"
|
|
|
|
#include "staff.h"
|
|
|
|
#include "score.h"
|
|
|
|
#include "chord.h"
|
|
|
|
#include "note.h"
|
|
|
|
#include "layoutbreak.h"
|
|
|
|
#include "image.h"
|
|
|
|
#include "segment.h"
|
|
|
|
#include "tempo.h"
|
2016-01-04 14:48:58 +01:00
|
|
|
#include "xml.h"
|
2016-10-18 15:41:00 +02:00
|
|
|
#include "system.h"
|
2016-12-18 14:31:13 +01:00
|
|
|
#include "stafftypechange.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
|
|
|
//---------------------------------------------------------
|
|
|
|
// MeasureBase
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
MeasureBase::MeasureBase(Score* score)
|
|
|
|
: Element(score)
|
|
|
|
{
|
2016-10-20 11:32:07 +02:00
|
|
|
setIrregular(true);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MeasureBase::MeasureBase(const MeasureBase& m)
|
|
|
|
: Element(m)
|
|
|
|
{
|
2016-10-20 11:32:07 +02:00
|
|
|
_next = m._next;
|
|
|
|
_prev = m._prev;
|
|
|
|
_tick = m._tick;
|
|
|
|
_no = m._no;
|
|
|
|
_noOffset = m._noOffset;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2016-01-04 14:48:58 +01:00
|
|
|
for (Element* e : m._el)
|
2012-05-26 14:26:10 +02:00
|
|
|
add(e->clone());
|
|
|
|
}
|
|
|
|
|
2015-02-17 21:12:19 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// clearElements
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::clearElements()
|
|
|
|
{
|
|
|
|
qDeleteAll(_el);
|
|
|
|
_el.clear();
|
|
|
|
}
|
|
|
|
|
2015-02-25 10:48:39 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// takeElements
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ElementList MeasureBase::takeElements()
|
|
|
|
{
|
|
|
|
ElementList l = _el;
|
|
|
|
_el.clear();
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// setScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::setScore(Score* score)
|
|
|
|
{
|
|
|
|
Element::setScore(score);
|
2016-02-09 09:20:54 +01:00
|
|
|
for (Element* e : _el)
|
2012-05-26 14:26:10 +02:00
|
|
|
e->setScore(score);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// MeasureBase
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
MeasureBase::~MeasureBase()
|
|
|
|
{
|
2016-02-09 09:20:54 +01:00
|
|
|
qDeleteAll(_el);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// scanElements
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::scanElements(void* data, void (*func)(void*, Element*), bool all)
|
|
|
|
{
|
2015-02-23 11:45:04 +01:00
|
|
|
if (isMeasure()) {
|
2016-02-09 09:20:54 +01:00
|
|
|
for (Element* e : _el) {
|
2012-05-26 14:26:10 +02:00
|
|
|
if (score()->tagIsValid(e->tag())) {
|
2014-11-10 14:18:42 +01:00
|
|
|
if (e->staffIdx() >= score()->staves().size())
|
|
|
|
qDebug("MeasureBase::scanElements: bad staffIdx %d in element %s", e->staffIdx(), e->name());
|
2015-01-18 02:30:14 +01:00
|
|
|
if ((e->track() == -1) || e->systemFlag() || ((Measure*)this)->visible(e->staffIdx()))
|
2012-05-26 14:26:10 +02:00
|
|
|
e->scanElements(data, func, all);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-02-09 09:20:54 +01:00
|
|
|
for (Element* e : _el) {
|
2012-05-26 14:26:10 +02:00
|
|
|
if (score()->tagIsValid(e->tag()))
|
|
|
|
e->scanElements(data, func, all);
|
|
|
|
}
|
|
|
|
}
|
2017-06-16 10:34:13 +02:00
|
|
|
if (isBox())
|
|
|
|
func(data, this);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// add
|
2015-02-17 20:22:24 +01:00
|
|
|
/// Add new Element \a el to MeasureBase
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::add(Element* e)
|
|
|
|
{
|
|
|
|
e->setParent(this);
|
2016-10-12 17:56:05 +02:00
|
|
|
if (e->isLayoutBreak()) {
|
2016-03-30 22:33:04 +02:00
|
|
|
LayoutBreak* b = toLayoutBreak(e);
|
2013-03-05 20:23:59 +01:00
|
|
|
switch (b->layoutBreakType()) {
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::PAGE:
|
2016-10-20 11:32:07 +02:00
|
|
|
setPageBreak(true);
|
|
|
|
setLineBreak(false);
|
|
|
|
setNoBreak(false);
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::LINE:
|
2016-10-20 11:32:07 +02:00
|
|
|
setPageBreak(false);
|
|
|
|
setLineBreak(true);
|
|
|
|
setSectionBreak(false);
|
|
|
|
setNoBreak(false);
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::SECTION:
|
2016-10-20 11:32:07 +02:00
|
|
|
setLineBreak(false);
|
|
|
|
setSectionBreak(true);
|
|
|
|
setNoBreak(false);
|
2016-10-13 14:28:00 +02:00
|
|
|
//does not work with repeats: score()->tempomap()->setPause(endTick(), b->pause());
|
2019-10-24 15:49:23 +02:00
|
|
|
triggerLayoutAll();
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::NOBREAK:
|
2016-10-20 11:32:07 +02:00
|
|
|
setPageBreak(false);
|
|
|
|
setLineBreak(false);
|
|
|
|
setSectionBreak(false);
|
|
|
|
setNoBreak(true);
|
2016-10-12 17:56:05 +02:00
|
|
|
break;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
2016-12-09 15:56:48 +01:00
|
|
|
if (next())
|
2019-10-24 15:49:23 +02:00
|
|
|
next()->triggerLayout();
|
|
|
|
// triggerLayoutAll(); // TODO
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
2016-10-18 15:41:00 +02:00
|
|
|
triggerLayout();
|
2013-03-25 16:27:20 +01:00
|
|
|
_el.push_back(e);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// remove
|
2015-02-17 20:22:24 +01:00
|
|
|
/// Remove Element \a el from MeasureBase.
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::remove(Element* el)
|
|
|
|
{
|
2016-02-09 09:20:54 +01:00
|
|
|
if (el->isLayoutBreak()) {
|
2016-02-17 14:54:23 +01:00
|
|
|
LayoutBreak* lb = toLayoutBreak(el);
|
2013-03-05 20:23:59 +01:00
|
|
|
switch (lb->layoutBreakType()) {
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::PAGE:
|
2016-10-20 11:32:07 +02:00
|
|
|
setPageBreak(false);
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::LINE:
|
2016-10-20 11:32:07 +02:00
|
|
|
setLineBreak(false);
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::SECTION:
|
2016-10-20 11:32:07 +02:00
|
|
|
setSectionBreak(false);
|
2018-03-22 06:49:11 +01:00
|
|
|
score()->setPause(endTick(), 0);
|
2019-10-24 15:49:23 +02:00
|
|
|
triggerLayoutAll();
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
2016-10-12 17:56:05 +02:00
|
|
|
case LayoutBreak::NOBREAK:
|
2016-10-20 11:32:07 +02:00
|
|
|
setNoBreak(false);
|
2016-10-12 17:56:05 +02:00
|
|
|
break;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-17 21:12:19 +01:00
|
|
|
if (!_el.remove(el)) {
|
2014-03-25 13:33:47 +01:00
|
|
|
qDebug("MeasureBase(%p)::remove(%s,%p) not found", this, el->name(), el);
|
2015-02-17 21:12:19 +01:00
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// nextMeasure
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Measure* MeasureBase::nextMeasure() const
|
|
|
|
{
|
2012-08-01 18:00:27 +02:00
|
|
|
MeasureBase* m = _next;
|
|
|
|
for (;;) {
|
2016-10-18 15:41:00 +02:00
|
|
|
if (m == 0 || m->isMeasure())
|
2012-08-01 18:00:27 +02:00
|
|
|
break;
|
|
|
|
m = m->_next;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
2016-10-18 15:41:00 +02:00
|
|
|
return toMeasure(m);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
2013-09-19 15:08:54 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// nextMeasureMM
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Measure* MeasureBase::nextMeasureMM() const
|
|
|
|
{
|
2015-03-30 10:42:27 +02:00
|
|
|
Measure* mm = nextMeasure();
|
2018-03-27 15:36:00 +02:00
|
|
|
if (mm && score()->styleB(Sid::createMultiMeasureRests) && mm->hasMMRest())
|
2013-09-20 12:59:31 +02:00
|
|
|
return mm->mmRest();
|
|
|
|
return mm;
|
2013-09-19 15:08:54 +02:00
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// prevMeasure
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Measure* MeasureBase::prevMeasure() const
|
|
|
|
{
|
|
|
|
MeasureBase* m = prev();
|
|
|
|
while (m) {
|
2016-10-18 15:41:00 +02:00
|
|
|
if (m->isMeasure())
|
|
|
|
return toMeasure(m);
|
2012-05-26 14:26:10 +02:00
|
|
|
m = m->prev();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-27 18:43:25 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// prevMeasure
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Measure* MeasureBase::prevMeasureMM() const
|
|
|
|
{
|
|
|
|
MeasureBase* m = prev();
|
|
|
|
while (m) {
|
2016-10-18 15:41:00 +02:00
|
|
|
if (m->isMeasure()) {
|
|
|
|
Measure* mm = toMeasure(m);
|
2018-03-27 15:36:00 +02:00
|
|
|
if (score()->styleB(Sid::createMultiMeasureRests)) {
|
2013-09-27 18:43:25 +02:00
|
|
|
if (mm->mmRestCount() >= 0) {
|
|
|
|
if (mm->hasMMRest())
|
|
|
|
return mm->mmRest();
|
|
|
|
return mm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return mm;
|
|
|
|
}
|
|
|
|
m = m->prev();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// pause
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
qreal MeasureBase::pause() const
|
|
|
|
{
|
2016-10-20 11:32:07 +02:00
|
|
|
return sectionBreak() ? sectionBreakElement()->pause() : 0.0;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::layout()
|
|
|
|
{
|
|
|
|
int breakCount = 0;
|
|
|
|
|
2016-02-09 09:20:54 +01:00
|
|
|
for (Element* element : _el) {
|
2012-05-26 14:26:10 +02:00
|
|
|
if (!score()->tagIsValid(element->tag()))
|
|
|
|
continue;
|
2016-02-09 09:20:54 +01:00
|
|
|
if (element->isLayoutBreak()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
qreal _spatium = spatium();
|
2016-10-12 17:56:05 +02:00
|
|
|
qreal x;
|
|
|
|
qreal y;
|
|
|
|
if (toLayoutBreak(element)->isNoBreak()) {
|
|
|
|
x = width() - element->width() * .5;
|
|
|
|
y = -(_spatium + element->height());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = -_spatium - element->width() + width()
|
2012-05-26 14:26:10 +02:00
|
|
|
- breakCount * (element->width() + _spatium * .8);
|
2016-10-12 17:56:05 +02:00
|
|
|
y = -2 * _spatium - element->height();
|
|
|
|
breakCount++;
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
element->setPos(x, y);
|
|
|
|
}
|
2018-02-01 10:37:12 +01:00
|
|
|
else if (element->isMarker() || element->isJump())
|
|
|
|
;
|
2014-08-05 20:40:43 +02:00
|
|
|
else
|
|
|
|
element->layout();
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 15:49:23 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// triggerLayout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::triggerLayout() const
|
|
|
|
{
|
|
|
|
if (prev() || next()) // avoid triggering layout before getting added to a score
|
|
|
|
score()->setLayout(tick(), -1, this);
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// first
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
MeasureBase* Score::first() const
|
|
|
|
{
|
|
|
|
return _measures.first();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// last
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
MeasureBase* Score::last() const
|
|
|
|
{
|
|
|
|
return _measures.last();
|
|
|
|
}
|
|
|
|
|
2012-08-02 18:33:43 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// getProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
QVariant MeasureBase::getProperty(Pid id) const
|
2012-08-02 18:33:43 +02:00
|
|
|
{
|
2016-02-09 09:20:54 +01:00
|
|
|
switch (id) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::REPEAT_END:
|
2016-02-04 11:27:47 +01:00
|
|
|
return repeatEnd();
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::REPEAT_START:
|
2016-02-04 11:27:47 +01:00
|
|
|
return repeatStart();
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::REPEAT_JUMP:
|
2016-02-04 11:27:47 +01:00
|
|
|
return repeatJump();
|
2019-01-09 06:30:28 +01:00
|
|
|
case Pid::NO_OFFSET:
|
|
|
|
return noOffset();
|
|
|
|
case Pid::IRREGULAR:
|
|
|
|
return irregular();
|
2012-08-02 18:33:43 +02:00
|
|
|
default:
|
|
|
|
return Element::getProperty(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setProperty
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
bool MeasureBase::setProperty(Pid id, const QVariant& value)
|
2012-08-02 18:33:43 +02:00
|
|
|
{
|
2016-02-09 09:20:54 +01:00
|
|
|
switch (id) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::REPEAT_END:
|
2016-02-04 11:27:47 +01:00
|
|
|
setRepeatEnd(value.toBool());
|
|
|
|
break;
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::REPEAT_START:
|
2016-02-04 11:27:47 +01:00
|
|
|
setRepeatStart(value.toBool());
|
|
|
|
break;
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::REPEAT_JUMP:
|
2016-02-04 11:27:47 +01:00
|
|
|
setRepeatJump(value.toBool());
|
2012-08-02 18:33:43 +02:00
|
|
|
break;
|
2019-01-09 06:30:28 +01:00
|
|
|
case Pid::NO_OFFSET:
|
|
|
|
setNoOffset(value.toInt());
|
|
|
|
break;
|
|
|
|
case Pid::IRREGULAR:
|
|
|
|
setIrregular(value.toBool());
|
|
|
|
break;
|
2012-08-02 18:33:43 +02:00
|
|
|
default:
|
2016-02-04 11:27:47 +01:00
|
|
|
if (!Element::setProperty(id, value))
|
2012-08-02 18:33:43 +02:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2019-10-24 15:49:23 +02:00
|
|
|
triggerLayoutAll();
|
2019-05-23 19:23:52 +02:00
|
|
|
score()->setPlaylistDirty();
|
2012-08-02 18:33:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-21 19:53:24 +02:00
|
|
|
//---------------------------------------------------------
|
2016-02-04 11:27:47 +01:00
|
|
|
// propertyDefault
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
QVariant MeasureBase::propertyDefault(Pid propertyId) const
|
2016-02-04 11:27:47 +01:00
|
|
|
{
|
2016-02-09 09:20:54 +01:00
|
|
|
switch (propertyId) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::REPEAT_END:
|
|
|
|
case Pid::REPEAT_START:
|
|
|
|
case Pid::REPEAT_JUMP:
|
2016-02-04 11:27:47 +01:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Element::propertyDefault(propertyId);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// undoSetBreak
|
2013-08-21 19:53:24 +02:00
|
|
|
//---------------------------------------------------------
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2014-06-25 13:57:29 +02:00
|
|
|
void MeasureBase::undoSetBreak(bool v, LayoutBreak::Type type)
|
2013-08-21 19:53:24 +02:00
|
|
|
{
|
2016-10-12 17:56:05 +02:00
|
|
|
switch (type) {
|
|
|
|
case LayoutBreak::LINE:
|
|
|
|
if (lineBreak() == v)
|
|
|
|
return;
|
2016-12-16 18:45:54 +01:00
|
|
|
setLineBreak(v);
|
2016-10-12 17:56:05 +02:00
|
|
|
break;
|
|
|
|
case LayoutBreak::PAGE:
|
|
|
|
if (pageBreak() == v)
|
|
|
|
return;
|
2016-10-13 14:28:00 +02:00
|
|
|
if (v && lineBreak())
|
|
|
|
setLineBreak(false);
|
2016-12-16 18:45:54 +01:00
|
|
|
setPageBreak(v);
|
2016-10-12 17:56:05 +02:00
|
|
|
break;
|
|
|
|
case LayoutBreak::SECTION:
|
2016-10-13 14:28:00 +02:00
|
|
|
if (sectionBreak() == v)
|
2016-10-12 17:56:05 +02:00
|
|
|
return;
|
2016-10-13 14:28:00 +02:00
|
|
|
if (v && lineBreak())
|
|
|
|
setLineBreak(false);
|
2016-12-16 18:45:54 +01:00
|
|
|
setSectionBreak(v);
|
2016-10-12 17:56:05 +02:00
|
|
|
break;
|
|
|
|
case LayoutBreak::NOBREAK:
|
|
|
|
if (noBreak() == v)
|
|
|
|
return;
|
2016-10-13 14:28:00 +02:00
|
|
|
if (v) {
|
|
|
|
setLineBreak(false);
|
|
|
|
setPageBreak(false);
|
|
|
|
setSectionBreak(false);
|
|
|
|
}
|
2016-12-16 18:45:54 +01:00
|
|
|
setNoBreak(v);
|
2016-10-12 17:56:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-21 19:53:24 +02:00
|
|
|
if (v) {
|
2016-03-10 10:41:31 +01:00
|
|
|
LayoutBreak* lb = new LayoutBreak(score());
|
2013-08-21 19:53:24 +02:00
|
|
|
lb->setLayoutBreakType(type);
|
|
|
|
lb->setTrack(-1); // this are system elements
|
2018-12-05 20:51:32 +01:00
|
|
|
MeasureBase* mb = (isMeasure() && toMeasure(this)->isMMRest()) ? toMeasure(this)->mmRestLast() : this;
|
|
|
|
lb->setParent(mb);
|
2016-03-10 10:41:31 +01:00
|
|
|
score()->undoAddElement(lb);
|
2013-08-21 19:53:24 +02:00
|
|
|
}
|
2016-10-13 14:28:00 +02:00
|
|
|
cleanupLayoutBreaks(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// cleanupLayoutBreaks
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MeasureBase::cleanupLayoutBreaks(bool undo)
|
|
|
|
{
|
|
|
|
// remove unneeded layout breaks
|
|
|
|
std::vector<Element*> toDelete;
|
|
|
|
for (Element* e : el()) {
|
|
|
|
if (e->isLayoutBreak()) {
|
|
|
|
switch (toLayoutBreak(e)->layoutBreakType()) {
|
|
|
|
case LayoutBreak::LINE:
|
|
|
|
if (!lineBreak())
|
|
|
|
toDelete.push_back(e);
|
|
|
|
break;
|
|
|
|
case LayoutBreak::PAGE:
|
|
|
|
if (!pageBreak())
|
|
|
|
toDelete.push_back(e);
|
|
|
|
break;
|
|
|
|
case LayoutBreak::SECTION:
|
|
|
|
if (!sectionBreak())
|
|
|
|
toDelete.push_back(e);
|
|
|
|
break;
|
|
|
|
case LayoutBreak::NOBREAK:
|
|
|
|
if (!noBreak())
|
|
|
|
toDelete.push_back(e);
|
|
|
|
break;
|
2013-08-21 19:53:24 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-13 14:28:00 +02:00
|
|
|
}
|
|
|
|
for (Element* e : toDelete) {
|
|
|
|
if (undo)
|
|
|
|
score()->undoRemoveElement(e);
|
|
|
|
else
|
|
|
|
_el.remove(e);
|
2013-08-21 19:53:24 +02:00
|
|
|
}
|
|
|
|
}
|
2013-09-19 15:08:54 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// nextMM
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
MeasureBase* MeasureBase::nextMM() const
|
|
|
|
{
|
|
|
|
if (_next
|
2016-02-09 09:20:54 +01:00
|
|
|
&& _next->isMeasure()
|
2018-03-27 15:36:00 +02:00
|
|
|
&& score()->styleB(Sid::createMultiMeasureRests)
|
2016-10-18 15:41:00 +02:00
|
|
|
&& toMeasure(_next)->hasMMRest()) {
|
2016-02-17 14:54:23 +01:00
|
|
|
return toMeasure(_next)->mmRest();
|
2013-09-19 15:08:54 +02:00
|
|
|
}
|
|
|
|
return _next;
|
|
|
|
}
|
2016-01-04 14:48:58 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// writeProperties
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-11-19 11:51:21 +01:00
|
|
|
void MeasureBase::writeProperties(XmlWriter& xml) const
|
2016-01-04 14:48:58 +01:00
|
|
|
{
|
|
|
|
Element::writeProperties(xml);
|
|
|
|
for (const Element* e : el())
|
|
|
|
e->write(xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// readProperties
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool MeasureBase::readProperties(XmlReader& e)
|
|
|
|
{
|
|
|
|
const QStringRef& tag(e.name());
|
|
|
|
if (tag == "LayoutBreak") {
|
|
|
|
LayoutBreak* lb = new LayoutBreak(score());
|
|
|
|
lb->read(e);
|
2016-10-13 14:28:00 +02:00
|
|
|
bool doAdd = true;
|
|
|
|
switch (lb->layoutBreakType()) {
|
|
|
|
case LayoutBreak::LINE:
|
|
|
|
if (lineBreak())
|
|
|
|
doAdd = false;
|
|
|
|
break;
|
|
|
|
case LayoutBreak::PAGE:
|
|
|
|
if (pageBreak())
|
|
|
|
doAdd = false;
|
|
|
|
break;
|
|
|
|
case LayoutBreak::SECTION:
|
|
|
|
if (sectionBreak())
|
|
|
|
doAdd = false;
|
|
|
|
break;
|
|
|
|
case LayoutBreak::NOBREAK:
|
|
|
|
if (noBreak())
|
|
|
|
doAdd = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (doAdd) {
|
|
|
|
add(lb);
|
|
|
|
cleanupLayoutBreaks(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete lb;
|
2016-01-04 14:48:58 +01:00
|
|
|
}
|
2016-12-18 14:31:13 +01:00
|
|
|
else if (tag == "StaffTypeChange") {
|
|
|
|
StaffTypeChange* stc = new StaffTypeChange(score());
|
|
|
|
stc->setTrack(e.track());
|
|
|
|
stc->setParent(this);
|
|
|
|
stc->read(e);
|
|
|
|
add(stc);
|
|
|
|
}
|
2016-01-04 14:48:58 +01:00
|
|
|
else if (Element::readProperties(e))
|
|
|
|
;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// index
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
int MeasureBase::index() const
|
|
|
|
{
|
|
|
|
int idx = 0;
|
|
|
|
MeasureBase* m = score()->first();
|
|
|
|
while (m) {
|
|
|
|
if (m == this)
|
|
|
|
return idx;
|
|
|
|
m = m->next();
|
2018-05-23 00:32:33 +02:00
|
|
|
++idx;
|
2016-01-04 14:48:58 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2016-10-13 14:28:00 +02:00
|
|
|
|
2018-08-14 23:15:43 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// measureIndex
|
|
|
|
// returns index of measure counting only Measures but
|
|
|
|
// skipping other MeasureBase descendants
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
int MeasureBase::measureIndex() const
|
|
|
|
{
|
|
|
|
int idx = 0;
|
|
|
|
MeasureBase* m = score()->first();
|
|
|
|
while (m) {
|
|
|
|
if (m == this)
|
|
|
|
return idx;
|
|
|
|
m = m->next();
|
2018-09-17 17:42:27 +02:00
|
|
|
if (m && m->isMeasure())
|
2018-08-14 23:15:43 +02:00
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-10-13 14:28:00 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// sectionBreakElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
LayoutBreak* MeasureBase::sectionBreakElement() const
|
|
|
|
{
|
2016-10-20 11:32:07 +02:00
|
|
|
if (sectionBreak()) {
|
2016-10-13 14:28:00 +02:00
|
|
|
for (Element* e : el()) {
|
|
|
|
if (e->isLayoutBreak() && toLayoutBreak(e)->isSectionBreak())
|
|
|
|
return toLayoutBreak(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|