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 "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"
|
2017-12-27 16:09:12 +01:00
|
|
|
#include "staff.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
#include "score.h"
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2018-08-01 11:46:07 +02:00
|
|
|
static const ElementStyle pedalStyle {
|
|
|
|
{ Sid::pedalFontFace, Pid::BEGIN_FONT_FACE },
|
|
|
|
{ Sid::pedalFontFace, Pid::CONTINUE_FONT_FACE },
|
|
|
|
{ Sid::pedalFontFace, Pid::END_FONT_FACE },
|
|
|
|
{ Sid::pedalFontSize, Pid::BEGIN_FONT_SIZE },
|
|
|
|
{ Sid::pedalFontSize, Pid::CONTINUE_FONT_SIZE },
|
|
|
|
{ Sid::pedalFontSize, Pid::END_FONT_SIZE },
|
2018-11-26 21:09:20 +01:00
|
|
|
{ Sid::pedalFontStyle, Pid::BEGIN_FONT_STYLE },
|
|
|
|
{ Sid::pedalFontStyle, Pid::CONTINUE_FONT_STYLE },
|
|
|
|
{ Sid::pedalFontStyle, Pid::END_FONT_STYLE },
|
2018-08-01 11:46:07 +02:00
|
|
|
{ Sid::pedalTextAlign, Pid::BEGIN_TEXT_ALIGN },
|
|
|
|
{ Sid::pedalTextAlign, Pid::CONTINUE_TEXT_ALIGN },
|
|
|
|
{ Sid::pedalTextAlign, Pid::END_TEXT_ALIGN },
|
|
|
|
{ Sid::pedalHookHeight, Pid::BEGIN_HOOK_HEIGHT },
|
|
|
|
{ Sid::pedalHookHeight, Pid::END_HOOK_HEIGHT },
|
|
|
|
{ Sid::pedalBeginTextOffset, Pid::BEGIN_TEXT_OFFSET },
|
|
|
|
{ Sid::pedalBeginTextOffset, Pid::CONTINUE_TEXT_OFFSET },
|
|
|
|
{ Sid::pedalBeginTextOffset, Pid::END_TEXT_OFFSET },
|
|
|
|
{ Sid::pedalPlacement, Pid::PLACEMENT },
|
2018-10-25 15:43:59 +02:00
|
|
|
{ Sid::pedalPosBelow, Pid::OFFSET },
|
2018-08-01 11:46:07 +02:00
|
|
|
};
|
|
|
|
|
2012-10-27 14:46:35 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void PedalSegment::layout()
|
|
|
|
{
|
2016-08-30 14:03:26 +02:00
|
|
|
TextLineBaseSegment::layout();
|
2018-11-05 11:49:28 +01:00
|
|
|
autoplaceSpannerSegment(spatium() * .7);
|
2016-11-18 14:28:53 +01:00
|
|
|
}
|
|
|
|
|
2018-10-25 15:43:59 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// getPropertyStyle
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Sid PedalSegment::getPropertyStyle(Pid pid) const
|
|
|
|
{
|
|
|
|
if (pid == Pid::OFFSET)
|
|
|
|
return spanner()->placeAbove() ? Sid::pedalPosAbove : Sid::pedalPosBelow;
|
|
|
|
return TextLineBaseSegment::getPropertyStyle(pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sid Pedal::getPropertyStyle(Pid pid) const
|
|
|
|
{
|
|
|
|
if (pid == Pid::OFFSET)
|
|
|
|
return placeAbove() ? Sid::pedalPosAbove : Sid::pedalPosBelow;
|
|
|
|
return TextLineBase::getPropertyStyle(pid);
|
|
|
|
}
|
2017-06-08 15:43:05 +02:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// Pedal
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Pedal::Pedal(Score* s)
|
2016-08-30 14:03:26 +02:00
|
|
|
: TextLineBase(s)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2018-08-01 11:46:07 +02:00
|
|
|
initElementStyle(&pedalStyle);
|
2018-03-27 14:40:34 +02:00
|
|
|
setLineVisible(true);
|
2018-03-27 15:36:00 +02:00
|
|
|
resetProperty(Pid::BEGIN_TEXT);
|
|
|
|
resetProperty(Pid::END_TEXT);
|
2018-03-27 14:40:34 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
resetProperty(Pid::LINE_WIDTH);
|
|
|
|
resetProperty(Pid::LINE_STYLE);
|
2018-03-27 14:40:34 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
resetProperty(Pid::BEGIN_HOOK_TYPE);
|
|
|
|
resetProperty(Pid::END_HOOK_TYPE);
|
2018-03-27 14:40:34 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
resetProperty(Pid::BEGIN_TEXT_PLACE);
|
2018-07-04 15:08:45 +02:00
|
|
|
resetProperty(Pid::LINE_VISIBLE);
|
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
|
|
|
{
|
2018-08-27 22:57:15 +02:00
|
|
|
if (score()->mscVersion() < 301)
|
|
|
|
e.addSpanner(e.intAttribute("id", -1), this);
|
2013-07-25 10:47:01 +02:00
|
|
|
while (e.readNextStartElement()) {
|
2017-02-07 18:48:23 +01:00
|
|
|
if (!TextLineBase::readProperties(e))
|
2013-07-25 10:47:01 +02:00
|
|
|
e.unknown();
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
2012-10-27 14:46:35 +02:00
|
|
|
|
2018-03-27 14:40:34 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// write
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Pedal::write(XmlWriter& xml) const
|
|
|
|
{
|
|
|
|
if (!xml.canWrite(this))
|
|
|
|
return;
|
2018-09-26 12:20:00 +02:00
|
|
|
xml.stag(this);
|
2018-03-27 14:40:34 +02:00
|
|
|
|
|
|
|
for (auto i : {
|
2018-03-27 15:36:00 +02:00
|
|
|
Pid::END_HOOK_TYPE,
|
|
|
|
Pid::BEGIN_TEXT,
|
|
|
|
Pid::END_TEXT,
|
2018-12-06 15:16:46 +01:00
|
|
|
Pid::LINE_VISIBLE,
|
2018-03-27 15:36:00 +02:00
|
|
|
Pid::BEGIN_HOOK_TYPE
|
2018-03-27 14:40:34 +02:00
|
|
|
}) {
|
|
|
|
writeProperty(xml, i);
|
|
|
|
}
|
2018-08-01 11:46:07 +02:00
|
|
|
for (const StyledProperty& spp : *styledProperties())
|
|
|
|
writeProperty(xml, spp.pid);
|
2018-03-27 14:40:34 +02:00
|
|
|
|
2019-01-09 10:32:05 +01:00
|
|
|
SLine::writeProperties(xml);
|
2018-03-27 14:40:34 +02:00
|
|
|
xml.etag();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-27 14:46:35 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// createLineSegment
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-10-25 15:43:59 +02:00
|
|
|
static const ElementStyle pedalSegmentStyle {
|
|
|
|
{ Sid::pedalPosBelow, Pid::OFFSET },
|
|
|
|
};
|
|
|
|
|
2012-10-27 14:46:35 +02:00
|
|
|
LineSegment* Pedal::createLineSegment()
|
|
|
|
{
|
2018-12-05 15:17:33 +01:00
|
|
|
PedalSegment* p = new PedalSegment(this, score());
|
2018-12-12 14:41:57 +01:00
|
|
|
p->setTrack(track());
|
2018-10-25 15:43:59 +02:00
|
|
|
p->initElementStyle(&pedalSegmentStyle);
|
|
|
|
return p;
|
2012-10-27 14:46:35 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 11:42:24 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// propertyDefault
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
QVariant Pedal::propertyDefault(Pid propertyId) const
|
2013-08-09 11:42:24 +02:00
|
|
|
{
|
|
|
|
switch (propertyId) {
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::LINE_WIDTH:
|
2018-07-04 15:08:45 +02:00
|
|
|
return score()->styleP(Sid::pedalLineWidth); // return point, not spatium
|
2013-08-09 11:42:24 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::LINE_STYLE:
|
|
|
|
return score()->styleV(Sid::pedalLineStyle);
|
2013-08-09 11:42:24 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::BEGIN_TEXT:
|
2018-07-04 15:08:45 +02:00
|
|
|
case Pid::CONTINUE_TEXT:
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::END_TEXT:
|
2018-03-27 14:40:34 +02:00
|
|
|
return "";
|
2013-08-09 11:42:24 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::BEGIN_TEXT_PLACE:
|
2018-07-04 15:08:45 +02:00
|
|
|
case Pid::CONTINUE_TEXT_PLACE:
|
|
|
|
case Pid::END_TEXT_PLACE:
|
2018-03-27 14:40:34 +02:00
|
|
|
return int(PlaceText::LEFT);
|
2017-06-08 15:43:05 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::BEGIN_HOOK_TYPE:
|
|
|
|
case Pid::END_HOOK_TYPE:
|
2018-03-27 14:40:34 +02:00
|
|
|
return int(HookType::NONE);
|
2013-08-09 11:42:24 +02:00
|
|
|
|
2018-07-04 15:08:45 +02:00
|
|
|
case Pid::LINE_VISIBLE:
|
|
|
|
return true;
|
|
|
|
|
2013-08-09 11:42:24 +02:00
|
|
|
default:
|
2017-02-07 18:48:23 +01:00
|
|
|
return TextLineBase::propertyDefault(propertyId);
|
2013-08-09 11:42:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 17:09:27 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// linePos
|
|
|
|
// return System() coordinates
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2015-01-19 12:37:17 +01:00
|
|
|
QPointF Pedal::linePos(Grip grip, System** sys) const
|
2014-05-27 17:09:27 +02:00
|
|
|
{
|
2018-08-14 10:03:49 +02:00
|
|
|
qreal x = 0.0;
|
2014-05-27 17:09:27 +02:00
|
|
|
qreal nhw = score()->noteHeadWidth();
|
2014-08-21 21:33:06 +02:00
|
|
|
System* s = nullptr;
|
2015-01-19 12:37:17 +01:00
|
|
|
if (grip == Grip::START) {
|
2017-12-20 16:49:30 +01:00
|
|
|
ChordRest* c = toChordRest(startElement());
|
2018-08-15 08:56:32 +02:00
|
|
|
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();
|
|
|
|
if (beginHookType() == HookType::HOOK_45)
|
|
|
|
x += nhw * .5;
|
|
|
|
}
|
2014-05-27 17:09:27 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-08-21 21:33:06 +02:00
|
|
|
Element* e = endElement();
|
2017-12-20 16:49:30 +01:00
|
|
|
ChordRest* c = toChordRest(endElement());
|
2017-02-07 18:48:23 +01:00
|
|
|
if (!e || e == startElement() || (endHookType() == HookType::HOOK_90)) {
|
2014-10-04 03:09:59 +02:00
|
|
|
// pedal marking on single note or ends with non-angled hook:
|
|
|
|
// extend to next note or end of measure
|
|
|
|
Segment* seg = nullptr;
|
|
|
|
if (!e)
|
|
|
|
seg = startSegment();
|
|
|
|
else
|
|
|
|
seg = c->segment();
|
2014-08-21 21:33:06 +02:00
|
|
|
if (seg) {
|
|
|
|
seg = seg->next();
|
|
|
|
for ( ; seg; seg = seg->next()) {
|
2017-03-08 13:12:26 +01:00
|
|
|
if (seg->segmentType() == SegmentType::ChordRest) {
|
2014-10-08 06:54:00 +02:00
|
|
|
// 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)
|
2014-08-21 21:33:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-03-08 13:12:26 +01:00
|
|
|
else if (seg->segmentType() == SegmentType::EndBarLine) {
|
2014-08-21 21:33:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (seg) {
|
|
|
|
s = seg->system();
|
|
|
|
x = seg->pos().x() + seg->measure()->pos().x() - nhw * 2;
|
|
|
|
}
|
2014-05-27 17:09:27 +02:00
|
|
|
}
|
2014-10-04 03:09:59 +02:00
|
|
|
else if (c) {
|
|
|
|
s = c->segment()->system();
|
|
|
|
x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
|
2017-01-18 14:16:33 +01:00
|
|
|
if (c->type() == ElementType::REST && c->durationType() == TDuration::DurationType::V_MEASURE)
|
2014-10-04 03:09:59 +02:00
|
|
|
x -= c->x();
|
2014-08-21 21:33:06 +02:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2017-02-07 18:48:23 +01:00
|
|
|
if (endHookType() == HookType::HOOK_45)
|
2014-05-27 17:09:27 +02:00
|
|
|
x += nhw * .5;
|
|
|
|
else
|
|
|
|
x += nhw;
|
|
|
|
}
|
2014-10-04 03:09:59 +02:00
|
|
|
|
2014-05-27 17:09:27 +02:00
|
|
|
*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
|
|
|
}
|
|
|
|
|