diff --git a/source/native-plugins/zynaddsubfx-synth.cpp b/source/native-plugins/zynaddsubfx-synth.cpp index 96e196f14..c89c63c1b 100644 --- a/source/native-plugins/zynaddsubfx-synth.cpp +++ b/source/native-plugins/zynaddsubfx-synth.cpp @@ -676,7 +676,6 @@ protected: fMiddleWare->updateResources(fMaster); _setMasterParameters(); - } // ------------------------------------------------------------------- @@ -752,11 +751,9 @@ private: void _initMaster() { fMiddleWare = new MiddleWare(fSynth); - fMaster = fMiddleWare->spawnMaster(); - - fMiddleWare->setIdleCallback(_idleCallback, this); fMiddleWare->setUiCallback(__uiCallback, this); - fMiddleWare->setMasterChangedCallback(_masterChangedCallback, this); + fMiddleWare->setIdleCallback(_idleCallback, this); + _masterChangedCallback(fMiddleWare->spawnMaster()); } void _setMasterParameters() @@ -803,6 +800,17 @@ private: fMiddleWare = nullptr; } + void _masterChangedCallback(Master* m) + { + fMaster = m; + fMaster->setMasterChangedCallback(__masterChangedCallback, this); + } + + static void __masterChangedCallback(void* ptr, Master* m) + { + ((ZynAddSubFxPlugin*)ptr)->_masterChangedCallback(m); + } + void _uiCallback(const char* const msg) { if (std::strncmp(msg, "/part", 5) != 0) @@ -853,19 +861,14 @@ private: } } - static void _idleCallback(void* ptr) - { - ((ZynAddSubFxPlugin*)ptr)->hostGiveIdle(); - } - static void __uiCallback(void* ptr, const char* msg) { ((ZynAddSubFxPlugin*)ptr)->_uiCallback(msg); } - static void _masterChangedCallback(void* ptr, Master* m) + static void _idleCallback(void* ptr) { - ((ZynAddSubFxPlugin*)ptr)->fMaster = m; + ((ZynAddSubFxPlugin*)ptr)->hostGiveIdle(); } // ------------------------------------------------------------------- diff --git a/source/native-plugins/zynaddsubfx/Misc/Master.cpp b/source/native-plugins/zynaddsubfx/Misc/Master.cpp index cc5be163c..06e6c1de0 100644 --- a/source/native-plugins/zynaddsubfx/Misc/Master.cpp +++ b/source/native-plugins/zynaddsubfx/Misc/Master.cpp @@ -332,6 +332,9 @@ Master::Master(const SYNTH_T &synth_) { fprintf(stderr, "MIDI- got an error '%s' -- '%s'\n",a,b); }; + + mastercb = 0; + mastercb_ptr = 0; } void Master::applyOscEvent(const char *msg) @@ -535,6 +538,12 @@ void Master::partonoff(int npart, int what) } } +void Master::setMasterChangedCallback(void(*cb)(void*,Master*), void *ptr) +{ + mastercb = cb; + mastercb_ptr = ptr; +} + #if 0 template struct def_skip @@ -617,6 +626,8 @@ void Master::AudioOut(float *outl, float *outr) Master *new_master = *(Master**)rtosc_argument(msg, 0).b.data; new_master->AudioOut(outl, outr); Nio::masterSwap(new_master); + if (mastercb) + mastercb(mastercb_ptr, new_master); bToU->write("/free", "sb", "Master", sizeof(Master*), &this_master); return; } diff --git a/source/native-plugins/zynaddsubfx/Misc/Master.h b/source/native-plugins/zynaddsubfx/Misc/Master.h index 8b8a0a12f..b2d743199 100644 --- a/source/native-plugins/zynaddsubfx/Misc/Master.h +++ b/source/native-plugins/zynaddsubfx/Misc/Master.h @@ -108,6 +108,9 @@ class Master void partonoff(int npart, int what); + //Set callback to run when master changes + void setMasterChangedCallback(void(*cb)(void*,Master*),void *ptr); + /**parts \todo see if this can be made to be dynamic*/ class Part * part[NUM_MIDI_PARTS]; @@ -178,6 +181,10 @@ class Master float *bufr; off_t off; size_t smps; + + //Callback When Master changes + void(*mastercb)(void*,Master*); + void* mastercb_ptr; }; #endif diff --git a/source/native-plugins/zynaddsubfx/Misc/MiddleWare.cpp b/source/native-plugins/zynaddsubfx/Misc/MiddleWare.cpp index c07cfd1de..fc2382f97 100644 --- a/source/native-plugins/zynaddsubfx/Misc/MiddleWare.cpp +++ b/source/native-plugins/zynaddsubfx/Misc/MiddleWare.cpp @@ -686,9 +686,6 @@ public: master = m; - if (mastercb) - mastercb(mastercb_ptr, m); - //Give it to the backend and wait for the old part to return for //deallocation uToB->write("/load-master", "b", sizeof(Master*), &m); @@ -815,10 +812,6 @@ public: void(*idle)(void*); void* idle_ptr; - //Callback When Master changes - void(*mastercb)(void*,Master*); - void* mastercb_ptr; - //General UI callback cb_t cb; //UI handle @@ -862,8 +855,6 @@ MiddleWareImpl::MiddleWareImpl(MiddleWare *mw, SYNTH_T synth_, int prefered_port cb = [](void*, const char*){}; idle = 0; idle_ptr = 0; - mastercb = 0; - mastercb_ptr = 0; the_bToU = bToU; master = new Master(synth); @@ -1312,12 +1303,6 @@ void MiddleWare::setIdleCallback(void(*cb)(void*), void *ptr) impl->idle_ptr = ptr; } -void MiddleWare::setMasterChangedCallback(void(*cb)(void*,Master*), void *ptr) -{ - impl->mastercb = cb; - impl->mastercb_ptr = ptr; -} - void MiddleWare::transmitMsg(const char *msg) { impl->handleMsg(msg); diff --git a/source/native-plugins/zynaddsubfx/Misc/MiddleWare.h b/source/native-plugins/zynaddsubfx/Misc/MiddleWare.h index 3744c1dd4..73739c5b5 100644 --- a/source/native-plugins/zynaddsubfx/Misc/MiddleWare.h +++ b/source/native-plugins/zynaddsubfx/Misc/MiddleWare.h @@ -19,8 +19,6 @@ class MiddleWare void setUiCallback(void(*cb)(void*,const char *),void *ui); //Set callback to run while busy void setIdleCallback(void(*cb)(void*),void *ptr); - //Set callback to run when master changed - void setMasterChangedCallback(void(*cb)(void*,Master*),void *ptr); //Handle events void tick(void); //Do A Readonly Operation (For Parameter Copy)