2 ZynAddSubFX - a software synthesizer
4 MicrotonalTest.h - CxxTest for Misc/Microtonal
5 Copyright (C) 2009-2012 Mark McCurry
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 #include "test-suite.h"
15 #include "../Misc/Microtonal.h"
16 #include "../Misc/XMLwrapper.h"
20 #include "../globals.h"
33 testMicro
= new Microtonal(compression
);
41 //Verifies that the object is initialized correctly
43 TS_ASSERT_EQUAL_INT(testMicro
->Pinvertupdown
, 0);
44 TS_ASSERT_EQUAL_INT(testMicro
->Pinvertupdowncenter
, 60);
45 TS_ASSERT_EQUAL_INT(testMicro
->getoctavesize(), 12);
46 TS_ASSERT_EQUAL_INT(testMicro
->Penabled
, 0);
47 TS_ASSERT_EQUAL_INT(testMicro
->PAnote
, 69);
48 TS_ASSERT_EQUAL_INT(testMicro
->PAfreq
, 440.0f
);
49 TS_ASSERT_EQUAL_INT(testMicro
->Pscaleshift
, 64);
50 TS_ASSERT_EQUAL_INT(testMicro
->Pfirstkey
, 0);
51 TS_ASSERT_EQUAL_INT(testMicro
->Plastkey
, 127);
52 TS_ASSERT_EQUAL_INT(testMicro
->Pmiddlenote
, 60);
53 TS_ASSERT_EQUAL_INT(testMicro
->Pmapsize
, 12);
54 TS_ASSERT_EQUAL_INT(testMicro
->Pmappingenabled
, 0);
55 TS_ASSERT_EQUAL_INT(testMicro
->Pglobalfinedetune
, 64);
57 TS_ASSERT_EQUAL_STR("12tET", (const char *)testMicro
->Pname
);
58 TS_ASSERT_EQUAL_STR("Equal Temperament 12 notes per octave",
61 for(int i
= 0; i
< 128; ++i
)
62 TS_ASSERT_EQUAL_INT(i
, testMicro
->Pmapping
[i
]);
64 TS_ASSERT_DELTA(testMicro
->getnotefreq(19 / 12.0f
, 0), 24.4997f
, 0.0001f
);
67 //Tests saving/loading to XML
69 //Gah, the XMLwrapper is a twisted maze
70 testMicro
->Penabled
= 1;
72 xml
.beginbranch("Dummy"); //this should not be needed, but odd behavior
73 //seems to exist from MICROTONAL being on the
75 xml
.beginbranch("MICROTONAL");
76 testMicro
->add2XML(xml
);
80 char *tmp
= xml
.getXMLdata();
81 Microtonal
other(compression
);
84 strcpy((char *)other
.Pname
, "Myname"); //will be nicer with strings
86 TS_ASSERT(*testMicro
!= other
); //sanity check
88 TS_ASSERT(xml
.enterbranch("Dummy"));
89 TS_ASSERT(xml
.enterbranch("MICROTONAL"));
91 other
.getfromXML(xml
);
94 char *tmpo
= xml
.getXMLdata();
96 TS_ASSERT(!strcmp(tmp
, tmpo
));
102 /**\todo Test Saving/loading from file*/
104 //Test texttomapping TODO finish
105 void _testTextToMapping() {
106 //the mapping is from old documentation for "Intense Diatonic" scale
107 const char *mapping
[12] =
108 {"0", "x", "1", "x", "2", "3", "x", "4", "x", "5", "x", "6"};
109 //for(int i=0;i<20;++i)
110 // cout << i << ':' << testMicro->getnotefreq(i,0) << endl;
115 //Test texttotunings TODO finish
116 void _testTextToTunings() {
117 //the tuning is from old documentation for "Intense Diatonic" scale
118 const char *tuning
[7] =
119 {"9/8", "5/4", "4/3", "3/2", "5/3", "15/8", "2/1"};
120 const int numTunings
= 7;
121 //for(int i=0;i<20;++i)
122 // cout << i << ':' << testMicro->getnotefreq(i,0) << endl;
123 // go to middle key and verify the proportions
125 /**\TODO test loading from scl and kbm files*/
129 Microtonal
*testMicro
;
137 return test_summary();