Finale PDK Framework 0.77
Power Up Your 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
79 void SetID(eKey newkey) { _key = newkey; }
80
88 void SetTransposeAlteration(twobyte value)
89 {
90 _transposealteration = value;
91 }
92
97 void SetTransposeSimplify(bool state)
98 {
99 _simplifykey = state;
100 }
101
108 void SetMajorKey(int accidentalnumber)
109 {
110 if (accidentalnumber < -7) return;
111 if (accidentalnumber > 7) return;
112 _key = MakeLinearKey( accidentalnumber, KEYMODE_MAJOR);
113 }
114
121 void SetMinorKey(int accidentalnumber)
122 {
123 if (accidentalnumber < -7) return;
124 if (accidentalnumber > 7) return;
125 _key = MakeLinearKey( accidentalnumber, KEYMODE_MINOR);
126 }
127
134 eKey GetID() const { return _key; }
135
144 twobyte GetAlteration() const
145 {
146 if (!IsLinear()) return 0;
147 return GetKeyAlteration(GetIDWithTransposition());
148 }
149
156 {
157 /* Don't use other methods here, to avoid recursive calls.
158 * Instead, use the PDK helper functions and macros.
159 */
160 twobyte keyalteration = GetKeyAlteration(_key);
161
162 /* Chromatic key uses the standard key, so the transposition
163 alteration should NOT be set. */
164 keyalteration += _transposealteration;
165 if (_simplifykey)
166 {
167 if (keyalteration < -6)
168 {
169 keyalteration += 12;
170 }
171 if (keyalteration > 6)
172 {
173 keyalteration -= 12;
174 }
175 }
176
177 if (IsLinear())
178 return MakeLinearKey( keyalteration, GetLinearKeyMode(_key) );
179 else
180 return _key;
181 }
182
190 {
191 return _transposealteration;
192 }
193
199 {
200 return _simplifykey;
201 }
202
206 {
207 return _simplifykey; //?? RGP 12/11/21 (not Lua-supported)
208 }
209
218 int CalcScaleRootIndex() const;
219
229 int CalcRootRelationIndex() const;
230
241
249 twobyte CalcSharps() const;
250
257 twobyte CalcFlats() const;
258
269 twobyte CalcTotalChromaticSteps() const;
270
283 std::vector<eHarmLev> CalcDiatonicStepsMap() const;
284
289 bool IsPredefined() const { return IsPredefinedKey( GetIDWithTransposition() ); }
290
299 bool IsLinear() const { return IsLinearKey( GetID() ); }
300
305 bool IsMajor() const { return IsMajorKey(GetIDWithTransposition()); }
306
311 bool IsMinor() const { return IsMinorKey(GetIDWithTransposition()); }
312
317 bool IsIdentical(const __FCBase* pCompareObject) const override;
318
329 bool IsSharpNote(int letterindex) const;
330
342 bool IsFlatNote(int letterindex) const;
343
349 void MakeString(FCString* pString) const;
350
363 eHarmLev CalcScaleNumber(eHarmLev displacement) const;
364
365
366#ifdef PDK_FRAMEWORK_DEBUG
367 void DebugDump() override
368 {
370 DebugOutInt("Key ID: ", GetID());
371 DebugOutBool("Is major: ", IsMajor());
372 DebugOutBool("Is minor: ", IsMinor());
373 DebugOutInt("Calculate sharps: ", CalcSharps());
374 DebugOutInt("Calculate flats: ", CalcFlats());
375 DebugOutInt("Calculate scale root index: ", CalcScaleRootIndex());
376 DebugOutInt("Calculate root relation index: ", CalcRootRelationIndex());
377 DebugOutInt("Calculate root relation absolute index: ", CalcRootRelationAbsoluteIndex());
378 }
379#endif
380
381};
382
383#endif /* FF_KEYSIG_H */
384
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:311
bool IsLinear() const
Returns true if the key mode can transpose its key signature. This includes standard major and minor ...
Definition ff_keysig.h:299
eKey GetID() const
Gets the key signature ID.
Definition ff_keysig.h:134
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:108
void SetTransposeSimplify(bool state)
Sets if a transposed key should be simplified.
Definition ff_keysig.h:97
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:289
eKey GetIDWithTransposition() const
Returns the key signature ID with the transposition (and transposition simplification) added.
Definition ff_keysig.h:155
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:189
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:88
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:198
bool IsMajor() const
Returns true if the key is a major key signature, using the predefined major key mode.
Definition ff_keysig.h:305
void SetMinorKey(int accidentalnumber)
Sets the key signature to a minor key.
Definition ff_keysig.h:121
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:79
bool GetTransposeChromatic() const
Returns true if the transposed key is chromatic.
Definition ff_keysig.h:205
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:367
twobyte GetAlteration() const
Returns the alteration for the key. Negative if the key signatures contains flats,...
Definition ff_keysig.h:144
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