MuseScore/libmscore/pedal.cpp

334 lines
10 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-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 "pedal.h"
#include "textline.h"
#include "sym.h"
2014-04-09 16:09:21 +02:00
#include "xml.h"
2014-05-27 17:09:27 +02:00
#include "system.h"
#include "measure.h"
#include "chordrest.h"
2012-05-26 14:26:10 +02:00
#include "score.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void PedalSegment::layout()
{
2012-11-07 16:47:42 +01:00
TextLineSegment::layout1();
2012-11-08 12:59:30 +01:00
if (parent()) // for palette
2014-05-26 15:31:36 +02:00
rypos() += score()->styleS(StyleIdx::pedalY).val() * spatium();
2012-10-27 14:46:35 +02:00
adjustReadPos();
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool PedalSegment::setProperty(P_ID id, const QVariant& v)
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
2013-08-09 11:42:24 +02:00
return pedal()->setProperty(id, v);
default:
return TextLineSegment::setProperty(id, v);
}
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant PedalSegment::propertyDefault(P_ID id) const
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
2013-08-09 11:42:24 +02:00
return pedal()->propertyDefault(id);
default:
return TextLineSegment::propertyDefault(id);
}
}
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle PedalSegment::propertyStyle(P_ID id) const
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
2013-08-09 11:42:24 +02:00
return pedal()->propertyStyle(id);
default:
return TextLineSegment::propertyStyle(id);
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void PedalSegment::resetProperty(P_ID id)
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
case P_ID::LINE_STYLE:
2013-08-09 11:42:24 +02:00
return pedal()->resetProperty(id);
default:
return TextLineSegment::resetProperty(id);
}
}
//---------------------------------------------------------
// styleChanged
//---------------------------------------------------------
void PedalSegment::styleChanged()
{
pedal()->styleChanged();
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Pedal
//---------------------------------------------------------
Pedal::Pedal(Score* s)
: TextLine(s)
{
setBeginHookHeight(Spatium(-1.2));
setEndHookHeight(Spatium(-1.2));
2013-08-09 11:42:24 +02:00
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
2013-08-09 11:42:24 +02:00
lineWidthStyle = PropertyStyle::STYLED;
2014-05-26 15:31:36 +02:00
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
2013-08-09 11:42:24 +02:00
lineStyleStyle = PropertyStyle::STYLED;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Pedal::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
if (score()->mscVersion() >= 110) {
// setBeginSymbol(SymId::noSym);
2012-05-26 14:26:10 +02:00
setEndHook(false);
}
2014-07-21 13:24:21 +02:00
int id = e.intAttribute("id", -1);
e.addSpanner(id, this);
while (e.readNextStartElement()) {
2013-08-09 11:42:24 +02:00
const QStringRef& tag(e.name());
if (tag == "subtype") // obsolete
e.skipCurrentElement();
2013-08-09 11:42:24 +02:00
else if (tag == "lineWidth") {
setLineWidth(Spatium(e.readDouble()));
lineWidthStyle = PropertyStyle::UNSTYLED;
}
else if (tag == "lineStyle") {
setLineStyle(Qt::PenStyle(e.readInt()));
lineStyleStyle = PropertyStyle::UNSTYLED;
}
else if (!TextLine::readProperties(e))
e.unknown();
}
2012-05-26 14:26:10 +02:00
}
2012-10-27 14:46:35 +02:00
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
LineSegment* Pedal::createLineSegment()
{
return new PedalSegment(score());
}
//---------------------------------------------------------
// setYoff
//---------------------------------------------------------
void Pedal::setYoff(qreal val)
{
2014-05-26 15:31:36 +02:00
rUserYoffset() += (val - score()->styleS(StyleIdx::pedalY).val()) * spatium();
2012-10-27 14:46:35 +02:00
}
2013-08-09 11:42:24 +02:00
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Pedal::setProperty(P_ID propertyId, const QVariant& val)
{
switch (propertyId) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2013-08-09 11:42:24 +02:00
lineWidthStyle = PropertyStyle::UNSTYLED;
TextLine::setProperty(propertyId, val);
break;
2014-05-26 18:18:01 +02:00
case P_ID::LINE_STYLE:
2013-08-09 11:42:24 +02:00
lineStyleStyle = PropertyStyle::UNSTYLED;
TextLine::setProperty(propertyId, val);
break;
default:
if (!TextLine::setProperty(propertyId, val))
return false;
break;
}
score()->setLayoutAll(true);
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Pedal::propertyDefault(P_ID propertyId) const
{
switch (propertyId) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2014-05-26 15:31:36 +02:00
return score()->styleS(StyleIdx::pedalLineWidth).val();
2013-08-09 11:42:24 +02:00
2014-05-26 18:18:01 +02:00
case P_ID::LINE_STYLE:
2014-05-26 15:31:36 +02:00
return int(score()->styleI(StyleIdx::pedalLineStyle));
2013-08-09 11:42:24 +02:00
default:
return TextLine::propertyDefault(propertyId);
}
}
//---------------------------------------------------------
// propertyStyle
//---------------------------------------------------------
PropertyStyle Pedal::propertyStyle(P_ID id) const
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2013-08-09 11:42:24 +02:00
return lineWidthStyle;
2014-05-26 18:18:01 +02:00
case P_ID::LINE_STYLE:
2013-08-09 11:42:24 +02:00
return lineStyleStyle;
default:
return TextLine::propertyStyle(id);
}
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void Pedal::resetProperty(P_ID id)
{
switch (id) {
2014-05-26 18:18:01 +02:00
case P_ID::LINE_WIDTH:
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
2013-08-09 11:42:24 +02:00
lineWidthStyle = PropertyStyle::STYLED;
break;
2014-05-26 18:18:01 +02:00
case P_ID::LINE_STYLE:
2014-05-26 15:31:36 +02:00
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
2013-08-09 11:42:24 +02:00
lineStyleStyle = PropertyStyle::STYLED;
break;
default:
return TextLine::resetProperty(id);
}
}
//---------------------------------------------------------
// styleChanged
// reset all styled values to actual style
//---------------------------------------------------------
void Pedal::styleChanged()
{
if (lineWidthStyle == PropertyStyle::STYLED)
2014-05-26 15:31:36 +02:00
setLineWidth(score()->styleS(StyleIdx::pedalLineWidth));
2013-08-09 11:42:24 +02:00
if (lineStyleStyle == PropertyStyle::STYLED)
2014-05-26 15:31:36 +02:00
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::pedalLineStyle)));
2013-08-09 11:42:24 +02:00
}
2014-05-27 17:09:27 +02:00
//---------------------------------------------------------
// linePos
// return System() coordinates
//---------------------------------------------------------
2014-08-06 12:28:58 +02:00
QPointF Pedal::linePos(GripLine grip, System** sys) const
2014-05-27 17:09:27 +02:00
{
qreal x;
qreal nhw = score()->noteHeadWidth();
System* s = nullptr;
2014-05-27 17:09:27 +02:00
if (grip == GripLine::START) {
ChordRest* c = static_cast<ChordRest*>(startElement());
s = c->segment()->system();
x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
if (beginHook() && beginHookType() == HookType::HOOK_45)
x += nhw * .5;
}
else {
ChordRest* c = nullptr;
Element* e = endElement();
if (!e || e == startElement()) {
// pedal marking on single note - extend to next note or end of measure
Segment* seg = startSegment();
if (seg) {
seg = seg->next();
for ( ; seg; seg = seg->next()) {
if (seg->segmentType() == Segment::Type::ChordRest) {
if (seg->element(track()))
break;
}
else if (seg->segmentType() == Segment::Type::EndBarLine) {
break;
}
}
}
if (seg) {
s = seg->system();
x = seg->pos().x() + seg->measure()->pos().x() - nhw * 2;
}
2014-05-27 17:09:27 +02:00
}
else {
c = static_cast<ChordRest*>(endElement());
if (c) {
s = c->segment()->system();
x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
2014-08-22 20:59:05 +02:00
if (c && c->durationType() == TDuration::DurationType::V_MEASURE)
x -= c->x();
}
}
if (!s) {
2014-05-27 17:09:27 +02:00
int t = tick2();
Measure* m = score()->tick2measure(t);
s = m->system();
x = m->tick2pos(t);
}
if (endHook() && endHookType() == HookType::HOOK_45)
x += nhw * .5;
else
x += nhw;
}
*sys = s;
2014-07-18 17:53:08 +02:00
return QPointF(x, 0);
2014-05-27 17:09:27 +02:00
}
2013-05-13 18:49:17 +02:00
}