Finale PDK Framework 0.78
Lua Power for Finale Music Software
Loading...
Searching...
No Matches
ff_keysig.h
1/*
2 * File: ff_keysig.h
3 * Author: Jari Williamsson
4 *
5 * Created on den 15 november 2010, 00:14
6 */
7
8#ifndef FF_KEYSIG_H
9#define FF_KEYSIG_H
10
11#include <vector>
12
25{
26 friend class FCTransposer;
27
28 twobyte _transposealteration;
29 bool _simplifykey;
30 eKey _key;
31
37 eHarmLev _CalcKeyStepsInNormalizedDiatonicInterval(eHarmLev normalizedInterval) const;
38
43 eHarmLev _CalcKeyStepsBetweenScaleDegrees(eHarmLev first, eHarmLev second) const;
44
49 eHarmAlt _CalcStepsInAlteration(eHarmLev diatonicInterval, eHarmLev alteration) const;
50
51public:
52
54 FCKeySignature(eKey key = KEY_C_MAJOR) : __FCBase()
55 {
56 _key = key;
57 _transposealteration = 0;
58 _simplifykey = false;
59 }
60
61 const char* ClassName() const override { return "FCKeySignature"; }
62 const PDKFRAMEWORK_CLASSID GetClassID() const override { return FCID_KEYSIGNATURE; }
63
68 twobyte GetKeyMode() const
69 {
70 if (IsLinear()) return GetLinearKeyMode(_key);
71 return _key;
72 }
73
81 void SetID(eKey newkey) { _key = newkey; }
82
90 void SetTransposeAlteration(twobyte value)
91 {
92 _transposealteration = value;
93 }
94
99 void SetTransposeSimplify(bool state)
100 {
101 _simplifykey = state;
102 }
103
110 void SetMajorKey(int accidentalnumber)
111 {
112 if (accidentalnumber < -7) return;
113 if (accidentalnumber > 7) return;
114 _key = MakeLinearKey( accidentalnumber, KEYMODE_MAJOR);
115 }
116
123 void SetMinorKey(int accidentalnumber)
124 {
125 if (accidentalnumber < -7) return;
126 if (accidentalnumber > 7) return;
127 _key = MakeLinearKey( accidentalnumber, KEYMODE_MINOR);
128 }
129
136 eKey GetID() const { return _key; }
137
146 twobyte GetAlteration() const
147 {
148 if (!IsLinear()) return 0;
149 return GetKeyAlteration(GetIDWithTransposition());
150 }
151
158 {
159 /* Don't use other methods here, to avoid recursive calls.
160 * Instead, use the PDK helper functions and macros.
161 */
162 twobyte keyalteration = GetKeyAlteration(_key);
163
164 /* Chromatic key uses the standard key, so the transposition
165 alteration should NOT be set. */
166 keyalteration += _transposealteration;
167 if (_simplifykey)
168 {
169 if (keyalteration < -6)
170 {
171 keyalteration += 12;
172 }
173 if (keyalteration > 6)
174 {
175 keyalteration -= 12;
176 }
177 }
178
179 if (IsLinear())
180 return MakeLinearKey( keyalteration, GetLinearKeyMode(_key) );
181 else
182 return _key;
183 }
184
192 {
193 return _transposealteration;
194 }
195
201 {
202 return _simplifykey;
203 }
204
208 {
209 return _simplifykey; //?? RGP 12/11/21 (not Lua-supported)
210 }
211
220 int CalcScaleRootIndex() const;
221
231 int CalcRootRelationIndex() const;
232
243
251 twobyte CalcSharps() const;
252
259 twobyte CalcFlats() const;
260
271 twobyte CalcTotalChromaticSteps() const;
272
285 std::vector<eHarmLev> CalcDiatonicStepsMap() const;
286
291 bool IsPredefined() const { return IsPredefinedKey( GetIDWithTransposition() ); }
292
301 bool IsLinear() const { return IsLinearKey( GetID() ); }
302
307 bool IsMajor() const { return IsMajorKey(GetIDWithTransposition()); }
308
313 bool IsMinor() const { return IsMinorKey(GetIDWithTransposition()); }
314
319 bool IsIdentical(const __FCBase* pCompareObject) const override;
320
331 bool IsSharpNote(int letterindex) const;
332
344 bool IsFlatNote(int letterindex) const;
345
351 void MakeString(FCString* pString) const;
352
365 eHarmLev CalcScaleNumber(eHarmLev displacement) const;
366
367
368#ifdef PDK_FRAMEWORK_DEBUG
369 void DebugDump() override
370 {
372 DebugOutInt("Key ID: ", GetID());
373 DebugOutBool("Is major: ", IsMajor());
374 DebugOutBool("Is minor: ", IsMinor());
375 DebugOutInt("Calculate sharps: ", CalcSharps());
376 DebugOutInt("Calculate flats: ", CalcFlats());
377 DebugOutInt("Calculate scale root index: ", CalcScaleRootIndex());
378 DebugOutInt("Calculate root relation index: ", CalcRootRelationIndex());
379 DebugOutInt("Calculate root relation absolute index: ", CalcRootRelationAbsoluteIndex());
380 }
381#endif
382
383};
384
385#endif /* FF_KEYSIG_H */
386
Base class for the Finale Framework classes.
Definition ff_base.h:71
PDKFRAMEWORK_CLASSID
Constants for the GetClassID method.
Definition ff_base.h:84
static void DebugOutInt(const char *pszPrefixText, int i)
Static method that outputs a line for debugging purposes. The text appears with the extra digit (in d...
Definition finaleframework.cpp:335
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition finaleframework.cpp:609
static void DebugOutBool(const char *pszPrefixText, bool state)
Static method that outputs a line for debugging purposes. The boolean state appears afterwards as eit...
Definition finaleframework.cpp:451
Class for key signatures. Instances of this class are auto-created by FCMeasure:GetKeySignature and F...
Definition ff_keysig.h:25
eHarmLev CalcScaleNumber(eHarmLev displacement) const
Calculate the scale number of the input displacement value.
Definition finaleframework.cpp:16146
const char * ClassName() const override
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition ff_keysig.h:61
FCKeySignature(eKey key=KEY_C_MAJOR)
The constructor. Sets the default key signature to C major is no key is supplied.
Definition ff_keysig.h:54
int CalcScaleRootIndex() const
Returns the scale's "letter root", as a 0-base index starting from 'A'. Only predefined major and min...
Definition finaleframework.cpp:16176
bool IsMinor() const
Returns true if the key is a minor key signature, using the predefined minor key mode.
Definition ff_keysig.h:313
bool IsLinear() const
Returns true if the key mode can transpose its key signature. This includes standard major and minor ...
Definition ff_keysig.h:301
eKey GetID() const
Gets the key signature ID.
Definition ff_keysig.h:136
int CalcRootRelationAbsoluteIndex() const
Returns the scale's root relation to C in the circle of fifths, based on the root's note....
Definition finaleframework.cpp:16207
twobyte CalcSharps() const
Returns the number of sharps in the key signature. Only predefined major and minor keys are supported...
Definition finaleframework.cpp:16051
bool IsFlatNote(int letterindex) const
Returns true if the key is adding a flat to the note. Only predefined major and minor keys are suppor...
Definition finaleframework.cpp:16276
int CalcRootRelationIndex() const
Returns the scale's root relation to C major in the circle of fifths. Only predefined major and minor...
Definition finaleframework.cpp:16194
void SetMajorKey(int accidentalnumber)
Sets the key signature to a major key.
Definition ff_keysig.h:110
void SetTransposeSimplify(bool state)
Sets if a transposed key should be simplified.
Definition ff_keysig.h:99
void MakeString(FCString *pString) const
Creates a string representation of the key. Only predefined major and minor keys are supported.
Definition finaleframework.cpp:16241
twobyte GetKeyMode() const
Returns the key mode that can be used to load the associated FCCustomKeyModeDef.
Definition ff_keysig.h:68
bool IsPredefined() const
Returns true if the key is a predefined key signature (major or minor).
Definition ff_keysig.h:291
eKey GetIDWithTransposition() const
Returns the key signature ID with the transposition (and transposition simplification) added.
Definition ff_keysig.h:157
twobyte CalcFlats() const
Returns the number of flats in the key signature.
Definition finaleframework.cpp:16043
twobyte GetTransposeAlteration() const
Returns the current transposition alteration index.
Definition ff_keysig.h:191
bool IsIdentical(const __FCBase *pCompareObject) const override
Returns true if the key is identical to the compared key signature.
Definition finaleframework.cpp:16226
void SetTransposeAlteration(twobyte value)
Sets the transpose alteration offset, if the key should be calculated based on a transposition of an ...
Definition ff_keysig.h:90
twobyte CalcTotalChromaticSteps() const
Returns the number of chromatic steps in the key mode. For predefined keys this is always 12....
Definition finaleframework.cpp:16059
bool GetTransposeSimplify() const
Returns true if the transposed key should be simplified.
Definition ff_keysig.h:200
bool IsMajor() const
Returns true if the key is a major key signature, using the predefined major key mode.
Definition ff_keysig.h:307
void SetMinorKey(int accidentalnumber)
Sets the key signature to a minor key.
Definition ff_keysig.h:123
std::vector< eHarmLev > CalcDiatonicStepsMap() const
Returns an array (or table in Lua) specifiying the chromatic step where each diatonic step occurs....
Definition finaleframework.cpp:16074
void SetID(eKey newkey)
Sets the key signature ID.
Definition ff_keysig.h:81
bool GetTransposeChromatic() const
Returns true if the transposed key is chromatic.
Definition ff_keysig.h:207
bool IsSharpNote(int letterindex) const
Returns true if the key is raising the note.
Definition finaleframework.cpp:16263
void DebugDump() override
Outputs the class data/information for debugging purposes.
Definition ff_keysig.h:369
twobyte GetAlteration() const
Returns the alteration for the key. Negative if the key signatures contains flats,...
Definition ff_keysig.h:146
const PDKFRAMEWORK_CLASSID GetClassID() const override
Returns the internal class ID for the PDK Framework class. This is implemented mostly because Lua has...
Definition ff_keysig.h:62
Class that provides storage for text. This is to achieve platform-transparent text handling,...
Definition ff_base.h:1877
This is a utility class to facilitate transposition. It supports:
Definition ff_celldetails.h:2766