commit e4a02e4bb94e2c19e9e495fe0be9c639bfa93a8d
parent 972bdaede37764d642f65655382b14d7b0fde0dd
Author: michiboo <[email protected]>
Date: Sat, 20 Jul 2019 16:14:57 +0300
failed trigger test
Diffstat:
2 files changed, 189 insertions(+), 0 deletions(-)
diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt
@@ -31,6 +31,8 @@ CXXTEST_ADD_TEST(KitTest KitTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/KitTest.h)
CXXTEST_ADD_TEST(MemoryStressTest MemoryStressTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MemoryStressTest.h)
+CXXTEST_ADD_TEST(TriggerTest TriggerTest.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/TriggerTest.h)
#Extra libraries added to make test and full compilation use the same library
#links for quirky compilers
@@ -49,6 +51,7 @@ target_link_libraries(RandTest ${test_lib})
target_link_libraries(PADnoteTest ${test_lib})
target_link_libraries(MqTest ${test_lib})
target_link_libraries(WatchTest ${test_lib})
+target_link_libraries(TriggerTest ${test_lib})
target_link_libraries(PluginTest zynaddsubfx_core zynaddsubfx_nio
zynaddsubfx_gui_bridge
${GUI_LIBRARIES} ${NIO_LIBRARIES} ${AUDIO_LIBRARIES})
diff --git a/src/Tests/TriggerTest.h b/src/Tests/TriggerTest.h
@@ -0,0 +1,186 @@
+/*
+ ZynAddSubFX - a software synthesizer
+
+ AdNoteTest.h - CxxTest for Synth/SUBnote
+ Copyright (C) 2009-2011 Mark McCurry
+ Author: Mark McCurry
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+*/
+
+//Based Upon AdNoteTest.h
+#include <cxxtest/TestSuite.h>
+#include <iostream>
+#include <fstream>
+#include <ctime>
+#include <string>
+#include "../Misc/Master.h"
+#include "../Misc/Allocator.h"
+#include "../Misc/Util.h"
+#include "../Misc/XMLwrapper.h"
+#include "../Synth/SUBnote.h"
+#include "../Params/SUBnoteParameters.h"
+#include "../Params/Presets.h"
+#include "../globals.h"
+#include <rtosc/thread-link.h>
+
+using namespace std;
+using namespace zyn;
+
+SYNTH_T *synth;
+
+class TriggerTest:public CxxTest::TestSuite
+{
+ public:
+
+ SUBnoteParameters *pars;
+ SUBnote *note;
+ Master *master;
+ AbsTime *time;
+ Controller *controller;
+ unsigned char testnote;
+ Alloc memory;
+ rtosc::ThreadLink *tr;
+ WatchManager *w;
+
+
+ float *outR, *outL;
+
+ void setUp() {
+ synth = new SYNTH_T;
+ // //First the sensible settings and variables that have to be set:
+ synth->buffersize = 256;
+ outL = new float[synth->buffersize];
+ for(int i = 0; i < synth->buffersize; ++i)
+ *(outL + i) = 0;
+ outR = new float[synth->buffersize];
+ for(int i = 0; i < synth->buffersize; ++i)
+ *(outR + i) = 0;
+
+ synth->buffersize = 64;
+ time = new AbsTime(*synth);
+
+ tr = new rtosc::ThreadLink(1024,3);
+ w = new WatchManager(tr);
+
+ //prepare the default settings
+ SUBnoteParameters *defaultPreset = new SUBnoteParameters(time);
+ XMLwrapper wrap;
+ wrap.loadXMLfile(string(SOURCE_DIR)
+ + string("/guitar-adnote.xmz"));
+ TS_ASSERT(wrap.enterbranch("MASTER"));
+ TS_ASSERT(wrap.enterbranch("PART", 1));
+ TS_ASSERT(wrap.enterbranch("INSTRUMENT"));
+ TS_ASSERT(wrap.enterbranch("INSTRUMENT_KIT"));
+ TS_ASSERT(wrap.enterbranch("INSTRUMENT_KIT_ITEM", 0));
+ TS_ASSERT(wrap.enterbranch("SUB_SYNTH_PARAMETERS"));
+ defaultPreset->getfromXML(wrap);
+
+ synth = new SYNTH_T;
+ synth->buffersize = 64;
+ controller = new Controller(*synth, time);
+
+ //lets go with.... 50! as a nice note
+ testnote = 50;
+ float freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
+
+
+ synth = new SYNTH_T;
+ synth->buffersize = 64;
+ SynthParams pars{memory, *controller, *synth, *time, freq, 120, 0, testnote / 12.0f, false, prng()};
+ note = new SUBnote(defaultPreset, pars, w);
+ this->pars = defaultPreset;
+ }
+
+ void tearDown() {
+ delete controller;
+ delete note;
+ delete [] outL;
+ delete [] outR;
+ delete time;
+ delete synth;
+ delete pars;
+ }
+
+ void testDefaults() {
+ //Note: if these tests fail it is due to the relationship between
+ //global.h::RND and SUBnote.cpp
+
+ int sampleCount = 0;
+
+//#define WRITE_OUTPUT
+
+#ifdef WRITE_OUTPUT
+ ofstream file("subnoteout", ios::out);
+#endif
+ note->noteout(outL, outR);
+#ifdef WRITE_OUTPUT
+ for(int i = 0; i < synth->buffersize; ++i)
+ file << outL[i] << std::endl;
+
+#endif
+ sampleCount += synth->buffersize;
+ note->releasekey();
+
+ TS_ASSERT(!tr->hasNext());
+ w->add_watch("noteout");
+
+ note->noteout(outL, outR);
+ sampleCount += synth->buffersize;
+ w->tick();
+ note->noteout(outL, outR);
+ sampleCount += synth->buffersize;
+ w->tick();
+ // TS_ASSERT(!tr->hasNext());
+
+ // w->add_watch("noteout1");
+ note->noteout(outL, outR);
+ sampleCount += synth->buffersize;
+ // w->tick();
+
+ note->noteout(outL, outR);
+ sampleCount += synth->buffersize;
+ w->tick();
+ TS_ASSERT(tr->hasNext());
+ TS_ASSERT(w->trigger_active("/part0/kit0/subpars/noteout"));
+
+ TS_ASSERT_EQUALS(string("noteout"), tr->read());
+
+ // TS_ASSERT(tr->hasNext());
+ // TS_ASSERT_EQUALS(string("noteout1"), tr->read());
+ // TS_ASSERT(!tr->hasNext());
+
+ while(!note->finished()) {
+ note->noteout(outL, outR);
+#ifdef WRITE_OUTPUT
+ for(int i = 0; i < synth->buffersize; ++i)
+ file << outL[i] << std::endl;
+
+#endif
+ sampleCount += synth->buffersize;
+ }
+#ifdef WRITE_OUTPUT
+ file.close();
+#endif
+ }
+
+#define OUTPUT_PROFILE
+#ifdef OUTPUT_PROFILE
+ void testSpeed() {
+
+
+ // const int samps = 15000;
+
+ // int t_on = clock(); // timer before calling func
+ // for(int i = 0; i < samps; ++i)
+ // note->noteout(outL, outR);
+ // int t_off = clock(); // timer when func returns
+
+ // printf("SubNoteTest: %f seconds for %d Samples to be generated.\n",
+ // (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
+ }
+#endif
+};