📄 notationhlayout.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 "NotationHLayout.h"#include "misc/Debug.h"#include <kapplication.h>#include "base/Composition.h"#include "base/LayoutEngine.h"#include "base/NotationTypes.h"#include "base/Profiler.h"#include "base/NotationQuantizer.h"#include "base/RulerScale.h"#include "base/Segment.h"#include "base/SegmentNotationHelper.h"#include "base/Staff.h"#include "base/ViewElement.h"#include "gui/editors/guitar/Chord.h"#include "gui/general/ProgressReporter.h"#include "gui/widgets/ProgressDialog.h"#include "NotationChord.h"#include "NotationElement.h"#include "NotationGroup.h"#include "NotationProperties.h"#include "NotationStaff.h"#include "NotePixmapFactory.h"#include <kconfig.h>#include <qobject.h>#include <cmath>namespace Rosegarden{using namespace BaseProperties;NotationHLayout::NotationHLayout(Composition *c, NotePixmapFactory *npf, const NotationProperties &properties, QObject* parent, const char* name) : ProgressReporter(parent, name), HorizontalLayoutEngine(c), m_totalWidth(0.), m_pageMode(false), m_pageWidth(0.), m_spacing(100), m_proportion(60), m_npf(npf), m_notationQuantizer(c->getNotationQuantizer()), m_properties(properties), m_timePerProgressIncrement(0), m_staffCount(0){ // NOTATION_DEBUG << "NotationHLayout::NotationHLayout()" << endl; KConfig *config = kapp->config(); config->setGroup("Notation Options"); m_keySigCancelMode = config->readNumEntry("keysigcancelmode", 1);}NotationHLayout::~NotationHLayout(){ // empty}std::vector<int>NotationHLayout::getAvailableSpacings(){ if (m_availableSpacings.size() == 0) { m_availableSpacings.push_back(30); m_availableSpacings.push_back(60); m_availableSpacings.push_back(85); m_availableSpacings.push_back(100); m_availableSpacings.push_back(130); m_availableSpacings.push_back(170); m_availableSpacings.push_back(220); } return m_availableSpacings;}std::vector<int>NotationHLayout::getAvailableProportions(){ if (m_availableProportions.size() == 0) { m_availableProportions.push_back(0); m_availableProportions.push_back(20); m_availableProportions.push_back(40); m_availableProportions.push_back(60); m_availableProportions.push_back(80); m_availableProportions.push_back(100); } return m_availableProportions;}NotationHLayout::BarDataList &NotationHLayout::getBarData(Staff &staff){ BarDataMap::iterator i = m_barData.find(&staff); if (i == m_barData.end()) { m_barData[&staff] = BarDataList(); } return m_barData[&staff];}const NotationHLayout::BarDataList &NotationHLayout::getBarData(Staff &staff) const{ return ((NotationHLayout *)this)->getBarData(staff);}NotationElementList::iteratorNotationHLayout::getStartOfQuantizedSlice(NotationElementList *notes, timeT t)const{ NotationElementList::iterator i = notes->findTime(t); NotationElementList::iterator j(i); while (true) { if (i == notes->begin()) return i; --j; if ((*j)->getViewAbsoluteTime() < t) return i; i = j; }}voidNotationHLayout::scanStaff(Staff &staff, timeT startTime, timeT endTime){ throwIfCancelled(); Profiler profiler("NotationHLayout::scanStaff"); Segment &segment(staff.getSegment()); bool isFullScan = (startTime == endTime); int startBarOfStaff = getComposition()->getBarNumber(segment.getStartTime()); if (isFullScan) { clearBarList(staff); startTime = segment.getStartTime(); endTime = segment.getEndMarkerTime(); } else { startTime = getComposition()->getBarStartForTime(startTime); endTime = getComposition()->getBarEndForTime(endTime); } NotationElementList *notes = staff.getViewElementList(); BarDataList &barList(getBarData(staff)); int startBarNo = getComposition()->getBarNumber(startTime); int endBarNo = getComposition()->getBarNumber(endTime); /* if (endBarNo > startBarNo && getComposition()->getBarStart(endBarNo) == segment.getEndMarkerTime()) { --endBarNo; } */ std::string name = segment.getComposition()-> getTrackById(segment.getTrack())->getLabel(); m_staffNameWidths[&staff] = m_npf->getNoteBodyWidth() * 2 + m_npf->getTextWidth(Text(name, Text::StaffName)); NOTATION_DEBUG << "NotationHLayout::scanStaff: full scan " << isFullScan << ", times " << startTime << "->" << endTime << ", bars " << startBarNo << "->" << endBarNo << ", staff name \"" << segment.getLabel() << "\", width " << m_staffNameWidths[&staff] << endl; SegmentNotationHelper helper(segment); if (isFullScan) { helper.setNotationProperties(); } else { helper.setNotationProperties(startTime, endTime); } ::Rosegarden::Key key = segment.getKeyAtTime(startTime); Clef clef = segment.getClefAtTime(startTime); TimeSignature timeSignature = segment.getComposition()->getTimeSignatureAt(startTime); bool barCorrect = true; int ottavaShift = 0; timeT ottavaEnd = segment.getEndMarkerTime(); if (isFullScan) { NOTATION_DEBUG << "full scan: setting haveOttava false" << endl; m_haveOttavaSomewhere[&staff] = false; } else if (m_haveOttavaSomewhere[&staff]) { NOTATION_DEBUG << "not full scan but ottava is listed" << endl; Segment::iterator i = segment.findTime(startTime); while (1) { if ((*i)->isa(Indication::EventType)) { try { Indication indication(**i); if (indication.isOttavaType()) { ottavaShift = indication.getOttavaShift(); ottavaEnd = (*i)->getAbsoluteTime() + indication.getIndicationDuration(); break; } } catch (...) { } } if (i == segment.begin()) break; --i; } } NOTATION_DEBUG << "ottava shift at start:" << ottavaShift << ", ottavaEnd " << ottavaEnd << endl; KConfig *config = kapp->config(); config->setGroup("Notation Options"); int accOctaveMode = config->readNumEntry("accidentaloctavemode", 1); AccidentalTable::OctaveType octaveType = (accOctaveMode == 0 ? AccidentalTable::OctavesIndependent : accOctaveMode == 1 ? AccidentalTable::OctavesCautionary : AccidentalTable::OctavesEquivalent); int accBarMode = config->readNumEntry("accidentalbarmode", 0); AccidentalTable::BarResetType barResetType = (accBarMode == 0 ? AccidentalTable::BarResetNone : accBarMode == 1 ? AccidentalTable::BarResetCautionary : AccidentalTable::BarResetExplicit); bool showInvisibles = config->readBoolEntry("showinvisibles", true); if (barResetType != AccidentalTable::BarResetNone) { //!!! very crude and expensive way of making sure we see the // accidentals from previous bar: if (startBarNo > segment.getComposition()->getBarNumber(segment.getStartTime())) { --startBarNo; } } AccidentalTable accTable(key, clef, octaveType, barResetType); for (int barNo = startBarNo; barNo <= endBarNo; ++barNo) { std::pair<timeT, timeT> barTimes = getComposition()->getBarRange(barNo); if (barTimes.first >= segment.getEndMarkerTime()) { // clear data if we have any old stuff BarDataList::iterator i(barList.find(barNo)); if (i != barList.end()) { barList.erase(i); } continue; // so as to erase any further bars next time around } NotationElementList::iterator from = getStartOfQuantizedSlice(notes, barTimes.first); NOTATION_DEBUG << "getStartOfQuantizedSlice returned " << (from != notes->end() ? (*from)->getViewAbsoluteTime() : -1) << " from " << barTimes.first << endl; NotationElementList::iterator to = getStartOfQuantizedSlice(notes, barTimes.second); if (barTimes.second >= segment.getEndMarkerTime()) { to = notes->end(); } bool newTimeSig = false; timeSignature = getComposition()->getTimeSignatureInBar (barNo, newTimeSig); NOTATION_DEBUG << "bar " << barNo << ", startBarOfStaff " << startBarOfStaff << ", newTimeSig " << newTimeSig << endl; if (barNo == startBarOfStaff) newTimeSig = true; float fixedWidth = 0.0; if (newTimeSig && !timeSignature.isHidden()) { fixedWidth += m_npf->getNoteBodyWidth() + m_npf->getTimeSigWidth(timeSignature); } setBarBasicData(staff, barNo, from, barCorrect, timeSignature, newTimeSig); BarDataList::iterator bdli(barList.find(barNo)); bdli->second.layoutData.needsLayout = true; ChunkList &chunks = bdli->second.chunks; chunks.clear(); float lyricWidth = 0; int graceCount = 0; typedef std::set <long> GroupIdSet; GroupIdSet groupIds; NOTATION_DEBUG << "NotationHLayout::scanStaff: bar " << barNo << ", from " << barTimes.first << ", to " << barTimes.second << " (end " << segment.getEndMarkerTime() << "); from is at " << (from == notes->end() ? -1 : (*from)->getViewAbsoluteTime()) << ", to is at " << (to == notes->end() ? -1 : (*to)->getViewAbsoluteTime()) << endl; timeT actualBarEnd = barTimes.first; accTable.newBar(); for (NotationElementList::iterator itr = from; itr != to; ++itr) { NotationElement *el = static_cast<NotationElement*>((*itr)); NOTATION_DEBUG << "element is a " << el->event()->getType() << endl; if (ottavaShift != 0) { if (el->event()->getAbsoluteTime() >= ottavaEnd) { NOTATION_DEBUG << "reached end of ottava" << endl; ottavaShift = 0; } } bool invisible = false; if (el->event()->get<Bool>(INVISIBLE, invisible) && invisible) { if (!showInvisibles) continue; } if (el->event()->has(BEAMED_GROUP_ID)) { NOTATION_DEBUG << "element is beamed" << endl; long groupId = el->event()->get<Int>(BEAMED_GROUP_ID); if (groupIds.find(groupId) == groupIds.end()) { NOTATION_DEBUG << "it's a new beamed group, applying stem properties" << endl; NotationGroup group(*staff.getViewElementList(), itr, m_notationQuantizer, barTimes, m_properties, clef, key); group.applyStemProperties(); groupIds.insert(groupId); } } if (el->event()->isa(Clef::EventType)) { // NOTATION_DEBUG << "Found clef" << endl; chunks.push_back(Chunk(el->event()->getSubOrdering(), getLayoutWidth(*el, key))); clef = Clef(*el->event()); accTable.newClef(clef); } else if (el->event()->isa(::Rosegarden::Key::EventType)) { // NOTATION_DEBUG << "Found key" << endl; chunks.push_back(Chunk(el->event()->getSubOrdering(), getLayoutWidth(*el, key))); key = ::Rosegarden::Key(*el->event()); accTable = AccidentalTable (key, clef, octaveType, barResetType); } else if (el->event()->isa(Text::EventType)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -