MuseScore/libmscore/lyrics.h

159 lines
6 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
//=============================================================================
#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
///\}
};
Q_ENUM(Syllabic);
2018-08-02 13:27:08 +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;
2012-05-26 14:26:10 +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
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;
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;
2012-05-26 14:26:10 +02:00
protected:
int _no; ///< row index
2018-07-02 10:24:58 +02:00
bool _even;
2012-05-26 14:26:10 +02:00
public:
2012-11-26 15:54:08 +01:00
Lyrics(Score* = 0);
2012-05-26 14:26:10 +02:00
Lyrics(const Lyrics&);
~Lyrics();
2020-03-24 14:49:16 +01:00
Lyrics* clone() const override { return new Lyrics(*this); }
ElementType type() const override { return ElementType::LYRICS; }
void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
bool acceptDrop(EditData&) const override;
Element* drop(EditData&) override;
2014-02-19 12:18:44 +01:00
Segment* segment() const { return toSegment(parent()->parent()); }
Measure* measure() const { return toMeasure(parent()->parent()->parent()); }
ChordRest* chordRest() const { return toChordRest(parent()); }
2012-05-26 14:26:10 +02:00
2020-03-24 14:49:16 +01:00
void layout() override;
2018-07-19 13:03:25 +02:00
void layout2(int);
2012-05-26 14:26:10 +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; }
2020-03-24 14:49:16 +01:00
void add(Element*) override;
void remove(Element*) override;
void endEdit(EditData&) override;
2012-05-26 14:26:10 +02:00
Fraction ticks() const { return _ticks; }
void setTicks(const Fraction& tick) { _ticks = tick; }
Fraction endTick() const;
void removeFromScore();
2018-07-19 13:03:25 +02:00
using ScoreElement::undoChangeProperty;
2020-03-24 14:49:16 +01:00
void paste(EditData&) override;
2014-08-13 21:01:21 +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;
Sid getPropertyStyle(Pid) 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;
public:
LyricsLine(Score*);
LyricsLine(const LyricsLine&);
2020-03-24 14:49:16 +01:00
LyricsLine* clone() const override { return new LyricsLine(*this); }
ElementType type() const override { return ElementType::LYRICSLINE; }
void layout() override;
LineSegment* createLineSegment() override;
void removeUnmanaged() override;
void styleChanged() override;
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;
2017-11-27 16:55:52 +01:00
public:
LyricsLineSegment(Spanner*, Score*);
2020-03-24 14:49:16 +01:00
LyricsLineSegment* clone() const override { return new LyricsLineSegment(*this); }
ElementType type() const override { return ElementType::LYRICSLINE_SEGMENT; }
void draw(QPainter*) const override;
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