Skip to content

Bar numbers revamp #28662

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 15 additions & 12 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace mu::engraving {

MStaff::~MStaff()
{
delete m_noText;
delete m_measureNumber;
delete m_mmRangeText;
delete m_lines;
delete m_vspacerUp;
Expand All @@ -102,7 +102,7 @@ MStaff::~MStaff()

MStaff::MStaff(const MStaff& m)
{
m_noText = 0;
m_measureNumber = 0;
m_mmRangeText = 0;
m_lines = Factory::copyStaffLines(*m.m_lines);
m_hasVoices = m.m_hasVoices;
Expand Down Expand Up @@ -131,8 +131,8 @@ void MStaff::setScore(Score* score)
if (m_vspacerDown) {
m_vspacerDown->setScore(score);
}
if (m_noText) {
m_noText->setScore(score);
if (m_measureNumber) {
m_measureNumber->setScore(score);
}
if (m_mmRangeText) {
m_mmRangeText->setScore(score);
Expand All @@ -154,8 +154,8 @@ void MStaff::setTrack(track_idx_t track)
if (m_vspacerDown) {
m_vspacerDown->setTrack(track);
}
if (m_noText) {
m_noText->setTrack(track);
if (m_measureNumber) {
m_measureNumber->setTrack(track);
}
if (m_mmRangeText) {
m_mmRangeText->setTrack(track);
Expand Down Expand Up @@ -819,7 +819,7 @@ void Measure::add(EngravingItem* e)
if (e->isStyled(Pid::OFFSET)) {
e->setOffset(e->propertyDefault(Pid::OFFSET).value<PointF>());
}
m_mstaves[e->staffIdx()]->setNoText(toMeasureNumber(e));
m_mstaves[e->staffIdx()]->setMeasureNumber(toMeasureNumber(e));
}
break;

Expand Down Expand Up @@ -932,7 +932,7 @@ void Measure::remove(EngravingItem* e)
break;

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

case ElementType::MMREST_RANGE:
Expand Down Expand Up @@ -2063,20 +2063,23 @@ void Measure::scanElements(void* data, void (* func)(void*, EngravingItem*), boo
MeasureBase::scanElements(data, func, all);

for (staff_idx_t staffIdx = 0; staffIdx < nstaves; ++staffIdx) {
MStaff* ms = m_mstaves[staffIdx];
if (ms->measureNumber()) {
func(data, ms->measureNumber());
}

if (!all && !(visible(staffIdx) && score()->staff(staffIdx)->show()) && !isCutawayClef(staffIdx)) {
continue;
}
MStaff* ms = m_mstaves[staffIdx];

func(data, ms->lines());
if (ms->vspacerUp()) {
func(data, ms->vspacerUp());
}
if (ms->vspacerDown()) {
func(data, ms->vspacerDown());
}
if (ms->noText()) {
func(data, ms->noText());
}

if (ms->mmRangeText()) {
func(data, ms->mmRangeText());
}
Expand Down
10 changes: 5 additions & 5 deletions src/engraving/dom/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class MStaff
void setScore(Score*);
void setTrack(track_idx_t);

MeasureNumber* noText() const { return m_noText; }
void setNoText(MeasureNumber* t) { m_noText = t; }
MeasureNumber* measureNumber() const { return m_measureNumber; }
void setMeasureNumber(MeasureNumber* t) { m_measureNumber = t; }

MMRestRange* mmRangeText() const { return m_mmRangeText; }
void setMMRangeText(MMRestRange* r) { m_mmRangeText = r; }
Expand Down Expand Up @@ -117,7 +117,7 @@ class MStaff
void setMeasureRepeatCount(int n) { m_measureRepeatCount = n; }

private:
MeasureNumber* m_noText = nullptr; // Measure number text object
MeasureNumber* m_measureNumber = nullptr; // Measure number text object
MMRestRange* m_mmRangeText = nullptr; // Multi measure rest range text object
StaffLines* m_lines = nullptr;
Spacer* m_vspacerUp = nullptr;
Expand Down Expand Up @@ -177,8 +177,8 @@ class Measure final : public MeasureBase
void setStaffStemless(staff_idx_t staffIdx, bool stemless);
bool corrupted(staff_idx_t staffIdx) const { return m_mstaves[staffIdx]->corrupted(); }
void setCorrupted(staff_idx_t staffIdx, bool val) { m_mstaves[staffIdx]->setCorrupted(val); }
MeasureNumber* noText(staff_idx_t staffIdx) const { return m_mstaves[staffIdx]->noText(); }
void setNoText(staff_idx_t staffIdx, MeasureNumber* t) { m_mstaves[staffIdx]->setNoText(t); }
MeasureNumber* measureNumber(staff_idx_t staffIdx) const { return m_mstaves[staffIdx]->measureNumber(); }
void setMeasureNumber(staff_idx_t staffIdx, MeasureNumber* t) { m_mstaves[staffIdx]->setMeasureNumber(t); }

const std::vector<MStaff*>& mstaves() const { return m_mstaves; }
std::vector<MStaff*>& mstaves() { return m_mstaves; }
Expand Down
24 changes: 2 additions & 22 deletions src/engraving/dom/measurenumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace mu::engraving {

static const ElementStyle measureNumberStyle {
{ Sid::measureNumberVPlacement, Pid::PLACEMENT },
{ Sid::measureNumberHPlacement, Pid::HPLACEMENT },
{ Sid::measureNumberMinDistance, Pid::MIN_DISTANCE }
{ Sid::measureNumberMinDistance, Pid::MIN_DISTANCE },
{ Sid::measureNumberTextStyle, Pid::TEXT_STYLE }
};

//---------------------------------------------------------
Expand All @@ -46,8 +46,6 @@ MeasureNumber::MeasureNumber(Measure* parent, TextStyleType tid)
: MeasureNumberBase(ElementType::MEASURE_NUMBER, parent, tid)
{
initElementStyle(&measureNumberStyle);

setHPlacement(style().styleV(Sid::measureNumberHPlacement).value<PlacementH>());
}

//---------------------------------------------------------
Expand All @@ -60,22 +58,4 @@ MeasureNumber::MeasureNumber(const MeasureNumber& other)
{
initElementStyle(&measureNumberStyle);
}

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

engraving::PropertyValue MeasureNumber::propertyDefault(Pid id) const
{
switch (id) {
case Pid::TEXT_STYLE:
return TextStyleType::MEASURE_NUMBER;
case Pid::PLACEMENT:
return style().styleV(Sid::measureNumberVPlacement);
case Pid::HPLACEMENT:
return style().styleV(Sid::measureNumberHPlacement);
default:
return MeasureNumberBase::propertyDefault(id);
}
}
} // namespace MS
2 changes: 0 additions & 2 deletions src/engraving/dom/measurenumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class MeasureNumber : public MeasureNumberBase
MeasureNumber(const MeasureNumber& other);

virtual MeasureNumber* clone() const override { return new MeasureNumber(*this); }

PropertyValue propertyDefault(Pid id) const override;
};
} // namespace mu::engraving

Expand Down
46 changes: 0 additions & 46 deletions src/engraving/dom/measurenumberbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,51 +51,5 @@ MeasureNumberBase::MeasureNumberBase(const MeasureNumberBase& other)
: TextBase(other)
{
setFlag(ElementFlag::ON_STAFF, true);
setHPlacement(other.hPlacement());
}

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

engraving::PropertyValue MeasureNumberBase::getProperty(Pid id) const
{
switch (id) {
case Pid::HPLACEMENT:
return int(hPlacement());
default:
return TextBase::getProperty(id);
}
}

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

bool MeasureNumberBase::setProperty(Pid id, const PropertyValue& val)
{
switch (id) {
case Pid::HPLACEMENT:
setHPlacement(val.value<PlacementH>());
mutldata()->layoutInvalid = true;
triggerLayout();
return true;
default:
return TextBase::setProperty(id, val);
}
}

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

PropertyValue MeasureNumberBase::propertyDefault(Pid id) const
{
switch (id) {
case Pid::TEXT_STYLE:
return TextStyleType::DEFAULT;
default:
return TextBase::propertyDefault(id);
}
}
} // namespace MS
10 changes: 0 additions & 10 deletions src/engraving/dom/measurenumberbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,9 @@ class MeasureNumberBase : public TextBase
MeasureNumberBase(const ElementType& type, Measure* parent = nullptr, TextStyleType = TextStyleType::DEFAULT);
MeasureNumberBase(const MeasureNumberBase& other);

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

Measure* measure() const { return toMeasure(explicitParent()); }

bool isEditable() const override { return false; } // The measure numbers' text should not be editable

PlacementH hPlacement() const { return m_placementH; }
void setHPlacement(PlacementH p) { m_placementH = p; }

private:
PlacementH m_placementH = PlacementH::LEFT;
};
} // namespace mu::engraving

Expand Down
17 changes: 2 additions & 15 deletions src/engraving/dom/mmrestrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static const ElementStyle mmRestRangeStyle {
{ Sid::mmRestRangeBracketType, Pid::MMREST_RANGE_BRACKET_TYPE },
{ Sid::mmRestRangeVPlacement, Pid::PLACEMENT },
{ Sid::mmRestRangeHPlacement, Pid::HPLACEMENT },
{ Sid::mmRestRangeMinDistance, Pid::MIN_DISTANCE }
{ Sid::mmRestRangeMinDistance, Pid::MIN_DISTANCE },
{ Sid::mmRestRangeTextStyle, Pid::TEXT_STYLE }
};

MMRestRange::MMRestRange(Measure* parent)
Expand Down Expand Up @@ -83,20 +84,6 @@ bool MMRestRange::setProperty(Pid id, const PropertyValue& val)
}
}

PropertyValue MMRestRange::propertyDefault(Pid id) const
{
switch (id) {
case Pid::TEXT_STYLE:
return TextStyleType::MMREST_RANGE;
case Pid::PLACEMENT:
return style().styleV(Sid::mmRestRangeVPlacement);
case Pid::HPLACEMENT:
return style().styleV(Sid::mmRestRangeHPlacement);
default:
return MeasureNumberBase::propertyDefault(id);
}
}

//---------------------------------------------------------
// setXmlText
/// This is reimplemented from TextBase::setXmlText to take care of the brackets
Expand Down
1 change: 0 additions & 1 deletion src/engraving/dom/mmrestrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class MMRestRange : public MeasureNumberBase

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

void setXmlText(const String&) override;
};
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::IS_COURTESY, false, "isCourtesy", P_TYPE::BOOL, PropertyGroup::NONE, DUMMY_QT_TR_NOOP("propertyName", "is courtesy") },
{ Pid::EXCLUDE_VERTICAL_ALIGN, false, "excludeVerticalAlign", P_TYPE::BOOL, PropertyGroup::POSITION, DUMMY_QT_TR_NOOP("propertyName", "exclude vertical align") },

{ Pid::SHOW_MEASURE_NUMBERS, false, "showMeasureNumbers", P_TYPE::AUTO_ON_OFF, PropertyGroup::NONE, DUMMY_QT_TR_NOOP("propertyName", "show bar numbers")},

{ Pid::END, false, "++end++", P_TYPE::INT, PropertyGroup::NONE, DUMMY_QT_TR_NOOP("propertyName", "<invalid property>") }
};
/* *INDENT-ON* */
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ enum class Pid {

EXCLUDE_VERTICAL_ALIGN,

SHOW_MEASURE_NUMBERS,

END
};

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/scoretree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ EngravingObjectList Measure::scanChildren() const
children.push_back(_vspacerDown);
}

if (MeasureNumber* _noText = noText(staffIdx)) {
if (MeasureNumber* _noText = measureNumber(staffIdx)) {
children.push_back(_noText);
}

Expand Down
28 changes: 28 additions & 0 deletions src/engraving/dom/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,27 @@ bool Staff::trackHasLinksInVoiceZero(track_idx_t track)
return false;
}

void Staff::undoSetShowMeasureNumbers(bool show)
{
bool isTopStave = score()->staves().front() == this;
if (show) {
undoChangeProperty(Pid::SHOW_MEASURE_NUMBERS, isTopStave ? AutoOnOff::AUTO : AutoOnOff::ON);
} else {
undoChangeProperty(Pid::SHOW_MEASURE_NUMBERS, isTopStave ? AutoOnOff::OFF : AutoOnOff::AUTO);
}
}

bool Staff::shouldShowMeasureNumbers() const
{
if (style().styleB(Sid::measureNumberAllStaves)) {
return true;
}

bool isTopStave = score()->staves().front() == this;
bool isSystemObjectStaff = muse::contains(score()->systemObjectStaves(), const_cast<Staff*>(this));
return isTopStave && m_showMeasureNumbers != AutoOnOff::OFF || isSystemObjectStaff && m_showMeasureNumbers == AutoOnOff::ON;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return isTopStave && m_showMeasureNumbers != AutoOnOff::OFF || isSystemObjectStaff && m_showMeasureNumbers == AutoOnOff::ON;
return (isTopStave && m_showMeasureNumbers != AutoOnOff::OFF) || (isSystemObjectStaff && m_showMeasureNumbers == AutoOnOff::ON);

}

//---------------------------------------------------------
// fillBrackets
// make sure index idx is valid
Expand Down Expand Up @@ -1524,6 +1545,8 @@ PropertyValue Staff::getProperty(Pid id) const
return userDist();
case Pid::GENERATED:
return false;
case Pid::SHOW_MEASURE_NUMBERS:
return m_showMeasureNumbers;
default:
LOGD("unhandled id <%s>", propertyName(id));
return PropertyValue();
Expand Down Expand Up @@ -1597,6 +1620,9 @@ bool Staff::setProperty(Pid id, const PropertyValue& v)
case Pid::STAFF_USERDIST:
setUserDist(v.value<Spatium>());
break;
case Pid::SHOW_MEASURE_NUMBERS:
m_showMeasureNumbers = v.value<AutoOnOff>();
break;
default:
LOGD("unhandled id <%s>", propertyName(id));
break;
Expand Down Expand Up @@ -1630,6 +1656,8 @@ PropertyValue Staff::propertyDefault(Pid id) const
return 0;
case Pid::STAFF_USERDIST:
return Spatium(0.0);
case Pid::SHOW_MEASURE_NUMBERS:
return AutoOnOff::AUTO;
default:
LOGD("unhandled id <%s>", propertyName(id));
return PropertyValue();
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/dom/staff.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ class Staff final : public EngravingItem
track_idx_t getLinkedTrackInStaff(const Staff* linkedStaff, const track_idx_t strack) const;
bool trackHasLinksInVoiceZero(track_idx_t track);

void undoSetShowMeasureNumbers(bool show);
bool shouldShowMeasureNumbers() const;

private:

friend class Factory;
Expand Down Expand Up @@ -313,6 +316,8 @@ class Staff final : public EngravingItem
PitchList m_pitchOffsets; // cached value

bool m_reflectTranspositionInLinkedTab = true;

AutoOnOff m_showMeasureNumbers = AutoOnOff::AUTO;
};
} // namespace mu::engraving
#endif
1 change: 1 addition & 0 deletions src/engraving/dom/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "repeatlist.h"
#include "keysig.h"
#include "measure.h"
#include "measurenumber.h"
#include "note.h"
#include "page.h"
#include "part.h"
Expand Down
Loading
Loading