Skip to content

Commit

Permalink
manually merge PR musescore#797 and PR#808
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Apr 2, 2014
1 parent 0522c00 commit 408b74d
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 108 deletions.
8 changes: 6 additions & 2 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,12 @@ void Score::cmdFlip()
MScore::Direction d = tuplet->isUp() ? MScore::DOWN : MScore::UP;
undoChangeProperty(tuplet, P_DIRECTION, d);
}
else if (e->type() == Element::NOTEDOT)
undo(new FlipNoteDotDirection(static_cast<Note*>(e->parent())));
else if (e->type() == Element::NOTEDOT) {
Note* note = static_cast<Note*>(e->parent());
MScore::Direction d = note->dotIsUp() ? MScore::DOWN : MScore::UP;
undoChangeProperty(note, P_DOT_POSITION, d);
// undo(new FlipNoteDotDirection(static_cast<Note*>(e->parent())));
}
else if (
(e->type() == Element::TEMPO_TEXT)
| (e->type() == Element::DYNAMIC)
Expand Down
68 changes: 55 additions & 13 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,30 +270,30 @@ void Score::layoutChords1(Segment* segment, int staffIdx)

// calculate offsets
if (shareHeads) {
#if 0
// TODO: get accidentals right
// TODO: make sure we hide the note that would have been underneath
// otherwise nudge might not appear to work since you aren't moving the visible note
// do we really even *need* to hide noteheads of overlap?
for (int i = overlapNotes.size() - 1; i >= 1; i -= 2) {
Note* p = overlapNotes[i-1];
Note* n = overlapNotes[i];
if (!(p->chord()->isNudged() || n->chord()->isNudged())) {
if (n->chord()->actualTicks() > p->chord()->actualTicks()) {
p->setHidden(true);
if (n->chord()->dots() == p->chord()->dots())
bool onLine = !(p->line() & 1);
if (onLine) {
// hide dots for lower voice
if (p->voice() & 1)
p->setDotsHidden(true);
// TODO: p->setAccidentalType(ACC_NONE);
else
n->setDotsHidden(true);
}
else {
n->setHidden(true);
if (n->chord()->dots() == p->chord()->dots())
// hide dots for upper voice
if (!(p->voice() & 1))
p->setDotsHidden(true);
else
n->setDotsHidden(true);
// TODO: n->setAccidentalType(ACC_NONE);
}
// formerly we hid noteheads in an effort to fix playback
// but this doesn't work for cases where noteheads cannot be shared
// so better to solve the problem elsewhere
}
}
#endif
}
else if (conflictUnison && separation == 0)
downOffset = maxUpWidth + 0.3 * sp;
Expand Down Expand Up @@ -766,6 +766,48 @@ void Score::layoutChords3(QList<Note*>& notes, Staff* staff, Segment* segment)
if (note->chord()->dots())
offsetDots = true;
}

if (note->chord()->dots()) {
MScore::Direction dotPosition = note->userDotPosition();

if (dotPosition == MScore::AUTO && nNotes > 1) {
// resolve dot conflicts
int line = note->line();
Note* above = (i < nNotes - 1) ? notes[i+1] : 0;
int intervalAbove = above ? line - above->line() : 1000;
Note* below = (i > 0) ? notes[i-1] : 0;
int intervalBelow = below ? below->line() - line : 1000;
if ((line & 1) == 0) {
// line
if (intervalAbove == 1 && intervalBelow != 1)
dotPosition = MScore::DOWN;
else if (intervalBelow ==1 && intervalAbove != 1)
dotPosition = MScore::UP;
else if (intervalAbove == 0 && above->chord()->dots()) {
// unison
if (((above->voice() & 1) == (note->voice() & 1))) {
above->setDotY(MScore::UP);
dotPosition = MScore::DOWN;
}
}
}
else {
// space
if (intervalAbove == 0 && above->chord()->dots()) {
// unison
if (!(note->voice() & 1))
dotPosition = MScore::UP;
else {
if (!(above->voice() & 1))
above->setDotY(MScore::UP);
else
dotPosition = MScore::DOWN;
}
}
}
}
note->setDotY(dotPosition);
}
}

if (segment) {
Expand Down
128 changes: 75 additions & 53 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Note::Note(Score* s)
_mirror = false;
_userMirror = MScore::DH_AUTO;
_small = false;
_dotPosition = MScore::AUTO;
_userDotPosition = MScore::AUTO;
_line = 0;
_fret = -1;
_string = -1;
Expand Down Expand Up @@ -230,7 +230,7 @@ Note::Note(const Note& n)
_mirror = n._mirror;
_userMirror = n._userMirror;
_small = n._small;
_dotPosition = n._dotPosition;
_userDotPosition = n._userDotPosition;
_accidental = 0;

if (n._accidental)
Expand Down Expand Up @@ -1280,6 +1280,72 @@ Element* Note::drop(const DropData& data)
return 0;
}

//---------------------------------------------------------
// setDotPosition
//---------------------------------------------------------

void Note::setDotY(MScore::Direction pos)
{
bool onLine = false;
qreal y = 0;

if (staff()->isTabStaff()) {
// with TAB's, dotPosX is not set:
// get dot X from width of fret text and use TAB default spacing
StaffTypeTablature* tab = static_cast<StaffTypeTablature*>(staff()->staffType());
if (tab->stemThrough() ) {
// if fret mark on lines, use standard processing
if (tab->onLines())
onLine = true;
else
// if fret marks above lines, raise the dots by half line distance
y = -0.5;
}
// if stems beside staff, do nothing
else
return;
}
else
onLine = !(line() & 1);

bool oddVoice = voice() & 1;
if (onLine) {
// displace dots by half spatium up or down according to voice
if (pos == MScore::AUTO)
y = oddVoice ? 0.5 : -0.5;
else if (pos == MScore::UP)
y = -0.5;
else
y = 0.5;
}
else {
if (pos == MScore::UP && !oddVoice)
y -= 1.0;
else if (pos == MScore::DOWN && oddVoice)
y += 1.0;
}
y *= spatium() * staff()->lineDistance();

// apply to dots

int dots = chord()->dots();
for (int i = 0; i < 3; ++i) {
if (i < dots) {
if (_dots[i] == 0) {
NoteDot* dot = new NoteDot(score());
dot->setIdx(i);
dot->setParent(this);
dot->setTrack(track()); // needed to know the staff it belongs to (and detect tablature)
score()->undoAddElement(dot); // move dot to _dots[i]
}
_dots[i]->layout();
_dots[i]->rypos() = y;
}
else if (_dots[i])
score()->undoRemoveElement(_dots[i]);
}
}

//---------------------------------------------------------
// layout
//---------------------------------------------------------
Expand All @@ -1298,24 +1364,6 @@ void Note::layout()
if (parent() == 0)
return;
}
// if not TAB or TAB with stems through
if (!useTablature || ((StaffTypeTablature*)staff()->staffType())->stemThrough()) {
int dots = chord()->dots();
for (int i = 0; i < 3; ++i) {
if (i < dots) {
if (_dots[i] == 0) {
NoteDot* dot = new NoteDot(score());
dot->setIdx(i);
dot->setParent(this);
dot->setTrack(track()); // needed to know the staff it belongs to (and detect tablature)
score()->undoAddElement(dot); // move dot to _dots[i]
}
_dots[i]->layout();
}
else if (_dots[i])
score()->undoRemoveElement(_dots[i]);
}
}
}

//---------------------------------------------------------
Expand All @@ -1331,51 +1379,25 @@ void Note::layout2()
if (dots) {
qreal d = point(score()->styleS(ST_dotNoteDistance));
qreal dd = point(score()->styleS(ST_dotDotDistance));
qreal y = 0.0;
qreal x = chord()->dotPosX() - pos().x() - chord()->pos().x();
bool onLine = false;

// do not draw dots on staff line:

// if TAB and stems through staff
if (staff()->isTabStaff()) {
// with TAB's, dotPosX is not set:
// get dot X from width of fret text and use TAB default spacing
StaffTypeTablature* tab = static_cast<StaffTypeTablature*>( staff()->staffType());
x = width();
dd = STAFFTYPE_TAB_DEFAULTDOTDIST_X * spatium();
d = dd * 0.5;
if(tab->stemThrough() ) {
// if fret mark on lines, use standard processing
if (tab->onLines())
onLine = true;
else
// if fret marks above lines, raise the dots by half line distance
y = -staff()->lineDistance() * 0.5;
}
// if stems beside staff, do nothing
else
StaffTypeTablature* tab = static_cast<StaffTypeTablature*>( staff()->staffType());
if (!tab->stemThrough())
return;
}
// if not TAB, look at note line
else
onLine = (_line & 1) == 0;
// if on line, displace dots by half spatium up or down according to voice
if (onLine) {
if (_dotPosition == MScore::AUTO)
y = (voice() & 1) == 0 ? -0.5 : 0.5;
else if (_dotPosition == MScore::UP)
y = -0.5;
else
y = 0.5;
}
y *= spatium();

// apply to dots
for (int i = 0; i < dots; ++i) {
NoteDot* dot = _dots[i];
if (dot) {
dot->setPos(x + d + dd * i, y);
dot->rxpos() = x + d + dd * i;
_dots[i]->adjustReadPos();
}
}
Expand Down Expand Up @@ -1802,7 +1824,7 @@ QVariant Note::getProperty(P_ID propertyId) const
case P_MIRROR_HEAD:
return userMirror();
case P_DOT_POSITION:
return dotPosition();
return userDotPosition();
case P_HEAD_GROUP:
return int(headGroup());
case P_VELO_OFFSET:
Expand Down Expand Up @@ -1856,7 +1878,7 @@ bool Note::setProperty(P_ID propertyId, const QVariant& v)
setUserMirror(MScore::DirectionH(v.toInt()));
break;
case P_DOT_POSITION:
setDotPosition(MScore::Direction(v.toInt()));
setUserDotPosition(MScore::Direction(v.toInt()));
break;
case P_HEAD_GROUP:
setHeadGroup(NoteHeadGroup(v.toInt()));
Expand Down Expand Up @@ -1989,10 +2011,10 @@ void Note::undoSetUserMirror(MScore::DirectionH val)
}

//---------------------------------------------------------
// undoSetDotPosition
// undoSetUserDotPosition
//---------------------------------------------------------

void Note::undoSetDotPosition(MScore::Direction val)
void Note::undoSetUserDotPosition(MScore::Direction val)
{
undoChangeProperty(P_DOT_POSITION, val);
}
Expand Down
15 changes: 8 additions & 7 deletions libmscore/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class NoteHead : public Symbol {
// @P veloType enum OFFSET_VAL, USER_VAL
// @P veloOffset int
// @P userMirror enum DH_AUTO, DH_LEFT, DH_RIGHT
// @P dotPosition enum AUTO, UP, DOWN
// @P userDotPosition enum AUTO, UP, DOWN
// @P headGroup enum HEAD_NORMAL, HEAD_CROSS, HEAD_DIAMOND, HEAD_TRIANGLE, HEAD_MI, HEAD_SLASH, HEAD_XCIRCLE, HEAD_DO, HEAD_RE, HEAD_FA, HEAD_LA, HEAD_TI, HEAD_SOL, HEAD_BREVIS_ALT
// @P headType enum HEAD_AUTO, HEAD_WHOLE, HEAD_HALF, HEAD_QUARTER, HEAD_BREVIS
// @P elements array[Element] list of elements attached to note head
Expand All @@ -154,7 +154,7 @@ class Note : public Element {
Q_PROPERTY(Ms::MScore::ValueType veloType READ veloType WRITE undoSetVeloType)
Q_PROPERTY(int veloOffset READ veloOffset WRITE undoSetVeloOffset)
Q_PROPERTY(Ms::MScore::DirectionH userMirror READ userMirror WRITE undoSetUserMirror)
Q_PROPERTY(Ms::MScore::Direction dotPosition READ dotPosition WRITE undoSetDotPosition)
Q_PROPERTY(Ms::MScore::Direction userDotPosition READ userDotPosition WRITE undoSetUserDotPosition)
Q_PROPERTY(NoteHeadGroup headGroup READ headGroup WRITE undoSetHeadGroup)
Q_PROPERTY(NoteHeadType headType READ headType WRITE undoSetHeadType)
Q_PROPERTY(QQmlListProperty<Element> elements READ qmlElements)
Expand Down Expand Up @@ -192,8 +192,8 @@ class Note : public Element {

qreal _tuning; ///< pitch offset in cent, playable only by internal synthesizer

MScore::DirectionH _userMirror; ///< user override of mirror
MScore::Direction _dotPosition; ///< dot position: above or below current staff line
MScore::DirectionH _userMirror; ///< user override of mirror
MScore::Direction _userDotPosition; ///< user override of dot position

Accidental* _accidental;

Expand Down Expand Up @@ -320,8 +320,8 @@ class Note : public Element {
MScore::DirectionH userMirror() const { return _userMirror; }
void setUserMirror(MScore::DirectionH d) { _userMirror = d; }

MScore::Direction dotPosition() const { return _dotPosition; }
void setDotPosition(MScore::Direction d) { _dotPosition = d; }
MScore::Direction userDotPosition() const { return _userDotPosition; }
void setUserDotPosition(MScore::Direction d) { _userDotPosition = d; }
bool dotIsUp() const; // actual dot position

void reset();
Expand Down Expand Up @@ -366,7 +366,7 @@ class Note : public Element {
void undoSetOnTimeUserOffset(int);
void undoSetOffTimeUserOffset(int);
void undoSetUserMirror(MScore::DirectionH);
void undoSetDotPosition(MScore::Direction);
void undoSetUserDotPosition(MScore::Direction);
void undoSetHeadGroup(NoteHeadGroup);
void undoSetHeadType(NoteHeadType);

Expand All @@ -377,6 +377,7 @@ class Note : public Element {
bool mark() const { return _mark; }
void setMark(bool v) const { _mark = v; }
virtual void setScore(Score* s);
void setDotY(MScore::Direction);

static SymId noteHead(int direction, NoteHeadGroup, NoteHeadType);
};
Expand Down
9 changes: 0 additions & 9 deletions libmscore/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,15 +1703,6 @@ void ChangePitch::flip()
score->setPlaylistDirty(true);
}

//---------------------------------------------------------
// FlipNoteDotDirection
//---------------------------------------------------------

void FlipNoteDotDirection::flip()
{
note->setDotPosition(note->dotIsUp() ? MScore::DOWN : MScore::UP);
}

//---------------------------------------------------------
// ChangeElement
//---------------------------------------------------------
Expand Down
Loading

0 comments on commit 408b74d

Please sign in to comment.