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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// -*- c-basic-offset: 4 -*-
//
#include "NotationTypes.h"
#include "gui/dialogs/IntervalDialog.h"
using namespace Rosegarden;
using std::cout;
// Unit test-ish tests for transposition.
//
// Returns -1 (or crashes :)) on error, 0 on success
/**
* should be in Pitch eventually
*/
int testAisDisplayAccidentalInCmaj()
{
Pitch ais(70, Accidentals::Sharp);
Key cmaj ("C major");
Accidental accidental = ais.getDisplayAccidental(cmaj);
if (accidental != Accidentals::Sharp)
{
std::cout << "Accidental for A# in Cmaj was " << accidental << " instead of expected Sharp" << std::endl;
return -1;
}
return 0;
}
/**
* transpose an C# down by an augmented prime in C# major, should yield a C (in C major)
*/
int testCisToC()
{
std::cout << "Testing transposing C# to C... ";
Pitch cis(73, Accidentals::Sharp);
Pitch result = cis.transpose(Key("C# major"), -1, 0);
Accidental resultAccidental = result.getAccidental(Key("C major"));
int resultPitch = result.getPerformancePitch();
if (resultAccidental != Accidentals::NoAccidental || resultPitch != 72)
{
std::cout << "Transposing C# down by an augmented prime didn't yield C, but " << result.getNoteName(Key("C major")) << resultAccidental << std::endl;
return -1;
}
return 0;
}
/**
* transpose an A# up by a major second, should
* yield a B# (as C would be a minor triad)
*/
int testAisToBis()
{
std::cout << "Testing transposing A# to B#... ";
Pitch ais(70, Accidentals::Sharp);
Key cmaj ("C major");
Pitch result = ais.transpose(cmaj, 2, 1);
Accidental resultAccidental = result.getAccidental(cmaj);
int resultPitch = result.getPerformancePitch();
if (resultAccidental != Accidentals::Sharp || resultPitch != 72)
{
std::cout << "Transposing A# up by a major second didn't yield B#, but " << result.getNoteName(cmaj) << resultAccidental << std::endl;
return -1;
}
std::cout << "Success" << std::endl;
return 0;
}
/**
* Transpose G to D in the key of D major.
*/
int testGToD()
{
std::cout << "Testing transposing G to D... ";
Pitch g(67, Accidentals::Natural);
Key* dmaj = new Key("D major");
Pitch result = g.transpose(*dmaj, 7, 4);
Accidental resultAccidental = result.getAccidental(*dmaj);
int resultPitch = result.getPerformancePitch();
if (resultAccidental != Accidentals::NoAccidental || resultPitch != 74)
{
std::cout << "Transposing G up by a fifth didn't yield D, but " << result.getNoteName(*dmaj) << resultAccidental << std::endl;
return -1;
}
std::cout << "Success" << std::endl;
return 0;
}
int testTransposeBbToF()
{
Pitch bb(70, Accidentals::Flat);
Key besmaj("Bb major");
Pitch result = bb.transpose(besmaj, -5, -3);
Accidental resultAccidental = result.getAccidental(besmaj);
int resultPitch = result.getPerformancePitch();
if (resultAccidental != Accidentals::NoAccidental || resultPitch != 65)
{
return -1;
}
return 0;
}
int testIntervalString(int steps, int semitones, QString expectedString)
{
QString text = IntervalDialog::getIntervalName(steps, semitones);
if (text != expectedString) {
std::cout << "When converting the interval " << steps << "," << semitones << " to string, expected '" << expectedString << "' but got '" << text << "'" << std::endl;
return -1;
}
return 0;
}
int testIntervalToString()
{
return testIntervalString(1,1,"up a minor second")
+ testIntervalString(0,0,"a perfect unison")
+ testIntervalString(0,1,"up an augmented unison")
+ testIntervalString(7,12,"up 1 octave")
+ testIntervalString(7,13,"up an augmented octave");
QString text = IntervalDialog::getIntervalName(1, 1);
std::cout << "Minor second: " << text << std::endl;
text = IntervalDialog::getIntervalName(0, 0);
std::cout << "Perfect unison: " << text << std::endl;
text = IntervalDialog::getIntervalName(0, 1);
std::cout << "Augmented unison: " << text << std::endl;
text = IntervalDialog::getIntervalName(7, 12);
std::cout << "1 octave: " << text << std::endl;
text = IntervalDialog::getIntervalName(7, 13);
std::cout << "Octave and augmented unison: " << text << std::endl;
return 0;
}
int test_transpose(int argc, char **argv)
{
return testAisDisplayAccidentalInCmaj() +
testAisToBis() +
testGToD() +
testTransposeBbToF() +
testIntervalToString() +
testCisToC();
}
|