📄 notationvlayout.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 <cmath>#include "NotationVLayout.h"#include "misc/Debug.h"#include <klocale.h>#include "base/Composition.h"#include "base/Event.h"#include "base/LayoutEngine.h"#include "base/NotationTypes.h"#include "base/NotationQuantizer.h"#include "base/Staff.h"#include "gui/general/ProgressReporter.h"#include "gui/editors/guitar/Chord.h"#include "NotationChord.h"#include "NotationElement.h"#include "NotationProperties.h"#include "NotationStaff.h"#include "NotePixmapFactory.h"#include <kmessagebox.h>#include <qobject.h>#include <qstring.h>#include <qwidget.h>namespace Rosegarden{using namespace BaseProperties;NotationVLayout::NotationVLayout(Composition *c, NotePixmapFactory *npf, const NotationProperties &properties, QObject* parent, const char* name) : ProgressReporter(parent, name), m_composition(c), m_npf(npf), m_notationQuantizer(c->getNotationQuantizer()), m_properties(properties){ // empty}NotationVLayout::~NotationVLayout(){ // empty}NotationVLayout::SlurList &NotationVLayout::getSlurList(Staff &staff){ SlurListMap::iterator i = m_slurs.find(&staff); if (i == m_slurs.end()) { m_slurs[&staff] = SlurList(); } return m_slurs[&staff];}voidNotationVLayout::reset(){ m_slurs.clear();}voidNotationVLayout::resetStaff(Staff &staff, timeT, timeT){ getSlurList(staff).clear();}voidNotationVLayout::scanStaff(Staff &staffBase, timeT, timeT){ START_TIMING; NotationStaff &staff = dynamic_cast<NotationStaff &>(staffBase); NotationElementList *notes = staff.getViewElementList(); NotationElementList::iterator from = notes->begin(); NotationElementList::iterator to = notes->end(); NotationElementList::iterator i; for (i = from; i != to; ++i) { NotationElement *el = static_cast<NotationElement*>(*i); // Displaced Y will only be used for certain events -- in // particular not for notes, whose y-coord is obviously kind // of meaningful. double displacedY = 0.0; long dyRaw = 0; el->event()->get<Int>(DISPLACED_Y, dyRaw); displacedY = double(dyRaw * m_npf->getLineSpacing()) / 1000.0; el->setLayoutY(staff.getLayoutYForHeight( -9) + displacedY); if (el->isRest()) { // rests for notes longer than the minim have hotspots // aligned with the line above the middle line; the rest // are aligned with the middle line long noteType; bool hasNoteType = el->event()->get <Int>(NOTE_TYPE, noteType); if (hasNoteType && noteType > Note::Minim) { el->setLayoutY(staff.getLayoutYForHeight(6) + displacedY); } else { el->setLayoutY(staff.getLayoutYForHeight(4) + displacedY); } // Fix for bug 1090767 Rests outside staves have wrong glyphs // by William <rosegarden4c AT orthoset.com> // We use a "rest-outside-stave" glyph for any minim/semibreve/breve // rest that has been displaced vertically e.g. by fine-positioning // outside the stave. For small vertical displacements that keep // the rest inside the stave, we use the "rest-inside-stave" glyph // and also discretise the displacement into multiples of the // stave-line spacing. The outside-stave glyphs match the character // numbers 1D13A, 1D13B and 1D13C in the Unicode 4.0 standard. if (hasNoteType && (displacedY > 0.1 || displacedY < -0.1)) { // a fiddly check for transition from inside to outside: int min = -1, max = 1; switch (noteType) { case Note::Breve: min = -1; max = 2; break; case Note::Semibreve: min = -1; max = 3; break; case Note::Minim: min = -2; max = 2; break; case Note::Crotchet: min = -1; max = 3; break; case Note::Quaver: min = -2; max = 3; break; case Note::Semiquaver: min = -3; max = 3; break; case Note::Demisemiquaver: min = -3; max = 4; break; case Note::Hemidemisemiquaver: min = -4; max = 4; break; } bool outside = false; if (noteType == Note::Breve) { if (nearbyint(displacedY) < min * m_npf->getLineSpacing() || nearbyint(displacedY) > max * m_npf->getLineSpacing()) { outside = true; } } else { if ((int)displacedY < min * m_npf->getLineSpacing() || (int)displacedY > max * m_npf->getLineSpacing()) { outside = true; } } el->event()->setMaybe<Bool>(m_properties.REST_OUTSIDE_STAVE, outside); if (!outside) { displacedY = (double)m_npf->getLineSpacing() * (int(nearbyint((double)displacedY / m_npf->getLineSpacing()))); if (noteType > Note::Minim) el->setLayoutY(staff.getLayoutYForHeight(6) + displacedY); else el->setLayoutY(staff.getLayoutYForHeight(4) + displacedY); } // if (displacedY != 0.0) // NOTATION_DEBUG << "REST_OUTSIDE_STAVE AFTER " // << " : displacedY : " << displacedY // << " line-spacing : " << m_npf->getLineSpacing() // << " time : " << (el->getViewAbsoluteTime()) // << endl; } else { el->event()->setMaybe<Bool>(m_properties.REST_OUTSIDE_STAVE, false); } } else if (el->isNote()) { NotationChord chord(*notes, i, m_notationQuantizer, m_properties); if (chord.size() == 0) continue; std::vector<int> h; for (unsigned int j = 0; j < chord.size(); ++j) { long height = 0; if (!(*chord[j])->event()->get <Int> (m_properties.HEIGHT_ON_STAFF, height)) { std::cerr << QString("ERROR: Event in chord at %1 has no HEIGHT_ON_STAFF property!\nThis is a bug (the program would previously have crashed by now)").arg((*chord[j])->getViewAbsoluteTime()) << std::endl; (*chord[j])->event()->dump(std::cerr); } h.push_back(height); } bool stemmed = chord.hasStem(); bool stemUp = chord.hasStemUp(); bool hasNoteHeadShifted = chord.hasNoteHeadShifted(); unsigned int flaggedNote = (stemUp ? chord.size() - 1 : 0); bool hasShifted = chord.hasNoteHeadShifted(); double y0 = -1E50; // A very unlikely Y layout value for (unsigned int j = 0; j < chord.size(); ++j) { el = static_cast<NotationElement*>(*chord[j]); el->setLayoutY(staff.getLayoutYForHeight(h[j])); // Look for collision const double eps = 0.001; Event *eel = el->event(); double y = el->getLayoutY(); if (eel->has("pitch")) { el->setIsColliding(fabs(y - y0) < eps); y0 = y; } // These calculations and assignments are pretty much final // if the chord is not in a beamed group, but if it is then // they will be reworked by NotationGroup::applyBeam, which // is called from NotationHLayout::layout, which is called // after this. Any inaccuracies here for beamed groups // should be stamped out there. // el->event()->setMaybe<Bool>(STEM_UP, stemUp); el->event()->setMaybe<Bool>(m_properties.VIEW_LOCAL_STEM_UP, stemUp); bool primary = ((stemmed && stemUp) ? (j == 0) : (j == chord.size() - 1)); el->event()->setMaybe<Bool> (m_properties.CHORD_PRIMARY_NOTE, primary); if (primary) { el->event()->setMaybe<Int> (m_properties.CHORD_MARK_COUNT, chord.getMarkCountForChord()); } bool shifted = chord.isNoteHeadShifted(chord[j]); el->event()->setMaybe<Bool> (m_properties.NOTE_HEAD_SHIFTED, shifted); el->event()->setMaybe<Bool> (m_properties.NOTE_DOT_SHIFTED, false); if (hasShifted && stemUp) { long dots = 0; (void)el->event()->get <Int>(NOTE_DOTS, dots); if (dots > 0) { el->event()->setMaybe<Bool> (m_properties.NOTE_DOT_SHIFTED, true); } } el->event()->setMaybe<Bool> (m_properties.NEEDS_EXTRA_SHIFT_SPACE, hasNoteHeadShifted && !stemUp); el->event()->setMaybe<Bool> (m_properties.DRAW_FLAG, j == flaggedNote); int stemLength = -1; if (j != flaggedNote) { stemLength = staff.getLayoutYForHeight(h[flaggedNote]) - staff.getLayoutYForHeight(h[j]); if (stemLength < 0) stemLength = -stemLength; // NOTATION_DEBUG << "Setting stem length to " // << stemLength << endl; } else { int minStemLength = stemLength; if (h[j] < -2 && stemUp) { //!!! needs tuning, & applying for beamed stems too minStemLength = staff.getLayoutYForHeight(h[j]) - staff.getLayoutYForHeight(4); } else if (h[j] > 10 && !stemUp) { minStemLength = staff.getLayoutYForHeight(4) - staff.getLayoutYForHeight(h[j]); } stemLength = std::max(minStemLength, stemLength); } el->event()->setMaybe<Int> (m_properties.UNBEAMED_STEM_LENGTH, stemLength); } // #938545 (Broken notation: Duplicated note can float // outside stave) -- Need to cope with the case where a // note that's not a member of a chord (different stem // direction &c) falls between notes that are members. // Not optimal, as we can end up scanning the chord // multiple times (we'll return to it after scanning the // contained note). [We can't just iterate over all // elements within the chord (as we can in hlayout) // because we need them in height order.] i = chord.getFirstElementNotInChord(); if (i == notes->end()) i = chord.getFinalElement(); else --i; } else { if (el->event()->isa(Clef::EventType)) { // clef pixmaps have the hotspot placed to coincide // with the pitch of the clef -- so the alto clef // should be "on" the middle line, the treble clef // "on" the line below the middle, etc el->setLayoutY(staff.getLayoutYForHeight (Clef(*el->event()).getAxisHeight())); } else if (el->event()->isa(Rosegarden::Key::EventType)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -