Skip to content
Permalink
Browse files

Merge pull request #2150 from MarcSabatella/cutaway

Support temporary & cutaway staves
  • Loading branch information...
wschweer committed Oct 28, 2015
2 parents 3d70f05 + 51cf4df commit e35a2a124dbe7a5e4632278768f1e8c88f189bbc
@@ -238,18 +238,24 @@ void BarLine::getY(qreal* y1, qreal* y2) const
Staff* staff2 = score()->staff(staffIdx2);
SysStaff* sysStaff1 = system->staff(staffIdx1);
SysStaff* sysStaff2 = system->staff(staffIdx2);
SysStaff* sysStaff1a = nullptr; // first staff that is shown, even if it has invisible measures
Measure* nm = measure->nextMeasure();
if (nm && nm->system() != measure->system())
nm = nullptr;
while (span > 0) {
bool show1 = sysStaff1->show() && staff1->show();
// if start staff not shown, reduce span and move one staff down

if ( !(sysStaff1->show() && staff1->show()) ) {
if (!(show1 && (measure->visible(staffIdx1) || (nm && nm->visible(staffIdx1))))) {
span--;
if (show1 && !sysStaff1a)
sysStaff1a = sysStaff1; // use for its y offset
if (staffIdx1 >= nstaves-1) // running out of staves?
break;
sysStaff1 = system->staff(++staffIdx1);
staff1 = score()->staff(staffIdx1);
}
// if end staff not shown, reduce span and move one staff up
else if ( !(sysStaff2->show() && staff2->show()) ) {
else if (!(sysStaff2->show() && staff2->show() && (measure->visible(staffIdx2) || (nm && nm->visible(staffIdx2))))) {
span--;
if (staffIdx2 == 0)
break;
@@ -280,7 +286,8 @@ void BarLine::getY(qreal* y1, qreal* y2) const
// ordinary barline within system, parent is measure
// base y on top visible staff in barline span
// after skipping ones with hideSystemBarLine set
yp = sysStaff1->y();
// and accounting for staves that are shown but have invisible measures
yp = sysStaff1a ? sysStaff1a->y() : sysStaff1->y();
}
*y1 = l1->y1() - yp;
*y1 += (_spanFrom * staff1->lineDistance() * staff1->spatium()) / 2;
@@ -2364,11 +2364,12 @@ void Score::hideEmptyStaves(System* system, bool isFirstSystem)
foreach (Staff* staff, _staves) {
SysStaff* s = system->staff(staffIdx);
bool oldShow = s->show();
if (styleB(StyleIdx::hideEmptyStaves)
&& (staves > 1)
&& !(isFirstSystem && styleB(StyleIdx::dontHideStavesInFirstSystem))
&& !staff->neverHide()
) {
Staff::HideMode hideMode = staff->hideWhenEmpty();
if (hideMode == Staff::HideMode::ALWAYS
|| (styleB(StyleIdx::hideEmptyStaves)
&& (staves > 1)
&& !(isFirstSystem && styleB(StyleIdx::dontHideStavesInFirstSystem))
&& hideMode != Staff::HideMode::NEVER)) {
bool hideStaff = true;
foreach(MeasureBase* m, system->measures()) {
if (m->type() != Element::Type::MEASURE)
@@ -2412,12 +2412,14 @@ void Measure::read(XmlReader& e, int staffIdx)

bool Measure::visible(int staffIdx) const
{
if (system() && (system()->staves()->isEmpty() || !system()->staff(staffIdx)->show()))
return false;
if (staffIdx >= score()->staves().size()) {
qDebug("Measure::visible: bad staffIdx: %d", staffIdx);
return false;
}
if (system() && (system()->staves()->isEmpty() || !system()->staff(staffIdx)->show()))
return false;
if (score()->staff(staffIdx)->cutaway() && isMeasureRest(staffIdx))
return false;
return score()->staff(staffIdx)->show() && staves[staffIdx]->_visible;
}

@@ -2847,7 +2849,7 @@ bool Measure::hasVoice(int track) const
/// all staves.
//-------------------------------------------------------------------

bool Measure::isMeasureRest(int staffIdx)
bool Measure::isMeasureRest(int staffIdx) const
{
int strack;
int etrack;
@@ -2875,7 +2877,7 @@ bool Measure::isMeasureRest(int staffIdx)
// rests.
//---------------------------------------------------------

bool Measure::isFullMeasureRest()
bool Measure::isFullMeasureRest() const
{
int strack = 0;
int etrack = score()->nstaves() * VOICES;
@@ -2898,7 +2900,7 @@ bool Measure::isFullMeasureRest()
// isRepeatMeasure
//---------------------------------------------------------

bool Measure::isRepeatMeasure(Staff* staff)
bool Measure::isRepeatMeasure(Staff* staff) const
{
int staffIdx = score()->staffIdx(staff);
int strack = staffIdx * VOICES;
@@ -288,9 +288,9 @@ class Measure : public MeasureBase {
void exchangeVoice(int voice1, int voice2, int staffIdx);
void checkMultiVoices(int staffIdx);
bool hasVoice(int track) const;
bool isMeasureRest(int staffIdx);
bool isFullMeasureRest();
bool isRepeatMeasure(Staff* staff);
bool isMeasureRest(int staffIdx) const;
bool isFullMeasureRest() const;
bool isRepeatMeasure(Staff* staff) const;
bool visible(int staffIdx) const;
bool slashStyle(int staffIdx) const;

@@ -303,7 +303,6 @@ class Measure : public MeasureBase {
bool isEmpty() const;
bool isOnlyRests(int track) const;


void layoutStage1();
int playbackCount() const { return _playbackCount; }
void setPlaybackCount(int val) { _playbackCount = val; }
@@ -1003,7 +1003,7 @@ void Segment::scanElements(void* data, void (*func)(void*, Element*), bool all)
if (e == 0) // if no element, skip
continue;
// if staff not visible
if (!all && !(measure()->visible(staffIdx) && _score->staff(staffIdx)->show())) {
if (!all && !(/*measure()->visible(staffIdx) && */_score->staff(staffIdx)->show())) {
// if bar line spans just this staff...
if (static_cast<BarLine*>(e)->span() <= 1
// ...or span another staff but without entering INTO it...
@@ -482,8 +482,10 @@ void Staff::write(Xml& xml) const
xml.tag("small", small());
if (invisible())
xml.tag("invisible", invisible());
if (neverHide())
xml.tag("neverHide", neverHide());
if (hideWhenEmpty() != HideMode::AUTO)
xml.tag("hideWhenEmpty", int(hideWhenEmpty()));
if (cutaway())
xml.tag("cutaway", cutaway());
if (showIfEmpty())
xml.tag("showIfSystemEmpty", showIfEmpty());
if (_hideSystemBarLine)
@@ -561,8 +563,15 @@ void Staff::read(XmlReader& e)
setSmall(e.readInt());
else if (tag == "invisible")
setInvisible(e.readInt());
else if (tag == "neverHide")
setNeverHide(e.readInt());
else if (tag == "hideWhenEmpty")
setHideWhenEmpty(HideMode(e.readInt()));
else if (tag == "neverHide") { // 2.0 compatibility
bool v = e.readInt();
if (v)
setHideWhenEmpty(HideMode::NEVER);
}
else if (tag == "cutaway")
setCutaway(e.readInt());
else if (tag == "showIfSystemEmpty")
setShowIfEmpty(e.readInt());
else if (tag == "hideSystemBarLine")
@@ -919,7 +928,8 @@ void Staff::init(const Staff* s)
_barLineFrom = s->_barLineFrom;
_barLineTo = s->_barLineTo;
_invisible = s->_invisible;
_neverHide = s->_neverHide;
_hideWhenEmpty = s->_hideWhenEmpty;
_cutaway = s->_cutaway;
_showIfEmpty = s->_showIfEmpty;
_hideSystemBarLine = s->_hideSystemBarLine;
_color = s->_color;
@@ -95,6 +95,10 @@ struct SwingParameters {
class Staff : public QObject, public ScoreElement {
Q_OBJECT

public:
enum class HideMode { AUTO, ALWAYS, NEVER };

private:
Part* _part { 0 };

ClefList clefs;
@@ -109,9 +113,10 @@ class Staff : public QObject, public ScoreElement {
int _barLineTo; ///< line of end staff to draw the bar line to (0= staff top line, ...)
bool _small { false };
bool _invisible { false };
bool _neverHide { false }; ///< always show this staff, even if empty and hideEmptyStaves is true
bool _cutaway { false };
bool _showIfEmpty { false }; ///< show this staff if system is empty and hideEmptyStaves is true
bool _hideSystemBarLine { false }; // no system barline if not preceeded by staff with barline
HideMode _hideWhenEmpty { HideMode::AUTO }; // hide empty staves

QColor _color { MScore::defaultColor };
qreal _userDist { 0.0 }; ///< user edited extra distance
@@ -183,13 +188,15 @@ class Staff : public QObject, public ScoreElement {
void setSmall(bool val) { _small = val; }
bool invisible() const { return _invisible; }
void setInvisible(bool val) { _invisible = val; }
bool neverHide() const { return _neverHide; }
void setNeverHide(bool val) { _neverHide = val; }
bool cutaway() const { return _cutaway; }
void setCutaway(bool val) { _cutaway = val; }
bool showIfEmpty() const { return _showIfEmpty; }
void setShowIfEmpty(bool val) { _showIfEmpty = val; }

void setHideSystemBarLine(bool val) { _hideSystemBarLine = val; }
bool hideSystemBarLine() const { return _hideSystemBarLine; }
void setHideSystemBarLine(bool val) { _hideSystemBarLine = val; }
HideMode hideWhenEmpty() const { return _hideWhenEmpty; }
void setHideWhenEmpty(HideMode v) { _hideWhenEmpty = v; }

void setSlashStyle(bool val);
int lines() const;
@@ -337,9 +337,12 @@ void System::layout2()
qreal _spatium = spatium();

qreal y = 0.0;
int lastStaffIdx = 0; // last visible staff
int firstStaffIdx = -1;
int firstStaffIdx = -1; // first/last visible staff
int lastStaffIdx = 0;
int firstStaffInitialIdx = -1; // first/last staff for initial barline
int lastStaffInitialIdx = 0;
qreal lastStaffDistanceDown = 0.0;
Measure* fm = firstMeasure();
for (int staffIdx = 0; staffIdx < nstaves; ++staffIdx) {
Staff* staff = score()->staff(staffIdx);
StyleIdx downDistance;
@@ -397,9 +400,16 @@ void System::layout2()
lastStaffDistanceDown = distDown - nominalDistDown;
if (firstStaffIdx == -1)
firstStaffIdx = staffIdx;
if (fm && fm->visible(staffIdx)) {
lastStaffInitialIdx = staffIdx;
if (firstStaffInitialIdx == -1)
firstStaffInitialIdx = staffIdx;
}
}
if (firstStaffIdx == -1)
firstStaffIdx = 0;
if (firstStaffInitialIdx == -1)
firstStaffInitialIdx = 0;

qreal systemHeight = staff(lastStaffIdx)->bbox().bottom();
if (lastStaffIdx < nstaves - 1)
@@ -421,15 +431,15 @@ void System::layout2()
}

if (_barLine) {
_barLine->setTrack(firstStaffIdx * VOICES);
_barLine->setSpan(lastStaffIdx - firstStaffIdx + 1);
if (score()->staff(firstStaffIdx)->lines() == 1)
_barLine->setTrack(firstStaffInitialIdx * VOICES);
_barLine->setSpan(lastStaffInitialIdx - firstStaffInitialIdx + 1);
if (score()->staff(firstStaffInitialIdx)->lines() == 1)
_barLine->setSpanFrom(BARLINE_SPAN_1LINESTAFF_FROM);
else
_barLine->setSpanFrom(0);
int spanTo = (score()->staff(lastStaffIdx)->lines() == 1) ?
int spanTo = (score()->staff(lastStaffInitialIdx)->lines() == 1) ?
BARLINE_SPAN_1LINESTAFF_TO :
(score()->staff(lastStaffIdx)->lines()-1)*2;
(score()->staff(lastStaffInitialIdx)->lines() - 1) * 2;
_barLine->setSpanTo(spanTo);
_barLine->layout();
}
@@ -2495,13 +2495,14 @@ void ChangePageFormat::flip()
//---------------------------------------------------------

ChangeStaff::ChangeStaff(Staff* _staff, bool _invisible,
qreal _userDist, bool _neverHide, bool _showIfEmpty, bool hide)
qreal _userDist, Staff::HideMode _hideMode, bool _showIfEmpty, bool _cutaway, bool hide)
{
staff = _staff;
invisible = _invisible;
userDist = _userDist;
neverHide = _neverHide;
hideMode = _hideMode;
showIfEmpty = _showIfEmpty;
cutaway = _cutaway;
hideSystemBarLine = hide;
}

@@ -2526,20 +2527,23 @@ void ChangeStaff::flip()

bool oldInvisible = staff->invisible();
qreal oldUserDist = staff->userDist();
bool oldNeverHide = staff->neverHide();
Staff::HideMode oldHideMode = staff->hideWhenEmpty();
bool oldShowIfEmpty = staff->showIfEmpty();
bool oldCutaway = staff->cutaway();
bool hide = staff->hideSystemBarLine();

staff->setInvisible(invisible);
staff->setUserDist(userDist);
staff->setNeverHide(neverHide);
staff->setHideWhenEmpty(hideMode);
staff->setShowIfEmpty(showIfEmpty);
staff->setCutaway(cutaway);
staff->setHideSystemBarLine(hideSystemBarLine);

invisible = oldInvisible;
userDist = oldUserDist;
neverHide = oldNeverHide;
hideMode = oldHideMode;
showIfEmpty = oldShowIfEmpty;
cutaway = oldCutaway;
hideSystemBarLine = hide;

Score* score = staff->score();
@@ -34,6 +34,7 @@
#include "synthesizerstate.h"
#include "bracket.h"
#include "dynamic.h"
#include "staff.h"
#include "stafftype.h"
#include "cleflist.h"
#include "note.h"
@@ -669,18 +670,19 @@ class ChangePageFormat : public UndoCommand {
//---------------------------------------------------------

class ChangeStaff : public UndoCommand {
Staff* staff;
bool invisible;
qreal userDist;
bool neverHide;
bool showIfEmpty;
bool hideSystemBarLine;
Staff* staff;
bool invisible;
qreal userDist;
Staff::HideMode hideMode;
bool showIfEmpty;
bool cutaway;
bool hideSystemBarLine;

void flip();

public:
ChangeStaff(Staff*, bool invisible, qreal userDist, bool _neverHide,
bool _showIfEmpty, bool hide);
ChangeStaff(Staff*, bool invisible, qreal userDist, Staff::HideMode _hideMode,
bool _showIfEmpty, bool _cutaway, bool hide);
UNDO_NAME("ChangeStaff")
};

@@ -71,7 +71,8 @@ EditStaff::EditStaff(Staff* s, int /*tick*/, QWidget* parent)
staff->setColor(orgStaff->color());
staff->setStaffType(orgStaff->staffType());
staff->setPart(part);
staff->setNeverHide(orgStaff->neverHide());
staff->setCutaway(orgStaff->cutaway());
staff->setHideWhenEmpty(orgStaff->hideWhenEmpty());
staff->setShowIfEmpty(orgStaff->showIfEmpty());
staff->setUserMag(orgStaff->userMag());
staff->setHideSystemBarLine(orgStaff->hideSystemBarLine());
@@ -100,7 +101,8 @@ EditStaff::EditStaff(Staff* s, int /*tick*/, QWidget* parent)
small->setChecked(staff->small());
color->setColor(s->color());
partName->setText(part->partName());
neverHide->setChecked(staff->neverHide());
cutaway->setChecked(staff->cutaway());
hideMode->setCurrentIndex(int(staff->hideWhenEmpty()));
showIfEmpty->setChecked(staff->showIfEmpty());
hideSystemBarLine->setChecked(staff->hideSystemBarLine());
mag->setValue(staff->userMag() * 100.0);
@@ -297,9 +299,10 @@ void EditStaff::apply()

bool inv = invisible->isChecked();
qreal userDist = spinExtraDistance->value();
bool nhide = neverHide->isChecked();
bool ifEmpty = showIfEmpty->isChecked();
bool hideSystemBL = hideSystemBarLine->isChecked();
bool cutAway = cutaway->isChecked();
Staff::HideMode hideEmpty = Staff::HideMode(hideMode->currentIndex());

QString newPartName = partName->text().simplified();
if (!(instrument == *part->instrument()) || part->partName() != newPartName) {
@@ -319,11 +322,12 @@ void EditStaff::apply()

if (inv != orgStaff->invisible()
|| userDist != orgStaff->userDist()
|| nhide != orgStaff->neverHide()
|| cutAway != orgStaff->cutaway()
|| hideEmpty != orgStaff->hideWhenEmpty()
|| ifEmpty != orgStaff->showIfEmpty()
|| hideSystemBL != orgStaff->hideSystemBarLine()
) {
score->undo(new ChangeStaff(orgStaff, inv, userDist * score->spatium(), nhide, ifEmpty, hideSystemBL));
score->undo(new ChangeStaff(orgStaff, inv, userDist * score->spatium(), hideEmpty, ifEmpty, cutAway, hideSystemBL));
}

if ( !(*orgStaff->staffType() == *staff->staffType()) ) {
Oops, something went wrong.

0 comments on commit e35a2a1

Please sign in to comment.
You can’t perform that action at this time.