MicrotonalTest.cpp (4622B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 MicrotonalTest.h - CxxTest for Misc/Microtonal 5 Copyright (C) 2009-2012 Mark McCurry 6 Author: Mark McCurry 7 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. 12 */ 13 #include "test-suite.h" 14 #include <iostream> 15 #include "../Misc/Microtonal.h" 16 #include "../Misc/XMLwrapper.h" 17 #include <cstring> 18 #include <string> 19 #include <cstdio> 20 #include "../globals.h" 21 using namespace std; 22 using namespace zyn; 23 24 SYNTH_T *synth; 25 26 class MicrotonalTest 27 { 28 public: 29 int compression; 30 void setUp() { 31 compression = 0; 32 synth = new SYNTH_T; 33 testMicro = new Microtonal(compression); 34 } 35 36 void tearDown() { 37 delete testMicro; 38 delete synth; 39 } 40 41 //Verifies that the object is initialized correctly 42 void testinit() { 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); 56 57 TS_ASSERT_EQUAL_STR("12tET", (const char *)testMicro->Pname); 58 TS_ASSERT_EQUAL_STR("Equal Temperament 12 notes per octave", 59 testMicro->Pcomment); 60 61 for(int i = 0; i < 128; ++i) 62 TS_ASSERT_EQUAL_INT(i, testMicro->Pmapping[i]); 63 64 TS_ASSERT_DELTA(testMicro->getnotefreq(19 / 12.0f, 0), 24.4997f, 0.0001f); 65 } 66 67 //Tests saving/loading to XML 68 void testXML() { 69 //Gah, the XMLwrapper is a twisted maze 70 testMicro->Penabled = 1; 71 XMLwrapper xml; 72 xml.beginbranch("Dummy"); //this should not be needed, but odd behavior 73 //seems to exist from MICROTONAL being on the 74 //top of the stack 75 xml.beginbranch("MICROTONAL"); 76 testMicro->add2XML(xml); 77 xml.endbranch(); 78 xml.endbranch(); 79 80 char *tmp = xml.getXMLdata(); 81 Microtonal other(compression); 82 83 other.Penabled = 1; 84 strcpy((char *)other.Pname, "Myname"); //will be nicer with strings 85 86 TS_ASSERT(*testMicro != other); //sanity check 87 88 TS_ASSERT(xml.enterbranch("Dummy")); 89 TS_ASSERT(xml.enterbranch("MICROTONAL")); 90 91 other.getfromXML(xml); 92 xml.exitbranch(); 93 xml.exitbranch(); 94 char *tmpo = xml.getXMLdata(); 95 96 TS_ASSERT(!strcmp(tmp, tmpo)); 97 free(tmp); 98 free(tmpo); 99 } 100 101 #if 0 102 /**\todo Test Saving/loading from file*/ 103 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; 111 // 112 // octave size == 7 113 // find dead notes 114 } 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 124 } 125 /**\TODO test loading from scl and kbm files*/ 126 #endif 127 128 private: 129 Microtonal *testMicro; 130 }; 131 132 int main() 133 { 134 MicrotonalTest test; 135 RUN_TEST(testinit); 136 RUN_TEST(testXML); 137 return test_summary(); 138 }