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 <cxxtest/TestSuite.h>
15 #include "../Misc/Microtonal.h"
16 #include "../Misc/XMLwrapper.h"
20 #include "../globals.h"
26 class MicrotonalTest
:public CxxTest::TestSuite
33 testMicro
= new Microtonal(compression
);
41 //Verifies that the object is initialized correctly
43 TS_ASSERT_EQUALS(testMicro
->Pinvertupdown
, 0);
44 TS_ASSERT_EQUALS(testMicro
->Pinvertupdowncenter
, 60);
45 TS_ASSERT_EQUALS(testMicro
->getoctavesize(), 12);
46 TS_ASSERT_EQUALS(testMicro
->Penabled
, 0);
47 TS_ASSERT_EQUALS(testMicro
->PAnote
, 69);
48 TS_ASSERT_EQUALS(testMicro
->PAfreq
, 440.0f
);
49 TS_ASSERT_EQUALS(testMicro
->Pscaleshift
, 64);
50 TS_ASSERT_EQUALS(testMicro
->Pfirstkey
, 0);
51 TS_ASSERT_EQUALS(testMicro
->Plastkey
, 127);
52 TS_ASSERT_EQUALS(testMicro
->Pmiddlenote
, 60);
53 TS_ASSERT_EQUALS(testMicro
->Pmapsize
, 12);
54 TS_ASSERT_EQUALS(testMicro
->Pmappingenabled
, 0);
55 TS_ASSERT_EQUALS(testMicro
->Pglobalfinedetune
, 64);
57 TS_ASSERT_EQUALS(string((const char *)testMicro
->Pname
), "12tET");
58 TS_ASSERT_EQUALS(string(
59 (const char *)testMicro
->Pcomment
),
60 "Equal Temperament 12 notes per octave");
62 for(int i
= 0; i
< 128; ++i
)
63 TS_ASSERT_EQUALS(testMicro
->Pmapping
[i
], i
);
65 TS_ASSERT_DELTA(testMicro
->getnotefreq(19 / 12.0f
, 0), 24.4997f
, 0.0001f
);
68 //Tests saving/loading to XML
70 //Gah, the XMLwrapper is a twisted maze
71 testMicro
->Penabled
= 1;
73 xml
.beginbranch("Dummy"); //this should not be needed, but odd behavior
74 //seems to exist from MICROTONAL being on the
76 xml
.beginbranch("MICROTONAL");
77 testMicro
->add2XML(xml
);
81 char *tmp
= xml
.getXMLdata();
82 Microtonal
other(compression
);
85 strcpy((char *)other
.Pname
, "Myname"); //will be nicer with strings
87 TS_ASSERT(*testMicro
!= other
); //sanity check
89 TS_ASSERT(xml
.enterbranch("Dummy"));
90 TS_ASSERT(xml
.enterbranch("MICROTONAL"));
92 other
.getfromXML(xml
);
95 char *tmpo
= xml
.getXMLdata();
97 TS_ASSERT(!strcmp(tmp
, tmpo
));
103 /**\todo Test Saving/loading from file*/
105 //Test texttomapping TODO finish
106 void _testTextToMapping() {
107 //the mapping is from old documentation for "Intense Diatonic" scale
108 const char *mapping
[12] =
109 {"0", "x", "1", "x", "2", "3", "x", "4", "x", "5", "x", "6"};
110 //for(int i=0;i<20;++i)
111 // cout << i << ':' << testMicro->getnotefreq(i,0) << endl;
116 //Test texttotunings TODO finish
117 void _testTextToTunings() {
118 //the tuning is from old documentation for "Intense Diatonic" scale
119 const char *tuning
[7] =
120 {"9/8", "5/4", "4/3", "3/2", "5/3", "15/8", "2/1"};
121 const int numTunings
= 7;
122 //for(int i=0;i<20;++i)
123 // cout << i << ':' << testMicro->getnotefreq(i,0) << endl;
124 // go to middle key and verify the proportions
126 /**\TODO test loading from scl and kbm files*/
130 Microtonal
*testMicro
;