MuseScore/src/engraving/libmscore/lyrics.h

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

168 lines
5.4 KiB
C
Raw Normal View History

/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2012-05-26 14:26:10 +02:00
#ifndef __LYRICS_H__
#define __LYRICS_H__
#include "line.h"
2012-05-26 14:26:10 +02:00
#include "text.h"
namespace Ms {
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Lyrics
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class LyricsLine;
2017-12-27 11:51:00 +01:00
class Lyrics final : public TextBase
{
Q_GADGET
2012-05-26 14:26:10 +02:00
public:
2019-03-21 17:37:06 +01:00
enum class Syllabic : char {
///.\{
SINGLE, BEGIN, END, MIDDLE
///\}
};
2021-07-01 18:44:52 +02:00
Q_ENUM(Syllabic)
2020-05-26 15:54:26 +02:00
// MELISMA FIRST UNDERSCORE:
// used as_ticks value to mark a melisma for which only the first chord has been spanned so far
// and to give the user a visible feedback that the undercore has been actually entered;
2015-01-23 23:50:49 +01:00
// it should be cleared to 0 at some point, so that it will not be carried over
// if the melisma is not extended beyond a single chord, but no suitable place to do this
// has been identified yet.
2018-08-02 13:27:08 +02:00
static constexpr int TEMP_MELISMA_TICKS = 1;
2020-05-26 15:54:26 +02:00
2018-08-02 13:27:08 +02:00
// WORD_MIN_DISTANCE has never been implemented
// static constexpr qreal LYRICS_WORD_MIN_DISTANCE = 0.33; // min. distance between lyrics from different words
2020-05-26 15:54:26 +02:00
2012-05-26 14:26:10 +02:00
private:
Fraction _ticks; ///< if > 0 then draw an underline to tick() + _ticks
2012-05-26 14:26:10 +02:00
///< (melisma)
Syllabic _syllabic;
LyricsLine* _separator;
2020-05-26 15:54:26 +02:00
friend class mu::engraving::Factory;
Lyrics(ChordRest* parent);
Lyrics(const Lyrics&);
2018-06-29 13:33:47 +02:00
bool isMelisma() const;
2020-03-24 14:49:16 +01:00
void undoChangeProperty(Pid id, const QVariant&, PropertyFlags ps) override;
2020-05-26 15:54:26 +02:00
2012-05-26 14:26:10 +02:00
protected:
int _no; ///< row index
2018-07-02 10:24:58 +02:00
bool _even;
2020-05-26 15:54:26 +02:00
2012-05-26 14:26:10 +02:00
public:
~Lyrics();
2020-05-26 15:54:26 +02:00
2020-03-24 14:49:16 +01:00
Lyrics* clone() const override { return new Lyrics(*this); }
bool acceptDrop(EditData&) const override;
2021-09-02 15:26:45 +02:00
EngravingItem* drop(EditData&) override;
2020-05-26 15:54:26 +02:00
Segment* segment() const { return toSegment(parent()->parent()); }
Measure* measure() const { return toMeasure(parent()->parent()->parent()); }
ChordRest* chordRest() const { return toChordRest(parent()); }
2020-05-26 15:54:26 +02:00
2020-03-24 14:49:16 +01:00
void layout() override;
2018-07-19 13:03:25 +02:00
void layout2(int);
2020-05-26 15:54:26 +02:00
2020-03-24 14:49:16 +01:00
void write(XmlWriter& xml) const override;
void read(XmlReader&) override;
bool readProperties(XmlReader&) override;
int subtype() const override { return _no; }
QString subtypeName() const override { return QObject::tr("Verse %1").arg(_no + 1); }
2018-06-29 13:33:47 +02:00
void setNo(int n) { _no = n; }
int no() const { return _no; }
2017-07-10 11:45:50 +02:00
bool isEven() const { return _no % 1; }
void setSyllabic(Syllabic s) { _syllabic = s; }
Syllabic syllabic() const { return _syllabic; }
2021-09-02 15:26:45 +02:00
void add(EngravingItem*) override;
void remove(EngravingItem*) override;
bool edit(EditData&) override;
2020-03-24 14:49:16 +01:00
void endEdit(EditData&) override;
2020-05-26 15:54:26 +02:00
Fraction ticks() const { return _ticks; }
void setTicks(const Fraction& tick) { _ticks = tick; }
Fraction endTick() const;
void removeFromScore();
2020-05-26 15:54:26 +02:00
using EngravingObject::undoChangeProperty;
void paste(EditData& ed, const QString& txt) override;
2020-05-26 15:54:26 +02:00
2020-03-24 14:49:16 +01:00
QVariant getProperty(Pid propertyId) const override;
bool setProperty(Pid propertyId, const QVariant&) override;
QVariant propertyDefault(Pid id) const override;
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
// LyricsLine
2019-03-21 17:37:06 +01:00
/// \cond PLUGIN_API \private \endcond
//---------------------------------------------------------
class LyricsLine final : public SLine
{
protected:
Lyrics* _nextLyrics;
2020-05-26 15:54:26 +02:00
public:
2021-09-02 15:26:45 +02:00
LyricsLine(EngravingItem* parent);
LyricsLine(const LyricsLine&);
2020-05-26 15:54:26 +02:00
2020-03-24 14:49:16 +01:00
LyricsLine* clone() const override { return new LyricsLine(*this); }
void layout() override;
2021-09-16 15:36:40 +02:00
LineSegment* createLineSegment(System* parent) override;
2020-03-24 14:49:16 +01:00
void removeUnmanaged() override;
void styleChanged() override;
2020-05-26 15:54:26 +02:00
Lyrics* lyrics() const { return toLyrics(parent()); }
Lyrics* nextLyrics() const { return _nextLyrics; }
bool isEndMelisma() const { return lyrics()->ticks().isNotZero(); }
bool isDash() const { return !isEndMelisma(); }
2020-03-24 14:49:16 +01:00
bool setProperty(Pid propertyId, const QVariant& v) override;
SpannerSegment* layoutSystem(System*) override;
};
//---------------------------------------------------------
// LyricsLineSegment
2019-03-21 17:37:06 +01:00
/// \cond PLUGIN_API \private \endcond
//---------------------------------------------------------
class LyricsLineSegment final : public LineSegment
{
protected:
int _numOfDashes = 0;
qreal _dashLength = 0;
2020-05-26 15:54:26 +02:00
2017-11-27 16:55:52 +01:00
public:
2021-09-16 15:36:40 +02:00
LyricsLineSegment(LyricsLine*, System* parent);
2020-05-26 15:54:26 +02:00
2020-03-24 14:49:16 +01:00
LyricsLineSegment* clone() const override { return new LyricsLineSegment(*this); }
void draw(mu::draw::Painter*) const override;
2020-03-24 14:49:16 +01:00
void layout() override;
// helper functions
LyricsLine* lyricsLine() const { return toLyricsLine(spanner()); }
Lyrics* lyrics() const { return lyricsLine()->lyrics(); }
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif