MuseScore/libmscore/palmmute.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

283 lines
9.1 KiB
C++
Raw Normal View History

2017-11-27 16:55:52 +01:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2017 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 "palmmute.h"
#include "sym.h"
#include "xml.h"
#include "system.h"
#include "measure.h"
#include "chordrest.h"
#include "score.h"
namespace Ms {
2018-08-01 11:46:07 +02:00
static const ElementStyle palmMuteStyle {
{ Sid::palmMuteFontFace, Pid::BEGIN_FONT_FACE },
{ Sid::palmMuteFontFace, Pid::CONTINUE_FONT_FACE },
{ Sid::palmMuteFontFace, Pid::END_FONT_FACE },
{ Sid::palmMuteFontSize, Pid::BEGIN_FONT_SIZE },
{ Sid::palmMuteFontSize, Pid::CONTINUE_FONT_SIZE },
{ Sid::palmMuteFontSize, Pid::END_FONT_SIZE },
{ Sid::palmMuteFontStyle, Pid::BEGIN_FONT_STYLE },
{ Sid::palmMuteFontStyle, Pid::CONTINUE_FONT_STYLE },
{ Sid::palmMuteFontStyle, Pid::END_FONT_STYLE },
2018-08-01 11:46:07 +02:00
{ Sid::palmMuteTextAlign, Pid::BEGIN_TEXT_ALIGN },
{ Sid::palmMuteTextAlign, Pid::CONTINUE_TEXT_ALIGN },
{ Sid::palmMuteTextAlign, Pid::END_TEXT_ALIGN },
{ Sid::palmMuteHookHeight, Pid::BEGIN_HOOK_HEIGHT },
{ Sid::palmMuteHookHeight, Pid::END_HOOK_HEIGHT },
{ Sid::palmMutePosBelow, Pid::OFFSET },
{ Sid::palmMuteLineStyle, Pid::LINE_STYLE },
{ Sid::palmMuteBeginTextOffset, Pid::BEGIN_TEXT_OFFSET },
{ Sid::palmMuteEndHookType, Pid::END_HOOK_TYPE },
{ Sid::palmMuteLineWidth, Pid::LINE_WIDTH },
{ Sid::palmMutePlacement, Pid::PLACEMENT },
{ Sid::palmMutePosBelow, Pid::OFFSET },
2018-08-01 11:46:07 +02:00
};
2017-11-27 16:55:52 +01:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void PalmMuteSegment::layout()
{
TextLineBaseSegment::layout();
autoplaceSpannerSegment();
2017-11-27 16:55:52 +01:00
}
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
Sid PalmMuteSegment::getPropertyStyle(Pid pid) const
{
if (pid == Pid::OFFSET) {
return spanner()->placeAbove() ? Sid::palmMutePosAbove : Sid::palmMutePosBelow;
2020-05-26 15:54:26 +02:00
}
return TextLineBaseSegment::getPropertyStyle(pid);
}
Sid PalmMute::getPropertyStyle(Pid pid) const
{
if (pid == Pid::OFFSET) {
return placeAbove() ? Sid::palmMutePosAbove : Sid::palmMutePosBelow;
2020-05-26 15:54:26 +02:00
}
return TextLineBase::getPropertyStyle(pid);
}
2017-11-27 16:55:52 +01:00
//---------------------------------------------------------
// PalmMute
//---------------------------------------------------------
2020-05-29 18:47:27 +02:00
PalmMute::PalmMute(Score* s)
: TextLineBase(s)
2017-11-27 16:55:52 +01:00
{
2018-08-01 11:46:07 +02:00
initElementStyle(&palmMuteStyle);
2018-04-09 11:51:35 +02:00
resetProperty(Pid::LINE_VISIBLE);
2020-05-26 15:54:26 +02:00
resetProperty(Pid::BEGIN_TEXT_PLACE);
resetProperty(Pid::BEGIN_TEXT);
2019-04-10 12:34:04 +02:00
resetProperty(Pid::CONTINUE_TEXT_PLACE);
resetProperty(Pid::CONTINUE_TEXT);
resetProperty(Pid::END_TEXT_PLACE);
resetProperty(Pid::END_TEXT);
2017-11-27 16:55:52 +01:00
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void PalmMute::read(XmlReader& e)
{
2018-08-27 22:57:15 +02:00
if (score()->mscVersion() < 301) {
e.addSpanner(e.intAttribute("id", -1), this);
2020-05-26 15:54:26 +02:00
}
2017-11-27 16:55:52 +01:00
while (e.readNextStartElement()) {
if (readProperty(e.name(), e, Pid::LINE_WIDTH)) {
setPropertyFlags(Pid::LINE_WIDTH, PropertyFlags::UNSTYLED);
} else if (!TextLineBase::readProperties(e)) {
2017-11-27 16:55:52 +01:00
e.unknown();
2020-05-26 15:54:26 +02:00
}
2017-11-27 16:55:52 +01:00
}
}
2018-03-27 14:40:34 +02:00
//---------------------------------------------------------
// write
//
// The removal of this function is potentially a temporary
// change. For now, the intended behavior does no more than
// the base write function and so we will just use that.
//
// also see letring.cpp
2018-03-27 14:40:34 +02:00
//---------------------------------------------------------
/*
2018-03-27 14:40:34 +02:00
void PalmMute::write(XmlWriter& xml) const
{
if (!xml.canWrite(this))
return;
xml.stag(this);
2018-03-27 14:40:34 +02:00
for (const StyledProperty& spp : *styledProperties()) {
if(!isStyled(spp.pid))
writeProperty(xml, spp.pid);
}
2018-03-27 14:40:34 +02:00
TextLineBase::writeProperties(xml);
2018-03-27 14:40:34 +02:00
xml.etag();
}
*/
2018-03-27 14:40:34 +02:00
2017-11-27 16:55:52 +01:00
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
static const ElementStyle palmMuteSegmentStyle {
{ Sid::palmMutePosBelow, Pid::OFFSET },
{ Sid::palmMuteMinDistance, Pid::MIN_DISTANCE },
};
2017-11-27 16:55:52 +01:00
LineSegment* PalmMute::createLineSegment()
{
PalmMuteSegment* pms = new PalmMuteSegment(this, score());
pms->setTrack(track());
pms->initElementStyle(&palmMuteSegmentStyle);
return pms;
2017-11-27 16:55:52 +01:00
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant PalmMute::propertyDefault(Pid propertyId) const
2017-11-27 16:55:52 +01:00
{
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::LINE_WIDTH:
return score()->styleV(Sid::palmMuteLineWidth);
2017-11-27 16:55:52 +01:00
2018-03-27 15:36:00 +02:00
case Pid::ALIGN:
2017-11-27 16:55:52 +01:00
return QVariant::fromValue(Align::LEFT | Align::BASELINE);
2018-03-27 15:36:00 +02:00
case Pid::LINE_STYLE:
return score()->styleV(Sid::palmMuteLineStyle);
2017-11-27 16:55:52 +01:00
2018-04-09 11:51:35 +02:00
case Pid::LINE_VISIBLE:
return true;
case Pid::CONTINUE_TEXT_OFFSET:
case Pid::END_TEXT_OFFSET:
return QPointF(0, 0);
2017-11-28 09:28:59 +01:00
//TODOws case Pid::BEGIN_FONT_ITALIC:
// return score()->styleV(Sid::palmMuteFontItalic);
2017-11-28 09:28:59 +01:00
2018-03-27 15:36:00 +02:00
case Pid::BEGIN_TEXT:
return score()->styleV(Sid::palmMuteText);
case Pid::CONTINUE_TEXT:
case Pid::END_TEXT:
return "";
case Pid::BEGIN_HOOK_TYPE:
return int(HookType::NONE);
2017-11-28 09:28:59 +01:00
case Pid::BEGIN_TEXT_PLACE:
case Pid::CONTINUE_TEXT_PLACE:
case Pid::END_TEXT_PLACE:
return int(PlaceText::AUTO);
2017-11-27 16:55:52 +01:00
default:
return TextLineBase::propertyDefault(propertyId);
}
}
//---------------------------------------------------------
// linePos
// return System() coordinates
//---------------------------------------------------------
QPointF PalmMute::linePos(Grip grip, System** sys) const
{
qreal x = 0.0;
2017-11-27 16:55:52 +01:00
qreal nhw = score()->noteHeadWidth();
System* s = nullptr;
if (grip == Grip::START) {
ChordRest* c = toChordRest(startElement());
if (!c) {
return QPointF();
2020-05-26 15:54:26 +02:00
}
2017-11-27 16:55:52 +01:00
s = c->segment()->system();
x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
if (c->isRest() && c->durationType() == TDuration::DurationType::V_MEASURE) {
x -= c->x();
2020-05-26 15:54:26 +02:00
}
} else {
2017-11-27 16:55:52 +01:00
Element* e = endElement();
ChordRest* c = toChordRest(endElement());
if (!e || e == startElement() || (endHookType() == HookType::HOOK_90)) {
// palmMute marking on single note or ends with non-angled hook:
// extend to next note or end of measure
Segment* seg = nullptr;
2020-05-26 15:54:26 +02:00
if (!e) {
2017-11-27 16:55:52 +01:00
seg = startSegment();
2020-05-26 15:54:26 +02:00
} else {
2017-11-27 16:55:52 +01:00
seg = c->segment();
}
if (seg) {
seg = seg->next();
for (; seg; seg = seg->next()) {
if (seg->isChordRestType()) {
// look for a chord/rest in any voice on this staff
bool crFound = false;
int track = staffIdx() * VOICES;
for (int i = 0; i < VOICES; ++i) {
if (seg->element(track + i)) {
crFound = true;
break;
}
}
if (crFound) {
break;
}
} else if (seg->segmentType() == SegmentType::EndBarLine) {
break;
}
2020-05-26 15:54:26 +02:00
}
2017-11-27 16:55:52 +01:00
}
if (seg) {
s = seg->system();
x = seg->pos().x() + seg->measure()->pos().x() - nhw * 2;
2020-05-26 15:54:26 +02:00
}
2017-11-27 16:55:52 +01:00
} else if (c) {
s = c->segment()->system();
x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
if (c->type() == ElementType::REST && c->durationType() == TDuration::DurationType::V_MEASURE) {
x -= c->x();
2020-05-26 15:54:26 +02:00
}
}
2017-11-27 16:55:52 +01:00
if (!s) {
Fraction t = tick2();
2017-11-27 16:55:52 +01:00
Measure* m = score()->tick2measure(t);
s = m->system();
x = m->tick2pos(t);
2020-05-26 15:54:26 +02:00
}
2017-11-27 16:55:52 +01:00
if (endHookType() == HookType::HOOK_45) {
x += nhw * .5;
2020-05-26 15:54:26 +02:00
} else {
2017-11-27 16:55:52 +01:00
x += nhw;
2020-05-26 15:54:26 +02:00
}
}
2017-11-27 16:55:52 +01:00
*sys = s;
return QPointF(x, 0);
}
}