MuseScore/libmscore/letring.cpp
ws ec3be9a99a Replacd integer midi tick values by fractions.
- tick names a position on the time axis
- tick is always a Fraction()
- only Measure() and Segment() (and Tuplet?) have a tick value
- tick() for an generic element return only a sensible value if isMeasure() or isSegment() or isSegment(parent())

- "ticks" names a duration stored in a Fraction()
- the tick value for an Segment is relative to its measure

- rename "duration" to "ticks"
- rename afrac() to tick()
- rename rfrac() to rtick()
- rename some variables, changing "fraction" into "tick"
  (example: actualFraction() into actualTicks())

- Lyrics ticks are written as Fraction, on read if xmlreader sees a "/" it reads a fraction
  else midi ticks for backwards compatibility
2019-02-18 11:46:05 +01:00

260 lines
9.2 KiB
C++

//=============================================================================
// 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 "letring.h"
#include "sym.h"
#include "xml.h"
#include "system.h"
#include "measure.h"
#include "chordrest.h"
#include "score.h"
namespace Ms {
static const ElementStyle letRingStyle {
{ Sid::letRingFontFace, Pid::BEGIN_FONT_FACE },
{ Sid::letRingFontFace, Pid::CONTINUE_FONT_FACE },
{ Sid::letRingFontFace, Pid::END_FONT_FACE },
{ Sid::letRingFontSize, Pid::BEGIN_FONT_SIZE },
{ Sid::letRingFontSize, Pid::CONTINUE_FONT_SIZE },
{ Sid::letRingFontSize, Pid::END_FONT_SIZE },
{ Sid::letRingFontStyle, Pid::BEGIN_FONT_STYLE },
{ Sid::letRingFontStyle, Pid::CONTINUE_FONT_STYLE },
{ Sid::letRingFontStyle, Pid::END_FONT_STYLE },
{ Sid::letRingTextAlign, Pid::BEGIN_TEXT_ALIGN },
{ Sid::letRingTextAlign, Pid::CONTINUE_TEXT_ALIGN },
{ Sid::letRingTextAlign, Pid::END_TEXT_ALIGN },
{ Sid::letRingHookHeight, Pid::BEGIN_HOOK_HEIGHT },
{ Sid::letRingHookHeight, Pid::END_HOOK_HEIGHT },
};
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void LetRingSegment::layout()
{
TextLineBaseSegment::layout();
autoplaceSpannerSegment(spatium() * .7);
}
//---------------------------------------------------------
// LetRing
//---------------------------------------------------------
LetRing::LetRing(Score* s)
: TextLineBase(s)
{
initElementStyle(&letRingStyle);
resetProperty(Pid::LINE_VISIBLE);
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void LetRing::read(XmlReader& e)
{
if (score()->mscVersion() < 301)
e.addSpanner(e.intAttribute("id", -1), this);
while (e.readNextStartElement()) {
if (!TextLineBase::readProperties(e))
e.unknown();
}
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void LetRing::write(XmlWriter& xml) const
{
if (!xml.canWrite(this))
return;
xml.stag(this);
for (const StyledProperty& spp : *styledProperties()) {
if (!isStyled(spp.pid))
writeProperty(xml, spp.pid);
}
Element::writeProperties(xml);
xml.etag();
}
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
LineSegment* LetRing::createLineSegment()
{
LetRingSegment* lr = new LetRingSegment(this, score());
lr->setTrack(track());
return lr;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant LetRing::propertyDefault(Pid propertyId) const
{
switch (propertyId) {
case Pid::LINE_WIDTH:
return score()->styleV(Sid::letRingLineWidth);
case Pid::ALIGN:
return QVariant::fromValue(Align::LEFT | Align::BASELINE);
case Pid::LINE_STYLE:
return score()->styleV(Sid::letRingLineStyle);
case Pid::LINE_VISIBLE:
return true;
case Pid::BEGIN_TEXT_OFFSET:
return score()->styleV(Sid::letRingBeginTextOffset).toPointF();
case Pid::BEGIN_TEXT_ALIGN:
case Pid::CONTINUE_TEXT_ALIGN:
case Pid::END_TEXT_ALIGN:
return score()->styleV(Sid::letRingTextAlign);
case Pid::BEGIN_HOOK_HEIGHT:
case Pid::END_HOOK_HEIGHT:
return score()->styleV(Sid::letRingHookHeight);
case Pid::BEGIN_FONT_STYLE:
return score()->styleV(Sid::letRingFontStyle);
case Pid::BEGIN_TEXT:
return score()->styleV(Sid::letRingText);
case Pid::END_HOOK_TYPE:
return int(HookType::HOOK_90T);
default:
return TextLineBase::propertyDefault(propertyId);
}
}
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
Sid LetRing::getPropertyStyle(Pid id) const
{
switch (id) {
case Pid::PLACEMENT:
return Sid::letRingPlacement;
case Pid::BEGIN_FONT_FACE:
return Sid::letRingFontFace;
case Pid::BEGIN_FONT_SIZE:
case Pid::CONTINUE_FONT_SIZE:
case Pid::END_FONT_SIZE:
return Sid::letRingFontSize;
case Pid::BEGIN_FONT_STYLE:
case Pid::CONTINUE_FONT_STYLE:
case Pid::END_FONT_STYLE:
return Sid::letRingFontStyle;
case Pid::BEGIN_TEXT_ALIGN:
case Pid::CONTINUE_TEXT_ALIGN:
case Pid::END_TEXT_ALIGN:
return Sid::letRingTextAlign;
case Pid::BEGIN_HOOK_HEIGHT:
case Pid::END_HOOK_HEIGHT:
return Sid::letRingHookHeight;
case Pid::BEGIN_TEXT:
return Sid::letRingText;
default:
break;
}
return TextLineBase::getPropertyStyle(id);
}
//---------------------------------------------------------
// linePos
// return System() coordinates
//---------------------------------------------------------
QPointF LetRing::linePos(Grip grip, System** sys) const
{
qreal x = 0.0;
qreal nhw = score()->noteHeadWidth();
System* s = nullptr;
if (grip == Grip::START) {
ChordRest* c = toChordRest(startElement());
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();
}
else {
Element* e = endElement();
ChordRest* c = toChordRest(endElement());
if (!e || e == startElement() || (endHookType() == HookType::HOOK_90)) {
// 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();
if (seg) {
seg = seg->next();
for ( ; seg; seg = seg->next()) {
if (seg->segmentType() == SegmentType::ChordRest) {
// 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;
}
}
}
if (seg) {
s = seg->system();
x = seg->pos().x() + seg->measure()->pos().x() - nhw * 2;
}
}
else if (c) {
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();
}
if (!s) {
Fraction t = tick2();
Measure* m = score()->tick2measure(t);
s = m->system();
x = m->tick2pos(t);
}
x += nhw;
}
*sys = s;
return QPointF(x, 0);
}
}