commit 8ab9dcf1999ad351aad3b790a46a42824d509286
parent fce3eae6b1a7f7cfcbb0607d89278a4f7a969c9e
Author: fundamental <[email protected]>
Date: Sun, 17 May 2015 13:28:14 -0400
Add Middleware Test
Diffstat:
3 files changed, 162 insertions(+), 2 deletions(-)
diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp
@@ -431,6 +431,19 @@ class MiddleWareImpl
static constexpr const char* tmp_nam_prefix = "/tmp/zynaddsubfx_";
MiddleWare *parent;
+ //Detect if the name of the process is 'zynaddsubfx'
+ bool isPlugin()
+ {
+ std::string proc_file = "/proc/" + to_s(getpid()) + "/comm";
+ std::ifstream ifs(proc_file);
+ if(ifs.good()) {
+ std::string comm_name;
+ ifs >> comm_name;
+ return comm_name != "zynaddsubfx";
+ }
+ return false;
+ }
+
//! returns file name to where UDP port is saved
std::string get_tmp_nam() const
{
@@ -626,7 +639,7 @@ public:
[master,filename,this,npart](){
Part *p = new Part(*master->memory, synth, &master->microtonal, master->fft);
if(p->loadXMLinstrument(filename))
- fprintf(stderr, "Warning: failed to load part!\n");
+ fprintf(stderr, "Warning: failed to load part<%s>!\n", filename);
auto isLateLoad = [this,npart]{
return actual_load[npart] != pending_load[npart];
@@ -837,7 +850,7 @@ public:
};
MiddleWareImpl::MiddleWareImpl(MiddleWare *mw, SYNTH_T synth_, int prefered_port)
- :parent(mw), synth(synth_)
+ :parent(mw), synth(synth_), ui(0)
{
bToU = new rtosc::ThreadLink(4096*2,1024);
uToB = new rtosc::ThreadLink(4096*2,1024);
@@ -851,6 +864,10 @@ MiddleWareImpl::MiddleWareImpl(MiddleWare *mw, SYNTH_T synth_, int prefered_port
#ifndef PLUGINVERSION
clean_up_tmp_nams();
create_tmp_file((unsigned)lo_server_get_port(server));
+ if(!isPlugin()) {
+ clean_up_tmp_nams();
+ create_tmp_file((unsigned)lo_server_get_port(server));
+ }
#endif
//dummy callback for starters
@@ -897,6 +914,8 @@ MiddleWareImpl::~MiddleWareImpl(void)
warnMemoryLeaks();
+ lo_server_free(server);
+
delete master;
delete osc;
delete bToU;
diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt
@@ -13,6 +13,7 @@ CXXTEST_ADD_TEST(OscilGenTest OscilGenTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Oscil
CXXTEST_ADD_TEST(RandTest RandTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/RandTest.h)
CXXTEST_ADD_TEST(PADnoteTest PadNoteTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PadNoteTest.h)
CXXTEST_ADD_TEST(PluginTest PluginTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PluginTest.h)
+CXXTEST_ADD_TEST(MiddlewareTest MiddlewareTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/MiddlewareTest.h)
CXXTEST_ADD_TEST(UnisonTest UnisonTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UnisonTest.h)
#CXXTEST_ADD_TEST(RtAllocTest RtAllocTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/RtAllocTest.h)
CXXTEST_ADD_TEST(AllocatorTest AllocatorTest.cpp
@@ -35,6 +36,9 @@ target_link_libraries(PADnoteTest ${test_lib})
target_link_libraries(PluginTest zynaddsubfx_core zynaddsubfx_nio
zynaddsubfx_gui_bridge
${GUI_LIBRARIES} ${NIO_LIBRARIES} ${AUDIO_LIBRARIES})
+target_link_libraries(MiddlewareTest zynaddsubfx_core zynaddsubfx_nio
+ zynaddsubfx_gui_bridge
+ ${GUI_LIBRARIES} ${NIO_LIBRARIES} ${AUDIO_LIBRARIES})
target_link_libraries(UnisonTest ${test_lib})
#target_link_libraries(RtAllocTest ${test_lib})
target_link_libraries(AllocatorTest ${test_lib})
diff --git a/src/Tests/MiddlewareTest.h b/src/Tests/MiddlewareTest.h
@@ -0,0 +1,137 @@
+/*
+ ZynAddSubFX - a software synthesizer
+
+ PluginTest.h - CxxTest for embedding zyn
+ Copyright (C) 2013-2013 Mark McCurry
+ Authors: Mark McCurry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License
+ as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License (version 2 or later) for more details.
+
+ You should have received a copy of the GNU General Public License (version 2)
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+*/
+#include <cxxtest/TestSuite.h>
+#include <cmath>
+#include <cstdlib>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include "../Misc/MiddleWare.h"
+#include "../Misc/Master.h"
+#include "../Misc/PresetExtractor.h"
+#include "../Misc/PresetExtractor.cpp"
+#include "../Misc/Util.h"
+#include "../globals.h"
+#include "../UI/NSM.H"
+NSM_Client *nsm = 0;
+MiddleWare *middleware = 0;
+
+using namespace std;
+
+char *instance_name=(char*)"";
+
+class PluginTest:public CxxTest::TestSuite
+{
+ public:
+ void setUp() {
+ synth = new SYNTH_T;
+ synth->buffersize = 256;
+ synth->samplerate = 48000;
+ synth->alias();
+
+ outL = new float[1024];
+ for(int i = 0; i < synth->buffersize; ++i)
+ outL[i] = 0.0f;
+ outR = new float[1024];
+ for(int i = 0; i < synth->buffersize; ++i)
+ outR[i] = 0.0f;
+
+ //next the bad global variables that for some reason have not been properly placed in some
+ //initialization routine, but rather exist as cryptic oneliners in main.cpp:
+ denormalkillbuf = new float[synth->buffersize];
+ for(int i = 0; i < synth->buffersize; ++i)
+ denormalkillbuf[i] = 0;
+
+ for(int i = 0; i < 16; ++i) {
+ middleware[i] = new MiddleWare(*synth);
+ master[i] = middleware[i]->spawnMaster();
+ }
+ }
+
+ void tearDown() {
+ for(int i = 0; i < 16; ++i)
+ delete middleware[i];
+
+ delete[] outL;
+ delete[] outR;
+ delete[] denormalkillbuf;
+ delete synth;
+ }
+
+
+ void testInit() {
+
+ for(int x=0; x<100; ++x) {
+ for(int i=0; i<16; ++i) {
+ middleware[i]->tick();
+ master[i]->GetAudioOutSamples(rand()%1025,
+ synth->samplerate, outL, outR);
+ }
+ }
+ }
+
+ void testPanic()
+ {
+ master[0]->setController(0, 0x64, 0);
+ master[0]->noteOn(0,64,64);
+ master[0]->AudioOut(outL, outR);
+
+ float sum = 0.0f;
+ for(int i = 0; i < synth->buffersize; ++i)
+ sum += fabs(outL[i]);
+
+ TS_ASSERT_LESS_THAN(0.1f, sum);
+ }
+
+ string loadfile(string fname) const
+ {
+ std::ifstream t(fname.c_str());
+ std::string str((std::istreambuf_iterator<char>(t)),
+ std::istreambuf_iterator<char>());
+ return str;
+ }
+
+ void testLoad(void)
+ {
+ for(int i=0; i<16; ++i) {
+ middleware[i]->transmitMsg("/load-part", "is", 0, (string(SOURCE_DIR) + "/../../instruments/banks/Organ/0037-Church Organ 1.xiz").c_str());
+ middleware[i]->tick();
+ master[i]->GetAudioOutSamples(synth->buffersize, synth->samplerate, outL, outR);
+ middleware[i]->tick();
+ master[i]->GetAudioOutSamples(synth->buffersize, synth->samplerate, outL, outR);
+ middleware[i]->tick();
+ master[i]->GetAudioOutSamples(synth->buffersize, synth->samplerate, outL, outR);
+ middleware[i]->tick();
+ master[i]->GetAudioOutSamples(synth->buffersize, synth->samplerate, outL, outR);
+ middleware[i]->tick();
+ }
+ //const string fname = string(SOURCE_DIR) + "/../../instruments/banks/Organ/0037-Church Organ 1.xiz";
+ //const string fdata = loadfile(fname);
+ }
+
+
+ private:
+ SYNTH_T *synth;
+ float *outR, *outL;
+ MiddleWare *middleware[16];
+ Master *master[16];
+};