Skip to content

Commit bc1f397

Browse files
authored
Merge pull request #29774 from mike-spa/moreFretDiagramImprovements
More fret diagram improvements
2 parents fad0111 + c37a121 commit bc1f397

File tree

11 files changed

+77
-127
lines changed

11 files changed

+77
-127
lines changed

src/engraving/dom/edit.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,11 +3980,7 @@ void Score::cmdDeleteSelection()
39803980
FretDiagram* fretDiagram = toFretDiagram(e);
39813981
Harmony* harmony = fretDiagram->harmony();
39823982
if (harmony) {
3983-
for (EngravingObject* o: fretDiagram->linkList()) {
3984-
FretDiagram* linkedDiagram = toFretDiagram(o);
3985-
Harmony* linkedHarmony = linkedDiagram->harmony();
3986-
undo(new FretLinkHarmony(linkedDiagram, linkedHarmony, true /* unlink */));
3987-
}
3983+
undoChangeParent(harmony, fretDiagram->segment(), track2staff(fretDiagram->track()));
39883984
elSelectedAfterDeletion = harmony;
39893985
}
39903986
} else if (e->isHarmony()) {
@@ -6987,21 +6983,7 @@ void Score::undoAddElement(EngravingItem* element, bool addToLinkedStaves, bool
69876983
ne->setTrack(linkedTrack);
69886984
ne->setParent(seg);
69896985

6990-
// make harmony child of fret diagram if possible
6991-
if (ne->isHarmony()) {
6992-
for (EngravingItem* segel : segment->annotations()) {
6993-
if (segel && segel->isFretDiagram() && segel->track() == linkedTrack && !toFretDiagram(segel)->harmony()) {
6994-
segel->add(ne);
6995-
break;
6996-
}
6997-
}
6998-
} else if (ne->isFretDiagram()) {
6999-
// update track of child harmony
7000-
FretDiagram* fd = toFretDiagram(ne);
7001-
if (fd->harmony()) {
7002-
fd->harmony()->setTrack(linkedTrack);
7003-
}
7004-
} else if (ne->isStringTunings()) {
6986+
if (ne->isStringTunings()) {
70056987
StringTunings* stringTunings = toStringTunings(ne);
70066988
if (stringTunings->stringData()->isNull()) {
70076989
const StringData* stringData = stringTunings->part()->stringData(tick, staff->idx());

src/engraving/dom/fret.cpp

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -804,21 +804,6 @@ std::vector<String> FretDiagram::patternHarmonies(const String& pattern)
804804
return muse::value(s_diagramPatternToHarmoniesMap, pattern);
805805
}
806806

807-
void FretDiagram::applyAlignmentToHarmony()
808-
{
809-
if (m_harmony->propertyFlags(Pid::OFFSET) == PropertyFlags::STYLED) {
810-
m_harmony->resetProperty(Pid::OFFSET);
811-
}
812-
813-
m_harmony->setProperty(Pid::ALIGN, Align(AlignH::HCENTER, AlignV::BASELINE));
814-
m_harmony->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED);
815-
}
816-
817-
void FretDiagram::resetHarmonyAlignment()
818-
{
819-
m_harmony->resetProperty(Pid::ALIGN);
820-
}
821-
822807
//---------------------------------------------------------
823808
// clear
824809
//---------------------------------------------------------
@@ -946,38 +931,6 @@ void FretDiagram::setHarmony(String harmonyText)
946931
triggerLayout();
947932
}
948933

949-
void FretDiagram::linkHarmony(Harmony* harmony)
950-
{
951-
m_harmony = harmony;
952-
953-
setParent(harmony->explicitParent());
954-
harmony->setParent(this);
955-
956-
//! on the same lavel as diagram
957-
m_harmony->setZ(z());
958-
959-
if (Segment* segment = this->segment()) {
960-
segment->removeAnnotation(harmony);
961-
}
962-
963-
m_harmony->setTrack(track());
964-
965-
applyAlignmentToHarmony();
966-
}
967-
968-
void FretDiagram::unlinkHarmony()
969-
{
970-
m_harmony->setTrack(track());
971-
972-
resetHarmonyAlignment();
973-
974-
m_harmony->setZ(-1);
975-
976-
segment()->add(m_harmony);
977-
978-
m_harmony = nullptr;
979-
}
980-
981934
//---------------------------------------------------------
982935
// add
983936
//---------------------------------------------------------
@@ -990,9 +943,6 @@ void FretDiagram::add(EngravingItem* e)
990943

991944
m_harmony->setTrack(track());
992945

993-
//! on the same lavel as diagram
994-
m_harmony->setZ(z());
995-
996946
if (m_harmony->harmonyName().empty()) {
997947
if (s_diagramPatternToHarmoniesMap.empty()) {
998948
readHarmonyToDiagramFile(HARMONY_TO_DIAGRAM_FILE_PATH);
@@ -1007,7 +957,9 @@ void FretDiagram::add(EngravingItem* e)
1007957
}
1008958
}
1009959

1010-
applyAlignmentToHarmony();
960+
m_harmony->resetProperty(Pid::OFFSET);
961+
m_harmony->setProperty(Pid::ALIGN, Align(AlignH::HCENTER, AlignV::BASELINE));
962+
m_harmony->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED);
1011963

1012964
e->added();
1013965
} else {
@@ -1355,7 +1307,7 @@ FretDiagram* FretDiagram::makeFromHarmonyOrFretDiagram(const EngravingItem* harm
13551307

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

1358-
fretDiagram->linkHarmony(harmony);
1310+
fretDiagram->add(harmony);
13591311
} else if (harmonyOrFretDiagram->isHarmony() && harmonyOrFretDiagram->parentItem()->isFretDiagram()) {
13601312
fretDiagram = toFretDiagram(harmonyOrFretDiagram->parentItem())->clone();
13611313
} else if (harmonyOrFretDiagram->isFretDiagram()) {

src/engraving/dom/fret.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ class FretDiagram final : public EngravingItem
209209
String harmonyText() const;
210210
Harmony* harmony() const { return m_harmony; }
211211
void setHarmony(String harmonyText);
212-
void linkHarmony(Harmony* harmony);
213-
void unlinkHarmony();
214212

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

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

305-
void applyAlignmentToHarmony();
306-
void resetHarmonyAlignment();
307-
308303
int m_strings = 0;
309304
int m_frets = 0;
310305
int m_fretOffset = 0;

src/engraving/dom/undo.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,31 +3557,6 @@ void ChangeTieJumpPointActive::flip(EditData*)
35573557
m_active = oldActive;
35583558
}
35593559

3560-
FretLinkHarmony::FretLinkHarmony(FretDiagram* diagram, Harmony* harmony, bool unlink)
3561-
{
3562-
m_fretDiagram = diagram;
3563-
m_harmony = harmony;
3564-
m_unlink = unlink;
3565-
}
3566-
3567-
void FretLinkHarmony::undo(EditData*)
3568-
{
3569-
if (m_unlink) {
3570-
m_fretDiagram->linkHarmony(m_harmony);
3571-
} else {
3572-
m_fretDiagram->unlinkHarmony();
3573-
}
3574-
}
3575-
3576-
void FretLinkHarmony::redo(EditData*)
3577-
{
3578-
if (m_unlink) {
3579-
m_fretDiagram->unlinkHarmony();
3580-
} else {
3581-
m_fretDiagram->linkHarmony(m_harmony);
3582-
}
3583-
}
3584-
35853560
RemoveFretDiagramFromFretBox::RemoveFretDiagramFromFretBox(FretDiagram* f)
35863561
: m_fretDiagram(f)
35873562
{

src/engraving/dom/undo.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ enum class CommandType : signed char {
159159
FretMarker,
160160
FretBarre,
161161
FretClear,
162-
FretLinkHarmony,
163162
RemoveFretDiagramFromFretBox,
164163

165164
// Harmony
@@ -1806,25 +1805,6 @@ class FretClear : public UndoCommand
18061805
UNDO_CHANGED_OBJECTS({ diagram })
18071806
};
18081807

1809-
class FretLinkHarmony : public UndoCommand
1810-
{
1811-
OBJECT_ALLOCATOR(engraving, FretLinkHarmony)
1812-
1813-
FretDiagram* m_fretDiagram = nullptr;
1814-
Harmony* m_harmony = nullptr;
1815-
bool m_unlink = false;
1816-
1817-
void undo(EditData*) override;
1818-
void redo(EditData*) override;
1819-
1820-
public:
1821-
FretLinkHarmony(FretDiagram*, Harmony*, bool unlink = false);
1822-
1823-
UNDO_TYPE(CommandType::FretLinkHarmony)
1824-
UNDO_NAME("FretLinkHarmony")
1825-
UNDO_CHANGED_OBJECTS({ m_fretDiagram })
1826-
};
1827-
18281808
class RemoveFretDiagramFromFretBox : public UndoCommand
18291809
{
18301810
OBJECT_ALLOCATOR(engraving, RemoveFretDiagramFromFretBox)

src/engraving/types/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ enum class ElementType : unsigned char {
128128
REHEARSAL_MARK,
129129
INSTRUMENT_CHANGE,
130130
STAFFTYPE_CHANGE,
131-
HARMONY,
132131
FRET_DIAGRAM,
132+
HARMONY,
133133
HARP_DIAGRAM,
134134
BEND,
135135
TREMOLOBAR,

src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ void FretFrameChordsSettingsModel::requestElements()
5555

5656
m_chordListModel->setFBox(fretBox());
5757
m_chordListModel->load();
58+
59+
updateHasInvisibleChords();
5860
}
5961

6062
void FretFrameChordsSettingsModel::loadProperties()
6163
{
6264
loadProperties({ Pid::FRET_FRAME_DIAGRAMS_ORDER });
6365
m_chordListModel->load();
66+
updateHasInvisibleChords();
6467
}
6568

6669
void FretFrameChordsSettingsModel::resetProperties()
@@ -81,6 +84,7 @@ void FretFrameChordsSettingsModel::onNotationChanged(const engraving::PropertyId
8184
const engraving::StyleIdSet&)
8285
{
8386
loadProperties(changedPropertyIdSet);
87+
updateHasInvisibleChords();
8488
}
8589

8690
void FretFrameChordsSettingsModel::loadProperties(const engraving::PropertyIdSet& propertyIdSet)
@@ -90,6 +94,26 @@ void FretFrameChordsSettingsModel::loadProperties(const engraving::PropertyIdSet
9094
}
9195
}
9296

97+
void FretFrameChordsSettingsModel::updateHasInvisibleChords()
98+
{
99+
bool hasInvisibleChords = false;
100+
101+
const FBox* fbox = fretBox();
102+
if (fbox) {
103+
for (EngravingItem* item : fbox->el()) {
104+
if (!item->visible()) {
105+
hasInvisibleChords = true;
106+
break;
107+
}
108+
}
109+
}
110+
111+
if (hasInvisibleChords != m_hasInvisibleChords) {
112+
m_hasInvisibleChords = hasInvisibleChords;
113+
emit hasInvisibleChordsChanged(m_hasInvisibleChords);
114+
}
115+
}
116+
93117
FretFrameChordListModel* FretFrameChordsSettingsModel::chordListModel() const
94118
{
95119
return m_chordListModel.get();
@@ -99,3 +123,27 @@ PropertyItem* FretFrameChordsSettingsModel::listOrder() const
99123
{
100124
return m_listOrder;
101125
}
126+
127+
bool FretFrameChordsSettingsModel::hasInvisibleChords() const
128+
{
129+
return m_hasInvisibleChords;
130+
}
131+
132+
void FretFrameChordsSettingsModel::resetList()
133+
{
134+
beginCommand(TranslatableString("undoableAction", "Reset Fret Diagram Legend chords list"));
135+
136+
FBox* fbox = fretBox();
137+
if (fbox) {
138+
fbox->undoResetProperty(Pid::FRET_FRAME_DIAGRAMS_ORDER);
139+
140+
for (EngravingItem* item : fbox->el()) {
141+
item->undoResetProperty(Pid::VISIBLE);
142+
}
143+
}
144+
145+
updateNotation();
146+
endCommand();
147+
148+
loadProperties();
149+
}

src/inspector/models/notation/frames/fretframe/fretframechordssettingsmodel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse:
4343

4444
Q_PROPERTY(PropertyItem * listOrder READ listOrder CONSTANT)
4545

46+
Q_PROPERTY(bool hasInvisibleChords READ hasInvisibleChords NOTIFY hasInvisibleChordsChanged)
47+
4648
muse::Inject<context::IGlobalContext> globalContext = { this };
4749

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

5355
PropertyItem* listOrder() const;
56+
bool hasInvisibleChords() const;
57+
58+
Q_INVOKABLE void resetList();
59+
60+
signals:
61+
void hasInvisibleChordsChanged(bool hasInvisible);
5462

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

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

75+
void updateHasInvisibleChords();
76+
6777
std::shared_ptr<FretFrameChordListModel> m_chordListModel;
6878

6979
PropertyItem* m_listOrder = nullptr;
80+
bool m_hasInvisibleChords = false;
7081
};
7182
}

src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsControlPanel.qml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ RowLayout {
4040

4141
property bool isMovingUpAvailable: false
4242
property bool isMovingDownAvailable: false
43+
property bool hasInvisibleChords: false
4344

4445
height: childrenRect.height
4546

4647
spacing: 6
4748

4849
signal moveSelectionUpRequested()
4950
signal moveSelectionDownRequested()
51+
signal resetListRequested();
5052

5153
FlatButton {
5254
id: upBotton
@@ -92,10 +94,10 @@ RowLayout {
9294
navigation.row: downButton.navigation.row + 1
9395
navigation.accessible.name: qsTrc("inspector", "Reset chord list")
9496

95-
enabled: root.listOrderItem.isModified
97+
enabled: root.listOrderItem.isModified || root.hasInvisibleChords
9698

9799
onClicked: {
98-
root.listOrderItem.resetToDefault()
100+
root.resetListRequested()
99101
}
100102
}
101103
}

src/inspector/view/qml/MuseScore/Inspector/notation/frames/internal/FretFrameChordsTab.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ FocusableItem {
5555
anchors.rightMargin: root.sideMargin
5656

5757
listOrderItem: root.model ? root.model.listOrder : null
58+
hasInvisibleChords: root.model ? root.model.hasInvisibleChords : null
5859

5960
isMovingUpAvailable: view.model ? view.model.isMovingUpAvailable : false
6061
isMovingDownAvailable: view.model ? view.model.isMovingDownAvailable : false
@@ -73,6 +74,10 @@ FocusableItem {
7374
view.model.moveSelectionDown()
7475
Qt.callLater(view.positionViewAtSelectedItems)
7576
}
77+
78+
onResetListRequested: {
79+
root.model.resetList()
80+
}
7681
}
7782

7883
FretFrameChordsView {

0 commit comments

Comments
 (0)