📄 rawnoteruler.cpp
字号:
(void)forest; // avoid warnings}intRawNoteRuler::EventTreeNode::getDepth(){ int subchildrenDepth = 0; for (NodeList::iterator i = children.begin(); i != children.end(); ++i) { int subchildDepth = (*i)->getDepth(); if (subchildDepth > subchildrenDepth) subchildrenDepth = subchildDepth; } return subchildrenDepth + 1;}intRawNoteRuler::EventTreeNode::getChildrenAboveOrBelow(bool below, int p){ long pitch(p); if (pitch < 0) (*node)->get <Int>(BaseProperties::PITCH, pitch); int max = 0; for (NodeList::iterator i = children.begin(); i != children.end(); ++i) { int forThisChild = (*i)->getChildrenAboveOrBelow(below, pitch); long thisChildPitch = pitch; (*(*i)->node)->get <Int>(BaseProperties::PITCH, thisChildPitch); if (below ? (thisChildPitch < pitch) : (thisChildPitch > pitch)) { ++forThisChild; } if (forThisChild > max) max = forThisChild; } return max;}voidRawNoteRuler::drawNode(QPainter &paint, DefaultVelocityColour &vc, EventTreeNode *node, double height, double yorigin){ int depth = node->getDepth(); int above = node->getChildrenAboveOrBelow(false);#ifdef DEBUG_RAW_NOTE_RULER int below = node->getChildrenAboveOrBelow(true); NOTATION_DEBUG << "RawNoteRuler::drawNode: children above: " << above << ", below: " << below << endl;#endif int toFit = depth; double heightPer = double(height) / toFit; if (heightPer > m_height / 4) heightPer = m_height / 4; if (heightPer < 2) heightPer = 2; double myOrigin = yorigin + (heightPer * above); long myPitch = 60; (*node->node)->get <Int>(BaseProperties::PITCH, myPitch); long velocity = 100; (*node->node)->get <Int>(BaseProperties::VELOCITY, velocity); QColor colour = vc.getColour(velocity); timeT start = (*node->node)->getAbsoluteTime(); timeT end = (*node->node)->getDuration() + start; double u0 = m_rulerScale->getXForTime(start); double u1 = m_rulerScale->getXForTime(end); u0 += m_currentXOffset + m_xorigin; u1 += m_currentXOffset + m_xorigin; start = m_segment->getComposition()->getNotationQuantizer()-> getQuantizedAbsoluteTime(*node->node); end = start + m_segment->getComposition()->getNotationQuantizer()-> getQuantizedDuration(*node->node); double q0 = m_rulerScale->getXForTime(start); double q1 = m_rulerScale->getXForTime(end); q0 += m_currentXOffset + m_xorigin; q1 += m_currentXOffset + m_xorigin;#ifdef DEBUG_RAW_NOTE_RULER NOTATION_DEBUG << "RawNoteRuler: (" << int(start) << "," << myOrigin << ") -> (" << int(end) << "," << myOrigin << ")" << endl;#endif int qi0 = int(q0); int ui0 = int(u0); int qi1 = int(q1); int ui1 = int(u1); // int qiw = int(q1-q0) - 1; int uiw = int(u1 - u0) - 1; // int iy = int(myOrigin + (height - heightPer) / 2); int iy = int(myOrigin); int ih = int(heightPer);#ifdef DEBUG_RAW_NOTE_RULER NOTATION_DEBUG << "RawNoteRuler: height " << height << ", heightPer " << heightPer << ", iy " << iy << endl;#endif paint.setPen(colour); paint.setBrush(colour); paint.drawRect(ui0 + 1, iy + 1, uiw, ih - 1); paint.setPen(GUIPalette::getColour(GUIPalette::RawNoteRulerForeground)); paint.setBrush(GUIPalette::getColour(GUIPalette::RawNoteRulerForeground)); paint.drawLine(qi0, iy, qi1 - 1, iy); paint.drawLine(qi0, iy + ih, qi1 - 1, iy + ih); paint.drawLine(ui0, iy + 1, ui0, iy + ih - 1); paint.drawLine(ui1 - 1, iy + 1, ui1 - 1, iy + ih - 1); for (EventTreeNode::NodeList::iterator i = node->children.begin(); i != node->children.end(); ++i) { long nodePitch = myPitch; (*(*i)->node)->get <Int>(BaseProperties::PITCH, nodePitch); if (nodePitch < myPitch) { drawNode(paint, vc, *i, height - heightPer - myOrigin, myOrigin + heightPer); } else { drawNode(paint, vc, *i, myOrigin - yorigin, yorigin); } }}voidRawNoteRuler::paintEvent(QPaintEvent* e){ if (!m_segment || !m_segment->getComposition()) return ; // Tooltips { QToolTip::remove(this); TrackId trackId = m_segment->getTrack(); Track *track = m_segment->getComposition()->getTrackById(trackId); int trackPosition = -1; if (track) trackPosition = track->getPosition(); QToolTip::add(this,i18n("Track #%1, Segment \"%2\" (runtime id %3)") .arg(trackPosition + 1) .arg(m_segment->getLabel()) .arg(m_segment->getRuntimeId())); } // START_TIMING; QPainter paint(this); paint.setClipRegion(e->region()); paint.setClipRect(e->rect().normalize()); QRect clipRect = paint.clipRegion().boundingRect(); timeT from = m_rulerScale->getTimeForX (clipRect.x() - m_currentXOffset - 100 - m_xorigin); timeT to = m_rulerScale->getTimeForX (clipRect.x() + clipRect.width() - m_currentXOffset + 100 - m_xorigin); paint.setPen(GUIPalette::getColour(GUIPalette::RawNoteRulerForeground)); paint.setBrush(GUIPalette::getColour(GUIPalette::RawNoteRulerForeground)); paint.drawLine(0, 0, width(), 0); // draw the extent of the segment using its color QColor brushColor = GUIPalette::convertColour(m_segment->getComposition()-> getSegmentColourMap().getColourByIndex(m_segment->getColourIndex())); paint.setPen(brushColor); paint.setBrush(brushColor); int x0 = int(m_rulerScale->getXForTime(m_segment->getStartTime()) + m_currentXOffset + m_xorigin); int x1 = int(m_rulerScale->getXForTime(m_segment->getEndTime()) + m_currentXOffset + m_xorigin); paint.drawRect(x0, 1, x1-x0+1, height()-1); // draw the bar divisions int firstBar = m_segment->getComposition()->getBarNumber(from); int lastBar = m_segment->getComposition()->getBarNumber(to); std::vector<int> divisions; for (int barNo = firstBar; barNo <= lastBar; ++barNo) { bool isNew = false; TimeSignature timeSig = m_segment->getComposition()->getTimeSignatureInBar(barNo, isNew); if (isNew || barNo == firstBar) { timeSig.getDivisions(3, divisions); if (timeSig == TimeSignature()) // special case for 4/4 divisions[0] = 2; } timeT barStart = m_segment->getComposition()->getBarStart(barNo); timeT base = timeSig.getBarDuration(); timeT barEnd = barStart + base; paint.setPen(GUIPalette::getColour(GUIPalette::RawNoteRulerForeground)); paint.setBrush(GUIPalette::getColour(GUIPalette::RawNoteRulerForeground)); int x = int(m_rulerScale->getXForTime(barStart) + m_currentXOffset + m_xorigin); paint.drawLine(x, 1, x, m_height); for (int depth = 0; depth < 3; ++depth) { int grey = depth * 60 + 60; paint.setPen(QColor(grey, grey, grey)); paint.setBrush(QColor(grey, grey, grey)); base /= divisions[depth]; timeT t(barStart + base); while (t < barEnd) { if ((t - barStart) % (base * divisions[depth]) != 0) { int x = int(m_rulerScale->getXForTime(t) + m_currentXOffset + m_xorigin); paint.drawLine(x, 1, x, m_height); } t += base; } } } // PRINT_ELAPSED("RawNoteRuler::paintEvent: drawing bar lines and divisions");#ifdef DEBUG_RAW_NOTE_RULER NOTATION_DEBUG << "RawNoteRuler: from is " << from << ", to is " << to << endl;#endif Segment::iterator i = m_segment->findNearestTime(from); if (i == m_segment->end()) i = m_segment->begin(); // somewhat experimental, as is this whole class Segment::iterator j = m_segment->findTime(to); buildForest(m_segment, i, j); // PRINT_ELAPSED("RawNoteRuler::paintEvent: buildForest"); dumpForest(&m_forest); // PRINT_ELAPSED("RawNoteRuler::paintEvent: dumpForest"); for (EventTreeNode::NodeList::iterator fi = m_forest.begin(); fi != m_forest.end(); ++fi) { // Each tree in the forest should represent a note that starts // at a time when no other notes are playing (at least of // those that started no earlier than the paint start time). // Each node in that tree represents a note that starts // playing during its parent node's note, or at the same time // as it. drawNode(paint, *DefaultVelocityColour::getInstance(), *fi, m_height - 3, 2); } // PRINT_ELAPSED("RawNoteRuler::paintEvent: complete");}}#include "RawNoteRuler.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -