📄 temporuler.cpp
字号:
for (int tempoNo = m_composition->getTempoChangeNumberAt(from); tempoNo <= m_composition->getTempoChangeNumberAt(to) + 1; ++tempoNo) { if (tempoNo >= 0 && tempoNo < m_composition->getTempoChangeCount()) { timePoints.insert (TimePoints::value_type (m_composition->getTempoChange(tempoNo).first, tempoChangeHere)); } } for (int sigNo = m_composition->getTimeSignatureNumberAt(from); sigNo <= m_composition->getTimeSignatureNumberAt(to) + 1; ++sigNo) { if (sigNo >= 0 && sigNo < m_composition->getTimeSignatureCount()) { timeT time(m_composition->getTimeSignatureChange(sigNo).first); if (timePoints.find(time) != timePoints.end()) { timePoints[time] |= timeSigChangeHere; } else { timePoints.insert(TimePoints::value_type(time, timeSigChangeHere)); } } } int lastx = 0, lasty = 0, lastx1 = 0; bool haveSome = false; // tempoT minTempo = m_composition->getMinTempo(); // tempoT maxTempo = m_composition->getMaxTempo(); bool illuminate = false; if (m_illuminate >= 0) { int tcn = m_composition->getTempoChangeNumberAt(from); illuminate = (m_illuminate == tcn); } for (TimePoints::iterator i = timePoints.begin(); ; ++i) { timeT t0, t1; if (i == timePoints.begin()) { t0 = from; } else { TimePoints::iterator j(i); --j; t0 = j->first; } if (i == timePoints.end()) { t1 = to; } else { t1 = i->first; } if (t1 <= t0) t1 = to; int tcn = m_composition->getTempoChangeNumberAt(t0); tempoT tempo = m_composition->getTempoAtTime(t0); std::pair<bool, tempoT> ramping(false, tempo); if (tcn > 0 && tcn < m_composition->getTempoChangeCount() + 1) { ramping = m_composition->getTempoRamping(tcn - 1, true); } double x0, x1; x0 = m_rulerScale->getXForTime(t0) + m_currentXOffset + m_xorigin; x1 = m_rulerScale->getXForTime(t1) + m_currentXOffset + m_xorigin; /*!!! if (x0 > e->rect().x()) { paint.fillRect(e->rect().x(), 0, x0 - e->rect().x(), height(), paletteBackgroundColor()); } */ QColor colour = TempoColour::getColour(m_composition->getTempoQpm(tempo)); paint.setPen(colour); paint.setBrush(colour); if (!m_refreshLinesOnly) { // RG_DEBUG << "TempoRuler: draw rect from " << x0 << " to " << x1 << endl; paint.drawRect(int(x0), 0, int(x1 - x0) + 1, height()); } int y = getYForTempo(tempo); /*!!! int drawh = height() - 4; int y = drawh / 2; if (maxTempo > minTempo) { y = drawh - int((double(tempo - minTempo) / double(maxTempo - minTempo)) * drawh + 0.5); } */ y += 2; if (haveSome) { int x = int(x0) + 1; int ry = lasty; bool illuminateLine = (illuminate && !m_illuminatePoint && !m_illuminateTarget); paint.setPen(illuminateLine ? Qt::white : Qt::black); if (ramping.first) { ry = getYForTempo(ramping.second); ry += 2; /*!!! ry = drawh - int((double(ramping.second - minTempo) / double(maxTempo - minTempo)) * drawh + 0.5); */ } paint.drawLine(lastx + 1, lasty, x - 2, ry); if (!illuminateLine && illuminate && m_illuminateTarget) { if (x > lastx) { paint.setPen(Qt::white); paint.drawLine(x - 6, ry - ((ry - lasty) * 6) / (x - lastx), x - 2, ry); } } if (m_illuminate >= 0) { illuminate = (m_illuminate == tcn); } bool illuminatePoint = (illuminate && m_illuminatePoint); paint.setPen(illuminatePoint ? Qt::white : Qt::black); paint.drawRect(x - 1, y - 1, 3, 3); paint.setPen(illuminatePoint ? Qt::black : Qt::white); paint.drawPoint(x, y); } lastx = int(x0) + 1; lastx1 = int(x1) + 1; lasty = y; if (i == timePoints.end()) break; haveSome = true; } if (lastx1 < e->rect().x() + e->rect().width()) { /*!!! paint.fillRect(lastx1, 0, e->rect().x() + e->rect().width() - lastx1, height(), paletteBackgroundColor()); */ } if (haveSome) { bool illuminateLine = (illuminate && !m_illuminatePoint); paint.setPen(illuminateLine ? Qt::white : Qt::black); paint.drawLine(lastx + 1, lasty, width(), lasty); } else if (!m_refreshLinesOnly) { tempoT tempo = m_composition->getTempoAtTime(from); QColor colour = TempoColour::getColour(m_composition->getTempoQpm(tempo)); paint.setPen(colour); paint.setBrush(colour); paint.drawRect(e->rect()); } paint.setPen(Qt::black); paint.setBrush(Qt::black); paint.drawLine(0, 0, width(), 0); for (TimePoints::iterator i = timePoints.begin(); i != timePoints.end(); ++i) { timeT time = i->first; double x = m_rulerScale->getXForTime(time) + m_currentXOffset + m_xorigin; /* paint.drawLine(static_cast<int>(x), height() - (height()/4), static_cast<int>(x), height()); */ if ((i->second & timeSigChangeHere) && !m_refreshLinesOnly) { TimeSignature sig = m_composition->getTimeSignatureAt(time); QString str = QString("%1/%2") .arg(sig.getNumerator()) .arg(sig.getDenominator()); paint.setFont(m_boldFont); paint.drawText(static_cast<int>(x) + 2, m_height - 2, str); } if ((i->second & tempoChangeHere) && !m_refreshLinesOnly) { double tempo = m_composition->getTempoQpm(m_composition->getTempoAtTime(time)); long bpm = long(tempo); // long frac = long(tempo * 100 + 0.001) - 100 * bpm; QString tempoString = QString("%1").arg(bpm); if (tempo == prevTempo) { if (m_small) continue; tempoString = "="; } else if (bpm == prevBpm) { tempoString = (tempo > prevTempo ? "+" : "-"); } else { if (m_small && (bpm != (bpm / 10 * 10))) { if (bpm == prevBpm + 1) tempoString = "+"; else if (bpm == prevBpm - 1) tempoString = "-"; } } prevTempo = tempo; prevBpm = bpm; QRect bounds = m_fontMetrics.boundingRect(tempoString); paint.setFont(m_font); if (time > 0) x -= bounds.width() / 2; // if (x > bounds.width() / 2) x -= bounds.width() / 2; if (prevEndX >= x - 3) x = prevEndX + 3; paint.drawText(static_cast<int>(x), textY, tempoString); prevEndX = x + bounds.width(); } } paint.end(); QPainter dbpaint(this); // dbpaint.drawPixmap(0, 0, m_buffer); dbpaint.drawPixmap(clipRect.x(), clipRect.y(), m_buffer, clipRect.x(), clipRect.y(), clipRect.width(), clipRect.height()); dbpaint.end(); m_refreshLinesOnly = false;}voidTempoRuler::slotInsertTempoHere(){ SnapGrid grid(m_rulerScale); grid.setSnapTime(SnapGrid::SnapToUnit); timeT t = grid.snapX(m_clickX - m_currentXOffset - m_xorigin, SnapGrid::SnapLeft); tempoT tempo = Composition::getTempoForQpm(120.0); int tcn = m_composition->getTempoChangeNumberAt(t); if (tcn >= 0 && tcn < m_composition->getTempoChangeCount()) { std::pair<timeT, tempoT> tc = m_composition->getTempoChange(tcn); if (tc.first == t) return ; tempo = tc.second; } emit changeTempo(t, tempo, -1, TempoDialog::AddTempo);}voidTempoRuler::slotInsertTempoAtPointer(){ timeT t = m_composition->getPosition(); tempoT tempo = Composition::getTempoForQpm(120.0); int tcn = m_composition->getTempoChangeNumberAt(t); if (tcn >= 0 && tcn < m_composition->getTempoChangeCount()) { std::pair<timeT, tempoT> tc = m_composition->getTempoChange(tcn); if (tc.first == t) return ; tempo = tc.second; } emit changeTempo(t, tempo, -1, TempoDialog::AddTempo);}voidTempoRuler::slotDeleteTempoChange(){ timeT t = m_rulerScale->getTimeForX(m_clickX - m_currentXOffset - m_xorigin); emit deleteTempo(t);}voidTempoRuler::slotRampToNext(){ timeT t = m_rulerScale->getTimeForX(m_clickX - m_currentXOffset - m_xorigin); int tcn = m_composition->getTempoChangeNumberAt(t); if (tcn < 0 || tcn >= m_composition->getTempoChangeCount()) return ; std::pair<timeT, tempoT> tc = m_composition->getTempoChange(tcn); emit changeTempo(tc.first, tc.second, 0, TempoDialog::AddTempo);}voidTempoRuler::slotUnramp(){ timeT t = m_rulerScale->getTimeForX(m_clickX - m_currentXOffset - m_xorigin); int tcn = m_composition->getTempoChangeNumberAt(t); if (tcn < 0 || tcn >= m_composition->getTempoChangeCount()) return ; std::pair<timeT, tempoT> tc = m_composition->getTempoChange(tcn); emit changeTempo(tc.first, tc.second, -1, TempoDialog::AddTempo);}voidTempoRuler::slotEditTempo(){ timeT t = m_rulerScale->getTimeForX(m_clickX - m_currentXOffset - m_xorigin); emit editTempo(t);}voidTempoRuler::slotEditTimeSignature(){ timeT t = m_rulerScale->getTimeForX(m_clickX - m_currentXOffset - m_xorigin); emit editTimeSignature(t);}voidTempoRuler::slotEditTempos(){ timeT t = m_rulerScale->getTimeForX(m_clickX - m_currentXOffset - m_xorigin); emit editTempos(t);}voidTempoRuler::createMenu(){ setXMLFile("temporuler.rc"); KXMLGUIFactory* factory = m_parentMainWindow->factory(); factory->addClient(this); QWidget* tmp = factory->container("tempo_ruler_menu", this); m_menu = dynamic_cast<QPopupMenu*>(tmp); if (!m_menu) { RG_DEBUG << "MarkerRuler::createMenu() failed\n"; }}}#include "TempoRuler.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -