Add python3 to github action test deps
[zynaddsubfx-code.git] / src / Tests / MicrotonalTest.h
blob4cae3c6341a2a527d93a07e53dd32c6d75af0435
1 /*
2 ZynAddSubFX - a software synthesizer
4 MicrotonalTest.h - CxxTest for Misc/Microtonal
5 Copyright (C) 2009-2012 Mark McCurry
6 Author: 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>
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;
24 SYNTH_T *synth;
26 class MicrotonalTest:public CxxTest::TestSuite
28 public:
29 int compression;
30 void setUp() {
31 compression = 0;
32 synth = new SYNTH_T;
33 testMicro = new Microtonal(compression);
36 void tearDown() {
37 delete testMicro;
38 delete synth;
41 //Verifies that the object is initialized correctly
42 void testinit() {
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
69 void testXML() {
70 //Gah, the XMLwrapper is a twisted maze
71 testMicro->Penabled = 1;
72 XMLwrapper xml;
73 xml.beginbranch("Dummy"); //this should not be needed, but odd behavior
74 //seems to exist from MICROTONAL being on the
75 //top of the stack
76 xml.beginbranch("MICROTONAL");
77 testMicro->add2XML(xml);
78 xml.endbranch();
79 xml.endbranch();
81 char *tmp = xml.getXMLdata();
82 Microtonal other(compression);
84 other.Penabled = 1;
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);
93 xml.exitbranch();
94 xml.exitbranch();
95 char *tmpo = xml.getXMLdata();
97 TS_ASSERT(!strcmp(tmp, tmpo));
98 free(tmp);
99 free(tmpo);
102 #if 0
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;
113 // octave size == 7
114 // find dead notes
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*/
127 #endif
129 private:
130 Microtonal *testMicro;