Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MicrotonalTest.h 4.7KB

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