Skip to content

Commit

Permalink
fix #25052
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Mar 26, 2014
1 parent 2486a95 commit ef3a7da
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 156 deletions.
5 changes: 2 additions & 3 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void Chord::remove(Element* e)
// update accidentals for endNote
Chord* chord = note->tieFor()->endNote()->chord();
Measure* m = chord->segment()->measure();
note->score()->updateAccidentals(m,chord->staffIdx());
m->updateAccidentals(chord->staffIdx());
}
}
}
Expand Down Expand Up @@ -1499,8 +1499,7 @@ void Chord::layout10(AccidentalState* as)
Drumset* drumset = 0;
if (staff()->part()->instr()->useDrumset())
drumset = staff()->part()->instr()->drumset();
for (int i = 0; i < notes().size(); ++i) {
Note* note = notes().at(i);
for (Note* note : notes()) {
if (drumset) {
int pitch = note->pitch();
if (!drumset->isValid(pitch)) {
Expand Down
49 changes: 23 additions & 26 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,22 +1067,20 @@ qDebug(" ChangeCRLen:: %d += %d(actual=%d)", tick, f2.ticks(), f2.ticks() * tim
void Score::upDown(bool up, UpDownMode mode)
{
QList<Note*> el;
int tick = -1;
foreach (Note* note, selection().noteList()) {
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)) {
if (!el.contains(note))
el.append(note);
if (tick == -1)
tick = note->chord()->tick();
}
}
}

if (el.empty())
return;

foreach(Note* oNote, el) {
foreach (Note* oNote, el) {
int tick = oNote->chord()->tick();
Part* part = oNote->staff()->part();
int key = oNote->staff()->key(tick).accidentalType();
int tpc = oNote->tpc();
Expand All @@ -1091,32 +1089,31 @@ void Score::upDown(bool up, UpDownMode mode)
int newPitch = pitch; // default to unchanged
int string = oNote->string();
int fret = oNote->fret();
StringData* stringData;

switch(oNote->staff()->staffType()->group()) {
switch (oNote->staff()->staffType()->group()) {
case PERCUSSION_STAFF_GROUP:
{
Drumset* ds = part->instr()->drumset();
if(ds) {
newPitch = up ? ds->prevPitch(pitch) : ds->nextPitch(pitch);
newTpc = oNote->tpc();
if (ds) {
newPitch = up ? ds->prevPitch(pitch) : ds->nextPitch(pitch);
newTpc = oNote->tpc();
}
}
break;
case TAB_STAFF_GROUP:
{
stringData = part->instr()->stringData();
StringData* stringData = part->instr()->stringData();
switch(mode) {
case UP_DOWN_OCTAVE: // move same note to next string, if possible
{
StaffTypeTablature * stt = static_cast<StaffTypeTablature*>(oNote->staff()->staffType());
StaffTypeTablature* stt = static_cast<StaffTypeTablature*>(oNote->staff()->staffType());
string = stt->physStringToVisual(string);
string += (up ? -1 : 1);
if(string < 0 || string >= stringData->strings())
if (string < 0 || string >= stringData->strings())
return; // no next string to move to
string = stt->VisualStringToPhys(string);
fret = stringData->fret(pitch, string);
if(fret == -1) // can't have that note on that string
if (fret == -1) // can't have that note on that string
return;
// newPitch and newTpc remain unchanged
}
Expand Down Expand Up @@ -1163,6 +1160,7 @@ void Score::upDown(bool up, UpDownMode mode)
}
}
break;

case STANDARD_STAFF_GROUP:
switch(mode) {
case UP_DOWN_OCTAVE:
Expand Down Expand Up @@ -1239,17 +1237,14 @@ void Score::upDown(bool up, UpDownMode mode)
// user added accidentals are removed here.
if (oNote->accidental())
undoRemoveElement(oNote->accidental());

Staff* s = oNote->score()->staff(oNote->staffIdx() + oNote->chord()->staffMove());
int tick = oNote->chord()->tick();
ClefType clef = s->clef(tick);
int newLine = relStep(absStep(newTpc, newPitch), clef);

undoChangePitch(oNote, newPitch, newTpc, newLine);
if (oNote->pitch() != newPitch)
undoChangeProperty(oNote, P_PITCH, newPitch);
if (oNote->tpc() != newTpc)
undoChangeProperty(oNote, P_TPC, newTpc);
}
// store fret change only if undoChangePitch has not been called,
// as undoChangePitch() already manages fret changes, if necessary
else if( oNote->staff()->staffType()->group() == TAB_STAFF_GROUP) {
else if (oNote->staff()->staffType()->group() == TAB_STAFF_GROUP) {
bool refret = false;
if (oNote->string() != string) {
undoChangeProperty(oNote, P_STRING, string);
Expand All @@ -1259,8 +1254,10 @@ void Score::upDown(bool up, UpDownMode mode)
undoChangeProperty(oNote, P_FRET, fret);
refret = true;
}
if (refret)
if (refret) {
StringData* stringData = part->instr()->stringData();
stringData->fretChords(oNote->chord());
}
}

// play new note with velocity 80 for 0.3 sec:
Expand Down Expand Up @@ -1349,7 +1346,7 @@ static void changeAccidental2(Note* n, int pitch, int tpc)
// recalculate needed accidentals for
// whole measure
//
score->updateAccidentals(chord->measure(), staffIdx);
chord->measure()->updateAccidentals(staffIdx);
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Chord* Score::addChord(int tick, TDuration d, Chord* oc, bool genTie, Tuplet* tu
}
}

updateAccidentals(measure, chord->staffIdx());
measure->updateAccidentals(chord->staffIdx());
return chord;
}

Expand Down
127 changes: 69 additions & 58 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void Measure::layoutCR0(ChordRest* cr, qreal mm)
if (chord->noteType() != NOTE_NORMAL)
m *= score()->styleD(ST_graceNoteMag);
if (drumset) {
foreach(Note* note, chord->notes()) {
for (Note* note : chord->notes()) {
int pitch = note->pitch();
if (!drumset->isValid(pitch)) {
// qDebug("unmapped drum note %d", pitch);
Expand All @@ -359,19 +359,25 @@ void Measure::layoutCR0(ChordRest* cr, qreal mm)
}

//---------------------------------------------------------
// layoutChords10
// layout10
// computes note lines and accidentals
//---------------------------------------------------------

void Measure::layoutChords10(Segment* segment, int startTrack, AccidentalState* as)
void Measure::layout10(int staffIdx)
{
int endTrack = startTrack + VOICES;
for (int track = startTrack; track < endTrack; ++track) {
Element* e = segment->element(track);
if (!e || e->type() != CHORD)
continue;
Chord* chord = static_cast<Chord*>(e);
chord->layout10(as);
AccidentalState as; // state of already set accidentals for this measure
Staff* staff = score()->staff(staffIdx);
as.init(staff->keymap()->key(tick()));
int startTrack = staffIdx * VOICES;
int endTrack = startTrack + VOICES;

for (Segment* s = first(Segment::SegChordRest); s; s = s->next(Segment::SegChordRest)) {
for (int track = startTrack; track < endTrack; ++track) {
Chord* chord = static_cast<Chord*>(s->element(track));
if (!chord || chord->type() != CHORD)
continue;
chord->layout10(&as);
}
}
}

Expand Down Expand Up @@ -3611,66 +3617,71 @@ void Measure::layoutStage1()
/// undoable add/remove
//---------------------------------------------------------

void Measure::updateAccidentals(Segment* segment, int staffIdx, AccidentalState* tversatz)
void Measure::updateAccidentals(int staffIdx)
{
Staff* staff = score()->staff(staffIdx);
int startTrack = staffIdx * VOICES;
int endTrack = startTrack + VOICES;
StaffGroup staffGroup = staff->staffType()->group();
Staff* staff = score()->staff(staffIdx);
StaffGroup staffGroup = staff->staffType()->group();
const Instrument* instrument = staff->part()->instr();
int startTrack = staffIdx * VOICES;
int endTrack = startTrack + VOICES;

for (int track = startTrack; track < endTrack; ++track) {
Chord* chord = static_cast<Chord*>(segment->element(track));
if (!chord || chord->type() != CHORD)
continue;
AccidentalState as; // list of already set accidentals for this measure
as.init(staff->keymap()->key(tick()));

// TAB_STAFF is different, as each note has to be fretted
// in the context of the all of the chords of the whole segment
for (Segment* segment = first(Segment::SegChordRest); segment; segment = segment->next(Segment::SegChordRest)) {
for (int track = startTrack; track < endTrack; ++track) {
Chord* chord = static_cast<Chord*>(segment->element(track));
if (!chord || chord->type() != CHORD)
continue;

if (staffGroup == TAB_STAFF_GROUP) {
for (Chord* ch : chord->graceNotes())
instrument->stringData()->fretChords(ch);
instrument->stringData()->fretChords(chord);
continue; // skip other staff type cases
}
// TAB_STAFF is different, as each note has to be fretted
// in the context of the all of the chords of the whole segment

// PITCHED_ and PERCUSSION_STAFF can go note by note
if (staffGroup == TAB_STAFF_GROUP) {
for (Chord* ch : chord->graceNotes())
instrument->stringData()->fretChords(ch);
instrument->stringData()->fretChords(chord);
continue; // skip other staff type cases
}

for (Chord* ch : chord->graceNotes()) {
for (Note* note : ch->notes())
note->updateAccidental(tversatz);
}
// PITCHED_ and PERCUSSION_STAFF can go note by note

for (Note* note : chord->notes()) {
switch(staffGroup) {
case STANDARD_STAFF_GROUP:
if (note->tieBack()) {
if (note->accidental() && note->tpc() == note->tieBack()->startNote()->tpc()) {
// TODO: remove accidental only if note is not
// on new system
score()->undoRemoveElement(note->accidental());
}
}
note->updateAccidental(tversatz);
break;
case PERCUSSION_STAFF_GROUP:
{
Drumset* drumset = instrument->drumset();
int pitch = note->pitch();
if(drumset) {
if (!drumset->isValid(pitch)) {
// qDebug("unmapped drum note %d", pitch);
for (Chord* ch : chord->graceNotes()) {
for (Note* note : ch->notes())
note->updateAccidental(&as);
}

for (Note* note : chord->notes()) {
switch(staffGroup) {
case STANDARD_STAFF_GROUP:
if (note->tieBack()) {
if (note->accidental() && note->tpc() == note->tieBack()->startNote()->tpc()) {
// TODO: remove accidental only if note is not
// on new system
score()->undoRemoveElement(note->accidental());
}
}
else {
note->setHeadGroup(drumset->noteHead(pitch));
note->setLine(drumset->line(pitch));
continue;
note->updateAccidental(&as);
break;
case PERCUSSION_STAFF_GROUP:
{
Drumset* drumset = instrument->drumset();
int pitch = note->pitch();
if (drumset) {
if (!drumset->isValid(pitch)) {
// qDebug("unmapped drum note %d", pitch);
}
else {
note->setHeadGroup(drumset->noteHead(pitch));
note->setLine(drumset->line(pitch));
continue;
}
}
}
break;
case TAB_STAFF_GROUP: // to avoid compiler warning
break;
}
break;
case TAB_STAFF_GROUP: // to avoid compiler warning
break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions libmscore/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ class Measure : public MeasureBase {
bool isOnlyRests(int track) const;

// void layoutChords0(Segment* segment, int startTrack);
void layoutChords10(Segment* segment, int startTrack, AccidentalState*);
void updateAccidentals(Segment* segment, int staffIdx, AccidentalState*);
void layout10(int staffIdx);
void updateAccidentals(int staffIdx);
void layoutStage1();
int playbackCount() const { return _playbackCount; }
void setPlaybackCount(int val) { _playbackCount = val; }
Expand Down
9 changes: 6 additions & 3 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ void Note::remove(Element* e)
tie->endNote()->setTieBack(0);
// update accidentals for endNote
Chord* chord = tie->endNote()->chord();
Measure *m = chord->segment()->measure();
score()->updateAccidentals(m,chord->staffIdx());
Measure* m = chord->segment()->measure();
m->updateAccidentals(chord->staffIdx());
}
int n = tie->spannerSegments().size();
for (int i = 0; i < n; ++i) {
Expand Down Expand Up @@ -1487,7 +1487,6 @@ void Note::layout10(AccidentalState* as)
Staff* s = score()->staff(staffIdx() + chord()->staffMove());
int tick = chord()->tick();
_line = relStep(_line, s->clef(tick));

}
}

Expand Down Expand Up @@ -1838,9 +1837,13 @@ bool Note::setProperty(P_ID propertyId, const QVariant& v)
switch(propertyId) {
case P_PITCH:
setPitch(v.toInt());
if (chord()->measure())
chord()->measure()->updateAccidentals(chord()->staffIdx());
break;
case P_TPC:
setTpc(v.toInt());
if (chord()->measure())
chord()->measure()->updateAccidentals(chord()->staffIdx());
break;
case P_SMALL:
setSmall(v.toBool());
Expand Down
6 changes: 3 additions & 3 deletions libmscore/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ static const PropertyData propertyList[] = {
{ P_SMALL, false, "small", T_BOOL },
{ P_SHOW_COURTESY, false, "", T_INT },
{ P_LINE_TYPE, false, "", T_INT },
{ P_PITCH, false, "pitch", T_INT },
{ P_TPC, false, "tpc", T_INT },
{ P_HEAD_TYPE, false, "headType", T_INT },
{ P_PITCH, true, "pitch", T_INT },
{ P_TPC, true, "tpc", T_INT },
{ P_HEAD_TYPE, false, "headType", T_INT },

{ P_HEAD_GROUP, false, "head", T_INT },
{ P_VELO_TYPE, false, "veloType", T_VALUE_TYPE },
Expand Down

0 comments on commit ef3a7da

Please sign in to comment.