📄 rawnoteruler.cpp
字号:
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: *//* Rosegarden A MIDI and audio sequencer and musical notation editor. This program is Copyright 2000-2007 Guillaume Laurent <glaurent@telegraph-road.org>, Chris Cannam <cannam@all-day-breakfast.com>, Richard Bown <richard.bown@ferventsoftware.com> The moral rights of Guillaume Laurent, Chris Cannam, and Richard Bown to claim authorship of this work have been asserted. Other copyrights also apply to some parts of this work. Please see the AUTHORS file and individual file headers for details. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information.*/#include "RawNoteRuler.h"#include "misc/Debug.h"#include "base/BaseProperties.h"#include "base/Composition.h"#include "base/NotationTypes.h"#include "base/NotationQuantizer.h"#include "base/RulerScale.h"#include "base/Segment.h"#include "DefaultVelocityColour.h"#include "gui/general/GUIPalette.h"#include <klocale.h>#include <qcolor.h>#include <qpainter.h>#include <qrect.h>#include <qsize.h>#include <qtooltip.h>#include <qwidget.h>namespace Rosegarden{RawNoteRuler::RawNoteRuler(RulerScale *rulerScale, Segment *segment, double xorigin, int height, QWidget *parent, const char *name) : QWidget(parent, name), m_xorigin(xorigin), m_height(height), m_currentXOffset(0), m_width( -1), m_segment(segment), m_rulerScale(rulerScale){ setBackgroundColor(GUIPalette::getColour(GUIPalette::RawNoteRulerBackground)); QToolTip::add(this,"");}RawNoteRuler::~RawNoteRuler(){ QToolTip::remove(this); // nothing else}voidRawNoteRuler::slotScrollHoriz(int x){ int w = width(), h = height(); int dx = x - ( -m_currentXOffset); if (dx == 0) return ; m_currentXOffset = -x; if (dx > w*3 / 4 || dx < -w*3 / 4) { update(); return ; } if (dx > 0) { // moving right, so the existing stuff moves left bitBlt(this, 0, 0, this, dx, 0, w - dx, h); repaint(w - dx, 0, dx, h); } else { // moving left, so the existing stuff moves right bitBlt(this, -dx, 0, this, 0, 0, w + dx, h); repaint(0, 0, -dx, h); }}QSizeRawNoteRuler::sizeHint() const{ double width = m_rulerScale->getBarPosition(m_rulerScale->getLastVisibleBar()) + m_rulerScale->getBarWidth(m_rulerScale->getLastVisibleBar()) + m_xorigin; QSize res(std::max(int(width), m_width), m_height); return res;}QSizeRawNoteRuler::minimumSizeHint() const{ double firstBarWidth = m_rulerScale->getBarWidth(0) + m_xorigin; QSize res = QSize(int(firstBarWidth), m_height); return res;}std::pair<timeT, timeT>RawNoteRuler::getExtents(Segment::iterator i){ const Quantizer *q = m_segment->getComposition()->getNotationQuantizer(); timeT u0 = (*i)->getAbsoluteTime(); timeT u1 = u0 + (*i)->getDuration(); timeT q0 = q->getQuantizedAbsoluteTime(*i); timeT q1 = q0 + q->getQuantizedDuration(*i); timeT t0 = std::min(u0, q0); timeT t1 = std::max(u1, q1); return std::pair<timeT, timeT>(t0, t1);}Segment::iteratorRawNoteRuler::addChildren(Segment *s, Segment::iterator to, timeT rightBound, EventTreeNode *node){ Segment::iterator i = node->node; std::pair<timeT, timeT> iex = getExtents(i); Segment::iterator j = i; Segment::iterator rightmost = to;#ifdef DEBUG_RAW_NOTE_RULER RG_DEBUG << "addChildren called for extents " << iex.first << "->" << iex.second << ", rightBound " << rightBound << endl;#endif for (++j; j != to && s->isBeforeEndMarker(j); ) { if (!(*j)->isa(Note::EventType)) { ++j; continue; } std::pair<timeT, timeT> jex = getExtents(j);#ifdef DEBUG_RAW_NOTE_RULER RG_DEBUG << "addChildren: event at " << (*j)->getAbsoluteTime() << ", extents " << jex.first << "->" << jex.second << endl;#endif if (jex.first == jex.second) { ++j; continue; } if (jex.first >= iex.second || jex.first >= rightBound) break;#ifdef DEBUG_RAW_NOTE_RULER RG_DEBUG << "addChildren: adding" << endl;#endif EventTreeNode *subnode = new EventTreeNode(j); Segment::iterator subRightmost = addChildren(s, to, rightBound, subnode); if (subRightmost != to) rightmost = subRightmost; else rightmost = j; node->children.push_back(subnode); j = s->findTime(jex.second); } return rightmost;}voidRawNoteRuler::buildForest(Segment *s, Segment::iterator from, Segment::iterator to){ for (EventTreeNode::NodeList::iterator i = m_forest.begin(); i != m_forest.end(); ++i) { delete *i; } m_forest.clear(); timeT endTime = (s->isBeforeEndMarker(to) ? (*to)->getAbsoluteTime() : s->getEndMarkerTime()); for (Segment::iterator i = from; i != to && s->isBeforeEndMarker(i); ) { if (!(*i)->isa(Note::EventType)) { ++i; continue; } std::pair<timeT, timeT> iex = getExtents(i);#ifdef DEBUG_RAW_NOTE_RULER RG_DEBUG << "buildForest: event at " << (*i)->getAbsoluteTime() << ", extents " << iex.first << "->" << iex.second << endl;#endif if (iex.first == iex.second) { ++i; continue; } if (iex.first >= endTime) break; EventTreeNode *node = new EventTreeNode(i); Segment::iterator rightmost = addChildren(s, to, iex.second, node); m_forest.push_back(node); if (rightmost != to) { i = rightmost; ++i; } else { i = s->findTime(iex.second); }#ifdef DEBUG_RAW_NOTE_RULER RG_DEBUG << "findTime " << iex.second << " returned iterator at " << (i == s->end() ? -1 : (*i)->getAbsoluteTime()) << endl;#endif }}voidRawNoteRuler::dumpSubtree(EventTreeNode *node, int depth){ if (!node) return ;#ifdef DEBUG_RAW_NOTE_RULER for (int i = 0; i < depth; ++i) std::cerr << " "; if (depth > 0) std::cerr << "->"; std::cerr << (*node->node)->getAbsoluteTime() << "," << (*node->node)->getDuration() << " ["; long pitch = 0; if ((*node->node)->get <Int>(PITCH, pitch)) { std::cerr << pitch << "]" << std::endl; } else { std::cerr << "no-pitch]" << std::endl; } for (EventTreeNode::NodeList::iterator i = node->children.begin(); i != node->children.end(); ++i) { dumpSubtree(*i, depth + 1); }#endif (void)depth; // avoid warnings}voidRawNoteRuler::dumpForest(EventTreeNode::NodeList *forest){#ifdef DEBUG_RAW_NOTE_RULER std::cerr << "\nFOREST:\n" << std::endl; for (unsigned int i = 0; i < forest->size(); ++i) { std::cerr << "\nTREE " << i << ":\n" << std::endl; dumpSubtree((*forest)[i], 0); } std::cerr << std::endl;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -