LMMS
Loading...
Searching...
No Matches
MicrotonalTest.h
Go to the documentation of this file.
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 modify
9 it under the terms of version 2 of the GNU General Public License
10 as published by the Free Software Foundation.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License (version 2 or later) for more details.
16
17 You should have received a copy of the GNU General Public License (version 2)
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21*/
22#include <cxxtest/TestSuite.h>
23#include <iostream>
24#include "../Misc/Microtonal.h"
25#include <cstring>
26#include <string>
27#include <cstdio>
28#include "../globals.h"
30
31using namespace std;
32
33class MicrotonalTest:public CxxTest::TestSuite
34{
35 public:
36 void setUp() {
37 synth = new SYNTH_T;
38 testMicro = new Microtonal();
39 }
40
41 void tearDown() {
42 delete testMicro;
43 delete synth;
44 }
45
46 //Verifies that the object is initialized correctly
47 void testinit() {
48 TS_ASSERT_EQUALS(testMicro->Pinvertupdown, 0);
49 TS_ASSERT_EQUALS(testMicro->Pinvertupdowncenter, 60);
50 TS_ASSERT_EQUALS(testMicro->getoctavesize(), 12);
51 TS_ASSERT_EQUALS(testMicro->Penabled, 0);
52 TS_ASSERT_EQUALS(testMicro->PAnote, 69);
53 TS_ASSERT_EQUALS(testMicro->PAfreq, 440.0f);
54 TS_ASSERT_EQUALS(testMicro->Pscaleshift, 64);
55 TS_ASSERT_EQUALS(testMicro->Pfirstkey, 0);
56 TS_ASSERT_EQUALS(testMicro->Plastkey, 127);
57 TS_ASSERT_EQUALS(testMicro->Pmiddlenote, 60);
58 TS_ASSERT_EQUALS(testMicro->Pmapsize, 12);
59 TS_ASSERT_EQUALS(testMicro->Pmappingenabled, 0);
60 TS_ASSERT_EQUALS(testMicro->Pglobalfinedetune, 64);
61
62 TS_ASSERT_EQUALS(string((const char *)testMicro->Pname), "12tET");
63 TS_ASSERT_EQUALS(string(
64 (const char *)testMicro->Pcomment),
65 "Equal Temperament 12 notes per octave");
66
67 for(int i = 0; i < 128; ++i)
68 TS_ASSERT_EQUALS(testMicro->Pmapping[i], i);
69
70 TS_ASSERT_DELTA(testMicro->getnotefreq(19, 0), 24.4997f, 0.0001f);
71 }
72
73 //Tests saving/loading to XML
74 void testXML() {
75 //Gah, the XMLwrapper is a twisted maze
76 testMicro->Penabled = 1;
77 XMLwrapper xml;
78 xml.beginbranch("Dummy"); //this should not be needed, but odd behavior
79 //seems to exist from MICROTONAL being on the
80 //top of the stack
81 xml.beginbranch("MICROTONAL");
82 testMicro->add2XML(&xml);
83 xml.endbranch();
84 xml.endbranch();
85
86 char *tmp = xml.getXMLdata();
87 Microtonal other;
88
89 other.Penabled = 1;
90 strcpy((char *)other.Pname, "Myname"); //will be nicer with strings
91
92 TS_ASSERT(*testMicro != other); //sanity check
93
94 TS_ASSERT(xml.enterbranch("Dummy"));
95 TS_ASSERT(xml.enterbranch("MICROTONAL"));
96
97 other.getfromXML(&xml);
98 xml.exitbranch();
99 xml.exitbranch();
100 char *tmpo = xml.getXMLdata();
101
102 TS_ASSERT(!strcmp(tmp, tmpo));
103 free(tmp);
104 free(tmpo);
105 }
106
107#if 0
109
110 //Test texttomapping TODO finish
111 void _testTextToMapping() {
112 //the mapping is from old documentation for "Intense Diatonic" scale
113 const char *mapping[12] =
114 {"0", "x", "1", "x", "2", "3", "x", "4", "x", "5", "x", "6"};
115 //for(int i=0;i<20;++i)
116 // cout << i << ':' << testMicro->getnotefreq(i,0) << endl;
117 //
118 // octave size == 7
119 // find dead notes
120 }
121 //Test texttotunings TODO finish
122 void _testTextToTunings() {
123 //the tuning is from old documentation for "Intense Diatonic" scale
124 const char *tuning[7] =
125 {"9/8", "5/4", "4/3", "3/2", "5/3", "15/8", "2/1"};
126 const int numTunings = 7;
127 //for(int i=0;i<20;++i)
128 // cout << i << ':' << testMicro->getnotefreq(i,0) << endl;
129 // go to middle key and verify the proportions
130 }
132#endif
133
134 private:
136};
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
SYNTH_T * synth
Definition MicrotonalTest.h:29
Definition Microtonal.h:37
unsigned char * Pname
Definition Microtonal.h:105
unsigned char Penabled
Definition Microtonal.h:57
void getfromXML(XMLwrapper *xml)
Definition Microtonal.cpp:602
Definition MicrotonalTest.h:34
void testXML()
Definition MicrotonalTest.h:74
Microtonal * testMicro
Definition MicrotonalTest.h:135
void setUp()
Definition MicrotonalTest.h:36
void testinit()
Definition MicrotonalTest.h:47
void tearDown()
Definition MicrotonalTest.h:41
register unsigned i
Definition inflate.c:1575
Definition juce_Uuid.h:141
Definition globals.h:204