summaryrefslogtreecommitdiffstats
path: root/src/base/test/transpose.cpp
blob: 9d810f890321a41307e04359eb6170b0043e5f1f (plain)
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
#include "NotationTypes.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
 */
void 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;
        exit(-1);
    }
}

/** 
 * transpose an A# up by a major second, should 
 * yield a B# (as C would be a minor triad) 
 */
void 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;
        exit(-1);
    }
    std::cout << "Success" << std::endl;
}

/**
 * Transpose G to D in the key of D major.
 */
void 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;
        exit(-1);
    }
    std::cout << "Success" << std::endl;
}

void testKeyTransposition()
{

}

int main(int argc, char **argv)
{
    testAisDisplayAccidentalInCmaj();
    testAisToBis();
    testGToD();
    testKeyTransposition();

    return 0;    
}