Finale PDK Framework  0.54
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 
23 {
24  twobyte _transposealteration;
25  bool _simplifykey;
26  eKey _key;
27 protected:
28 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
29 
34  virtual EXTAG Tag() { return 0; }
35  virtual int DataSizeLoad() { return sizeof(_key); }
36  virtual void* Allocate() { return (void*) &_key; }
37 
42  virtual void CloneMemoryFrom(__FCBaseData* pSource)
43  {
44  _key = ((FCKeySignature*)pSource)->GetID();
45  _transposealteration = ((FCKeySignature*)pSource)->GetTransposeAlteration();
46  _simplifykey = ((FCKeySignature*)pSource)->GetTransposeSimplify();
47  _datablock = &_key;
49  }
50 
51  virtual __FCBaseData* CreateObject() { return new FCKeySignature(); }
52 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
53 
57  virtual bool LoadFirst() { return false; }
58 public:
59 
62  {
63  _key = 0;
64  _transposealteration = 0;
65  _simplifykey = false;
66  }
67 
68  virtual const char* ClassName() { return "FCKeySignature"; }
69  virtual const PDKFRAMEWORK_CLASSID GetClassID() { return FCID_KEYSIGNATURE; }
70 
76  void SetID(eKey newkey) { _key = newkey; }
77 
85  void SetTransposeAlteration(twobyte value)
86  {
87  _transposealteration = value;
88  }
89 
92  void SetTransposeSimplify(bool state)
93  {
94  _simplifykey = state;
95  }
96 
103  void SetMajorKey(int accidentalnumber)
104  {
105  if (accidentalnumber < -7) return;
106  if (accidentalnumber > 7) return;
107  _key = MakeLinearKey( accidentalnumber, KEYMODE_MAJOR);
108  }
109 
116  void SetMinorKey(int accidentalnumber)
117  {
118  if (accidentalnumber < -7) return;
119  if (accidentalnumber > 7) return;
120  _key = MakeLinearKey( accidentalnumber, KEYMODE_MINOR);
121  }
122 
130  eKey GetID() const { return _key; }
131 
141  twobyte GetAlteration() const
142  {
143  if (!IsPredefined()) return 0;
144  return GetKeyAlteration(GetIDWithTransposition());
145  }
146 
153  {
154  /* Don't use other methods here, to avoid recursive calls.
155  * Instead, use the PDK helper functions and macros.
156  */
157  twobyte keyalteration = GetKeyAlteration(_key);
158 
159  /* Chromatic key uses the standard key, so the transposition
160  alteration should NOT be set. */
161  keyalteration += _transposealteration;
162  if (_simplifykey)
163  {
164  if (keyalteration < -7)
165  {
166  keyalteration += 12;
167  }
168  if (keyalteration > 7)
169  {
170  keyalteration -= 12;
171  }
172  }
173 
174 
175  if (IsMinorKey(_key))
176  return MAKE_TWOBYTE( keyalteration, KEYMODE_MINOR );
177  else if (IsMajorKey(_key))
178  return MAKE_TWOBYTE( keyalteration, KEYMODE_MAJOR );
179  else
180  return _key;
181  }
182 
189  twobyte GetTransposeAlteration() const
190  {
191  return _transposealteration;
192  }
193 
196  bool GetTransposeSimplify() const
197  {
198  return _simplifykey;
199  }
200 
204  {
205  return _simplifykey;
206  }
207 
215  int CalcScaleRootIndex();
216 
226  int CalcRootRelationIndex();
227 
238 
245  twobyte CalcSharps();
246 
253  twobyte CalcFlats();
254 
260  bool IsPredefined() const { return IsPredefinedKey( GetIDWithTransposition() ); }
261 
266  bool IsMajor() { return IsMajorKey(GetIDWithTransposition()); }
267 
272  bool IsMinor() { return IsMinorKey(GetIDWithTransposition()); }
273 
278  bool IsIdentical(FCKeySignature* pCompareSig);
279 
290  bool IsSharpNote(int letterindex);
291 
302  bool IsFlatNote(int letterindex);
303 
305  void MakeString(FCString* pString);
306 
307 
308 #ifdef PDK_FRAMEWORK_DEBUG
309  virtual void DebugDump()
310  {
312  DebugOutDigit("Key ID: ", GetID());
313  DebugOutBool("Is major: ", IsMajor());
314  DebugOutBool("Is minor: ", IsMinor());
315  DebugOutDigit("Calculate sharps: ", CalcSharps());
316  DebugOutDigit("Calculate flats: ", CalcFlats());
317  DebugOutDigit("Calculate scale root index: ", CalcScaleRootIndex());
318  DebugOutDigit("Calculate root relation index: ", CalcRootRelationIndex());
319  DebugOutDigit("Calculate root relation absolute index: ", CalcRootRelationAbsoluteIndex());
320  }
321 #endif
322 
323 };
324 
325 #endif /* FF_KEYSIG_H */
326 
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition: ff_base.h:918
void * _datablock
Pointer to the object's data block, the meaning is implementation-specific for each derived subclass...
Definition: ff_base.h:640
bool IsFlatNote(int letterindex)
Returns true if the key is adding a flat to the note.
Definition: finaleframework.cpp:15073
int CalcScaleRootIndex()
Returns the scale's "letter root", as a 0-base index starting from 'A'.
Definition: finaleframework.cpp:14984
bool IsIdentical(FCKeySignature *pCompareSig)
Returns true if the key is identical to the compared key signature.
Definition: finaleframework.cpp:15032
void SetID(eKey newkey)
Sets the key signature ID.
Definition: ff_keysig.h:76
bool IsMajor()
Returns true if the key is a major key signature.
Definition: ff_keysig.h:266
twobyte GetAlteration() const
Returns the alteration for the key. Negative if the key signatures contains flats, positive if the signature contains sharps.
Definition: ff_keysig.h:141
virtual const char * ClassName()
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition: ff_keysig.h:68
void SetTransposeSimplify(bool state)
Sets if a transposed key should be simplified.
Definition: ff_keysig.h:92
int CalcRootRelationIndex()
Returns the scale's root relation to C major in the circle of fifths.
Definition: finaleframework.cpp:15002
PDKFRAMEWORK_CLASSID
Constants for the GetClassID method.
Definition: ff_base.h:60
virtual void CloneMemoryFrom(__FCBaseData *pSource)
Definition: finaleframework.cpp:753
static void DebugOutDigit(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:274
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition: ff_keysig.h:309
bool GetTransposeSimplify() const
Returns true if the transposed key should be simplified.
Definition: ff_keysig.h:196
virtual const PDKFRAMEWORK_CLASSID GetClassID()
Returns the internal class ID for the PDK Framework class. This is implemented mostly because Lua has...
Definition: ff_keysig.h:69
twobyte GetTransposeAlteration() const
Returns the current transposition alteration index.
Definition: ff_keysig.h:189
void MakeString(FCString *pString)
Creates a string representation of the key.
Definition: finaleframework.cpp:15043
virtual void * Allocate()=0
void SetMinorKey(int accidentalnumber)
Sets the key signature to a minor key.
Definition: ff_keysig.h:116
eKey GetID() const
Gets the key signature ID.
Definition: ff_keysig.h:130
twobyte CalcSharps()
Returns the number of sharps in the key signature.
Definition: finaleframework.cpp:14976
bool IsMinor()
Returns true if the key is a minor key signature.
Definition: ff_keysig.h:272
twobyte CalcFlats()
Returns the number of flats in the key signature.
Definition: finaleframework.cpp:14968
int _loadedsize
Loaded size of the data block for a loaded object, in bytes. Since the datablock is implementation-sp...
Definition: ff_base.h:653
bool GetTransposeChromatic() const
Returns true if the transposed key is chromatic.
Definition: ff_keysig.h:203
Base class for all data-related classes (that handles Finale data).
Definition: ff_base.h:628
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:390
virtual __FCBaseData * CreateObject()=0
Creates a new instance of the object.
void SetMajorKey(int accidentalnumber)
Sets the key signature to a major key.
Definition: ff_keysig.h:103
bool IsSharpNote(int letterindex)
Returns true if the key is raising the note.
Definition: finaleframework.cpp:15061
Class that provides storage for text. This is to achieve platform-transparent text handling...
Definition: ff_base.h:1473
FCKeySignature()
The constructor. Sets the default key signature to C major.
Definition: ff_keysig.h:61
virtual EXTAG Tag()=0
The Enigma tag for the derived class.
eKey GetIDWithTransposition() const
Returns the key signature ID with the transposition (and transposition simplification) added...
Definition: ff_keysig.h:152
Class for key signatures. Instances of this class is auto-created by FCMeasure:GetKeySignature and FC...
Definition: ff_keysig.h:22
bool IsPredefined() const
Returns true if the key is a predefined key signature (major or minor).
Definition: ff_keysig.h:260
int CalcRootRelationAbsoluteIndex()
Returns the scale's root relation to C in the circle of fifths, based on the root's note...
Definition: finaleframework.cpp:15014
virtual int DataSizeLoad()=0
Returns the data size for the data structure that should be loaded.
virtual bool LoadFirst()
Finding first key sig recs currently not supported.
Definition: ff_keysig.h:57
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:85