Skip to content

Commit 08c8ba0

Browse files
committed
requested changes
1 parent cd5a17a commit 08c8ba0

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/engraving/editing/edit.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,48 +2165,51 @@ Tie* Score::cmdToggleTie()
21652165
return nullptr;
21662166
}
21672167

2168-
bool canAddTies = false;
2169-
const size_t notes = noteList.size();
2170-
std::vector<Note*> tieNoteList(notes);
2171-
Note* tieNote = nullptr;
2172-
Note* n = nullptr;
2168+
std::vector<Note*> tieNoteList(noteList.size());
2169+
Chord* chord = noteList.front()->chord();
2170+
bool someHaveExistingNextNoteToTieTo = false;
2171+
bool allHaveExistingNextNoteToTieTo = true;
21732172

2174-
bool sameChord = std::all_of(noteList.begin(), noteList.end(), [&](const Note* n) { return n->chord() == noteList[0]->chord(); });
2175-
const bool shouldTieListSelection = !sameChord;
2176-
2177-
for (size_t i = 0; i < notes; ++i) {
2178-
n = noteList[i];
2173+
for (size_t i = 0; i < noteList.size(); ++i) {
2174+
Note* n = noteList[i];
2175+
if (chord && n->chord() != chord) {
2176+
chord = nullptr;
2177+
}
21792178
if (n->tieFor()) {
21802179
tieNoteList[i] = nullptr;
21812180
} else {
2182-
tieNote = searchTieNote(n);
2181+
Note* tieNote = searchTieNote(n);
21832182
tieNoteList[i] = tieNote;
21842183
if (tieNote) {
2185-
canAddTies = true;
2184+
someHaveExistingNextNoteToTieTo = true;
2185+
} else {
2186+
allHaveExistingNextNoteToTieTo = false;
21862187
}
21872188
}
21882189
}
21892190

2190-
if (!tieNote && selection().isList() && sameChord) {
2191+
const bool shouldTieListSelection = noteList.size() >= 2 && !chord;
2192+
2193+
if (chord /* i.e. all notes are in the same chord */ && !allHaveExistingNextNoteToTieTo) {
21912194
cmdAddTie();
2192-
if (notes >= 2) {
2193-
Chord* c = n->chord()->next();
2195+
if (noteList.size() >= 2) {
2196+
Chord* c = chord->next();
21942197
for (Note* cn : c->notes()) {
21952198
score()->select(cn, SelectType::ADD);
21962199
}
21972200
}
21982201
return nullptr;
21992202
}
22002203

2201-
const TranslatableString actionName = canAddTies
2204+
const TranslatableString actionName = someHaveExistingNextNoteToTieTo
22022205
? TranslatableString("undoableAction", "Add tie")
22032206
: TranslatableString("undoableAction", "Remove tie");
22042207

22052208
startCmd(actionName);
22062209

22072210
Tie* tie = nullptr;
22082211

2209-
for (size_t i = 0; i < notes; ++i) {
2212+
for (size_t i = 0; i < noteList.size(); ++i) {
22102213
Note* note = noteList[i];
22112214
Note* tieToNote = tieNoteList[i];
22122215

@@ -2215,7 +2218,7 @@ Tie* Score::cmdToggleTie()
22152218
}
22162219

22172220
// Tie to adjacent unselected note
2218-
if (canAddTies && tieToNote) {
2221+
if (someHaveExistingNextNoteToTieTo && tieToNote) {
22192222
Note* startNote = note->tick() <= tieToNote->tick() ? note : tieToNote;
22202223
Note* endNote = startNote == tieToNote ? note : tieToNote;
22212224
tie = createAndAddTie(startNote, endNote);
@@ -2239,14 +2242,14 @@ Tie* Score::cmdToggleTie()
22392242
continue;
22402243
}
22412244

2242-
if (!shouldTieListSelection || i > notes - 2) {
2245+
if (!shouldTieListSelection || i > noteList.size() - 2) {
22432246
continue;
22442247
}
22452248

22462249
// Tie to next appropriate note in selection
22472250
Note* note2 = nullptr;
22482251

2249-
for (size_t j = i + 1; j < notes; ++j) {
2252+
for (size_t j = i + 1; j < noteList.size(); ++j) {
22502253
Note* candidateNote = noteList[j];
22512254
if (!candidateNote) {
22522255
continue;

0 commit comments

Comments
 (0)