CFugue
KeySignature.h
Go to the documentation of this file.
1 /*
2  This is part of CFugue, the C++ Runtime for MIDI Score Programming
3  Copyright (C) 2009 Gopalakrishna Palem
4 
5  For links to further information, or to contact the author,
6  see <http://cfugue.sourceforge.net/>.
7 
8  $LastChangedDate: 2013-12-18 10:59:57 +0530 (Wed, 18 Dec 2013) $
9  $Rev: 197 $
10  $LastChangedBy: krishnapg $
11 */
12 
13 #ifndef KEYSIGNATURE_H__56751CC1_46A2_4238_BAF1_7884CDA8089B__
14 #define KEYSIGNATURE_H__56751CC1_46A2_4238_BAF1_7884CDA8089B__
15 
16 /** @file KeySignature.h
17  * \brief Declares KeySignature class used in CFugue MusicString
18  */
19 #include "Talam.h"
20 
21 namespace CFugue
22 {
23  /// <Summary>
24  /// \brief Class representing the Key Signature
25  ///
26  /// Key Signatures are applicable for the whole song, independent of tracks. It
27  /// can be changed during a song, though. Player will automatically adjust
28  /// note values based on the current Key Signature. For example, in a F-Major
29  /// Key Signature, all B notes will be converted to B-Flat automatically, unless
30  /// explicitly indicated as a B natural (i.e., "Bn"). However, note that such
31  /// modifications are applied only to the Notes that are specified in alphabetic
32  /// format. Notes specified using numeric form will not get affected by the
33  /// KeySignature manipulations. They will be played as is.
34  ///
35  /// Key Signatures support both Carnatic and Western Music modes.
36  /// Use the appropriate Macros to distinguish between them.
37  ///
38  /// In Carnatic mode, all the basic 72 Key Signatures, known as the
39  /// Melakartha Janya Ragas, are supported. These are accessible through MELA_x macro,
40  /// where x specifies a number in the range [1, 72]. In addition, MELA_0
41  /// and MELA_DEFAULT are available, that map to Melakartha 29 - the Shankarabharanam scale.
42  ///
43  /// In addition, numerous Ragas are accessible through their names directly,
44  /// such as KALYANI, MOHANA etc. Any missing notes in those ragas will default
45  /// to their 29th scale values (and not to their Parent Janya raga values, <i>be careful</i>).
46  /// In other words, Shankarabharanam is the default scale for all
47  /// default Note values, no matter from which Ragam you are referring.
48  ///
49  /// In Western mode, a total of 15 Key Signatures are present. These are accessible
50  /// through their names, such as CMAJ, DMAJ, F\#MIN etc... Additionally SCALE_DEFAULT
51  /// Macro is available that maps to CMAJ scale.
52  ///
53  /// Western is the default mode, and C-Major is the default KeySignature. All Parsers
54  /// start in Western mode with C-Major scale set to their default. If you rather want
55  /// the Parser to use a different Scale or different Mode, then you should explicitly
56  /// supply a KeySignature token with appropriate macro values before passing on any Notes.
57  ///
58  /// %Note that once a
59  /// KeySignature is encountered in one particular mode (Carnatic or Western),
60  /// then all the subsequent Notes will be interpreted as being in that mode, till
61  /// another KeySignature token is encountered with a different mode.
62  ///
63  /// For example, once the parser encounters a token such as K[MELA_22] then
64  /// it will start interpreting all the subsequent Notes in S R G M P D N
65  /// style, instead of the default western C D E F G A B style.
66  /// So any notes that use the latter style of notation will fail to
67  /// render properly, unless a token with western Key
68  /// Signature, such as K[F\#MAJ] or K[AMIN] etc, is inserted before them.
69  /// Same is the case the other way round. Once a KeySignature token with
70  /// Western mode is encountered, all the subsequent Notes will be parsed
71  /// using the Western C D E F G A B notation, and any notes that are inscribed
72  /// using the S R G M P D N notation will fail to render properly, unless an appropriate
73  /// Carnatic KeySignature such as K[MELA_65] or K[KALYANI] etc.. is used to
74  /// appropriately direct the Parser about the notation switch to Carnatic Mode.
75  ///
76  /// Use K[MELA_DEFAULT] for Carnatic Mode and K[SCALE_DEFAULT] for Western Mode if you
77  /// are not sure which value to specify for the KeySignature.
78  /// </Summary>
80  {
81  public:
82  enum Scale { MAJOR_SCALE = 0, MINOR_SCALE = 1 }; ///< Scale Identifiers [Western Mode]
83  enum Mode { WESTERN =0, CARNATIC = 1 }; ///< Music Mode Identifiers
84  enum Defaults { DEFAULT_KEY = 0, DEFAULT_RAGAM = 29 }; ///< Default Values
85 
86  protected:
87  signed short m_nKeySig; // Values are in the range [-7, 7] for Western, and in the range [1, 72] for Carnatic
88  Scale m_bScale; // Indicates Major scale or Minor scale for Western Mode
89  Mode m_bMode; // Indicates Carnatic Mode or Western Mode
90  Talam m_nTalam; // Indicates Talam [Carnatic Mode]
91  unsigned short m_nSpeed; // Indicates Speed [Carnatic Mode]
92 
93  public:
94  /// Default constructor
95  inline KeySignature()
96  : m_nKeySig(DEFAULT_KEY), m_bScale(MAJOR_SCALE), m_bMode(WESTERN), m_nSpeed(1)
97  { }
98 
99  /// Western Mode constructor
100  inline KeySignature(const signed short nKeySig, const Scale bScale)
101  : m_nKeySig(nKeySig), m_bScale(bScale), m_bMode(WESTERN), m_nSpeed(1)
102  { }
103 
104  /// Carnatic Mode constructor
105  inline KeySignature(const unsigned short nRagam, const unsigned short nTalam)
106  : m_nKeySig(nRagam), m_bScale(MAJOR_SCALE), m_bMode(CARNATIC), m_nTalam(nTalam), m_nSpeed(1)
107  {
108  }
109 
110  /// \brief Returns the Key Signature value.
111  /// Based on the Mode, Value will be in the range [-7, 7] or [1, 72].
112  /// Use GetMode() to find the Mode.
113  inline signed char GetKey() const { return (signed char) m_nKeySig; }
114 
115  /// Returns if the Key Signature refers to a Major (0) scale or Minor(1) scale.
116  /// Valid only if the Mode is set to KeySignature::WESTERN. Use GetMode()
117  /// to verify the Mode.
118  inline unsigned char GetMajMin() const { return m_bScale; }
119 
120  /// Returns if the KeySignature refers to Carnatic Mode or Western Mode
121  inline Mode GetMode() const { return m_bMode; }
122 
123  /// \brief Returns the Talam Value.
124  /// Valid only when the Mode is CARNATIC. Use GetMode() to find the Mode;
125  inline const Talam& GetTalam() const { return m_nTalam; }
126 
127  /// Sets the Key Signature value for Western Scales
128  /// @param nKeySig Key Signature value in the range [-7, 7]
129  inline void SetKey(const signed short nKeySig) { m_nKeySig = nKeySig; m_bMode = WESTERN; }
130 
131  /// Sets if the Key Signature refers to a Major (0) scale or Minor(1) scale
132  /// @param bScale Value indicating if the scale is Major (0) or Minor (1)
133  inline void SetMajMin(const Scale bScale) { m_bScale = bScale; }
134 
135  /// Sets the Key Signature value for Carnatic Ragams
136  /// @param nRagam Melakartha Janya Ragam number in the range [1, 72]
137  inline void SetRagam(const unsigned short nRagam) { m_nKeySig = nRagam; m_bMode = CARNATIC; }
138 
139  /// Sets the Talam to the specified value
140  /// @param talam The Talam value to be used from now on
141  inline void SetTalam(const Talam& talam) { m_nTalam = talam; }
142 
143  /// \brief Returns the current Song speed.
144  /// Valid only for Carnatic Mode. Use GetMode() to verify the Mode.
145  inline unsigned short& Speed() { return m_nSpeed; }
146 
147  /// Populates Western Music Scale values
148  inline static void PopulateWesternDefinitions(DICTIONARY& stdDefns)
149  {
150  // In Western Music,
151  // Key signature values span from -7 to 7. But our dictionary does not
152  // allow negative values. So we make the values to be from 0 to 14. We
153  // move the negative values to the 8 to 14 range. So to get back the
154  // correct value, we have to check if the dictionary value is > 7 and
155  // substract the number from 7 if so. That will map the 8 to 14 range
156  // values, back to -1 to -7 range correctly.
157 
158  // Also, Major and Minor scale usually share same Keysignature value.
159  // To distinguish, we add 64 to the Major Keysignature values. This
160  // will set the 7th high bit in the byte to 1. To get the correct value,
161  // boolean-and the value with 0x40; That is, scale == maj if value >= 64;
162 
163  // See MusicStringParser::ParseKeySignatureToken to see how
164  // these values are interpreted correctly.
165 
166  stdDefns[_T("CBMAJ")] = _T("78");
167  stdDefns[_T("ABMIN")] = _T("14");
168 
169  stdDefns[_T("GBMAJ")] = _T("77");
170  stdDefns[_T("EBMIN")] = _T("13");
171 
172  stdDefns[_T("DBMAJ")] = _T("76");
173  stdDefns[_T("BBMIN")] = _T("12");
174 
175  stdDefns[_T("ABMAJ")] = _T("75");
176  stdDefns[_T("FMIN" )] = _T("11");
177 
178  stdDefns[_T("EBMAJ")] = _T("74");
179  stdDefns[_T("CMIN" )] = _T("10");
180 
181  stdDefns[_T("BBMAJ")] = _T("73");
182  stdDefns[_T("GMIN" )] = _T("9");
183 
184  stdDefns[_T("FMAJ") ] = _T("72");
185  stdDefns[_T("DMIN" )] = _T("8");
186 
187  stdDefns[_T("CMAJ") ] = _T("64");
188  stdDefns[_T("AMIN") ] = _T("0");
189 
190  stdDefns[_T("GMAJ")] = _T("65");
191  stdDefns[_T("EMIN")] = _T("1");
192 
193  stdDefns[_T("DMAJ")] = _T("66");
194  stdDefns[_T("BMIN")] = _T("2");
195 
196  stdDefns[_T("AMAJ") ] = _T("67");
197  stdDefns[_T("F#MIN")] = _T("3");
198 
199  stdDefns[_T("EMAJ") ] = _T("68");
200  stdDefns[_T("C#MIN")] = _T("4");
201 
202  stdDefns[_T("BMAJ") ] = _T("69");
203  stdDefns[_T("G#MIN")] = _T("5");
204 
205  stdDefns[_T("F#MAJ")] = _T("70");
206  stdDefns[_T("D#MIN")] = _T("6");
207 
208  stdDefns[_T("C#MAJ")] = _T("71");
209  stdDefns[_T("A#MIN")] = _T("7");
210 
211  stdDefns[_T("SCALE")] = _T("64"); // Same as C-Major
212  stdDefns[_T("SCALE_DEF")] = _T("64"); // Same as C-Major
213  stdDefns[_T("SCALE_DEFAULT")] = _T("64"); // Same as C-Major
214  }
215 
216  /// Populates Carnatic Ragas and Mela values
217  inline static void PopulateCarnaticDefinitions(DICTIONARY& stdDefns)
218  {
219  // In Carnatic Music,
220  // a total of 72 Key Signatures, known as Melakartha Janya Ragas, are
221  // present. These values are added to the dictionary with MELA_X key name,
222  // where x specifies a number in the range [1, 72]. However, to distinguish
223  // these values from the Western Key Signature values, we set the
224  // 8th high bit in the byte to be 1, so all the values for the Carnatic
225  // music will be in the range [129, 200]. We also support MELA_0
226  // and MELA_DEFAULT macros that maps to Melakartha 29 - Shankarabharanam scale.
227 
228  // See MusicStringParser::ParseKeySignatureToken to see how
229  // these values are interpreted correctly.
230 
231  stdDefns[_T("MELA_1")] = _T("129");
232  stdDefns[_T("MELA_2")] = _T("130");
233  stdDefns[_T("MELA_3")] = _T("131");
234  stdDefns[_T("MELA_4")] = _T("132");
235  stdDefns[_T("MELA_5")] = _T("133");
236  stdDefns[_T("MELA_6")] = _T("134");
237  stdDefns[_T("MELA_7")] = _T("135");
238  stdDefns[_T("MELA_8")] = _T("136");
239  stdDefns[_T("MELA_9")] = _T("137");
240  stdDefns[_T("MELA_10")] = _T("138");
241  stdDefns[_T("MELA_11")] = _T("139");
242  stdDefns[_T("MELA_12")] = _T("140");
243  stdDefns[_T("MELA_13")] = _T("141");
244  stdDefns[_T("MELA_14")] = _T("142");
245  stdDefns[_T("MELA_15")] = _T("143");
246  stdDefns[_T("MELA_16")] = _T("144");
247  stdDefns[_T("MELA_17")] = _T("145");
248  stdDefns[_T("MELA_18")] = _T("146");
249  stdDefns[_T("MELA_19")] = _T("147");
250  stdDefns[_T("MELA_20")] = _T("148");
251  stdDefns[_T("MELA_21")] = _T("149");
252  stdDefns[_T("MELA_22")] = _T("150");
253  stdDefns[_T("MELA_23")] = _T("151");
254  stdDefns[_T("MELA_24")] = _T("152");
255  stdDefns[_T("MELA_25")] = _T("153");
256  stdDefns[_T("MELA_26")] = _T("154");
257  stdDefns[_T("MELA_27")] = _T("155");
258  stdDefns[_T("MELA_28")] = _T("156");
259  stdDefns[_T("MELA_29")] = _T("157");
260  stdDefns[_T("MELA_30")] = _T("158");
261  stdDefns[_T("MELA_31")] = _T("159");
262  stdDefns[_T("MELA_32")] = _T("160");
263  stdDefns[_T("MELA_33")] = _T("161");
264  stdDefns[_T("MELA_34")] = _T("162");
265  stdDefns[_T("MELA_35")] = _T("163");
266  stdDefns[_T("MELA_36")] = _T("164");
267  stdDefns[_T("MELA_37")] = _T("165");
268  stdDefns[_T("MELA_38")] = _T("166");
269  stdDefns[_T("MELA_39")] = _T("167");
270  stdDefns[_T("MELA_40")] = _T("168");
271  stdDefns[_T("MELA_41")] = _T("169");
272  stdDefns[_T("MELA_42")] = _T("170");
273  stdDefns[_T("MELA_43")] = _T("171");
274  stdDefns[_T("MELA_44")] = _T("172");
275  stdDefns[_T("MELA_45")] = _T("173");
276  stdDefns[_T("MELA_46")] = _T("174");
277  stdDefns[_T("MELA_47")] = _T("175");
278  stdDefns[_T("MELA_48")] = _T("176");
279  stdDefns[_T("MELA_49")] = _T("177");
280  stdDefns[_T("MELA_50")] = _T("178");
281  stdDefns[_T("MELA_51")] = _T("179");
282  stdDefns[_T("MELA_52")] = _T("180");
283  stdDefns[_T("MELA_53")] = _T("181");
284  stdDefns[_T("MELA_54")] = _T("182");
285  stdDefns[_T("MELA_55")] = _T("183");
286  stdDefns[_T("MELA_56")] = _T("184");
287  stdDefns[_T("MELA_57")] = _T("185");
288  stdDefns[_T("MELA_58")] = _T("186");
289  stdDefns[_T("MELA_59")] = _T("187");
290  stdDefns[_T("MELA_60")] = _T("188");
291  stdDefns[_T("MELA_61")] = _T("189");
292  stdDefns[_T("MELA_62")] = _T("190");
293  stdDefns[_T("MELA_63")] = _T("191");
294  stdDefns[_T("MELA_64")] = _T("192");
295  stdDefns[_T("MELA_65")] = _T("193");
296  stdDefns[_T("MELA_66")] = _T("194");
297  stdDefns[_T("MELA_67")] = _T("195");
298  stdDefns[_T("MELA_68")] = _T("196");
299  stdDefns[_T("MELA_69")] = _T("197");
300  stdDefns[_T("MELA_70")] = _T("198");
301  stdDefns[_T("MELA_71")] = _T("199");
302  stdDefns[_T("MELA_72")] = _T("200");
303 
304  stdDefns[_T("MELA_0")] = _T("157"); // Defaults to 29th Mela
305  stdDefns[_T("MELA_DEFAULT")] = _T("157");
306  stdDefns[_T("MELA")] = _T("157");
307 
308  // Carnatic name mappings to the Melakartha Janya Ragas
309  stdDefns[_T("KANAKANGI")] = stdDefns[_T("MELA_1")];
310  stdDefns[_T("RATNANGI")] = stdDefns[_T("MELA_2")];
311  stdDefns[_T("GANAMURTHI")] = stdDefns[_T("MELA_3")];
312  stdDefns[_T("VANASPATHI")] = stdDefns[_T("MELA_4")];
313  stdDefns[_T("MANAVATHI")] = stdDefns[_T("MELA_5")];
314  stdDefns[_T("TANARUPI")] = stdDefns[_T("MELA_6")];
315 
316  stdDefns[_T("SENAVATHI")] = stdDefns[_T("MELA_7")];
317  stdDefns[_T("HANUMATHODI")] = stdDefns[_T("MELA_8")];
318  stdDefns[_T("DHENUKA")] = stdDefns[_T("MELA_9")];
319  stdDefns[_T("NATAKAPRIYA")] = stdDefns[_T("MELA_10")];
320  stdDefns[_T("KOKILAPRIYA")] = stdDefns[_T("MELA_11")];
321  stdDefns[_T("RUPAVATHI")] = stdDefns[_T("MELA_12")];
322 
323  stdDefns[_T("GAYAKAPRIYA")] = stdDefns[_T("MELA_13")];
324  stdDefns[_T("VAKULABHARANAM")]= stdDefns[_T("MELA_14")];
325  stdDefns[_T("MAYAMALAVAGOWLA")] = stdDefns[_T("MELA_15")];
326  stdDefns[_T("CHAKRAVAKAM")] = stdDefns[_T("MELA_16")];
327  stdDefns[_T("SURYAKANTHAM")] = stdDefns[_T("MELA_17")];
328  stdDefns[_T("HATAKAMBARI")] = stdDefns[_T("MELA_18")];
329 
330  stdDefns[_T("JHANKARADHWANI")]= stdDefns[_T("MELA_19")];
331  stdDefns[_T("NATABHAIRAVI")] = stdDefns[_T("MELA_20")];
332  stdDefns[_T("KEERAVANI")] = stdDefns[_T("MELA_21")];
333  stdDefns[_T("KHARAHARAPRIYA")]= stdDefns[_T("MELA_22")];
334  stdDefns[_T("GOWRIMANOHARI")] = stdDefns[_T("MELA_23")];
335  stdDefns[_T("VARUNAPRIYA")] = stdDefns[_T("MELA_24")];
336 
337  stdDefns[_T("MARARANJANI")] = stdDefns[_T("MELA_25")];
338  stdDefns[_T("CHARUKESHI")] = stdDefns[_T("MELA_26")];
339  stdDefns[_T("SARASANGI")] = stdDefns[_T("MELA_27")];
340  stdDefns[_T("HARIKHAMBHOJI")] = stdDefns[_T("MELA_28")];
341  stdDefns[_T("DHEERASHANKARABHARANAM")] = stdDefns[_T("MELA_29")];
342  stdDefns[_T("SHANKARABHARANAM")] = stdDefns[_T("MELA_29")];
343  stdDefns[_T("NAGANANDINI")] = stdDefns[_T("MELA_30")];
344 
345  stdDefns[_T("YAGAPRIYA")] = stdDefns[_T("MELA_31")];
346  stdDefns[_T("RAGAVARDHINI")] = stdDefns[_T("MELA_32")];
347  stdDefns[_T("GANGEYABHUSHINI")]= stdDefns[_T("MELA_33")];
348  stdDefns[_T("VAGADHISHWARI")] = stdDefns[_T("MELA_34")];
349  stdDefns[_T("SHULINI")] = stdDefns[_T("MELA_35")];
350  stdDefns[_T("CHALANATTAI")] = stdDefns[_T("MELA_36")];
351 
352  stdDefns[_T("SALAGAM")] = stdDefns[_T("MELA_37")];
353  stdDefns[_T("JALARNAVAM")] = stdDefns[_T("MELA_38")];
354  stdDefns[_T("JHALAVARALI")] = stdDefns[_T("MELA_39")];
355  stdDefns[_T("NAVANEETHAM")] = stdDefns[_T("MELA_40")];
356  stdDefns[_T("PAVANI")] = stdDefns[_T("MELA_41")];
357  stdDefns[_T("RAGHUPRIYA")] = stdDefns[_T("MELA_42")];
358 
359  stdDefns[_T("GAVAMBODHI")] = stdDefns[_T("MELA_43")];
360  stdDefns[_T("BHAVAPRIYA")] = stdDefns[_T("MELA_44")];
361  stdDefns[_T("SHUBHAPANTUVARALI")] = stdDefns[_T("MELA_45")];
362  stdDefns[_T("PANTUVARALI")] = stdDefns[_T("MELA_45")];
363  stdDefns[_T("SHADVIDHAMARGINI")] = stdDefns[_T("MELA_46")];
364  stdDefns[_T("SUVARNANGI")] = stdDefns[_T("MELA_47")];
365  stdDefns[_T("DIVYAMANI")] = stdDefns[_T("MELA_48")];
366 
367  stdDefns[_T("DHAVALAMBARI")] = stdDefns[_T("MELA_49")];
368  stdDefns[_T("NAMANARAYANI")] = stdDefns[_T("MELA_50")];
369  stdDefns[_T("KAMAVARDHINI")] = stdDefns[_T("MELA_51")];
370  stdDefns[_T("RAMAPRIYA")] = stdDefns[_T("MELA_52")];
371  stdDefns[_T("GAMANASHRAMA")] = stdDefns[_T("MELA_53")];
372  stdDefns[_T("VISHWAMBHARI")] = stdDefns[_T("MELA_54")];
373 
374  stdDefns[_T("SHYAMALANGI")] = stdDefns[_T("MELA_55")];
375  stdDefns[_T("SHANMUKHAPRIYA")]= stdDefns[_T("MELA_56")];
376  stdDefns[_T("SIMHENDRAMADHYAMAM")] = stdDefns[_T("MELA_57")];
377  stdDefns[_T("HEMAVATHI")] = stdDefns[_T("MELA_58")];
378  stdDefns[_T("DHARMAVATHI")] = stdDefns[_T("MELA_59")];
379  stdDefns[_T("NEETHIMATHI")] = stdDefns[_T("MELA_60")];
380 
381  stdDefns[_T("KANTHAMANI")] = stdDefns[_T("MELA_61")];
382  stdDefns[_T("RISHABHAPRIYA")] = stdDefns[_T("MELA_62")];
383  stdDefns[_T("LATHANGI")] = stdDefns[_T("MELA_63")];
384  stdDefns[_T("VACHASPATHI")] = stdDefns[_T("MELA_64")];
385  stdDefns[_T("MECHAKALYANI")] = stdDefns[_T("MELA_65")];
386  stdDefns[_T("KALYANI")] = stdDefns[_T("MELA_65")];
387  stdDefns[_T("CHITRAMBARI")] = stdDefns[_T("MELA_66")];
388 
389  stdDefns[_T("SUCHARITRA")] = stdDefns[_T("MELA_67")];
390  stdDefns[_T("JYOTHISWARUPINI")] = stdDefns[_T("MELA_68")];
391  stdDefns[_T("DHATUVARDHINI")] = stdDefns[_T("MELA_69")];
392  stdDefns[_T("NASIKABHUSHINI")]= stdDefns[_T("MELA_70")];
393  stdDefns[_T("KOSALAM")] = stdDefns[_T("MELA_71")];
394  stdDefns[_T("RASIKAPRIYA")] = stdDefns[_T("MELA_72")];
395 
396  stdDefns[_T("BILAHARI")] = stdDefns[_T("MELA_29")];
397  stdDefns[_T("HAMSADHWANI")] = stdDefns[_T("MELA_29")];
398  stdDefns[_T("HINDOLAM")] = stdDefns[_T("MELA_20")];
399  stdDefns[_T("KAMBHOJI")] = stdDefns[_T("MELA_28")];
400  stdDefns[_T("MADHYAMAVATHI")] = stdDefns[_T("MELA_22")];
401  stdDefns[_T("MOHANAM")] = stdDefns[_T("MELA_28")];
402  stdDefns[_T("NEELAMBARI")] = stdDefns[_T("MELA_29")];
403  }
404 
405  /// Populates Speed values for Carnatic music
406  inline static void PopulateSpeedDefinitions(DICTIONARY& stdDefns)
407  {
408  stdDefns[_T("1ST_SPEED")] = _T("1");
409  stdDefns[_T("2ND_SPEED")] = _T("2");
410  stdDefns[_T("3RD_SPEED")] = _T("3");
411  stdDefns[_T("4TH_SPEED")] = _T("4");
412  stdDefns[_T("5TH_SPEED")] = _T("5");
413  stdDefns[_T("6TH_SPEED")] = _T("6");
414  stdDefns[_T("1ST")] = _T("1");
415  stdDefns[_T("2ND")] = _T("2");
416  stdDefns[_T("3RD")] = _T("3");
417  stdDefns[_T("4TH")] = _T("4");
418  stdDefns[_T("5TH")] = _T("5");
419  stdDefns[_T("6TH")] = _T("6");
420  stdDefns[_T("FIRST")] = _T("1");
421  stdDefns[_T("SECOND")] = _T("2");
422  stdDefns[_T("THIRD")] = _T("3");
423  stdDefns[_T("FOURTH")] = _T("4");
424  stdDefns[_T("FIFTH")] = _T("5");
425  stdDefns[_T("SIXTH")] = _T("6");
426  }
427 
428  /// \brief Populates the standard KeySignature Macro defintions into Music String Dictionary
429  /// Western Key Signatures, Carnatic Ragas, Talam and Speed values are populated.
430  inline static void PopulateStandardDefinitions(DICTIONARY& stdDefns)
431  {
432  //
433  // Western Scale Definitions
434  //
435  PopulateWesternDefinitions(stdDefns);
436 
437  //
438  // Carnatic Raga & Mela Definitions
439  //
440  PopulateCarnaticDefinitions(stdDefns);
441 
442  // Special Identifiers to Restore the Previous Scale/Raga while Switching the Mode
443  stdDefns[_T("CARNATIC")] = _T("256");
444  stdDefns[_T("WESTERN")] = _T("256");
445 
446  // Populate the Talam Macro Definitions
448 
449  //
450  // Speed Definitions
451  //
452  PopulateSpeedDefinitions(stdDefns);
453  }
454 
455  /// Takes a plain Swara and converts it to the correct value based on the supplied Melakartha Raga.
456  /// @param nSwara the Swara to be looked up. A value in the range [0, 6]
457  /// @param nMela the index of the Mela the Swara sthana is being looked for. A value in the range [1, 72]
458  /// @return A value in the range [0, 11] indicating the Swara sthana as per the Mela
459  inline static unsigned short LookupSwaraSthanaForMela(short nSwara, unsigned short nMela)
460  {
461  enum SwaraSthanas
462  { S=0, R1=1, R2=2, R3=3,
463  G1=2, G2=3, G3=4,
464  M1=5, M2=6,
465  P=7, D1=8, D2=9, D3=10,
466  N1=9, N2=10,N3=11
467  } ragaSwaraSthanas[][7]=
468  {
469  { S, R2, G3, M1, P, D2, N3 }, // Mela_0 same as Mela_29
470  { S, R1, G1, M1, P, D1, N1 }, // Mela_1
471  { S, R1, G1, M1, P, D1, N2 }, // Mela_2
472  { S, R1, G1, M1, P, D1, N3 }, // Mela_3
473  { S, R1, G1, M1, P, D2, N2 }, // Mela_4
474  { S, R1, G1, M1, P, D2, N3 }, // Mela_5
475  { S, R1, G1, M1, P, D3, N3 }, // Mela_6
476  { S, R1, G2, M1, P, D1, N1 }, // Mela_7
477  { S, R1, G2, M1, P, D1, N2 }, // Mela_8
478  { S, R1, G2, M1, P, D1, N3 }, // Mela_9
479  { S, R1, G2, M1, P, D2, N2 }, // Mela_10
480  { S, R1, G2, M1, P, D2, N3 }, // Mela_11
481  { S, R1, G2, M1, P, D3, N3 }, // Mela_12
482  { S, R1, G3, M1, P, D1, N1 }, // Mela_13
483  { S, R1, G3, M1, P, D1, N2 }, // Mela_14
484  { S, R1, G3, M1, P, D1, N3 }, // Mela_15
485  { S, R1, G3, M1, P, D2, N2 }, // Mela_16
486  { S, R1, G3, M1, P, D2, N3 }, // Mela_17
487  { S, R1, G3, M1, P, D3, N3 }, // Mela_18
488  { S, R2, G2, M1, P, D1, N1 }, // Mela_19
489  { S, R2, G2, M1, P, D1, N2 }, // Mela_20
490  { S, R2, G2, M1, P, D1, N3 }, // Mela_21
491  { S, R2, G2, M1, P, D2, N2 }, // Mela_22
492  { S, R2, G2, M1, P, D2, N3 }, // Mela_23
493  { S, R2, G2, M1, P, D3, N3 }, // Mela_24
494  { S, R2, G3, M1, P, D1, N1 }, // Mela_25
495  { S, R2, G3, M1, P, D1, N2 }, // Mela_26
496  { S, R2, G3, M1, P, D1, N3 }, // Mela_27
497  { S, R2, G3, M1, P, D2, N2 }, // Mela_28
498  { S, R2, G3, M1, P, D2, N3 }, // Mela_29
499  { S, R2, G3, M1, P, D3, N3 }, // Mela_30
500  { S, R3, G3, M1, P, D1, N1 }, // Mela_31
501  { S, R3, G3, M1, P, D1, N2 }, // Mela_32
502  { S, R3, G3, M1, P, D1, N3 }, // Mela_33
503  { S, R3, G3, M1, P, D2, N2 }, // Mela_34
504  { S, R3, G3, M1, P, D2, N3 }, // Mela_35
505  { S, R3, G3, M1, P, D3, N3 }, // Mela_36
506  { S, R1, G1, M2, P, D1, N1 }, // Mela_37
507  { S, R1, G1, M2, P, D1, N2 }, // Mela_38
508  { S, R1, G1, M2, P, D1, N3 }, // Mela_39
509  { S, R1, G1, M2, P, D2, N2 }, // Mela_40
510  { S, R1, G1, M2, P, D2, N3 }, // Mela_41
511  { S, R1, G1, M2, P, D3, N3 }, // Mela_42
512  { S, R1, G2, M2, P, D1, N1 }, // Mela_43
513  { S, R1, G2, M2, P, D1, N2 }, // Mela_44
514  { S, R1, G2, M2, P, D1, N3 }, // Mela_45
515  { S, R1, G2, M2, P, D2, N2 }, // Mela_46
516  { S, R1, G2, M2, P, D2, N3 }, // Mela_47
517  { S, R1, G2, M2, P, D3, N3 }, // Mela_48
518  { S, R1, G3, M2, P, D1, N1 }, // Mela_49
519  { S, R1, G3, M2, P, D1, N2 }, // Mela_50
520  { S, R1, G3, M2, P, D1, N3 }, // Mela_51
521  { S, R1, G3, M2, P, D2, N2 }, // Mela_52
522  { S, R1, G3, M2, P, D2, N3 }, // Mela_53
523  { S, R1, G3, M2, P, D3, N3 }, // Mela_54
524  { S, R2, G2, M2, P, D1, N1 }, // Mela_55
525  { S, R2, G2, M2, P, D1, N2 }, // Mela_56
526  { S, R2, G2, M2, P, D1, N3 }, // Mela_57
527  { S, R2, G2, M2, P, D2, N2 }, // Mela_58
528  { S, R2, G2, M2, P, D2, N3 }, // Mela_59
529  { S, R2, G2, M2, P, D3, N3 }, // Mela_60
530  { S, R2, G3, M2, P, D1, N1 }, // Mela_61
531  { S, R2, G3, M2, P, D1, N2 }, // Mela_62
532  { S, R2, G3, M2, P, D1, N3 }, // Mela_63
533  { S, R2, G3, M2, P, D2, N2 }, // Mela_64
534  { S, R2, G3, M2, P, D2, N3 }, // Mela_65
535  { S, R2, G3, M2, P, D3, N3 }, // Mela_66
536  { S, R3, G3, M2, P, D1, N1 }, // Mela_67
537  { S, R3, G3, M2, P, D1, N2 }, // Mela_68
538  { S, R3, G3, M2, P, D1, N3 }, // Mela_69
539  { S, R3, G3, M2, P, D2, N2 }, // Mela_70
540  { S, R3, G3, M2, P, D2, N3 }, // Mela_71
541  { S, R3, G3, M2, P, D3, N3 }, // Mela_72
542  };
543 
544  return ragaSwaraSthanas[nMela][nSwara];
545 
546  /* SwaraSthanas generator code
547 
548  int nRagaCount = 1;
549 
550  printf( "\nenum SwaraSthanas "
551  "\n { S=0, R1=1, R2=2, R3=3, "
552  "\n G1=2, G2=3, G3=4,"
553  "\n M1=5, M2=6,"
554  "\n P=7, D1=8, D2=9, D3=10,"
555  "\n N1=9, N2=10,N3=11"
556  "\n } ragaSwaraSthanas[][7]="
557  "\n {"
558  "\n { S, R2, G3, M1, P, D2, N3 }, // Mela_0 same as Mela_29" );
559 
560  for(int m=1; m <=2 ; ++m)
561  {
562  for(int r=1; r <= 3; ++r)
563  {
564  for(int g=r; g <= 3; ++g)
565  {
566  for(int d=1; d <= 3; ++d)
567  {
568  for(int n=d; n <= 3; ++n, nRagaCount++)
569  {
570  printf("\n { S, R%d, G%d, M%d, P, D%d, N%d }, // Mela_%d", r, g, m, d, n, nRagaCount);
571  }
572  }
573  }
574  }
575  }
576 
577  printf("\n };\n");
578  */
579  }
580 
581  };
582 
583 } // namespace CFugue
584 
585 #endif // KEYSIGNATURE_H__56751CC1_46A2_4238_BAF1_7884CDA8089B__
void SetRagam(const unsigned short nRagam)
Definition: KeySignature.h:137
KeySignature(const unsigned short nRagam, const unsigned short nTalam)
Carnatic Mode constructor.
Definition: KeySignature.h:105
const Talam & GetTalam() const
Returns the Talam Value. Valid only when the Mode is CARNATIC. Use GetMode() to find the Mode;...
Definition: KeySignature.h:125
static unsigned short LookupSwaraSthanaForMela(short nSwara, unsigned short nMela)
Definition: KeySignature.h:459
void SetMajMin(const Scale bScale)
Definition: KeySignature.h:133
signed char GetKey() const
Returns the Key Signature value. Based on the Mode, Value will be in the range [-7, 7] or [1, 72]. Use GetMode() to find the Mode.
Definition: KeySignature.h:113
void SetTalam(const Talam &talam)
Definition: KeySignature.h:141
Class representing the Key Signature.
Definition: KeySignature.h:79
static void PopulateSpeedDefinitions(DICTIONARY &stdDefns)
Populates Speed values for Carnatic music.
Definition: KeySignature.h:406
KeySignature(const signed short nKeySig, const Scale bScale)
Western Mode constructor.
Definition: KeySignature.h:100
static void PopulateStandardDefinitions(DICTIONARY &stdDefns)
Populates the standard KeySignature Macro defintions into Music String Dictionary Western Key Signatu...
Definition: KeySignature.h:430
unsigned short & Speed()
Returns the current Song speed. Valid only for Carnatic Mode. Use GetMode() to verify the Mode...
Definition: KeySignature.h:145
Mode GetMode() const
Returns if the KeySignature refers to Carnatic Mode or Western Mode.
Definition: KeySignature.h:121
static void PopulateWesternDefinitions(DICTIONARY &stdDefns)
Populates Western Music Scale values.
Definition: KeySignature.h:148
std::map< MString, MString, StringLess< const TCHAR * > > DICTIONARY
Definition: Dictionary.h:37
static void PopulateStandardDefinitions(DICTIONARY &stdDefns)
Populates the standard Talam Macro defintions into Music String Dictionary.
Definition: Talam.h:39
KeySignature()
Default constructor.
Definition: KeySignature.h:95
unsigned char GetMajMin() const
Definition: KeySignature.h:118
void SetKey(const signed short nKeySig)
Definition: KeySignature.h:129
static void PopulateCarnaticDefinitions(DICTIONARY &stdDefns)
Populates Carnatic Ragas and Mela values.
Definition: KeySignature.h:217
Class representing Carnatic Music Talam
Definition: Talam.h:21

CFugue, the C++ Music Programming Library © Copyright 2009 Cenacle Research India Private Limited Gopalakrishna Palem