Skip to content

Commit

Permalink
Better management of bend end note visibility from TAB to standard staff
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-spa committed Nov 30, 2023
1 parent 2594f19 commit e43a5d2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5777,6 +5777,9 @@ void Score::undoAddElement(EngravingItem* element, bool addToLinkedStaves, bool
if (newEnd) {
ne = element->linkedClone();
toSpanner(ne)->setNoteSpan(toNote(e), newEnd);
if (element->isGuitarBend() && element->staffType()->isTabStaff()) {
toGuitarBend(ne)->endNote()->setVisible(true);
}
} else { //couldn't find suitable start note
continue;
}
Expand Down
36 changes: 36 additions & 0 deletions src/engraving/dom/guitarbend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,42 @@ mu::draw::Color GuitarBend::uiColor() const
return curColor();
}

void GuitarBend::adaptBendsFromTabToStandardStaff(const Staff* staff)
{
// On tabs, bends force end notes to be invisible. When switching to
// normal staff we need to turn all the end notes visible again.

auto processBends = [](Chord* chord) {
for (Note* note : chord->notes()) {
GuitarBend* bend = note->bendFor();
if (!bend) {
continue;
}
bend->endNote()->setVisible(true);
}
};

staff_idx_t staffIdx = staff->idx();
track_idx_t startTrack = staff2track(staffIdx);
track_idx_t endTrack = startTrack + VOICES;
for (Segment* segment = staff->score()->firstSegment(SegmentType::ChordRest); segment; segment = segment->next1()) {
if (!segment->isChordRestType()) {
continue;
}
for (track_idx_t track = startTrack; track < endTrack; ++track) {
EngravingItem* item = segment->elementAt(track);
if (!item || !item->isChord()) {
continue;
}
Chord* chord = toChord(item);
processBends(chord);
for (Chord* grace : chord->graceNotes()) {
processBends(grace);
}
}
}
}

/****************************************
* GuitarBendHold
* **************************************/
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/guitarbend.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class GuitarBend final : public SLine

mu::draw::Color uiColor() const;

static void adaptBendsFromTabToStandardStaff(const Staff* staff);

struct LayoutData : public SLine::LayoutData
{
public:
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/dom/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2928,6 +2928,11 @@ PropertyValue Note::propertyDefault(Pid propertyId) const
case Pid::PITCH:
case Pid::TPC1:
return PropertyValue();
case Pid::VISIBLE:
if (staffType() && staffType()->isTabStaff() && bendBack()) {
return false;
}
return EngravingItem::propertyDefault(propertyId);
default:
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/engraving/dom/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "engravingitem.h"
#include "excerpt.h"
#include "fret.h"
#include "guitarbend.h"
#include "harmony.h"
#include "harppedaldiagram.h"
#include "input.h"
Expand Down Expand Up @@ -1839,6 +1840,7 @@ void ChangeStaffType::flip(EditData*)
staff->setStaffType(Fraction(0, 1), staffType);

bool invisibleChanged = oldStaffType.invisible() != staffType.invisible();
bool fromTabToStandard = oldStaffType.isTabStaff() && !staffType.isTabStaff();

staffType = oldStaffType;

Expand All @@ -1850,6 +1852,10 @@ void ChangeStaffType::flip(EditData*)
}
}

if (fromTabToStandard) {
GuitarBend::adaptBendsFromTabToStandardStaff(staff);
}

staff->triggerLayout();
}

Expand Down

0 comments on commit e43a5d2

Please sign in to comment.