backport more fixes
[alioth/musescore.git] / debian / patches / backports / change-staff-name.diff
1 Origin: upstream, commit:c2a4051e6dd832ba6d8ff83cd4b3a70c262b944b
2 Author: Marc Sabatella <marc@outsideshore.com>
3 Description: fix #88861: allow mid-score staff name changes
4
5 --- a/mscore/editstaff.cpp
6 +++ b/mscore/editstaff.cpp
7 @@ -43,7 +43,7 @@ namespace Ms {
8  //   EditStaff
9  //---------------------------------------------------------
10  
11 -EditStaff::EditStaff(Staff* s, const Fraction& /*tick*/, QWidget* parent)
12 +EditStaff::EditStaff(Staff* s, const Fraction& tick, QWidget* parent)
13     : QDialog(parent)
14        {
15        setObjectName("EditStaff");
16 @@ -52,7 +52,7 @@ EditStaff::EditStaff(Staff* s, const Fra
17        setModal(true);
18  
19        staff = nullptr;
20 -      setStaff(s);
21 +      setStaff(s, tick);
22  
23        MuseScore::restoreGeometry(this);
24  
25 @@ -83,14 +83,14 @@ EditStaff::EditStaff(Staff* s, const Fra
26  //   setStaff
27  //---------------------------------------------------------
28  
29 -void EditStaff::setStaff(Staff* s)
30 +void EditStaff::setStaff(Staff* s, const Fraction& tick)
31        {
32        if (staff != nullptr)
33              delete staff;
34  
35        orgStaff = s;
36        Part* part        = orgStaff->part();
37 -      instrument        = *part->instrument(/*tick*/);
38 +      instrument        = *part->instrument(tick);
39        Score* score      = part->score();
40        staff             = new Staff(score);
41        staff->setStaffType(Fraction(0,1), *orgStaff->staffType(Fraction(0,1)));
42 @@ -106,20 +106,16 @@ void EditStaff::setStaff(Staff* s)
43        staff->setHideSystemBarLine(orgStaff->hideSystemBarLine());
44  
45        // get tick range for instrument
46 -      auto i = part->instruments()->upper_bound(0);   // tick
47 +      auto i = part->instruments()->upper_bound(tick.ticks());
48        if (i == part->instruments()->end())
49              _tickEnd = Fraction(-1,1);
50        else
51              _tickEnd = Fraction::fromTicks(i->first);
52 -#if 1
53 -      _tickStart = Fraction(-1,1);
54 -#else
55        --i;
56        if (i == part->instruments()->begin())
57 -            _tickStart = 0;
58 +            _tickStart = Fraction(-1, 1);
59        else
60 -            _tickStart = i->first;
61 -#endif
62 +            _tickStart = Fraction::fromTicks(i->first);
63  
64        // set dlg controls
65        spinExtraDistance->setValue(s->userDist() / score->spatium());
66 @@ -254,7 +250,7 @@ void EditStaff::gotoNextStaff()
67        Staff* nextStaff = orgStaff->score()->staff(orgStaff->idx() + 1);
68        if (nextStaff)
69              {
70 -            setStaff(nextStaff);
71 +            setStaff(nextStaff, _tickStart);
72              }
73        }
74  
75 @@ -267,7 +263,7 @@ void EditStaff::gotoPreviousStaff()
76        Staff* prevStaff = orgStaff->score()->staff(orgStaff->idx() - 1);
77        if (prevStaff)
78              {
79 -            setStaff(prevStaff);
80 +            setStaff(prevStaff, _tickStart);
81              }
82        }
83  
84 @@ -350,16 +346,32 @@ void EditStaff::apply()
85  
86        QString newPartName = partName->text().simplified();
87  
88 -      bool instrumentFieldChanged = !(instrument == *part->instrument());
89 -      if (instrumentFieldChanged)
90 +      bool instrumentFieldChanged = !(instrument == *part->instrument(_tickStart));
91 +      if (instrumentFieldChanged && _tickStart == Fraction(-1, 1))
92              clefType = instrument.clefType(orgStaff->rstaff());
93  
94        if (instrumentFieldChanged || part->partName() != newPartName) {
95              // instrument has changed
96              Interval v1 = instrument.transpose();
97 -            Interval v2 = part->instrument()->transpose();
98 +            Interval v2 = part->instrument(_tickStart)->transpose();
99  
100 -            score->undo(new ChangePart(part, new Instrument(instrument), newPartName));
101 +            if (_tickStart == Fraction(-1, 1)) {
102 +                  // change instrument and part name globally
103 +                  score->undo(new ChangePart(part, new Instrument(instrument), newPartName));
104 +                  }
105 +            else {
106 +                  // change part name globally, instrument locally if possible
107 +                  if (part->partName() != newPartName)
108 +                        score->undo(new ChangePart(part, new Instrument(*part->instrument()), newPartName));
109 +                  if (instrumentFieldChanged) {
110 +                        Segment* s = score->tick2segment(_tickStart, true, SegmentType::ChordRest);
111 +                        Element* e = s ? s->findAnnotation(ElementType::INSTRUMENT_CHANGE, part->startTrack(), part->endTrack()) : nullptr;
112 +                        if (e)
113 +                              score->undo(new ChangeInstrument(toInstrumentChange(e), new Instrument(instrument)));
114 +                        else
115 +                              score->undo(new ChangePart(part, new Instrument(instrument), newPartName));
116 +                        }
117 +                  }
118              emit instrumentChanged();
119  
120              if (v1 != v2)
121 --- a/mscore/editstaff.h
122 +++ b/mscore/editstaff.h
123 @@ -46,7 +46,7 @@ class EditStaff : public QDialog, privat
124  
125        virtual void hideEvent(QHideEvent*);
126        void apply();
127 -      void setStaff(Staff*);
128 +      void setStaff(Staff*, const Fraction& tick);
129        void updateInterval(const Interval&);
130        void updateStaffType();
131        void updateInstrument();
132 --- a/mscore/propertymenu.cpp
133 +++ b/mscore/propertymenu.cpp
134 @@ -62,6 +62,8 @@
135  #include "libmscore/jump.h"
136  #include "libmscore/marker.h"
137  #include "libmscore/measure.h"
138 +#include "libmscore/iname.h"
139 +#include "libmscore/system.h"
140  
141  namespace Ms {
142  
143 @@ -522,12 +524,21 @@ void ScoreView::elementPropertyAction(co
144  //            editFretDiagram(static_cast<FretDiagram*>(e));
145        else if (cmd == "staff-props") {
146              Fraction tick = {-1,1};
147 -            if (e->isChordRest())
148 -                  tick = static_cast<ChordRest*>(e)->tick();
149 -            else if (e->type() == ElementType::NOTE)
150 -                  tick = static_cast<Note*>(e)->chord()->tick();
151 -            else if (e->type() == ElementType::MEASURE)
152 -                  tick = static_cast<Measure*>(e)->tick();
153 +            if (e->isChordRest()) {
154 +                  tick = toChordRest(e)->tick();
155 +                  }
156 +            else if (e->isNote()) {
157 +                  tick = toNote(e)->chord()->tick();
158 +                  }
159 +            else if (e->isMeasure()) {
160 +                  tick = toMeasure(e)->tick();
161 +                  }
162 +            else if (e->isInstrumentName()) {
163 +                  System* system = toSystem(toInstrumentName(e)->parent());
164 +                  Measure* m = system ? system->firstMeasure() : nullptr;
165 +                  if (m)
166 +                        tick = m->tick();
167 +                  }
168              EditStaff editStaff(e->staff(), tick, 0);
169              connect(&editStaff, SIGNAL(instrumentChanged()), mscore, SLOT(instrumentChanged()));
170              editStaff.exec();