change mouse note entry

This commit is contained in:
Werner Schweer 2012-08-06 21:55:51 +02:00
parent 69c0b17495
commit 50aa1f5cd3
8 changed files with 76 additions and 56 deletions

View file

@ -29,7 +29,7 @@
const ClefInfo clefTable[] = {
// |--MusicXml-| octchng pitchoffset
// tag xmlName line yoffs |-lines for sharps--||--lines for flats--| name
// tag xmlName line yoffs |-lines for sharps--||--lines for flats--| name
{ "G", "G", 2, 0, 0, 45, { 0, 3,-1, 2, 5, 1, 4, 4, 1, 5, 2, 6, 3, 7 }, TR("Treble clef"), PITCHED_STAFF },
{ "G8va", "G", 2, 1, 7, 52, { 0, 3,-1, 2, 5, 1, 4, 4, 1, 5, 2, 6, 3, 7 }, TR("Treble clef 8va"), PITCHED_STAFF },
{ "G15ma","G", 2, 2, 14, 59, { 0, 3,-1, 2, 5, 1, 4, 4, 1, 5, 2, 6, 3, 7 }, TR("Treble clef 15ma"), PITCHED_STAFF },

View file

@ -641,9 +641,10 @@ void Score::putNote(const QPointF& pos, bool replace)
Staff* st = staff(staffIdx);
KeySigEvent key = st->keymap()->key(tick);
int clef = st->clef(tick);
int acci = s->measure()->findAccidental(s, staffIdx, line);
qDebug("putNote at tick %d staff %d line %d key %d clef %d",
tick, staffIdx, line, key.accidentalType(), clef);
qDebug("putNote at tick %d staff %d line %d key %d clef %d currentAccidental %d",
tick, staffIdx, line, key.accidentalType(), clef, acci);
_is.setTrack(staffIdx * VOICES + _is.voice());
_is.setSegment(s);
@ -686,7 +687,8 @@ qDebug("putNote at tick %d staff %d line %d key %d clef %d",
}
case PITCHED_STAFF:
nval.pitch = line2pitch(line, clef, key.accidentalType());
// nval.pitch = line2pitch(line, clef, key.accidentalType());
nval.pitch = line2pitch(line, clef, 0) + acci;
break;
}

View file

@ -384,24 +384,15 @@ int Measure::findAccidental(Note* note) const
foreach(Note* note1, chord->notes()) {
if (note1->tieBack())
continue;
int pitch = note1->pitch();
//
// compute accidental
//
int tpc = note1->tpc();
int line = tpc2step(tpc) + (pitch/12) * 7;
int tpcPitch = tpc2pitch(tpc);
if (tpcPitch < 0)
line += 7;
else
line -= (tpcPitch/12)*7;
int tpc = note1->tpc();
int line = computeLine(tpc, note1->pitch());
if (note == note1)
return tversatz.accidentalVal(line);
int accVal = ((tpc + 1) / 7) - 2;
if (accVal != tversatz.accidentalVal(line))
tversatz.setAccidentalVal(line, accVal);
tversatz.setAccidentalVal(line, tpc2alter(tpc));
}
}
}
@ -409,6 +400,40 @@ int Measure::findAccidental(Note* note) const
return 0;
}
int Measure::findAccidental(Segment* s, int staffIdx, int line) const
{
AccidentalState tversatz; // state of already set accidentals for this measure
Staff* staff = score()->staff(staffIdx);
tversatz.init(staff->keymap()->key(tick()));
Segment::SegmentTypes st = Segment::SegChordRest | Segment::SegGrace;
int startTrack = staffIdx * VOICES;
int endTrack = startTrack + VOICES;
for (Segment* segment = first(st); segment; segment = segment->next(st)) {
if (segment == s) {
int clef = staff->clef(s->tick());
int l = -line + 45 + clefTable[clef].yOffset;
return tversatz.accidentalVal(l);
}
for (int track = startTrack; track < endTrack; ++track) {
Element* e = segment->element(track);
if (!e || e->type() != CHORD)
continue;
Chord* chord = static_cast<Chord*>(e);
foreach(Note* note, chord->notes()) {
if (note->tieBack())
continue;
int tpc = note->tpc();
int l = computeLine(tpc, note->pitch());
tversatz.setAccidentalVal(l, tpc2alter(tpc));
}
}
}
qDebug("segment not found");
return 0;
}
//---------------------------------------------------------
// Measure::layout
//---------------------------------------------------------

View file

@ -249,6 +249,7 @@ class Measure : public MeasureBase {
int repeatFlags() const { return _repeatFlags; }
void setRepeatFlags(int val);
int findAccidental(Note*) const;
int findAccidental(Segment* s, int staffIdx, int line) const;
void exchangeVoice(int, int, int, int);
void checkMultiVoices(int staffIdx);
bool hasVoice(int track) const;

View file

@ -1285,12 +1285,7 @@ void Note::layout10(AccidentalState* as)
}
}
else {
_line = tpc2step(_tpc) + (_pitch/12) * 7;
int tpcPitch = tpc2pitch(_tpc);
if (tpcPitch < 0)
_line += 7;
else
_line -= (tpcPitch/12)*7;
_line = computeLine(_tpc, _pitch);
// calculate accidental
@ -1303,12 +1298,7 @@ void Note::layout10(AccidentalState* as)
qDebug("note has wrong tpc: %d, expected %d", _tpc, ntpc);
setColor(QColor(255, 0, 0));
_tpc = ntpc;
_line = tpc2step(_tpc) + (_pitch/12) * 7;
int tpcPitch = tpc2pitch(_tpc);
if (tpcPitch < 0)
_line += 7;
else
_line -= (tpcPitch/12)*7;
_line = computeLine(_tpc, _pitch);
}
}
}
@ -1597,12 +1587,7 @@ void Note::updateAccidental(AccidentalState* as)
void Note::updateLine()
{
_line = tpc2step(_tpc) + (_pitch/12) * 7;
int tpcPitch = tpc2pitch(_tpc);
if (tpcPitch < 0)
_line += 7;
else
_line -= (tpcPitch/12)*7;
_line = computeLine(_tpc, _pitch);
Staff* s = score()->staff(staffIdx() + chord()->staffMove());
int tick = chord()->tick();
int clef = s->clef(tick);

View file

@ -117,16 +117,6 @@ int tpc2pitch(int tpc)
return pitches[tpc];
}
//---------------------------------------------------------
// pitch2line
//---------------------------------------------------------
int pitch2line(int pitch)
{
int tpc = pitch2tpc(pitch);
return tpc2step(tpc) + (pitch / 12) * 7;
}
//---------------------------------------------------------
// printTpc
// print note name
@ -175,15 +165,6 @@ QString tpc2stepName(int tpc)
return QString(names[(tpc + 1) % 7]);
}
//---------------------------------------------------------
// tpc2alter
//---------------------------------------------------------
int tpc2alter(int tpc)
{
return ((tpc+1) / 7) - 2;
}
// table of alternative spellings for one octave
// each entry is the TPC of the note
// tab1 does not contain double sharps
@ -699,3 +680,29 @@ int pitch2tpc(int pitch, int key)
return ptab[key+7][step];
}
//---------------------------------------------------------
// computeLine
//---------------------------------------------------------
int computeLine(int tpc, int pitch)
{
int line = tpc2step(tpc) + (pitch/12) * 7;
int tpcPitch = tpc2pitch(tpc);
if (tpcPitch < 0)
line += 7;
else
line -= (tpcPitch / 12) * 7;
return line;
}
//---------------------------------------------------------
// pitch2line
//---------------------------------------------------------
int pitch2line(int pitch)
{
int tpc = pitch2tpc(pitch);
return tpc2step(tpc) + (pitch / 12) * 7;
}

View file

@ -46,9 +46,9 @@ extern int step2tpc(const QString& stepName, int alter);
extern int step2tpc(int step, int alter);
extern int tpc2pitch(int tpc);
extern int tpc2step(int tpc);
extern int tpc2alter(int tpc);
static inline int tpc2alter(int tpc) { return ((tpc+1) / 7) - 2; }
extern QString tpc2stepName(int tpc);
extern bool tpcIsValid(int val);
extern int computeLine(int tpc, int pitch);
#endif

View file

@ -5309,7 +5309,7 @@ void ScoreView::cmdAddPitch1(int pitch, bool addFlag, int step)
}
}
}
segm = segm->next(SegGrace | SegChordRest);
segm = segm->next(Segment::SegGrace | Segment::SegChordRest);
}
// }
// }