void KeySignatureAction::mousePress(Staff* staff, int barIdx, const QPointF& pos) { Q_UNUSED( pos ); if (m_showDialog) { KeySignatureDialog dlg; dlg.setMusicStyle(m_tool->shape()->style()); dlg.setBar(barIdx); KeySignature* ks = staff->lastKeySignatureChange(barIdx); dlg.setAccidentals(ks ? ks->accidentals() : 0); if (dlg.exec() == QDialog::Accepted) { if (dlg.updateAllStaves()) { staff = NULL; } if (dlg.updateToNextChange() || dlg.updateTillEndOfPiece()) { SetKeySignatureCommand::RegionType t = dlg.updateToNextChange() ? SetKeySignatureCommand::NextChange : SetKeySignatureCommand::EndOfPiece; m_tool->addCommand(new SetKeySignatureCommand(m_tool->shape(), dlg.startBar(), t, staff, dlg.accidentals())); } else { m_tool->addCommand(new SetKeySignatureCommand(m_tool->shape(), dlg.startBar(), dlg.endBar(), staff, dlg.accidentals())); } } } else { m_tool->addCommand(new SetKeySignatureCommand(m_tool->shape(), barIdx, SetKeySignatureCommand::NextChange, NULL, m_accidentals)); } }
void NoteEntryAction::mousePress(Staff* staff, int bar, const QPointF& pos) { Clef* clef = staff->lastClefChange(bar); Voice* voice = staff->part()->voice(m_tool->voice()); VoiceBar* vb = voice->bar(bar); // find element before which to insert the chord int before = 0; for (int i = 0; i < vb->elementCount(); i++) { VoiceElement* e = vb->element(i); if (e->x() >= pos.x()) break; before++; } int line = staff->line(pos.y()); int pitch = 0, accidentals = 0; if (clef && !m_isRest) { pitch = clef->lineToPitch(line); // get correct accidentals for note KeySignature* ks = staff->lastKeySignatureChange(bar); if (ks) accidentals = ks->accidentals(pitch); for (int i = 0; i < before; 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 = NULL; if (before > 0) join = dynamic_cast<Chord*>(vb->element(before-1)); if (join && join->x() + join->width() >= pos.x()) { if (clef && !m_isRest) { m_tool->addCommand(new AddNoteCommand(m_tool->shape(), join, staff, m_duration, pitch, accidentals)); } else { m_tool->addCommand(new MakeRestCommand(m_tool->shape(), join)); } } else { if (clef && !m_isRest) { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before, pitch, accidentals)); } else { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before)); } } }
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(); } }
static void writeChord(KoXmlWriter& w, Chord* chord, Voice* voice, Part* part, int bar) { if (!chord->noteCount()) { w.startElement("music:note"); w.startElement("music:rest"); w.endElement(); // music:rest w.startElement("music:duration"); w.addTextNode(QString::number(chord->length())); w.endElement(); // music:duration w.startElement("music:voice"); w.addTextNode(QString::number(part->indexOfVoice(voice) + 1)); w.endElement(); // music:voice w.startElement("music:type"); w.addTextNode(durationToString(chord->duration())); w.endElement(); // music:type for (int i = 0; i < chord->dots(); i++) { w.startElement("music:dot"); w.endElement(); // music:dot } if (part->staffCount() > 1) { // only write staff info when more than one staff exists Staff* s = chord->staff(); w.startElement("music:staff"); w.addTextNode(QString::number(part->indexOfStaff(s) + 1)); w.endElement(); //music:staff } w.endElement(); // music:note } else for (int n = 0; n < chord->noteCount(); n++) { Staff* staff = chord->note(n)->staff(); w.startElement("music:note"); if (n > 0) { w.startElement("music:chord"); w.endElement(); // music:chord } w.startElement("music:pitch"); w.startElement("music:step"); int pitch = chord->note(n)->pitch(); char note = 'A' + ((((pitch + 2) % 7) + 7) % 7); w.addTextNode(QString(note)); w.endElement(); // music:step if (chord->note(n)->accidentals()) { w.startElement("music:alter"); w.addTextNode(QString::number(chord->note(n)->accidentals())); w.endElement(); // music:alter } w.startElement("music:octave"); w.addTextNode(QString::number((pitch + 4*7) / 7)); // first add, than divide to get proper rounding w.endElement(); // music:octave w.endElement(); // music:pitch w.startElement("music:duration"); w.addTextNode(QString::number(chord->length())); w.endElement(); // music:duration w.startElement("music:voice"); w.addTextNode(QString::number(part->indexOfVoice(voice) + 1)); w.endElement(); // music:voice w.startElement("music:type"); w.addTextNode(durationToString(chord->duration())); w.endElement(); // music:type for (int i = 0; i < chord->dots(); i++) { w.startElement("music:dot"); w.endElement(); // music:dot } int activeAccidentals = 0; KeySignature* ks = staff->lastKeySignatureChange(bar); if (ks) activeAccidentals = ks->accidentals(chord->note(n)->pitch()); VoiceBar* vb = chord->voiceBar(); // next check the bar for the last previous note in the same voice with the same pitch for (int e = 0; e < vb->elementCount(); e++) { Chord* c = dynamic_cast<Chord*>(vb->element(e)); if (!c) continue; if (c == chord) break; for (int nid = 0; nid < c->noteCount(); nid++) { Note* note = c->note(nid); if (note->staff() != staff) continue; if (note->pitch() == chord->note(n)->pitch()) { activeAccidentals = note->accidentals(); } } } if (chord->note(n)->accidentals() != activeAccidentals) { w.startElement("music:accidental"); switch (chord->note(n)->accidentals()) { case -2: w.addTextNode("flat-flat"); break; case -1: w.addTextNode("flat"); break; case 0: w.addTextNode("natural"); break; case 1: w.addTextNode("sharp"); break; case 2: w.addTextNode("double-sharp"); break; } w.endElement(); // music:accidental } if (part->staffCount() > 1) { // only write staff info when more than one staff exists Staff* s = chord->note(n)->staff(); w.startElement("music:staff"); w.addTextNode(QString::number(part->indexOfStaff(s) + 1)); w.endElement(); //music:staff } w.endElement(); // music:note } }