MUSX Document Model
Loading...
Searching...
No Matches
musx::dom::KeySignature Class Reference

Shared key signature class that is contained in other classes. (See others::Measure) More...

#include <CommonClasses.h>

+ Inheritance diagram for musx::dom::KeySignature:

Public Member Functions

Cmper getKeyMode () const
 Returns the key mode.
 
int getAlteration () const
 For linear keys, returns the number of sharps or flats from -7..7.
 
bool isLinear () const
 whether this is a linear key
 
bool isNonLinear () const
 whether this is a non-linear key
 
bool isBuiltIn () const
 whether this is a built-in key
 
bool isMajor () const
 whether this is a built-in major key
 
bool isMinor () const
 whether this is a built-in minor key
 
bool isSame (const KeySignature &src)
 returns whether the two key signatures represent the same key signature. Does not take into account transposition.
 
void setTransposition (int interval, int keyAdjustment, bool simplify)
 Transposes the key by the specified amounts. Set them to zero to remove transposition.
 
int calcTonalCenterIndex () const
 Calculates the tonal center index for the key, where C=0, D=1, E=2, ...
 
int getOctaveDisplacement () const
 The octave displacement if this key is a transposed key.
 
int calcAlterationOnNote (unsigned noteIndex) const
 Calculates the amount of alteration on a note int the key.
 
int calcEDODivisions () const
 Calculates the number of EDO division for the key. (The standard value is 12.)
 
std::optional< std::vector< int > > calcKeyMap () const
 Calculates the key's diatonic key map.
 
std::unique_ptr< music_theory::TransposercreateTransposer (int displacement, int alteration) const
 Creates a transposer for this KeySignature instance.
 
void integrityCheck () override
 Allows a class to determine if it has been properly contructed by the factory and fix issues that it can, such as creating default instances of contained classes.
 
 CommonClassBase (const DocumentWeakPtr &document)
 Constructs a CommonClassBase object.
 
- Public Member Functions inherited from musx::dom::CommonClassBase
 CommonClassBase (const DocumentWeakPtr &document)
 Constructs a CommonClassBase object.
 
- Public Member Functions inherited from musx::dom::Base
virtual ~Base () noexcept(false)=default
 Virtual destructor for polymorphic behavior.
 
DocumentPtr getDocument () const
 Gets a reference to the Document.
 
Cmper getPartId () const
 Gets the partId for this instance (or 0 for score)
 
std::shared_ptr< others::PartDefinitiongetPartDefinition () const
 Gets the others::PartDefinition corresponding to getPartId.
 
ShareMode getShareMode () const
 Gets the sharing mode for this instance.
 
const SharedNodesgetUnlinkedNodes () const
 Gets the unlinked nodes for this instance. (Only populated for ShareMode::Partial)
 
void addUnlinkedNode (const std::string &nodeName)
 Adds a shared node for this instance.
 
virtual bool requireAllFields () const
 Specifies if the parser should alert (print or throw) when an unknown xml tag is found for this class.
 

Static Public Member Functions

static const xml::XmlElementArray< KeySignature > & xmlMappingArray ()
 Required for musx::factory::FieldPopulator.
 

Public Attributes

uint16_t key {}
 16-bit value intepreted as follows:
 
bool keyless {}
 Indicates the absence of a key signature.
 
bool hideKeySigShowAccis {}
 Instead of a key signature, show accidentals for the key on the notes where they occur.
 

Additional Inherited Members

- Public Types inherited from musx::dom::Base
enum class  ShareMode { All , Partial , None }
 Describes how this instance is shared between part and score. More...
 
using SharedNodes = std::set< std::string >
 The container type for shared nodes.
 
- Protected Member Functions inherited from musx::dom::CommonClassBase
std::shared_ptr< others::PartDefinitiongetPartDefinition () const
 Gets the others::PartDefinition corresponding to getPartId.
 
Cmper getPartId () const
 Gets the partId for this instance (or 0 for score)
 
ShareMode getShareMode () const
 Gets the sharing mode for this instance.
 
const SharedNodesgetUnlinkedNodes () const
 Gets the unlinked nodes for this instance. (Only populated for ShareMode::Partial)
 
- Protected Member Functions inherited from musx::dom::Base
 Base (const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode)
 Constructs the base class and enforces the static constexpr XmlNodeName.
 
Baseoperator= (const Base &)
 assignment constructor: m_unlinkedNodes is intentionally omitted
 

Detailed Description

Shared key signature class that is contained in other classes. (See others::Measure)

Member Function Documentation

◆ calcAlterationOnNote()

int musx::dom::KeySignature::calcAlterationOnNote ( unsigned  noteIndex) const

Calculates the amount of alteration on a note int the key.

Parameters
noteIndexnote index, where C=0, D=1, E=3, F=3, G=4, A=5, B=6

◆ calcTonalCenterIndex()

int musx::dom::KeySignature::calcTonalCenterIndex ( ) const

Calculates the tonal center index for the key, where C=0, D=1, E=2, ...

This is the modal tonal center, so a minor key with no sharps or flats returns 5 (=A).

◆ CommonClassBase()

musx::dom::CommonClassBase::CommonClassBase ( const DocumentWeakPtr document)
inline

Constructs a CommonClassBase object.

Parameters
documentA weak pointer to the parent document.

◆ createTransposer()

std::unique_ptr< music_theory::Transposer > musx::dom::KeySignature::createTransposer ( int  displacement,
int  alteration 
) const

Creates a transposer for this KeySignature instance.

Parameters
displacementDisplacement value (e.g., from Note)
alterationAlteration value (e.g., from Note)
Returns
A unique pointer to a transposer for this key.

◆ getAlteration()

int musx::dom::KeySignature::getAlteration ( ) const
inline

For linear keys, returns the number of sharps or flats from -7..7.

Returns
Number of sharps/flats for linear keys or 0 for non-linear or invalid keys

◆ getKeyMode()

Cmper musx::dom::KeySignature::getKeyMode ( ) const
inline

Returns the key mode.

For linear keys, this is a value from 0..127 where 0 is reserved for built-in major keys and 1 is reserved for built-in minor keys. Values from 2..127 are user-defined linear modes and are a Cmper value for finding the custom key signature information related to the key. User-defined linear keys might, for example, represent diatonic jazz modes or church modes. They can also be used to define microtonal scales with key signatures.

For non-linear keys, this is a value from 0x4000..0x4fff. This is a Cmper that is used to find all the custom key signature information that defines the key. These are sometimes used to define modes like Klezmer Freyish mode, or other modes whose accidentals do not follow the circle of fifths. They can also be used to define microtonal scales without key signatures.

Values from 0x8000 and higher are invalid.

◆ getOctaveDisplacement()

int musx::dom::KeySignature::getOctaveDisplacement ( ) const
inline

The octave displacement if this key is a transposed key.

Returns
0 for non-transposing keys or the octave displacement for transposed keys.

◆ integrityCheck()

void musx::dom::KeySignature::integrityCheck ( )
inlineoverridevirtual

Allows a class to determine if it has been properly contructed by the factory and fix issues that it can, such as creating default instances of contained classes.

The default implementation should always be called inside an overridden implementation.

Exceptions
musx::dom::integrity_errorif there is a problem.

Reimplemented from musx::dom::Base.

◆ setTransposition()

void musx::dom::KeySignature::setTransposition ( int  interval,
int  keyAdjustment,
bool  simplify 
)

Transposes the key by the specified amounts. Set them to zero to remove transposition.

This is used to adjust the key signature for staves that use Key Signature transposition. Staves that use Chromatic transposition do not transpose the key. They transpose the pitches directly.

Finale works pretty well with key signature transposition in microtone scales. However, it does not simplify key signatures usefully. This function simplifies them correctly, provided that the step values for accidentals are set to cycle through sharps and flats by chromatic half-steps rather than the default of 1. See others::AcciAmountSharps and others::AcciAmountFlats.

Parameters
intervalThe interval by which to transpose.
keyAdjustmentThe key adjustment (positive for sharps, negative for flats)
simplifyIf true, enharmonically adjust the key to have 6 or fewer accidentals

Member Data Documentation

◆ key

uint16_t musx::dom::KeySignature::key {}

16-bit value intepreted as follows:

  • Linear Keys : top bit is 0, the next 7 bits define the key mode (see getKeyMode), bottom 8 bits is a signed byte (+/-7) giving the number of sharps or flats.
  • Nonlinear Keys : Always have values from 0x4000-0x4fff. These are Cmper values to the records that define the nonlinear key.