Skip to content
Merged
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
56 changes: 35 additions & 21 deletions src/Editor/Editing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,43 +565,57 @@ struct EditingImpl : public Editing {
}

void changeNoteSide() override {
Style* style = gStyle->get();
if (gChart->isClosed()) return;

if (!style) {
HudNote("No style is currently active.");
return;
}
NoteEdit edit;
gSelection->getSelectedNotes(edit.add);

if (!style->id.ends_with("double")) {
HudNote("Switch side is only available in a double style.");
if (edit.add.empty()) {
HudNote("There are no notes selected.");
return;
}
edit.rem = edit.add;

NoteEdit edit;
gSelection->getSelectedNotes(edit.add);

// Move the selected notes.
auto style = gStyle->get();
int halfpoint = style->numCols / 2;

// Copied from mirrorNotes to sort per row first (to stop an error
// message).
// Even Column Count
if (style->numCols % 2 == 0) {
for (auto& n : edit.add) {
if (n.col <= (halfpoint - 1)) {
n.col += halfpoint;
} else {
n.col -= halfpoint;
}
}
}
// Odd Column Count
else {
for (auto& n : edit.add) {
if (n.col < halfpoint) {
n.col += halfpoint + 1;
} else if (n.col > halfpoint) {
n.col -= halfpoint + 1;
}
}
}

// Resort the notes per row.
auto ptr = edit.add.begin();
for (int i = 0, size = edit.add.size(); i < size;) {
int row = (ptr + i)->row, begin = i;
while (i != size && (ptr + i)->row == row) ++i;
std::sort(ptr + begin, ptr + i, LessThanRowCol<Note, Note>);
}

for (auto& n : edit.add) {
if (n.col <= (halfpoint - 1)) {
n.col += halfpoint;
} else {
n.col -= halfpoint;
}
}

// Perform the move operation.
static const NotesMan::EditDescription desc = {
"Switched side for %1 note.", "Switched side for %1 notes."};
gNotes->modify(edit, true, &desc);
gNotes->modify(edit, false, &desc);

// Reselect the moved notes.
gNotes->select(SELECT_SET, edit.add.begin(), edit.rem.size(), true);
}

template <typename T>
Expand Down
Loading