快速判断和弦的紧张程度

理论依据来自:怎样写和声不会出错?五度圈居然这么好用? - 松竹梅的文章 - 知乎 https://zhuanlan.zhihu.com/p/357311147 ,我写了一个 C++ 程序来帮助快速判断。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <vector>
#include <cstdint>
#include <cstddef>
#include <algorithm>

int main()
{
std::cout << " 请输入和弦组成音的数量:\n";
size_t len;
std::cin >> len;
char cnote[3] = { 0 };
uint16_t unote = 0;
std::vector<uint16_t> notes(0);

std::cout << " 请输入所有和弦的组成音,一行一个,半音只支持 bX 的形式:\n";
for (size_t i = 0; i < len; i++)
{
std::cin >> cnote;
switch ((*(uint16_t*)cnote))
{
case 'C':
unote = 1;
notes.push_back(unote);
break;
case 'G':
unote = 2;
notes.push_back(unote);
break;
case 'D':
unote = 3;
notes.push_back(unote);
break;
case 'A':
unote = 4;
notes.push_back(unote);
break;
case 'E':
unote = 5;
notes.push_back(unote);
break;
case 'B':
unote = 6;
notes.push_back(unote);
break;
case 'Gb':
unote = 7;
notes.push_back(unote);
break;
case 'Db':
unote = 8;
notes.push_back(unote);
break;
case 'Ab':
unote = 9;
notes.push_back(unote);
break;
case 'Eb':
unote = 10;
notes.push_back(unote);
break;
case 'Bb':
unote = 11;
notes.push_back(unote);
break;
case 'F':
unote = 12;
notes.push_back(unote);
break;
//std::cout << cnote;
default:
std::cout << " 不是音符!\n";
i--;
break;
}
}

std::sort(notes.begin(), notes.end());
notes.push_back(notes[0] + 12);

for (auto it = notes.begin() + 1; it != notes.end(); it++)
{
//std::cout << *(it - 1) << "," << *it << "\n";
if ((*it - *(it - 1)) > 6)
{
goto low;
}
else if ((*it - *(it - 1)) == 6)
{
goto mid;
}
}
high:
std::cout << " 这个和弦的张力非常大。" << std::endl;
goto end;

low:
std::cout << " 这个和弦的张力不太大。" << std::endl;
goto end;
mid:
std::cout << " 这个和弦的张力较大。" << std::endl;
goto end;


end:
return 0;
}