MuseScore/libmscore/clef.h

197 lines
6.4 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 __CLEF_H__
#define __CLEF_H__
/**
\file
2014-05-08 17:59:24 +02:00
Definition of classes Clef
2012-05-26 14:26:10 +02:00
*/
#include "element.h"
#include "mscore.h"
2013-05-13 18:49:17 +02:00
class QPainter;
namespace Ms {
2012-05-26 14:26:10 +02:00
class Xml;
class MuseScoreView;
class Segment;
static const int NO_CLEF = -1000;
2013-09-05 16:37:49 +02:00
//---------------------------------------------------------
// ClefType
//---------------------------------------------------------
enum class ClefType : signed char {
INVALID = -1,
G = 0,
G1,
G2,
G3,
F,
F8,
F15,
F_B,
F_C,
C1,
C2,
C3,
C4,
TAB,
PERC,
C5,
G4,
F_8VA,
F_15MA,
PERC2, // no longer supported, but kept for compat. with old scores; rendered as PERC
2013-09-05 16:37:49 +02:00
TAB2,
MAX
};
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// ClefTypeList
//---------------------------------------------------------
struct ClefTypeList {
2014-05-08 17:59:24 +02:00
ClefType _concertClef = ClefType::G;
ClefType _transposingClef = ClefType::G;
2012-05-26 14:26:10 +02:00
ClefTypeList() {}
ClefTypeList(ClefType a, ClefType b) : _concertClef(a), _transposingClef(b) {}
2014-08-15 11:58:19 +02:00
ClefTypeList(ClefType a) : _concertClef(a), _transposingClef(a) {}
2012-05-26 14:26:10 +02:00
bool operator==(const ClefTypeList& t) const;
bool operator!=(const ClefTypeList& t) const;
};
//---------------------------------------------------------
// ClefInfo
/// Info about a clef.
//---------------------------------------------------------
2013-09-05 16:37:49 +02:00
class ClefInfo {
public:
static const ClefInfo clefTable[];
const char* _tag; ///< comprehensive name for instruments.xml
const char* _sign; ///< Name for musicXml.
int _line; ///< Line for musicXml.
int _octChng; ///< Octave change for musicXml.
int _pitchOffset; ///< Pitch offset for line 0.
char _lines[14];
const char* _name;
StaffGroup _staffGroup;
public:
static const char* tag(ClefType t) { return clefTable[int(t)]._tag; }
static const char* sign(ClefType t) { return clefTable[int(t)]._sign; }
static int line(ClefType t) { return clefTable[int(t)]._line; }
static int octChng(ClefType t) { return clefTable[int(t)]._octChng; }
static int pitchOffset(ClefType t) { return clefTable[int(t)]._pitchOffset; }
static const char* lines(ClefType t) { return clefTable[int(t)]._lines; }
static const char* name(ClefType t) { return clefTable[int(t)]._name; }
static StaffGroup staffGroup(ClefType t) { return clefTable[int(t)]._staffGroup; }
static ClefType tag2type(const QString&);
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ Clef
/// Graphic representation of a clef.
2012-07-27 18:01:15 +02:00
//
// @P showCourtesy bool
// @P small bool set by layout (read only)
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class Clef : public Element {
Q_OBJECT
2012-07-27 18:35:37 +02:00
Q_PROPERTY(bool showCourtesy READ showCourtesy WRITE undoSetShowCourtesy)
2012-07-27 18:01:15 +02:00
Q_PROPERTY(bool small READ small)
2012-05-26 14:26:10 +02:00
QList<Element*> elements;
2012-07-27 18:35:37 +02:00
bool _showCourtesy;
2012-05-26 14:26:10 +02:00
bool _showPreviousClef; // show clef type at position tick-1
// used for first clef on staff immediatly followed
// by a different clef at same tick position
bool _small;
ClefTypeList _clefTypes;
2012-07-27 18:01:15 +02:00
ClefType curClefType; // cached value of clef type (for re-laying out)
2012-05-26 14:26:10 +02:00
int curLines; // cached value of staff nm. of lines ( " )
qreal curLineDist; // cached value of staff line distance ( " )
void layout1(); // lays the element out, using cached values
public:
Clef(Score*);
Clef(const Clef&);
2014-09-06 11:08:37 +02:00
~Clef();
virtual Clef* clone() const { return new Clef(*this); }
virtual Element::Type type() const { return Element::Type::CLEF; }
2012-05-26 14:26:10 +02:00
virtual void setSelected(bool f);
2013-05-28 15:42:02 +02:00
virtual qreal mag() const;
2012-05-26 14:26:10 +02:00
Segment* segment() const { return (Segment*)parent(); }
Measure* measure() const { return (Measure*)parent()->parent(); }
2012-05-26 14:26:10 +02:00
2014-08-13 21:01:21 +02:00
virtual bool acceptDrop(const DropData&) const override;
2012-05-26 14:26:10 +02:00
virtual Element* drop(const DropData&);
virtual void layout();
virtual void draw(QPainter*) const;
2013-01-11 18:10:18 +01:00
virtual void read(XmlReader&);
2012-05-26 14:26:10 +02:00
virtual void write(Xml&) const;
2014-05-08 17:59:24 +02:00
virtual bool isEditable() const { return false; }
2012-05-26 14:26:10 +02:00
virtual void addElement(Element* e, qreal x, qreal y);
virtual Space space() const { return Space(0.0, bbox().x() * 2.0 + width()); }
bool small() const { return _small; }
void setSmall(bool val);
2012-07-27 18:01:15 +02:00
2012-05-26 14:26:10 +02:00
int tick() const;
bool showCourtesy() const { return _showCourtesy; }
2012-07-27 18:35:37 +02:00
void setShowCourtesy(bool v) { _showCourtesy = v; }
void undoSetShowCourtesy(bool v);
2012-05-26 14:26:10 +02:00
static ClefType clefType(const QString& s);
2014-05-08 17:59:24 +02:00
const char* clefTypeName();
2012-05-26 14:26:10 +02:00
ClefType clefType() const;
void setClefType(ClefType i);
void setClefType(const QString& s);
ClefTypeList clefTypeList() const { return _clefTypes; }
ClefType concertClef() const { return _clefTypes._concertClef; }
ClefType transposingClef() const { return _clefTypes._transposingClef; }
void setConcertClef(ClefType val);
void setTransposingClef(ClefType val);
void setClefType(const ClefTypeList& ctl) { _clefTypes = ctl; }
virtual void spatiumChanged(qreal oldValue, qreal newValue);
2012-07-27 18:01:15 +02:00
QVariant getProperty(P_ID propertyId) const;
bool setProperty(P_ID propertyId, const QVariant&);
QVariant propertyDefault(P_ID id) const;
virtual Element* nextElement() override;
virtual Element* prevElement() override;
QString accessibleInfo() override;
2012-05-26 14:26:10 +02:00
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif