Skip to content

Commit

Permalink
[Command] Select All Similar (Same System + Same Staff), utilizing su…
Browse files Browse the repository at this point in the history
…btype

Omit some subtypes, i.e.:
+  Dynamics
  • Loading branch information
worldwideweary committed Sep 30, 2024
1 parent 33f2b19 commit a951f87
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
23 changes: 21 additions & 2 deletions libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,24 +3425,43 @@ void Score::collectNoteMatch(void* data, Element* e)
// selectSimilar
//---------------------------------------------------------

void Score::selectSimilar(Element* e, bool sameStaff)
void Score::selectSimilar(Element* e, bool sameStaff, bool sameSystem)
{
ElementType type = e->type();
auto subtype = e->subtype();
Score* score = e->score();
System* currentSystem = nullptr;
if (auto p = e->parent()) {
if (p->isSystem())
currentSystem = toSystem(p);
else if (auto m = e->findMeasure())
currentSystem = m->system();
}

ElementPattern pattern;
pattern.type = int(type);
pattern.subtype = 0;
pattern.subtypeValid = false;

if (sameSystem && (subtype != -1)) {
// Subtypes to omit
if (type != ElementType::DYNAMIC) {
pattern.subtype = subtype;
pattern.subtypeValid = true;
}
}

if (type == ElementType::NOTE) {
if (toNote(e)->chord()->isGrace())
pattern.subtype = -1; // hack
else
pattern.subtype = e->subtype();
pattern.subtype = subtype;
}
pattern.staffStart = sameStaff ? e->staffIdx() : -1;
pattern.staffEnd = sameStaff ? e->staffIdx() + 1 : -1;
pattern.voice = -1;
pattern.system = sameSystem ? currentSystem : 0;
pattern.durationTicks = Fraction(-1,1);

score->scanElements(&pattern, collectMatch);

Expand Down
2 changes: 1 addition & 1 deletion libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ class Score : public QObject, public ScoreElement {
void getSelectedChordRest2(ChordRest** cr1, ChordRest** cr2) const;

void select(Element* obj, SelectType = SelectType::SINGLE, int staff = 0);
void selectSimilar(Element* e, bool sameStaff);
void selectSimilar(Element* e, bool sameStaff, bool sameSystem = false);
void selectSimilarInRange(Element* e);
static void collectMatch(void* data, Element* e);
static void collectNoteMatch(void* data, Element* e);
Expand Down
4 changes: 2 additions & 2 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5762,10 +5762,10 @@ QNetworkAccessManager* MuseScore::networkManager()
// selectSimilar
//---------------------------------------------------------

void MuseScore::selectSimilar(Element* e, bool sameStaff)
void MuseScore::selectSimilar(Element* e, bool sameStaff, bool sameSystem)
{
Score* score = e->score();
score->selectSimilar(e, sameStaff);
score->selectSimilar(e, sameStaff, sameSystem);

if (score->selectionChanged()) {
score->setSelectionChanged(false);
Expand Down
2 changes: 1 addition & 1 deletion mscore/musescore.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
void disableCommands(bool val) { inChordEditor = val; }

Tuplet* tupletDialog();
void selectSimilar(Element*, bool);
void selectSimilar(Element*, bool, bool);
void selectSimilarInRange(Element* e);
void selectElementDialog(Element* e);
void transpose();
Expand Down
17 changes: 13 additions & 4 deletions mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ void ScoreView::objectPopup(const QPoint& pos, Element* obj)
}
}
else if (cmd == "select-similar")
mscore->selectSimilar(obj, false);
mscore->selectSimilar(obj, false, false);
else if (cmd == "select-similar-staff")
mscore->selectSimilar(obj, true);
mscore->selectSimilar(obj, true, false);
else if (cmd == "select-similar-staff-system")
mscore->selectSimilar(obj, true, true);
else if (cmd == "select-similar-range")
mscore->selectSimilarInRange(obj);
else if (cmd == "select-dialog")
Expand Down Expand Up @@ -2320,13 +2322,20 @@ void ScoreView::cmd(const char* s)
{{"select-similar"}, [](ScoreView* cv, const QByteArray&) {
if (cv->score()->selection().isSingle()) {
Element* e = cv->score()->selection().element();
mscore->selectSimilar(e, false);
mscore->selectSimilar(e, false, false);
}
}},
{{"select-similar-staff"}, [](ScoreView* cv, const QByteArray&) {
if (cv->score()->selection().isSingle()) {
Element* e = cv->score()->selection().element();
mscore->selectSimilar(e, true);
mscore->selectSimilar(e, true, false);
}
}},
{{"select-similar-staff-system"}, [](ScoreView* cv, const QByteArray&) {
if (cv->score()->selection().isSingle()) {
Element* e = cv->score()->selection().element();
mscore->selectSimilar(e, true, true);
cv->updateAll();
}
}},
{{"select-dialog"}, [](ScoreView* cv, const QByteArray&) {
Expand Down
7 changes: 7 additions & 0 deletions mscore/shortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,13 @@ Shortcut Shortcut::_sc[] = {
QT_TRANSLATE_NOOP("action","All Similar Elements in Same Staff"),
QT_TRANSLATE_NOOP("action","Select all similar elements in same staff")
},
{
MsWidget::SCORE_TAB,
STATE_NORMAL | STATE_NOTE_ENTRY,
"select-similar-staff-system",
QT_TRANSLATE_NOOP("action","All Similar Elements in Same Staff & System"),
QT_TRANSLATE_NOOP("action","Select all similar elements in same staff & system")
},
{
MsWidget::SCORE_TAB,
STATE_NORMAL | STATE_NOTE_ENTRY,
Expand Down

0 comments on commit a951f87

Please sign in to comment.