commit e002b68022595ec5bd6d73bb5e8b832de3782410
parent a39dade5079c90e0a98ed980065df725a2e4d917
Author: fundamental <[email protected]>
Date: Sat, 16 Jan 2016 11:25:56 -0500
EffectMgr: Fix Multiple Calls to init()
When reinitializing Effects changes in effect id could be ignored
previously. Deleting old effects when reinitializing fixes this.
Diffstat:
3 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp
@@ -241,6 +241,7 @@ int EffectMgr::geteffect(void)
// Initialize An Effect in RT context
void EffectMgr::init(void)
{
+ kill();
changeeffectrt(nefx, true);
changepresetrt(preset, true);
for(int i=0; i<128; ++i)
diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt
@@ -20,6 +20,7 @@ CXXTEST_ADD_TEST(MqTest MqTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/MqTest.h)
#CXXTEST_ADD_TEST(RtAllocTest RtAllocTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/RtAllocTest.h)
CXXTEST_ADD_TEST(AllocatorTest AllocatorTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/AllocatorTest.h)
+CXXTEST_ADD_TEST(EffectTest EffectTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/EffectTest.h)
CXXTEST_ADD_TEST(KitTest KitTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/KitTest.h)
CXXTEST_ADD_TEST(MemoryStressTest MemoryStressTest.cpp
@@ -54,6 +55,7 @@ target_link_libraries(UnisonTest ${test_lib})
target_link_libraries(AllocatorTest ${test_lib})
target_link_libraries(KitTest ${test_lib})
target_link_libraries(MemoryStressTest ${test_lib})
+target_link_libraries(EffectTest ${test_lib})
#Testbed app
add_executable(ins-test InstrumentStats.cpp)
diff --git a/src/Tests/EffectTest.h b/src/Tests/EffectTest.h
@@ -0,0 +1,86 @@
+/*
+ ZynAddSubFX - a software synthesizer
+
+ EffectTest.h - CxxTest for General Effect Stuff
+ Copyright (C) 2015 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 <cstdio>
+#include "../Misc/Allocator.h"
+#include "../Misc/Stereo.h"
+#include "../Effects/EffectMgr.h"
+#include "../Effects/Reverb.h"
+#include "../Effects/Echo.h"
+#include "../globals.h"
+SYNTH_T *synth;
+
+class EchoTest:public CxxTest::TestSuite
+{
+ public:
+ void setUp() {
+ synth = new SYNTH_T;
+ alloc = new AllocatorClass;
+ mgr = new EffectMgr(*alloc, *synth, true);
+ }
+
+ void tearDown() {
+ delete mgr;
+ delete alloc;
+ delete synth;
+ }
+
+ void testInit() {
+ TS_ASSERT_EQUALS(mgr->nefx, 0);
+ mgr->changeeffect(1);
+ TS_ASSERT_EQUALS(mgr->nefx, 1);
+ TS_ASSERT_EQUALS(mgr->efx, nullptr);
+ mgr->init();
+ TS_ASSERT_DIFFERS(mgr->efx, nullptr);
+ }
+
+ void testClear() {
+ mgr->changeeffect(1);
+ mgr->init();
+ TS_ASSERT_DIFFERS(mgr->efx, nullptr);
+ mgr->changeeffect(0);
+ mgr->init();
+ TS_ASSERT_EQUALS(mgr->efx, nullptr);
+ }
+
+ void testSwap() {
+ //Initially the effect is NULL
+ TS_ASSERT_EQUALS(mgr->efx, nullptr);
+
+ //A Reverb is selected
+ mgr->changeeffect(1);
+ mgr->init();
+ TS_ASSERT_DIFFERS(dynamic_cast<Reverb*>(mgr->efx), nullptr);
+ TS_ASSERT_EQUALS(dynamic_cast<Echo*>(mgr->efx), nullptr);
+
+ //An Echo is selected
+ mgr->changeeffect(2);
+ mgr->init();
+ TS_ASSERT_EQUALS(dynamic_cast<Reverb*>(mgr->efx), nullptr);
+ TS_ASSERT_DIFFERS(dynamic_cast<Echo*>(mgr->efx), nullptr);
+ }
+
+ private:
+ EffectMgr *mgr;
+ Allocator *alloc;
+ SYNTH_T *synth;
+};