Skip to content

Commit

Permalink
Add option to show measure number interval in mmrests
Browse files Browse the repository at this point in the history
the MMRestRange is a new class derived from MeasureNumber.
The logic is handled by layoutMeasureNumber, as if it was an usual measurenumber.

MMRestRange may not be styled like MeasureNumber, so a new set of textstyles were added.
There is 3 possible bracketing around the ranges: parentheses, brackets, or none (the default).
  • Loading branch information
ecstrema committed Apr 29, 2020
1 parent 0a49685 commit 26cff22
Show file tree
Hide file tree
Showing 15 changed files with 439 additions and 52 deletions.
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
22 changes: 18 additions & 4 deletions 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 Down Expand Up @@ -433,7 +434,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 @@ -486,6 +487,10 @@ bool Measure::showsMeasureNumberInAutoMode()
if (irregular())
return false;

// MMRests have an option to show the measure number range
if (isMMRest())
return score()->styleB(Sid::mmRestShowMeasureNumberRange);

// Measure numbers should not show on first measure unless specified with Sid::showMeasureNumberOne
if (!no())
return score()->styleB(Sid::showMeasureNumberOne);
Expand Down Expand Up @@ -536,8 +541,12 @@ void Measure::layoutMeasureNumber()
bool smn = showsMeasureNumber();

QString s;
if (smn)
s = QString("%1").arg(no() + 1);
if (smn) {
if (isMMRest())
s = QString("%1–%2").arg(no() + 1).arg(no() + mmRestCount()); // middle char is an en dash (not em)
else
s = QString("%1").arg(no() + 1);
}
unsigned nn = 1;
bool nas = score()->styleB(Sid::measureNumberAllStaves);

Expand All @@ -560,12 +569,17 @@ void Measure::layoutMeasureNumber()
t->setTrack(staffIdx * VOICES);
if (smn && ((staffIdx == nn) || nas)) {
if (t == 0) {
t = new MeasureNumber(score());
if (isMMRest())
t = new MMRestRange(score());
else
t = new MeasureNumber(score());
t->setTrack(staffIdx * VOICES);
t->setGenerated(true);
t->setParent(this);
add(t);
}
// in the case of a mmrest range, setXmlText is overriden to take care
// of special bracketing
t->setXmlText(s);
t->layout();
}
Expand Down
7 changes: 2 additions & 5 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 @@ -92,10 +93,6 @@ QVariant MeasureNumber::propertyDefault(Pid id) const
switch(id) {
case Pid::SUB_STYLE:
return int(Tid::MEASURE_NUMBER);
case Pid::PLACEMENT:
return score()->styleV(Sid::measureNumberVPlacement);
case Pid::HPLACEMENT:
return score()->styleV(Sid::measureNumberHPlacement);;
default:
return TextBase::propertyDefault(id);
}
Expand Down
6 changes: 4 additions & 2 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 to show the measureNumberRange with mmrests
//---------------------------------------------------------

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 Down
127 changes: 127 additions & 0 deletions libmscore/mmrestrange.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2020 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#include "score.h"
#include "mmrestrange.h"
#include "measure.h"
#include "staff.h"

namespace Ms {

//---------------------------------------------------------
// mmRestRangeStyle
//---------------------------------------------------------

static const ElementStyle mmRestRangeStyle {
{ Sid::mmRestRangeBracketType, Pid::MMREST_RANGE_BRACKET_TYPE },
{ Sid::mmRestRangeVPlacement, Pid::PLACEMENT },
{ Sid::mmRestRangeHPlacement, Pid::HPLACEMENT }
};

//---------------------------------------------------------
// MMRestRange
//---------------------------------------------------------

MMRestRange::MMRestRange(Score* s) : MeasureNumber(s, Tid::MMREST_RANGE)
{
initElementStyle(&mmRestRangeStyle);
}

//---------------------------------------------------------
// getProperty
//---------------------------------------------------------

QVariant MMRestRange::getProperty(Pid id) const
{
switch (id) {
case Pid::MMREST_RANGE_BRACKET_TYPE:
return int(bracketType());
default:
return MeasureNumber::getProperty(id);
}
}

//---------------------------------------------------------
// setProperty
//---------------------------------------------------------

bool MMRestRange::setProperty(Pid id, const QVariant& val)
{
switch (id) {
case Pid::MMREST_RANGE_BRACKET_TYPE:
setBracketType(MMRestRangeBracketType(val.toInt()));
setLayoutInvalid();
triggerLayout();
return true;
default:
return MeasureNumber::setProperty(id, val);
}
}

//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------

QVariant MMRestRange::propertyDefault(Pid id) const
{
switch(id) {
case Pid::SUB_STYLE:
return int(Tid::MMREST_RANGE);
default:
return MeasureNumber::propertyDefault(id);
}
}

//---------------------------------------------------------
// readProperties
//---------------------------------------------------------

bool MMRestRange::readProperties(XmlReader& xml)
{
if (readProperty(xml.name(), xml, Pid::MMREST_RANGE_BRACKET_TYPE))
return true;
else
return MeasureNumber::readProperties(xml);
}

//---------------------------------------------------------
// setXmlText
/// This is reimplemented from TextBase::setXmlText to take care of the brackets
//---------------------------------------------------------

void MMRestRange::setXmlText(const QString& s)
{
switch (bracketType()) {
case MMRestRangeBracketType::BRACKETS:
TextBase::setXmlText("[" + s + "]");
break;
case MMRestRangeBracketType::PARENTHESES:
TextBase::setXmlText("(" + s + ")");
break;
case MMRestRangeBracketType::NONE:
TextBase::setXmlText(s);
break;
default:
Q_UNREACHABLE();
break;
}
}

} // namespace MS

55 changes: 55 additions & 0 deletions libmscore/mmrestrange.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2020 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#ifndef __MMRESTRANGE_H__
#define __MMRESTRANGE_H__

#include "measurenumber.h"
#include "property.h"

namespace Ms {

//---------------------------------------------------------
// MMRestRange
//---------------------------------------------------------

class MMRestRange : public MeasureNumber {

/// Bracketing: [18-24], (18-24) or 18-24
M_PROPERTY (MMRestRangeBracketType, bracketType, setBracketType)

public:
MMRestRange(Score* s = nullptr);

virtual ElementType type() const override { return ElementType::MEASURE_NUMBER; }
virtual MMRestRange* clone() const override { return new MMRestRange(*this); }

virtual QVariant getProperty(Pid id) const override;
virtual bool setProperty(Pid id, const QVariant& val) override;
virtual QVariant propertyDefault(Pid id) const override;

virtual bool readProperties(XmlReader&) override;

virtual void setXmlText(const QString&) override;
};

} // namespace Ms

#endif

1 change: 1 addition & 0 deletions libmscore/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::CHANGE_METHOD, true, "changeMethod", P_TYPE::CHANGE_METHOD, DUMMY_QT_TRANSLATE_NOOP("propertyName", "change method") }, // the new, more general version of VELO_CHANGE_METHOD
{ Pid::PLACEMENT, false, "placement", P_TYPE::PLACEMENT, DUMMY_QT_TRANSLATE_NOOP("propertyName", "placement") },
{ Pid::HPLACEMENT, false, "hplacement", P_TYPE::HPLACEMENT, DUMMY_QT_TRANSLATE_NOOP("propertyName", "horizontal placement") },
{ Pid::MMREST_RANGE_BRACKET_TYPE, false, "mmrestRangeBracketType", P_TYPE::INT, DUMMY_QT_TRANSLATE_NOOP("propertyName", "multi-measure rest range bracket type") },
{ Pid::VELOCITY, false, "velocity", P_TYPE::INT, DUMMY_QT_TRANSLATE_NOOP("propertyName", "velocity") },
{ Pid::JUMP_TO, true, "jumpTo", P_TYPE::STRING, DUMMY_QT_TRANSLATE_NOOP("propertyName", "jump to") },
{ Pid::PLAY_UNTIL, true, "playUntil", P_TYPE::STRING, DUMMY_QT_TRANSLATE_NOOP("propertyName", "play until") },
Expand Down
3 changes: 2 additions & 1 deletion libmscore/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ enum class Pid {
CHANGE_METHOD,
PLACEMENT, // Goes with P_TYPE::PLACEMENT
HPLACEMENT, // Goes with P_TYPE::HPLACEMENT
MMREST_RANGE_BRACKET_TYPE, // The brackets used arond the measure numbers indicating the range covered by the mmrest
VELOCITY,
JUMP_TO,
PLAY_UNTIL,
Expand Down Expand Up @@ -396,7 +397,7 @@ enum class P_TYPE : char {
FONT,
SUB_STYLE,
ALIGN,
CHANGE_METHOD, // enum class VeloChangeMethod (for single notedynamics)
CHANGE_METHOD, // enum class VeloChangeMethod (for single note dynamics)
CHANGE_SPEED, // enum class Dynamic::Speed
CLEF_TYPE, // enum class ClefType
DYNAMIC_TYPE, // enum class Dynamic::Type
Expand Down
38 changes: 38 additions & 0 deletions libmscore/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,26 @@ static const StyleType styleTypes[] {
{ Sid::measureNumberFrameFgColor, "measureNumberFrameFgColor", QColor(0, 0, 0, 255) },
{ Sid::measureNumberFrameBgColor, "measureNumberFrameBgColor", QColor(255, 255, 255, 0) },

{ Sid::mmRestShowMeasureNumberRange, "mmRestShowMeasureNumberRange", false },
{ Sid::mmRestRangeBracketType, "mmRestRangeBracketType", int(MMRestRangeBracketType::NONE) },

{ Sid::mmRestRangeFontFace, "mmRestRangeFontFace", "FreeSerif" },
{ Sid::mmRestRangeFontSize, "mmRestRangeFontSize", 8.0 },
{ Sid::mmRestRangeFontSpatiumDependent, "mmRestRangeFontSpatiumDependent", true },
{ Sid::mmRestRangeFontStyle, "mmRestRangeFontStyle", int(FontStyle::Normal) },
{ Sid::mmRestRangeColor, "mmRestRangeColor", QColor(0, 0, 0, 255) },
{ Sid::mmRestRangeOffset, "mmRestRangeOffset", QPointF(0.0, 0.0) },
{ Sid::mmRestRangeOffsetType, "mmRestRangeOffsetType", int(OffsetType::SPATIUM) },
{ Sid::mmRestRangeVPlacement, "mmRestRangeVPlacement", int(Placement::ABOVE) },
{ Sid::mmRestRangeHPlacement, "mmRestRangeHPlacement", int(HPlacement::LEFT) },
{ Sid::mmRestRangeAlign, "mmRestRangeAlign", QVariant::fromValue(Align::HCENTER | Align::BASELINE) },
{ Sid::mmRestRangeFrameType, "mmRestRangeFrameType", int(FrameType::NO_FRAME) },
{ Sid::mmRestRangeFramePadding, "mmRestRangeFramePadding", 0.2 },
{ Sid::mmRestRangeFrameWidth, "mmRestRangeFrameWidth", 0.1 },
{ Sid::mmRestRangeFrameRound, "mmRestRangeFrameRound", 0 },
{ Sid::mmRestRangeFrameFgColor, "mmRestRangeFrameFgColor", QColor(0, 0, 0, 255) },
{ Sid::mmRestRangeFrameBgColor, "mmRestRangeFrameBgColor", QColor(255, 255, 255, 0) },

{ Sid::translatorFontFace, "translatorFontFace", "FreeSerif" },
{ Sid::translatorFontSize, "translatorFontSize", 11.0 },
{ Sid::translatorFontSpatiumDependent, "translatorFontSpatiumDependent", false },
Expand Down Expand Up @@ -1630,6 +1650,22 @@ const TextStyle measureNumberTextStyle {{
{ Sid::measureNumberFrameBgColor, Pid::FRAME_BG_COLOR },
}};

const TextStyle mmRestRangeTextStyle {{
{ Sid::mmRestRangeFontFace, Pid::FONT_FACE },
{ Sid::mmRestRangeFontSize, Pid::FONT_SIZE },
{ Sid::mmRestRangeFontSpatiumDependent, Pid::SIZE_SPATIUM_DEPENDENT },
{ Sid::mmRestRangeFontStyle, Pid::FONT_STYLE },
{ Sid::mmRestRangeColor, Pid::COLOR },
{ Sid::mmRestRangeAlign, Pid::ALIGN },
{ Sid::mmRestRangeOffset, Pid::OFFSET },
{ Sid::mmRestRangeFrameType, Pid::FRAME_TYPE },
{ Sid::mmRestRangeFramePadding, Pid::FRAME_PADDING },
{ Sid::mmRestRangeFrameWidth, Pid::FRAME_WIDTH },
{ Sid::mmRestRangeFrameRound, Pid::FRAME_ROUND },
{ Sid::mmRestRangeFrameFgColor, Pid::FRAME_FG_COLOR },
{ Sid::mmRestRangeFrameBgColor, Pid::FRAME_BG_COLOR },
}};

const TextStyle translatorTextStyle {{
{ Sid::translatorFontFace, Pid::FONT_FACE },
{ Sid::translatorFontSize, Pid::FONT_SIZE },
Expand Down Expand Up @@ -2255,6 +2291,7 @@ static constexpr std::array<TextStyleName, int(Tid::TEXT_STYLES)> textStyles { {
{ QT_TRANSLATE_NOOP("TextStyle", "Tempo"), &tempoTextStyle, Tid::TEMPO },
{ QT_TRANSLATE_NOOP("TextStyle", "Metronome"), &metronomeTextStyle, Tid::METRONOME },
{ QT_TRANSLATE_NOOP("TextStyle", "Measure Number"), &measureNumberTextStyle, Tid::MEASURE_NUMBER },
{ QT_TRANSLATE_NOOP("TextStyle", "Multi Measure Rest Range"), &mmRestRangeTextStyle, Tid::MMREST_RANGE },
{ QT_TRANSLATE_NOOP("TextStyle", "Translator"), &translatorTextStyle, Tid::TRANSLATOR },
{ QT_TRANSLATE_NOOP("TextStyle", "Tuplet"), &tupletTextStyle, Tid::TUPLET },

Expand Down Expand Up @@ -2369,6 +2406,7 @@ static const std::vector<Tid> _primaryTextStyles = {
Tid::HEADER,
Tid::FOOTER,
Tid::MEASURE_NUMBER,
Tid::MMREST_RANGE,
Tid::INSTRUMENT_EXCERPT,
Tid::INSTRUMENT_CHANGE,
Tid::STAFF,
Expand Down
Loading

0 comments on commit 26cff22

Please sign in to comment.