MuseScore/libmscore/chord.cpp

3598 lines
134 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2013 Werner Schweer
2012-05-26 14:26:10 +02:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "chord.h"
#include "note.h"
#include "xml.h"
#include "style.h"
#include "segment.h"
#include "text.h"
#include "measure.h"
#include "system.h"
#include "tuplet.h"
#include "hook.h"
2013-08-22 12:18:14 +02:00
#include "tie.h"
2012-05-26 14:26:10 +02:00
#include "arpeggio.h"
#include "score.h"
#include "tremolo.h"
#include "glissando.h"
2012-05-26 14:26:10 +02:00
#include "staff.h"
2013-06-10 21:13:04 +02:00
#include "part.h"
2012-05-26 14:26:10 +02:00
#include "utils.h"
#include "articulation.h"
#include "undo.h"
#include "chordline.h"
#include "lyrics.h"
#include "navigate.h"
#include "stafftype.h"
#include "stem.h"
#include "mscore.h"
#include "accidental.h"
#include "noteevent.h"
#include "pitchspelling.h"
#include "stemslash.h"
#include "ledgerline.h"
2013-06-10 21:13:04 +02:00
#include "drumset.h"
#include "key.h"
2013-11-11 16:53:03 +01:00
#include "sym.h"
2014-04-22 17:02:03 +02:00
#include "stringdata.h"
2014-04-23 18:07:38 +02:00
#include "beam.h"
#include "slur.h"
#include "fingering.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
2016-09-03 17:45:59 +02:00
//---------------------------------------------------------
// LedgerLineData
//---------------------------------------------------------
struct LedgerLineData {
int line;
qreal minX, maxX;
bool visible;
bool accidental;
};
//---------------------------------------------------------
2017-08-08 14:01:01 +02:00
// upNote
//---------------------------------------------------------
Note* Chord::upNote() const
{
2016-06-06 10:33:09 +02:00
Q_ASSERT(!_notes.empty());
Note* result = _notes.back();
if (!staff())
return result;
2017-08-08 14:01:01 +02:00
const Staff* stf = staff();
const StaffType* st = stf->staffType(tick());
2017-08-08 14:01:01 +02:00
if (st->isDrumStaff()) {
2016-02-06 22:03:43 +01:00
for (Note* n : _notes) {
if (n->line() < result->line()) {
result = n;
}
}
}
2017-08-08 14:01:01 +02:00
else if (st->isTabStaff()) {
int line = st->lines() - 1; // start at bottom line
int noteLine;
// scan each note: if TAB strings are not in sequential order,
// visual order of notes might not correspond to pitch order
2016-02-06 22:03:43 +01:00
for (Note* n : _notes) {
2017-08-08 14:01:01 +02:00
noteLine = st->physStringToVisual(n->string());
if (noteLine < line) {
2017-08-08 14:01:01 +02:00
line = noteLine;
result = n;
}
}
}
return result;
}
2017-08-08 14:01:01 +02:00
//---------------------------------------------------------
// downNote
//---------------------------------------------------------
Note* Chord::downNote() const
{
2016-06-06 10:33:09 +02:00
Q_ASSERT(!_notes.empty());
Note* result = _notes.front();
if (!staff())
return result;
2017-08-08 14:01:01 +02:00
const Staff* stf = staff();
const StaffType* st = stf->staffType(tick());
2017-08-08 14:01:01 +02:00
if (st->isDrumStaff()) {
2016-02-06 22:03:43 +01:00
for (Note* n : _notes) {
if (n->line() > result->line()) {
result = n;
}
}
}
2017-08-08 14:01:01 +02:00
else if (st->isTabStaff()) {
2014-04-28 18:38:50 +02:00
int line = 0; // start at top line
int noteLine;
// scan each note: if TAB strings are not in sequential order,
// visual order of notes might not correspond to pitch order
2016-02-06 22:03:43 +01:00
for (Note* n : _notes) {
2017-08-08 14:01:01 +02:00
noteLine = st->physStringToVisual(n->string());
if (noteLine > line) {
line = noteLine;
result = n;
2014-05-15 13:42:03 +02:00
}
}
}
return result;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// upLine / downLine
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
int Chord::upLine() const
{
2016-12-13 13:16:17 +01:00
return (staff() && staff()->isTabStaff(tick())) ? upString()*2 : upNote()->line();
2012-05-26 14:26:10 +02:00
}
int Chord::downLine() const
{
2016-12-13 13:16:17 +01:00
return (staff() && staff()->isTabStaff(tick())) ? downString()*2 : downNote()->line();
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// upString / downString
//
// return the topmost / bottommost string used by chord
// Top and bottom refer to the DRAWN position, not the position in the instrument
// (i.e., upside-down TAB are taken into account)
//
// If no staff, always return 0
// If staf is not a TAB, always returns TOP and BOTTOM staff lines
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
int Chord::upString() const
2012-05-26 14:26:10 +02:00
{
// if no staff or staff not a TAB, return 0 (=topmost line)
2016-12-13 13:16:17 +01:00
if(!staff() || !staff()->isTabStaff(tick()))
return 0;
const Staff* st = staff();
const StaffType* tab = st->staffType(tick());
2014-04-28 18:38:50 +02:00
int line = tab->lines() - 1; // start at bottom line
int noteLine;
// scan each note: if TAB strings are not in sequential order,
// visual order of notes might not correspond to pitch order
size_t n = _notes.size();
for (size_t i = 0; i < n; ++i) {
noteLine = tab->physStringToVisual(_notes.at(i)->string());
if (noteLine < line)
line = noteLine;
}
return line;
}
int Chord::downString() const
{
2014-04-28 18:38:50 +02:00
if (!staff()) // if no staff, return 0
return 0;
2016-12-13 13:16:17 +01:00
if (!staff()->isTabStaff(tick())) // if staff not a TAB, return bottom line
return staff()->lines(tick())-1;
const Staff* st = staff();
const StaffType* tab = st->staffType(tick());
int line = 0; // start at top line
int noteLine;
size_t n = _notes.size();
for (size_t i = 0; i < n; ++i) {
noteLine = tab->physStringToVisual(_notes.at(i)->string());
2014-04-28 18:38:50 +02:00
if (noteLine > line)
line = noteLine;
}
return line;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// Chord
//---------------------------------------------------------
Chord::Chord(Score* s)
: ChordRest(s)
{
_ledgerLines = 0;
2012-11-19 10:08:15 +01:00
_stem = 0;
_hook = 0;
2017-06-22 12:42:14 +02:00
_stemDirection = Direction::AUTO;
2012-11-19 10:08:15 +01:00
_arpeggio = 0;
_tremolo = 0;
_endsGlissando = false;
2014-05-27 10:35:28 +02:00
_noteType = NoteType::NORMAL;
2012-11-19 10:08:15 +01:00
_stemSlash = 0;
_noStem = false;
_playEventType = PlayEventType::Auto;
_crossMeasure = CrossMeasure::UNKNOWN;
2013-06-16 23:33:37 +02:00
_graceIndex = 0;
2012-05-26 14:26:10 +02:00
}
2014-06-27 13:41:49 +02:00
Chord::Chord(const Chord& c, bool link)
: ChordRest(c, link)
2012-05-26 14:26:10 +02:00
{
2014-06-27 13:41:49 +02:00
if (link)
2018-04-27 13:29:20 +02:00
score()->undo(new Link(this, const_cast<Chord*>(&c)));
_ledgerLines = 0;
for (Note* onote : c._notes) {
2014-07-10 18:59:44 +02:00
Note* nnote = new Note(*onote, link);
2014-06-27 13:41:49 +02:00
add(nnote);
}
for (Chord* gn : c.graceNotes()) {
2014-06-27 13:41:49 +02:00
Chord* nc = new Chord(*gn, link);
add(nc);
}
2018-01-17 13:25:23 +01:00
for (Articulation* a : c._articulations) { // make deep copy
Articulation* na = new Articulation(*a);
if (link)
na->linkTo(a);
na->setParent(this);
na->setTrack(track());
_articulations.append(na);
}
2012-05-26 14:26:10 +02:00
_stem = 0;
_hook = 0;
_endsGlissando = false;
2012-05-26 14:26:10 +02:00
_arpeggio = 0;
_stemSlash = 0;
_tremolo = 0;
2012-05-26 14:26:10 +02:00
2013-06-16 23:33:37 +02:00
_graceIndex = c._graceIndex;
2012-11-19 10:08:15 +01:00
_noStem = c._noStem;
_playEventType = c._playEventType;
2014-06-27 13:41:49 +02:00
_stemDirection = c._stemDirection;
_noteType = c._noteType;
_crossMeasure = CrossMeasure::UNKNOWN;
2012-11-19 10:08:15 +01:00
2012-05-26 14:26:10 +02:00
if (c._stem)
add(new Stem(*(c._stem)));
if (c._hook)
add(new Hook(*(c._hook)));
if (c._stemSlash)
2012-05-26 14:26:10 +02:00
add(new StemSlash(*(c._stemSlash)));
2014-06-27 13:41:49 +02:00
if (c._arpeggio) {
Arpeggio* a = new Arpeggio(*(c._arpeggio));
add(a);
if (link)
2018-04-27 13:29:20 +02:00
score()->undo(new Link(a, const_cast<Arpeggio*>(c._arpeggio)));
2014-06-27 13:41:49 +02:00
}
if (c._tremolo) {
2014-06-27 13:41:49 +02:00
Tremolo* t = new Tremolo(*(c._tremolo));
if (link) {
2018-04-27 13:29:20 +02:00
score()->undo(new Link(t, const_cast<Tremolo*>(c._tremolo)));
if (c._tremolo->twoNotes()) {
if (c._tremolo->chord1() == &c)
t->setChords(this, nullptr);
else
t->setChords(nullptr, this);
}
}
add(t);
2014-06-27 13:41:49 +02:00
}
2012-05-26 14:26:10 +02:00
2014-06-27 13:41:49 +02:00
for (Element* e : c.el()) {
2016-12-06 09:35:52 +01:00
if (e->isChordLine()) {
ChordLine* cl = toChordLine(e);
2014-06-27 13:41:49 +02:00
ChordLine* ncl = new ChordLine(*cl);
add(ncl);
if (link)
2016-12-06 09:35:52 +01:00
score()->undo(new Link(ncl, cl));
2014-05-10 17:36:32 +02:00
}
}
2014-08-07 10:55:36 +02:00
}
//---------------------------------------------------------
// undoUnlink
//---------------------------------------------------------
void Chord::undoUnlink()
{
ChordRest::undoUnlink();
for (Note* n : _notes)
n->undoUnlink();
for (Chord* gn : graceNotes())
gn->undoUnlink();
2018-01-17 13:25:23 +01:00
for (Articulation* a : _articulations)
a->undoUnlink();
/* if (_glissando)
_glissando->undoUnlink(); */
2014-08-07 10:55:36 +02:00
if (_arpeggio)
_arpeggio->undoUnlink();
if (_tremolo && !_tremolo->twoNotes())
_tremolo->undoUnlink();
for (Element* e : el()) {
2017-01-18 14:16:33 +01:00
if (e->type() == ElementType::CHORDLINE)
2014-08-07 10:55:36 +02:00
e->undoUnlink();
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// ~Chord
//---------------------------------------------------------
Chord::~Chord()
{
2018-01-17 13:25:23 +01:00
qDeleteAll(_articulations);
2012-05-26 14:26:10 +02:00
delete _arpeggio;
if (_tremolo && _tremolo->chord1() == this) {
if (_tremolo->chord2())
_tremolo->chord2()->setTremolo(0);
2012-05-26 14:26:10 +02:00
delete _tremolo;
}
2012-05-26 14:26:10 +02:00
delete _stemSlash;
delete _stem;
delete _hook;
for (LedgerLine* ll = _ledgerLines; ll;) {
LedgerLine* llNext = ll->next();
delete ll;
ll = llNext;
}
qDeleteAll(_graceNotes);
qDeleteAll(_notes);
2012-05-26 14:26:10 +02:00
}
2016-02-15 12:23:28 +01:00
//---------------------------------------------------------
// noteHeadWidth
//---------------------------------------------------------
qreal Chord::noteHeadWidth() const
{
qreal nhw = score()->noteHeadWidth();
if (_noteType != NoteType::NORMAL)
2018-03-27 15:36:00 +02:00
nhw *= score()->styleD(Sid::graceNoteMag);
2016-02-15 12:23:28 +01:00
return nhw * mag();
}
2013-05-23 12:58:06 +02:00
//---------------------------------------------------------
// stemPosX
// return Chord coordinates. Based on nominal notehead
2013-05-23 12:58:06 +02:00
//---------------------------------------------------------
qreal Chord::stemPosX() const
{
const Staff* stf = staff();
const StaffType* st = stf ? stf->staffType(tick()) : 0;
2017-08-08 14:01:01 +02:00
if (st && st->isTabStaff())
return st->chordStemPosX(this) * spatium();
2016-02-15 12:23:28 +01:00
return _up ? noteHeadWidth() : 0.0;
2013-05-23 12:58:06 +02:00
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// stemPos
// return page coordinates
//---------------------------------------------------------
QPointF Chord::stemPos() const
{
2013-08-01 13:16:07 +02:00
QPointF p(pagePos());
2016-12-13 13:16:17 +01:00
const Staff* stf = staff();
const StaffType* st = stf ? stf->staffType(tick()) : 0;
2017-08-08 14:01:01 +02:00
if (st && st->isTabStaff())
return st->chordStemPos(this) * spatium() + p;
2013-05-23 12:32:40 +02:00
if (_up) {
qreal nhw = _notes.size() == 1 ? downNote()->bboxRightPos() : noteHeadWidth();
2013-05-23 16:58:22 +02:00
p.rx() += nhw;
2013-05-23 12:58:06 +02:00
p.ry() += downNote()->pos().y();
2013-05-23 12:32:40 +02:00
}
else
2013-05-23 12:58:06 +02:00
p.ry() += upNote()->pos().y();
2013-05-23 12:32:40 +02:00
return p;
2013-01-02 14:33:23 +01:00
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// stemPosBeam
// return stem position of note on beam side
2016-02-15 12:23:28 +01:00
// return page coordinates
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
QPointF Chord::stemPosBeam() const
{
2013-05-23 12:32:40 +02:00
qreal _spatium = spatium();
QPointF p(pagePos());
2016-02-15 12:23:28 +01:00
const Staff* stf = staff();
const StaffType* st = stf ? stf->staffType(tick()) : 0;
2017-08-08 14:01:01 +02:00
if (st && st->isTabStaff())
return st->chordStemPosBeam(this) * _spatium + p;
2016-02-15 12:23:28 +01:00
2013-05-23 12:32:40 +02:00
if (_up) {
2016-02-15 12:23:28 +01:00
qreal nhw = noteHeadWidth();
2013-05-23 16:58:22 +02:00
p.rx() += nhw;
2013-05-23 12:58:06 +02:00
p.ry() += upNote()->pos().y();
2013-05-23 12:32:40 +02:00
}
else
2013-05-23 12:58:06 +02:00
p.ry() += downNote()->pos().y();
2016-02-16 21:21:28 +01:00
2013-05-23 12:32:40 +02:00
return p;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// setTremolo
//---------------------------------------------------------
void Chord::setTremolo(Tremolo* tr)
{
if (_tremolo && tr && tr == _tremolo)
return;
if (_tremolo) {
if (_tremolo->twoNotes()) {
TDuration d;
const Fraction f = ticks();
if (f.numerator() > 0)
d = TDuration(f);
else {
d = _tremolo->durationType();
const int dots = d.dots();
d = d.shift(1);
d.setDots(dots);
}
setDurationType(d);
Chord* other = _tremolo->chord1() == this ? _tremolo->chord2() : _tremolo->chord1();
_tremolo = nullptr;
if (other)
other->setTremolo(nullptr);
}
else
_tremolo = nullptr;
}
if (tr) {
if (tr->twoNotes()) {
TDuration d = tr->durationType();
if (!d.isValid()) {
d = durationType();
const int dots = d.dots();
d = d.shift(-1);
d.setDots(dots);
tr->setDurationType(d);
}
setDurationType(d);
Chord* other = tr->chord1() == this ? tr->chord2() : tr->chord1();
_tremolo = tr;
if (other)
other->setTremolo(tr);
}
else
_tremolo = tr;
}
else {
_tremolo = nullptr;
}
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// add
//---------------------------------------------------------
void Chord::add(Element* e)
{
e->setParent(this);
e->setTrack(track());
switch(e->type()) {
2017-01-18 14:16:33 +01:00
case ElementType::NOTE:
2012-05-26 14:26:10 +02:00
{
Note* note = toNote(e);
2012-05-26 14:26:10 +02:00
bool found = false;
// _notes should be sorted by line position,
// but it's often not yet possible since line is unknown
// use pitch instead, and line as a second sort criteria.
2016-02-06 22:03:43 +01:00
for (unsigned idx = 0; idx < _notes.size(); ++idx) {
if (note->pitch() <= _notes[idx]->pitch()) {
if (note->pitch() == _notes[idx]->pitch() && note->line() > _notes[idx]->line())
2016-02-06 22:03:43 +01:00
_notes.insert(_notes.begin()+idx+1, note);
else
2016-02-06 22:03:43 +01:00
_notes.insert(_notes.begin()+idx, note);
2012-05-26 14:26:10 +02:00
found = true;
break;
}
}
if (!found)
2016-02-06 22:03:43 +01:00
_notes.push_back(note);
note->connectTiedNotes();
if (voice() && measure() && note->visible())
2016-12-12 12:02:18 +01:00
measure()->setHasVoices(staffIdx(), true);
2012-05-26 14:26:10 +02:00
}
score()->setPlaylistDirty();
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::ARPEGGIO:
_arpeggio = toArpeggio(e);
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::TREMOLO:
setTremolo(toTremolo(e));
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::GLISSANDO:
_endsGlissando = true;
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::STEM:
Q_ASSERT(!_stem);
_stem = toStem(e);
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::HOOK:
_hook = toHook(e);
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::CHORDLINE:
2016-12-06 09:35:52 +01:00
el().push_back(e);
break;
2017-01-18 14:16:33 +01:00
case ElementType::STEM_SLASH:
Q_ASSERT(!_stemSlash);
_stemSlash = toStemSlash(e);
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::CHORD:
2013-06-16 23:33:37 +02:00
{
2017-12-20 16:49:30 +01:00
Chord* gc = toChord(e);
Q_ASSERT(gc->noteType() != NoteType::NORMAL);
2013-06-16 23:33:37 +02:00
int idx = gc->graceIndex();
gc->setFlag(ElementFlag::MOVABLE, true);
2013-06-16 23:33:37 +02:00
_graceNotes.insert(_graceNotes.begin() + idx, gc);
}
2013-06-12 14:23:57 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::LEDGER_LINE:
qFatal("Chord::add ledgerline");
2014-04-22 17:02:03 +02:00
break;
2018-01-17 13:25:23 +01:00
case ElementType::ARTICULATION:
{
Articulation* a = toArticulation(e);
if (a->layoutCloseToNote()) {
auto i = _articulations.begin();
while (i != _articulations.end() && (*i)->layoutCloseToNote())
i++;
_articulations.insert(i, a);
}
else
_articulations.push_back(a);
}
2018-01-17 13:25:23 +01:00
break;
2012-05-26 14:26:10 +02:00
default:
ChordRest::add(e);
break;
}
}
//---------------------------------------------------------
// remove
//---------------------------------------------------------
void Chord::remove(Element* e)
{
2016-02-06 22:03:43 +01:00
if (!e)
2016-02-01 09:29:09 +01:00
return;
2016-02-06 22:03:43 +01:00
switch (e->type()) {
2017-01-18 14:16:33 +01:00
case ElementType::NOTE:
2012-05-26 14:26:10 +02:00
{
2016-02-17 14:54:23 +01:00
Note* note = toNote(e);
2016-02-06 22:03:43 +01:00
auto i = std::find(_notes.begin(), _notes.end(), note);
if (i != _notes.end()) {
_notes.erase(i);
note->disconnectTiedNotes();
2016-03-02 13:20:19 +01:00
for (Spanner* s : note->spannerBack())
note->removeSpannerBack(s);
2016-03-02 13:20:19 +01:00
for (Spanner* s : note->spannerFor())
note->removeSpannerFor(s);
2012-05-26 14:26:10 +02:00
}
else
qDebug("Chord::remove() note %p not found!", e);
if (voice() && measure() && note->visible())
measure()->checkMultiVoices(staffIdx());
score()->setPlaylistDirty();
2012-05-26 14:26:10 +02:00
}
break;
2017-01-18 14:16:33 +01:00
case ElementType::ARPEGGIO:
2012-05-26 14:26:10 +02:00
_arpeggio = 0;
break;
2017-01-18 14:16:33 +01:00
case ElementType::TREMOLO:
setTremolo(nullptr);
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::GLISSANDO:
_endsGlissando = false;
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::STEM:
2012-05-26 14:26:10 +02:00
_stem = 0;
break;
2017-01-18 14:16:33 +01:00
case ElementType::HOOK:
2012-05-26 14:26:10 +02:00
_hook = 0;
break;
2017-01-18 14:16:33 +01:00
case ElementType::STEM_SLASH:
Q_ASSERT(_stemSlash);
if (_stemSlash->selected() && score())
score()->deselect(_stemSlash);
_stemSlash = 0;
break;
2017-01-18 14:16:33 +01:00
case ElementType::CHORDLINE:
2016-12-06 09:35:52 +01:00
el().remove(e);
2012-05-26 14:26:10 +02:00
break;
2017-01-18 14:16:33 +01:00
case ElementType::CHORD:
2013-06-16 23:33:37 +02:00
{
2017-12-20 16:49:30 +01:00
auto i = std::find(_graceNotes.begin(), _graceNotes.end(), toChord(e));
2013-06-16 23:33:37 +02:00
Chord* grace = *i;
grace->setGraceIndex(i - _graceNotes.begin());
_graceNotes.erase(i);
}
2013-06-12 14:23:57 +02:00
break;
2018-01-17 13:25:23 +01:00
case ElementType::ARTICULATION:
{
Articulation* a = toArticulation(e);
if (!_articulations.removeOne(a))
qDebug("ChordRest::remove(): articulation not found");
}
break;
2012-05-26 14:26:10 +02:00
default:
ChordRest::remove(e);
break;
}
}
//---------------------------------------------------------
// maxHeadWidth
//---------------------------------------------------------
2013-09-02 19:07:39 +02:00
qreal Chord::maxHeadWidth() const
{
// determine max head width in chord
2017-08-08 14:01:01 +02:00
qreal hw = 0;
for (const Note* n : _notes) {
qreal t = n->headWidth();
if (t > hw)
hw = t;
}
return hw;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// addLedgerLines
//---------------------------------------------------------
void Chord::addLedgerLines()
2012-05-26 14:26:10 +02:00
{
// initialize for palette
int track = 0; // the track lines belong to
// the line pos corresponding to the bottom line of the staff
int lineBelow = 8; // assuming 5-lined "staff"
qreal lineDistance = 1;
qreal mag = 1;
bool staffVisible = true;
if (segment()) { //not palette
Fraction tick = segment()->tick();
int idx = staffIdx() + staffMove();
track = staff2track(idx);
Staff* st = score()->staff(idx);
lineBelow = (st->lines(tick) - 1) * 2;
lineDistance = st->lineDistance(tick);
mag = staff()->mag(tick);
staffVisible = !staff()->invisible();
}
// need ledger lines?
if (downLine() <= lineBelow + 1 && upLine() >= -1)
return;
// the extra length of a ledger line with respect to notehead (half of it on each side)
qreal extraLen = score()->styleP(Sid::ledgerLineLength) * mag * 0.5;
qreal hw;
qreal minX, maxX; // note extrema in raster units
int minLine, maxLine;
bool visible = false;
qreal x;
// scan chord notes, collecting visibility and x and y extrema
// NOTE: notes are sorted from bottom to top (line no. decreasing)
// notes are scanned twice from outside (bottom or top) toward the staff
// each pass stops at the first note without ledger lines
size_t n = _notes.size();
for (size_t j = 0; j < 2; j++) { // notes are scanned twice...
int from, delta;
vector<LedgerLineData> vecLines;
hw = 0.0;
minX = maxX = 0;
minLine = 0;
maxLine = lineBelow;
if (j == 0) { // ...once from lowest up...
from = 0;
delta = +1;
}
else {
from = int(n)-1; // ...once from highest down
delta = -1;
}
for (int i = from; i < int(n) && i >= 0 ; i += delta) {
2016-09-03 17:45:59 +02:00
Note* note = _notes.at(i);
2016-12-23 12:05:18 +01:00
int l = note->line();
// if 1st pass and note not below staff or 2nd pass and note not above staff
if ((!j && l <= lineBelow + 1) || (j && l >= -1))
break; // stop this pass
// round line number to even number toward 0
if (l < 0)
l = (l + 1) & ~ 1;
else
l = l & ~ 1;
if (note->visible()) // if one note is visible,
visible = true; // all lines between it and the staff are visible
hw = qMax(hw, note->headWidth());
//
// Experimental:
// shorten ledger line to avoid collisions with accidentals
//
2013-09-05 16:37:49 +02:00
// bool accid = (note->accidental() && note->line() >= (l-1) && note->line() <= (l+1) );
//
// TODO : do something with this accid flag in the following code!
//
// check if note horiz. pos. is outside current range
// if more length on the right, increase range
2016-09-03 17:45:59 +02:00
// note->layout();
//ledger lines need the leftmost point of the notehead with a respect of bbox
x = note->pos().x() + note->bboxXShift();
2016-09-03 17:45:59 +02:00
if (x - extraLen < minX) {
minX = x - extraLen;
// increase width of all lines between this one and the staff
2016-09-03 17:45:59 +02:00
for (auto& d : vecLines) {
if (!d.accidental && ((l < 0 && d.line >= l) || (l > 0 && d.line <= l)) )
d.minX = minX ;
2016-09-03 17:45:59 +02:00
}
}
// same for left side
2016-09-03 17:45:59 +02:00
if (x + hw + extraLen > maxX) {
maxX = x + hw + extraLen;
for (auto& d : vecLines)
if ( (l < 0 && d.line >= l) || (l > 0 && d.line <= l) )
d.maxX = maxX;
}
LedgerLineData lld;
// check if note vert. pos. is outside current range
// and, if so, add data for new line(s)
if (l < minLine) {
for (int i1 = l; i1 < minLine; i1 += 2) {
lld.line = i1;
if (lineDistance != 1.0)
lld.line *= lineDistance;
lld.minX = minX;
lld.maxX = maxX;
lld.visible = visible;
lld.accidental = false;
vecLines.push_back(lld);
}
minLine = l;
}
if (l > maxLine) {
for (int i1 = maxLine+2; i1 <= l; i1 += 2) {
lld.line = i1;
if (lineDistance != 1.0)
lld.line *= lineDistance;
lld.minX = minX;
lld.maxX = maxX;
lld.visible = visible;
lld.accidental = false;
vecLines.push_back(lld);
}
maxLine = l;
}
}
if (minLine < 0 || maxLine > lineBelow) {
qreal _spatium = spatium();
qreal stepDistance = 0.5; // staff() ? staff()->lineDistance() * 0.5 : 0.5;
for (auto lld : vecLines) {
LedgerLine* h = new LedgerLine(score());
h->setParent(this);
h->setTrack(track);
h->setVisible(lld.visible && staffVisible);
2016-09-03 17:45:59 +02:00
h->setLen(lld.maxX - lld.minX);
h->setPos(lld.minX, lld.line * _spatium * stepDistance);
h->setNext(_ledgerLines);
_ledgerLines = h;
}
}
2012-05-26 14:26:10 +02:00
}
for (LedgerLine* ll = _ledgerLines; ll; ll = ll->next())
ll->layout();
2012-05-26 14:26:10 +02:00
}
//-----------------------------------------------------------------------------
// computeUp
// rules:
// single note:
// All notes beneath the middle line: upward stems
// All notes on or above the middle line: downward stems
// two notes:
// If the interval above the middle line is greater than the interval
// below the middle line: downward stems
// If the interval below the middle line is greater than the interval
// above the middle line: upward stems
// If the two notes are the same distance from the middle line:
// stem can go in either direction. but most engravers prefer
// downward stems
// > two notes:
// If the interval of the highest note above the middle line is greater
// than the interval of the lowest note below the middle line:
// downward stems
// If the interval of the lowest note below the middle line is greater
// than the interval of the highest note above the middle line:
// upward stem
// If the highest and the lowest notes are the same distance from
// the middle line:, use these rules to determine stem direction:
// - If the majority of the notes are above the middle:
// downward stems
// - If the majority of the notes are below the middle:
// upward stems
// TABlatures:
// stems beside staves:
// All stems are up / down according to TAB::stemsDown() setting
// stems through staves:
// Same rules as per pitched staves
2012-05-26 14:26:10 +02:00
//-----------------------------------------------------------------------------
void Chord::computeUp()
{
2016-06-06 10:33:09 +02:00
Q_ASSERT(!_notes.empty());
const Staff* st = staff();
const StaffType* tab = st ? st->staffType(tick()) : 0;
2017-08-10 14:35:18 +02:00
bool tabStaff = tab && tab->isTabStaff();
// TAB STAVES
2017-08-10 14:35:18 +02:00
if (tabStaff) {
// if no stems or stem beside staves
if (tab->stemless() || !tab->stemThrough()) {
// if measure has voices, set stem direction according to voice
2016-12-12 12:02:18 +01:00
if (measure()->hasVoices(staffIdx()))
Fix #69846, #69821, #63561 - multi-voice TAB's: stem and slur positions __Background__: In the original TAB implementation, the "Stems above / below" setting was followed when there was only one voice, while with multiple voices, voice 1 stems were always above and voice 2 stems always below. In issue https://musescore.org/en/node/63561 the OP reported that: - with multiple voices, stems in TAB did not follow the "Stems above / below" setting; - extra space was allocated for voice 2 stems. Both issues were more apparent than real, because the example provided casually had no stems in voice 2 (all whole notes). With the commit https://github.com/musescore/MuseScore/commit/33797cd6c55490cd67a3267e5e7e09f409e61dbf : - voice 1 stems are forced to be below or down according to the setting even for multi-voice cases and voice 2 stems on the opposite side; - additional distance is allocated above the TAB staff (but not below) if stems are above or there are multiple voices or below (but not above) if stems are below and there is only voice 1. __Issues__: 1a) The original stem directions were __by design__, assuming that with multiple voices notes of voice 1 tend to be above and notes of voice 2 tend to be below; then it is more sensible to put voice 1 stems above and voice 2 stems below, limiting the "Stems above / below" setting to the single voice case only. 1b) Stem direction controls slurs and tie placement and users are complaining that, with multiple voices, stems, slurs and ties are placed unexpectedly. See issue https://musescore.org/en/node/69846 and forum post https://musescore.org/en/node/69821 . 2) About additional staff distance allocation, with multiple voices it has to be allocated __both__ above and below, as stems may appear both above and below. __Fix__: 1) This patch fixes 1) by restoring the original stem direction computation (single voice: follow "Stems above / below" setting | multiple voices: voice 1 unconditionally above and voice 2 below) when tab is configured to have stems beside the staff and also when it is configured to have __no stems at all_ (so that slurs and ties occur in expected positions). 2) It corrects additional staff distance allocation for the multiple voice case. No resources are spent to check the odd case when one voice casually has no stems over the entire system (in which case, additional distance on that side could in theory be spared).
2015-07-26 20:55:02 +02:00
_up = !(track() % 2);
else // if only voice 1,
// unconditionally set to down if not stems or according to TAB stem direction otherwise
Fix #69846, #69821, #63561 - multi-voice TAB's: stem and slur positions __Background__: In the original TAB implementation, the "Stems above / below" setting was followed when there was only one voice, while with multiple voices, voice 1 stems were always above and voice 2 stems always below. In issue https://musescore.org/en/node/63561 the OP reported that: - with multiple voices, stems in TAB did not follow the "Stems above / below" setting; - extra space was allocated for voice 2 stems. Both issues were more apparent than real, because the example provided casually had no stems in voice 2 (all whole notes). With the commit https://github.com/musescore/MuseScore/commit/33797cd6c55490cd67a3267e5e7e09f409e61dbf : - voice 1 stems are forced to be below or down according to the setting even for multi-voice cases and voice 2 stems on the opposite side; - additional distance is allocated above the TAB staff (but not below) if stems are above or there are multiple voices or below (but not above) if stems are below and there is only voice 1. __Issues__: 1a) The original stem directions were __by design__, assuming that with multiple voices notes of voice 1 tend to be above and notes of voice 2 tend to be below; then it is more sensible to put voice 1 stems above and voice 2 stems below, limiting the "Stems above / below" setting to the single voice case only. 1b) Stem direction controls slurs and tie placement and users are complaining that, with multiple voices, stems, slurs and ties are placed unexpectedly. See issue https://musescore.org/en/node/69846 and forum post https://musescore.org/en/node/69821 . 2) About additional staff distance allocation, with multiple voices it has to be allocated __both__ above and below, as stems may appear both above and below. __Fix__: 1) This patch fixes 1) by restoring the original stem direction computation (single voice: follow "Stems above / below" setting | multiple voices: voice 1 unconditionally above and voice 2 below) when tab is configured to have stems beside the staff and also when it is configured to have __no stems at all_ (so that slurs and ties occur in expected positions). 2) It corrects additional staff distance allocation for the multiple voice case. No resources are spent to check the odd case when one voice casually has no stems over the entire system (in which case, additional distance on that side could in theory be spared).
2015-07-26 20:55:02 +02:00
// (even with no stems, stem direction controls position of slurs and ties)
_up = tab->stemless() ? false : !tab->stemsDown();
Fix #69846, #69821, #63561 - multi-voice TAB's: stem and slur positions __Background__: In the original TAB implementation, the "Stems above / below" setting was followed when there was only one voice, while with multiple voices, voice 1 stems were always above and voice 2 stems always below. In issue https://musescore.org/en/node/63561 the OP reported that: - with multiple voices, stems in TAB did not follow the "Stems above / below" setting; - extra space was allocated for voice 2 stems. Both issues were more apparent than real, because the example provided casually had no stems in voice 2 (all whole notes). With the commit https://github.com/musescore/MuseScore/commit/33797cd6c55490cd67a3267e5e7e09f409e61dbf : - voice 1 stems are forced to be below or down according to the setting even for multi-voice cases and voice 2 stems on the opposite side; - additional distance is allocated above the TAB staff (but not below) if stems are above or there are multiple voices or below (but not above) if stems are below and there is only voice 1. __Issues__: 1a) The original stem directions were __by design__, assuming that with multiple voices notes of voice 1 tend to be above and notes of voice 2 tend to be below; then it is more sensible to put voice 1 stems above and voice 2 stems below, limiting the "Stems above / below" setting to the single voice case only. 1b) Stem direction controls slurs and tie placement and users are complaining that, with multiple voices, stems, slurs and ties are placed unexpectedly. See issue https://musescore.org/en/node/69846 and forum post https://musescore.org/en/node/69821 . 2) About additional staff distance allocation, with multiple voices it has to be allocated __both__ above and below, as stems may appear both above and below. __Fix__: 1) This patch fixes 1) by restoring the original stem direction computation (single voice: follow "Stems above / below" setting | multiple voices: voice 1 unconditionally above and voice 2 below) when tab is configured to have stems beside the staff and also when it is configured to have __no stems at all_ (so that slurs and ties occur in expected positions). 2) It corrects additional staff distance allocation for the multiple voice case. No resources are spent to check the odd case when one voice casually has no stems over the entire system (in which case, additional distance on that side could in theory be spared).
2015-07-26 20:55:02 +02:00
return;
}
// if TAB has stems through staves, chain into standard processing
2012-05-26 14:26:10 +02:00
}
// PITCHED STAVES (or TAB with stems through staves)
2017-08-08 14:01:01 +02:00
if (_stemDirection != Direction::AUTO)
2017-06-22 12:42:14 +02:00
_up = _stemDirection == Direction::UP;
2016-01-04 14:48:58 +01:00
else if (!parent())
// hack for palette and drumset editor
2016-01-04 14:48:58 +01:00
_up = upNote()->line() > 4;
2014-05-27 10:35:28 +02:00
else if (_noteType != NoteType::NORMAL) {
//
// stem direction for grace notes
//
2016-12-12 12:02:18 +01:00
if (measure()->hasVoices(staffIdx()))
2013-08-09 11:42:24 +02:00
_up = !(track() % 2);
2012-05-26 14:26:10 +02:00
else
_up = true;
}
2016-01-04 14:48:58 +01:00
else if (staffMove())
2013-01-29 15:21:01 +01:00
_up = staffMove() > 0;
2017-08-10 14:35:18 +02:00
else if (measure()->hasVoices(staffIdx()))
2013-08-09 11:42:24 +02:00
_up = !(track() % 2);
2012-05-26 14:26:10 +02:00
else {
2016-12-13 13:16:17 +01:00
int dnMaxLine = staff()->middleLine(tick());
2017-08-10 14:35:18 +02:00
int ud = (tabStaff ? upString() * 2 : upNote()->line() ) - dnMaxLine;
// standard case: if only 1 note or cross beaming
if (_notes.size() == 1 || staffMove()) {
if (staffMove() > 0)
_up = true;
else if (staffMove() < 0)
_up = false;
else
_up = ud > 0;
}
// if more than 1 note, compare extrema (topmost and bottommost notes)
else {
2017-08-10 14:35:18 +02:00
int dd = (tabStaff ? downString() * 2 : downNote()->line() ) - dnMaxLine;
// if extrema symmetrical, average directions of intermediate notes
if (-ud == dd) {
int up = 0;
size_t n = _notes.size();
for (size_t i = 0; i < n; ++i) {
const Note* currentNote = _notes.at(i);
int l = tabStaff ? currentNote->string() * 2 : currentNote->line();
if (l <= dnMaxLine)
--up;
else
++up;
}
_up = up > 0;
2012-05-26 14:26:10 +02:00
}
// if extrema not symmetrical, set _up to prevailing
else
_up = dd > -ud;
2012-05-26 14:26:10 +02:00
}
}
}
//---------------------------------------------------------
// selectedNote
//---------------------------------------------------------
Note* Chord::selectedNote() const
{
Note* note = 0;
size_t n = _notes.size();
for (size_t i = 0; i < n; ++i) {
Note* currentNote = _notes.at(i);
if (currentNote->selected()) {
2012-05-26 14:26:10 +02:00
if (note)
return 0;
note = currentNote;
2012-05-26 14:26:10 +02:00
}
}
return note;
}
//---------------------------------------------------------
// Chord::write
//---------------------------------------------------------
2016-11-19 11:51:21 +01:00
void Chord::write(XmlWriter& xml) const
2012-05-26 14:26:10 +02:00
{
2013-06-19 16:25:29 +02:00
for (Chord* c : _graceNotes) {
2013-06-12 14:23:57 +02:00
c->write(xml);
2013-06-19 16:25:29 +02:00
}
2018-06-09 04:45:54 +02:00
writeBeam(xml);
xml.stag(this);
2012-05-26 14:26:10 +02:00
ChordRest::writeProperties(xml);
2018-01-17 13:25:23 +01:00
for (const Articulation* a : _articulations)
a->write(xml);
2013-06-19 16:25:29 +02:00
switch (_noteType) {
2014-05-27 10:35:28 +02:00
case NoteType::NORMAL:
2013-06-19 16:25:29 +02:00
break;
2014-05-27 10:35:28 +02:00
case NoteType::ACCIACCATURA:
2013-06-19 16:25:29 +02:00
xml.tagE("acciaccatura");
break;
2014-05-27 10:35:28 +02:00
case NoteType::APPOGGIATURA:
2013-06-19 16:25:29 +02:00
xml.tagE("appoggiatura");
break;
2014-05-30 13:35:44 +02:00
case NoteType::GRACE4:
2013-06-19 16:25:29 +02:00
xml.tagE("grace4");
break;
2014-05-27 10:35:28 +02:00
case NoteType::GRACE16:
2013-06-19 16:25:29 +02:00
xml.tagE("grace16");
break;
2014-05-27 10:35:28 +02:00
case NoteType::GRACE32:
2013-06-19 16:25:29 +02:00
xml.tagE("grace32");
break;
2014-05-27 10:35:28 +02:00
case NoteType::GRACE8_AFTER:
2014-04-23 18:07:38 +02:00
xml.tagE("grace8after");
break;
2014-05-27 10:35:28 +02:00
case NoteType::GRACE16_AFTER:
2014-04-23 18:07:38 +02:00
xml.tagE("grace16after");
break;
2014-05-27 10:35:28 +02:00
case NoteType::GRACE32_AFTER:
2014-04-23 18:07:38 +02:00
xml.tagE("grace32after");
break;
default:
break;
2012-05-26 14:26:10 +02:00
}
2013-06-19 16:25:29 +02:00
2012-05-26 14:26:10 +02:00
if (_noStem)
xml.tag("noStem", _noStem);
2015-03-06 10:44:47 +01:00
else if (_stem && (_stem->isUserModified() || (_stem->userLen() != 0.0)))
2012-05-26 14:26:10 +02:00
_stem->write(xml);
2015-03-06 10:44:47 +01:00
if (_hook && _hook->isUserModified())
2012-05-26 14:26:10 +02:00
_hook->write(xml);
2015-03-06 10:44:47 +01:00
if (_stemSlash && _stemSlash->isUserModified())
_stemSlash->write(xml);
2018-03-27 15:36:00 +02:00
writeProperty(xml, Pid::STEM_DIRECTION);
2013-06-19 16:25:29 +02:00
for (Note* n : _notes)
n->write(xml);
2012-05-26 14:26:10 +02:00
if (_arpeggio)
_arpeggio->write(xml);
2014-05-15 13:42:03 +02:00
if (_tremolo && tremoloChordType() != TremoloChordType::TremoloSecondNote)
2012-05-26 14:26:10 +02:00
_tremolo->write(xml);
2016-12-06 09:35:52 +01:00
for (Element* e : el())
2014-07-09 18:05:58 +02:00
e->write(xml);
2012-05-26 14:26:10 +02:00
xml.etag();
}
//---------------------------------------------------------
// Chord::read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Chord::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
2013-01-11 18:10:18 +01:00
while (e.readNextStartElement()) {
2016-09-22 12:02:27 +02:00
if (readProperties(e))
2013-05-29 10:31:26 +02:00
;
else
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
}
2016-09-22 12:02:27 +02:00
//---------------------------------------------------------
// readProperties
//---------------------------------------------------------
bool Chord::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (tag == "Note") {
Note* note = new Note(score());
// the note needs to know the properties of the track it belongs to
note->setTrack(track());
note->setChord(this);
note->read(e);
add(note);
}
else if (ChordRest::readProperties(e))
;
else if (tag == "Stem") {
Stem* s = new Stem(score());
s->read(e);
add(s);
}
else if (tag == "Hook") {
_hook = new Hook(score());
_hook->read(e);
add(_hook);
}
else if (tag == "appoggiatura") {
_noteType = NoteType::APPOGGIATURA;
e.readNext();
}
else if (tag == "acciaccatura") {
_noteType = NoteType::ACCIACCATURA;
e.readNext();
}
else if (tag == "grace4") {
_noteType = NoteType::GRACE4;
e.readNext();
}
else if (tag == "grace16") {
_noteType = NoteType::GRACE16;
e.readNext();
}
else if (tag == "grace32") {
_noteType = NoteType::GRACE32;
e.readNext();
}
else if (tag == "grace8after") {
_noteType = NoteType::GRACE8_AFTER;
e.readNext();
}
else if (tag == "grace16after") {
_noteType = NoteType::GRACE16_AFTER;
e.readNext();
}
else if (tag == "grace32after") {
_noteType = NoteType::GRACE32_AFTER;
e.readNext();
}
else if (tag == "StemSlash") {
StemSlash* ss = new StemSlash(score());
ss->read(e);
add(ss);
}
2018-03-27 15:36:00 +02:00
else if (readProperty(tag, e, Pid::STEM_DIRECTION))
2017-01-16 20:51:12 +01:00
;
2016-09-22 12:02:27 +02:00
else if (tag == "noStem")
_noStem = e.readInt();
else if (tag == "Arpeggio") {
_arpeggio = new Arpeggio(score());
_arpeggio->setTrack(track());
_arpeggio->read(e);
_arpeggio->setParent(this);
}
else if (tag == "Tremolo") {
_tremolo = new Tremolo(score());
_tremolo->setTrack(track());
_tremolo->read(e);
_tremolo->setParent(this);
_tremolo->setDurationType(durationType());
2016-09-22 12:02:27 +02:00
}
else if (tag == "tickOffset") // obsolete
;
else if (tag == "ChordLine") {
ChordLine* cl = new ChordLine(score());
cl->read(e);
add(cl);
}
else
return false;
return true;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// upPos
//---------------------------------------------------------
qreal Chord::upPos() const
{
return upNote()->pos().y();
}
//---------------------------------------------------------
// downPos
//---------------------------------------------------------
qreal Chord::downPos() const
{
return downNote()->pos().y();
}
//---------------------------------------------------------
// centerX
// return x position for attributes
//---------------------------------------------------------
qreal Chord::centerX() const
{
// TAB 'notes' are always centered on the stem
const Staff* st = staff();
if (st->isTabStaff(tick()))
return st->staffType(tick())->chordStemPosX(this) * spatium();
2012-05-26 14:26:10 +02:00
const Note* note = up() ? upNote() : downNote();
qreal x = note->pos().x() + note->noteheadCenterX();
2017-08-08 14:01:01 +02:00
if (note->mirror())
x += (note->headBodyWidth()) * (up() ? -1.0 : 1.0);
2012-05-26 14:26:10 +02:00
return x;
}
//---------------------------------------------------------
// scanElements
//---------------------------------------------------------
void Chord::scanElements(void* data, void (*func)(void*, Element*), bool all)
{
2018-01-17 13:25:23 +01:00
for (Articulation* a : _articulations)
func(data, a);
if (_hook)
func(data, _hook );
if (_stem)
2012-05-26 14:26:10 +02:00
func(data, _stem);
if (_stemSlash)
func(data, _stemSlash);
if (_arpeggio)
func(data, _arpeggio);
2014-05-15 13:42:03 +02:00
if (_tremolo && (tremoloChordType() != TremoloChordType::TremoloSecondNote))
2012-05-26 14:26:10 +02:00
func(data, _tremolo);
const Staff* st = staff();
2016-12-13 13:16:17 +01:00
if ((st && st->showLedgerLines(tick())) || !st) // also for palette
for (LedgerLine* ll = _ledgerLines; ll; ll = ll->next())
func(data, ll);
size_t n = _notes.size();
for (size_t i = 0; i < n; ++i)
_notes.at(i)->scanElements(data, func, all);
2013-06-10 21:13:04 +02:00
for (Chord* chord : _graceNotes)
chord->scanElements(data, func, all);
2016-12-06 09:35:52 +01:00
for (Element* e : el())
2013-03-25 16:27:20 +01:00
e->scanElements(data, func, all);
2012-05-26 14:26:10 +02:00
ChordRest::scanElements(data, func, all);
}
//---------------------------------------------------------
2013-03-25 16:27:20 +01:00
// processSiblings
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2016-01-04 14:48:58 +01:00
void Chord::processSiblings(std::function<void(Element*)> func) const
2012-05-26 14:26:10 +02:00
{
if (_hook)
2013-03-25 16:27:20 +01:00
func(_hook);
2012-05-26 14:26:10 +02:00
if (_stem)
2013-03-25 16:27:20 +01:00
func(_stem);
2012-05-26 14:26:10 +02:00
if (_stemSlash)
2013-03-25 16:27:20 +01:00
func(_stemSlash);
2012-05-26 14:26:10 +02:00
if (_arpeggio)
2013-03-25 16:27:20 +01:00
func(_arpeggio);
2012-05-26 14:26:10 +02:00
if (_tremolo)
2013-03-25 16:27:20 +01:00
func(_tremolo);
for (LedgerLine* ll = _ledgerLines; ll; ll = ll->next())
2013-03-25 16:27:20 +01:00
func(ll);
2018-01-17 13:25:23 +01:00
for (Articulation* a : _articulations)
func(a);
2016-02-06 22:03:43 +01:00
for (Note* note : _notes)
func(note);
2016-12-06 09:35:52 +01:00
for (Element* e : el())
2013-03-25 16:27:20 +01:00
func(e);
2016-01-04 14:48:58 +01:00
for (Chord* chord : _graceNotes) // process grace notes last, needed for correct shape calculation
func(chord);
2013-03-25 16:27:20 +01:00
}
2012-05-26 14:26:10 +02:00
2013-03-25 16:27:20 +01:00
//---------------------------------------------------------
// setTrack
//---------------------------------------------------------
void Chord::setTrack(int val)
{
2012-05-26 14:26:10 +02:00
ChordRest::setTrack(val);
2013-03-25 16:27:20 +01:00
processSiblings([val] (Element* e) { e->setTrack(val); } );
2012-05-26 14:26:10 +02:00
}
2013-03-25 16:27:20 +01:00
//---------------------------------------------------------
// setScore
//---------------------------------------------------------
void Chord::setScore(Score* s)
{
ChordRest::setScore(s);
processSiblings([s] (Element* e) { e->setScore(s); } );
2012-05-26 14:26:10 +02:00
}
//-----------------------------------------------------------------------------
// hookAdjustment
// Adjustment to the length of the stem in order to accomodate hooks
// This function replaces this bit of code:
// switch (hookIdx) {
// case 3: normalStemLen += small() ? .5 : 0.75; break; //32nd notes
// case 4: normalStemLen += small() ? 1.0 : 1.5; break; //64th notes
// case 5: normalStemLen += small() ? 1.5 : 2.25; break; //128th notes
// }
// which was not sufficient for two reasons:
// 1. It only lengthened the stem for 3, 4, or 5 hooks.
// 2. It was too general to produce good results for all combinations of factors.
// This provides a way to take a number of factors into account. Further tweaking may be in order.
//-----------------------------------------------------------------------------
qreal hookAdjustment(QString font, int hooks, bool up, bool small)
{
bool fallback = MScore::useFallbackFont && (hooks > 5);
if (font == "Emmentaler" && !fallback) {
if (up) {
if (hooks > 2)
return (hooks - 2) * (small ? .75 : 1);
}
else {
if (hooks == 3)
return (small ? .75 : 1);
else if (hooks > 3)
return (hooks - 2) * (small ? .5 : .75);
}
}
else if (font == "Gonville" && !fallback) {
if (up) {
if (hooks > 2)
return (hooks - 2) * (small ? .5 : .75);
}
else {
if (hooks > 1)
return (hooks - 1) * (small ? .5 : .75);
}
}
else if (font == "MuseJazz") {
if (hooks > 2)
return (hooks - 2) * (small ? .75 : 1);
}
else {
if (hooks > 2)
return (hooks - 2) * (small ? .5 : .75);
}
return 0;
}
//-----------------------------------------------------------------------------
// defaultStemLength
/// Get the default stem length for this chord
//-----------------------------------------------------------------------------
qreal Chord::defaultStemLength() const
2016-03-19 11:41:38 +01:00
{
Note* downnote;
qreal stemLen;
2016-12-23 12:05:18 +01:00
qreal _spatium = spatium();
int hookIdx = durationType().hooks();
downnote = downNote();
int ul = upLine();
int dl = downLine();
const Staff* st = staff();
2016-12-23 12:05:18 +01:00
qreal lineDistance = st ? st->lineDistance(tick()) : 1.0;
const StaffType* tab = (st && st->isTabStaff(tick())) ? st->staffType(tick()) : nullptr;
if (tab) {
// require stems only if TAB is not stemless and this chord has a stem
if (!tab->stemless() && _stem) {
// if stems are beside staff, apply special formatting
if (!tab->stemThrough()) {
// process stem:
return tab->chordStemLength(this) * _spatium;
2016-01-04 14:48:58 +01:00
}
}
}
2016-12-23 12:05:18 +01:00
else if (lineDistance != 1.0) {
// convert to actual distance from top of staff in sp
2017-12-15 16:17:17 +01:00
// ul *= lineDistance;
// dl *= lineDistance;
}
if (tab && !tab->onLines()) { // if TAB and frets above strings, move 1 position up
--ul;
--dl;
}
2018-03-27 15:36:00 +02:00
bool shortenStem = score()->styleB(Sid::shortenStem);
if (hookIdx >= 2 || _tremolo)
shortenStem = false;
2018-03-27 15:36:00 +02:00
Spatium progression = score()->styleS(Sid::shortStemProgression);
qreal shortest = score()->styleS(Sid::shortestStem).val();
if (hookIdx) {
if (up()) {
if (shortest < 3.0)
shortest = 3.0;
}
else {
if (shortest < 3.5)
shortest = 3.5;
}
}
qreal normalStemLen = small() ? 2.5 : 3.5;
normalStemLen += hookAdjustment(score()->styleSt(Sid::MusicalSymbolFont), hookIdx, up(), small());
if (hookIdx && tab == 0) {
if (up() && durationType().dots()) {
//
// avoid collision of dot with hook
//
if (!(ul & 1))
normalStemLen += .5;
shortenStem = false;
}
}
2016-12-23 12:05:18 +01:00
if (isGrace()) {
// grace notes stems are not subject to normal
// stem rules
stemLen = qAbs(ul - dl) * .5;
2018-03-27 15:36:00 +02:00
stemLen += normalStemLen * score()->styleD(Sid::graceNoteMag);
if (up())
stemLen *= -1;
}
else {
// normal note (not grace)
2016-12-13 13:16:17 +01:00
qreal staffHeight = st ? st->lines(tick()) - 1 : 4;
2016-12-23 12:05:18 +01:00
if (!tab)
staffHeight *= lineDistance;
qreal staffHlfHgt = staffHeight * 0.5;
if (up()) { // stem up
qreal dy = dl * .5; // note-side vert. pos.
qreal sel = ul * .5 - normalStemLen; // stem end vert. pos
// if stem ends above top line (with some exceptions), shorten it
2016-05-19 13:15:34 +02:00
if (shortenStem && (sel < 0.0) && (hookIdx == 0 || tab || !downnote->mirror()))
sel -= sel * progression.val();
if (sel > staffHlfHgt) // if stem ends below ('>') staff mid position,
sel = staffHlfHgt; // stretch it to mid position
stemLen = sel - dy; // actual stem length
if (-stemLen < shortest) // is stem too short,
stemLen = -shortest; // lengthen it to shortest possible length
}
else { // stem down
qreal uy = ul * .5; // note-side vert. pos.
qreal sel = dl * .5 + normalStemLen; // stem end vert. pos.
// if stem ends below bottom line (with some exceptions), shorten it
2016-05-19 13:15:34 +02:00
if (shortenStem && (sel > staffHeight) && (hookIdx == 0 || tab || downnote->mirror()))
sel -= (sel - staffHeight) * progression.val();
if (sel < staffHlfHgt) // if stem ends above ('<') staff mid position,
sel = staffHlfHgt; // stretch it to mid position
stemLen = sel - uy; // actual stem length
if (stemLen < shortest) // if stem too short,
stemLen = shortest; // lengthen it to shortest possible position
}
}
// adjust stem len for tremolo
if (_tremolo && !_tremolo->twoNotes() && !_tremolo->placeMidStem()) {
// Use the old algorithm for stem lengthening. It not always
// optimal but still performs better when not placing the tremolo
// at stem middle. TODO: rework minAbsStemLen() to perform
// correctly in this case too.
// hook up odd lines
static const int tab1[2][2][2][4] = {
{ { { 0, 0, 0, 1 }, // stem - down - even - lines
{ 0, 0, 0, 2 } // stem - down - odd - lines
},
{ { 0, 0, 0, -1 }, // stem - up - even - lines
{ 0, 0, 0, -2 } // stem - up - odd - lines
}
},
{ { { 0, 0, 1, 2 }, // hook - down - even - lines
{ 0, 0, 1, 2 } // hook - down - odd - lines
},
{ { 0, 0, -1, -2 }, // hook - up - even - lines
{ 0, 0, -1, -2 } // hook - up - odd - lines
}
}
};
int odd = (up() ? upLine() : downLine()) & 1;
int n = tab1[hookIdx ? 1 : 0][up() ? 1 : 0][odd][_tremolo->lines()-1];
stemLen += n * .5;
}
if (tab)
stemLen *= lineDistance;
const qreal sgn = up() ? -1.0 : 1.0;
qreal stemLenPoints = stemLen * _spatium;
const qreal minAbsStemLen = minAbsStemLength();
if (sgn * stemLenPoints < minAbsStemLen)
stemLenPoints = sgn * minAbsStemLen;
return stemLenPoints;
}
//---------------------------------------------------------
// minAbsStemLength
//---------------------------------------------------------
qreal Chord::minAbsStemLength() const
{
if (!_tremolo || _tremolo->twoNotes() || !_tremolo->placeMidStem())
return 0.0;
int beamLvl = beams();
const bool hasHook = (beamLvl > 0) && !beam();
if (hasHook)
++beamLvl; // reserve more space for stem with both hook and tremolo
const qreal beamDist = beam() ? beam()->beamDist() : (0.5 * spatium());
const qreal tremoloSpacing = 0.5 * spatium(); // TODO: style setting
return beamLvl * beamDist + _tremolo->height() + 2 * tremoloSpacing;
2016-01-04 14:48:58 +01:00
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// layoutStem1
2013-07-13 11:17:47 +02:00
/// Layout _stem and _stemSlash
2012-05-26 14:26:10 +02:00
//
2013-07-13 11:17:47 +02:00
// Called before layout spacing of notes.
// Create stem if necessary.
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
void Chord::layoutStem1()
{
const Staff* stf = staff();
const StaffType* st = stf ? stf->staffType(tick()) : 0;
if (durationType().hasStem() && !(_noStem || (measure() && measure()->stemless(staffIdx())) || (st && st->isTabStaff() && st->stemless()))) {
2013-07-13 11:17:47 +02:00
if (!_stem) {
Stem* stem = new Stem(score());
stem->setParent(this);
stem->setGenerated(true);
score()->undoAddElement(stem);
}
if ((_noteType == NoteType::ACCIACCATURA) && !(beam() && beam()->elements().front() != this)) {
if (!_stemSlash)
add(new StemSlash(score()));
2013-07-13 11:17:47 +02:00
}
else if (_stemSlash)
remove(_stemSlash);
2019-03-24 16:46:57 +01:00
qreal stemWidth5 = _stem->lineWidth() * .5 * mag();
_stem->rxpos() = stemPosX() + (up() ? -stemWidth5 : +stemWidth5);
_stem->setLen(defaultStemLength());
2012-05-26 14:26:10 +02:00
}
else {
if (_stem)
score()->undoRemoveElement(_stem);
if (_stemSlash)
score()->undoRemoveElement(_stemSlash);
}
2013-07-11 12:25:25 +02:00
}
2012-05-26 14:26:10 +02:00
2013-06-20 10:19:04 +02:00
//-----------------------------------------------------------------------------
2012-05-26 14:26:10 +02:00
// layoutStem
/// Layout chord tremolo stem and hook.
//
// hook: sets position
2013-06-20 10:19:04 +02:00
//-----------------------------------------------------------------------------
2012-05-26 14:26:10 +02:00
void Chord::layoutStem()
{
2013-06-10 21:13:04 +02:00
for (Chord* c : _graceNotes)
c->layoutStem();
2016-05-19 13:15:34 +02:00
if (_beam)
2013-06-16 23:33:37 +02:00
return;
2016-05-19 13:15:34 +02:00
// create hooks for unbeamed chords
int hookIdx = durationType().hooks();
if (hookIdx && !(noStem() || measure()->stemless(staffIdx()))) {
2016-05-19 13:15:34 +02:00
if (!hook()) {
Hook* hook = new Hook(score());
hook->setParent(this);
hook->setGenerated(true);
score()->undoAddElement(hook);
}
hook()->setHookType(up() ? hookIdx : -hookIdx);
}
else if (hook())
score()->undoRemoveElement(hook());
//
// TAB
//
const Staff* st = staff();
const StaffType* tab = st ? st->staffType(tick()) : 0;
2017-08-08 14:01:01 +02:00
if (tab && tab->isTabStaff()) {
TAB - Mixing mensural value symbols and beaming in historic tablatures __References__: Technology Preview forum post with discussion, screen-shots and links to additional threads https://musescore.org/en/node/81051 Implements the possibility to mix, in TAB's with note symbols at staff side, mensural value symbols (discreet glyphs) with the 'grid'-shaped beaming found in historical sources and commonly used in lute literature. The beaming is implemented by special drawing of the `TabDurationSymbol` element holding the note value symbol, using drawing primitives instead of the relevant font glyph. The user may choose between the two renderings (discreet glyph or beaming grid), on a chord-by-chord basis, by setting the chord `BeamMode` (via for instance the relevant palette): `AUTO` selects the glyph rendering, `beam start` the start of the grid and `beam middle` the continuation of the grid beamed to the previous element. Typographic features of the grid (stem width, stem height and beam thickness) depend on the glyph style and are hard-coded in the style definition. As well as the number of beams for note value, which also depends on the note value style. Also: - Implements to possibility to force the display of a note value which would not be rendered by the current note value repetition setting, by setting the chord beam mode to any other value. - Implements the 'no stem' chord setting for this TAB style, allowing to remove a note value symbol otherwise generated by the current repetition setting. - Improves the detection of note value font metrics (still not perfect, though, as Qt `QFontMetricsF::tightboundingRect()` returns very approximated results) - Fixes note value glyph scaling, when the staff scale is modified.
2015-09-27 13:33:05 +02:00
// if stemless TAB
if (tab->stemless()) {
TAB - Mixing mensural value symbols and beaming in historic tablatures __References__: Technology Preview forum post with discussion, screen-shots and links to additional threads https://musescore.org/en/node/81051 Implements the possibility to mix, in TAB's with note symbols at staff side, mensural value symbols (discreet glyphs) with the 'grid'-shaped beaming found in historical sources and commonly used in lute literature. The beaming is implemented by special drawing of the `TabDurationSymbol` element holding the note value symbol, using drawing primitives instead of the relevant font glyph. The user may choose between the two renderings (discreet glyph or beaming grid), on a chord-by-chord basis, by setting the chord `BeamMode` (via for instance the relevant palette): `AUTO` selects the glyph rendering, `beam start` the start of the grid and `beam middle` the continuation of the grid beamed to the previous element. Typographic features of the grid (stem width, stem height and beam thickness) depend on the glyph style and are hard-coded in the style definition. As well as the number of beams for note value, which also depends on the note value style. Also: - Implements to possibility to force the display of a note value which would not be rendered by the current note value repetition setting, by setting the chord beam mode to any other value. - Implements the 'no stem' chord setting for this TAB style, allowing to remove a note value symbol otherwise generated by the current repetition setting. - Improves the detection of note value font metrics (still not perfect, though, as Qt `QFontMetricsF::tightboundingRect()` returns very approximated results) - Fixes note value glyph scaling, when the staff scale is modified.
2015-09-27 13:33:05 +02:00
// if 'grid' duration symbol of MEDIALFINAL type, it is time to compute its width
if (_tabDur != nullptr && _tabDur->beamGrid() == TabBeamGrid::MEDIALFINAL)
_tabDur->layout2();
// in all other stemless cases, do nothing
return;
}
// not a stemless TAB; if stems are beside staff, apply special formatting
if (!tab->stemThrough()) {
if (_stem) { // (duplicate code with defaultStemLength())
// process stem:
_stem->setLen(tab->chordStemLength(this) * spatium());
// process hook
hookIdx = durationType().hooks();
if (!up())
hookIdx = -hookIdx;
if (hookIdx && _hook) {
_hook->setHookType(hookIdx);
2017-12-05 09:44:13 +01:00
#if 0
_hook->layout();
QPointF p(_stem->hookPos());
2013-11-07 19:58:42 +01:00
if (up()) {
2017-12-05 09:44:13 +01:00
p.ry() -= _hook->bbox().top();
p.rx() -= _stem->width();
2013-11-07 19:58:42 +01:00
}
else {
2017-12-05 09:44:13 +01:00
p.ry() -= _hook->bbox().bottom();
p.rx() -= _stem->width();
2013-11-07 19:58:42 +01:00
}
2017-12-05 09:44:13 +01:00
_hook->setPos(p);
#endif
}
2012-05-26 14:26:10 +02:00
}
TAB - Mixing mensural value symbols and beaming in historic tablatures __References__: Technology Preview forum post with discussion, screen-shots and links to additional threads https://musescore.org/en/node/81051 Implements the possibility to mix, in TAB's with note symbols at staff side, mensural value symbols (discreet glyphs) with the 'grid'-shaped beaming found in historical sources and commonly used in lute literature. The beaming is implemented by special drawing of the `TabDurationSymbol` element holding the note value symbol, using drawing primitives instead of the relevant font glyph. The user may choose between the two renderings (discreet glyph or beaming grid), on a chord-by-chord basis, by setting the chord `BeamMode` (via for instance the relevant palette): `AUTO` selects the glyph rendering, `beam start` the start of the grid and `beam middle` the continuation of the grid beamed to the previous element. Typographic features of the grid (stem width, stem height and beam thickness) depend on the glyph style and are hard-coded in the style definition. As well as the number of beams for note value, which also depends on the note value style. Also: - Implements to possibility to force the display of a note value which would not be rendered by the current note value repetition setting, by setting the chord beam mode to any other value. - Implements the 'no stem' chord setting for this TAB style, allowing to remove a note value symbol otherwise generated by the current repetition setting. - Improves the detection of note value font metrics (still not perfect, though, as Qt `QFontMetricsF::tightboundingRect()` returns very approximated results) - Fixes note value glyph scaling, when the staff scale is modified.
2015-09-27 13:33:05 +02:00
return;
2012-05-26 14:26:10 +02:00
}
TAB - Mixing mensural value symbols and beaming in historic tablatures __References__: Technology Preview forum post with discussion, screen-shots and links to additional threads https://musescore.org/en/node/81051 Implements the possibility to mix, in TAB's with note symbols at staff side, mensural value symbols (discreet glyphs) with the 'grid'-shaped beaming found in historical sources and commonly used in lute literature. The beaming is implemented by special drawing of the `TabDurationSymbol` element holding the note value symbol, using drawing primitives instead of the relevant font glyph. The user may choose between the two renderings (discreet glyph or beaming grid), on a chord-by-chord basis, by setting the chord `BeamMode` (via for instance the relevant palette): `AUTO` selects the glyph rendering, `beam start` the start of the grid and `beam middle` the continuation of the grid beamed to the previous element. Typographic features of the grid (stem width, stem height and beam thickness) depend on the glyph style and are hard-coded in the style definition. As well as the number of beams for note value, which also depends on the note value style. Also: - Implements to possibility to force the display of a note value which would not be rendered by the current note value repetition setting, by setting the chord beam mode to any other value. - Implements the 'no stem' chord setting for this TAB style, allowing to remove a note value symbol otherwise generated by the current repetition setting. - Improves the detection of note value font metrics (still not perfect, though, as Qt `QFontMetricsF::tightboundingRect()` returns very approximated results) - Fixes note value glyph scaling, when the staff scale is modified.
2015-09-27 13:33:05 +02:00
// if stems are through staff, use standard formatting
2012-05-26 14:26:10 +02:00
}
//
// NON-TAB (or TAB with stems through staff)
//
2012-05-26 14:26:10 +02:00
if (_stem) {
if (_hook) {
2016-01-04 14:48:58 +01:00
_hook->layout();
2013-11-07 19:58:42 +01:00
QPointF p(_stem->hookPos());
if (up()) {
p.ry() -= _hook->bbox().top();
p.rx() -= _stem->width();
}
else {
p.ry() -= _hook->bbox().bottom();
p.rx() -= _stem->width();
}
_hook->setPos(p);
2012-05-26 14:26:10 +02:00
}
if (_stemSlash)
_stemSlash->layout();
2012-05-26 14:26:10 +02:00
}
//-----------------------------------------
// process tremolo
//-----------------------------------------
// if (_tremolo)
// _tremolo->layout();
2012-05-26 14:26:10 +02:00
}
2014-04-23 18:07:38 +02:00
//---------------------------------------------------------
// underBeam: true, if grace note is placed under a beam.
//---------------------------------------------------------
bool Chord::underBeam() const
{
2017-08-08 14:01:01 +02:00
if (_noteType == NoteType::NORMAL)
2014-04-23 18:07:38 +02:00
return false;
2017-08-08 14:01:01 +02:00
const Chord* cr = toChord(parent());
2014-04-23 18:07:38 +02:00
Beam* beam = cr->beam();
if(!beam || !cr->beam()->up())
return false;
int s = beam->elements().count();
2017-08-08 14:01:01 +02:00
if (isGraceBefore()){
if (beam->elements()[0] != cr)
2014-04-23 18:07:38 +02:00
return true;
}
2017-08-08 14:01:01 +02:00
if (isGraceAfter()){
if (beam->elements()[s - 1] != cr)
2014-04-23 18:07:38 +02:00
return true;
}
return false;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// layout2
// Called after horizontal positions of all elements
// are fixed.
//---------------------------------------------------------
void Chord::layout2()
{
2013-06-10 21:13:04 +02:00
for (Chord* c : _graceNotes)
c->layout2();
qreal mag = staff()->mag(tick());
2012-05-26 14:26:10 +02:00
//
// position after-chord grace notes
// room for them has been reserved in Chord::layout()
//
2016-02-06 22:03:43 +01:00
QVector<Chord*> gna = graceNotesAfter();
if (!gna.empty()) {
qreal minNoteDist = score()->styleP(Sid::minNoteDistance) * mag * score()->styleD(Sid::graceNoteMag);
// position grace notes from the rightmost to the leftmost
// get segment (of whatever type) at the end of this chord; if none, get measure last segment
2017-03-08 13:12:26 +01:00
Segment* s = measure()->tick2segment(segment()->tick() + actualTicks(), SegmentType::All);
if (s == nullptr)
s = measure()->last();
if (s == segment()) // if our segment is the last, no adjacent segment found
s = nullptr;
// start from the right (if next segment found, x of it relative to this chord;
// chord right space otherwise)
Chord* last = gna.last();
qreal xOff = s ? (s->pos().x() - s->staffShape(last->vStaffIdx()).left()) - (segment()->pos().x() + pos().x()) : _spaceRw;
// final distance: if near to another chord, leave minNoteDist at right of last grace
// else leave note-to-barline distance;
2017-03-08 13:12:26 +01:00
xOff -= (s != nullptr && s->segmentType() != SegmentType::ChordRest)
? score()->styleP(Sid::noteBarDistance) * mag
: minNoteDist;
// scan grace note list from the end
2015-02-19 10:28:25 +01:00
int n = gna.size();
for (int i = n-1; i >= 0; i--) {
Chord* g = gna.value(i);
2016-02-04 11:27:47 +01:00
xOff -= g->_spaceRw; // move to left by grace note left space (incl. grace own width)
g->rxpos() = xOff;
2016-02-04 11:27:47 +01:00
xOff -= minNoteDist + g->_spaceLw; // move to left by grace note right space and inter-grace distance
}
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// updatePercussionNotes
//---------------------------------------------------------
static void updatePercussionNotes(Chord* c, const Drumset* drumset)
{
for (Chord* ch : c->graceNotes())
updatePercussionNotes(ch, drumset);
std::vector<Note*> lnotes(c->notes()); // we need a copy!
for (Note* note : lnotes) {
if (!drumset)
note->setLine(0);
else {
int pitch = note->pitch();
if (!drumset->isValid(pitch)) {
note->setLine(0);
qWarning("unmapped drum note %d", pitch);
}
else if (!note->fixed()) {
2018-03-27 15:36:00 +02:00
note->undoChangeProperty(Pid::HEAD_GROUP, int(drumset->noteHead(pitch)));
note->setLine(drumset->line(pitch));
}
}
}
}
2014-04-22 17:02:03 +02:00
//---------------------------------------------------------
// cmdUpdateNotes
//---------------------------------------------------------
void Chord::cmdUpdateNotes(AccidentalState* as)
{
// TAB_STAFF is different, as each note has to be fretted
// in the context of the all of the chords of the whole segment
const Staff* st = staff();
StaffGroup staffGroup = st->staffType(tick())->group();
if (staffGroup == StaffGroup::TAB) {
const Instrument* instrument = part()->instrument();
2014-04-22 17:02:03 +02:00
for (Chord* ch : graceNotes())
instrument->stringData()->fretChords(ch);
instrument->stringData()->fretChords(this);
return;
}
// PITCHED_ and PERCUSSION_STAFF can go note by note
if (staffGroup == StaffGroup::STANDARD) {
for (Chord* ch : graceNotesBefore()) {
2016-02-06 22:03:43 +01:00
std::vector<Note*> notes(ch->notes()); // we need a copy!
2015-02-19 10:28:25 +01:00
for (Note* note : notes)
note->updateAccidental(as);
ch->sortNotes();
}
2016-12-23 12:05:18 +01:00
std::vector<Note*> lnotes(notes()); // we need a copy!
for (Note* note : lnotes) {
if (note->tieBack() && note->tpc() == note->tieBack()->startNote()->tpc()) {
// same pitch
if (note->accidental() && note->accidental()->role() == AccidentalRole::AUTO) {
// not courtesy
2014-04-22 17:02:03 +02:00
// TODO: remove accidental only if note is not
// on new system
score()->undoRemoveElement(note->accidental());
}
}
note->updateAccidental(as);
}
for (Chord* ch : graceNotesAfter()) {
std::vector<Note*> notes(ch->notes()); // we need a copy!
for (Note* note : notes)
note->updateAccidental(as);
ch->sortNotes();
}
}
else if (staffGroup == StaffGroup::PERCUSSION) {
const Instrument* instrument = part()->instrument();
const Drumset* drumset = instrument->drumset();
if (!drumset)
qWarning("no drumset");
updatePercussionNotes(this, drumset);
2014-04-22 17:02:03 +02:00
}
2014-04-22 17:02:03 +02:00
sortNotes();
}
//---------------------------------------------------------
// pagePos
//---------------------------------------------------------
QPointF Chord::pagePos() const
{
if (isGrace()) {
QPointF p(pos());
if (parent() == 0)
return p;
p.rx() = pageX();
const Chord* pc = static_cast<const Chord*>(parent());
System* system = pc->segment()->system();
2015-08-28 15:58:42 +02:00
if (!system)
return p;
2016-04-01 14:57:24 +02:00
p.ry() += system->staffYpage(vStaffIdx());
return p;
}
return Element::pagePos();
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Chord::layout()
{
if (_notes.empty())
return;
2016-12-13 13:16:17 +01:00
if (staff() && staff()->isTabStaff(tick()))
2013-05-23 15:39:14 +02:00
layoutTablature();
else
2013-06-16 23:33:37 +02:00
layoutPitched();
2013-05-23 15:39:14 +02:00
}
2012-05-26 14:26:10 +02:00
2013-05-23 15:39:14 +02:00
//---------------------------------------------------------
2013-06-16 23:33:37 +02:00
// layoutPitched
2013-05-23 15:39:14 +02:00
//---------------------------------------------------------
2013-06-16 23:33:37 +02:00
void Chord::layoutPitched()
2013-05-23 15:39:14 +02:00
{
int gi = 0;
for (Chord* c : _graceNotes) {
// HACK: graceIndex is not well-maintained on add & remove
// so rebuild now
c->setGraceIndex(gi++);
if (c->isGraceBefore())
c->layoutPitched();
}
2016-02-06 22:03:43 +01:00
QVector<Chord*> graceNotesBefore = Chord::graceNotesBefore();
2015-02-19 10:28:25 +01:00
int gnb = graceNotesBefore.size();
// lay out grace notes after separately so they are processed left to right
// (they are normally stored right to left)
2015-02-19 10:28:25 +01:00
2016-02-06 22:03:43 +01:00
QVector<Chord*> gna = graceNotesAfter();
2015-02-19 10:28:25 +01:00
for (Chord* c : gna)
c->layoutPitched();
2013-06-19 16:25:29 +02:00
2016-01-04 14:48:58 +01:00
qreal _spatium = spatium();
qreal mag_ = staff() ? staff()->mag(tick()) : 1.0; // palette elements do not have a staff
qreal dotNoteDistance = score()->styleP(Sid::dotNoteDistance) * mag_;
qreal minNoteDistance = score()->styleP(Sid::minNoteDistance) * mag_;
qreal minTieLength = score()->styleP(Sid::MinTieLength) * mag_;
2016-03-02 13:20:19 +01:00
2018-03-27 15:36:00 +02:00
qreal graceMag = score()->styleD(Sid::graceNoteMag);
2016-01-04 14:48:58 +01:00
qreal chordX = (_noteType == NoteType::NORMAL) ? ipos().x() : 0.0;
2012-05-26 14:26:10 +02:00
while (_ledgerLines) {
LedgerLine* l = _ledgerLines->next();
delete _ledgerLines;
_ledgerLines = l;
}
2012-05-26 14:26:10 +02:00
2013-06-19 16:25:29 +02:00
qreal lll = 0.0; // space to leave at left of chord
qreal rrr = 0.0; // space to leave at right of chord
qreal lhead = 0.0; // amount of notehead to left of chord origin
2013-06-19 16:25:29 +02:00
Note* upnote = upNote();
2012-05-26 14:26:10 +02:00
2013-05-23 15:39:14 +02:00
delete _tabDur; // no TAB? no duration symbol! (may happen when converting a TAB into PITCHED)
_tabDur = 0;
if (!segment()) {
2012-05-26 14:26:10 +02:00
//
2013-05-23 15:39:14 +02:00
// hack for use in palette
2012-05-26 14:26:10 +02:00
//
size_t n = _notes.size();
for (size_t i = 0; i < n; i++) {
Note* note = _notes.at(i);
2012-05-26 14:26:10 +02:00
note->layout();
2013-05-23 15:39:14 +02:00
qreal x = 0.0;
qreal y = note->line() * _spatium * .5;
note->setPos(x, y);
2012-05-26 14:26:10 +02:00
}
2013-05-23 15:39:14 +02:00
computeUp();
layoutStem1();
if (_stem) { //false when dragging notes from drum palette
qreal stemWidth5 = _stem->lineWidth() * .5;
_stem->rxpos() = up() ? (upNote()->headBodyWidth() - stemWidth5) : stemWidth5;
}
addLedgerLines();
2013-05-23 15:39:14 +02:00
return;
}
//-----------------------------------------
// process notes
//-----------------------------------------
2016-02-06 22:03:43 +01:00
for (Note* note : _notes) {
2013-05-23 15:39:14 +02:00
note->layout();
2013-05-23 16:58:22 +02:00
2014-05-22 08:49:57 +02:00
qreal x1 = note->pos().x() + chordX;
2013-05-23 16:58:22 +02:00
qreal x2 = x1 + note->headWidth();
lll = qMax(lll, -x1);
rrr = qMax(rrr, x2);
// track amount of space due to notehead only
lhead = qMax(lhead, -x1);
2013-05-23 15:39:14 +02:00
Accidental* accidental = note->accidental();
if (accidental && !note->fixed()) {
2014-03-25 18:33:53 +01:00
// convert x position of accidental to segment coordinate system
2014-05-22 08:49:57 +02:00
qreal x = accidental->pos().x() + note->pos().x() + chordX;
// distance from accidental to note already taken into account
// but here perhaps we create more padding in *front* of accidental?
x -= score()->styleP(Sid::accidentalDistance) * mag_;
2013-07-18 17:01:45 +02:00
lll = qMax(lll, -x);
2012-05-26 14:26:10 +02:00
}
2014-02-22 21:29:29 +01:00
// allow extra space for shortened ties
// this code must be kept synchronized
// with the tie positioning code in Tie::slurPos()
// but the allocation of space needs to be performed here
2014-02-22 21:29:29 +01:00
Tie* tie;
tie = note->tieBack();
if (tie) {
tie->calculateDirection();
qreal overlap = 0.0;
bool shortStart = false;
2014-02-23 17:16:39 +01:00
Note* sn = tie->startNote();
Chord* sc = sn->chord();
2014-02-24 18:01:55 +01:00
if (sc && sc->measure() == measure() && sc == prevChordRest(this)) {
2014-02-23 17:16:39 +01:00
if (sc->notes().size() > 1 || (sc->stem() && sc->up() == tie->up())) {
shortStart = true;
2014-02-23 17:16:39 +01:00
if (sc->width() > sn->width()) {
// chord with second?
// account for noteheads further to right
qreal snEnd = sn->x() + sn->bboxRightPos();
2014-02-23 17:16:39 +01:00
qreal scEnd = snEnd;
2016-02-06 22:03:43 +01:00
for (unsigned i = 0; i < sc->notes().size(); ++i)
scEnd = qMax(scEnd, sc->notes().at(i)->x() + sc->notes().at(i)->bboxRightPos());
overlap += scEnd - snEnd;
2014-02-23 17:16:39 +01:00
}
else
overlap -= sn->headWidth() * 0.12;
2014-02-23 17:16:39 +01:00
}
else
overlap += sn->headWidth() * 0.35;
2014-02-23 17:16:39 +01:00
if (notes().size() > 1 || (stem() && !up() && !tie->up())) {
// for positive offset:
// use available space
// for negative x offset:
// space is allocated elsewhere, so don't re-allocate here
if (note->ipos().x() != 0.0)
overlap += qAbs(note->ipos().x());
else
overlap -= note->headWidth() * 0.12;
}
else {
if (shortStart)
overlap += note->headWidth() * 0.15;
else
overlap += note->headWidth() * 0.35;
2014-02-23 17:16:39 +01:00
}
qreal d = qMax(minTieLength - overlap, 0.0);
2014-02-22 21:29:29 +01:00
lll = qMax(lll, d);
}
}
// clear layout for note-based fingerings
for (Element* e : note->el()) {
if (e->isFingering()) {
Fingering* f = toFingering(e);
if (f->layoutType() == ElementType::NOTE) {
f->setPos(QPointF());
f->setbbox(QRectF());
}
}
}
2013-05-23 15:39:14 +02:00
}
//-----------------------------------------
// create ledger lines
//-----------------------------------------
2013-05-24 11:44:21 +02:00
addLedgerLines();
2013-05-23 15:39:14 +02:00
if (_arpeggio) {
qreal arpeggioDistance = score()->styleP(Sid::ArpeggioNoteDistance) * mag_;
2013-11-19 12:12:07 +01:00
_arpeggio->layout(); // only for width() !
_arpeggio->setHeight(0.0);
lll += _arpeggio->width() + arpeggioDistance + chordX;
2013-11-19 12:12:07 +01:00
qreal y1 = upnote->pos().y() - upnote->headHeight() * .5;
_arpeggio->setPos(-lll, y1);
// _arpeggio->layout() called in layoutArpeggio2()
2013-05-23 15:39:14 +02:00
// handle the special case of _arpeggio->span() > 1
// in layoutArpeggio2() after page layout has done so we
// know the y position of the next staves
}
2014-05-27 05:04:49 +02:00
// allocate enough room for glissandi
if (_endsGlissando) {
if (!rtick().isZero() // if not at beginning of measure
|| graceNotesBefore.size() > 0) // or there are graces before
lll += _spatium * 0.5 + minTieLength;
// special case of system-initial glissando final note is handled in Glissando::layout() itself
2014-05-27 05:04:49 +02:00
}
2013-05-23 15:39:14 +02:00
if (dots()) {
qreal x = dotPosX() + dotNoteDistance
+ (dots()-1) * score()->styleP(Sid::dotDotDistance) * mag_;
2013-11-11 15:11:28 +01:00
x += symWidth(SymId::augmentationDot);
2013-07-18 17:01:45 +02:00
rrr = qMax(rrr, x);
2013-05-23 15:39:14 +02:00
}
if (_hook) {
if (beam())
score()->undoRemoveElement(_hook);
2012-05-26 14:26:10 +02:00
else {
2013-05-23 15:39:14 +02:00
_hook->layout();
if (up() && stem()) {
2013-05-23 15:39:14 +02:00
// hook position is not set yet
2014-05-22 08:49:57 +02:00
qreal x = _hook->bbox().right() + stem()->hookPos().x() + chordX;
2013-05-23 15:39:14 +02:00
rrr = qMax(rrr, x);
2012-05-26 14:26:10 +02:00
}
2013-05-23 15:39:14 +02:00
}
}
2012-05-26 14:26:10 +02:00
#if 0
if (!_articulations.isEmpty()) {
// TODO: allocate space to avoid "staircase" effect
// but we would need to determine direction in order to get correct symid & bbox
// another alternative is to limit the width contribution of the articulation in layoutArticulations2()
//qreal aWidth = 0.0;
for (Articulation* a : articulations())
a->layout(); // aWidth = qMax(aWidth, a->width());
//qreal w = width();
//qreal aExtra = (qMax(aWidth, w) - w) * 0.5;
//lll = qMax(lll, aExtra);
//rrr = qMax(rrr, aExtra);
}
#endif
2016-01-04 14:48:58 +01:00
_spaceLw = lll;
_spaceRw = rrr;
2013-05-23 15:39:14 +02:00
2018-12-03 12:31:31 +01:00
if (gnb) {
2016-02-04 11:27:47 +01:00
qreal xl = -(_spaceLw + minNoteDistance) - chordX;
for (int i = gnb-1; i >= 0; --i) {
Chord* g = graceNotesBefore.value(i);
2016-01-04 14:48:58 +01:00
xl -= g->_spaceRw/* * 1.2*/;
g->setPos(xl, 0);
2016-01-04 14:48:58 +01:00
xl -= g->_spaceLw + minNoteDistance * graceMag;
2014-04-23 18:07:38 +02:00
}
2016-01-04 14:48:58 +01:00
if (-xl > _spaceLw)
_spaceLw = -xl;
2014-04-23 18:07:38 +02:00
}
2016-02-06 22:03:43 +01:00
if (!gna.empty()) {
2016-01-04 14:48:58 +01:00
qreal xr = _spaceRw;
2015-02-19 10:28:25 +01:00
int n = gna.size();
for (int i = 0; i <= n - 1; i++) {
Chord* g = gna.value(i);
2016-01-04 14:48:58 +01:00
xr += g->_spaceLw + g->_spaceRw + minNoteDistance * graceMag;
}
2016-01-04 14:48:58 +01:00
if (xr > _spaceRw)
_spaceRw = xr;
2014-04-23 18:07:38 +02:00
}
2012-05-26 14:26:10 +02:00
2016-12-06 09:35:52 +01:00
for (Element* e : el()) {
2017-01-18 14:16:33 +01:00
if (e->type() == ElementType::SLUR) // we cannot at this time as chordpositions are not fixed
2013-06-20 17:23:24 +02:00
continue;
e->layout();
2017-01-18 14:16:33 +01:00
if (e->type() == ElementType::CHORDLINE) {
QRectF tbbox = e->bbox().translated(e->pos());
2014-05-22 08:49:57 +02:00
qreal lx = tbbox.left() + chordX;
qreal rx = tbbox.right() + chordX;
2016-01-04 14:48:58 +01:00
if (-lx > _spaceLw)
_spaceLw = -lx;
if (rx > _spaceRw)
_spaceRw = rx;
2013-06-16 23:33:37 +02:00
}
2013-06-12 14:23:57 +02:00
}
2016-02-06 11:41:16 +01:00
for (Note* note : _notes)
note->layout2();
// align note-based fingerings
std::vector<Fingering*> alignNote;
qreal xNote = 10000.0;
for (Note* note : _notes) {
bool leftFound = false;
for (Element* e : note->el()) {
if (e->isFingering() && e->autoplace()) {
Fingering* f = toFingering(e);
if (f->layoutType() == ElementType::NOTE && f->tid() == Tid::LH_GUITAR_FINGERING) {
alignNote.push_back(f);
if (!leftFound) {
leftFound = true;
qreal xf = f->ipos().x();
xNote = qMin(xNote, xf);
}
}
}
}
}
for (Fingering* f : alignNote)
f->rxpos() = xNote;
2013-05-23 15:39:14 +02:00
}
2012-05-26 14:26:10 +02:00
2013-05-23 15:39:14 +02:00
//---------------------------------------------------------
// layoutTablature
//---------------------------------------------------------
2012-05-26 14:26:10 +02:00
2013-05-23 15:39:14 +02:00
void Chord::layoutTablature()
{
qreal _spatium = spatium();
2018-03-27 15:36:00 +02:00
qreal dotNoteDistance = score()->styleP(Sid::dotNoteDistance);
qreal minNoteDistance = score()->styleP(Sid::minNoteDistance);
qreal minTieLength = score()->styleP(Sid::MinTieLength);
2013-01-02 09:29:17 +01:00
for (Chord* c : _graceNotes)
c->layoutTablature();
2013-05-23 15:39:14 +02:00
while (_ledgerLines) {
LedgerLine* l = _ledgerLines->next();
delete _ledgerLines;
_ledgerLines = l;
}
2013-01-02 14:33:23 +01:00
qreal lll = 0.0; // space to leave at left of chord
qreal rrr = 0.0; // space to leave at right of chord
Note* upnote = upNote();
2013-11-11 15:11:28 +01:00
qreal headWidth = symWidth(SymId::noteheadBlack);
const Staff* st = staff();
const StaffType* tab = st->staffType(tick());
qreal lineDist = tab->lineDistance().val() *_spatium;
qreal stemX = tab->chordStemPosX(this) *_spatium;
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
int ledgerLines = 0;
qreal llY = 0.0;
2012-05-26 14:26:10 +02:00
size_t numOfNotes = _notes.size();
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
qreal minY = 1000.0; // just a very large value
for (size_t i = 0; i < numOfNotes; ++i) {
2013-05-23 15:39:14 +02:00
Note* note = _notes.at(i);
note->layout();
// set headWidth to max fret text width
qreal fretWidth = note->bbox().width();
if (headWidth < fretWidth)
headWidth = fretWidth;
// centre fret string on stem
qreal x = stemX - fretWidth*0.5;
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
qreal y = note->fixed() ? note->line() * lineDist / 2 : tab->physStringToYOffset(note->string()) * _spatium;
note->setPos(x, y);
if (y < minY)
minY = y;
int currLedgerLines = tab->numOfTabLedgerLines(note->string());
if (currLedgerLines > ledgerLines) {
ledgerLines = currLedgerLines;
llY = y;
}
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
// allow extra space for shortened ties; this code must be kept synchronized
// with the tie positioning code in Tie::slurPos()
// but the allocation of space needs to be performed here
Tie* tie;
tie = note->tieBack();
if (tie) {
tie->calculateDirection();
qreal overlap = 0.0; // how much tie can overlap start and end notes
bool shortStart = false; // whether tie should clear start note or not
Note* startNote = tie->startNote();
Chord* startChord = startNote->chord();
if (startChord && startChord->measure() == measure() && startChord == prevChordRest(this)) {
qreal startNoteWidth = startNote->width();
// overlap into start chord?
// if in start chord, there are several notes or stem and tie in same direction
if (startChord->notes().size() > 1 || (startChord->stem() && startChord->up() == tie->up())) {
// clear start note (1/8 of fret mark width)
shortStart = true;
overlap -= startNoteWidth * 0.125;
}
else // overlap start note (by ca. 1/3 of fret mark width)
overlap += startNoteWidth * 0.35;
// overlap into end chord (this)?
// if several notes or neither stem or tie are up
if (notes().size() > 1 || (stem() && !up() && !tie->up())) {
// for positive offset:
// use available space
// for negative x offset:
// space is allocated elsewhere, so don't re-allocate here
if (note->ipos().x() != 0.0) // this probably does not work for TAB, as
overlap += qAbs(note->ipos().x()); // _pos is used to centre the fret on the stem
else
overlap -= fretWidth * 0.125;
}
else {
if (shortStart)
overlap += fretWidth * 0.15;
else
overlap += fretWidth * 0.35;
}
qreal d = qMax(minTieLength - overlap, 0.0);
lll = qMax(lll, d);
}
}
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
}
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
// create ledger lines, if required (in some historic styles)
if (ledgerLines > 0) {
// there seems to be no need for widening 'ledger lines' beyond fret mark widths; more 'on the field'
// tests and usage will show if this depends on the metrics of the specific fonts used or not.
2018-03-27 15:36:00 +02:00
// qreal extraLen = score()->styleS(Sid::ledgerLineLength).val() * _spatium;
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
qreal extraLen = 0;
qreal llX = stemX - (headWidth + extraLen) * 0.5;
for (int i = 0; i < ledgerLines; i++) {
LedgerLine* ldgLin = new LedgerLine(score());
ldgLin->setParent(this);
ldgLin->setTrack(track());
2016-10-20 11:32:07 +02:00
ldgLin->setVisible(visible());
2016-09-03 17:45:59 +02:00
ldgLin->setLen(headWidth + extraLen);
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
ldgLin->setPos(llX, llY);
ldgLin->setNext(_ledgerLines);
_ledgerLines = ldgLin;
ldgLin->layout();
llY += lineDist / ledgerLines;
}
headWidth += extraLen; // include ledger lines extra width in chord width
2013-05-23 15:39:14 +02:00
}
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
2013-05-23 15:39:14 +02:00
// horiz. spacing: leave half width at each side of the (potential) stem
qreal halfHeadWidth = headWidth * 0.5;
if (lll < stemX - halfHeadWidth)
lll = stemX - halfHeadWidth;
if (rrr < stemX + halfHeadWidth)
rrr = stemX + halfHeadWidth;
// align dots to the widest fret mark (not needed in all TAB styles, but harmless anyway)
if (segment())
segment()->setDotPosX(staffIdx(), headWidth);
2013-05-23 15:39:14 +02:00
// if tab type is stemless or chord is stemless (possible when imported from MusicXML)
// or measure is stemless
2013-05-23 15:39:14 +02:00
// or duration longer than half (if halves have stems) or duration longer than crochet
// remove stems
if (tab->stemless() || _noStem || measure()->stemless(staffIdx()) || durationType().type() <
(tab->minimStyle() != TablatureMinimStyle::NONE ? TDuration::DurationType::V_HALF : TDuration::DurationType::V_QUARTER) ) {
2014-08-13 16:36:09 +02:00
if (_stem)
score()->undo(new RemoveElement(_stem));
if (_hook)
score()->undo(new RemoveElement(_hook));
if (_beam)
score()->undo(new RemoveElement(_beam));
2013-05-23 15:39:14 +02:00
}
// if stem is required but missing, add it;
// set stem position (stem length is set in Chord:layoutStem() )
else {
if (_stem == 0) {
Stem* stem = new Stem(score());
stem->setParent(this);
score()->undo(new AddElement(stem));
}
2013-05-23 15:39:14 +02:00
_stem->setPos(tab->chordStemPos(this) * _spatium);
if (_hook) {
2013-07-11 14:44:35 +02:00
if (beam())
score()->undoRemoveElement(_hook);
2013-05-23 15:39:14 +02:00
else {
_hook->layout();
if (rrr < stemX + _hook->width())
rrr = stemX + _hook->width();
2017-12-05 09:44:13 +01:00
QPointF p(_stem->hookPos());
if (up()) {
p.ry() -= _hook->bbox().top();
p.rx() -= _stem->width();
}
else {
p.ry() -= _hook->bbox().bottom();
p.rx() -= _stem->width();
}
_hook->setPos(p);
2013-03-04 12:00:02 +01:00
}
2012-05-26 14:26:10 +02:00
}
}
if (!tab->genDurations() // if tab is not set for duration symbols
|| track2voice(track()) // or not in first voice
|| (isGrace() // no tab duration symbols if grace notes
&& beamMode() == Beam::Mode::AUTO)) { // and beammode == AUTO
//
2013-05-23 15:39:14 +02:00
delete _tabDur; // delete an existing duration symbol
_tabDur = 0;
}
else {
//
// tab duration symbols
//
// if no previous CR
TAB - Mixing mensural value symbols and beaming in historic tablatures __References__: Technology Preview forum post with discussion, screen-shots and links to additional threads https://musescore.org/en/node/81051 Implements the possibility to mix, in TAB's with note symbols at staff side, mensural value symbols (discreet glyphs) with the 'grid'-shaped beaming found in historical sources and commonly used in lute literature. The beaming is implemented by special drawing of the `TabDurationSymbol` element holding the note value symbol, using drawing primitives instead of the relevant font glyph. The user may choose between the two renderings (discreet glyph or beaming grid), on a chord-by-chord basis, by setting the chord `BeamMode` (via for instance the relevant palette): `AUTO` selects the glyph rendering, `beam start` the start of the grid and `beam middle` the continuation of the grid beamed to the previous element. Typographic features of the grid (stem width, stem height and beam thickness) depend on the glyph style and are hard-coded in the style definition. As well as the number of beams for note value, which also depends on the note value style. Also: - Implements to possibility to force the display of a note value which would not be rendered by the current note value repetition setting, by setting the chord beam mode to any other value. - Implements the 'no stem' chord setting for this TAB style, allowing to remove a note value symbol otherwise generated by the current repetition setting. - Improves the detection of note value font metrics (still not perfect, though, as Qt `QFontMetricsF::tightboundingRect()` returns very approximated results) - Fixes note value glyph scaling, when the staff scale is modified.
2015-09-27 13:33:05 +02:00
// OR symbol repeat set to ALWAYS
// OR symbol repeat condition is triggered
2013-05-23 15:39:14 +02:00
// OR duration type and/or number of dots is different from current CR
TAB - Mixing mensural value symbols and beaming in historic tablatures __References__: Technology Preview forum post with discussion, screen-shots and links to additional threads https://musescore.org/en/node/81051 Implements the possibility to mix, in TAB's with note symbols at staff side, mensural value symbols (discreet glyphs) with the 'grid'-shaped beaming found in historical sources and commonly used in lute literature. The beaming is implemented by special drawing of the `TabDurationSymbol` element holding the note value symbol, using drawing primitives instead of the relevant font glyph. The user may choose between the two renderings (discreet glyph or beaming grid), on a chord-by-chord basis, by setting the chord `BeamMode` (via for instance the relevant palette): `AUTO` selects the glyph rendering, `beam start` the start of the grid and `beam middle` the continuation of the grid beamed to the previous element. Typographic features of the grid (stem width, stem height and beam thickness) depend on the glyph style and are hard-coded in the style definition. As well as the number of beams for note value, which also depends on the note value style. Also: - Implements to possibility to force the display of a note value which would not be rendered by the current note value repetition setting, by setting the chord beam mode to any other value. - Implements the 'no stem' chord setting for this TAB style, allowing to remove a note value symbol otherwise generated by the current repetition setting. - Improves the detection of note value font metrics (still not perfect, though, as Qt `QFontMetricsF::tightboundingRect()` returns very approximated results) - Fixes note value glyph scaling, when the staff scale is modified.
2015-09-27 13:33:05 +02:00
// OR chord beam mode not AUTO
2013-05-23 15:39:14 +02:00
// OR previous CR is a rest
TAB - Mixing mensural value symbols and beaming in historic tablatures __References__: Technology Preview forum post with discussion, screen-shots and links to additional threads https://musescore.org/en/node/81051 Implements the possibility to mix, in TAB's with note symbols at staff side, mensural value symbols (discreet glyphs) with the 'grid'-shaped beaming found in historical sources and commonly used in lute literature. The beaming is implemented by special drawing of the `TabDurationSymbol` element holding the note value symbol, using drawing primitives instead of the relevant font glyph. The user may choose between the two renderings (discreet glyph or beaming grid), on a chord-by-chord basis, by setting the chord `BeamMode` (via for instance the relevant palette): `AUTO` selects the glyph rendering, `beam start` the start of the grid and `beam middle` the continuation of the grid beamed to the previous element. Typographic features of the grid (stem width, stem height and beam thickness) depend on the glyph style and are hard-coded in the style definition. As well as the number of beams for note value, which also depends on the note value style. Also: - Implements to possibility to force the display of a note value which would not be rendered by the current note value repetition setting, by setting the chord beam mode to any other value. - Implements the 'no stem' chord setting for this TAB style, allowing to remove a note value symbol otherwise generated by the current repetition setting. - Improves the detection of note value font metrics (still not perfect, though, as Qt `QFontMetricsF::tightboundingRect()` returns very approximated results) - Fixes note value glyph scaling, when the staff scale is modified.
2015-09-27 13:33:05 +02:00
// AND no not-stem
2013-05-23 15:39:14 +02:00
// set a duration symbol (trying to re-use existing symbols where existing to minimize
// symbol creation and deletion)
bool needTabDur = false;
bool repeat = false;
if (!noStem()) {
// check duration of prev. CR segm
ChordRest * prevCR = prevChordRest(this);
if (prevCR == 0)
needTabDur = true;
else if (beamMode() != Beam::Mode::AUTO
|| prevCR->durationType().type() != durationType().type()
|| prevCR->dots() != dots()
|| prevCR->tuplet() != tuplet()
|| prevCR->type() == ElementType::REST)
needTabDur = true;
else if (tab->symRepeat() == TablatureSymbolRepeat::ALWAYS
|| ((tab->symRepeat() == TablatureSymbolRepeat::MEASURE ||
tab->symRepeat() == TablatureSymbolRepeat::SYSTEM)
&& measure() != prevCR->measure())) {
needTabDur = true;
repeat = true;
}
}
if (needTabDur) {
2013-05-23 15:39:14 +02:00
// symbol needed; if not exist, create; if exists, update duration
if (!_tabDur)
_tabDur = new TabDurationSymbol(score(), tab, durationType().type(), dots());
else
_tabDur->setDuration(durationType().type(), dots(), tab);
_tabDur->setParent(this);
_tabDur->setRepeat(repeat);
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
// _tabDur->setMag(mag()); // useless to set grace mag: graces have no dur. symbol
2013-05-23 15:39:14 +02:00
_tabDur->layout();
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
if (minY < 0) { // if some fret extends above tab body (like bass strings)
_tabDur->rypos() += minY; // raise duration symbol
_tabDur->bbox().translate(0, minY);
}
2013-05-23 15:39:14 +02:00
}
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
else { // symbol not needed: if exists, delete
2013-05-23 15:39:14 +02:00
delete _tabDur;
_tabDur = 0;
}
TAB: Support for input and display of bass string notations Supports 'standard' configuration for bass string notations in historic tablatures (lutes and other plucked instruments, as well as viols), both of the French and of the Italian style. This should fill the last 'big hole' in historic TAB support. Bass strings (or bourdons) are extra strings in addition to the 6 'standard' strings, which are not represented by tab lines and were indicated by other typograhic devices in historic sources. Among the innumerable variations shown in sources, this implementation supports the following styles, chosen to be general enough to suit the majority of cases, without requiring new parameters in the TAB style dialogue box: - French: the first 4 bass courses are indicated by a fret mark in the 'seventh' TAB position (below bottom string) with 0, 1, 2 or 3 slashes prefixed; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 4 on) and cannot contain a fret mark (as they didn't in historic sources). - Italian: the first 2 bass courses are indicated by a fret mark in the 'seventh' TAB position (abover top string) with 1 or 2 'ledger lines' underneath; other bass courses are indicated, also in the 'seventh' TAB position, by the string number (from 9 on) and cannot contain a fret mark (as they didn't in historic sources). Rhythm marks above these indication are raised to leave room for them. Both styles do not blindly assume that French style is top-to-bottom and Italian is 'upside-down' -- as historic sources are -- but adapt to the actual string order of the TAB. The choice between the two styles depends on the TAB using numbers or letters for the fret marks. The implementation does not try to detect if the TAB is really of a historic style and applies either bass string notation whenever more strings are used than there are TAB lines. If this proves unsuitable to modern usage, some better heuristics can probably be found. For a discussion and some screen shots, see: https://musescore.org/en/node/67261 **Note entry** During TAB note entry, if the instruments has more strings than the TAB has lines, the string cursor can be moved outside of the TAB body, one position below for 'top-to-bottom' TAB's and one position above for 'upside-down' TAB's. Further up or down movements add, to the 'blue cursor rectangle', markers indicating which is the actual target string (the cursor does not actually move), equal to the marks a note in that string will receive (slashes, ledger lines or string ordinal, according to the style and the string); during input the user will then receive the same info as when reading entered notes. Other Notes: - the `InputStatus::_string` variable, holding the current target TAB string in TAB note entry, changed meaning from the __visual__ string index to the __physical__ string index: this allows a better containment of the peculiarities of the individual TAB styles within the `StaffStyle` class, leaving other classes somehow freer of concern about TAB visual order and other peculiarities. As this variable is only used with TAB's, this change should not affect other functions. - Some calculation for rhythm symbols have been moved from `TabDurationSymbol::draw()` to `TabDurationSymbol::layout()`, hopefully speeding up the drawing process. - In fonts for historic styles, '10' has been replaced by 'X' both in fret numbers and in string ordinals, as this is more common in historic sources. Currently, this is not configurable; an additional style parameter could be added in future, if there will be enough request for it.
2015-07-06 17:40:02 +02:00
} // end of if(duration_symbols)
2012-05-26 14:26:10 +02:00
if (_arpeggio) {
qreal headHeight = upnote->headHeight();
_arpeggio->layout();
lll += _arpeggio->width() + _spatium * .5;
qreal y = upNote()->pos().y() - headHeight * .5;
2013-04-26 17:14:37 +02:00
qreal h = downNote()->pos().y() + downNote()->headHeight() - y;
2012-05-26 14:26:10 +02:00
_arpeggio->setHeight(h);
_arpeggio->setPos(-lll, y);
// handle the special case of _arpeggio->span() > 1
// in layoutArpeggio2() after page layout has done so we
// know the y position of the next staves
}
// allocate enough room for glissandi
if (_endsGlissando) {
if (!rtick().isZero()) // if not at beginning of measure
2018-03-27 15:36:00 +02:00
lll += (0.5 + score()->styleS(Sid::MinTieLength).val()) * _spatium;
// special case of system-initial glissando final note is handled in Glissando::layout() itself
}
2012-05-26 14:26:10 +02:00
if (_hook) {
if (beam())
score()->undoRemoveElement(_hook);
else if(tab == 0) {
2013-03-04 12:00:02 +01:00
_hook->layout();
2013-03-25 12:45:35 +01:00
if (up()) {
// hook position is not set yet
qreal x = _hook->bbox().right() + stem()->hookPos().x();
rrr = qMax(rrr, x);
}
2013-03-04 12:00:02 +01:00
}
2012-05-26 14:26:10 +02:00
}
if (dots()) {
qreal x = 0.0;
// if stems are beside staff, dots are placed near to stem
if (!tab->stemThrough()) {
// if there is an unbeamed hook, dots should start after the hook
if (_hook && !beam())
x = _hook->width() + dotNoteDistance;
// if not, dots should start at a fixed distance right after the stem
else
x = STAFFTYPE_TAB_DEFAULTDOTDIST_X * _spatium;
if (segment())
segment()->setDotPosX(staffIdx(), x);
}
// if stems are through staff, use dot position computed above on fret mark widths
else
x = dotPosX() + dotNoteDistance
2018-03-27 15:36:00 +02:00
+ (dots()-1) * score()->styleS(Sid::dotDotDistance).val() * _spatium;
x += symWidth(SymId::augmentationDot);
rrr = qMax(rrr, x);
}
2019-05-23 08:51:00 +02:00
#if 0
if (!_articulations.isEmpty()) {
// TODO: allocate space? see layoutPitched()
for (Articulation* a : articulations())
a->layout();
}
2019-05-23 08:51:00 +02:00
#endif
2016-01-04 14:48:58 +01:00
_spaceLw = lll;
_spaceRw = rrr;
2018-03-27 15:36:00 +02:00
qreal graceMag = score()->styleD(Sid::graceNoteMag);
2015-02-19 10:28:25 +01:00
2016-02-06 22:03:43 +01:00
QVector<Chord*> graceNotesBefore = Chord::graceNotesBefore();
2015-02-19 10:28:25 +01:00
int nb = graceNotesBefore.size();
if (nb) {
2016-01-04 14:48:58 +01:00
qreal xl = -(_spaceLw + minNoteDistance);
2014-04-23 18:07:38 +02:00
for (int i = nb-1; i >= 0; --i) {
Chord* c = graceNotesBefore.value(i);
2016-01-04 14:48:58 +01:00
xl -= c->_spaceRw/* * 1.2*/;
2014-04-23 18:07:38 +02:00
c->setPos(xl, 0);
2016-01-04 14:48:58 +01:00
xl -= c->_spaceLw + minNoteDistance * graceMag;
2014-04-23 18:07:38 +02:00
}
2016-01-04 14:48:58 +01:00
if (-xl > _spaceLw)
_spaceLw = -xl;
2014-04-23 18:07:38 +02:00
}
2016-02-06 22:03:43 +01:00
QVector<Chord*> gna = graceNotesAfter();
2015-02-19 10:28:25 +01:00
int na = gna.size();
if (na) {
2014-04-23 18:07:38 +02:00
// get factor for start distance after main note. Values found by testing.
qreal fc;
switch (durationType().type()) {
case TDuration::DurationType::V_LONG: fc = 3.8; break;
case TDuration::DurationType::V_BREVE: fc = 3.8; break;
case TDuration::DurationType::V_WHOLE: fc = 3.8; break;
case TDuration::DurationType::V_HALF: fc = 3.6; break;
case TDuration::DurationType::V_QUARTER: fc = 2.1; break;
case TDuration::DurationType::V_EIGHTH: fc = 1.4; break;
case TDuration::DurationType::V_16TH: fc = 1.2; break;
2014-04-23 18:07:38 +02:00
default: fc = 1;
}
2016-01-04 14:48:58 +01:00
qreal xr = fc * (_spaceRw + minNoteDistance);
2014-04-23 18:07:38 +02:00
for (int i = 0; i <= na - 1; i++) {
2015-02-19 10:28:25 +01:00
Chord* c = gna.value(i);
2016-01-04 14:48:58 +01:00
xr += c->_spaceLw * (i == 0 ? 1.3 : 1);
2014-04-23 18:07:38 +02:00
c->setPos(xr, 0);
2016-01-04 14:48:58 +01:00
xr += c->_spaceRw + minNoteDistance * graceMag;
2014-04-23 18:07:38 +02:00
}
2016-01-04 14:48:58 +01:00
if (xr > _spaceRw)
_spaceRw = xr;
2014-04-23 18:07:38 +02:00
}
2016-12-06 09:35:52 +01:00
for (Element* e : el()) {
2012-05-26 14:26:10 +02:00
e->layout();
2017-01-18 14:16:33 +01:00
if (e->type() == ElementType::CHORDLINE) {
QRectF tbbox = e->bbox().translated(e->pos());
qreal lx = tbbox.left();
qreal rx = tbbox.right();
2016-01-04 14:48:58 +01:00
if (-lx > _spaceLw)
_spaceLw = -lx;
if (rx > _spaceRw)
_spaceRw = rx;
2012-05-26 14:26:10 +02:00
}
}
for (size_t i = 0; i < numOfNotes; ++i)
2013-03-25 16:27:20 +01:00
_notes.at(i)->layout2();
2012-07-24 14:20:43 +02:00
QRectF bb;
2013-03-25 16:27:20 +01:00
processSiblings([&bb] (Element* e) { bb |= e->bbox().translated(e->pos()); } );
2013-05-23 15:39:14 +02:00
if (_tabDur)
bb |= _tabDur->bbox().translated(_tabDur->pos());
2012-07-24 14:20:43 +02:00
setbbox(bb);
2012-05-26 14:26:10 +02:00
}
2013-05-12 12:51:42 +02:00
//---------------------------------------------------------
// crossMeasureSetup
//---------------------------------------------------------
void Chord::crossMeasureSetup(bool on)
{
2013-05-22 15:20:14 +02:00
if (!on) {
if (_crossMeasure != CrossMeasure::UNKNOWN) {
_crossMeasure = CrossMeasure::UNKNOWN;
layoutStem1();
}
2013-05-12 12:51:42 +02:00
return;
}
if (_crossMeasure == CrossMeasure::UNKNOWN) {
CrossMeasure tempCross = CrossMeasure::NONE; // assume no cross-measure modification
2013-05-12 12:51:42 +02:00
// if chord has only one note and note is tied forward
2016-02-06 22:03:43 +01:00
if (notes().size() == 1 && _notes[0]->tieFor()) {
2013-05-12 12:51:42 +02:00
Chord* tiedChord = _notes[0]->tieFor()->endNote()->chord();
// if tied note belongs to another measure and to a single-note chord
2016-02-06 22:03:43 +01:00
if (tiedChord->measure() != measure() && tiedChord->notes().size() == 1) {
2013-05-12 12:51:42 +02:00
// get total duration
2016-02-06 22:03:43 +01:00
std::vector<TDuration> durList = toDurationList(
2013-05-12 12:51:42 +02:00
actualDurationType().fraction() +
tiedChord->actualDurationType().fraction(), true);
// if duration can be expressed as a single duration
// apply cross-measure modification
2016-02-06 22:03:43 +01:00
if (durList.size() == 1) {
_crossMeasure = tempCross = CrossMeasure::FIRST;
2013-05-12 12:51:42 +02:00
_crossMeasureTDur = durList[0];
layoutStem1();
2013-05-12 12:51:42 +02:00
}
}
_crossMeasure = tempCross;
tiedChord->setCrossMeasure(tempCross == CrossMeasure::FIRST ?
CrossMeasure::SECOND : CrossMeasure::NONE);
2013-05-12 12:51:42 +02:00
}
}
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// layoutArpeggio2
// called after layout of page
//---------------------------------------------------------
void Chord::layoutArpeggio2()
{
if (!_arpeggio)
return;
2013-11-19 12:12:07 +01:00
qreal y = upNote()->pagePos().y() - upNote()->headHeight() * .5;
2012-05-26 14:26:10 +02:00
int span = _arpeggio->span();
int btrack = track() + (span - 1) * VOICES;
2017-12-20 16:49:30 +01:00
ChordRest* bchord = toChordRest(segment()->element(btrack));
Note* dnote = (bchord && bchord->type() == ElementType::CHORD) ? toChord(bchord)->downNote() : downNote();
2012-05-26 14:26:10 +02:00
2013-11-19 12:12:07 +01:00
qreal h = dnote->pagePos().y() + dnote->headHeight() * .5 - y;
2012-05-26 14:26:10 +02:00
_arpeggio->setHeight(h);
2013-11-19 12:12:07 +01:00
_arpeggio->layout();
2012-05-26 14:26:10 +02:00
2013-11-19 12:12:07 +01:00
#if 0 // collect notes for arpeggio
2012-05-26 14:26:10 +02:00
QList<Note*> notes;
int n = _notes.size();
for (int j = n - 1; j >= 0; --j) {
Note* note = _notes[j];
if (note->tieBack())
continue;
notes.prepend(note);
}
for (int i = 1; i < span; ++i) {
2017-12-20 16:49:30 +01:00
ChordRest* c = toChordRest(segment()->element(track() + i * VOICES));
2012-05-26 14:26:10 +02:00
if (c && c->type() == CHORD) {
2017-12-20 16:49:30 +01:00
QList<Note*> nl = toChord(c)->notes();
2012-05-26 14:26:10 +02:00
int n = nl.size();
for (int j = n - 1; j >= 0; --j) {
Note* note = nl[j];
if (note->tieBack())
continue;
notes.prepend(note);
}
}
}
2013-11-19 12:12:07 +01:00
#endif
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// findNote
//---------------------------------------------------------
Note* Chord::findNote(int pitch) const
{
size_t ns = _notes.size();
for (size_t i = 0; i < ns; ++i) {
Note* n = _notes.at(i);
2012-05-26 14:26:10 +02:00
if (n->pitch() == pitch)
return n;
}
return 0;
}
//---------------------------------------------------------
// drop
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
Element* Chord::drop(EditData& data)
2012-05-26 14:26:10 +02:00
{
Element* e = data.dropElement;
2012-05-26 14:26:10 +02:00
switch (e->type()) {
2017-01-18 14:16:33 +01:00
case ElementType::ARTICULATION:
2012-05-26 14:26:10 +02:00
{
2017-12-20 16:49:30 +01:00
Articulation* atr = toArticulation(e);
2012-05-26 14:26:10 +02:00
Articulation* oa = hasArticulation(atr);
if (oa) {
delete atr;
atr = 0;
// if attribute is already there, remove
// score()->cmdRemove(oa); // unexpected behaviour?
score()->select(oa, SelectType::SINGLE, 0);
2012-05-26 14:26:10 +02:00
}
else {
atr->setParent(this);
atr->setTrack(track());
score()->undoAddElement(atr);
}
return atr;
}
2012-11-19 10:08:15 +01:00
2017-01-18 14:16:33 +01:00
case ElementType::CHORDLINE:
2012-05-26 14:26:10 +02:00
e->setParent(this);
2013-02-28 15:06:54 +01:00
e->setTrack(track());
2012-05-26 14:26:10 +02:00
score()->undoAddElement(e);
break;
2012-11-19 10:08:15 +01:00
2017-01-18 14:16:33 +01:00
case ElementType::TREMOLO:
2012-11-19 10:08:15 +01:00
{
2017-11-27 09:56:41 +01:00
Tremolo* t = toTremolo(e);
2012-11-19 10:08:15 +01:00
if (t->twoNotes()) {
Segment* s = segment()->next();
while (s) {
2017-11-27 09:56:41 +01:00
if (s->element(track()) && s->element(track())->isChord())
2012-11-19 10:08:15 +01:00
break;
s = s->next();
}
if (s == 0) {
qDebug("no segment for second note of tremolo found");
2012-11-19 10:08:15 +01:00
delete e;
return 0;
}
2017-11-27 09:56:41 +01:00
Chord* ch2 = toChord(s->element(track()));
if (ch2->ticks() != ticks()) {
qDebug("no matching chord for second note of tremolo found");
delete e;
return 0;
}
2012-11-19 10:08:15 +01:00
t->setChords(this, ch2);
}
}
if (tremolo())
score()->undoRemoveElement(tremolo());
e->setParent(this);
e->setTrack(track());
score()->undoAddElement(e);
break;
2017-01-18 14:16:33 +01:00
case ElementType::ARPEGGIO:
2012-11-20 20:51:18 +01:00
{
2017-12-20 16:49:30 +01:00
Arpeggio* a = toArpeggio(e);
if (arpeggio())
score()->undoRemoveElement(arpeggio());
2013-02-28 17:46:30 +01:00
a->setTrack(track());
2012-11-20 20:51:18 +01:00
a->setParent(this);
a->setHeight(spatium() * 5); //DEBUG
score()->undoAddElement(a);
}
return e;
2012-05-26 14:26:10 +02:00
default:
return ChordRest::drop(data);
}
return 0;
}
//---------------------------------------------------------
// dotPosX
//---------------------------------------------------------
qreal Chord::dotPosX() const
{
2013-05-29 17:11:57 +02:00
if (parent())
return segment()->dotPosX(staffIdx());
return -1000.0;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// localSpatiumChanged
//---------------------------------------------------------
void Chord::localSpatiumChanged(qreal oldValue, qreal newValue)
{
ChordRest::localSpatiumChanged(oldValue, newValue);
for (Element* e : graceNotes())
e->localSpatiumChanged(oldValue, newValue);
if (_hook)
_hook->localSpatiumChanged(oldValue, newValue);
if (_stem)
_stem->localSpatiumChanged(oldValue, newValue);
if (_stemSlash)
_stemSlash->localSpatiumChanged(oldValue, newValue);
if (arpeggio())
arpeggio()->localSpatiumChanged(oldValue, newValue);
if (_tremolo && (tremoloChordType() != TremoloChordType::TremoloSecondNote))
_tremolo->localSpatiumChanged(oldValue, newValue);
for (Element* e : articulations())
e->localSpatiumChanged(oldValue, newValue);
for (Note* note : notes())
note->localSpatiumChanged(oldValue, newValue);
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant Chord::getProperty(Pid propertyId) const
2012-05-26 14:26:10 +02:00
{
2016-05-25 19:48:18 +02:00
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::NO_STEM: return noStem();
case Pid::SMALL: return small();
case Pid::STEM_DIRECTION: return QVariant::fromValue<Direction>(stemDirection());
2012-05-26 14:26:10 +02:00
default:
return ChordRest::getProperty(propertyId);
}
}
2013-03-14 13:30:25 +01:00
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant Chord::propertyDefault(Pid propertyId) const
2013-03-14 13:30:25 +01:00
{
2016-05-25 19:48:18 +02:00
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::NO_STEM: return false;
case Pid::SMALL: return false;
case Pid::STEM_DIRECTION: return QVariant::fromValue<Direction>(Direction::AUTO);
2013-03-14 13:30:25 +01:00
default:
return ChordRest::propertyDefault(propertyId);
2013-03-14 13:30:25 +01:00
}
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
bool Chord::setProperty(Pid propertyId, const QVariant& v)
2012-05-26 14:26:10 +02:00
{
2016-05-25 19:48:18 +02:00
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::NO_STEM:
2012-05-26 14:26:10 +02:00
setNoStem(v.toBool());
break;
2018-03-27 15:36:00 +02:00
case Pid::SMALL:
2012-05-26 14:26:10 +02:00
setSmall(v.toBool());
break;
2018-03-27 15:36:00 +02:00
case Pid::STEM_DIRECTION:
setStemDirection(v.value<Direction>());
2012-05-26 14:26:10 +02:00
break;
default:
return ChordRest::setProperty(propertyId, v);
}
triggerLayout();
2012-05-26 14:26:10 +02:00
return true;
}
2018-01-17 13:25:23 +01:00
//---------------------------------------------------------
// hasArticulation
//---------------------------------------------------------
Articulation* Chord::hasArticulation(const Articulation* aa)
{
2018-01-17 13:25:23 +01:00
for (Articulation* a : _articulations) {
if (a->subtype() == aa->subtype())
2018-01-17 13:25:23 +01:00
return a;
}
return 0;
}
2012-08-23 17:40:04 +02:00
//---------------------------------------------------------
2012-11-19 10:08:15 +01:00
// reset
2012-08-23 17:40:04 +02:00
//---------------------------------------------------------
2012-11-19 10:08:15 +01:00
void Chord::reset()
2012-08-23 17:40:04 +02:00
{
2018-03-27 15:36:00 +02:00
undoChangeProperty(Pid::STEM_DIRECTION, QVariant::fromValue<Direction>(Direction::AUTO));
undoChangeProperty(Pid::BEAM_MODE, int(Beam::Mode::AUTO));
2013-07-01 16:28:39 +02:00
score()->createPlayEvents(this);
2012-11-19 10:08:15 +01:00
ChordRest::reset();
2012-08-23 17:40:04 +02:00
}
//---------------------------------------------------------
// slash
//---------------------------------------------------------
bool Chord::slash()
{
Note* n = upNote();
return n->fixed();
}
//---------------------------------------------------------
// setSlash
//---------------------------------------------------------
void Chord::setSlash(bool flag, bool stemless)
{
int line = 0;
NoteHead::Group head = NoteHead::Group::HEAD_SLASH;
if (!flag) {
// restore to normal
2018-03-27 15:36:00 +02:00
undoChangeProperty(Pid::NO_STEM, false);
undoChangeProperty(Pid::SMALL, false);
undoChangeProperty(Pid::OFFSET, QPointF());
for (Note* n : _notes) {
2018-03-27 15:36:00 +02:00
n->undoChangeProperty(Pid::HEAD_GROUP, int(NoteHead::Group::HEAD_NORMAL));
n->undoChangeProperty(Pid::FIXED, false);
n->undoChangeProperty(Pid::FIXED_LINE, 0);
n->undoChangeProperty(Pid::PLAY, true);
n->undoChangeProperty(Pid::VISIBLE, true);
2016-12-13 13:16:17 +01:00
if (staff()->isDrumStaff(tick())) {
const Drumset* ds = part()->instrument()->drumset();
int pitch = n->pitch();
if (ds && ds->isValid(pitch)) {
2018-03-27 15:36:00 +02:00
undoChangeProperty(Pid::STEM_DIRECTION, QVariant::fromValue<Direction>(ds->stemDirection(pitch)));
n->undoChangeProperty(Pid::HEAD_GROUP, int(ds->noteHead(pitch)));
}
}
}
return;
}
// set stem to auto (mostly important for rhythmic notation on drum staves)
2018-03-27 15:36:00 +02:00
undoChangeProperty(Pid::STEM_DIRECTION, QVariant::fromValue<Direction>(Direction::AUTO));
// make stemless if asked
if (stemless) {
2018-03-27 15:36:00 +02:00
undoChangeProperty(Pid::NO_STEM, true);
undoChangeProperty(Pid::BEAM_MODE, int(Beam::Mode::NONE));
}
// voice-dependent attributes - line, size, offset, head
if (track() % VOICES < 2) {
// use middle line
2016-12-13 13:16:17 +01:00
line = staff()->middleLine(tick());
}
else {
// set small
2018-03-27 15:36:00 +02:00
undoChangeProperty(Pid::SMALL, true);
// set outside the staff
qreal y = 0.0;
if (track() % 2) {
2016-12-13 13:16:17 +01:00
line = staff()->bottomLine(tick()) + 1;
2016-06-05 10:23:37 +02:00
y = 0.5 * spatium();
}
else {
line = -1;
2016-12-13 13:16:17 +01:00
if (!staff()->isDrumStaff(tick()))
y = -0.5 * spatium();
}
// for non-drum staves, add an additional offset
// for drum staves, no offset, but use normal head
2016-12-13 13:16:17 +01:00
if (!staff()->isDrumStaff(tick()))
// undoChangeProperty(Pid::OFFSET, QPointF(0.0, y));
rypos() += y;
else
head = NoteHead::Group::HEAD_NORMAL;
}
size_t ns = _notes.size();
for (size_t i = 0; i < ns; ++i) {
Note* n = _notes[i];
2018-03-27 15:36:00 +02:00
n->undoChangeProperty(Pid::HEAD_GROUP, static_cast<int>(head));
n->undoChangeProperty(Pid::FIXED, true);
n->undoChangeProperty(Pid::FIXED_LINE, line);
n->undoChangeProperty(Pid::PLAY, false);
// hide all but first notehead
if (i)
2018-03-27 15:36:00 +02:00
n->undoChangeProperty(Pid::VISIBLE, false);
}
}
Fixes #19155, #22861 (duplicate of the former) and #23100. __References__: Issues: https://musescore.org/en/node/19155 https://musescore.org/en/node/22861 https://musescore.org/en/node/23100 __Description__: Allows to change the start and end note to which a glissando is anchored after it has been entered. Either anchor can be changed independently. The user interface follows the current working of other 'snappable' lines. Once either the start or end grip is selected: - `[Shift]+[Left]` snaps the anchor to the previous chord, defaulting to its top note. - `[Shift]+[Right]` snaps to the next chord, defaulting to its top note. - `[Shift]+[Up]` snaps to the note above (possibly in a chord, voice or staff above the current one). - `[Shift]+[Down]` snaps to the note below (possibly in a chord, voice or staff below the current one). This permits to set the anchor points of a glissando to any note in the score, allowing several glissandi between the notes of the same two chords and other complex configurations (glissandi skipping intermediate chords, start and end notes in different voices or staves, and so on). It is possible to move the anchor to a different staff of the same instrument, but not to a different instrument; also, it is not possible to 'cross' a change of instrument in the same staff. __Known limitations__: - The `[Shift]+[Up]` and `[Shift]+[Down]` use the same note-finding functions as the `[Alt]+[Up]` and `[Alt]+[Down]`actions which move the selection cursor to the above and below note, even across voices or staves. Occasionally, in particular if the note immediately above or below is not time-aligned, the algorithm has little expected results; however, the behaviour is already known to the user. Improving the algorithm would benefit both uses. __Notes__: - Most of the added infrastructure is not specific to glissando but to any spanner anchored to notes, then it should also add after-the-fact "snap to" note support to note-anchored text line. - When moving an anchor, the algorithm usually prefers a note in the same voice/staff of the old note if it exists; if there is none, it tries other voices of the same staff. - The change of anchor is undoable. - The fix corrects the management of the `Chord::_endsGlissando` flag, taking into account that a chord can be the ending point of several glissandi and removing one of them not necessarily means the chord no longer ends a glissando (another glissando may still exists). - The fix also improved the rendering of the glissando wavy line, with better alignment with anchor notes and, with glissando text, better text-line spacing.
2015-08-06 11:11:16 +02:00
//---------------------------------------------------------
// updateEndsGlissando
// sets/resets the chord _endsGlissando according any glissando (or more)
// end into this chord or no.
//---------------------------------------------------------
void Chord::updateEndsGlissando()
{
_endsGlissando = false; // assume no glissando ends here
// scan all chord notes for glissandi ending on this chord
for (Note* note : notes()) {
for (Spanner* sp : note->spannerBack())
2017-01-18 14:16:33 +01:00
if (sp->type() == ElementType::GLISSANDO) {
Fixes #19155, #22861 (duplicate of the former) and #23100. __References__: Issues: https://musescore.org/en/node/19155 https://musescore.org/en/node/22861 https://musescore.org/en/node/23100 __Description__: Allows to change the start and end note to which a glissando is anchored after it has been entered. Either anchor can be changed independently. The user interface follows the current working of other 'snappable' lines. Once either the start or end grip is selected: - `[Shift]+[Left]` snaps the anchor to the previous chord, defaulting to its top note. - `[Shift]+[Right]` snaps to the next chord, defaulting to its top note. - `[Shift]+[Up]` snaps to the note above (possibly in a chord, voice or staff above the current one). - `[Shift]+[Down]` snaps to the note below (possibly in a chord, voice or staff below the current one). This permits to set the anchor points of a glissando to any note in the score, allowing several glissandi between the notes of the same two chords and other complex configurations (glissandi skipping intermediate chords, start and end notes in different voices or staves, and so on). It is possible to move the anchor to a different staff of the same instrument, but not to a different instrument; also, it is not possible to 'cross' a change of instrument in the same staff. __Known limitations__: - The `[Shift]+[Up]` and `[Shift]+[Down]` use the same note-finding functions as the `[Alt]+[Up]` and `[Alt]+[Down]`actions which move the selection cursor to the above and below note, even across voices or staves. Occasionally, in particular if the note immediately above or below is not time-aligned, the algorithm has little expected results; however, the behaviour is already known to the user. Improving the algorithm would benefit both uses. __Notes__: - Most of the added infrastructure is not specific to glissando but to any spanner anchored to notes, then it should also add after-the-fact "snap to" note support to note-anchored text line. - When moving an anchor, the algorithm usually prefers a note in the same voice/staff of the old note if it exists; if there is none, it tries other voices of the same staff. - The change of anchor is undoable. - The fix corrects the management of the `Chord::_endsGlissando` flag, taking into account that a chord can be the ending point of several glissandi and removing one of them not necessarily means the chord no longer ends a glissando (another glissando may still exists). - The fix also improved the rendering of the glissando wavy line, with better alignment with anchor notes and, with glissando text, better text-line spacing.
2015-08-06 11:11:16 +02:00
_endsGlissando = true;
return;
}
}
}
//---------------------------------------------------------
// removeMarkings
// - this is normally called after cloning a chord to tie a note over the barline
// - there is no special undo handling; the assumption is that undo will simply remove the cloned chord
// - two note tremolos are converted into simple notes
// - single note tremolos are optionally retained
//---------------------------------------------------------
void Chord::removeMarkings(bool keepTremolo)
{
if (tremolo() && !keepTremolo)
remove(tremolo());
if (arpeggio())
remove(arpeggio());
2016-12-06 09:35:52 +01:00
qDeleteAll(graceNotes());
graceNotes().clear();
qDeleteAll(articulations());
articulations().clear();
for (Note* n : notes()) {
for (Element* e : n->el())
n->remove(e);
}
2016-12-06 09:35:52 +01:00
ChordRest::removeMarkings(keepTremolo);
}
2013-05-28 15:42:02 +02:00
//---------------------------------------------------------
// mag
//---------------------------------------------------------
qreal Chord::mag() const
{
2016-12-23 12:05:18 +01:00
qreal m = staff() ? staff()->mag(tick()) : 1.0;
2013-05-28 15:42:02 +02:00
if (small())
2018-03-27 15:36:00 +02:00
m *= score()->styleD(Sid::smallNoteMag);
2014-05-27 10:35:28 +02:00
if (_noteType != NoteType::NORMAL)
2018-03-27 15:36:00 +02:00
m *= score()->styleD(Sid::graceNoteMag);
2013-05-28 15:42:02 +02:00
return m;
}
2013-06-10 21:13:04 +02:00
//---------------------------------------------------------
// segment
//---------------------------------------------------------
Segment* Chord::segment() const
{
Element* e = parent();
2017-01-18 14:16:33 +01:00
for (; e && e->type() != ElementType::SEGMENT; e = e->parent())
2013-06-10 21:13:04 +02:00
;
2017-12-20 16:49:30 +01:00
return toSegment(e);
2013-06-10 21:13:04 +02:00
}
//---------------------------------------------------------
// measure
//---------------------------------------------------------
Measure* Chord::measure() const
{
Element* e = parent();
2017-01-18 14:16:33 +01:00
for (; e && e->type() != ElementType::MEASURE; e = e->parent())
2013-06-10 21:13:04 +02:00
;
2017-12-20 16:49:30 +01:00
return toMeasure(e);
2013-06-10 21:13:04 +02:00
}
2013-06-16 23:33:37 +02:00
2014-04-23 18:07:38 +02:00
//---------------------------------------------------------
2015-02-19 10:28:25 +01:00
// graceNotesBefore
2014-04-23 18:07:38 +02:00
//---------------------------------------------------------
2016-02-06 22:03:43 +01:00
QVector<Chord*> Chord::graceNotesBefore() const
2014-04-23 18:07:38 +02:00
{
2016-02-06 22:03:43 +01:00
QVector<Chord*> cl;
2015-02-19 10:28:25 +01:00
for (Chord* c : _graceNotes) {
Q_ASSERT(c->noteType() != NoteType::NORMAL && c->noteType() != NoteType::INVALID);
if (c->noteType() & (
NoteType::ACCIACCATURA
| NoteType::APPOGGIATURA
| NoteType::GRACE4
| NoteType::GRACE16
| NoteType::GRACE32)) {
2016-02-06 22:03:43 +01:00
cl.push_back(c);
}
}
2015-02-19 10:28:25 +01:00
return cl;
2014-04-23 18:07:38 +02:00
}
//---------------------------------------------------------
2015-02-19 10:28:25 +01:00
// graceNotesAfter
2014-04-23 18:07:38 +02:00
//---------------------------------------------------------
2016-02-06 22:03:43 +01:00
QVector<Chord*> Chord::graceNotesAfter() const
2014-04-23 18:07:38 +02:00
{
2016-02-06 22:03:43 +01:00
QVector<Chord*> cl;
for (int i = _graceNotes.size() - 1; i >= 0; i--) {
Chord* c = _graceNotes[i];
Q_ASSERT(c->noteType() != NoteType::NORMAL && c->noteType() != NoteType::INVALID);
2016-02-15 12:23:28 +01:00
if (c->noteType() & (NoteType::GRACE8_AFTER | NoteType::GRACE16_AFTER | NoteType::GRACE32_AFTER))
2016-02-06 22:03:43 +01:00
cl.push_back(c);
2014-04-23 18:07:38 +02:00
}
2015-02-19 10:28:25 +01:00
return cl;
2014-04-23 18:07:38 +02:00
}
//---------------------------------------------------------
// sortNotes
//---------------------------------------------------------
void Chord::sortNotes()
{
std::sort(notes().begin(), notes().end(),
[](const Note* a,const Note* b)->bool { return b->line() < a->line(); }
);
2014-04-23 18:07:38 +02:00
}
//---------------------------------------------------------
// nextTiedChord
// Return next chord if all notes in this chord are tied to it.
// Set backwards=true to return the previous chord instead.
//
// Note: the next chord might have extra notes that are not tied
// back to this one. Set sameSize=true to return 0 in this case.
//---------------------------------------------------------
Chord* Chord::nextTiedChord(bool backwards, bool sameSize)
{
Segment* nextSeg = backwards ? segment()->prev1(SegmentType::ChordRest) : segment()->next1(SegmentType::ChordRest);
if (!nextSeg)
return 0;
ChordRest* nextCR = nextSeg->nextChordRest(track(), backwards);
if (!nextCR || !nextCR->isChord())
return 0;
Chord* next = toChord(nextCR);
if (sameSize && notes().size() != next->notes().size())
return 0; // sizes don't match so some notes can't be tied
if (tuplet() != next->tuplet())
return 0; // next chord belongs to a different tuplet
for (Note* n : _notes) {
Tie* tie = backwards ? n->tieBack() : n->tieFor();
if (!tie)
return 0; // not tied
Note* nn = backwards ? tie->startNote() : tie->endNote();
if (!nn || nn->chord() != next)
return 0; // tied to note in wrong voice, or tied over rest
}
return next; // all notes in this chord are tied to notes in next chord
}
2014-04-23 18:07:38 +02:00
//---------------------------------------------------------
// toGraceAfter
//---------------------------------------------------------
void Chord::toGraceAfter()
{
switch (noteType()) {
2016-02-15 12:23:28 +01:00
case NoteType::APPOGGIATURA: setNoteType(NoteType::GRACE8_AFTER); break;
case NoteType::GRACE16: setNoteType(NoteType::GRACE16_AFTER); break;
case NoteType::GRACE32: setNoteType(NoteType::GRACE32_AFTER); break;
2014-04-23 18:07:38 +02:00
default: break;
}
}
2014-05-15 13:42:03 +02:00
//---------------------------------------------------------
// tremoloChordType
//---------------------------------------------------------
TremoloChordType Chord::tremoloChordType() const
{
if (_tremolo && _tremolo->twoNotes()) {
if (_tremolo->chord1() == this)
return TremoloChordType::TremoloFirstNote;
else if (_tremolo->chord2() == this)
return TremoloChordType::TremoloSecondNote;
else
qFatal("Chord::tremoloChordType(): inconsistency %p - %p, this is %p", _tremolo->chord1(), _tremolo->chord2(), this);
2014-05-15 13:42:03 +02:00
}
return TremoloChordType::TremoloSingle;
}
//---------------------------------------------------------
// nextElement
//---------------------------------------------------------
Element* Chord::nextElement()
{
Element* e = score()->selection().element();
if (!e && !score()->selection().elements().isEmpty())
2017-08-04 12:05:30 +02:00
e = score()->selection().elements().first();
switch(e->type()) {
case ElementType::SYMBOL:
case ElementType::IMAGE:
case ElementType::FINGERING:
case ElementType::TEXT:
case ElementType::BEND: {
Note* n = toNote(e->parent());
2017-08-04 12:05:30 +02:00
if(n == _notes.front()) {
if (_arpeggio)
return _arpeggio;
else if (_tremolo)
return _tremolo;
break;
}
for (auto &i : _notes) {
if (i == n) {
return *(&i-1);
}
}
break;
}
case ElementType::GLISSANDO_SEGMENT:
case ElementType::TIE_SEGMENT: {
2017-12-20 16:49:30 +01:00
SpannerSegment* s = toSpannerSegment(e);
Spanner* sp = s->spanner();
Element* elSt = sp->startElement();
Q_ASSERT(elSt->type() == ElementType::NOTE);
2017-12-20 16:49:30 +01:00
Note* n = toNote(elSt);
Q_ASSERT(n != NULL);
if (n == _notes.front()) {
if (_arpeggio)
return _arpeggio;
else if (_tremolo)
return _tremolo;
break;
}
for (auto &i : _notes) {
if (i == n) {
return *(&i-1);
}
}
break;
}
case ElementType::ARPEGGIO:
if (_tremolo)
return _tremolo;
break;
case ElementType::ACCIDENTAL:
e = e->parent();
// fall through
2017-08-04 12:05:30 +02:00
case ElementType::NOTE: {
if (e == _notes.front()) {
if (_arpeggio)
return _arpeggio;
else if (_tremolo)
return _tremolo;
break;
}
for (auto &i : _notes) {
if (i == e)
return *(&i -1);
}
}
break;
case ElementType::CHORD:
return _notes.back();
default:
2017-08-04 12:05:30 +02:00
break;
}
return ChordRest::nextElement();
}
//---------------------------------------------------------
// prevElement
//---------------------------------------------------------
Element* Chord::prevElement()
{
Element* e = score()->selection().element();
if (!e && !score()->selection().elements().isEmpty())
e = score()->selection().elements().last();
switch (e->type()) {
case ElementType::NOTE: {
if (e == _notes.back())
break;
Note* prevNote = nullptr;
for (auto &i : _notes) {
if (i == e) {
prevNote = *(&i+1);
}
}
Element* next = prevNote->lastElementBeforeSegment();
return next;
}
case ElementType::CHORD:
return _notes.front();
case ElementType::TREMOLO:
if (_arpeggio)
return _arpeggio;
// fall through
case ElementType::ARPEGGIO: {
Note* n = _notes.front();
Element* elN = n->lastElementBeforeSegment();
Q_ASSERT(elN != NULL);
return elN;
}
default:
break;
}
return ChordRest::prevElement();
}
//---------------------------------------------------------
// lastElementBeforeSegment
//---------------------------------------------------------
Element* Chord::lastElementBeforeSegment()
{
if (_tremolo) {
return _tremolo;
}
else if (_arpeggio) {
return _arpeggio;
}
else {
Note* n = _notes.front();
Element* elN = n->lastElementBeforeSegment();
Q_ASSERT(elN != NULL);
return elN;
}
}
//---------------------------------------------------------
// nextSegmentElement
//---------------------------------------------------------
Element* Chord::nextSegmentElement()
{
for (int v = track() + 1; staffIdx() == v/VOICES; ++v) {
Element* e = segment()->element(v);
if (e) {
2017-01-18 14:16:33 +01:00
if (e->type() == ElementType::CHORD)
2017-12-20 16:49:30 +01:00
return toChord(e)->notes().back();
return e;
}
}
return ChordRest::nextSegmentElement();
}
//---------------------------------------------------------
// prevSegmentElement
//---------------------------------------------------------
Element* Chord::prevSegmentElement()
{
Element* el = score()->selection().element();
if (!el && !score()->selection().elements().isEmpty() )
el = score()->selection().elements().first();
Element* e = segment()->lastInPrevSegments(el->staffIdx());
if (e) {
2017-12-20 16:49:30 +01:00
if (e->isChord())
return toChord(e)->notes().front();
return e;
}
return ChordRest::prevSegmentElement();
}
2016-01-04 14:48:58 +01:00
//---------------------------------------------------------
// accessibleExtraInfo
//---------------------------------------------------------
2016-02-04 17:06:32 +01:00
QString Chord::accessibleExtraInfo() const
{
QString rez = "";
2017-08-04 12:05:30 +02:00
for (const Chord* c : graceNotes()) {
if (!score()->selectionFilter().canSelect(c))
continue;
for (const Note* n : c->notes())
rez = QString("%1 %2").arg(rez).arg(n->screenReaderInfo());
}
for (Articulation* a : articulations()) {
if (!score()->selectionFilter().canSelect(a))
continue;
rez = QString("%1 %2").arg(rez).arg(a->screenReaderInfo());
}
if (arpeggio() && score()->selectionFilter().canSelect(arpeggio()))
rez = QString("%1 %2").arg(rez).arg(arpeggio()->screenReaderInfo());
if (tremolo() && score()->selectionFilter().canSelect(tremolo()))
rez = QString("%1 %2").arg(rez).arg(tremolo()->screenReaderInfo());
foreach (Element* e, el()) {
2016-06-02 10:38:36 +02:00
if (!score()->selectionFilter().canSelect(e))
continue;
rez = QString("%1 %2").arg(rez).arg(e->screenReaderInfo());
}
return QString("%1 %2").arg(rez).arg(ChordRest::accessibleExtraInfo());
}
2016-01-04 14:48:58 +01:00
//---------------------------------------------------------
// shape
2019-05-10 17:48:28 +02:00
// does not contain articulations
2016-01-04 14:48:58 +01:00
//---------------------------------------------------------
Shape Chord::shape() const
{
Shape shape;
if (_hook && _hook->addToSkyline())
2018-01-23 13:19:34 +01:00
shape.add(_hook->shape().translated(_hook->pos()));
if (_stem && _stem->addToSkyline()) {
// stem direction is not known soon enough for cross staff beamed notes
if (!(beam() && (staffMove() || beam()->cross())))
shape.add(_stem->shape().translated(_stem->pos()));
}
if (_stemSlash && _stemSlash->addToSkyline())
2018-01-23 13:19:34 +01:00
shape.add(_stemSlash->shape().translated(_stemSlash->pos()));
if (_arpeggio && _arpeggio->addToSkyline())
2018-01-23 13:19:34 +01:00
shape.add(_arpeggio->shape().translated(_arpeggio->pos()));
// if (_tremolo)
// shape.add(_tremolo->shape().translated(_tremolo->pos()));
for (Note* note : _notes) {
2018-01-23 13:19:34 +01:00
shape.add(note->shape().translated(note->pos()));
for (Element* e : note->el()) {
if (!e->addToSkyline())
continue;
2019-05-08 03:45:32 +02:00
if (e->isFingering() && toFingering(e)->layoutType() == ElementType::CHORD && e->bbox().isValid())
shape.add(e->bbox().translated(e->pos() + note->pos()));
}
}
for (Element* e : el()) {
if (e->addToSkyline())
shape.add(e->shape().translated(e->pos()));
}
2018-01-23 13:19:34 +01:00
for (Chord* chord : _graceNotes) // process grace notes last, needed for correct shape calculation
shape.add(chord->shape().translated(chord->pos()));
shape.add(ChordRest::shape()); // add lyrics
for (LedgerLine* l = _ledgerLines; l; l = l->next())
shape.add(l->shape().translated(l->pos()));
if (_spaceLw || _spaceRw)
shape.addHorizontalSpacing(Shape::SPACING_GENERAL, -_spaceLw, _spaceRw);
return shape;
2016-01-04 14:48:58 +01:00
}
2018-01-22 10:12:49 +01:00
//---------------------------------------------------------
// layoutArticulations
// layout tenuto and staccato
2018-01-22 10:12:49 +01:00
// called before layouting slurs
//---------------------------------------------------------
void Chord::layoutArticulations()
{
for (Chord* gc : graceNotes())
gc->layoutArticulations();
2018-01-22 10:12:49 +01:00
if (_articulations.empty())
return;
const Staff* st = staff();
const StaffType* staffType = st->staffType(tick());
2018-03-27 15:36:00 +02:00
qreal mag = (staffType->small() ? score()->styleD(Sid::smallStaffMag) : 1.0) * staffType->userMag();
2018-01-23 13:19:34 +01:00
qreal _spatium = score()->spatium() * mag;
qreal _spStaff = _spatium * staffType->lineDistance().val();
2018-01-22 10:12:49 +01:00
//
2018-01-23 13:19:34 +01:00
// determine direction
// place tenuto and staccato
2018-01-22 10:12:49 +01:00
//
2018-01-23 13:19:34 +01:00
Articulation* prevArticulation = nullptr;
2018-01-22 10:12:49 +01:00
for (Articulation* a : _articulations) {
if (a->anchor() == ArticulationAnchor::CHORD) {
if (measure()->hasVoices(a->staffIdx()))
a->setUp(up()); // if there are voices place articulation at stem
else if (a->symId() >= SymId::articMarcatoAbove && a->symId() <= SymId::articMarcatoTenutoBelow)
a->setUp(true); // Gould, p. 117: strong accents above staff
else if (isGrace() && up() && !a->layoutCloseToNote() && downNote()->line() < 6)
a->setUp(true); // keep articulation close to grace note
else
a->setUp(!up()); // place articulation at note head
2018-01-22 10:12:49 +01:00
}
else
a->setUp(a->anchor() == ArticulationAnchor::TOP_STAFF || a->anchor() == ArticulationAnchor::TOP_CHORD);
2018-01-23 13:19:34 +01:00
if (!a->layoutCloseToNote())
2018-01-22 10:12:49 +01:00
continue;
2018-12-03 12:31:31 +01:00
bool bottom = !a->up(); // true: articulation is below chord; false: articulation is above chord
a->layout(); // must be done after assigning direction, or else symId is not reliable
2018-01-23 13:19:34 +01:00
2018-01-22 10:12:49 +01:00
bool headSide = bottom == up();
qreal x = centerX();
qreal y = 0.0;
2018-01-22 10:12:49 +01:00
if (bottom) {
2018-01-22 10:48:05 +01:00
if (!headSide && stem()) {
2018-01-23 13:19:34 +01:00
y = upPos() + stem()->stemLen();
2018-01-22 10:48:05 +01:00
if (beam())
2018-03-27 15:36:00 +02:00
y += score()->styleS(Sid::beamWidth).val() * _spatium * .5;
2018-01-23 13:19:34 +01:00
int line = lrint((y + 0.5 * _spStaff) / _spStaff);
if (line < staffType->lines()) // align between staff lines
2018-01-22 10:12:49 +01:00
y = line * _spStaff + _spatium * .5;
else
y += _spatium;
if (a->isStaccato() && articulations().size() == 1) {
if (_up)
x = downNote()->bboxRightPos() - stem()->width() * .5;
else
x = stem()->width() * .5;
}
2018-01-22 10:12:49 +01:00
}
else {
2018-01-23 13:19:34 +01:00
int line = downLine();
int lines = (staffType->lines() - 1) * 2;
2018-01-22 10:12:49 +01:00
if (line < lines)
y = ((line & ~1) + 3) * _spStaff;
else
y = line * _spStaff + 2 * _spatium;
y *= .5;
}
if (prevArticulation && (prevArticulation->up() == a->up()))
y += _spatium;
2018-01-22 10:48:05 +01:00
y -= a->height() * .5; // center symbol
2018-01-22 10:12:49 +01:00
}
else {
2018-01-22 10:48:05 +01:00
if (!headSide && stem()) {
2018-01-23 13:19:34 +01:00
y = downPos() + stem()->stemLen();
2018-01-22 10:48:05 +01:00
if (beam())
2018-03-27 15:36:00 +02:00
y -= score()->styleS(Sid::beamWidth).val() * _spatium * .5;
2018-01-22 10:12:49 +01:00
int line = lrint((y-0.5*_spStaff) / _spStaff);
if (line >= 0) // align between staff lines
2018-01-22 10:12:49 +01:00
y = line * _spStaff - _spatium * .5;
else
y -= _spatium;
if (a->isStaccato() && articulations().size() == 1) {
if (_up)
x = downNote()->bboxRightPos() - stem()->width() * .5;
else
x = stem()->width() * .5;
}
2018-01-22 10:12:49 +01:00
}
else {
2018-01-23 13:19:34 +01:00
int line = upLine();
2018-01-22 10:12:49 +01:00
if (line > 0)
y = (((line+1) & ~1) - 3) * _spStaff;
else
y = line * _spStaff - 2 * _spatium;
y *= .5;
}
if (prevArticulation && (prevArticulation->up() == a->up()))
y -= _spatium;
2018-01-22 10:48:05 +01:00
y += a->height() * .5; // center symbol
2018-01-22 10:12:49 +01:00
}
a->setPos(x, y);
prevArticulation = a;
2018-09-12 10:51:08 +02:00
// measure()->system()->staff(a->staffIdx())->skyline().add(a->shape().translated(a->pos() + segment()->pos() + measure()->pos()));
2018-01-22 10:12:49 +01:00
}
}
//---------------------------------------------------------
// layoutArticulations2
// Called after layouting systems
// Tentatively layout all articulations
// To be finished after laying out slurs
2018-01-22 10:12:49 +01:00
//---------------------------------------------------------
void Chord::layoutArticulations2()
{
for (Chord* gc : graceNotes())
gc->layoutArticulations2();
2018-01-22 10:12:49 +01:00
if (_articulations.empty())
return;
qreal _spatium = spatium();
qreal x = centerX();
2018-03-27 15:36:00 +02:00
qreal distance0 = score()->styleP(Sid::propertyDistance);
qreal distance2 = score()->styleP(Sid::propertyDistanceStem);
2018-01-22 10:12:49 +01:00
qreal chordTopY = upPos(); // note position of highest note
qreal chordBotY = downPos(); // note position of lowest note
qreal staffTopY = -distance2;
qreal staffBotY = staff()->height() + distance2;
// avoid collisions of staff articulations with chord notes:
// gap between note and staff articulation is distance0 + 0.5 spatium
if (stem()) {
qreal y = stem()->pos().y() + pos().y() + stem()->stemLen();
2018-01-22 10:12:49 +01:00
if (beam()) {
2018-03-27 15:36:00 +02:00
qreal bw = score()->styleS(Sid::beamWidth).val() * _spatium;
2018-01-22 10:12:49 +01:00
y += up() ? -bw : bw;
}
if (up())
chordTopY = y;
2018-01-22 10:12:49 +01:00
else
chordBotY = y;
2018-01-22 10:12:49 +01:00
}
//
// place all articulations with anchor at chord/rest
//
2018-03-27 15:36:00 +02:00
qreal distance1 = score()->styleP(Sid::propertyDistanceHead);
chordTopY -= up() ? 0.5 * _spatium : distance1;
chordBotY += up() ? distance1 : 0.5 * _spatium;
2018-01-22 10:12:49 +01:00
for (Articulation* a : _articulations) {
ArticulationAnchor aa = a->anchor();
2018-01-23 13:19:34 +01:00
if (aa != ArticulationAnchor::CHORD && aa != ArticulationAnchor::TOP_CHORD && aa != ArticulationAnchor::BOTTOM_CHORD)
2018-01-22 10:12:49 +01:00
continue;
if (a->up()) {
if (!a->layoutCloseToNote()) {
a->layout();
a->setPos(x, chordTopY);
a->doAutoplace();
}
chordTopY = a->y() - a->height() - 0.5 * _spatium;
}
else {
if (!a->layoutCloseToNote()) {
a->layout();
a->setPos(x, chordBotY);
a->doAutoplace();
}
chordBotY = a->y() + a->height() + 0.5 * _spatium;
}
2018-01-22 10:12:49 +01:00
}
//
// now place all articulations with staff top or bottom anchor
//
staffTopY = qMin(staffTopY, chordTopY - distance0 - 0.5 * _spatium);
staffBotY = qMax(staffBotY, chordBotY + distance0 + 0.5 * _spatium);
2018-01-22 10:12:49 +01:00
for (Articulation* a : _articulations) {
ArticulationAnchor aa = a->anchor();
if (aa == ArticulationAnchor::TOP_STAFF || aa == ArticulationAnchor::BOTTOM_STAFF) {
a->layout();
2018-01-22 10:12:49 +01:00
if (a->up()) {
2018-01-23 13:19:34 +01:00
a->setPos(x, staffTopY);
staffTopY -= distance0;
2018-01-22 10:12:49 +01:00
}
else {
2018-01-23 13:19:34 +01:00
a->setPos(x, staffBotY);
staffBotY += distance0;
2018-01-22 10:12:49 +01:00
}
a->doAutoplace();
}
}
2018-09-12 10:51:08 +02:00
for (Articulation* a : _articulations) {
if (a->addToSkyline()) {
// the segment shape has already been calculated
// so measure width and spacing is already determined
// in line mode, we cannot add to segment shape without throwing this off
// but adding to skyline is always good
Segment* s = segment();
Measure* m = s->measure();
QRectF r = a->bbox().translated(a->pos() + pos());
// TODO: limit to width of chord
// this avoids "staircase" effect due to space not having been allocated already
// ANOTHER alternative is to allocate the space in layoutPitched() / layoutTablature()
//qreal w = qMin(r.width(), width());
//r.translate((r.width() - w) * 0.5, 0.0);
//r.setWidth(w);
if (!score()->lineMode())
s->staffShape(staffIdx()).add(r);
r.translate(s->pos() + m->pos());
m->system()->staff(vStaffIdx())->skyline().add(r);
}
2018-09-12 10:51:08 +02:00
}
2018-01-22 10:12:49 +01:00
}
//---------------------------------------------------------
// layoutArticulations3
// Called after layouting slurs
// Fix up articulations that need to go outside the slur
//---------------------------------------------------------
void Chord::layoutArticulations3(Slur* slur)
{
SlurSegment* ss;
if (this == slur->startCR())
ss = slur->frontSegment();
else if (this == slur->endCR())
ss = slur->backSegment();
else
return;
Segment* s = segment();
Measure* m = measure();
SysStaff* sstaff = m->system() ? m->system()->staff(vStaffIdx()) : nullptr;
for (Articulation* a : _articulations) {
if (a->layoutCloseToNote() || !a->autoplace() || !slur->addToSkyline())
continue;
Shape aShape = a->shape().translated(a->pos() + pos() + s->pos() + m->pos());
Shape sShape = ss->shape().translated(ss->pos());
if (aShape.intersects(sShape)) {
qreal d = score()->styleS(Sid::articulationMinDistance).val() * spatium();
if (slur->up()) {
d += qMax(aShape.minVerticalDistance(sShape), 0.0);
a->rypos() -= d;
aShape.translateY(-d);
}
else {
d += qMax(sShape.minVerticalDistance(aShape), 0.0);
a->rypos() += d;
aShape.translateY(d);
}
if (sstaff && a->addToSkyline())
sstaff->skyline().add(aShape);
}
}
}
2016-01-04 14:48:58 +01:00
//---------------------------------------------------------
// getNoteEventLists
// Get contents of all NoteEventLists for all notes in
// the chord.
//---------------------------------------------------------
QList<NoteEventList> Chord::getNoteEventLists()
{
QList<NoteEventList> ell;
if (notes().empty())
return ell;
for (size_t i = 0; i < notes().size(); ++i) {
ell.append(NoteEventList(notes()[i]->playEvents()));
}
return ell;
}
//---------------------------------------------------------
// setNoteEventLists
// Set contents of all NoteEventLists for all notes in
// the chord.
//---------------------------------------------------------
void Chord::setNoteEventLists(QList<NoteEventList>& ell)
{
if (notes().empty())
return;
Q_ASSERT(ell.size() == int(notes().size()));
for (size_t i = 0; int(i) < ell.size(); i++) {
notes()[i]->setPlayEvents(ell[int(i)]);
}
}
}