2012-05-26 14:26:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2010-2011 Werner Schweer
|
|
|
|
//
|
|
|
|
// 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 "shadownote.h"
|
|
|
|
#include "score.h"
|
|
|
|
#include "drumset.h"
|
|
|
|
#include "sym.h"
|
2016-06-03 00:39:58 +02:00
|
|
|
#include "rest.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
#include "mscore.h"
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// ShadowNote
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ShadowNote::ShadowNote(Score* s)
|
2016-06-03 00:39:58 +02:00
|
|
|
: Element(s), _notehead(SymId::noSym)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
|
|
|
_line = 1000;
|
2016-06-03 00:39:58 +02:00
|
|
|
_duration = TDuration(TDuration::DurationType::V_INVALID);
|
|
|
|
_voice = 0;
|
|
|
|
_rest = false;
|
2015-10-28 14:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShadowNote::isValid() const
|
|
|
|
{
|
|
|
|
return _notehead != SymId::noSym;
|
|
|
|
}
|
|
|
|
|
2016-06-03 00:39:58 +02:00
|
|
|
void ShadowNote::setState(SymId noteSymbol, int voice, TDuration duration, bool rest)
|
2015-10-28 14:11:29 +01:00
|
|
|
{
|
|
|
|
// clear symbols
|
|
|
|
_notehead = SymId::noSym;
|
2016-06-03 00:39:58 +02:00
|
|
|
|
2015-10-28 14:11:29 +01:00
|
|
|
_notehead = noteSymbol;
|
2016-06-03 00:39:58 +02:00
|
|
|
_duration = duration;
|
|
|
|
_voice = voice;
|
|
|
|
_rest = rest;
|
|
|
|
}
|
2015-10-28 14:11:29 +01:00
|
|
|
|
2016-06-03 00:39:58 +02:00
|
|
|
SymId ShadowNote::getNoteFlag() const
|
|
|
|
{
|
|
|
|
SymId flag = SymId::noSym;
|
|
|
|
if (_rest)
|
|
|
|
return flag;
|
|
|
|
TDuration::DurationType type = _duration.type();
|
2015-10-28 14:11:29 +01:00
|
|
|
switch(type) {
|
|
|
|
case TDuration::DurationType::V_LONG:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = SymId::lastSym;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_BREVE:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = SymId::noSym;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_WHOLE:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = SymId::noSym;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_HALF:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = SymId::lastSym;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_QUARTER:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = SymId::lastSym;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_EIGHTH:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = computeUp() ? SymId::flag8thUp : SymId::flag8thDown;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_16TH:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = computeUp() ? SymId::flag16thUp : SymId::flag16thDown;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_32ND:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = computeUp() ? SymId::flag32ndUp : SymId::flag32ndDown;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_64TH:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = computeUp() ? SymId::flag64thUp : SymId::flag64thDown;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
case TDuration::DurationType::V_128TH:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = computeUp() ? SymId::flag128thUp : SymId::flag128thDown;
|
2015-10-28 14:11:29 +01:00
|
|
|
break;
|
|
|
|
default:
|
2016-06-03 00:39:58 +02:00
|
|
|
flag = SymId::noSym;
|
2015-10-28 14:11:29 +01:00
|
|
|
}
|
2016-06-03 00:39:58 +02:00
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShadowNote::computeUp() const
|
|
|
|
{
|
|
|
|
if (_voice % VOICES == 0)
|
|
|
|
return _line > 4;
|
|
|
|
else
|
|
|
|
return _voice % VOICES == 2;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// draw
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ShadowNote::draw(QPainter* painter) const
|
|
|
|
{
|
2015-10-28 14:11:29 +01:00
|
|
|
if (!visible() || !isValid())
|
2012-05-26 14:26:10 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
QPointF ap(pagePos());
|
|
|
|
painter->translate(ap);
|
2015-10-28 14:11:29 +01:00
|
|
|
qreal lw = score()->styleP(StyleIdx::stemWidth);
|
2016-06-03 00:39:58 +02:00
|
|
|
QPen pen(MScore::selectColor[_voice].lighter(SHADOW_NOTE_LIGHT), lw, Qt::SolidLine, Qt::RoundCap);
|
2012-05-26 14:26:10 +02:00
|
|
|
painter->setPen(pen);
|
|
|
|
|
2015-10-28 14:11:29 +01:00
|
|
|
drawSymbol(_notehead, painter);
|
|
|
|
|
2016-06-03 00:39:58 +02:00
|
|
|
// draw the dots
|
2015-10-28 14:11:29 +01:00
|
|
|
qreal noteheadWidth = symWidth(_notehead);
|
2016-06-03 00:39:58 +02:00
|
|
|
QPointF posDot;
|
|
|
|
if (_duration.dots() > 0) {
|
|
|
|
qreal d = score()->styleP(StyleIdx::dotNoteDistance) * mag();
|
|
|
|
qreal dd = score()->styleP(StyleIdx::dotDotDistance) * mag();
|
|
|
|
posDot.rx() += (noteheadWidth + d);
|
|
|
|
if (!_rest)
|
|
|
|
posDot.ry() -= (_line % 2 == 0 ? 0.5 * spatium() : 0);
|
|
|
|
else
|
|
|
|
posDot.ry() += Rest::getDotline(_duration.type()) * spatium() * mag() * .5;
|
|
|
|
for (int i = 0; i < _duration.dots(); i++) {
|
|
|
|
posDot.rx() += dd * i;
|
|
|
|
drawSymbol(SymId::augmentationDot, painter, posDot, 1);
|
|
|
|
posDot.rx() -= dd * i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// stem and flag
|
|
|
|
SymId flag = getNoteFlag();
|
|
|
|
int up = computeUp() ? 1 : -1;
|
|
|
|
if (flag != SymId::noSym) {
|
2015-10-28 14:11:29 +01:00
|
|
|
QPointF pos;
|
2016-06-03 00:39:58 +02:00
|
|
|
pos.rx() = up == 1 ? (noteheadWidth - (lw / 2)) : lw / 2;
|
|
|
|
qreal yOffset = up == 1 ? symStemUpSE(_notehead).y() * magS() : symStemDownNW(_notehead).y() * magS();
|
|
|
|
if(flag != SymId::lastSym) {
|
|
|
|
pos.ry() -= up * (symHeight(flag) + (posDot.y() != 0 ? posDot.y() + spatium() : 0) + 0.5*spatium());
|
|
|
|
painter->drawLine(QLineF(pos.x(), yOffset, pos.x(), pos.y() - up * (yOffset + lw/2)));
|
2015-10-28 14:11:29 +01:00
|
|
|
pos.rx() -= (lw / 2); // flag offset?
|
2016-06-03 00:39:58 +02:00
|
|
|
drawSymbol(flag, painter, pos, 1);
|
2015-10-28 14:11:29 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-06-03 00:39:58 +02:00
|
|
|
painter->drawLine(QLineF(pos.x(), yOffset, pos.x(), -3 * up * spatium() * mag() + yOffset));
|
2015-10-28 14:11:29 +01:00
|
|
|
}
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
qreal ms = spatium();
|
2015-10-28 14:11:29 +01:00
|
|
|
qreal x1 = noteheadWidth * .5 - (ms * mag());
|
2013-06-05 17:19:11 +02:00
|
|
|
qreal x2 = x1 + 2 * ms * mag();
|
2012-05-26 14:26:10 +02:00
|
|
|
ms *= .5;
|
2015-10-28 14:11:29 +01:00
|
|
|
|
|
|
|
lw = score()->styleP(StyleIdx::ledgerLineWidth);
|
2016-06-03 00:39:58 +02:00
|
|
|
QPen penL(MScore::selectColor[_voice].lighter(SHADOW_NOTE_LIGHT), lw);
|
2015-10-28 14:11:29 +01:00
|
|
|
painter->setPen(penL);
|
|
|
|
|
2016-06-03 00:39:58 +02:00
|
|
|
if (_line < 100 && _line > -100 && !_rest) {
|
2012-05-26 14:26:10 +02:00
|
|
|
for (int i = -2; i >= _line; i -= 2) {
|
2013-06-05 20:20:19 +02:00
|
|
|
qreal y = ms * mag() * (i - _line);
|
2012-05-26 14:26:10 +02:00
|
|
|
painter->drawLine(QLineF(x1, y, x2, y));
|
|
|
|
}
|
|
|
|
for (int i = 10; i <= _line; i += 2) {
|
2013-06-05 20:20:19 +02:00
|
|
|
qreal y = ms * mag() * (i - _line);
|
2012-05-26 14:26:10 +02:00
|
|
|
painter->drawLine(QLineF(x1, y, x2, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
painter->translate(-ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ShadowNote::layout()
|
|
|
|
{
|
2015-10-28 14:11:29 +01:00
|
|
|
if (!isValid()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
setbbox(QRectF());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qreal _spatium = spatium();
|
2015-10-28 14:11:29 +01:00
|
|
|
QRectF b;
|
|
|
|
QRectF noteheadBbox = symBbox(_notehead);
|
2016-06-03 00:39:58 +02:00
|
|
|
SymId flag = getNoteFlag();
|
|
|
|
qreal height = noteheadBbox.height();
|
|
|
|
qreal dotWidth = 0;
|
|
|
|
if (_duration.dots() > 0) {
|
|
|
|
qreal noteheadWidth = symWidth(_notehead);
|
|
|
|
qreal d = score()->styleP(StyleIdx::dotNoteDistance) * mag();
|
|
|
|
qreal dd = score()->styleP(StyleIdx::dotDotDistance) * mag();
|
|
|
|
dotWidth += (noteheadWidth + d);
|
|
|
|
for (int i = 0; i < _duration.dots(); i++)
|
|
|
|
dotWidth += dd * i;
|
|
|
|
height += (_line % 2 == 0 && !_rest ? 0.5 * spatium() : 0); // move flag up
|
|
|
|
}
|
|
|
|
if(flag == SymId::noSym) {
|
|
|
|
b.setRect(noteheadBbox.x(), noteheadBbox.y(), noteheadBbox.width() + dotWidth, noteheadBbox.height());
|
2015-10-28 14:11:29 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
qreal x = noteheadBbox.x();
|
|
|
|
qreal width = noteheadBbox.width();
|
2016-06-03 00:39:58 +02:00
|
|
|
qreal flagWidth = 0;
|
|
|
|
int up = computeUp() ? 1 : 0;
|
|
|
|
qreal y = up ? 0 : -height;
|
|
|
|
if (flag != SymId::lastSym) {
|
|
|
|
QRectF flagBbox = symBbox(flag);
|
|
|
|
qreal lw = score()->styleP(StyleIdx::stemWidth) * mag();
|
|
|
|
qreal h = flagBbox.height() + lw / 2 + spatium() * mag();
|
|
|
|
y -= h * up;
|
|
|
|
height += h;
|
|
|
|
flagWidth = flagBbox.width();
|
2015-10-28 14:11:29 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-06-03 00:39:58 +02:00
|
|
|
qreal sh = 4 * spatium() * mag();
|
|
|
|
y -= up * sh;
|
|
|
|
height += sh;
|
2015-10-28 14:11:29 +01:00
|
|
|
}
|
2016-06-03 00:39:58 +02:00
|
|
|
width += qMax(flagWidth, dotWidth);
|
2015-10-28 14:11:29 +01:00
|
|
|
|
|
|
|
b.setRect(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2016-06-03 00:39:58 +02:00
|
|
|
qreal lw = score()->styleP(StyleIdx::ledgerLineWidth);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2015-10-28 14:11:29 +01:00
|
|
|
qreal x1 = (noteheadBbox.width()) * .5 - (_spatium * mag()) - lw * .5;
|
|
|
|
|
2013-07-25 10:47:01 +02:00
|
|
|
qreal x2 = x1 + 2 * _spatium * mag() + lw * .5;
|
|
|
|
|
|
|
|
InputState ps = score()->inputState();
|
|
|
|
QRectF r(x1, -lw * .5, x2 - x1, lw);
|
2013-10-24 12:09:00 +02:00
|
|
|
if (_line < 100 && _line > -100 && !ps.rest()) {
|
2012-05-26 14:26:10 +02:00
|
|
|
for (int i = -2; i >= _line; i -= 2)
|
2013-07-25 10:47:01 +02:00
|
|
|
b |= r.translated(QPointF(0, _spatium * .5 * (i - _line)));
|
2012-05-26 14:26:10 +02:00
|
|
|
for (int i = 10; i <= _line; i += 2)
|
2013-07-25 10:47:01 +02:00
|
|
|
b |= r.translated(QPointF(0, _spatium * .5 * (i - _line)));
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
setbbox(b);
|
|
|
|
}
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|