Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mu3] Fix #214996: Add a style option to show measure number range at mmrests #6935

Merged
merged 2 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libmscore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ add_library (
segmentlist.h select.h sequencer.h shadownote.h shape.h sig.h slur.h slurtie.h spacer.h spanner.h spannermap.h spatium.h
staff.h stafflines.h staffstate.h stafftext.h stafftextbase.h stafftype.h stafftypechange.h stafftypelist.h stem.h
stemslash.h stringdata.h style.h sym.h symbol.h synthesizerstate.h system.h systemdivider.h systemtext.h tempo.h
tempotext.h text.h measurenumber.h textbase.h textedit.h textframe.h textline.h textlinebase.h tie.h tiemap.h timesig.h
tempotext.h text.h mmrestrange.h measurenumber.h textbase.h textedit.h textframe.h textline.h textlinebase.h tie.h tiemap.h timesig.h
tremolo.h tremolobar.h trill.h tuplet.h tupletmap.h types.h undo.h utils.h vibrato.h volta.h xml.h

segmentlist.cpp fingering.cpp accidental.cpp arpeggio.cpp
Expand All @@ -75,7 +75,7 @@ add_library (
score.cpp segment.cpp select.cpp shadownote.cpp slur.cpp tie.cpp slurtie.cpp
spacer.cpp spanner.cpp staff.cpp staffstate.cpp
stafftextbase.cpp stafftext.cpp systemtext.cpp stafftype.cpp stem.cpp style.cpp symbol.cpp
sym.cpp system.cpp stringdata.cpp tempotext.cpp text.cpp measurenumber.cpp textbase.cpp textedit.cpp
sym.cpp system.cpp stringdata.cpp tempotext.cpp text.cpp mmrestrange.cpp measurenumber.cpp textbase.cpp textedit.cpp
textframe.cpp textline.cpp textlinebase.cpp timesig.cpp
tremolobar.cpp tremolo.cpp trill.cpp tuplet.cpp
utils.cpp volta.cpp xmlreader.cpp xmlwriter.cpp mscore.cpp
Expand Down
2 changes: 2 additions & 0 deletions libmscore/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "textframe.h"
#include "text.h"
#include "measurenumber.h"
#include "mmrestrange.h"
#include "textline.h"
#include "tie.h"
#include "timesig.h"
Expand Down Expand Up @@ -1072,6 +1073,7 @@ Element* Element::create(ElementType type, Score* score)
case ElementType::DYNAMIC: return new Dynamic(score);
case ElementType::TEXT: return new Text(score);
case ElementType::MEASURE_NUMBER: return new MeasureNumber(score);
case ElementType::MMREST_RANGE: return new MMRestRange(score);
case ElementType::INSTRUMENT_NAME: return new InstrumentName(score);
case ElementType::STAFF_TEXT: return new StaffText(score);
case ElementType::SYSTEM_TEXT: return new SystemText(score);
Expand Down
2 changes: 2 additions & 0 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4018,6 +4018,8 @@ void Score::layoutSystemElements(System* system, LayoutContext& lc)
continue;
Measure* m = toMeasure(mb);
m->layoutMeasureNumber();
m->layoutMMRestRange();

// in continuous view, entire score is one system
// but we only need to process the range
if (lineMode() && (m->tick() < lc.startTick || m->tick() > lc.endTick))
Expand Down
88 changes: 87 additions & 1 deletion libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "system.h"
#include "tempotext.h"
#include "measurenumber.h"
#include "mmrestrange.h"
#include "tie.h"
#include "tiemap.h"
#include "timesig.h"
Expand All @@ -91,6 +92,7 @@ namespace Ms {

class MStaff {
MeasureNumber* _noText { 0 }; ///< Measure number text object
MMRestRange* _mmRangeText { 0 }; ///< Multi measure rest range text object
StaffLines* _lines { 0 };
Spacer* _vspacerUp { 0 };
Spacer* _vspacerDown { 0 };
Expand All @@ -113,6 +115,9 @@ class MStaff {
MeasureNumber* noText() const { return _noText; }
void setNoText(MeasureNumber* t) { _noText = t; }

MMRestRange *mmRangeText() const { return _mmRangeText; }
void setMMRangeText(MMRestRange *r) { _mmRangeText = r; }

StaffLines* lines() const { return _lines; }
void setLines(StaffLines* l) { _lines = l; }

Expand All @@ -139,6 +144,7 @@ class MStaff {
MStaff::~MStaff()
{
delete _noText;
delete _mmRangeText;
delete _lines;
delete _vspacerUp;
delete _vspacerDown;
Expand All @@ -147,6 +153,7 @@ MStaff::~MStaff()
MStaff::MStaff(const MStaff& m)
{
_noText = 0;
_mmRangeText = 0;
_lines = new StaffLines(*m._lines);
_hasVoices = m._hasVoices;
_vspacerUp = 0;
Expand All @@ -172,6 +179,8 @@ void MStaff::setScore(Score* score)
_vspacerDown->setScore(score);
if (_noText)
_noText->setScore(score);
if (_mmRangeText)
_mmRangeText->setScore(score);
}

//---------------------------------------------------------
Expand All @@ -188,6 +197,8 @@ void MStaff::setTrack(int track)
_vspacerDown->setTrack(track);
if (_noText)
_noText->setTrack(track);
if(_mmRangeText)
_mmRangeText->setTrack(track);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -298,6 +309,9 @@ void Measure::setCorrupted(int staffIdx, bool val) { _mstaves[staff
void Measure::setNoText(int staffIdx, MeasureNumber* t) { _mstaves[staffIdx]->setNoText(t); }
MeasureNumber* Measure::noText(int staffIdx) const { return _mstaves[staffIdx]->noText(); }

void Measure::setMMRangeText(int staffIdx, MMRestRange* t) { _mstaves[staffIdx]->setMMRangeText(t); }
MMRestRange* Measure::mmRangeText(int staffIdx) const { return _mstaves[staffIdx]->mmRangeText(); }

//---------------------------------------------------------
// Measure
//---------------------------------------------------------
Expand Down Expand Up @@ -433,7 +447,7 @@ AccidentalVal Measure::findAccidental(Segment* s, int staffIdx, int line, bool &

//---------------------------------------------------------
// tick2pos
// return x position for tick relative to System
/// return x position for tick relative to System
//---------------------------------------------------------

qreal Measure::tick2pos(Fraction tck) const
Expand Down Expand Up @@ -538,6 +552,7 @@ void Measure::layoutMeasureNumber()
QString s;
if (smn)
s = QString("%1").arg(no() + 1);

unsigned nn = 1;
bool nas = score()->styleB(Sid::measureNumberAllStaves);

Expand Down Expand Up @@ -580,6 +595,52 @@ void Measure::layoutMeasureNumber()
}
}

void Measure::layoutMMRestRange()
{
if (!isMMRest() || !score()->styleB(Sid::mmRestShowMeasureNumberRange)) {
// Remove existing
for (unsigned staffIdx = 0; staffIdx < _mstaves.size(); ++staffIdx) {
MStaff *ms = _mstaves[staffIdx];
MMRestRange *rr = ms->mmRangeText();
if (rr) {
if (rr->generated())
score()->removeElement(rr);
else
score()->undo(new RemoveElement(rr));
}
}

return;
}


QString s;
if (mmRestCount() > 1) {
// middle char is an en dash (not em)
s = QString("%1–%2").arg(no() + 1).arg(no() + mmRestCount());
}
else {
// If the minimum range to create a mmrest is set to 1,
// then simply show the measure number as there is no range
s = QString("%1").arg(no() + 1);
}

for (unsigned staffIdx = 0; staffIdx < _mstaves.size(); ++staffIdx) {
MStaff *ms = _mstaves[staffIdx];
MMRestRange *rr = ms->mmRangeText();
if (!rr) {
rr = new MMRestRange(score());
rr->setTrack(staffIdx * VOICES);
rr->setGenerated(true);
rr->setParent(this);
add(rr);
}
// setXmlText is reimplemented to take care of brackets
rr->setXmlText(s);
rr->layout();
}
}

//---------------------------------------------------------
// layout2
// called after layout of page
Expand Down Expand Up @@ -819,6 +880,14 @@ void Measure::add(Element* e)
}
break;

case ElementType::MMREST_RANGE:
if (e->staffIdx() < int(_mstaves.size())) {
if (e->isStyled(Pid::OFFSET))
e->setOffset(e->propertyDefault(Pid::OFFSET).toPointF());
_mstaves[e->staffIdx()]->setMMRangeText(toMMRestRange(e));
}
break;

case ElementType::SPACER:
{
Spacer* sp = toSpacer(e);
Expand Down Expand Up @@ -913,6 +982,12 @@ void Measure::remove(Element* e)

case ElementType::MEASURE_NUMBER:
_mstaves[e->staffIdx()]->setNoText(nullptr);
delete e;
break;

case ElementType::MMREST_RANGE:
_mstaves[e->staffIdx()]->setMMRangeText(nullptr);
delete e;
break;

case ElementType::SPACER:
Expand Down Expand Up @@ -1878,6 +1953,9 @@ void Measure::write(XmlWriter& xml, int staff, bool writeSystemElements, bool fo
if (mstaff->noText() && !mstaff->noText()->generated())
mstaff->noText()->write(xml);

if (mstaff->mmRangeText() && !mstaff->mmRangeText()->generated())
mstaff->mmRangeText()->write(xml);

if (mstaff->vspacerUp())
xml.tag("vspacerUp", mstaff->vspacerUp()->gap() / _spatium);
if (mstaff->vspacerDown()) {
Expand Down Expand Up @@ -2030,6 +2108,12 @@ void Measure::read(XmlReader& e, int staffIdx)
noText->setTrack(e.track());
add(noText);
}
else if (tag == "MMRestRange") {
MMRestRange* range = new MMRestRange(score());
range->read(e);
range->setTrack(e.track());
add(range);
}
else if (MeasureBase::readProperties(e))
;
else
Expand Down Expand Up @@ -2517,6 +2601,8 @@ void Measure::scanElements(void* data, void (*func)(void*, Element*), bool all)
func(data, ms->vspacerDown());
if (ms->noText())
func(data, ms->noText());
if (ms->mmRangeText())
func(data, ms->mmRangeText());
}

for (Segment* s = first(); s; s = s->next()) {
Expand Down
5 changes: 4 additions & 1 deletion libmscore/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Tuplet;
class Staff;
class Chord;
class MeasureNumber;
class MMRestRange;
class ChordRest;
class Score;
class MuseScoreView;
Expand Down Expand Up @@ -130,6 +131,8 @@ class Measure final : public MeasureBase {
void setCorrupted(int staffIdx, bool val);
void setNoText(int staffIdx, MeasureNumber*);
MeasureNumber* noText(int staffIdx) const;
void setMMRangeText(int staffIdx, MMRestRange *);
MMRestRange *mmRangeText(int staffIdx) const;

void createStaves(int);

Expand Down Expand Up @@ -162,6 +165,7 @@ class Measure final : public MeasureBase {
bool showsMeasureNumber();
bool showsMeasureNumberInAutoMode();
void layoutMeasureNumber();
void layoutMMRestRange();

Chord* findChord(Fraction tick, int track);
ChordRest* findChordRest(Fraction tick, int track);
Expand Down Expand Up @@ -278,4 +282,3 @@ class Measure final : public MeasureBase {

} // namespace Ms
#endif

6 changes: 3 additions & 3 deletions libmscore/measurenumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static const ElementStyle measureNumberStyle {
// MeasureNumber
//---------------------------------------------------------

MeasureNumber::MeasureNumber(Score* s) : TextBase(s, Tid::MEASURE_NUMBER)
MeasureNumber::MeasureNumber(Score* s, Tid tid, ElementFlags flags)
: TextBase(s, tid, flags)
{
setFlag(ElementFlag::ON_STAFF, true);
initElementStyle(&measureNumberStyle);
Expand Down Expand Up @@ -95,7 +96,7 @@ QVariant MeasureNumber::propertyDefault(Pid id) const
case Pid::PLACEMENT:
return score()->styleV(Sid::measureNumberVPlacement);
case Pid::HPLACEMENT:
return score()->styleV(Sid::measureNumberHPlacement);;
return score()->styleV(Sid::measureNumberHPlacement);
default:
return TextBase::propertyDefault(id);
}
Expand Down Expand Up @@ -197,4 +198,3 @@ void MeasureNumber::layout()
}

} // namespace MS

7 changes: 4 additions & 3 deletions libmscore/measurenumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ namespace Ms {

//---------------------------------------------------------
// MeasureNumber
/// The basic element making measure numbers.
/// Reimplemented by MMRestRange
//---------------------------------------------------------

class MeasureNumber final : public TextBase {
class MeasureNumber : public TextBase {

M_PROPERTY (HPlacement, hPlacement, setHPlacement) // Horizontal Placement

public:
MeasureNumber(Score* s = nullptr);
MeasureNumber(Score* = nullptr, Tid tid = Tid::MEASURE_NUMBER, ElementFlags flags = ElementFlag::NOTHING);
MeasureNumber(const MeasureNumber& other);

virtual ElementType type() const override { return ElementType::MEASURE_NUMBER; }
Expand All @@ -47,4 +49,3 @@ class MeasureNumber final : public TextBase {
} // namespace Ms

#endif

Loading