void NoteEntryAction::keyPress(QKeyEvent* event, const MusicCursor& cursor) { if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { Staff* staff = cursor.staff(); //Part* part = staff->part(); //Sheet* sheet = part->sheet(); //Bar* bar = sheet->bar(cursor.bar()); Clef* clef = staff->lastClefChange(cursor.bar()); int line = cursor.line(); int pitch = 0, accidentals = 0; VoiceBar* vb = cursor.voiceBar(); if (clef) { pitch = clef->lineToPitch(line); // get correct accidentals for note KeySignature* ks = staff->lastKeySignatureChange(cursor.bar()); if (ks) accidentals = ks->accidentals(pitch); for (int i = 0; i < cursor.element(); i++) { Chord* c = dynamic_cast<Chord*>(vb->element(i)); if (!c) continue; for (int n = 0; n < c->noteCount(); n++) { if (c->note(n)->pitch() == pitch) { accidentals = c->note(n)->accidentals(); } } } } Chord* join = 0; if (cursor.element() < vb->elementCount()) join = dynamic_cast<Chord*>(vb->element(cursor.element())); if (event->modifiers() & Qt::ShiftModifier || !join) { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, cursor.element(), pitch, accidentals)); } else { m_tool->addCommand(new AddNoteCommand(m_tool->shape(), join, staff, join->duration(), pitch, accidentals)); } event->accept(); } }