11 static const ChordDef DefChordDefinitions[] =
13 {_T(
"MAJ"), {4,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 2},
14 {_T(
"MIN"), {3,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 2},
15 {_T(
"AUG"), {4,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 2},
16 {_T(
"DIM"), {3,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 2},
17 {_T(
"DOM7"), {4,7,10,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
18 {_T(
"MAJ7"), {4,7,11,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
19 {_T(
"MIN7"), {3,7,10,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
20 {_T(
"SUS4"), {5,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 2},
21 {_T(
"SUS2"), {2,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 2},
22 {_T(
"MAJ6"), {4,7,9,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
23 {_T(
"MIN6"), {3,7,9,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
24 {_T(
"DOM9"), {4,7,10,14,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
25 {_T(
"MAJ9"), {4,7,11,14,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
26 {_T(
"MIN9"), {3,7,10,14,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
27 {_T(
"DIM7"), {3,6,9,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
28 {_T(
"ADD9"), {4,7,14,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
29 {_T(
"MIN11"), {7,10,14,15,17,0,0,0,0,0,0,0,0,0,0,0}, 5},
30 {_T(
"DOM11"), {7,10,14,17,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
31 {_T(
"DOM13"), {7,10,14,16,21,0,0,0,0,0,0,0,0,0,0,0}, 5},
32 {_T(
"MIN13"), {7,10,14,15,21,0,0,0,0,0,0,0,0,0,0,0}, 5},
33 {_T(
"MAJ13"), {7,11,14,16,21,0,0,0,0,0,0,0,0,0,0,0}, 5},
34 {_T(
"DOM7_5"), {4,6,10,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
35 {_T(
"DOM7<5"), {4,6,10,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
36 {_T(
"DOM75"), {4,8,10,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
37 {_T(
"DOM7>5"), {4,8,10,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
38 {_T(
"MAJ7_5"), {4,6,11,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
39 {_T(
"MAJ7<5"), {4,6,11,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
40 {_T(
"MAJ75"), {4,8,11,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
41 {_T(
"MAJ7>5"), {4,8,11,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
42 {_T(
"MINMAJ7"), {3,7,11,0,0,0,0,0,0,0,0,0,0,0,0,0}, 3},
43 {_T(
"DOM7_5_9"), {4,6,10,13,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
44 {_T(
"DOM7<5<9"), {4,6,10,13,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
45 {_T(
"DOM7_59"), {4,6,10,15,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
46 {_T(
"DOM7<5>9"), {4,6,10,15,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
47 {_T(
"DOM75_9"), {4,8,10,13,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
48 {_T(
"DOM7>5<9"), {4,8,10,13,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
49 {_T(
"DOM759"), {4,8,10,15,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
50 {_T(
"DOM7>5>9"), {4,8,10,15,0,0,0,0,0,0,0,0,0,0,0,0}, 4},
55 template <
typename T,
size_t N >
56 inline size_t _countof(T(&arr)[N]) {
return std::extent< T[N] >::value; }
61 bool phRepComparator(
const T* input1,
const T* input2)
63 return _tcslen(input1->szChordName) > _tcslen(input2->szChordName);
67 void LoadVector(std::map<TCHAR, std::vector<const T*> >& vecArray,
const T* inputArr,
int nInputSize)
70 for(
int i=0; i < nInputSize; ++i)
72 const T& Obj = inputArr[i];
74 const TCHAR chIndex = Obj.szChordName[0];
76 vecArray[chIndex].push_back(inputArr+i);
79 typedef typename std::map<TCHAR, std::vector<const T*> >::value_type VecIterTypeT;
82 std::for_each(vecArray.begin(), vecArray.end(), [](VecIterTypeT& iter)
84 std::vector<const T*>& vec = iter.second;
85 std::sort(vec.begin(), vec.end(), phRepComparator<T>);
92 inline unsigned int IsPrefixMatching(
const TCHAR* sz,
const TCHAR* pfx)
94 unsigned int nMatched = 0;
96 while(*sz && *pfx && *sz == *pfx)
103 return (*pfx == _T(
'\0')) ? nMatched : 0;
111 inline unsigned int ExtractMatchingObject(
const std::map<TCHAR, std::vector<const T*> >& vecArray,
const TCHAR* sz, T* retVal)
113 const TCHAR chIndex = sz[0];
115 const auto iterVecObjects = vecArray.find(chIndex);
117 if(iterVecObjects != vecArray.end())
119 const std::vector<const T*>& vecObjects = iterVecObjects->second;
121 unsigned int nMatched = 0;
123 for(
size_t i=0, nMax = vecObjects.size(); i < nMax; ++i)
125 *retVal = *vecObjects[i];
127 if((nMatched = IsPrefixMatching(sz, retVal->szChordName)) > 0)
147 m_Definitions.clear();
148 if(pChords == NULL || nSize == 0)
150 pChords = DefChordDefinitions;
151 nSize = _countof(DefChordDefinitions);
153 LoadVector(this->m_Definitions, pChords, nSize);
159 if(pChords != NULL && nSize != 0)
160 LoadVector(this->m_Definitions, pChords, nSize);
165 return ExtractMatchingObject(this->m_Definitions, szToken, retVal);
Chords()
Initialize the Chords with default definitions.
void LoadDefinitions(const ChordDef *pChords=NULL, int nSize=0)
unsigned int ExtractMatchingChord(const TCHAR *szToken, ChordDef *retVal) const
Definition of a Chord entry.
Maniuplates Chord definitions for Western Music
static unsigned int GetDefaultMatchingChord(const TCHAR *szToken, ChordDef *retVal)
void AddDefinitions(const ChordDef *pChords, int nSize)