Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #20579
  • Loading branch information
wschweer committed May 26, 2014
1 parent 62110ec commit bdc7ec2
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 18 deletions.
17 changes: 7 additions & 10 deletions libmscore/cmd.cpp
Expand Up @@ -1147,16 +1147,7 @@ static void setTpc(Note* oNote, int tpc, int& newTpc1, int& newTpc2)

void Score::upDown(bool up, UpDownMode mode)
{
QList<Note*> el;
for (Note* note : selection().noteList()) {
while (note->tieBack())
note = note->tieBack()->startNote();
for (; note; note = note->tieFor() ? note->tieFor()->endNote() : 0) {
if (!el.contains(note))
el.append(note);
}
}

QList<Note*> el = selection().uniqueNotes();
if (el.empty())
return;

Expand Down Expand Up @@ -1207,12 +1198,18 @@ void Score::upDown(bool up, UpDownMode mode)

case UP_DOWN_CHROMATIC: // increase / decrease the fret
{ // without changing the string
if (!stringData->frets())
qDebug("upDown tab chromatic: no frets?");
fret += (up ? 1 : -1);
if (fret < 0)
fret = 0;
else if (fret >= stringData->frets())
fret = stringData->frets() - 1;
newPitch = stringData->getPitch(string, fret);
if (newPitch == -1) {
qDebug("upDown tab chromatic: getPitch(%d,%d) returns -1", string, fret);
newPitch = oNote->pitch();
}
int nTpc = pitch2tpc(newPitch, key, up ? PREFER_SHARPS : PREFER_FLATS);
if (oNote->concertPitch()) {
newTpc1 = nTpc;
Expand Down
55 changes: 55 additions & 0 deletions libmscore/select.cpp
Expand Up @@ -33,6 +33,7 @@
#include "select.h"
#include "sig.h"
#include "slur.h"
#include "tie.h"
#include "system.h"
#include "text.h"
#include "textline.h"
Expand Down Expand Up @@ -846,6 +847,60 @@ bool Selection::measureRange(Measure** m1, Measure** m2) const
return true;
}

//---------------------------------------------------------
// uniqueElements
// Return list of selected elements.
// If some elements are linked, only one of the linked
// elements show up in the list.
//---------------------------------------------------------

const QList<Element*> Selection::uniqueElements() const
{
QList<Element*> l;

for (Element* e : elements()) {
bool alreadyThere = false;
for (Element* ee : l) {
if ((ee->links() && ee->links()->contains(e)) || e == ee) {
alreadyThere = true;
break;
}
}
if (!alreadyThere)
l.append(e);
}
return l;
}

//---------------------------------------------------------
// uniqueNotes
// Return list of selected notes.
// If some notes are linked, only one of the linked
// elements show up in the list.
//---------------------------------------------------------

QList<Note*> Selection::uniqueNotes(int track) const
{
QList<Note*> l;

for (Note* note : noteList(track)) {
while (note->tieBack())
note = note->tieBack()->startNote();
for (; note; note = note->tieFor() ? note->tieFor()->endNote() : 0) {
bool alreadyThere = false;
for (Note* n : l) {
if ((n->links() && n->links()->contains(note)) || n == note) {
alreadyThere = true;
break;
}
}
if (!alreadyThere)
l.append(note);
}
}
return l;
}


}

7 changes: 6 additions & 1 deletion libmscore/select.h
Expand Up @@ -79,8 +79,13 @@ class Selection {
void setState(SelState s);

const QList<Element*>& elements() const { return _el; }
bool isSingle() const { return (_state == SEL_LIST) && (_el.size() == 1); }
QList<Note*> noteList(int track = -1) const;

const QList<Element*> uniqueElements() const;
QList<Note*> uniqueNotes(int track = -1) const;

bool isSingle() const { return (_state == SEL_LIST) && (_el.size() == 1); }

void add(Element*);
void deselectAll();
void remove(Element*);
Expand Down
38 changes: 31 additions & 7 deletions libmscore/transpose.cpp
Expand Up @@ -263,8 +263,7 @@ void Score::transpose(Note* n, Interval interval, bool useDoubleSharpsFlats)
//---------------------------------------------------------

void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
int transposeInterval,
bool trKeys, bool transposeChordNames, bool useDoubleSharpsFlats)
int transposeInterval, bool trKeys, bool transposeChordNames, bool useDoubleSharpsFlats)
{
bool rangeSelection = selection().state() == SEL_RANGE;
int startStaffIdx = 0;
Expand Down Expand Up @@ -302,7 +301,7 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
transposeInterval *= -1;

if (_selection.state() == SEL_LIST) {
foreach(Element* e, _selection.elements()) {
foreach(Element* e, _selection.uniqueElements()) {
if (e->staff()->staffType()->group() == PERCUSSION_STAFF_GROUP)
continue;
if (e->type() == Element::ElementType::NOTE) {
Expand Down Expand Up @@ -347,11 +346,36 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
return;
}

int startTrack = _selection.staffStart() * VOICES;
int endTrack = _selection.staffEnd() * VOICES;
//--------------------------
// process range selection
//--------------------------

QList<Staff*> sl;
for (int staffIdx = _selection.staffStart(); staffIdx < _selection.staffEnd(); ++staffIdx) {
Staff* s = staff(staffIdx);
if (s->staffType()->group() == PERCUSSION_STAFF_GROUP) // ignore percussion staff
continue;
if (sl.contains(s))
continue;
bool alreadyThere = false;
for (Staff* s2 : sl) {
if (s2 == s || (s2->linkedStaves() && s2->linkedStaves()->staves().contains(s))) {
alreadyThere = true;
break;
}
}
if (!alreadyThere)
sl.append(s);
}
QList<int> tracks;
for (Staff* s : sl) {
int idx = s->idx() * VOICES;
for (int i = 0; i < VOICES; ++i)
tracks.append(idx + i);
}

for (Segment* segment = _selection.startSegment(); segment && segment != _selection.endSegment(); segment = segment->next1()) {
for (int st = startTrack; st < endTrack; ++st) {
for (int st : tracks) {
if (staff(st/VOICES)->staffType()->group() == PERCUSSION_STAFF_GROUP)
continue;
Element* e = segment->element(st);
Expand All @@ -376,7 +400,7 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
}
if (transposeChordNames) {
foreach (Element* e, segment->annotations()) {
if ((e->type() != Element::ElementType::HARMONY) || (e->track() < startTrack) || (e->track() >= endTrack))
if ((e->type() != Element::ElementType::HARMONY) || (!tracks.contains(e->track())))
continue;
Harmony* h = static_cast<Harmony*>(e);
int rootTpc, baseTpc;
Expand Down

0 comments on commit bdc7ec2

Please sign in to comment.