📄 notationgroup.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 "NotationGroup.h"#include "misc/Debug.h"#include "base/Equation.h"#include "base/Event.h"#include "base/NotationTypes.h"#include "base/Quantizer.h"#include "NotationChord.h"#include "NotationElement.h"#include "NotationProperties.h"#include "NotationStaff.h"#include "NoteStyleFactory.h"#include "NotePixmapFactory.h"namespace Rosegarden{NotationGroup::NotationGroup(NotationElementList &nel, NELIterator i, const Quantizer *q, std::pair<timeT, timeT> barRange, const NotationProperties &p, const Clef &clef, const Key &key) : AbstractSet<NotationElement, NotationElementList>(nel, i, q), m_barRange(barRange), //!!! What if the clef and/or key change in the course of the group? m_clef(clef), m_key(key), m_weightAbove(0), m_weightBelow(0), m_userSamples(false), m_type(Beamed), m_properties(p){ if (!(*i)->event()->get <Int> (BaseProperties::BEAMED_GROUP_ID, m_groupNo)) m_groupNo = -1; initialise(); /* NOTATION_DEBUG << "NotationGroup::NotationGroup: id is " << m_groupNo << endl; i = getInitialElement(); while (i != getContainer().end()) { long gid = -1; (*i)->event()->get<Int>(BEAMED_GROUP_ID, gid); NOTATION_DEBUG << "Found element with group id " << gid << endl; if (i == getFinalElement()) break; ++i; } */}NotationGroup::NotationGroup(NotationElementList &nel, const Quantizer *q, const NotationProperties &p, const Clef &clef, const Key &key) : AbstractSet<NotationElement, NotationElementList>(nel, nel.end(), q), m_barRange(0, 0), //!!! What if the clef and/or key change in the course of the group? m_clef(clef), m_key(key), m_weightAbove(0), m_weightBelow(0), m_userSamples(true), m_groupNo( -1), m_type(Beamed), m_properties(p){ //...}NotationGroup::~NotationGroup(){}bool NotationGroup::test(const NELIterator &i){ // An event is a candidate for being within the bounds of the // set if it's simply within the same bar as the original event. // (Groups may contain other groups, so our bounds may enclose // events that aren't members of the group: we reject those in // sample rather than test, so as to avoid erroneously ending // the group too soon.) return ((*i)->getViewAbsoluteTime() >= m_barRange.first && (*i)->getViewAbsoluteTime() < m_barRange.second);}boolNotationGroup::sample(const NELIterator &i, bool goingForwards){ if (m_baseIterator == getContainer().end()) { m_baseIterator = i; if (m_userSamples) m_initial = i; } if (m_userSamples) m_final = i; std::string t; if (!(*i)->event()->get <String>(BaseProperties::BEAMED_GROUP_TYPE, t)) { // NOTATION_DEBUG << "NotationGroup::NotationGroup: Rejecting sample() for non-beamed element" << endl; return false; } long n; if (!(*i)->event()->get <Int>(BaseProperties::BEAMED_GROUP_ID, n)) return false; if (m_groupNo == -1) { m_groupNo = n; } else if (n != m_groupNo) { // NOTATION_DEBUG << "NotationGroup::NotationGroup: Rejecting sample() for event with group id " << n << " (mine is " << m_groupNo << ")" << endl; return false; } if (t == BaseProperties::GROUP_TYPE_BEAMED) { m_type = Beamed; } else if (t == BaseProperties::GROUP_TYPE_TUPLED) { m_type = Tupled; } else if (t == BaseProperties::GROUP_TYPE_GRACE) { m_type = Grace; } else { NOTATION_DEBUG << "NotationGroup::NotationGroup: Warning: Rejecting sample() for unknown GroupType \"" << t << "\"" << endl; return false; } // NOTATION_DEBUG << "NotationGroup::sample: group id is " << m_groupNo << endl; AbstractSet<NotationElement, NotationElementList>::sample (i, goingForwards); // If the sum of the distances from the middle line to the notes // above the middle line exceeds the sum of the distances from the // middle line to the notes below, then the beam goes below. We // can calculate the weightings here, as we construct the group. if (!static_cast<NotationElement*>(*i)->isNote()) return true; if (m_userSamples) { if (m_initialNote == getContainer().end()) m_initialNote = i; m_finalNote = i; } // The code that uses the Group should not rely on the presence of // e.g. BEAM_GRADIENT to indicate that a beam should be drawn; // it's possible the gradient might be left over from a previous // calculation and the group might have changed since. Instead it // should test BEAMED, which may be false even if there is a // gradient present. (*i)->event()->setMaybe<Bool>(NotationProperties::BEAMED, false); int h = height(i); if (h > 4) m_weightAbove += h - 4; if (h < 4) m_weightBelow += 4 - h; return true;}boolNotationGroup::contains(const NELIterator &i) const{ NELIterator j(getInitialElement()), k( getFinalElement()); for (;;) { if (j == i) return true; if (j == k) return false; ++j; }}intNotationGroup::height(const NELIterator &i) const{ long h = 0; if ((*i)->event()->get <Int>(NotationProperties::HEIGHT_ON_STAFF, h)) { return h; } //!!! int pitch = (*i)->event()->get<Int>(PITCH); // NotationDisplayPitch p(pitch, m_clef, m_key); // h = p.getHeightOnStaff(); try { Pitch pitch(*getAsEvent(i)); h = pitch.getHeightOnStaff(m_clef, m_key); } catch (...) { // no pitch! } // not setMaybe, as we know the property is absent: (*i)->event()->set <Int>(NotationProperties::HEIGHT_ON_STAFF, h, false); return h;}voidNotationGroup::applyStemProperties(){ NELIterator initialNote(getInitialNote()), finalNote( getFinalNote()); if (initialNote == getContainer().end() || initialNote == finalNote) { NOTATION_DEBUG << "NotationGroup::applyStemProperties: no notes in group" << endl; return ; // no notes, no case to answer } int up = 0, down = 0; for (NELIterator i = initialNote; i != getContainer().end(); ++i) { NotationElement* el = static_cast<NotationElement*>(*i); if (el->isNote()) { if (el->event()->has(NotationProperties::STEM_UP)) { if (el->event()->get <Bool>(NotationProperties::STEM_UP)) ++up; else ++down; } } if (i == finalNote) break; } NOTATION_DEBUG << "NotationGroup::applyStemProperties: weightAbove " << m_weightAbove << ", weightBelow " << m_weightBelow << ", up " << up << ", down " << down << endl; bool aboveNotes = !(m_weightAbove > m_weightBelow); if (up != down) { if (up > down) aboveNotes = true; else aboveNotes = false; } NOTATION_DEBUG << "NotationGroup::applyStemProperties: hence aboveNotes " << aboveNotes << endl; /*!!! if ((*initialNote)->event()->has(STEM_UP) && (*initialNote)->event()->isPersistent<Bool>(STEM_UP)) { aboveNotes = (*initialNote)->event()->get<Bool>(STEM_UP); } if ((*initialNote)->event()->has(NotationProperties::BEAM_ABOVE) && (*initialNote)->event()->isPersistent<Bool>(NotationProperties::BEAM_ABOVE)) { aboveNotes = (*initialNote)->event()->get<Bool> (NotationProperties::BEAM_ABOVE); } */ for (NELIterator i = initialNote; i != getContainer().end(); ++i) { NotationElement* el = static_cast<NotationElement*>(*i); el->event()->setMaybe<Bool>(NotationProperties::BEAM_ABOVE, aboveNotes); if (el->isNote() && el->event()->has(BaseProperties::NOTE_TYPE) && el->event()->get <Int>(BaseProperties::NOTE_TYPE) < Note::Crotchet && el->event()->has(BaseProperties::BEAMED_GROUP_ID) && el->event()->get<Int>(BaseProperties::BEAMED_GROUP_ID) == m_groupNo) { el->event()->setMaybe<Bool>(NotationProperties::BEAMED, true); // el->event()->setMaybe<Bool>(m_properties.VIEW_LOCAL_STEM_UP, aboveNotes); } else if (el->isNote()) { if (i == initialNote || i == finalNote) { (*i)->event()->setMaybe<Bool> (m_properties.VIEW_LOCAL_STEM_UP, aboveNotes); } else { (*i)->event()->setMaybe<Bool> (m_properties.VIEW_LOCAL_STEM_UP, !aboveNotes); } } if (i == finalNote) break; }}boolNotationGroup::haveInternalRest()const{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -