diff --git a/source/backend/CarlaEngine.hpp b/source/backend/CarlaEngine.hpp index 678040a8c..72cc7bb8f 100644 --- a/source/backend/CarlaEngine.hpp +++ b/source/backend/CarlaEngine.hpp @@ -169,7 +169,7 @@ struct EngineControlEvent { */ struct EngineMidiEvent { uint8_t port; //!< Port offset (usually 0) - uint8_t data[3]; //!< MIDI data, without channel bit + uint8_t data[4]; //!< MIDI data, without channel bit uint8_t size; //!< Number of bytes used #ifndef CARLA_PROPER_CPP11_SUPPORT @@ -185,6 +185,7 @@ struct EngineMidiEvent { data[0] = 0; data[1] = 0; data[2] = 0; + data[3] = 0; size = 0; } }; diff --git a/source/backend/native/midi-sequencer.cpp b/source/backend/native/midi-sequencer.cpp index 64906411e..f42c204a7 100644 --- a/source/backend/native/midi-sequencer.cpp +++ b/source/backend/native/midi-sequencer.cpp @@ -20,7 +20,7 @@ #include "CarlaMutex.hpp" #include "RtList.hpp" -#define MAX_EVENT_DATA_SIZE 3 +#define MAX_EVENT_DATA_SIZE 4 #define MIN_PREALLOCATED_EVENT_COUNT 100 #define MAX_PREALLOCATED_EVENT_COUNT 1000 @@ -215,6 +215,8 @@ public: midiEvent.data[0] = rawMidiEvent->data[0]; midiEvent.data[1] = rawMidiEvent->data[1]; midiEvent.data[2] = rawMidiEvent->data[2]; + midiEvent.data[3] = rawMidiEvent->data[3]; + midiEvent.size = rawMidiEvent->size; writeMidiEvent(&midiEvent); } @@ -303,6 +305,8 @@ protected: rawMidiEvent.data[0] = midiEvent->data[0]; rawMidiEvent.data[1] = midiEvent->data[1]; rawMidiEvent.data[2] = midiEvent->data[2]; + rawMidiEvent.data[3] = midiEvent->data[3]; + rawMidiEvent.size = midiEvent->size; rawMidiEvent.time = timePos->frame + midiEvent->time; fInEvents.appendRT(rawMidiEvent); diff --git a/source/backend/native/midi-split.c b/source/backend/native/midi-split.c index 4add4bac0..956261c27 100644 --- a/source/backend/native/midi-split.c +++ b/source/backend/native/midi-split.c @@ -65,6 +65,8 @@ static void midiSplit_process(PluginHandle handle, float** inBuffer, float** out tmpEvent.data[0] = status; tmpEvent.data[1] = midiEvent->data[1]; tmpEvent.data[2] = midiEvent->data[2]; + tmpEvent.data[3] = midiEvent->data[3]; + tmpEvent.size = midiEvent->size; host->write_midi_event(host->handle, &tmpEvent); } diff --git a/source/backend/native/midi-transpose.c b/source/backend/native/midi-transpose.c index eac3269c7..38eba795a 100644 --- a/source/backend/native/midi-transpose.c +++ b/source/backend/native/midi-transpose.c @@ -123,6 +123,8 @@ static void midiTranspose_process(PluginHandle handle, float** inBuffer, float** tmpEvent.data[0] = midiEvent->data[0]; tmpEvent.data[1] = rnote; tmpEvent.data[2] = midiEvent->data[2]; + tmpEvent.data[3] = midiEvent->data[3]; + tmpEvent.size = midiEvent->size; host->write_midi_event(host->handle, &tmpEvent); } diff --git a/source/backend/native/zynaddsubfx.cpp b/source/backend/native/zynaddsubfx.cpp index 53a3a0a4f..6981d2998 100644 --- a/source/backend/native/zynaddsubfx.cpp +++ b/source/backend/native/zynaddsubfx.cpp @@ -58,15 +58,6 @@ public: kSampleRate(getSampleRate()) { _maybeInitPrograms(kMaster); - - // pre-run to create static data - { - const size_t bufSize = getBufferSize(); - float out[bufSize]; - carla_stdout("BEFORE %li %i", bufSize, kSampleRate); - //kMaster->GetAudioOutSamples(bufSize, kSampleRate, out, out); - carla_stdout("AFTER %li %i", bufSize, kSampleRate); - } } ~ZynAddSubFxPlugin() @@ -206,15 +197,13 @@ protected: void process(float**, float** const outBuffer, const uint32_t frames, const uint32_t midiEventCount, const MidiEvent* const midiEvents) { - //if (pthread_mutex_trylock(&kMaster->mutex) != 0) + if (pthread_mutex_trylock(&kMaster->mutex) != 0) { carla_zeroFloat(outBuffer[0], frames); carla_zeroFloat(outBuffer[1], frames); return; } - pthread_mutex_lock(&kMaster->mutex); - for (uint32_t i=0; i < midiEventCount; i++) { const MidiEvent* const midiEvent = &midiEvents[i]; @@ -349,11 +338,10 @@ public: if (! doSearch) return; - doSearch = false; pthread_mutex_lock(&master->mutex); -#if 0 + // refresh banks master->bank.rescanforbanks(); @@ -374,16 +362,36 @@ public: sPrograms.append(new ProgramInfo(i, instrument, insName.c_str())); } } -#endif + pthread_mutex_unlock(&master->mutex); } + static void _clearPrograms() + { + for (auto it = sPrograms.begin(); it.valid(); it.next()) + { + ProgramInfo* const programInfo(*it); + delete programInfo; + } + + sPrograms.clear(); + } + +private: CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ZynAddSubFxPlugin) }; int ZynAddSubFxPlugin::sInstanceCount = 0; NonRtList ZynAddSubFxPlugin::sPrograms; +struct ProgramsDestructor { + ProgramsDestructor() {} + ~ProgramsDestructor() + { + ZynAddSubFxPlugin::_clearPrograms(); + } +} programsDestructor; + // ----------------------------------------------------------------------- static const PluginDescriptor zynAddSubFxDesc = { diff --git a/source/backend/native/zynaddsubfx/CMakeLists.txt b/source/backend/native/zynaddsubfx/CMakeLists.txt index 7a913fd11..7ee11f207 100644 --- a/source/backend/native/zynaddsubfx/CMakeLists.txt +++ b/source/backend/native/zynaddsubfx/CMakeLists.txt @@ -303,9 +303,6 @@ add_subdirectory(Synth) add_subdirectory(Effects) add_subdirectory(Params) add_subdirectory(DSP) -if(CompileTests) - add_subdirectory(Tests) -endif(CompileTests) add_subdirectory(Nio) add_library(zynaddsubfx_core STATIC @@ -323,6 +320,10 @@ target_link_libraries(zynaddsubfx_core ${OS_LIBRARIES} pthread) +if(CompileTests) + add_subdirectory(Tests) +endif(CompileTests) + message(STATUS "using link directories: ${AUDIO_LIBRARY_DIRS} ${ZLIB_LIBRARY_DIRS} ${FFTW_LIBRARY_DIRS} ${MXML_LIBRARY_DIRS} ${FLTK_LIBRARY_DIRS}") diff --git a/source/backend/native/zynaddsubfx/Misc/Master.cpp b/source/backend/native/zynaddsubfx/Misc/Master.cpp index 2bb2fd212..91020d498 100644 --- a/source/backend/native/zynaddsubfx/Misc/Master.cpp +++ b/source/backend/native/zynaddsubfx/Misc/Master.cpp @@ -50,6 +50,10 @@ static Master* masterInstance = NULL; Master::Master() { swaplr = 0; + off = 0; + smps = 0; + bufl = new float[synth->buffersize]; + bufr = new float[synth->buffersize]; pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&vumutex, NULL); @@ -482,11 +486,6 @@ void Master::GetAudioOutSamples(size_t nsamples, float *outl, float *outr) { - static float *bufl = new float[synth->buffersize], - *bufr = new float[synth->buffersize]; - static off_t off = 0; - static size_t smps = 0; - off_t out_off = 0; //Fail when resampling rather than doing a poor job @@ -505,9 +504,8 @@ void Master::GetAudioOutSamples(size_t nsamples, //generate samples AudioOut(bufl, bufr); off = 0; - smps = synth->buffersize; - out_off += smps; + smps = synth->buffersize; } else { //use some samples memcpy(outl + out_off, bufl + off, sizeof(float) * nsamples); @@ -521,6 +519,9 @@ void Master::GetAudioOutSamples(size_t nsamples, Master::~Master() { + delete []bufl; + delete []bufr; + for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart) delete part[npart]; for(int nefx = 0; nefx < NUM_INS_EFX; ++nefx) diff --git a/source/backend/native/zynaddsubfx/Misc/Master.h b/source/backend/native/zynaddsubfx/Misc/Master.h index 4de2ea6f2..0de022b53 100644 --- a/source/backend/native/zynaddsubfx/Misc/Master.h +++ b/source/backend/native/zynaddsubfx/Misc/Master.h @@ -171,6 +171,12 @@ class Master float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS]; float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX]; int keyshift; + + //information relevent to generating plugin audio samples + float *bufl; + float *bufr; + off_t off; + size_t smps; }; #endif diff --git a/source/backend/native/zynaddsubfx/Misc/Stereo.cpp b/source/backend/native/zynaddsubfx/Misc/Stereo.cpp index f96a1dc07..ac2f31727 100644 --- a/source/backend/native/zynaddsubfx/Misc/Stereo.cpp +++ b/source/backend/native/zynaddsubfx/Misc/Stereo.cpp @@ -19,8 +19,6 @@ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "Stereo.h" - template Stereo::Stereo(const T &left, const T &right) :l(left), r(right) diff --git a/source/backend/native/zynaddsubfx/Tests/CMakeLists.txt b/source/backend/native/zynaddsubfx/Tests/CMakeLists.txt index a3e0054fa..ac75f25ed 100644 --- a/source/backend/native/zynaddsubfx/Tests/CMakeLists.txt +++ b/source/backend/native/zynaddsubfx/Tests/CMakeLists.txt @@ -12,6 +12,7 @@ CXXTEST_ADD_TEST(SUBnoteTest SubNoteTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/SubNote CXXTEST_ADD_TEST(OscilGenTest OscilGenTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/OscilGenTest.h) 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) #Extra libraries added to make test and full compilation use the same library #links for quirky compilers @@ -26,5 +27,7 @@ target_link_libraries(MicrotonalTest ${test_lib}) target_link_libraries(OscilGenTest ${test_lib}) target_link_libraries(XMLwrapperTest ${test_lib}) target_link_libraries(RandTest ${test_lib}) -target_link_libraries(PADnoteTest ${test_lib}) +target_link_libraries(PADnoteTest ${test_lib}) +target_link_libraries(PluginTest zynaddsubfx_core zynaddsubfx_nio + ${OS_LIBRARIES} ${AUDIO_LIBRARIES}) diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index e95075274..ba109d69e 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -1468,10 +1468,12 @@ public: fMidiEvents[fMidiEventCount].port = 0; fMidiEvents[fMidiEventCount].time = sampleAccurate ? startTime : time; + fMidiEvents[fMidiEventCount].size = 3; // FIXME fMidiEvents[fMidiEventCount].data[0] = status + channel; fMidiEvents[fMidiEventCount].data[1] = midiEvent.data[1]; fMidiEvents[fMidiEventCount].data[2] = midiEvent.data[2]; + fMidiEvents[fMidiEventCount].data[3] = midiEvent.data[3]; fMidiEventCount += 1;