📄 noteinserter.cpp
字号:
} } } if (i == segment.begin()) break; --i; } } bool changed = false; if (m_clickHappened) { if (time != m_clickTime || pitch != m_clickPitch || height != m_clickHeight || staffNo != m_clickStaffNo) { changed = true; } } else { m_clickHappened = true; changed = true; } if (changed) { m_clickTime = time; m_clickPitch = pitch; m_clickHeight = height; m_clickStaffNo = staffNo; showPreview(); } return true;}void NoteInserter::showPreview(){ Segment &segment = m_nParentView->getStaff(m_clickStaffNo)->getSegment(); int pitch = m_clickPitch; pitch += getOttavaShift(segment, m_clickTime) * 12; m_nParentView->showPreviewNote(m_clickStaffNo, m_clickInsertX, pitch, m_clickHeight, Note(m_noteType, m_noteDots));}void NoteInserter::clearPreview(){ m_nParentView->clearPreviewNote();}timeTNoteInserter::getOffsetWithinRest(int staffNo, const NotationElementList::iterator &i, double &canvasX) // will be snapped{ //!!! To make this work correctly in tuplet mode, our divisor would // have to be the tupletified duration of the tuplet unit -- we can // do that, we just haven't yet if (m_nParentView->isInTripletMode()) return 0; Staff *staff = m_nParentView->getStaff(staffNo); NotationElement* el = static_cast<NotationElement*>(*i); if (!el->getCanvasItem()) return 0; double offset = canvasX - el->getCanvasX(); if (offset < 0) return 0; double airX, airWidth; el->getLayoutAirspace(airX, airWidth); double origin = ((*i)->getLayoutX() - airX) / 2; double width = airWidth - origin; timeT duration = (*i)->getViewDuration(); TimeSignature timeSig = staff->getSegment().getComposition()->getTimeSignatureAt ((*i)->event()->getAbsoluteTime()); timeT unit = timeSig.getUnitDuration(); int unitCount = duration / unit; if (unitCount > 1) { timeT result = (int)((offset / width) * unitCount); if (result > unitCount - 1) result = unitCount - 1; double visibleWidth(airWidth); NotationElementList::iterator j(i); if (++j != staff->getViewElementList()->end()) { visibleWidth = (*j)->getLayoutX() - (*i)->getLayoutX(); } offset = (visibleWidth * result) / unitCount; canvasX = el->getCanvasX() + offset; result *= unit; return result; } return 0;}intNoteInserter::getOttavaShift(Segment &segment, timeT time){ // Find out whether we're in an ottava section. int ottavaShift = 0; for (Segment::iterator i = segment.findTime(time); ; --i) { if (!segment.isBeforeEndMarker(i)) break; if ((*i)->isa(Note::EventType) && (*i)->has(NotationProperties::OTTAVA_SHIFT)) { ottavaShift = (*i)->get <Int>(NotationProperties::OTTAVA_SHIFT); break; } if ((*i)->isa(Indication::EventType)) { try { Indication ind(**i); if (ind.isOttavaType()) { ottavaShift = ind.getOttavaShift(); break; } } catch (...) { } } if (i == segment.begin()) break; } return ottavaShift;}Event *NoteInserter::doAddCommand(Segment &segment, timeT time, timeT endTime, const Note ¬e, int pitch, Accidental accidental){ timeT noteEnd = time + note.getDuration(); // #1046934: make it possible to insert triplet at end of segment! if (m_nParentView->isInTripletMode()) { noteEnd = time + (note.getDuration() * 2 / 3); } if (time < segment.getStartTime() || endTime > segment.getEndMarkerTime() || noteEnd > segment.getEndMarkerTime()) { return 0; } pitch += getOttavaShift(segment, time) * 12; NoteInsertionCommand *insertionCommand = new NoteInsertionCommand (segment, time, endTime, note, pitch, accidental, m_autoBeam && !m_nParentView->isInTripletMode(), m_matrixInsertType, m_defaultStyle); KCommand *activeCommand = insertionCommand; if (m_nParentView->isInTripletMode()) { Segment::iterator i(segment.findTime(time)); if (i != segment.end() && !(*i)->has(BaseProperties::BEAMED_GROUP_TUPLET_BASE)) { KMacroCommand *command = new KMacroCommand(insertionCommand->name()); //## Attempted fix to bug reported on rg-user by SlowPic //## <slowpic@web.de> 28/02/2005 22:32:56 UTC: Triplet input error //# HJJ: Comment out this attempt. It breaks the splitting of //# the first bars into rests. //## if ((*i)->isa(Note::EventRestType) && //## (*i)->getNotationDuration() > (note.getDuration() * 3)) { // split the rest command->addCommand(new RestInsertionCommand (segment, time, time + note.getDuration() * 2, Note::getNearestNote(note.getDuration() * 2))); //## } //# These comments should probably be deleted. command->addCommand(new TupletCommand (segment, time, note.getDuration(), 3, 2, true)); // #1046934: "has timing already" command->addCommand(insertionCommand); activeCommand = command; } } m_nParentView->addCommandToHistory(activeCommand); NOTATION_DEBUG << "NoteInserter::doAddCommand: accidental is " << accidental << endl; return insertionCommand->getLastInsertedEvent();}void NoteInserter::slotSetNote(Note::Type nt){ m_noteType = nt;}void NoteInserter::slotSetDots(unsigned int dots){ m_noteDots = dots; KToggleAction *dotsAction = dynamic_cast<KToggleAction *> (actionCollection()->action("toggle_dot")); if (dotsAction) dotsAction->setChecked(dots > 0);}void NoteInserter::slotSetAccidental(Accidental accidental, bool follow){ NOTATION_DEBUG << "NoteInserter::setAccidental: accidental is " << accidental << endl; m_accidental = accidental; m_followAccidental = follow;}void NoteInserter::slotNoAccidental(){ m_parentView->actionCollection()->action("no_accidental")->activate();}void NoteInserter::slotFollowAccidental(){ m_parentView->actionCollection()->action("follow_accidental")->activate();}void NoteInserter::slotSharp(){ m_parentView->actionCollection()->action("sharp_accidental")->activate();}void NoteInserter::slotFlat(){ m_parentView->actionCollection()->action("flat_accidental")->activate();}void NoteInserter::slotNatural(){ m_parentView->actionCollection()->action("natural_accidental")->activate();}void NoteInserter::slotDoubleSharp(){ m_parentView->actionCollection()->action("double_sharp_accidental")->activate();}void NoteInserter::slotDoubleFlat(){ m_parentView->actionCollection()->action("double_flat_accidental")->activate();}void NoteInserter::slotToggleDot(){ m_noteDots = (m_noteDots) ? 0 : 1; Note note(m_noteType, m_noteDots); QString actionName(NotationStrings::getReferenceName(note)); actionName.replace(QRegExp("-"), "_"); KAction *action = m_parentView->actionCollection()->action(actionName); if (!action) { std::cerr << "WARNING: No such action as " << actionName << std::endl; } else { action->activate(); }}void NoteInserter::slotToggleAutoBeam(){ m_autoBeam = !m_autoBeam;}void NoteInserter::slotEraseSelected(){ m_parentView->actionCollection()->action("erase")->activate();}void NoteInserter::slotSelectSelected(){ m_parentView->actionCollection()->action("select")->activate();}void NoteInserter::slotRestsSelected(){ Note note(m_noteType, m_noteDots); QString actionName(NotationStrings::getReferenceName(note, true)); actionName.replace(QRegExp("-"), "_"); KAction *action = m_parentView->actionCollection()->action(actionName); if (!action) { std::cerr << "WARNING: No such action as " << actionName << std::endl; } else { action->activate(); }}const char* NoteInserter::m_actionsAccidental[][4] ={ { "No accidental", "1slotNoAccidental()", "no_accidental", "accidental-none" }, { "Follow accidental", "1slotFollowAccidental()", "follow_accidental", "accidental-follow" }, { "Sharp", "1slotSharp()", "sharp_accidental", "accidental-sharp" }, { "Flat", "1slotFlat()", "flat_accidental", "accidental-flat" }, { "Natural", "1slotNatural()", "natural_accidental", "accidental-natural" }, { "Double sharp", "1slotDoubleSharp()", "double_sharp_accidental", "accidental-doublesharp" }, { "Double flat", "1slotDoubleFlat()", "double_flat_accidental", "accidental-doubleflat" }};const QString NoteInserter::ToolName = "noteinserter";}#include "NoteInserter.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -