📄 notationstaff.cpp
字号:
*m_printPainter, int(coords.first), coords.second); m_printPainter->restore(); } } else { pixmap = m_notePixmapFactory->makeOttavaPixmap (length, octaves); } } else { NOTATION_DEBUG << "Unrecognised indicationType " << indicationType << endl; if (m_showUnknowns) { pixmap = m_notePixmapFactory->makeUnknownPixmap(); } } } } catch (...) { NOTATION_DEBUG << "Bad indication!" << endl; } } else if (elt->event()->isa(Controller::EventType)) { bool isSustain = false; long controlNumber = 0; elt->event()->get <Int>(Controller::NUMBER, controlNumber); Studio *studio = &m_notationView->getDocument()->getStudio(); Track *track = getSegment().getComposition()->getTrackById (getSegment().getTrack()); if (track) { Instrument *instrument = studio->getInstrumentById (track->getInstrument()); if (instrument) { MidiDevice *device = dynamic_cast<MidiDevice *> (instrument->getDevice()); if (device) { for (ControlList::const_iterator i = device->getControlParameters().begin(); i != device->getControlParameters().end(); ++i) { if (i->getType() == Controller::EventType && i->getControllerValue() == controlNumber) { if (i->getName() == "Sustain" || strtoqstr(i->getName()) == i18n("Sustain")) { isSustain = true; } break; } } } else if (instrument->getDevice() && instrument->getDevice()->getType() == Device::SoftSynth) { if (controlNumber == 64) { isSustain = true; } } } } if (isSustain) { long value = 0; elt->event()->get <Int>(Controller::VALUE, value); if (value > 0) { pixmap = m_notePixmapFactory->makePedalDownPixmap(); } else { pixmap = m_notePixmapFactory->makePedalUpPixmap(); } } else { if (m_showUnknowns) { pixmap = m_notePixmapFactory->makeUnknownPixmap(); } } } else if (elt->event()->isa(Guitar::Chord::EventType)) { // Create a guitar chord pixmap try { Guitar::Chord chord (*elt->event()); /* UNUSED - for printing, just use a large pixmap as below if (m_printPainter) { int length = m_notePixmapFactory->getTextWidth(text); for (double w = -1, inc = 0; w != 0; inc += w) { w = setPainterClipping(m_printPainter, elt->getLayoutX(), int(elt->getLayoutY()), int(inc), length, coords, policy); m_notePixmapFactory->drawText (text, *m_printPainter, int(coords.first), coords.second); m_printPainter->restore(); } } else { */ pixmap = m_notePixmapFactory->makeGuitarChordPixmap (chord.getFingering(), int(coords.first), coords.second); // } } catch (Exception e) { // GuitarChord ctor failed NOTATION_DEBUG << "Bad guitar chord event" << endl; } } else { if (m_showUnknowns) { pixmap = m_notePixmapFactory->makeUnknownPixmap(); } } // Show the result, one way or another if (elt->isNote()) { // No need, we already set and showed it in renderNote } else if (pixmap) { setPixmap(elt, pixmap, z, policy); } else { elt->removeCanvasItem(); } // NOTATION_DEBUG << "NotationStaff::renderSingleElement: Setting selected at " << elt->getAbsoluteTime() << " to " << selected << endl; } catch (...) { std::cerr << "Event lacks the proper properties: " << std::endl; elt->event()->dump(std::cerr); } m_notePixmapFactory->setSelected(false); m_notePixmapFactory->setShaded(false);}doubleNotationStaff::setPainterClipping(QPainter *painter, double lx, int ly, double dx, double w, LinedStaffCoords &coords, FitPolicy policy){ painter->save(); // NOTATION_DEBUG << "NotationStaff::setPainterClipping: lx " << lx << ", dx " << dx << ", w " << w << endl; coords = getCanvasCoordsForLayoutCoords(lx + dx, ly); int row = getRowForLayoutX(lx + dx); double rightMargin = getCanvasXForRightOfRow(row); double available = rightMargin - coords.first; // NOTATION_DEBUG << "NotationStaff::setPainterClipping: row " << row << ", rightMargin " << rightMargin << ", available " << available << endl; switch (policy) { case SplitToFit: { bool fit = (w - dx <= available + m_notePixmapFactory->getNoteBodyWidth()); if (dx > 0.01 || !fit) { int clipLeft = int(coords.first), clipWidth = int(available); if (dx < 0.01) { // never clip the left side of the first part of something clipWidth += clipLeft; clipLeft = 0; } QRect clip(clipLeft, coords.second - getRowSpacing() / 2, clipWidth, getRowSpacing()); painter->setClipRect(clip, QPainter::CoordPainter); coords.first -= dx; } if (fit) { return 0.0; } return available; } case MoveBackToFit: if (w - dx > available + m_notePixmapFactory->getNoteBodyWidth()) { coords.first -= (w - dx) - available; } return 0.0; default: return 0.0; }}voidNotationStaff::setPixmap(NotationElement *elt, QCanvasPixmap *pixmap, int z, FitPolicy policy){ double layoutX = elt->getLayoutX(); int layoutY = (int)elt->getLayoutY(); elt->removeCanvasItem(); while (1) { LinedStaffCoords coords = getCanvasCoordsForLayoutCoords(layoutX, layoutY); double canvasX = coords.first; int canvasY = coords.second; QCanvasItem *item = 0; if (m_pageMode == LinearMode || policy == PretendItFittedAllAlong) { item = new QCanvasNotationSprite(*elt, pixmap, m_canvas); } else { int row = getRowForLayoutX(layoutX); double rightMargin = getCanvasXForRightOfRow(row); double extent = canvasX + pixmap->width(); // NOTATION_DEBUG << "NotationStaff::setPixmap: row " << row << ", right margin " << rightMargin << ", extent " << extent << endl; if (extent > rightMargin + m_notePixmapFactory->getNoteBodyWidth()) { if (policy == SplitToFit) { // NOTATION_DEBUG << "splitting at " << (rightMargin-canvasX) << endl; std::pair<QPixmap, QPixmap> split = PixmapFunctions::splitPixmap(*pixmap, int(rightMargin - canvasX)); QCanvasPixmap *leftCanvasPixmap = new QCanvasPixmap (split.first, QPoint(pixmap->offsetX(), pixmap->offsetY())); QCanvasPixmap *rightCanvasPixmap = new QCanvasPixmap (split.second, QPoint(0, pixmap->offsetY())); item = new QCanvasNotationSprite(*elt, leftCanvasPixmap, m_canvas); item->setZ(z); if (elt->getCanvasItem()) { elt->addCanvasItem(item, canvasX, canvasY); } else { elt->setCanvasItem(item, canvasX, canvasY); } item->show(); delete pixmap; pixmap = rightCanvasPixmap; layoutX += rightMargin - canvasX + 0.01; // ensure flip to next row continue; } else { // policy == MoveBackToFit item = new QCanvasNotationSprite(*elt, pixmap, m_canvas); elt->setLayoutX(elt->getLayoutX() - (extent - rightMargin)); coords = getCanvasCoordsForLayoutCoords(layoutX, layoutY); canvasX = coords.first; } } else { item = new QCanvasNotationSprite(*elt, pixmap, m_canvas); } } item->setZ(z); if (elt->getCanvasItem()) { elt->addCanvasItem(item, canvasX, canvasY); } else { elt->setCanvasItem(item, canvasX, canvasY); } item->show(); break; }}voidNotationStaff::renderNote(ViewElementList::iterator &vli){ NotationElement* elt = static_cast<NotationElement*>(*vli); const NotationProperties &properties(getProperties()); static NotePixmapParameters params(Note::Crotchet, 0); Note::Type note = elt->event()->get <Int>(BaseProperties::NOTE_TYPE); int dots = elt->event()->get <Int>(BaseProperties::NOTE_DOTS); Accidental accidental = Accidentals::NoAccidental; (void)elt->event()->get <String>(properties.DISPLAY_ACCIDENTAL, accidental); bool cautionary = false; if (accidental != Accidentals::NoAccidental) { (void)elt->event()->get <Bool>(properties.DISPLAY_ACCIDENTAL_IS_CAUTIONARY, cautionary); } bool up = true; // (void)(elt->event()->get<Bool>(properties.STEM_UP, up)); (void)(elt->event()->get <Bool>(properties.VIEW_LOCAL_STEM_UP, up)); bool flag = true; (void)(elt->event()->get <Bool>(properties.DRAW_FLAG, flag)); bool beamed = false; (void)(elt->event()->get <Bool>(properties.BEAMED, beamed)); bool shifted = false; (void)(elt->event()->get <Bool>(properties.NOTE_HEAD_SHIFTED, shifted)); bool dotShifted = false; (void)(elt->event()->get <Bool>(properties.NOTE_DOT_SHIFTED, dotShifted)); long stemLength = m_notePixmapFactory->getNoteBodyHeight(); (void)(elt->event()->get <Int>(properties.UNBEAMED_STEM_LENGTH, stemLength)); long heightOnStaff = 0; int legerLines = 0; (void)(elt->event()->get <Int>(properties.HEIGHT_ON_STAFF, heightOnStaff)); if (heightOnStaff < 0) { legerLines = heightOnStaff; } else if (heightOnStaff > 8) { legerLines = heightOnStaff - 8; } long slashes = 0; (void)(elt->event()->get <Int>(properties.SLASHES, slashes)); bool quantized = false; if (m_colourQuantize && !elt->isTuplet()) { quantized = (elt->getViewAbsoluteTime() != elt->event()->getAbsoluteTime() || elt->getViewDuration() != elt->event()->getDuration()); } params.setQuantized(quantized); bool trigger = false; if (elt->event()->has(BaseProperties::TRIGGER_SEGMENT_ID)) trigger = true; params.setTrigger(trigger); bool inRange = true; Pitch p(*elt->event()); Segment *segment = &getSegment(); if (m_showRanges) { int pitch = p.getPerformancePitch(); if (pitch > segment->getHighestPlayable() || pitch < segment->getLowestPlayable()) { inRange = false; } } params.setInRange(inRange); params.setNoteType(note); params.setDots(dots); params.setAccidental(accidental); params.setAccidentalCautionary(cautionary); params.setNoteHeadShifted(shifted); params.setNoteDotShifted(dotShifted); params.setDrawFlag(flag); params.setDrawStem(true); params.setStemGoesUp(up); params.setLegerLines(legerLines); params.setSlashes(slashes); params.setBeamed(false); params.setIsOnLine(heightOnStaff % 2 == 0); params.removeMarks(); params.setSafeVertDistance(0); bool primary = false; int safeVertDistance = 0; if (elt->event()->get <Bool>(properties.CHORD_PRIMARY_NOTE, primary) && primary) { long marks = 0; elt->event()->get <Int>(properties.CHORD_MARK_COUNT, marks);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -