Skip to content
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
22 changes: 2 additions & 20 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3980,11 +3980,7 @@ void Score::cmdDeleteSelection()
FretDiagram* fretDiagram = toFretDiagram(e);
Harmony* harmony = fretDiagram->harmony();
if (harmony) {
for (EngravingObject* o: fretDiagram->linkList()) {
FretDiagram* linkedDiagram = toFretDiagram(o);
Harmony* linkedHarmony = linkedDiagram->harmony();
undo(new FretLinkHarmony(linkedDiagram, linkedHarmony, true /* unlink */));
}
undoChangeParent(harmony, fretDiagram->segment(), track2staff(fretDiagram->track()));
elSelectedAfterDeletion = harmony;
}
} else if (e->isHarmony()) {
Expand Down Expand Up @@ -6987,21 +6983,7 @@ void Score::undoAddElement(EngravingItem* element, bool addToLinkedStaves, bool
ne->setTrack(linkedTrack);
ne->setParent(seg);

// make harmony child of fret diagram if possible
if (ne->isHarmony()) {
for (EngravingItem* segel : segment->annotations()) {
if (segel && segel->isFretDiagram() && segel->track() == linkedTrack && !toFretDiagram(segel)->harmony()) {
segel->add(ne);
break;
}
}
} else if (ne->isFretDiagram()) {
// update track of child harmony
FretDiagram* fd = toFretDiagram(ne);
if (fd->harmony()) {
fd->harmony()->setTrack(linkedTrack);
}
} else if (ne->isStringTunings()) {
if (ne->isStringTunings()) {
StringTunings* stringTunings = toStringTunings(ne);
if (stringTunings->stringData()->isNull()) {
const StringData* stringData = stringTunings->part()->stringData(tick, staff->idx());
Expand Down
56 changes: 4 additions & 52 deletions src/engraving/dom/fret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,21 +804,6 @@ std::vector<String> FretDiagram::patternHarmonies(const String& pattern)
return muse::value(s_diagramPatternToHarmoniesMap, pattern);
}

void FretDiagram::applyAlignmentToHarmony()
{
if (m_harmony->propertyFlags(Pid::OFFSET) == PropertyFlags::STYLED) {
m_harmony->resetProperty(Pid::OFFSET);
}

m_harmony->setProperty(Pid::ALIGN, Align(AlignH::HCENTER, AlignV::BASELINE));
m_harmony->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED);
}

void FretDiagram::resetHarmonyAlignment()
{
m_harmony->resetProperty(Pid::ALIGN);
}

//---------------------------------------------------------
// clear
//---------------------------------------------------------
Expand Down Expand Up @@ -946,38 +931,6 @@ void FretDiagram::setHarmony(String harmonyText)
triggerLayout();
}

void FretDiagram::linkHarmony(Harmony* harmony)
{
m_harmony = harmony;

setParent(harmony->explicitParent());
harmony->setParent(this);

//! on the same lavel as diagram
m_harmony->setZ(z());

if (Segment* segment = this->segment()) {
segment->removeAnnotation(harmony);
}

m_harmony->setTrack(track());

applyAlignmentToHarmony();
}

void FretDiagram::unlinkHarmony()
{
m_harmony->setTrack(track());

resetHarmonyAlignment();

m_harmony->setZ(-1);

segment()->add(m_harmony);

m_harmony = nullptr;
}

//---------------------------------------------------------
// add
//---------------------------------------------------------
Expand All @@ -990,9 +943,6 @@ void FretDiagram::add(EngravingItem* e)

m_harmony->setTrack(track());

//! on the same lavel as diagram
m_harmony->setZ(z());

if (m_harmony->harmonyName().empty()) {
if (s_diagramPatternToHarmoniesMap.empty()) {
readHarmonyToDiagramFile(HARMONY_TO_DIAGRAM_FILE_PATH);
Expand All @@ -1007,7 +957,9 @@ void FretDiagram::add(EngravingItem* e)
}
}

applyAlignmentToHarmony();
m_harmony->resetProperty(Pid::OFFSET);
m_harmony->setProperty(Pid::ALIGN, Align(AlignH::HCENTER, AlignV::BASELINE));
m_harmony->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED);

e->added();
} else {
Expand Down Expand Up @@ -1355,7 +1307,7 @@ FretDiagram* FretDiagram::makeFromHarmonyOrFretDiagram(const EngravingItem* harm

fretDiagram->updateDiagram(harmony->plainText());

fretDiagram->linkHarmony(harmony);
fretDiagram->add(harmony);
} else if (harmonyOrFretDiagram->isHarmony() && harmonyOrFretDiagram->parentItem()->isFretDiagram()) {
fretDiagram = toFretDiagram(harmonyOrFretDiagram->parentItem())->clone();
} else if (harmonyOrFretDiagram->isFretDiagram()) {
Expand Down
5 changes: 0 additions & 5 deletions src/engraving/dom/fret.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ class FretDiagram final : public EngravingItem
String harmonyText() const;
Harmony* harmony() const { return m_harmony; }
void setHarmony(String harmonyText);
void linkHarmony(Harmony* harmony);
void unlinkHarmony();

std::vector<FretItem::Dot> dot(int s, int f = 0) const;
FretItem::Marker marker(int s) const;
Expand Down Expand Up @@ -302,9 +300,6 @@ class FretDiagram final : public EngravingItem

static void applyDiagramPattern(FretDiagram* diagram, const String& pattern);

void applyAlignmentToHarmony();
void resetHarmonyAlignment();

int m_strings = 0;
int m_frets = 0;
int m_fretOffset = 0;
Expand Down
25 changes: 0 additions & 25 deletions src/engraving/dom/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3557,31 +3557,6 @@ void ChangeTieJumpPointActive::flip(EditData*)
m_active = oldActive;
}

FretLinkHarmony::FretLinkHarmony(FretDiagram* diagram, Harmony* harmony, bool unlink)
{
m_fretDiagram = diagram;
m_harmony = harmony;
m_unlink = unlink;
}

void FretLinkHarmony::undo(EditData*)
{
if (m_unlink) {
m_fretDiagram->linkHarmony(m_harmony);
Copy link
Contributor

Choose a reason for hiding this comment

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

This function sets the harmony's z value and applies some alignment changes. I think we still need to do these things when adding and removing harmony from fret diagrams.

} else {
m_fretDiagram->unlinkHarmony();
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise here

}
}

void FretLinkHarmony::redo(EditData*)
{
if (m_unlink) {
m_fretDiagram->unlinkHarmony();
} else {
m_fretDiagram->linkHarmony(m_harmony);
}
}

RemoveFretDiagramFromFretBox::RemoveFretDiagramFromFretBox(FretDiagram* f)
: m_fretDiagram(f)
{
Expand Down
20 changes: 0 additions & 20 deletions src/engraving/dom/undo.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ enum class CommandType : signed char {
FretMarker,
FretBarre,
FretClear,
FretLinkHarmony,
RemoveFretDiagramFromFretBox,

// Harmony
Expand Down Expand Up @@ -1806,25 +1805,6 @@ class FretClear : public UndoCommand
UNDO_CHANGED_OBJECTS({ diagram })
};

class FretLinkHarmony : public UndoCommand
{
OBJECT_ALLOCATOR(engraving, FretLinkHarmony)

FretDiagram* m_fretDiagram = nullptr;
Harmony* m_harmony = nullptr;
bool m_unlink = false;

void undo(EditData*) override;
void redo(EditData*) override;

public:
FretLinkHarmony(FretDiagram*, Harmony*, bool unlink = false);

UNDO_TYPE(CommandType::FretLinkHarmony)
Copy link
Contributor

Choose a reason for hiding this comment

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

This enum value can be removed now

UNDO_NAME("FretLinkHarmony")
UNDO_CHANGED_OBJECTS({ m_fretDiagram })
};

class RemoveFretDiagramFromFretBox : public UndoCommand
{
OBJECT_ALLOCATOR(engraving, RemoveFretDiagramFromFretBox)
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ enum class ElementType : unsigned char {
REHEARSAL_MARK,
INSTRUMENT_CHANGE,
STAFFTYPE_CHANGE,
HARMONY,
FRET_DIAGRAM,
HARMONY,
HARP_DIAGRAM,
BEND,
TREMOLOBAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ void FretFrameChordsSettingsModel::requestElements()

m_chordListModel->setFBox(fretBox());
m_chordListModel->load();

updateHasInvisibleChords();
}

void FretFrameChordsSettingsModel::loadProperties()
{
loadProperties({ Pid::FRET_FRAME_DIAGRAMS_ORDER });
m_chordListModel->load();
updateHasInvisibleChords();
}

void FretFrameChordsSettingsModel::resetProperties()
Expand All @@ -81,6 +84,7 @@ void FretFrameChordsSettingsModel::onNotationChanged(const engraving::PropertyId
const engraving::StyleIdSet&)
{
loadProperties(changedPropertyIdSet);
updateHasInvisibleChords();
}

void FretFrameChordsSettingsModel::loadProperties(const engraving::PropertyIdSet& propertyIdSet)
Expand All @@ -90,6 +94,26 @@ void FretFrameChordsSettingsModel::loadProperties(const engraving::PropertyIdSet
}
}

void FretFrameChordsSettingsModel::updateHasInvisibleChords()
{
bool hasInvisibleChords = false;

const FBox* fbox = fretBox();
if (fbox) {
for (EngravingItem* item : fbox->el()) {
if (!item->visible()) {
hasInvisibleChords = true;
break;
}
}
}

if (hasInvisibleChords != m_hasInvisibleChords) {
m_hasInvisibleChords = hasInvisibleChords;
emit hasInvisibleChordsChanged(m_hasInvisibleChords);
}
}

FretFrameChordListModel* FretFrameChordsSettingsModel::chordListModel() const
{
return m_chordListModel.get();
Expand All @@ -99,3 +123,27 @@ PropertyItem* FretFrameChordsSettingsModel::listOrder() const
{
return m_listOrder;
}

bool FretFrameChordsSettingsModel::hasInvisibleChords() const
{
return m_hasInvisibleChords;
}

void FretFrameChordsSettingsModel::resetList()
{
beginCommand(TranslatableString("undoableAction", "Reset Fret Diagram Legend chords list"));

FBox* fbox = fretBox();
if (fbox) {
fbox->undoResetProperty(Pid::FRET_FRAME_DIAGRAMS_ORDER);

for (EngravingItem* item : fbox->el()) {
item->undoResetProperty(Pid::VISIBLE);
}
}

updateNotation();
endCommand();

loadProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse:

Q_PROPERTY(PropertyItem * listOrder READ listOrder CONSTANT)

Q_PROPERTY(bool hasInvisibleChords READ hasInvisibleChords NOTIFY hasInvisibleChordsChanged)

muse::Inject<context::IGlobalContext> globalContext = { this };

public:
Expand All @@ -51,6 +53,12 @@ class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse:
FretFrameChordListModel* chordListModel() const;

PropertyItem* listOrder() const;
bool hasInvisibleChords() const;

Q_INVOKABLE void resetList();

signals:
void hasInvisibleChordsChanged(bool hasInvisible);

private:
engraving::FBox* fretBox() const;
Expand All @@ -64,8 +72,11 @@ class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse:

void loadProperties(const mu::engraving::PropertyIdSet& propertyIdSet);

void updateHasInvisibleChords();

std::shared_ptr<FretFrameChordListModel> m_chordListModel;

PropertyItem* m_listOrder = nullptr;
bool m_hasInvisibleChords = false;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ RowLayout {

property bool isMovingUpAvailable: false
property bool isMovingDownAvailable: false
property bool hasInvisibleChords: false

height: childrenRect.height

spacing: 6

signal moveSelectionUpRequested()
signal moveSelectionDownRequested()
signal resetListRequested();

FlatButton {
id: upBotton
Expand Down Expand Up @@ -92,10 +94,10 @@ RowLayout {
navigation.row: downButton.navigation.row + 1
navigation.accessible.name: qsTrc("inspector", "Reset chord list")

enabled: root.listOrderItem.isModified
enabled: root.listOrderItem.isModified || root.hasInvisibleChords

onClicked: {
root.listOrderItem.resetToDefault()
root.resetListRequested()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ FocusableItem {
anchors.rightMargin: root.sideMargin

listOrderItem: root.model ? root.model.listOrder : null
hasInvisibleChords: root.model ? root.model.hasInvisibleChords : null

isMovingUpAvailable: view.model ? view.model.isMovingUpAvailable : false
isMovingDownAvailable: view.model ? view.model.isMovingDownAvailable : false
Expand All @@ -73,6 +74,10 @@ FocusableItem {
view.model.moveSelectionDown()
Qt.callLater(view.positionViewAtSelectedItems)
}

onResetListRequested: {
root.model.resetList()
}
}

FretFrameChordsView {
Expand Down
4 changes: 2 additions & 2 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7856,11 +7856,11 @@ void NotationInteraction::addFretboardDiagram()
diagram->setTrack(element->track());

Harmony* harmony = toHarmony(element);

diagram->updateDiagram(harmony->harmonyName());
score->undo(new FretLinkHarmony(diagram, harmony));

diagram->setParent(harmony->parent());
score->undoAddElement(diagram);
score->undoChangeParent(harmony, diagram, track2staff(element->track()));

lastAddedDiagram = diagram;
}
Expand Down
Loading