You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rosegarden/src/base/test/transpose.cpp

82 lines
2.0 KiB

#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;
}