shithub: leaf

Download patch

ref: 53a6d7a024d9b38c86da84fe5fc43d3fc2753621
parent: 179138388fd1ca5562ed0b0ff822ed2da3d6114b
author: Matthew Wang <mjw7@princeton.edu>
date: Mon Aug 31 11:19:03 EDT 2020

remove the global leaf instance, a user declared instance of leaf must be passed into objects; update objects accordingly

--- a/TestPlugin/Source/MyTest.cpp
+++ b/TestPlugin/Source/MyTest.cpp
@@ -45,37 +45,39 @@
 float* bufIn;
 float* bufOut;
 
+LEAF leaf;
+
 #define MSIZE 2048000
 char memory[MSIZE];
 
 void    LEAFTest_init            (float sampleRate, int blockSize)
 {
-    LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
+    LEAF_init(&leaf, sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
     
-    tMBSaw_init(&bsaw);
-    tMBTriangle_init(&btri);
-    tMBPulse_init(&bpulse);
+    tMBSaw_init(&bsaw, &leaf);
+    tMBTriangle_init(&btri, &leaf);
+    tMBPulse_init(&bpulse, &leaf);
     
-    bufIn = (float*) leaf_alloc(sizeof(float) * 4096);
-    bufOut = (float*) leaf_alloc(sizeof(float) * 4096);
+    bufIn = (float*) leaf_alloc(&leaf, sizeof(float) * 4096);
+    bufOut = (float*) leaf_alloc(&leaf, sizeof(float) * 4096);
     
-    tDualPitchDetector_init(&detector, mtof(48), mtof(84));
+    tDualPitchDetector_init(&detector, mtof(48), mtof(84), &leaf);
     
-    tCompressor_init(&compressor);
+    tCompressor_init(&compressor, &leaf);
     
-    tSVF_init(&lp, SVFTypeLowpass, mtof(84) * 2.0f, 1.0f);
-    tSVF_init(&hp, SVFTypeHighpass, mtof(48) * 0.5f, 1.0f);
+    tSVF_init(&lp, SVFTypeLowpass, mtof(84) * 2.0f, 1.0f, &leaf);
+    tSVF_init(&hp, SVFTypeHighpass, mtof(48) * 0.5f, 1.0f, &leaf);
     
-    tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024);
+    tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024, &leaf);
     
-    tZeroCrossingCounter_init(&zc, 128);
-    tEnvelopeFollower_init(&ef, 0.02f, 0.9999f);
+    tZeroCrossingCounter_init(&zc, 128, &leaf);
+    tEnvelopeFollower_init(&ef, 0.02f, 0.9999f, &leaf);
     
-    tTriangle_init(&tri);
+    tTriangle_init(&tri, &leaf);
     tTriangle_setFreq(&tri, 100);
     
-    tBuffer_init(&samp, 5.0f * leaf.sampleRate);
-    tMBSampler_init(&sampler, &samp);
+    tBuffer_init(&samp, 5.0f * leaf.sampleRate, &leaf);
+    tMBSampler_init(&sampler, &samp, &leaf);
     
     tMBSampler_setMode(&sampler, PlayLoop);
     tMBSampler_setEnd(&sampler, samp->bufferLength);
@@ -191,13 +193,13 @@
 
 void leaf_pool_report(void)
 {
-    DBG(String(leaf_pool_get_used()) + " of  " + String(leaf_pool_get_size()));
+    DBG(String(leaf_pool_get_used(&leaf)) + " of  " + String(leaf_pool_get_size(&leaf)));
 }
 
 void leaf_pool_dump(void)
 {
-    float* buff = (float*)leaf_pool_get_pool();
-    unsigned long siz = leaf_pool_get_size();
+    float* buff = (float*)leaf_pool_get_pool(&leaf);
+    unsigned long siz = leaf_pool_get_size(&leaf);
     siz /= sizeof(float);
     for (int i = 0; i < siz; i++)
     {
@@ -212,7 +214,7 @@
     DBG("ALLOC BUFFER 1");
     int size = 50;
     float* buffer;
-    buffer = (float*) leaf_alloc(sizeof(float) * size);
+    buffer = (float*) leaf_alloc(&leaf, sizeof(float) * size);
     
     for (int i = 0; i < size; i++)
     {
@@ -225,7 +227,7 @@
     DBG("ALLOC BUFFER 2");
     size = 25;
     
-    buffer = (float*) leaf_alloc(sizeof(float) * size);
+    buffer = (float*) leaf_alloc(&leaf, sizeof(float) * size);
     
     leaf_pool_report();
     
@@ -233,7 +235,7 @@
     {
         buffer[i] = (float)(i*2);
     }
-    leaf_free((char*)buffer);
+    leaf_free(&leaf, (char*)buffer);
     
     leaf_pool_report();
     
@@ -240,7 +242,7 @@
     DBG("ALLOC BUFFER 3");
     size = 15;
     
-    buffer = (float*) leaf_alloc(sizeof(float) * size);
+    buffer = (float*) leaf_alloc(&leaf, sizeof(float) * size);
     
     for (int i = 0; i < size; i++)
     {
--- a/leaf/Inc/leaf-analysis.h
+++ b/leaf/Inc/leaf-analysis.h
@@ -38,7 +38,7 @@
      @brief Detects and returns the basic envelope of incoming audio data.
      @{
      
-     @fn void    tEnvelopeFollower_init          (tEnvelopeFollower* const follower, float attackThreshold, float decayCoeff)
+     @fn void    tEnvelopeFollower_init          (tEnvelopeFollower* const follower, float attackThreshold, float decayCoeff, LEAF* const leaf)
      @brief Initialize a tEnvelopeFollower to the default LEAF mempool.
      @param follower A pointer to the tEnvelopeFollower to be initialized.
      @param attackThreshold Amplitude threshold for determining an envelope onset. 0.0 to 1.0
@@ -74,6 +74,7 @@
     
     typedef struct _tEnvelopeFollower
     {
+        
         tMempool mempool;
         float y;
         float a_thresh;
@@ -83,7 +84,7 @@
     
     typedef _tEnvelopeFollower* tEnvelopeFollower;
     
-    void    tEnvelopeFollower_init          (tEnvelopeFollower* const follower, float attackThreshold, float decayCoefficient);
+    void    tEnvelopeFollower_init          (tEnvelopeFollower* const follower, float attackThreshold, float decayCoefficient, LEAF* const leaf);
     void    tEnvelopeFollower_initToPool    (tEnvelopeFollower* const follower, float attackThreshold, float decayCoefficient, tMempool* const mempool);
     void    tEnvelopeFollower_free          (tEnvelopeFollower* const follower);
     
@@ -97,7 +98,7 @@
      @brief Counts the amount of zero crossings within a window of the input audio data
      @{
      
-     @fn void    tZeroCrossingCounter_init         (tZeroCrossingCounter* const counter, int maxWindowSize)
+     @fn void    tZeroCrossingCounter_init         (tZeroCrossingCounter* const counter, int maxWindowSize, LEAF* const leaf)
      @brief Initialize a tZeroCrossingCounter to the default LEAF mempool.
      @param counter A pointer to the tZeroCrossingCounter to be initialized.
      @param maxWindowSize The max and initial size of the window.
@@ -126,7 +127,9 @@
      @} */
     
     /* Zero Crossing Detector */
-    typedef struct _tZeroCrossingCounter {
+    typedef struct _tZeroCrossingCounter
+    {
+        
         tMempool mempool;
         int count;
         int maxWindowSize;
@@ -140,7 +143,7 @@
     
     typedef _tZeroCrossingCounter* tZeroCrossingCounter;
     
-    void    tZeroCrossingCounter_init         (tZeroCrossingCounter* const, int maxWindowSize);
+    void    tZeroCrossingCounter_init         (tZeroCrossingCounter* const, int maxWindowSize, LEAF* const leaf);
     void    tZeroCrossingCounter_initToPool   (tZeroCrossingCounter* const, int maxWindowSize, tMempool* const mempool);
     void    tZeroCrossingCounter_free         (tZeroCrossingCounter* const);
     
@@ -155,7 +158,7 @@
      @brief
      @{
      
-     @fn void    tPowerFollower_init         (tPowerFollower* const, float factor)
+     @fn void    tPowerFollower_init         (tPowerFollower* const, float factor, LEAF* const leaf)
      @brief Initialize a tPowerFollower to the default LEAF mempool.
      @param
      
@@ -184,6 +187,7 @@
     /* PowerEnvelopeFollower */
     typedef struct _tPowerFollower
     {
+        
         tMempool mempool;
         float factor, oneminusfactor;
         float curr;
@@ -192,7 +196,7 @@
     
     typedef _tPowerFollower* tPowerFollower;
     
-    void    tPowerFollower_init         (tPowerFollower* const, float factor);
+    void    tPowerFollower_init         (tPowerFollower* const, float factor, LEAF* const leaf);
     void    tPowerFollower_initToPool   (tPowerFollower* const, float factor, tMempool* const);
     void    tPowerFollower_free         (tPowerFollower* const);
     
@@ -208,7 +212,7 @@
      @brief ENV~ from PD, modified for LEAF
      @{
      
-     @fn void    tEnvPD_init             (tEnvPD* const, int windowSize, int hopSize, int blockSize)
+     @fn void    tEnvPD_init             (tEnvPD* const, int windowSize, int hopSize, int blockSize, LEAF* const leaf)
      @brief Initialize a tEnvPD to the default LEAF mempool.
      @param
      
@@ -237,6 +241,7 @@
     
     typedef struct _tEnvPD
     {
+        
         tMempool mempool;
         float buf[ENV_WINDOW_SIZE + INITVSTAKEN];
         int x_phase;                    /* number of points since last output */
@@ -252,7 +257,7 @@
     
     typedef _tEnvPD* tEnvPD;
     
-    void    tEnvPD_init             (tEnvPD* const, int windowSize, int hopSize, int blockSize);
+    void    tEnvPD_init             (tEnvPD* const, int windowSize, int hopSize, int blockSize, LEAF* const leaf);
     void    tEnvPD_initToPool       (tEnvPD* const, int windowSize, int hopSize, int blockSize, tMempool* const);
     void    tEnvPD_free             (tEnvPD* const);
     
@@ -267,7 +272,7 @@
      @brief
      @{
      
-     @fn void    tAttackDetection_init           (tAttackDetection* const, int blocksize, int atk, int rel)
+     @fn void    tAttackDetection_init           (tAttackDetection* const, int blocksize, int atk, int rel, LEAF* const leaf)
      @brief Initialize a tAttackDetection to the default LEAF mempool.
      @param
      
@@ -312,6 +317,7 @@
     
     typedef struct _tAttackDetection
     {
+        
         tMempool mempool;
         
         float env;
@@ -335,7 +341,7 @@
     
     typedef _tAttackDetection* tAttackDetection;
     
-    void    tAttackDetection_init           (tAttackDetection* const, int blocksize, int atk, int rel);
+    void    tAttackDetection_init           (tAttackDetection* const, int blocksize, int atk, int rel, LEAF* const leaf);
     void    tAttackDetection_initToPool     (tAttackDetection* const, int blocksize, int atk, int rel, tMempool* const);
     void    tAttackDetection_free           (tAttackDetection* const);
     
@@ -354,7 +360,7 @@
      @brief Period detection algorithm from Katja Vetters http://www.katjaas.nl/helmholtz/helmholtz.html
      @{
      
-     @fn void    tSNAC_init          (tSNAC* const, int overlaparg)
+     @fn void    tSNAC_init          (tSNAC* const, int overlaparg, LEAF* const leaf)
      @brief Initialize a tSNAC to the default LEAF mempool.
      @param
      
@@ -400,6 +406,7 @@
     
     typedef struct _tSNAC
     {
+        
         tMempool mempool;
         
         float* inputbuf;
@@ -420,7 +427,7 @@
     
     typedef _tSNAC* tSNAC;
     
-    void    tSNAC_init          (tSNAC* const, int overlaparg);
+    void    tSNAC_init          (tSNAC* const, int overlaparg, LEAF* const leaf);
     void    tSNAC_initToPool    (tSNAC* const, int overlaparg, tMempool* const);
     void    tSNAC_free          (tSNAC* const);
     
@@ -443,7 +450,7 @@
     
     
     /*!
-     @fn void    tPeriodDetection_init               (tPeriodDetection* const, float* in, float* out, int bufSize, int frameSize)
+     @fn void    tPeriodDetection_init               (tPeriodDetection* const, float* in, float* out, int bufSize, int frameSize, LEAF* const leaf)
      @brief Initialize a tPeriodDetection to the default LEAF mempool.
      @param
      
@@ -494,6 +501,7 @@
     
     typedef struct _tPeriodDetection
     {
+        
         tMempool mempool;
         
         tEnvPD env;
@@ -531,7 +539,7 @@
     
     typedef _tPeriodDetection* tPeriodDetection;
     
-    void    tPeriodDetection_init               (tPeriodDetection* const, float* in, float* out, int bufSize, int frameSize);
+    void    tPeriodDetection_init               (tPeriodDetection* const, float* in, float* out, int bufSize, int frameSize, LEAF* const leaf);
     void    tPeriodDetection_initToPool         (tPeriodDetection* const, float* in, float* out, int bufSize, int frameSize, tMempool* const);
     void    tPeriodDetection_free               (tPeriodDetection* const);
     
@@ -549,6 +557,7 @@
     
     typedef struct _tZeroCrossingInfo
     {
+        
         tMempool mempool;
         
         float _before_crossing;
@@ -562,7 +571,7 @@
     
     typedef _tZeroCrossingInfo* tZeroCrossingInfo;
     
-    void    tZeroCrossingInfo_init  (tZeroCrossingInfo* const);
+    void    tZeroCrossingInfo_init  (tZeroCrossingInfo* const, LEAF* const leaf);
     void    tZeroCrossingInfo_initToPool    (tZeroCrossingInfo* const, tMempool* const);
     void    tZeroCrossingInfo_free  (tZeroCrossingInfo* const);
     
@@ -577,6 +586,7 @@
     
     typedef struct _tZeroCrossingCollector
     {
+        
         tMempool mempool;
         
         tZeroCrossingInfo* _info;
@@ -597,7 +607,7 @@
     
     typedef _tZeroCrossingCollector* tZeroCrossingCollector;
     
-    void    tZeroCrossingCollector_init  (tZeroCrossingCollector* const, int windowSize, float hysteresis);
+    void    tZeroCrossingCollector_init  (tZeroCrossingCollector* const, int windowSize, float hysteresis, LEAF* const leaf);
     void    tZeroCrossingCollector_initToPool    (tZeroCrossingCollector* const, int windowSize, float hysteresis, tMempool* const);
     void    tZeroCrossingCollector_free  (tZeroCrossingCollector* const);
     
@@ -621,6 +631,7 @@
     
     typedef struct _tBitset
     {
+        
         tMempool mempool;
         
         unsigned int _value_size;
@@ -631,7 +642,7 @@
     
     typedef _tBitset* tBitset;
     
-    void    tBitset_init    (tBitset* const bitset, int numBits);
+    void    tBitset_init    (tBitset* const bitset, int numBits, LEAF* const leaf);
     void    tBitset_initToPool  (tBitset* const bitset, int numBits, tMempool* const mempool);
     void    tBitset_free    (tBitset* const bitset);
     
@@ -649,6 +660,7 @@
     
     typedef struct _tBACF
     {
+        
         tMempool mempool;
         
         tBitset _bitset;
@@ -657,7 +669,7 @@
     
     typedef _tBACF* tBACF;
     
-    void    tBACF_init  (tBACF* const bacf, tBitset* const bitset);
+    void    tBACF_init  (tBACF* const bacf, tBitset* const bitset, LEAF* const leaf);
     void    tBACF_initToPool    (tBACF* const bacf, tBitset* const bitset, tMempool* const mempool);
     void    tBACF_free  (tBACF* const bacf);
     
@@ -672,7 +684,7 @@
      @brief
      @{
      
-     @fn void    tPeriodDetector_init    (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis)
+     @fn void    tPeriodDetector_init    (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis, LEAF* const leaf)
      @brief Initialize a tPeriodDetector to the default LEAF mempool.
      @param
      
@@ -734,6 +746,7 @@
     
     typedef struct _sub_collector
     {
+        
         tMempool mempool;
         
         float             _first_period;
@@ -756,6 +769,7 @@
 
     typedef struct _tPeriodDetector
     {
+        
         tMempool mempool;
         
         tZeroCrossingCollector          _zc;
@@ -778,7 +792,7 @@
     
     typedef _tPeriodDetector* tPeriodDetector;
     
-    void    tPeriodDetector_init    (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis);
+    void    tPeriodDetector_init    (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis, LEAF* const leaf);
     void    tPeriodDetector_initToPool  (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis, tMempool* const mempool);
     void    tPeriodDetector_free    (tPeriodDetector* const detector);
     
@@ -802,7 +816,7 @@
      @brief
      @{
      
-     @fn void    tPitchDetector_init (tPitchDetector* const detector, float lowestFreq, float highestFreq)
+     @fn void    tPitchDetector_init (tPitchDetector* const detector, float lowestFreq, float highestFreq, LEAF* const leaf)
      @brief Initialize a tPitchDetector to the default LEAF mempool.
      @param detector A pointer to the relevant tPitchDetector.
      @param lowestFreq
@@ -859,6 +873,7 @@
     
     typedef struct _tPitchDetector
     {
+        
         tMempool mempool;
         
         tPeriodDetector _pd;
@@ -869,7 +884,7 @@
     
     typedef _tPitchDetector* tPitchDetector;
     
-    void    tPitchDetector_init (tPitchDetector* const detector, float lowestFreq, float highestFreq);
+    void    tPitchDetector_init (tPitchDetector* const detector, float lowestFreq, float highestFreq, LEAF* const leaf);
     void    tPitchDetector_initToPool   (tPitchDetector* const detector, float lowestFreq, float highestFreq, tMempool* const mempool);
     void    tPitchDetector_free (tPitchDetector* const detector);
     
@@ -886,6 +901,7 @@
 
     typedef struct _tDualPitchDetector
     {
+        
         tMempool mempool;
         
         tPitchDetector _pd1;
@@ -899,7 +915,7 @@
     
     typedef _tDualPitchDetector* tDualPitchDetector;
     
-    void    tDualPitchDetector_init (tDualPitchDetector* const detector, float lowestFreq, float highestFreq);
+    void    tDualPitchDetector_init (tDualPitchDetector* const detector, float lowestFreq, float highestFreq, LEAF* const leaf);
     void    tDualPitchDetector_initToPool   (tDualPitchDetector* const detector, float lowestFreq, float highestFreq, tMempool* const mempool);
     void    tDualPitchDetector_free (tDualPitchDetector* const detector);
     
--- a/leaf/Inc/leaf-delay.h
+++ b/leaf/Inc/leaf-delay.h
@@ -34,7 +34,7 @@
      @brief Non-interpolating delay, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void        tDelay_init         (tDelay* const, uint32_t delay, uint32_t maxDelay)
+     @fn void        tDelay_init         (tDelay* const, uint32_t delay, uint32_t maxDelay, LEAF* const leaf)
      @brief
      @param
      
@@ -86,6 +86,7 @@
     
     typedef struct _tDelay
     {
+        
         tMempool mempool;
         
         float gain;
@@ -101,7 +102,7 @@
     
     typedef _tDelay* tDelay;
     
-    void        tDelay_init         (tDelay* const, uint32_t delay, uint32_t maxDelay);
+    void        tDelay_init         (tDelay* const, uint32_t delay, uint32_t maxDelay, LEAF* const leaf);
     void        tDelay_initToPool   (tDelay* const, uint32_t delay, uint32_t maxDelay, tMempool* const);
     void        tDelay_free         (tDelay* const);
     
@@ -123,7 +124,7 @@
      @brief Linearly-interpolating delay, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tLinearDelay_init        (tLinearDelay* const, float delay, uint32_t maxDelay)
+     @fn void    tLinearDelay_init        (tLinearDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf)
      @brief
      @param
      
@@ -183,6 +184,7 @@
     
     typedef struct _tLinearDelay
     {
+        
         tMempool mempool;
         
         float gain;
@@ -202,7 +204,7 @@
     
     typedef _tLinearDelay* tLinearDelay;
     
-    void    tLinearDelay_init        (tLinearDelay* const, float delay, uint32_t maxDelay);
+    void    tLinearDelay_init        (tLinearDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf);
     void    tLinearDelay_initToPool  (tLinearDelay* const, float delay, uint32_t maxDelay, tMempool* const);
     void    tLinearDelay_free        (tLinearDelay* const);
     
@@ -228,7 +230,7 @@
      @brief Hermite-interpolating delay, created by adapting STK linear delay with Hermite interpolation.
      @{
      
-     @fn void       tHermiteDelay_init             (tHermiteDelay* const dl, float delay, uint32_t maxDelay)
+     @fn void       tHermiteDelay_init             (tHermiteDelay* const dl, float delay, uint32_t maxDelay, LEAF* const leaf)
      @brief
      @param
      
@@ -296,6 +298,7 @@
     
     typedef struct _tHermiteDelay
     {
+        
         tMempool mempool;
         
         float gain;
@@ -314,7 +317,7 @@
     
     typedef _tHermiteDelay* tHermiteDelay;
     
-    void       tHermiteDelay_init             (tHermiteDelay* const dl, float delay, uint32_t maxDelay);
+    void       tHermiteDelay_init             (tHermiteDelay* const dl, float delay, uint32_t maxDelay, LEAF* const leaf);
     void    tHermiteDelay_initToPool      (tHermiteDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp);
     void     tHermiteDelay_free            (tHermiteDelay* const dl);
     
@@ -341,7 +344,7 @@
      @brief Allpass-interpolating delay, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tAllpassDelay_init        (tAllpassDelay* const, float delay, uint32_t maxDelay)
+     @fn void    tAllpassDelay_init        (tAllpassDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf)
      @brief
      @param
      
@@ -393,6 +396,7 @@
     
     typedef struct _tAllpassDelay
     {
+        
         tMempool mempool;
         
         float gain;
@@ -414,7 +418,7 @@
     
     typedef _tAllpassDelay* tAllpassDelay;
     
-    void    tAllpassDelay_init        (tAllpassDelay* const, float delay, uint32_t maxDelay);
+    void    tAllpassDelay_init        (tAllpassDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf);
     void    tAllpassDelay_initToPool  (tAllpassDelay* const, float delay, uint32_t maxDelay, tMempool* const);
     void    tAllpassDelay_free        (tAllpassDelay* const);
     
@@ -436,7 +440,7 @@
      @brief Linear interpolating delay with fixed read and write pointers, variable rate.
      @{
      
-     @fn void    tTapeDelay_init        (tTapeDelay* const, float delay, uint32_t maxDelay)
+     @fn void    tTapeDelay_init        (tTapeDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf)
      @brief
      @param
      
@@ -492,6 +496,7 @@
     
     typedef struct _tTapeDelay
     {
+        
         tMempool mempool;
         
         float gain;
@@ -511,7 +516,7 @@
     
     typedef _tTapeDelay* tTapeDelay;
     
-    void    tTapeDelay_init        (tTapeDelay* const, float delay, uint32_t maxDelay);
+    void    tTapeDelay_init        (tTapeDelay* const, float delay, uint32_t maxDelay, LEAF* const leaf);
     void    tTapeDelay_initToPool  (tTapeDelay* const, float delay, uint32_t maxDelay, tMempool* const);
     void    tTapeDelay_free        (tTapeDelay* const);
     
@@ -534,7 +539,7 @@
      @brief
      @{
      
-     @fn void    tRingBuffer_init     (tRingBuffer* const ring, int size)
+     @fn void    tRingBuffer_init     (tRingBuffer* const ring, int size, LEAF* const leaf)
      @brief
      @param
      
@@ -573,6 +578,7 @@
      @} */
     typedef struct _tRingBuffer
     {
+        
         tMempool mempool;
         
         float* buffer;
@@ -583,7 +589,7 @@
     
     typedef _tRingBuffer* tRingBuffer;
     
-    void    tRingBuffer_init     (tRingBuffer* const ring, int size);
+    void    tRingBuffer_init     (tRingBuffer* const ring, int size, LEAF* const leaf);
     void    tRingBuffer_initToPool   (tRingBuffer* const ring, int size, tMempool* const mempool);
     void    tRingBuffer_free     (tRingBuffer* const ring);
     
--- a/leaf/Inc/leaf-distortion.h
+++ b/leaf/Inc/leaf-distortion.h
@@ -35,7 +35,7 @@
      @brief
      @{
      
-     @fn void    tSampleReducer_init    (tSampleReducer* const)
+     @fn void    tSampleReducer_init    (tSampleReducer* const, LEAF* const leaf)
      @brief
      @param
      
@@ -59,6 +59,7 @@
     
     typedef struct _tSampleReducer
     {
+        
         tMempool mempool;
         float invRatio;
         float hold;
@@ -67,7 +68,7 @@
     
     typedef _tSampleReducer* tSampleReducer;
     
-    void    tSampleReducer_init    (tSampleReducer* const);
+    void    tSampleReducer_init    (tSampleReducer* const, LEAF* const leaf);
     void    tSampleReducer_initToPool   (tSampleReducer* const, tMempool* const);
     void    tSampleReducer_free    (tSampleReducer* const);
     
@@ -82,7 +83,7 @@
      @brief
      @{
      
-     @fn void    tOversampler_init           (tOversampler* const, int order, int extraQuality)
+     @fn void    tOversampler_init           (tOversampler* const, int order, int extraQuality, LEAF* const leaf)
      @brief
      @param
      
@@ -114,6 +115,7 @@
     
     typedef struct _tOversampler
     {
+        
         tMempool mempool;
         int ratio;
         float* pCoeffs;
@@ -125,7 +127,7 @@
     
     typedef _tOversampler* tOversampler;
     
-    void    tOversampler_init           (tOversampler* const, int order, int extraQuality);
+    void    tOversampler_init           (tOversampler* const, int order, int extraQuality, LEAF* const leaf);
     void    tOversampler_initToPool     (tOversampler* const, int order, int extraQuality, tMempool* const);
     void    tOversampler_free           (tOversampler* const);
     
@@ -142,7 +144,7 @@
      @brief
      @{
      
-     @fn void    tLockhartWavefolder_init    (tLockhartWavefolder* const)
+     @fn void    tLockhartWavefolder_init    (tLockhartWavefolder* const, LEAF* const leaf)
      @brief
      @param
      
@@ -162,6 +164,7 @@
     
     typedef struct _tLockhartWavefolder
     {
+        
         tMempool mempool;
         
         double Ln1;
@@ -193,7 +196,7 @@
     
     typedef _tLockhartWavefolder* tLockhartWavefolder;
     
-    void    tLockhartWavefolder_init    (tLockhartWavefolder* const);
+    void    tLockhartWavefolder_init    (tLockhartWavefolder* const, LEAF* const leaf);
     void    tLockhartWavefolder_initToPool   (tLockhartWavefolder* const, tMempool* const);
     void    tLockhartWavefolder_free    (tLockhartWavefolder* const);
     
@@ -207,7 +210,7 @@
      @brief
      @{
      
-     @fn void    tCrusher_init    (tCrusher* const)
+     @fn void    tCrusher_init    (tCrusher* const, LEAF* const leaf)
      @brief
      @param
      
@@ -243,6 +246,7 @@
     
     typedef struct _tCrusher
     {
+        
         tMempool mempool;
         
         float srr;
@@ -258,7 +262,7 @@
     
     typedef _tCrusher* tCrusher;
     
-    void    tCrusher_init    (tCrusher* const);
+    void    tCrusher_init    (tCrusher* const, LEAF* const leaf);
     void    tCrusher_initToPool   (tCrusher* const, tMempool* const);
     void    tCrusher_free    (tCrusher* const);
     
--- a/leaf/Inc/leaf-dynamics.h
+++ b/leaf/Inc/leaf-dynamics.h
@@ -37,7 +37,7 @@
      @brief
      @{
      
-     @fn void    tCompressor_init        (tCompressor* const)
+     @fn void    tCompressor_init        (tCompressor* const, LEAF* const leaf)
      @brief
      @param
      
@@ -57,6 +57,7 @@
    
     typedef struct _tCompressor
     {
+        
         tMempool mempool;
         
         float tauAttack, tauRelease;
@@ -70,7 +71,7 @@
     
     typedef _tCompressor* tCompressor;
     
-    void    tCompressor_init        (tCompressor* const);
+    void    tCompressor_init        (tCompressor* const, LEAF* const leaf);
     void    tCompressor_initToPool  (tCompressor* const, tMempool* const);
     void    tCompressor_free        (tCompressor* const);
     
@@ -84,7 +85,7 @@
      @detail An auto VCA that you put into a feedback circuit to make it stay at the same level. It can enforce level bidirectionally (amplifying and attenuating as needed) or just attenutating. The former option allows for infinite sustain strings, for example, while The latter option allows for decaying strings, which can never exceed a specific level.
      @{
      
-     @fn void tFeedbackLeveler_init (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode)
+     @fn void tFeedbackLeveler_init (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode, LEAF* const leaf)
      @brief
      @param
      
@@ -124,6 +125,7 @@
     
     typedef struct _tFeedbackLeveler
     {
+        
         tMempool mempool;
         float targetLevel;    // target power level
         float strength;        // how strongly level difference affects the VCA
@@ -135,7 +137,7 @@
     
     typedef _tFeedbackLeveler* tFeedbackLeveler;
     
-    void    tFeedbackLeveler_init           (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode);
+    void    tFeedbackLeveler_init           (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode, LEAF* const leaf);
     void    tFeedbackLeveler_initToPool     (tFeedbackLeveler* const, float targetLevel, float factor, float strength, int mode, tMempool* const);
     void    tFeedbackLeveler_free           (tFeedbackLeveler* const);
     
@@ -156,7 +158,7 @@
      @brief Threshold with hysteresis (like Max/MSP thresh~ object)
      @{
      
-     @fn void    tThreshold_init        (tThreshold* const, float low, float high)
+     @fn void    tThreshold_init        (tThreshold* const, float low, float high, LEAF* const leaf)
      @brief
      @param
      
@@ -184,6 +186,7 @@
 
     typedef struct _tThreshold
     {
+        
         tMempool mempool;
         float highThresh, lowThresh;
 		int currentValue;
@@ -191,7 +194,7 @@
 
     typedef _tThreshold* tThreshold;
 
-    void    tThreshold_init        (tThreshold* const, float low, float high);
+    void    tThreshold_init        (tThreshold* const, float low, float high, LEAF* const leaf);
     void    tThreshold_initToPool  (tThreshold* const, float low, float high, tMempool* const);
     void    tThreshold_free        (tThreshold* const);
 
--- a/leaf/Inc/leaf-effects.h
+++ b/leaf/Inc/leaf-effects.h
@@ -30,7 +30,7 @@
      @brief
      @{
      
-     @fn void    tTalkbox_init           (tTalkbox* const, int bufsize)
+     @fn void    tTalkbox_init           (tTalkbox* const, int bufsize, LEAF* const leaf)
      @brief
      @param
      
@@ -92,6 +92,7 @@
     
     typedef struct _tTalkbox
     {
+        
         tMempool mempool;
         
         float param[NUM_TALKBOX_PARAM];
@@ -120,7 +121,7 @@
     
     typedef _tTalkbox* tTalkbox;
     
-    void    tTalkbox_init           (tTalkbox* const, int bufsize);
+    void    tTalkbox_init           (tTalkbox* const, int bufsize, LEAF* const leaf);
     void    tTalkbox_initToPool     (tTalkbox* const, int bufsize, tMempool* const);
     void    tTalkbox_free           (tTalkbox* const);
     
@@ -146,7 +147,7 @@
      @brief
      @{
      
-     @fn void    tTalkboxFloat_init           (tTalkboxFloat* const, int bufsize)
+     @fn void    tTalkboxFloat_init           (tTalkboxFloat* const, int bufsize, LEAF* const leaf)
      @brief
      @param
      
@@ -206,6 +207,7 @@
 
     typedef struct _tTalkboxFloat
       {
+            
           tMempool mempool;
           
           float param[NUM_TALKBOX_PARAM];
@@ -233,7 +235,7 @@
 
       typedef _tTalkboxFloat* tTalkboxFloat;
 
-      void    tTalkboxFloat_init           (tTalkboxFloat* const, int bufsize);
+      void    tTalkboxFloat_init           (tTalkboxFloat* const, int bufsize, LEAF* const leaf);
       void    tTalkboxFloat_initToPool     (tTalkboxFloat* const, int bufsize, tMempool* const);
       void    tTalkboxFloat_free           (tTalkboxFloat* const);
 
@@ -257,7 +259,7 @@
      @brief
      @{
      
-     @fn void    tVocoder_init           (tVocoder* const)
+     @fn void    tVocoder_init           (tVocoder* const, LEAF* const leaf)
      @brief
      @param
      
@@ -288,6 +290,7 @@
     
     typedef struct _tVocoder
     {
+        
         tMempool mempool;
         
         float param[NUM_VOCODER_PARAM];
@@ -305,7 +308,7 @@
     
     typedef _tVocoder* tVocoder;
     
-    void    tVocoder_init           (tVocoder* const);
+    void    tVocoder_init           (tVocoder* const, LEAF* const leaf);
     void    tVocoder_initToPool     (tVocoder* const, tMempool* const);
     void    tVocoder_free           (tVocoder* const);
     
@@ -321,7 +324,7 @@
      @brief
      @{
      
-     @fn void    tRosenbergGlottalPulse_init           (tRosenbergGlottalPulse* const)
+     @fn void    tRosenbergGlottalPulse_init           (tRosenbergGlottalPulse* const, LEAF* const leaf)
      @brief
      @param
      
@@ -361,6 +364,7 @@
 
     typedef struct _tRosenbergGlottalPulse
     {
+        
         tMempool mempool;
         float phase;
         float openLength;
@@ -372,7 +376,7 @@
 
     typedef _tRosenbergGlottalPulse* tRosenbergGlottalPulse;
 
-    void    tRosenbergGlottalPulse_init           (tRosenbergGlottalPulse* const);
+    void    tRosenbergGlottalPulse_init           (tRosenbergGlottalPulse* const, LEAF* const leaf);
     void    tRosenbergGlottalPulse_initToPool     (tRosenbergGlottalPulse* const, tMempool* const);
     void    tRosenbergGlottalPulse_free           (tRosenbergGlottalPulse* const);
 
@@ -392,7 +396,7 @@
      @brief pitch shifting algorithm that underlies tRetune etc from Katja Vetters http://www.katjaas.nl/pitchshiftlowlatency/pitchshiftlowlatency.html
      @{
      
-     @fn void    tSOLAD_init             (tSOLAD* const)
+     @fn void    tSOLAD_init             (tSOLAD* const, LEAF* const leaf)
      @brief
      @param
      
@@ -435,6 +439,7 @@
     
     typedef struct _tSOLAD
     {
+        
         tMempool mempool;
         
         uint16_t timeindex;              // current reference time, write index
@@ -452,7 +457,7 @@
     
     typedef _tSOLAD* tSOLAD;
     
-    void    tSOLAD_init             (tSOLAD* const);
+    void    tSOLAD_init             (tSOLAD* const, LEAF* const leaf);
     void    tSOLAD_initToPool       (tSOLAD* const, tMempool* const);
     void    tSOLAD_free             (tSOLAD* const);
     
@@ -473,7 +478,7 @@
      @brief
      @{
      
-     @fn void    tPitchShift_init            (tPitchShift* const, tPeriodDetection* const, float* out, int bufSize)
+     @fn void    tPitchShift_init            (tPitchShift* const, tPeriodDetection* const, float* out, int bufSize, LEAF* const leaf)
      @brief
      @param
      
@@ -505,6 +510,7 @@
     
     typedef struct _tPitchShift
     {
+        
         tMempool mempool;
         
         tSOLAD sola;
@@ -527,7 +533,7 @@
     
     typedef _tPitchShift* tPitchShift;
     
-    void    tPitchShift_init            (tPitchShift* const, tPeriodDetection* const, float* out, int bufSize);
+    void    tPitchShift_init            (tPitchShift* const, tPeriodDetection* const, float* out, int bufSize, LEAF* const leaf);
     void    tPitchShift_initToPool      (tPitchShift* const, tPeriodDetection* const, float* out, int bufSize, tMempool* const);
     void    tPitchShift_free            (tPitchShift* const);
     
@@ -542,7 +548,7 @@
      @brief
      @{
      
-     @fn void    tRetune_init                (tRetune* const, int numVoices, int bufSize, int frameSize)
+     @fn void    tRetune_init                (tRetune* const, int numVoices, int bufSize, int frameSize, LEAF* const leaf)
      @brief
      @param
      
@@ -598,6 +604,7 @@
     
     typedef struct _tRetune
     {
+        
         tMempool mempool;
         
         tPeriodDetection pd;
@@ -624,7 +631,7 @@
     
     typedef _tRetune* tRetune;
     
-    void    tRetune_init                (tRetune* const, int numVoices, int bufSize, int frameSize);
+    void    tRetune_init                (tRetune* const, int numVoices, int bufSize, int frameSize, LEAF* const leaf);
     void    tRetune_initToPool          (tRetune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
     void    tRetune_free                (tRetune* const);
     
@@ -645,7 +652,7 @@
      @brief
      @{
      
-     @fn void    tAutotune_init                  (tAutotune* const, int numVoices, int bufSize, int frameSize)
+     @fn void    tAutotune_init                  (tAutotune* const, int numVoices, int bufSize, int frameSize, LEAF* const leaf)
      @brief
      @param
      
@@ -709,6 +716,7 @@
     
     typedef struct _tAutotune
     {
+        
         tMempool mempool;
         
         tPeriodDetection pd;
@@ -735,7 +743,7 @@
     
     typedef _tAutotune* tAutotune;
     
-    void    tAutotune_init                  (tAutotune* const, int numVoices, int bufSize, int frameSize);
+    void    tAutotune_init                  (tAutotune* const, int numVoices, int bufSize, int frameSize, LEAF* const leaf);
     void    tAutotune_initToPool            (tAutotune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
     void    tAutotune_free                  (tAutotune* const);
     
@@ -760,7 +768,7 @@
      @brief
      @{
      
-     @fn void    tFormantShifter_init            (tFormantShifter* const, int order)
+     @fn void    tFormantShifter_init            (tFormantShifter* const, int order, LEAF* const leaf)
      @brief
      @param
      
@@ -800,6 +808,7 @@
     
     typedef struct _tFormantShifter
     {
+        
         tMempool mempool;
         int ford;
         float falph;
@@ -829,7 +838,7 @@
     
     typedef _tFormantShifter* tFormantShifter;
     
-    void    tFormantShifter_init            (tFormantShifter* const, int order);
+    void    tFormantShifter_init            (tFormantShifter* const, int order, LEAF* const leaf);
     void    tFormantShifter_initToPool      (tFormantShifter* const, int order, tMempool* const);
     void    tFormantShifter_free            (tFormantShifter* const);
     
--- a/leaf/Inc/leaf-electrical.h
+++ b/leaf/Inc/leaf-electrical.h
@@ -34,7 +34,7 @@
      @brief
      @{
      
-     @fn void    tWDF_init                   (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR)
+     @fn void    tWDF_init                   (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, LEAF* const leaf)
      @brief
      @param
      
@@ -108,6 +108,7 @@
     typedef _tWDF* tWDF;
     struct _tWDF
     {
+        
         tMempool mempool;
         WDFComponentType type;
         float port_resistance_up;
@@ -134,7 +135,7 @@
     };
     
     //WDF Linear Components
-    void    tWDF_init                   (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR);
+    void    tWDF_init                   (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, LEAF* const leaf);
     void    tWDF_initToPool             (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, tMempool* const);
     void    tWDF_free                   (tWDF* const);
     
--- a/leaf/Inc/leaf-envelopes.h
+++ b/leaf/Inc/leaf-envelopes.h
@@ -40,7 +40,7 @@
      @brief Basic attack-decay envelope.
      @{
      
-     @fn void    tEnvelope_init          (tEnvelope* const, float attack, float decay, int loop)
+     @fn void    tEnvelope_init          (tEnvelope* const, float attack, float decay, int loop, LEAF* const leaf)
      @brief
      @param
      
@@ -76,6 +76,7 @@
     
     typedef struct _tEnvelope
     {
+        
         tMempool mempool;
         
         const float *exp_buff;
@@ -98,7 +99,7 @@
     
     typedef _tEnvelope* tEnvelope;
     
-    void    tEnvelope_init          (tEnvelope* const, float attack, float decay, int loop);
+    void    tEnvelope_init          (tEnvelope* const, float attack, float decay, int loop, LEAF* const leaf);
     void    tEnvelope_initToPool    (tEnvelope* const, float attack, float decay, int loop, tMempool* const);
     void    tEnvelope_free          (tEnvelope* const);
     
@@ -117,7 +118,7 @@
      @brief
      @{
      
-     @fn void    tExpSmooth_init         (tExpSmooth* const, float val, float factor)
+     @fn void    tExpSmooth_init         (tExpSmooth* const, float val, float factor, LEAF* const leaf)
      @brief
      @param
      
@@ -157,6 +158,7 @@
     
     typedef struct _tExpSmooth
     {
+        
         tMempool mempool;
         float factor, oneminusfactor;
         float curr,dest;
@@ -164,7 +166,7 @@
     
     typedef _tExpSmooth* tExpSmooth;
     
-    void    tExpSmooth_init         (tExpSmooth* const, float val, float factor);
+    void    tExpSmooth_init         (tExpSmooth* const, float val, float factor, LEAF* const leaf);
     void    tExpSmooth_initToPool   (tExpSmooth* const, float val, float factor, tMempool* const);
     void    tExpSmooth_free         (tExpSmooth* const);
     
@@ -186,7 +188,7 @@
      @brief
      @{
      
-     @fn void    tADSR_init    (tADSR* const adsrenv, float attack, float decay, float sustain, float release)
+     @fn void    tADSR_init    (tADSR* const adsrenv, float attack, float decay, float sustain, float release, LEAF* const leaf)
      @brief
      @param
      
@@ -235,6 +237,7 @@
     /* ADSR */
     typedef struct _tADSR
     {
+        
         tMempool mempool;
         
         const float *exp_buff;
@@ -256,7 +259,7 @@
     
     typedef _tADSR* tADSR;
     
-    void    tADSR_init    (tADSR* const adsrenv, float attack, float decay, float sustain, float release);
+    void    tADSR_init    (tADSR* const adsrenv, float attack, float decay, float sustain, float release, LEAF* const leaf);
     void    tADSR_initToPool    (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp);
     void    tADSR_free          (tADSR* const);
     
@@ -277,7 +280,7 @@
      @brief
      @{
      
-     @fn void    tADSR2_init          (tADSR2* const, float attack, float decay, float sustain, float release)
+     @fn void    tADSR2_init          (tADSR2* const, float attack, float decay, float sustain, float release, LEAF* const leaf)
      @brief
      @param
      
@@ -325,6 +328,7 @@
     
     typedef struct _tADSR2
     {
+        
         tMempool mempool;
         float sampleRateInMs;
         float attack;
@@ -348,7 +352,7 @@
     
     typedef _tADSR2* tADSR2;
     
-    void    tADSR2_init          (tADSR2* const, float attack, float decay, float sustain, float release);
+    void    tADSR2_init          (tADSR2* const, float attack, float decay, float sustain, float release, LEAF* const leaf);
     void    tADSR2_initToPool    (tADSR2* const, float attack, float decay, float sustain, float release, tMempool* const);
     void    tADSR2_free          (tADSR2* const);
     
@@ -370,7 +374,7 @@
      @brief
      @{
      
-     @fn void    tADSR3_init          (tADSR3* const, float attack, float decay, float sustain, float release)
+     @fn void    tADSR3_init          (tADSR3* const, float attack, float decay, float sustain, float release, LEAF* const leaf)
      @brief
      @param
      
@@ -427,6 +431,7 @@
     
     typedef struct _tADSR3
     {
+        
         tMempool mempool;
         float sampleRateInMs;
         int state;
@@ -453,7 +458,7 @@
     
     typedef _tADSR3* tADSR3;
     
-    void    tADSR3_init          (tADSR3* const, float attack, float decay, float sustain, float release);
+    void    tADSR3_init          (tADSR3* const, float attack, float decay, float sustain, float release, LEAF* const leaf);
     void    tADSR3_initToPool    (tADSR3* const, float attack, float decay, float sustain, float release, tMempool* const);
     void    tADSR3_free          (tADSR3* const);
     
@@ -474,7 +479,7 @@
      @brief
      @{
      
-     @fn void    tADSR4_init          (tADSR4* const, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize)
+     @fn void    tADSR4_init          (tADSR4* const, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize, LEAF* const leaf)
      @brief
      @param
      
@@ -526,6 +531,7 @@
     
     typedef struct _tADSR4
     {
+        
         tMempool mempool;
         const float *exp_buff;
         uint32_t buff_size;
@@ -546,7 +552,7 @@
     
     typedef _tADSR4* tADSR4;
     
-    void    tADSR4_init          (tADSR4* const, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize);
+    void    tADSR4_init          (tADSR4* const, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize, LEAF* const leaf);
     void    tADSR4_initToPool    (tADSR4* const, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize, tMempool* const);
     void    tADSR4_free          (tADSR4* const);
     
@@ -568,7 +574,7 @@
      @brief
      @{
      
-     @fn void    tRamp_init          (tRamp* const, float time, int samplesPerTick)
+     @fn void    tRamp_init          (tRamp* const, float time, int samplesPerTick, LEAF* const leaf)
      @brief
      @param
      
@@ -604,6 +610,7 @@
     
     typedef struct _tRamp
     {
+        
         tMempool mempool;
         float inc;
         float inv_sr_ms;
@@ -616,7 +623,7 @@
     
     typedef _tRamp* tRamp;
     
-    void    tRamp_init          (tRamp* const, float time, int samplesPerTick);
+    void    tRamp_init          (tRamp* const, float time, int samplesPerTick, LEAF* const leaf);
     void    tRamp_initToPool    (tRamp* const, float time, int samplesPerTick, tMempool* const);
     void    tRamp_free          (tRamp* const);
     
@@ -632,7 +639,7 @@
      @brief
      @{
      
-     @fn void    tRampUpDown_init          (tRampUpDown* const, float upTime, float downTime, int samplesPerTick)
+     @fn void    tRampUpDown_init          (tRampUpDown* const, float upTime, float downTime, int samplesPerTick, LEAF* const leaf)
      @brief
      @param
      
@@ -672,6 +679,7 @@
     
     typedef struct _tRampUpDown
     {
+        
         tMempool mempool;
         float upInc;
         float downInc;
@@ -685,7 +693,7 @@
     
     typedef _tRampUpDown* tRampUpDown;
     
-    void    tRampUpDown_init          (tRampUpDown* const, float upTime, float downTime, int samplesPerTick);
+    void    tRampUpDown_init          (tRampUpDown* const, float upTime, float downTime, int samplesPerTick, LEAF* const leaf);
     void    tRampUpDown_initToPool    (tRampUpDown* const, float upTime, float downTime, int samplesPerTick, tMempool* const);
     void    tRampUpDown_free          (tRampUpDown* const);
     
@@ -704,7 +712,7 @@
      @brief based on Max/MSP's slide~
      @{
      
-     @fn void    tSlide_init          (tSlide* const, float upSlide, float downSlide)
+     @fn void    tSlide_init          (tSlide* const, float upSlide, float downSlide, LEAF* const leaf)
      @brief
      @param
      
@@ -740,6 +748,7 @@
     
     typedef struct _tSlide
     {
+        
         tMempool mempool;
         float prevOut;
         float currentOut;
@@ -751,7 +760,7 @@
     
     typedef _tSlide* tSlide;
     
-    void    tSlide_init          (tSlide* const, float upSlide, float downSlide);
+    void    tSlide_init          (tSlide* const, float upSlide, float downSlide, LEAF* const leaf);
     void    tSlide_initToPool    (tSlide* const, float upSlide, float downSlide, tMempool* const);
     void    tSlide_free          (tSlide* const);
     
--- a/leaf/Inc/leaf-filters.h
+++ b/leaf/Inc/leaf-filters.h
@@ -36,7 +36,7 @@
      @brief Schroeder allpass. Comb-filter with feedforward and feedback.
      @{
      
-     @fn void    tAllpass_init           (tAllpass* const, float initDelay, uint32_t maxDelay)
+     @fn void    tAllpass_init           (tAllpass* const, float initDelay, uint32_t maxDelay, LEAF* const leaf)
      @brief
      @param
      
@@ -64,6 +64,7 @@
     
     typedef struct _tAllpass
     {
+        
         tMempool mempool;
         
         float gain;
@@ -75,7 +76,7 @@
     
     typedef _tAllpass* tAllpass;
     
-    void    tAllpass_init           (tAllpass* const, float initDelay, uint32_t maxDelay);
+    void    tAllpass_init           (tAllpass* const, float initDelay, uint32_t maxDelay, LEAF* const leaf);
     void    tAllpass_initToPool     (tAllpass* const, float initDelay, uint32_t maxDelay, tMempool* const);
     void    tAllpass_free           (tAllpass* const);
     
@@ -92,7 +93,7 @@
      @brief OnePole filter, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tOnePole_init           (tOnePole* const, float thePole)
+     @fn void    tOnePole_init           (tOnePole* const, float thePole, LEAF* const leaf)
      @brief
      @param
      
@@ -136,6 +137,7 @@
     
     typedef struct _tOnePole
     {
+        
         tMempool mempool;
         float gain;
         float a0,a1;
@@ -145,7 +147,7 @@
     
     typedef _tOnePole* tOnePole;
     
-    void    tOnePole_init           (tOnePole* const, float thePole);
+    void    tOnePole_init           (tOnePole* const, float thePole, LEAF* const leaf);
     void    tOnePole_initToPool     (tOnePole* const, float thePole, tMempool* const);
     void    tOnePole_free           (tOnePole* const);
     
@@ -165,7 +167,7 @@
      @brief TwoPole filter, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tTwoPole_init           (tTwoPole* const)
+     @fn void    tTwoPole_init           (tTwoPole* const, LEAF* const leaf)
      @brief
      @param
      
@@ -209,6 +211,7 @@
 
     typedef struct _tTwoPole
     {
+        
         tMempool mempool;
         
         float gain;
@@ -223,7 +226,7 @@
     
     typedef _tTwoPole* tTwoPole;
     
-    void    tTwoPole_init           (tTwoPole* const);
+    void    tTwoPole_init           (tTwoPole* const, LEAF* const leaf);
     void    tTwoPole_initToPool     (tTwoPole* const, tMempool* const);
     void    tTwoPole_free           (tTwoPole* const);
     
@@ -243,7 +246,7 @@
      @brief OneZero filter, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tOneZero_init           (tOneZero* const, float theZero)
+     @fn void    tOneZero_init           (tOneZero* const, float theZero, LEAF* const leaf)
      @brief
      @param
      
@@ -287,6 +290,7 @@
     
     typedef struct _tOneZero
     {
+        
         tMempool mempool;
         float gain;
         float b0,b1;
@@ -295,7 +299,7 @@
     
     typedef _tOneZero* tOneZero;
     
-    void    tOneZero_init           (tOneZero* const, float theZero);
+    void    tOneZero_init           (tOneZero* const, float theZero, LEAF* const leaf);
     void    tOneZero_initToPool     (tOneZero* const, float theZero, tMempool* const);
     void    tOneZero_free           (tOneZero* const);
     
@@ -315,7 +319,7 @@
      @brief TwoZero filter, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tTwoZero_init           (tTwoZero* const)
+     @fn void    tTwoZero_init           (tTwoZero* const, LEAF* const leaf)
      @brief
      @param
      
@@ -360,6 +364,7 @@
 
     typedef struct _tTwoZero
     {
+        
         tMempool mempool;
         
         float gain;
@@ -372,7 +377,7 @@
     
     typedef _tTwoZero* tTwoZero;
     
-    void    tTwoZero_init           (tTwoZero* const);
+    void    tTwoZero_init           (tTwoZero* const, LEAF* const leaf);
     void    tTwoZero_initToPool     (tTwoZero* const, tMempool* const);
     void    tTwoZero_free           (tTwoZero* const);
     
@@ -392,7 +397,7 @@
      @brief PoleZero filter, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tPoleZero_init              (tPoleZero* const)
+     @fn void    tPoleZero_init              (tPoleZero* const, LEAF* const leaf)
      @brief
      @param
      
@@ -442,6 +447,7 @@
     
     typedef struct _tPoleZero
     {
+        
         tMempool mempool;
         
         float gain;
@@ -453,7 +459,7 @@
     
     typedef _tPoleZero* tPoleZero;
     
-    void    tPoleZero_init              (tPoleZero* const);
+    void    tPoleZero_init              (tPoleZero* const, LEAF* const leaf);
     void    tPoleZero_initToPool        (tPoleZero* const, tMempool* const);
     void    tPoleZero_free              (tPoleZero* const);
     
@@ -474,7 +480,7 @@
      @brief BiQuad filter, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tBiQuad_init           (tBiQuad* const)
+     @fn void    tBiQuad_init           (tBiQuad* const, LEAF* const leaf)
      @brief
      @param
      
@@ -532,6 +538,7 @@
     
     typedef struct _tBiQuad
     {
+        
         tMempool mempool;
         
         float gain;
@@ -547,7 +554,7 @@
     
     typedef _tBiQuad* tBiQuad;
     
-    void    tBiQuad_init           (tBiQuad* const);
+    void    tBiQuad_init           (tBiQuad* const, LEAF* const leaf);
     void    tBiQuad_initToPool     (tBiQuad* const, tMempool* const);
     void    tBiQuad_free           (tBiQuad* const);
     
@@ -570,7 +577,7 @@
      @brief State Variable Filter, algorithm from Andy Simper.
      @{
      
-     @fn void    tSVF_init           (tSVF* const, SVFType type, float freq, float Q)
+     @fn void    tSVF_init           (tSVF* const, SVFType type, float freq, float Q, LEAF* const leaf)
      @brief
      @param
      
@@ -613,6 +620,7 @@
     
     typedef struct _tSVF
     {
+        
         tMempool mempool;
         SVFType type;
         float cutoff, Q;
@@ -622,7 +630,7 @@
     
     typedef _tSVF* tSVF;
     
-    void    tSVF_init           (tSVF* const, SVFType type, float freq, float Q);
+    void    tSVF_init           (tSVF* const, SVFType type, float freq, float Q, LEAF* const leaf);
     void    tSVF_initToPool     (tSVF* const, SVFType type, float freq, float Q, tMempool* const);
     void    tSVF_free           (tSVF* const);
     
@@ -639,7 +647,7 @@
      @brief Efficient State Variable Filter for 14-bit control input, [0, 4096).
      @{
      
-     @fn void    tEfficientSVF_init          (tEfficientSVF* const, SVFType type, uint16_t input, float Q)
+     @fn void    tEfficientSVF_init          (tEfficientSVF* const, SVFType type, uint16_t input, float Q, LEAF* const leaf)
      @brief
      @param
      
@@ -667,6 +675,7 @@
     
     typedef struct _tEfficientSVF
     {
+        
         tMempool mempool;
         SVFType type;
         float cutoff, Q;
@@ -676,7 +685,7 @@
     
     typedef _tEfficientSVF* tEfficientSVF;
     
-    void    tEfficientSVF_init          (tEfficientSVF* const, SVFType type, uint16_t input, float Q);
+    void    tEfficientSVF_init          (tEfficientSVF* const, SVFType type, uint16_t input, float Q, LEAF* const leaf);
     void    tEfficientSVF_initToPool    (tEfficientSVF* const, SVFType type, uint16_t input, float Q, tMempool* const);
     void    tEfficientSVF_free          (tEfficientSVF* const);
     
@@ -692,7 +701,7 @@
      @brief Simple Highpass filter.
      @{
      
-     @fn void    tHighpass_init          (tHighpass* const, float freq)
+     @fn void    tHighpass_init          (tHighpass* const, float freq, LEAF* const leaf)
      @brief
      @param
      
@@ -720,6 +729,7 @@
     
     typedef struct _tHighpass
     {
+        
         tMempool mempool;
         float xs, ys, R;
         float frequency;
@@ -727,7 +737,7 @@
     
     typedef _tHighpass* tHighpass;
     
-    void    tHighpass_init          (tHighpass* const, float freq);
+    void    tHighpass_init          (tHighpass* const, float freq, LEAF* const leaf);
     void    tHighpass_initToPool    (tHighpass* const, float freq, tMempool* const);
     void    tHighpass_free          (tHighpass* const);
     
@@ -743,7 +753,7 @@
      @brief
      @{
      
-     @fn void    tButterworth_init           (tButterworth* const, int N, float f1, float f2)
+     @fn void    tButterworth_init           (tButterworth* const, int N, float f1, float f2, LEAF* const leaf, LEAF* const leaf)
      @brief
      @param
      
@@ -776,6 +786,7 @@
 #define NUM_SVF_BW 16
     typedef struct _tButterworth
     {
+        
         tMempool mempool;
         
         float gain;
@@ -790,7 +801,7 @@
     
     typedef _tButterworth* tButterworth;
     
-    void    tButterworth_init           (tButterworth* const, int N, float f1, float f2);
+    void    tButterworth_init           (tButterworth* const, int N, float f1, float f2, LEAF* const leaf);
     void    tButterworth_initToPool     (tButterworth* const, int N, float f1, float f2, tMempool* const);
     void    tButterworth_free           (tButterworth* const);
     
@@ -807,7 +818,7 @@
      @brief
      @{
      
-     @fn void    tFIR_init           (tFIR* const, float* coeffs, int numTaps)
+     @fn void    tFIR_init           (tFIR* const, float* coeffs, int numTaps, LEAF* const leaf)
      @brief
      @param
      
@@ -827,6 +838,7 @@
     
     typedef struct _tFIR
     {
+        
         tMempool mempool;
         float* past;
         float* coeff;
@@ -835,7 +847,7 @@
     
     typedef _tFIR* tFIR;
     
-    void    tFIR_init           (tFIR* const, float* coeffs, int numTaps);
+    void    tFIR_init           (tFIR* const, float* coeffs, int numTaps, LEAF* const leaf);
     void    tFIR_initToPool     (tFIR* const, float* coeffs, int numTaps, tMempool* const);
     void    tFIR_free           (tFIR* const);
     
@@ -850,7 +862,7 @@
      @brief
      @{
      
-     @fn void    tMedianFilter_init           (tMedianFilter* const, int size)
+     @fn void    tMedianFilter_init           (tMedianFilter* const, int size, LEAF* const leaf)
      @brief
      @param
      
@@ -870,6 +882,7 @@
     
     typedef struct _tMedianFilter
     {
+        
         tMempool mempool;
         float* val;
         int* age;
@@ -882,7 +895,7 @@
     
     typedef _tMedianFilter* tMedianFilter;
     
-    void    tMedianFilter_init           (tMedianFilter* const, int size);
+    void    tMedianFilter_init           (tMedianFilter* const, int size, LEAF* const leaf);
     void    tMedianFilter_initToPool     (tMedianFilter* const, int size, tMempool* const);
     void    tMedianFilter_free           (tMedianFilter* const);
     
@@ -895,7 +908,7 @@
      @brief Vadim Zavalishin style from VA book (from implementation in RSlib posted to kvr forum)
      @{
      
-     @fn void    tVZFilter_init           (tVZFilter* const, VZFilterType type, float freq, float Q)
+     @fn void    tVZFilter_init           (tVZFilter* const, VZFilterType type, float freq, float Q, LEAF* const leaf)
      @brief
      @param
      
@@ -965,6 +978,7 @@
     
     typedef struct _tVZFilter
     {
+        
         tMempool mempool;
         
         VZFilterType type;
@@ -990,7 +1004,7 @@
     
     typedef _tVZFilter* tVZFilter;
     
-    void    tVZFilter_init           (tVZFilter* const, VZFilterType type, float freq, float Q);
+    void    tVZFilter_init           (tVZFilter* const, VZFilterType type, float freq, float Q, LEAF* const leaf);
     void    tVZFilter_initToPool     (tVZFilter* const, VZFilterType type, float freq, float Q, tMempool* const);
     void    tVZFilter_free           (tVZFilter* const);
     
@@ -1012,7 +1026,7 @@
      @brief
      @{
      
-     @fn void    tDiodeFilter_init           (tDiodeFilter* const, float freq, float Q)
+     @fn void    tDiodeFilter_init           (tDiodeFilter* const, float freq, float Q, LEAF* const leaf)
      @brief
      @param
      
@@ -1041,6 +1055,7 @@
     //diode ladder filter
     typedef struct _tDiodeFilter
     {
+        
         tMempool mempool;
         float f;
         float r;
@@ -1056,7 +1071,7 @@
     
     typedef _tDiodeFilter* tDiodeFilter;
     
-    void    tDiodeFilter_init           (tDiodeFilter* const, float freq, float Q);
+    void    tDiodeFilter_init           (tDiodeFilter* const, float freq, float Q, LEAF* const leaf);
     void    tDiodeFilter_initToPool     (tDiodeFilter* const, float freq, float Q, tMempool* const);
     void    tDiodeFilter_free           (tDiodeFilter* const);
     
--- a/leaf/Inc/leaf-global.h
+++ b/leaf/Inc/leaf-global.h
@@ -21,6 +21,7 @@
      * @ingroup leaf
      * @brief The struct of the global LEAF instance `leaf`. Contains global variables and settings.
      */
+    
     struct LEAF
     {
         ///@{ 
@@ -33,14 +34,11 @@
         tMempool mempool; //!< The default LEAF mempool object.
         _tMempool _internal_mempool;
         size_t header_size; //!< The size in bytes of memory region headers within mempools.
-        void (*errorCallback)(LEAFErrorType); //!< A pointer to the callback function for LEAF errors. Can be set by the user.
+        void (*errorCallback)(LEAF* const, LEAFErrorType); //!< A pointer to the callback function for LEAF errors. Can be set by the user.
         int     errorState[LEAFErrorNil]; //!< An array of flags that indicate which errors have occurred.
         
         ///@}
     };
-    typedef struct LEAF LEAF;
-    
-    extern LEAF leaf;
     
     //==============================================================================
     
--- a/leaf/Inc/leaf-instruments.h
+++ b/leaf/Inc/leaf-instruments.h
@@ -37,7 +37,7 @@
      @brief
      @{
      
-     @fn void    t808Cowbell_init            (t808Cowbell* const, int useStick)
+     @fn void    t808Cowbell_init            (t808Cowbell* const, int useStick, LEAF* const leaf)
      @brief
      @param
      
@@ -101,7 +101,7 @@
     
     typedef _t808Cowbell* t808Cowbell;
     
-    void    t808Cowbell_init            (t808Cowbell* const, int useStick);
+    void    t808Cowbell_init            (t808Cowbell* const, int useStick, LEAF* const leaf);
     void    t808Cowbell_initToPool      (t808Cowbell* const, int useStick, tMempool* const);
     void    t808Cowbell_free            (t808Cowbell* const);
     
@@ -122,7 +122,7 @@
      @brief
      @{
      
-     @fn void    t808Hihat_init                  (t808Hihat* const)
+     @fn void    t808Hihat_init                  (t808Hihat* const, LEAF* const leaf)
      @brief
      @param
      
@@ -186,6 +186,7 @@
     
     typedef struct _t808Hihat
     {
+        
         tMempool mempool;
         // 6 Square waves
         tSquare p[6];
@@ -206,7 +207,7 @@
     
     typedef _t808Hihat* t808Hihat;
     
-    void    t808Hihat_init                  (t808Hihat* const);
+    void    t808Hihat_init                  (t808Hihat* const, LEAF* const leaf);
     void    t808Hihat_initToPool            (t808Hihat* const, tMempool* const);
     void    t808Hihat_free                  (t808Hihat* const);
     
@@ -231,7 +232,7 @@
      @brief
      @{
      
-     @fn void    t808Snare_init                  (t808Snare* const)
+     @fn void    t808Snare_init                  (t808Snare* const, LEAF* const leaf)
      @brief
      @param
      
@@ -287,6 +288,7 @@
     
     typedef struct _t808Snare
     {
+        
         tMempool mempool;
         // Tone 1, Tone 2, Noise
         tTriangle tone[2]; // Tri (not yet antialiased or wavetabled)
@@ -311,7 +313,7 @@
     
     typedef _t808Snare* t808Snare;
     
-    void    t808Snare_init                  (t808Snare* const);
+    void    t808Snare_init                  (t808Snare* const, LEAF* const leaf);
     void    t808Snare_initToPool            (t808Snare* const, tMempool* const);
     void    t808Snare_free                  (t808Snare* const);
     
@@ -334,7 +336,7 @@
      @brief
      @{
      
-     @fn void    t808Kick_init               (t808Kick* const)
+     @fn void    t808Kick_init               (t808Kick* const, LEAF* const leaf)
      @brief
      @param
      
@@ -390,6 +392,7 @@
     
     typedef struct _t808Kick
     {
+        
         tMempool mempool;
         
         tCycle tone; // Tri
@@ -412,7 +415,7 @@
     
     typedef _t808Kick* t808Kick;
     
-    void    t808Kick_init               (t808Kick* const);
+    void    t808Kick_init               (t808Kick* const, LEAF* const leaf);
     void    t808Kick_initToPool         (t808Kick* const, tMempool* const);
     void    t808Kick_free               (t808Kick* const);
     
--- a/leaf/Inc/leaf-math.h
+++ b/leaf/Inc/leaf-math.h
@@ -118,9 +118,9 @@
     float       LEAF_frequencyToMidi(float f);
     
     void        LEAF_generate_sine     (float* buffer, int size);
-    void        LEAF_generate_sawtooth (float* buffer, float basefreq, int size);
-    void        LEAF_generate_triangle (float* buffer, float basefreq, int size);
-    void        LEAF_generate_square   (float* buffer, float basefreq, int size);
+    void        LEAF_generate_sawtooth (float* buffer, float basefreq, int size, LEAF* const leaf);
+    void        LEAF_generate_triangle (float* buffer, float basefreq, int size, LEAF* const leaf);
+    void        LEAF_generate_square   (float* buffer, float basefreq, int size, LEAF* const leaf);
     
     // dope af
     float       LEAF_chebyshevT(float in, int n);
@@ -160,11 +160,6 @@
     float fast_tanh2(float x);
     float fast_tanh3(float x);
     float fast_tanh4(float x);
-    
-    void LEAF_generate_sine(float* buffer, int size);
-    void LEAF_generate_sawtooth(float* buffer, float basefreq, int size);
-    void LEAF_generate_triangle(float* buffer, float basefreq, int size);
-    void LEAF_generate_square(float* buffer, float basefreq, int size);
 
     //0.001 base gives a good curve that goes from 1 to near zero
     //1000 gives a good curve from -1.0 to 0.0
--- a/leaf/Inc/leaf-mempool.h
+++ b/leaf/Inc/leaf-mempool.h
@@ -52,7 +52,7 @@
     
 #define MPOOL_ALIGN_SIZE (8)
     
-    //#define size_t unsigned long
+    typedef struct LEAF LEAF;
     
     typedef enum LEAFErrorType
     {
@@ -77,15 +77,17 @@
         size_t size;
     } mpool_node_t;
     
-    typedef struct _tMempool
+    typedef struct _tMempool _tMempool;
+    typedef _tMempool* tMempool;
+    struct _tMempool
     {
+        tMempool      mempool;
+        LEAF*         leaf;
         char*         mpool;       // start of the mpool
         size_t        usize;       // used size of the pool
         size_t        msize;       // max size of the pool
         mpool_node_t* head;        // first node of memory pool free list
-    } _tMempool;
-
-    typedef _tMempool* tMempool;
+    };
     
     //! Initialize a tMempool for a given memory location and size to the default LEAF mempool.
     /*!
@@ -93,7 +95,7 @@
      @param memory A pointer to the chunk of memory to be used as a mempool.
      @param size The size of the chunk of memory to be used as a mempool.
      */
-    void    tMempool_init           (tMempool* const pool, char* memory, size_t size);
+    void    tMempool_init           (tMempool* const pool, char* memory, size_t size, LEAF* const leaf);
     
     
     //! Free a tMempool from its mempool.
@@ -111,15 +113,7 @@
      @param poolTo A pointer to the tMempool to which a tMempool should be initialized.
      */
     void    tMempool_initToPool     (tMempool* const pool, char* memory, size_t size, tMempool* const poolTo);
-    
-    
-    //! Free a tMempool from a specified mempool.
-    /*!
-     @param pool A pointer to the tMempool to be freed from its mempool.
-     @param poolFrom A pointer to the tMempool from which a tMempool should be freed.
-     */
-    void    tMempool_freeFromPool   (tMempool* const pool, tMempool* const poolFrom);
-    
+
     /*!
      @} */
     
@@ -142,17 +136,17 @@
     size_t mpool_get_size(_tMempool* pool);
     size_t mpool_get_used(_tMempool* pool);
     
-    void leaf_pool_init(char* memory, size_t size);
+    void leaf_pool_init(LEAF* const leaf, char* memory, size_t size);
     
-    char* leaf_alloc(size_t size);
-    char* leaf_calloc(size_t size);
+    char* leaf_alloc(LEAF* const leaf, size_t size);
+    char* leaf_calloc(LEAF* const leaf, size_t size);
     
-    void leaf_free(char* ptr);
+    void leaf_free(LEAF* const leaf, char* ptr);
     
-    size_t leaf_pool_get_size(void);
-    size_t leaf_pool_get_used(void);
+    size_t leaf_pool_get_size(LEAF* const leaf);
+    size_t leaf_pool_get_used(LEAF* const leaf);
     
-    char* leaf_pool_get_pool(void);
+    char* leaf_pool_get_pool(LEAF* const leaf);
     
 #ifdef __cplusplus
 }
--- a/leaf/Inc/leaf-midi.h
+++ b/leaf/Inc/leaf-midi.h
@@ -38,7 +38,7 @@
      @brief A basic stack of integers with a fixed capacity of 128, used by tPoly to keep track of MIDI notes.
      @{
      
-     @fn void    tStack_init                 (tStack* const stack)
+     @fn void    tStack_init                 (tStack* const stack, LEAF* const leaf)
      @brief Initialize a tStack to the default LEAF mempool.
      @param stack A pointer to the tStack to be initialized.
      
@@ -107,6 +107,7 @@
 #define STACK_SIZE 128
     typedef struct _tStack
     {
+        
         tMempool mempool;
         int data[STACK_SIZE];
         uint16_t pos;
@@ -117,7 +118,7 @@
     
     typedef _tStack* tStack;
     
-    void    tStack_init                 (tStack* const stack);
+    void    tStack_init                 (tStack* const stack, LEAF* const leaf);
     void    tStack_initToPool           (tStack* const stack, tMempool* const pool);
     void    tStack_free                 (tStack* const stack);
     
@@ -138,7 +139,7 @@
      @brief An object for polyphonic handling.
      @{
      
-     @fn void    tPoly_init                  (tPoly* const poly, int maxNumVoices)
+     @fn void    tPoly_init                  (tPoly* const poly, int maxNumVoices, LEAF* const leaf)
      @brief Initialize a tPoly to the default LEAF mempool.
      @param poly A pointer to the tPoly to be initialized.
      @param maxNumVoices The maximum number of voices this tPoly can handle at once.
@@ -247,6 +248,7 @@
 
     typedef struct _tPoly
     {
+        
         tMempool mempool;
         
         tStack stack;
@@ -283,7 +285,7 @@
     
     typedef _tPoly* tPoly;
     
-    void    tPoly_init                  (tPoly* const poly, int maxNumVoices);
+    void    tPoly_init                  (tPoly* const poly, int maxNumVoices, LEAF* const leaf);
     void    tPoly_initToPool            (tPoly* const poly, int maxNumVoices, tMempool* const pool);
     void    tPoly_free                  (tPoly* const poly);
     
@@ -314,7 +316,7 @@
      @brief An object for polyphonic handling.
      @{
      
-     @fn void    tSimplePoly_init                  (tSimplePoly* const poly, int maxNumVoices)
+     @fn void    tSimplePoly_init                  (tSimplePoly* const poly, int maxNumVoices, LEAF* const leaf)
      @brief Initialize a tSimplePoly to the default LEAF mempool.
      @param poly A pointer to the tSimplePoly to be initialized.
      @param maxNumVoices The maximum number of voices this tSimplePoly can handle at once.
@@ -392,6 +394,7 @@
      @} */
     typedef struct _tSimplePoly
     {
+        
         tMempool mempool;
         
         tStack stack;
@@ -407,7 +410,7 @@
 
     typedef _tSimplePoly* tSimplePoly;
 
-    void    tSimplePoly_init                  (tSimplePoly* const poly, int maxNumVoices);
+    void    tSimplePoly_init                  (tSimplePoly* const poly, int maxNumVoices, LEAF* const leaf);
     void    tSimplePoly_initToPool            (tSimplePoly* const poly, int maxNumVoices, tMempool* const pool);
     void    tSimplePoly_free                  (tSimplePoly* const poly);
     
--- a/leaf/Inc/leaf-oscillators.h
+++ b/leaf/Inc/leaf-oscillators.h
@@ -34,7 +34,7 @@
      @brief A general wavetable oscillator.
      @{
 
-     @fn void    tTable_init         (tTable* const osc, float* table, int size)
+     @fn void    tTable_init         (tTable* const osc, float* table, int size, LEAF* const leaf)
      @brief Initialize a tTable to the default LEAF mempool.
      @param osc A pointer to the tTable to be initialized.
      @param table A pointer to the wave table data.
@@ -65,6 +65,7 @@
     
     typedef struct _tTable
     {
+        
         tMempool mempool;
         
         float* waveTable;
@@ -75,7 +76,7 @@
     
     typedef _tTable* tTable;
 
-     void    tTable_init(tTable* const osc, float* table, int size);
+     void    tTable_init(tTable* const osc, float* table, int size, LEAF* const leaf);
      void    tTable_initToPool(tTable* const osc, float* table, int size, tMempool* const mempool);
      void    tTable_free(tTable* const osc);
     
@@ -90,7 +91,7 @@
      @brief A cycle/sine waveform oscillator. Uses wavetable synthesis.
      @{
 
-     @fn void    tCycle_init         (tCycle* const osc)
+     @fn void    tCycle_init         (tCycle* const osc, LEAF* const leaf)
      @brief Initialize a tCycle to the default LEAF mempool.
      @param osc A pointer to the tCycle to be initialized.
      
@@ -118,6 +119,7 @@
     
     typedef struct _tCycle
     {
+        
         tMempool mempool;
         // Underlying phasor
         float phase;
@@ -126,7 +128,7 @@
     
     typedef _tCycle* tCycle;
     
-    void    tCycle_init         (tCycle* const osc);
+    void    tCycle_init         (tCycle* const osc, LEAF* const leaf);
     void    tCycle_initToPool   (tCycle* const osc, tMempool* const mempool);
     void    tCycle_free         (tCycle* const osc);
     
@@ -141,7 +143,7 @@
      @brief Anti-aliased Triangle waveform using wavetable interpolation. Wavetables constructed from sine components.
      @{
      
-     @fn void    tTriangle_init         (tTriangle* const osc)
+     @fn void    tTriangle_init         (tTriangle* const osc, LEAF* const leaf)
      @brief Initialize a tTriangle to the default LEAF mempool.
      @param osc A pointer to the tTriangle to be initialized.
      
@@ -168,6 +170,7 @@
 
     typedef struct _tTriangle
     {
+        
         tMempool mempool;
         // Underlying phasor
         float phase;
@@ -178,7 +181,7 @@
     
     typedef _tTriangle* tTriangle;
 
-    void    tTriangle_init          (tTriangle* const osc);
+    void    tTriangle_init          (tTriangle* const osc, LEAF* const leaf);
     void    tTriangle_initToPool    (tTriangle* const osc, tMempool* const mempool);
     void    tTriangle_free          (tTriangle* const osc);
     
@@ -194,7 +197,7 @@
      @brief Anti-aliased Square waveform using wavetable interpolation. Wavetables constructed from sine components.
      @{
      
-     @fn void    tSquare_init         (tSquare* const osc)
+     @fn void    tSquare_init         (tSquare* const osc, LEAF* const leaf)
      @brief Initialize a tSquare to the default LEAF mempool.
      @param osc A pointer to the tSquare to be initialized.
      
@@ -221,6 +224,7 @@
     
     typedef struct _tSquare
     {
+        
         tMempool mempool;
         // Underlying phasor
         float phase;
@@ -231,7 +235,7 @@
     
     typedef _tSquare* tSquare;
 
-    void    tSquare_init        (tSquare* const osc);
+    void    tSquare_init        (tSquare* const osc, LEAF* const leaf);
     void    tSquare_initToPool  (tSquare* const osc, tMempool* const);
     void    tSquare_free        (tSquare* const osc);
 
@@ -249,7 +253,7 @@
      @brief Anti-aliased Square waveform using wavetable interpolation. Wavetables constructed from sine components.
      @{
      
-     @fn void    tSawtooth_init         (tSawtooth* const osc)
+     @fn void    tSawtooth_init         (tSawtooth* const osc, LEAF* const leaf)
      @brief Initialize a tSawtooth to the default LEAF mempool.
      @param osc A pointer to the tSawtooth to be initialized.
      
@@ -276,6 +280,7 @@
     
     typedef struct _tSawtooth
     {
+        
         tMempool mempool;
         // Underlying phasor
         float phase;
@@ -286,7 +291,7 @@
     
     typedef _tSawtooth* tSawtooth;
 
-    void    tSawtooth_init          (tSawtooth* const osc);
+    void    tSawtooth_init          (tSawtooth* const osc, LEAF* const leaf);
     void    tSawtooth_initToPool    (tSawtooth* const osc, tMempool* const mempool);
     void    tSawtooth_free          (tSawtooth* const osc);
 
@@ -301,7 +306,7 @@
      @brief
      @{
      
-     @fn void    tTri_init          (tTri* const osc)
+     @fn void    tTri_init          (tTri* const osc, LEAF* const leaf)
      @brief
      @param
      
@@ -329,6 +334,7 @@
 
     typedef struct _tTri
     {
+        
         tMempool mempool;
         float phase;
         float inc,freq;
@@ -338,7 +344,7 @@
     
     typedef _tTri* tTri;
     
-    void    tTri_init          (tTri* const osc);
+    void    tTri_init          (tTri* const osc, LEAF* const leaf);
     void    tTri_initToPool    (tTri* const osc, tMempool* const mempool);
     void    tTri_free          (tTri* const osc);
     
@@ -354,7 +360,7 @@
      @brief
      @{
      
-     @fn void    tPulse_init        (tPulse* const osc)
+     @fn void    tPulse_init        (tPulse* const osc, LEAF* const leaf)
      @brief
      @param
      
@@ -382,6 +388,7 @@
     
     typedef struct _tPulse
     {
+        
         tMempool mempool;
         float phase;
         float inc,freq;
@@ -390,7 +397,7 @@
     
     typedef _tPulse* tPulse;
     
-    void    tPulse_init        (tPulse* const osc);
+    void    tPulse_init        (tPulse* const osc, LEAF* const leaf);
     void    tPulse_initToPool  (tPulse* const osc, tMempool* const);
     void    tPulse_free        (tPulse* const osc);
     
@@ -406,7 +413,7 @@
      @brief
      @{
      
-     @fn void    tSaw_init          (tSaw* const osc)
+     @fn void    tSaw_init          (tSaw* const osc, LEAF* const leaf)
      @brief
      @param
      
@@ -430,6 +437,7 @@
     
     typedef struct _tSaw
     {
+        
         tMempool mempool;
         float phase;
         float inc,freq;
@@ -437,7 +445,7 @@
     
     typedef _tSaw* tSaw;
     
-    void    tSaw_init          (tSaw* const osc);
+    void    tSaw_init          (tSaw* const osc, LEAF* const leaf);
     void    tSaw_initToPool    (tSaw* const osc, tMempool* const mempool);
     void    tSaw_free          (tSaw* const osc);
     
@@ -452,7 +460,7 @@
      @brief
      @{
      
-     @fn void    tPhasor_init        (tPhasor* const osc)
+     @fn void    tPhasor_init        (tPhasor* const osc, LEAF* const leaf)
      @brief
      @param
      
@@ -476,6 +484,7 @@
     
     typedef struct _tPhasor
     {
+        
         tMempool mempool;
         float phase;
         float inc,freq;
@@ -484,7 +493,7 @@
     
     typedef _tPhasor* tPhasor;
     
-    void    tPhasor_init        (tPhasor* const osc);
+    void    tPhasor_init        (tPhasor* const osc, LEAF* const leaf);
     void    tPhasor_initToPool  (tPhasor* const osc, tMempool* const);
     void    tPhasor_free        (tPhasor* const osc);
     
@@ -499,7 +508,7 @@
      @brief
      @{
      
-     @fn void    tNoise_init         (tNoise* const noise, NoiseType type)
+     @fn void    tNoise_init         (tNoise* const noise, NoiseType type, LEAF* const leaf)
      @brief
      @param
      
@@ -533,6 +542,7 @@
     
     typedef struct _tNoise
     {
+        
         tMempool mempool;
         NoiseType type;
         float pinkb0, pinkb1, pinkb2;
@@ -541,7 +551,7 @@
     
     typedef _tNoise* tNoise;
 
-    void    tNoise_init         (tNoise* const noise, NoiseType type);
+    void    tNoise_init         (tNoise* const noise, NoiseType type, LEAF* const leaf);
     void    tNoise_initToPool   (tNoise* const noise, NoiseType type, tMempool* const);
     void    tNoise_free         (tNoise* const noise);
     
@@ -555,7 +565,7 @@
      @brief A model of a neuron, adapted to act as an oscillator.
      @{
      
-     @fn void    tNeuron_init        (tNeuron* const neuron)
+     @fn void    tNeuron_init        (tNeuron* const neuron, LEAF* const leaf)
      @brief Initialize a tNeuron to the default LEAF mempool.
      @param neuron A pointer to the tNeuron to be initialized.
      
@@ -643,6 +653,7 @@
     
     typedef struct _tNeuron
     {
+        
         tMempool mempool;
         
         tPoleZero f;
@@ -662,7 +673,7 @@
     
     typedef _tNeuron* tNeuron;
     
-    void    tNeuron_init        (tNeuron* const neuron);
+    void    tNeuron_init        (tNeuron* const neuron, LEAF* const leaf);
     void    tNeuron_initToPool  (tNeuron* const neuron, tMempool* const mempool);
     void    tNeuron_free        (tNeuron* const neuron);
     
@@ -692,7 +703,7 @@
      @brief
      @{
      
-     @fn void tMBPulse_init(tMBPulse* const osc)
+     @fn void tMBPulse_init(tMBPulse* const osc, LEAF* const leaf)
      @brief
      @param
      
@@ -728,6 +739,7 @@
     
     typedef struct _tMBPulse
     {
+        
         tMempool mempool;
         float    out;
         float    amp;
@@ -744,7 +756,7 @@
     
     typedef _tMBPulse* tMBPulse;
     
-    void tMBPulse_init(tMBPulse* const osc);
+    void tMBPulse_init(tMBPulse* const osc, LEAF* const leaf);
     void tMBPulse_initToPool(tMBPulse* const osc, tMempool* const mempool);
     void tMBPulse_free(tMBPulse* const osc);
     
@@ -760,7 +772,7 @@
      @brief
      @{
      
-     @fn void tMBTriangle_init(tMBTriangle* const osc)
+     @fn void tMBTriangle_init(tMBTriangle* const osc, LEAF* const leaf)
      @brief
      @param
      
@@ -796,6 +808,7 @@
     
     typedef struct _tMBTriangle
     {
+        
         tMempool mempool;
         float    out;
         float    amp;
@@ -812,7 +825,7 @@
     
     typedef _tMBTriangle* tMBTriangle;
     
-    void tMBTriangle_init(tMBTriangle* const osc);
+    void tMBTriangle_init(tMBTriangle* const osc, LEAF* const leaf);
     void tMBTriangle_initToPool(tMBTriangle* const osc, tMempool* const mempool);
     void tMBTriangle_free(tMBTriangle* const osc);
     
@@ -829,7 +842,7 @@
      @brief
      @{
      
-     @fn void tMBSaw_init(tMBSaw* const osc)
+     @fn void tMBSaw_init(tMBSaw* const osc, LEAF* const leaf)
      @brief
      @param
      
@@ -861,6 +874,7 @@
     
     typedef struct _tMBSaw
     {
+        
         tMempool mempool;
         float    out;
         float    amp;
@@ -876,7 +890,7 @@
     
     typedef _tMBSaw* tMBSaw;
     
-    void tMBSaw_init(tMBSaw* const osc);
+    void tMBSaw_init(tMBSaw* const osc, LEAF* const leaf);
     void tMBSaw_initToPool(tMBSaw* const osc, tMempool* const mempool);
     void tMBSaw_free(tMBSaw* const osc);
     
--- a/leaf/Inc/leaf-physical.h
+++ b/leaf/Inc/leaf-physical.h
@@ -42,7 +42,7 @@
      @brief Karplus-Strong model
      @{
      
-     @fn void    tPluck_init          (tPluck* const, float lowestFrequency)
+     @fn void    tPluck_init          (tPluck* const, float lowestFrequency, LEAF* const leaf)
      @brief
      @param
      
@@ -86,6 +86,7 @@
     
     typedef struct _tPluck
     {
+        
         tMempool mempool;
         
         tAllpassDelay     delayLine; // Allpass or Linear??  big difference...
@@ -102,7 +103,7 @@
     
     typedef _tPluck* tPluck;
     
-    void    tPluck_init          (tPluck* const, float lowestFrequency); //float delayBuff[DELAY_LENGTH]);
+    void    tPluck_init          (tPluck* const, float lowestFrequency, LEAF* const leaf); //float delayBuff[DELAY_LENGTH]);
     void    tPluck_initToPool    (tPluck* const, float lowestFrequency, tMempool* const);
     void    tPluck_free          (tPluck* const);
     
@@ -122,7 +123,7 @@
      @brief Stiff Karplus-Strong model
      @{
      
-     @fn void    tKarplusStrong_init               (tKarplusStrong* const, float lowestFrequency)
+     @fn void    tKarplusStrong_init               (tKarplusStrong* const, float lowestFrequency, LEAF* const leaf)
      @brief
      @param
      
@@ -186,6 +187,7 @@
     
     typedef struct _tKarplusStrong
     {
+        
         tMempool mempool;
         
         tAllpassDelay  delayLine;
@@ -208,7 +210,7 @@
     
     typedef _tKarplusStrong* tKarplusStrong;
     
-    void    tKarplusStrong_init               (tKarplusStrong* const, float lowestFrequency); // float delayBuff[2][DELAY_LENGTH]);
+    void    tKarplusStrong_init               (tKarplusStrong* const, float lowestFrequency, LEAF* const leaf); // float delayBuff[2][DELAY_LENGTH]);
     void    tKarplusStrong_initToPool         (tKarplusStrong* const, float lowestFrequency, tMempool* const);
     void    tKarplusStrong_free               (tKarplusStrong* const);
     
@@ -231,7 +233,7 @@
      @brief
      @{
      
-     @fn void    tSimpleLivingString_init   (tSimpleLivingString* const, float freq, float dampFreq, float decay, float targetLev, float levSmoothFactor, float levStrength, int levMode)
+     @fn void    tSimpleLivingString_init   (tSimpleLivingString* const, float freq, float dampFreq, float decay, float targetLev, float levSmoothFactor, float levStrength, int levMode, LEAF* const leaf)
      @brief
      @param
      
@@ -287,6 +289,7 @@
     
     typedef struct _tSimpleLivingString
     {
+        
         tMempool mempool;
         float freq, waveLengthInSamples;        // the frequency of the string, determining delay length
         float dampFreq;    // frequency for the bridge LP filter, in Hz
@@ -304,7 +307,7 @@
     
     void    tSimpleLivingString_init                (tSimpleLivingString* const, float freq, float dampFreq,
                                                      float decay, float targetLev, float levSmoothFactor,
-                                                     float levStrength, int levMode);
+                                                     float levStrength, int levMode, LEAF* const leaf);
     void    tSimpleLivingString_initToPool          (tSimpleLivingString* const, float freq, float dampFreq,
                                                      float decay, float targetLev, float levSmoothFactor,
                                                      float levStrength, int levMode, tMempool* const);
@@ -329,7 +332,7 @@
      @brief
      @{
      
-     @fn void    tLivingString_init                  (tLivingString* const, float freq, float pickPos, float prepIndex, float dampFreq, float decay, float targetLev, float levSmoothFactor, float levStrength, int levMode)
+     @fn void    tLivingString_init                  (tLivingString* const, float freq, float pickPos, float prepIndex, float dampFreq, float decay, float targetLev, float levSmoothFactor, float levStrength, int levMode, LEAF* const leaf)
      @brief
      @param
      
@@ -393,6 +396,7 @@
     
     typedef struct _tLivingString
     {
+        
         tMempool mempool;
         float freq, waveLengthInSamples;        // the frequency of the whole string, determining delay length
         float pickPos;    // the pick position, dividing the string in two, in ratio
@@ -412,7 +416,7 @@
     
     void    tLivingString_init                  (tLivingString* const, float freq, float pickPos, float prepIndex,
                                                  float dampFreq, float decay, float targetLev, float levSmoothFactor,
-                                                 float levStrength, int levMode);
+                                                 float levStrength, int levMode, LEAF* const leaf);
     void    tLivingString_initToPool            (tLivingString* const, float freq, float pickPos, float prepIndex,
                                                  float dampFreq, float decay, float targetLev, float levSmoothFactor,
                                                  float levStrength, int levMode, tMempool* const);
@@ -441,7 +445,7 @@
      @brief
      @{
      
-     @fn void    tComplexLivingString_init  (tComplexLivingString* const, float freq, float pickPos, float prepPos, float prepIndex, float dampFreq, float decay, float targetLev, float levSmoothFactor, float levStrength, int levMode)
+     @fn void    tComplexLivingString_init  (tComplexLivingString* const, float freq, float pickPos, float prepPos, float prepIndex, float dampFreq, float decay, float targetLev, float levSmoothFactor, float levStrength, int levMode, LEAF* const leaf)
      @brief
      @param
      
@@ -509,6 +513,7 @@
     
     typedef struct _tComplexLivingString
     {
+        
         tMempool mempool;
         float freq, waveLengthInSamples;        // the frequency of the whole string, determining delay length
         float pickPos;    // the pick position, dividing the string, in ratio
@@ -528,12 +533,14 @@
 
     typedef _tComplexLivingString* tComplexLivingString;
 
-    void    tComplexLivingString_init                  (tComplexLivingString* const, float freq, float pickPos, float prepPos, float prepIndex,
-                                                 float dampFreq, float decay, float targetLev, float levSmoothFactor,
-                                                 float levStrength, int levMode);
-    void    tComplexLivingString_initToPool            (tComplexLivingString* const, float freq, float pickPos, float prepPos, float prepIndex,
-                                                 float dampFreq, float decay, float targetLev, float levSmoothFactor,
-                                                 float levStrength, int levMode, tMempool* const);
+    void    tComplexLivingString_init                  (tComplexLivingString* const, float freq, float pickPos,
+                                                        float prepPos, float prepIndex, float dampFreq,
+                                                        float decay, float targetLev, float levSmoothFactor,
+                                                        float levStrength, int levMode, LEAF* const leaf);
+    void    tComplexLivingString_initToPool            (tComplexLivingString* const, float freq, float pickPos,
+                                                        float prepPos, float prepIndex, float dampFreq,
+                                                        float decay, float targetLev, float levSmoothFactor,
+                                                        float levStrength, int levMode, tMempool* const);
     void    tComplexLivingString_free                  (tComplexLivingString* const);
 
     float   tComplexLivingString_tick                  (tComplexLivingString* const, float input);
@@ -559,7 +566,7 @@
      @brief Reed Table - borrowed from STK
      @{
      
-     @fn void    tReedTable_init         (tReedTable* const, float offset, float slope)
+     @fn void    tReedTable_init         (tReedTable* const, float offset, float slope, LEAF* const leaf)
      @brief
      @param
      
@@ -591,6 +598,7 @@
 
     typedef struct _tReedTable
     {
+        
         tMempool mempool;
         float offset, slope;
     } _tReedTable;
@@ -597,7 +605,7 @@
     
     typedef _tReedTable* tReedTable;
     
-    void    tReedTable_init         (tReedTable* const, float offset, float slope);
+    void    tReedTable_init         (tReedTable* const, float offset, float slope, LEAF* const leaf);
     void    tReedTable_initToPool   (tReedTable* const, float offset, float slope, tMempool* const);
     void    tReedTable_free         (tReedTable* const);
     
--- a/leaf/Inc/leaf-reverb.h
+++ b/leaf/Inc/leaf-reverb.h
@@ -38,7 +38,7 @@
      @brief Reverb, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tPRCReverb_init         (tPRCReverb* const, float t60)
+     @fn void    tPRCReverb_init         (tPRCReverb* const, float t60, LEAF* const leaf)
      @brief
      @param
      
@@ -70,6 +70,7 @@
     
     typedef struct _tPRCReverb
     {
+        
         tMempool mempool;
         
         float mix, t60;
@@ -86,7 +87,7 @@
     
     typedef _tPRCReverb* tPRCReverb;
     
-    void    tPRCReverb_init         (tPRCReverb* const, float t60);
+    void    tPRCReverb_init         (tPRCReverb* const, float t60, LEAF* const leaf);
     void    tPRCReverb_initToPool   (tPRCReverb* const, float t60, tMempool* const);
     void    tPRCReverb_free         (tPRCReverb* const);
     
@@ -103,7 +104,7 @@
      @brief Reverb, reimplemented from STK (Cook and Scavone).
      @{
      
-     @fn void    tNReverb_init           (tNReverb* const, float t60)
+     @fn void    tNReverb_init           (tNReverb* const, float t60, LEAF* const leaf)
      @brief
      @param
      
@@ -139,6 +140,7 @@
     
     typedef struct _tNReverb
     {
+        
         tMempool mempool;
         
         float mix, t60;
@@ -156,7 +158,7 @@
     
     typedef _tNReverb* tNReverb;
     
-    void    tNReverb_init           (tNReverb* const, float t60);
+    void    tNReverb_init           (tNReverb* const, float t60, LEAF* const leaf);
     void    tNReverb_initToPool     (tNReverb* const, float t60, tMempool* const);
     void    tNReverb_free           (tNReverb* const);
     
@@ -174,7 +176,7 @@
      @brief
      @{
      
-     @fn void    tDattorroReverb_init              (tDattorroReverb* const)
+     @fn void    tDattorroReverb_init              (tDattorroReverb* const, LEAF* const leaf)
      @brief
      @param
      
@@ -234,6 +236,7 @@
     
     typedef struct _tDattorroReverb
     {
+        
         tMempool mempool;
         
         float   predelay;
@@ -279,7 +282,7 @@
     
     typedef _tDattorroReverb* tDattorroReverb;
     
-    void    tDattorroReverb_init              (tDattorroReverb* const);
+    void    tDattorroReverb_init              (tDattorroReverb* const, LEAF* const leaf);
     void    tDattorroReverb_initToPool        (tDattorroReverb* const, tMempool* const);
     void    tDattorroReverb_free              (tDattorroReverb* const);
     
--- a/leaf/Inc/leaf-sampling.h
+++ b/leaf/Inc/leaf-sampling.h
@@ -39,7 +39,7 @@
      @brief
      @{
      
-     @fn void  tBuffer_init                  (tBuffer* const, uint32_t length)
+     @fn void  tBuffer_init                  (tBuffer* const, uint32_t length, LEAF* const leaf)
      @brief
      @param
      
@@ -114,6 +114,7 @@
     
     typedef struct _tBuffer
     {
+        
         tMempool mempool;
         
         float* buff;
@@ -128,7 +129,7 @@
     
     typedef _tBuffer* tBuffer;
     
-    void  tBuffer_init                  (tBuffer* const, uint32_t length);
+    void  tBuffer_init                  (tBuffer* const, uint32_t length, LEAF* const leaf);
     void  tBuffer_initToPool            (tBuffer* const, uint32_t length, tMempool* const);
     void  tBuffer_free                  (tBuffer* const);
     
@@ -154,7 +155,7 @@
      @brief
      @{
      
-     @fn void    tSampler_init               (tSampler* const, tBuffer* const)
+     @fn void    tSampler_init               (tSampler* const, tBuffer* const, LEAF* const leaf)
      @brief
      @param
      
@@ -218,6 +219,7 @@
     
     typedef struct _tSampler
     {
+        
         tMempool mempool;
         
         tBuffer samp;
@@ -251,7 +253,7 @@
     
     typedef _tSampler* tSampler;
     
-    void    tSampler_init               (tSampler* const, tBuffer* const);
+    void    tSampler_init               (tSampler* const, tBuffer* const, LEAF* const leaf);
     void    tSampler_initToPool         (tSampler* const, tBuffer* const, tMempool* const);
     void    tSampler_free               (tSampler* const);
     
@@ -274,7 +276,7 @@
      @brief
      @{
      
-     @fn void    tAutoSampler_init               (tAutoSampler* const, tBuffer* const)
+     @fn void    tAutoSampler_init               (tAutoSampler* const, tBuffer* const, LEAF* const leaf)
      @brief
      @param
      
@@ -326,6 +328,7 @@
     
     typedef struct _tAutoSampler
     {
+        
         tMempool mempool;
         tSampler sampler;
         tEnvelopeFollower ef;
@@ -339,7 +342,7 @@
     
     typedef _tAutoSampler* tAutoSampler;
     
-    void    tAutoSampler_init               (tAutoSampler* const, tBuffer* const);
+    void    tAutoSampler_init               (tAutoSampler* const, tBuffer* const, LEAF* const leaf);
     void    tAutoSampler_initToPool         (tAutoSampler* const, tBuffer* const, tMempool* const);
     void    tAutoSampler_free               (tAutoSampler* const);
     
@@ -360,7 +363,7 @@
      @brief
      @{
      
-     @fn void    tMBSampler_init               (tMBSampler* const, tBuffer* const)
+     @fn void    tMBSampler_init               (tMBSampler* const, tBuffer* const, LEAF* const leaf)
      @brief
      @param
      
@@ -418,6 +421,7 @@
 
     typedef struct _tMBSampler
     {
+        
         tMempool mempool;
         
         tBuffer samp;
@@ -442,7 +446,7 @@
     
     typedef _tMBSampler* tMBSampler;
     
-    void    tMBSampler_init               (tMBSampler* const, tBuffer* const);
+    void    tMBSampler_init               (tMBSampler* const, tBuffer* const, LEAF* const leaf);
     void    tMBSampler_initToPool         (tMBSampler* const, tBuffer* const, tMempool* const);
     void    tMBSampler_free               (tMBSampler* const);
     
--- a/leaf/Src/leaf-analysis.c
+++ b/leaf/Src/leaf-analysis.c
@@ -22,9 +22,9 @@
 /* Envelope Follower */
 //===========================================================================
 
-void    tEnvelopeFollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff)
+void    tEnvelopeFollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff, LEAF* const leaf)
 {
-    tEnvelopeFollower_initToPool(ef, attackThreshold, decayCoeff, &leaf.mempool);
+    tEnvelopeFollower_initToPool(ef, attackThreshold, decayCoeff, &leaf->mempool);
 }
 
 void    tEnvelopeFollower_initToPool    (tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff, tMempool* const mp)
@@ -82,9 +82,9 @@
 
 // zero crossing detector
 
-void    tZeroCrossingCounter_init         (tZeroCrossingCounter* const zc, int maxWindowSize)
+void    tZeroCrossingCounter_init         (tZeroCrossingCounter* const zc, int maxWindowSize, LEAF* const leaf)
 {
-    tZeroCrossingCounter_initToPool   (zc, maxWindowSize, &leaf.mempool);
+    tZeroCrossingCounter_initToPool   (zc, maxWindowSize, &leaf->mempool);
 }
 
 void    tZeroCrossingCounter_initToPool   (tZeroCrossingCounter* const zc, int maxWindowSize, tMempool* const mp)
@@ -173,9 +173,9 @@
 //===========================================================================
 /* Power Follower */
 //===========================================================================
-void    tPowerFollower_init(tPowerFollower* const pf, float factor)
+void    tPowerFollower_init(tPowerFollower* const pf, float factor, LEAF* const leaf)
 {
-    tPowerFollower_initToPool(pf, factor, &leaf.mempool);
+    tPowerFollower_initToPool(pf, factor, &leaf->mempool);
 }
 
 void    tPowerFollower_initToPool   (tPowerFollower* const pf, float factor, tMempool* const mp)
@@ -227,9 +227,9 @@
 /* ---------------- env~ - simple envelope follower. ----------------- */
 //===========================================================================
 
-void tEnvPD_init(tEnvPD* const xpd, int ws, int hs, int bs)
+void tEnvPD_init(tEnvPD* const xpd, int ws, int hs, int bs, LEAF* const leaf)
 {
-    tEnvPD_initToPool(xpd, ws, hs, bs, &leaf.mempool);
+    tEnvPD_initToPool(xpd, ws, hs, bs, &leaf->mempool);
 }
 
 void    tEnvPD_initToPool       (tEnvPD* const xpd, int ws, int hs, int bs, tMempool* const mp)
@@ -335,9 +335,9 @@
 
 /********Constructor/Destructor***************/
 
-void tAttackDetection_init(tAttackDetection* const ad, int blocksize, int atk, int rel)
+void tAttackDetection_init(tAttackDetection* const ad, int blocksize, int atk, int rel, LEAF* const leaf)
 {
-    tAttackDetection_initToPool(ad, blocksize, atk, rel, &leaf.mempool);
+    tAttackDetection_initToPool(ad, blocksize, atk, rel, &leaf->mempool);
 }
 
 void tAttackDetection_initToPool     (tAttackDetection* const ad, int blocksize, int atk, int rel, tMempool* const mp)
@@ -426,11 +426,12 @@
 static void atkdtk_init(tAttackDetection* const ad, int blocksize, int atk, int rel)
 {
     _tAttackDetection* a = *ad;
+    LEAF* leaf = a->mempool->leaf;
     
     a->env = 0;
     a->blocksize = blocksize;
     a->threshold = DEFTHRESHOLD;
-    a->samplerate = leaf.sampleRate;
+    a->samplerate = leaf->sampleRate;
     a->prevAmp = 0;
     
     a->env = 0;
@@ -480,9 +481,9 @@
 /******************************************************************************/
 
 
-void tSNAC_init(tSNAC* const snac, int overlaparg)
+void tSNAC_init(tSNAC* const snac, int overlaparg, LEAF* const leaf)
 {
-    tSNAC_initToPool(snac, overlaparg, &leaf.mempool);
+    tSNAC_initToPool(snac, overlaparg, &leaf->mempool);
 }
 
 void    tSNAC_initToPool    (tSNAC* const snac, int overlaparg, tMempool* const mp)
@@ -831,9 +832,9 @@
 //===========================================================================
 // PERIODDETECTION
 //===========================================================================
-void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize)
+void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize, LEAF* const leaf)
 {
-    tPeriodDetection_initToPool(pd, in, out, bufSize, frameSize, &leaf.mempool);
+    tPeriodDetection_initToPool(pd, in, out, bufSize, frameSize, &leaf->mempool);
 }
 
 void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize, tMempool* const mp)
@@ -841,6 +842,7 @@
     _tMempool* m = *mp;
     _tPeriodDetection* p = *pd = (_tPeriodDetection*) mpool_calloc(sizeof(_tPeriodDetection), m);
     p->mempool = m;
+    LEAF* leaf = p->mempool->leaf;
     
     p->inBuffer = in;
     p->outBuffer = out;
@@ -863,7 +865,7 @@
     p->alpha = 1.0f;
     p->tolerance = 1.0f;
     p->timeConstant = DEFTIMECONSTANT;
-    p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
+    p->radius = expf(-1000.0f * p->hopSize * leaf->invSampleRate / p->timeConstant);
     p->fidelityThreshold = 0.95f;
 }
 
@@ -952,9 +954,9 @@
 }
 
 
-void    tZeroCrossingInfo_init  (tZeroCrossingInfo* const zc)
+void    tZeroCrossingInfo_init  (tZeroCrossingInfo* const zc, LEAF* const leaf)
 {
-    tZeroCrossingInfo_initToPool(zc, &leaf.mempool);
+    tZeroCrossingInfo_initToPool(zc, &leaf->mempool);
 }
 
 void    tZeroCrossingInfo_initToPool    (tZeroCrossingInfo* const zc, tMempool* const mp)
@@ -1025,9 +1027,9 @@
 static inline void shift(tZeroCrossingCollector* const zc, int n);
 static inline void reset(tZeroCrossingCollector* const zc);
 
-void    tZeroCrossingCollector_init  (tZeroCrossingCollector* const zc, int windowSize, float hysteresis)
+void    tZeroCrossingCollector_init  (tZeroCrossingCollector* const zc, int windowSize, float hysteresis, LEAF* const leaf)
 {
-    tZeroCrossingCollector_initToPool(zc, windowSize, hysteresis, &leaf.mempool);
+    tZeroCrossingCollector_initToPool(zc, windowSize, hysteresis, &leaf->mempool);
 }
 
 void    tZeroCrossingCollector_initToPool    (tZeroCrossingCollector* const zc, int windowSize, float hysteresis, tMempool* const mp)
@@ -1257,9 +1259,9 @@
 
 
 
-void    tBitset_init    (tBitset* const bitset, int numBits)
+void    tBitset_init    (tBitset* const bitset, int numBits, LEAF* const leaf)
 {
-    tBitset_initToPool(bitset, numBits, &leaf.mempool);
+    tBitset_initToPool(bitset, numBits, &leaf->mempool);
 }
 
 void    tBitset_initToPool  (tBitset* const bitset, int numBits, tMempool* const mempool)
@@ -1407,9 +1409,9 @@
     }
 }
 
-void    tBACF_init  (tBACF* const bacf, tBitset* const bitset)
+void    tBACF_init  (tBACF* const bacf, tBitset* const bitset, LEAF* const leaf)
 {
-    tBACF_initToPool(bacf, bitset, &leaf.mempool);
+    tBACF_initToPool(bacf, bitset, &leaf->mempool);
 }
 
 void    tBACF_initToPool    (tBACF* const bacf, tBitset* const bitset, tMempool* const mempool)
@@ -1496,9 +1498,9 @@
 static inline void sub_collector_process(_sub_collector* collector, _auto_correlation_info info);
 static inline void sub_collector_get(_sub_collector* collector, _auto_correlation_info info, _period_info* result);
 
-void    tPeriodDetector_init    (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis)
+void    tPeriodDetector_init    (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis, LEAF* const leaf)
 {
-    tPeriodDetector_initToPool(detector, lowestFreq, highestFreq, hysteresis, &leaf.mempool);
+    tPeriodDetector_initToPool(detector, lowestFreq, highestFreq, hysteresis, &leaf->mempool);
 }
 
 void    tPeriodDetector_initToPool  (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis, tMempool* const mempool)
@@ -1507,8 +1509,10 @@
     _tPeriodDetector* p = *detector = (_tPeriodDetector*) mpool_alloc(sizeof(_tPeriodDetector), m);
     p->mempool = m;
     
-    tZeroCrossingCollector_initToPool(&p->_zc, (1.0f / lowestFreq) * leaf.sampleRate * 2.0f, hysteresis, mempool);
-    p->_min_period = (1.0f / highestFreq) * leaf.sampleRate;
+    LEAF* leaf = p->mempool->leaf;
+    
+    tZeroCrossingCollector_initToPool(&p->_zc, (1.0f / lowestFreq) * leaf->sampleRate * 2.0f, hysteresis, mempool);
+    p->_min_period = (1.0f / highestFreq) * leaf->sampleRate;
     p->_range = highestFreq / lowestFreq;
     
     int windowSize = tZeroCrossingCollector_getWindowSize(&p->_zc);
@@ -1876,9 +1880,9 @@
 static inline float calculate_frequency(tPitchDetector* const detector);
 static inline void bias(tPitchDetector* const detector, _pitch_info incoming);
 
-void    tPitchDetector_init (tPitchDetector* const detector, float lowestFreq, float highestFreq)
+void    tPitchDetector_init (tPitchDetector* const detector, float lowestFreq, float highestFreq, LEAF* const leaf)
 {
-    tPitchDetector_initToPool(detector, lowestFreq, highestFreq, &leaf.mempool);
+    tPitchDetector_initToPool(detector, lowestFreq, highestFreq, &leaf->mempool);
 }
 
 void    tPitchDetector_initToPool   (tPitchDetector* const detector, float lowestFreq, float highestFreq, tMempool* const mempool)
@@ -1976,10 +1980,11 @@
 float   tPitchDetector_predictFrequency (tPitchDetector* const detector)
 {
     _tPitchDetector* p = *detector;
+    LEAF* leaf = p->mempool->leaf;
     
     float period = tPeriodDetector_predictPeriod(&p->_pd);
     if (period > 0.0f)
-       return leaf.sampleRate / period;
+       return leaf->sampleRate / period;
    return 0.0f;
 }
 
@@ -2000,10 +2005,11 @@
 static inline float calculate_frequency(tPitchDetector* const detector)
 {
     _tPitchDetector* p = *detector;
+    LEAF* leaf = p->mempool->leaf;
     
     float period = p->_pd->_fundamental.period;
     if (period > 0.0f)
-        return leaf.sampleRate / period;
+        return leaf->sampleRate / period;
     return 0.0f;
 }
 
@@ -2104,9 +2110,9 @@
 
 static inline void compute_predicted_frequency(tDualPitchDetector* const detector);
 
-void    tDualPitchDetector_init (tDualPitchDetector* const detector, float lowestFreq, float highestFreq)
+void    tDualPitchDetector_init (tDualPitchDetector* const detector, float lowestFreq, float highestFreq, LEAF* const leaf)
 {
-    tDualPitchDetector_initToPool(detector, lowestFreq, highestFreq, &leaf.mempool);
+    tDualPitchDetector_initToPool(detector, lowestFreq, highestFreq, &leaf->mempool);
 }
 
 void    tDualPitchDetector_initToPool   (tDualPitchDetector* const detector, float lowestFreq, float highestFreq, tMempool* const mempool)
--- a/leaf/Src/leaf-delay.c
+++ b/leaf/Src/leaf-delay.c
@@ -19,9 +19,9 @@
 #endif
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Delay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tDelay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay)
+void    tDelay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay, LEAF* const leaf)
 {
-    tDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
+    tDelay_initToPool(dl, delay, maxDelay, &leaf->mempool);
 }
 
 void    tDelay_initToPool   (tDelay* const dl, uint32_t delay, uint32_t maxDelay, tMempool* const mp)
@@ -162,9 +162,9 @@
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void   tLinearDelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay)
+void   tLinearDelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay, LEAF* const leaf)
 {
-    tLinearDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
+    tLinearDelay_initToPool(dl, delay, maxDelay, &leaf->mempool);
 }
 
 void tLinearDelay_initToPool  (tLinearDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
@@ -355,9 +355,9 @@
 
 /// Hermite Interpolated Delay
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay)
+void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay, LEAF* const leaf)
 {
-    tHermiteDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
+    tHermiteDelay_initToPool(dl, delay, maxDelay, &leaf->mempool);
 }
 
 void tHermiteDelay_initToPool  (tHermiteDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
@@ -550,9 +550,9 @@
 
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AllpassDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay)
+void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay, LEAF* const leaf)
 {
-    tAllpassDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
+    tAllpassDelay_initToPool(dl, delay, maxDelay, &leaf->mempool);
 }
 
 void tAllpassDelay_initToPool  (tAllpassDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
@@ -725,9 +725,9 @@
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay)
+void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay, LEAF* const leaf)
 {
-    tTapeDelay_initToPool(dl, delay, maxDelay, &leaf.mempool);
+    tTapeDelay_initToPool(dl, delay, maxDelay, &leaf->mempool);
 }
 
 void tTapeDelay_initToPool (tTapeDelay* const dl, float delay, uint32_t maxDelay, tMempool* const mp)
@@ -903,9 +903,9 @@
 
 
 
-void    tRingBuffer_init     (tRingBuffer* const ring, int size)
+void    tRingBuffer_init     (tRingBuffer* const ring, int size, LEAF* const leaf)
 {
-    tRingBuffer_initToPool(ring, size, &leaf.mempool);
+    tRingBuffer_initToPool(ring, size, &leaf->mempool);
 }
 
 void    tRingBuffer_initToPool   (tRingBuffer* const ring, int size, tMempool* const mempool)
--- a/leaf/Src/leaf-distortion.c
+++ b/leaf/Src/leaf-distortion.c
@@ -23,9 +23,9 @@
 //============================================================================================================
 
 
-void tSampleReducer_init (tSampleReducer* const sr)
+void tSampleReducer_init (tSampleReducer* const sr, LEAF* const leaf)
 {
-    tSampleReducer_initToPool(sr, &leaf.mempool);
+    tSampleReducer_initToPool(sr, &leaf->mempool);
 }
 
 void tSampleReducer_initToPool (tSampleReducer* const sr, tMempool* const mp)
@@ -72,9 +72,9 @@
 // Oversampler
 //============================================================================================================
 // Latency is equal to the phase length (numTaps / ratio)
-void tOversampler_init (tOversampler* const osr, int ratio, int extraQuality)
+void tOversampler_init (tOversampler* const osr, int ratio, int extraQuality, LEAF* const leaf)
 {
-    tOversampler_initToPool(osr, ratio, extraQuality, &leaf.mempool);
+    tOversampler_initToPool(osr, ratio, extraQuality, &leaf->mempool);
 }
 
 void tOversampler_initToPool (tOversampler* const osr, int ratio, int extraQuality, tMempool* const mp)
@@ -312,9 +312,9 @@
 //from the paper: Virtual Analog Model of the Lockhart Wavefolder
 //by Fabián Esqueda, Henri Pöntynen, Julian D. Parker and Stefan Bilbao
 
-void tLockhartWavefolder_init (tLockhartWavefolder* const wf)
+void tLockhartWavefolder_init (tLockhartWavefolder* const wf, LEAF* const leaf)
 {
-	tLockhartWavefolder_initToPool   (wf,  &leaf.mempool);
+	tLockhartWavefolder_initToPool   (wf, &leaf->mempool);
 }
 
 void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* const mp)
@@ -554,9 +554,9 @@
 //============================================================================================================
 #define SCALAR 5000.f
 
-void tCrusher_init (tCrusher* const cr)
+void tCrusher_init (tCrusher* const cr, LEAF* const leaf)
 {
-    tCrusher_initToPool(cr, &leaf.mempool);
+    tCrusher_initToPool(cr, &leaf->mempool);
 }
 
 void tCrusher_initToPool (tCrusher* const cr, tMempool* const mp)
--- a/leaf/Src/leaf-dynamics.c
+++ b/leaf/Src/leaf-dynamics.c
@@ -41,9 +41,9 @@
  return c;
  }
  */
-void tCompressor_init (tCompressor* const comp)
+void tCompressor_init (tCompressor* const comp, LEAF* const leaf)
 {
-    tCompressor_initToPool(comp, &leaf.mempool);
+    tCompressor_initToPool(comp, &leaf->mempool);
 }
 
 void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp)
@@ -73,6 +73,7 @@
 float tCompressor_tick(tCompressor* const comp, float in)
 {
     _tCompressor* c = *comp;
+    LEAF* leaf = c->mempool->leaf;
     
     float slope, overshoot;
     float alphaAtt, alphaRel;
@@ -106,8 +107,8 @@
     
     c->x_T[0] = out_db - in_db;
     
-    alphaAtt = expf(-1.0f/(0.001f * c->tauAttack * leaf.sampleRate));
-    alphaRel = expf(-1.0f/(0.001f * c->tauRelease * leaf.sampleRate));
+    alphaAtt = expf(-1.0f/(0.001f * c->tauAttack * leaf->sampleRate));
+    alphaRel = expf(-1.0f/(0.001f * c->tauRelease * leaf->sampleRate));
     
     if (c->x_T[0] > c->y_T[1])
         c->y_T[0] = alphaAtt * c->y_T[1] + (1-alphaAtt) * c->x_T[0];
@@ -121,9 +122,9 @@
 
 /* Feedback Leveler */
 
-void tFeedbackLeveler_init (tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode)
+void tFeedbackLeveler_init (tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode, LEAF* const leaf)
 {
-    tFeedbackLeveler_initToPool(fb, targetLevel, factor, strength, mode, &leaf.mempool);
+    tFeedbackLeveler_initToPool(fb, targetLevel, factor, strength, mode, &leaf->mempool);
 }
 
 void tFeedbackLeveler_initToPool (tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode, tMempool* const mp)
@@ -134,7 +135,7 @@
     
     p->curr=0.0f;
     p->targetLevel=targetLevel;
-    tPowerFollower_initToPool(&p->pwrFlw,factor, mp);
+    tPowerFollower_initToPool(&p->pwrFlw, factor, mp);
     p->mode=mode;
     p->strength=strength;
 }
@@ -190,9 +191,9 @@
 
 
 
-void tThreshold_init (tThreshold* const th, float low, float high)
+void tThreshold_init (tThreshold* const th, float low, float high, LEAF* const leaf)
 {
-	tThreshold_initToPool(th, low, high, &leaf.mempool);
+	tThreshold_initToPool(th, low, high, &leaf->mempool);
 }
 
 void tThreshold_initToPool (tThreshold* const th, float low, float high, tMempool* const mp)
--- a/leaf/Src/leaf-effects.c
+++ b/leaf/Src/leaf-effects.c
@@ -32,9 +32,9 @@
 // -JS
 
 
-void tTalkbox_init (tTalkbox* const voc, int bufsize)
+void tTalkbox_init (tTalkbox* const voc, int bufsize, LEAF* const leaf)
 {
-    tTalkbox_initToPool(voc, bufsize, &leaf.mempool);
+    tTalkbox_initToPool(voc, bufsize, &leaf->mempool);
 }
 
 void tTalkbox_initToPool (tTalkbox* const voc, int bufsize, tMempool* const mp)
@@ -86,8 +86,9 @@
 void tTalkbox_update(tTalkbox* const voc) ///update internal parameters...
 {
     _tTalkbox* v = *voc;
+    LEAF* leaf = v->mempool->leaf;
     
-    float fs = leaf.sampleRate;
+    float fs = leaf->sampleRate;
     if(fs <  8000.0f) fs =  8000.0f;
     if(fs > 96000.0f) fs = 96000.0f;
     
@@ -316,8 +317,10 @@
 void tTalkbox_setQuality(tTalkbox* const voc, float quality)
 {
     _tTalkbox* v = *voc;
+    LEAF* leaf = v->mempool->leaf;
+    
     v->param[3] = quality;
-    v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate);
+    v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf->sampleRate);
     if (v->O >= ORD_MAX)
     {
         v->O = ORD_MAX-1;
@@ -358,9 +361,9 @@
 // -JS
 
 
-void tTalkboxFloat_init (tTalkboxFloat* const voc, int bufsize)
+void tTalkboxFloat_init (tTalkboxFloat* const voc, int bufsize, LEAF* const leaf)
 {
-    tTalkboxFloat_initToPool(voc, bufsize, &leaf.mempool);
+    tTalkboxFloat_initToPool(voc, bufsize, &leaf->mempool);
 }
 
 void tTalkboxFloat_initToPool (tTalkboxFloat* const voc, int bufsize, tMempool* const mp)
@@ -412,8 +415,9 @@
 void tTalkboxFloat_update(tTalkboxFloat* const voc) ///update internal parameters...
 {
     _tTalkboxFloat* v = *voc;
-
-    float fs = leaf.sampleRate;
+    LEAF* leaf = v->mempool->leaf;
+    
+    float fs = leaf->sampleRate;
     if(fs <  8000.0f) fs =  8000.0f;
     if(fs > 96000.0f) fs = 96000.0f;
 
@@ -643,8 +647,10 @@
 void tTalkboxFloat_setQuality(tTalkboxFloat* const voc, float quality)
 {
     _tTalkboxFloat* v = *voc;
+    LEAF* leaf = v->mempool->leaf;
+    
     v->param[3] = quality;
-    v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate);
+    v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf->sampleRate);
     if (v->O >= ORD_MAX)
     {
         v->O = ORD_MAX-1;
@@ -677,9 +683,9 @@
 // VOCODER
 //============================================================================================================
 
-void tVocoder_init (tVocoder* const voc)
+void tVocoder_init (tVocoder* const voc, LEAF* const leaf)
 {
-    tVocoder_initToPool(voc, &leaf.mempool);
+    tVocoder_initToPool(voc, &leaf->mempool);
 }
 
 void tVocoder_initToPool (tVocoder* const voc, tMempool* const mp)
@@ -710,8 +716,9 @@
 void        tVocoder_update      (tVocoder* const voc)
 {
     _tVocoder* v = *voc;
+    LEAF* leaf = v->mempool->leaf;
     
-    float tpofs = 6.2831853f * leaf.invSampleRate;
+    float tpofs = 6.2831853f * leaf->invSampleRate;
     
     float rr, th;
     
@@ -872,9 +879,9 @@
 
 /// Glottal Pulse (Rosenberg model)
 
-void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const gp)
+void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const gp, LEAF* const leaf)
 {
-    tRosenbergGlottalPulse_initToPool(gp, &leaf.mempool);
+    tRosenbergGlottalPulse_initToPool(gp, &leaf->mempool);
 }
 
 void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const gp, tMempool* const mp)
@@ -957,8 +964,10 @@
 void   tRosenbergGlottalPulse_setFreq           (tRosenbergGlottalPulse* const gp, float freq)
 {
     _tRosenbergGlottalPulse* g = *gp;
+    LEAF* leaf = g->mempool->leaf;
+    
     g->freq = freq;
-    g->inc = freq * leaf.invSampleRate;
+    g->inc = freq * leaf->invSampleRate;
 }
 
 void   tRosenbergGlottalPulse_setOpenLength           (tRosenbergGlottalPulse* const gp, float openLength)
@@ -1002,9 +1011,9 @@
 /******************************************************************************/
 
 // init
-void tSOLAD_init (tSOLAD* const wp)
+void tSOLAD_init (tSOLAD* const wp, LEAF* const leaf)
 {
-    tSOLAD_initToPool(wp, &leaf.mempool);
+    tSOLAD_initToPool(wp, &leaf->mempool);
 }
 
 void tSOLAD_initToPool (tSOLAD* const wp, tMempool* const mp)
@@ -1357,9 +1366,9 @@
     return (p->fba == 0 && (p->max > 60 && p->deltamax > 6)) ? 1 : 0;
 }
 
-void tPitchShift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize)
+void tPitchShift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize, LEAF* const leaf)
 {
-    tPitchShift_initToPool(psr, pd, out, bufSize, &leaf.mempool);
+    tPitchShift_initToPool(psr, pd, out, bufSize, &leaf->mempool);
 }
 
 void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp)
@@ -1440,6 +1449,7 @@
 {
     _tPitchShift* ps = *psr;
     _tPeriodDetection* p = *ps->p;
+    LEAF* leaf = ps->mempool->leaf;
     
     float period, out;
     int i, iLast;
@@ -1461,7 +1471,7 @@
         
         tSOLAD_setPeriod(&ps->sola, period);
         
-        if (period != 0) ps->pitchFactor = period*freq*leaf.invSampleRate;
+        if (period != 0) ps->pitchFactor = period * freq * leaf->invSampleRate;
         else ps->pitchFactor = 1.0f;
         
         tSOLAD_setPitchFactor(&ps->sola, ps->pitchFactor);
@@ -1514,9 +1524,9 @@
 // RETUNE
 //============================================================================================================
 
-void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize)
+void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize, LEAF* const leaf)
 {
-    tRetune_initToPool(rt, numVoices, bufSize, frameSize, &leaf.mempool);
+    tRetune_initToPool(rt, numVoices, bufSize, frameSize, &leaf->mempool);
 }
 
 void tRetune_initToPool (tRetune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp)
@@ -1621,9 +1631,10 @@
 void tRetune_setTimeConstant(tRetune* const rt, float tc)
 {
     _tRetune* r = *rt;
+    LEAF* leaf = r->mempool->leaf;
     
     r->timeConstant = tc;
-    r->radius = expf(-1000.0f * r->hopSize * leaf.invSampleRate / r->timeConstant);
+    r->radius = expf(-1000.0f * r->hopSize * leaf->invSampleRate / r->timeConstant);
 }
 
 void tRetune_setHopSize(tRetune* const rt, int hs)
@@ -1652,15 +1663,17 @@
 float tRetune_getInputPeriod(tRetune* const rt)
 {
     _tRetune* r = *rt;
-    
-    return (r->inputPeriod * leaf.invSampleRate);
+    LEAF* leaf = r->mempool->leaf;
+
+    return (r->inputPeriod * leaf->invSampleRate);
 }
 
 float tRetune_getInputFreq(tRetune* const rt)
 {
     _tRetune* r = *rt;
+    LEAF* leaf = r->mempool->leaf;
     
-    return 1.0f/(r->inputPeriod * leaf.invSampleRate);
+    return 1.0f/(r->inputPeriod * leaf->invSampleRate);
 }
 
 //============================================================================================================
@@ -1667,9 +1680,9 @@
 // AUTOTUNE
 //============================================================================================================
 
-void tAutotune_init (tAutotune* const rt, int numVoices, int bufSize, int frameSize)
+void tAutotune_init (tAutotune* const rt, int numVoices, int bufSize, int frameSize, LEAF* const leaf)
 {
-    tAutotune_initToPool(rt, numVoices, bufSize, frameSize, &leaf.mempool);
+    tAutotune_initToPool(rt, numVoices, bufSize, frameSize, &leaf->mempool);
 }
 
 void tAutotune_initToPool (tAutotune* const rt, int numVoices, int bufSize, int frameSize, tMempool* const mp)
@@ -1777,9 +1790,10 @@
 void tAutotune_setTimeConstant(tAutotune* const rt, float tc)
 {
     _tAutotune* r = *rt;
+    LEAF* leaf = r->mempool->leaf;
     
     r->timeConstant = tc;
-    r->radius = expf(-1000.0f * r->hopSize * leaf.invSampleRate / r->timeConstant);
+    r->radius = expf(-1000.0f * r->hopSize * leaf->invSampleRate / r->timeConstant);
 }
 
 void tAutotune_setHopSize(tAutotune* const rt, int hs)
@@ -1836,9 +1850,9 @@
 //============================================================================================================
 // algorithm from Tom Baran's autotalent code.
 
-void tFormantShifter_init (tFormantShifter* const fsr, int order)
+void tFormantShifter_init (tFormantShifter* const fsr, int order, LEAF* const leaf)
 {
-    tFormantShifter_initToPool(fsr, order, &leaf.mempool);
+    tFormantShifter_initToPool(fsr, order, &leaf->mempool);
 }
 
 void tFormantShifter_initToPool (tFormantShifter* const fsr, int order, tMempool* const mp)
@@ -1847,6 +1861,8 @@
     _tFormantShifter* fs = *fsr = (_tFormantShifter*) mpool_alloc(sizeof(_tFormantShifter), m);
     fs->mempool = m;
     
+    LEAF* leaf = fs->mempool->leaf;
+    
     fs->ford = order;
     fs->fk = (float*) mpool_calloc(sizeof(float) * fs->ford, m);
     fs->fb = (float*) mpool_calloc(sizeof(float) * fs->ford, m);
@@ -1860,13 +1876,13 @@
     fs->fbuff = (float*) mpool_calloc(sizeof(float*) * fs->ford, m);
 
     
-    fs->falph = powf(0.001f, 10.0f * leaf.invSampleRate);
-    fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f);
+    fs->falph = powf(0.001f, 10.0f * leaf->invSampleRate);
+    fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f * leaf->sampleRate)) - 0.1916f);
     fs->fhp = 0.0f;
     fs->flp = 0.0f;
-    fs->flpa = powf(0.001f, 10.0f * leaf.invSampleRate);
+    fs->flpa = powf(0.001f, 10.0f * leaf->invSampleRate);
     fs->fmute = 1.0f;
-    fs->fmutealph = powf(0.001f, 1.0f * leaf.invSampleRate);
+    fs->fmutealph = powf(0.001f, 1.0f * leaf->invSampleRate);
     fs->cbi = 0;
     fs->intensity = 1.0f;
     fs->invIntensity = 1.0f;
--- a/leaf/Src/leaf-electrical.c
+++ b/leaf/Src/leaf-electrical.c
@@ -48,6 +48,7 @@
 static void wdf_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR)
 {
     _tWDF* r = *wdf;
+    LEAF* leaf = r->mempool->leaf;
     
     r->type = type;
     r->child_left = rL;
@@ -58,7 +59,7 @@
     r->reflected_wave_up = 0.0f;
     r->reflected_wave_left = 0.0f;
     r->reflected_wave_right = 0.0f;
-    r->sample_rate = leaf.sampleRate;
+    r->sample_rate = leaf->sampleRate;
     r->value = value;
     
     tWDF* child;
@@ -164,9 +165,9 @@
     }
 }
 //WDF
-void tWDF_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR)
+void tWDF_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, LEAF* const leaf)
 {
-    tWDF_initToPool(wdf, type, value, rL, rR, &leaf.mempool);
+    tWDF_initToPool(wdf, type, value, rL, rR, &leaf->mempool);
 }
 
 void    tWDF_initToPool(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, tMempool* const mp)
--- a/leaf/Src/leaf-envelopes.c
+++ b/leaf/Src/leaf-envelopes.c
@@ -24,9 +24,9 @@
 #endif
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Envelope ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tEnvelope_init(tEnvelope* const envlp, float attack, float decay, int loop)
+void    tEnvelope_init(tEnvelope* const envlp, float attack, float decay, int loop, LEAF* const leaf)
 {
-    tEnvelope_initToPool(envlp, attack, decay, loop, &leaf.mempool);
+    tEnvelope_initToPool(envlp, attack, decay, loop, &leaf->mempool);
 }
 
 void    tEnvelope_initToPool    (tEnvelope* const envlp, float attack, float decay, int loop, tMempool* const mp)
@@ -215,9 +215,9 @@
 
 
 /* ADSR */
-void    tADSR_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release)
+void    tADSR_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release, LEAF* const leaf)
 {
-    tADSR_initToPool(adsrenv, attack, decay, sustain, release, &leaf.mempool);
+    tADSR_initToPool(adsrenv, attack, decay, sustain, release, &leaf->mempool);
 }
 
 void    tADSR_initToPool    (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp)
@@ -498,9 +498,9 @@
 const float ADSR2_LAMBDA_BASE = 10000.0f;
 
 
-void    tADSR2_init(tADSR2* const adsrenv, float attack, float decay, float sustain, float release)
+void    tADSR2_init(tADSR2* const adsrenv, float attack, float decay, float sustain, float release, LEAF* const leaf)
 {
-    tADSR2_initToPool(adsrenv, attack, decay, sustain, release, &leaf.mempool);
+    tADSR2_initToPool(adsrenv, attack, decay, sustain, release, &leaf->mempool);
 }
 
 void    tADSR2_initToPool    (tADSR2* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp)
@@ -509,7 +509,9 @@
     _tADSR2* adsr = *adsrenv = (_tADSR2*) mpool_alloc(sizeof(_tADSR2), m);
     adsr->mempool = m;
     
-    adsr->sampleRateInMs =  leaf.sampleRate * 0.001f;
+    LEAF* leaf = adsr->mempool->leaf;
+    
+    adsr->sampleRateInMs = leaf->sampleRate * 0.001f;
     adsr->attack = LEAF_clip(0.0f, attack * 0.001f, 1.0f);
     adsr->attackLambda = powf(ADSR2_LAMBDA_BASE, -adsr->attack) * ADSR2_INV_MIN_TIME;
 
@@ -605,6 +607,8 @@
 float   tADSR2_tick(tADSR2* const adsrenv)
 {
     _tADSR2* adsr = *adsrenv;
+    LEAF* leaf = adsr->mempool->leaf;
+    
     float lambda;
 
     if (adsr->gate)
@@ -625,7 +629,7 @@
 
 
     // Adjust env
-    adsr->env += (adsr->envTarget - adsr->env) * lambda * leaf.invSampleRate;
+    adsr->env += (adsr->envTarget - adsr->env) * lambda * leaf->invSampleRate;
 
     // Turn off attacking state if envelope is HIGH
     if (adsr->env >= 1.0f)
@@ -650,9 +654,9 @@
 }
 
 
-void    tADSR3_init(tADSR3* const adsrenv, float attack, float decay, float sustain, float release)
+void    tADSR3_init(tADSR3* const adsrenv, float attack, float decay, float sustain, float release, LEAF* const leaf)
 {
-    tADSR3_initToPool(adsrenv, attack, decay, sustain, release, &leaf.mempool);
+    tADSR3_initToPool(adsrenv, attack, decay, sustain, release, &leaf->mempool);
 }
 
 void    tADSR3_initToPool    (tADSR3* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp)
@@ -661,7 +665,9 @@
     _tADSR3* adsr = *adsrenv = (_tADSR3*) mpool_alloc(sizeof(_tADSR3), m);
     adsr->mempool = m;
     
-    adsr->sampleRateInMs =  leaf.sampleRate * 0.001f;
+    LEAF* leaf = adsr->mempool->leaf;
+    
+    adsr->sampleRateInMs =  leaf->sampleRate * 0.001f;
     adsr->targetRatioA = 0.3f;
     adsr->targetRatioDR = 0.0001f;
     adsr->attackRate = attack * adsr->sampleRateInMs;
@@ -796,9 +802,9 @@
 
 /* ADSR 4 */ // new version of our original table-based ADSR but with the table passed in by the user
 // use this if the size of the big ADSR tables is too much.
-void    tADSR4_init    (tADSR4* const adsrenv, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize)
+void    tADSR4_init    (tADSR4* const adsrenv, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize, LEAF* const leaf)
 {
-    tADSR4_initToPool    (adsrenv, attack, decay, sustain, release, expBuffer, bufferSize, &leaf.mempool);
+    tADSR4_initToPool    (adsrenv, attack, decay, sustain, release, expBuffer, bufferSize, &leaf->mempool);
 }
 
 //initialize with an exponential function that decays -- i.e. a call to LEAF_generate_exp(expBuffer, 0.001f, 0.0f, 1.0f, -0.0008f, EXP_BUFFER_SIZE);
@@ -808,12 +814,14 @@
     _tMempool* m = *mp;
     _tADSR4* adsr = *adsrenv = (_tADSR4*) mpool_alloc(sizeof(_tADSR4), m);
     adsr->mempool = m;
+    
+    LEAF* leaf = adsr->mempool->leaf;
 
     adsr->exp_buff = expBuffer;
     adsr->buff_size = bufferSize;
     adsr->buff_sizeMinusOne = bufferSize - 1;
 
-    adsr->bufferSizeDividedBySampleRateInMs = bufferSize / (leaf.sampleRate * 0.001f);
+    adsr->bufferSizeDividedBySampleRateInMs = bufferSize / (leaf->sampleRate * 0.001f);
 
     if (attack < 0.0f)
         attack = 0.0f;
@@ -1144,9 +1152,9 @@
 
 /////-----------------
 /* Ramp */
-void    tRamp_init(tRamp* const r, float time, int samples_per_tick)
+void    tRamp_init(tRamp* const r, float time, int samples_per_tick, LEAF* const leaf)
 {
-    tRamp_initToPool(r, time, samples_per_tick, &leaf.mempool);
+    tRamp_initToPool(r, time, samples_per_tick, &leaf->mempool);
 }
 
 void    tRamp_initToPool    (tRamp* const r, float time, int samples_per_tick, tMempool* const mp)
@@ -1155,7 +1163,9 @@
     _tRamp* ramp = *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), m);
     ramp->mempool = m;
     
-    ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
+    LEAF* leaf = ramp->mempool->leaf;
+    
+    ramp->inv_sr_ms = 1.0f/(leaf->sampleRate*0.001f);
     ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
     ramp->curr = 0.0f;
     ramp->dest = 0.0f;
@@ -1235,7 +1245,9 @@
 void    tRampSampleRateChanged(tRamp* const ramp)
 {
     _tRamp* r = *ramp;
-    r->inv_sr_ms = 1.0f / (leaf.sampleRate * 0.001f);
+    LEAF* leaf = r->mempool->leaf;
+    
+    r->inv_sr_ms = 1.0f / (leaf->sampleRate * 0.001f);
     r->factor = (1.0f / r->time) * r->inv_sr_ms * (float)r->samples_per_tick;
     r->inc = (r->dest - r->curr) * r->factor;
 }
@@ -1243,9 +1255,9 @@
 
 
 /* RampUpDown */
-void    tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick)
+void    tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick, LEAF* const leaf)
 {
-    tRampUpDown_initToPool(r, upTime, downTime, samples_per_tick, &leaf.mempool);
+    tRampUpDown_initToPool(r, upTime, downTime, samples_per_tick, &leaf->mempool);
 }
 
 void    tRampUpDown_initToPool(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick, tMempool* const mp)
@@ -1253,8 +1265,10 @@
     _tMempool* m = *mp;
     _tRampUpDown* ramp = *r = (_tRampUpDown*) mpool_alloc(sizeof(_tRampUpDown), m);
     ramp->mempool = m;
+    
+    LEAF* leaf = ramp->mempool->leaf;
 
-    ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f);
+    ramp->inv_sr_ms = 1.0f/(leaf->sampleRate*0.001f);
     ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick;
     ramp->curr = 0.0f;
     ramp->dest = 0.0f;
@@ -1382,9 +1396,9 @@
 
 
 /* Exponential Smoother */
-void    tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor)
+void    tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor, LEAF* const leaf)
 {   // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms
-    tExpSmooth_initToPool(expsmooth, val, factor, &leaf.mempool);
+    tExpSmooth_initToPool(expsmooth, val, factor, &leaf->mempool);
 }
 
 void    tExpSmooth_initToPool   (tExpSmooth* const expsmooth, float val, float factor, tMempool* const mp)
@@ -1455,9 +1469,9 @@
 //tSlide is based on the max/msp slide~ object
 ////
 
-void    tSlide_init          (tSlide* const sl, float upSlide, float downSlide)
+void    tSlide_init          (tSlide* const sl, float upSlide, float downSlide, LEAF* const leaf)
 {
-    tSlide_initToPool    (sl, upSlide, downSlide, &leaf.mempool);
+    tSlide_initToPool    (sl, upSlide, downSlide, &leaf->mempool);
 }
 
 void    tSlide_initToPool    (tSlide* const sl, float upSlide, float downSlide, tMempool* const mp)
--- a/leaf/Src/leaf-filters.c
+++ b/leaf/Src/leaf-filters.c
@@ -21,9 +21,9 @@
 #endif
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tAllpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay)
+void    tAllpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay, LEAF* const leaf)
 {
-    tAllpass_initToPool(ft, initDelay, maxDelay, &leaf.mempool);
+    tAllpass_initToPool(ft, initDelay, maxDelay, &leaf->mempool);
 }
 
 void    tAllpass_initToPool     (tAllpass* const ft, float initDelay, uint32_t maxDelay, tMempool* const mp)
@@ -75,9 +75,9 @@
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tOnePole_init(tOnePole* const ft, float freq)
+void    tOnePole_init(tOnePole* const ft, float freq, LEAF* const leaf)
 {
-    tOnePole_initToPool(ft, freq, &leaf.mempool);
+    tOnePole_initToPool(ft, freq, &leaf->mempool);
 }
 
 void    tOnePole_initToPool     (tOnePole* const ft, float freq, tMempool* const mp)
@@ -131,7 +131,9 @@
 void        tOnePole_setFreq        (tOnePole* const ft, float freq)
 {
     _tOnePole* f = *ft;
-    f->b0 = freq * leaf.twoPiTimesInvSampleRate;
+    LEAF* leaf = f->mempool->leaf;
+    
+    f->b0 = freq * leaf->twoPiTimesInvSampleRate;
     f->b0 = LEAF_clip(0.0f, f->b0, 1.0f);
     f->a1 = 1.0f - f->b0;
 }
@@ -164,9 +166,9 @@
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoPole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tTwoPole_init(tTwoPole* const ft)
+void    tTwoPole_init(tTwoPole* const ft, LEAF* const leaf)
 {
-    tTwoPole_initToPool(ft, &leaf.mempool);
+    tTwoPole_initToPool(ft, &leaf->mempool);
 }
 
 void    tTwoPole_initToPool     (tTwoPole* const ft, tMempool* const mp)
@@ -225,9 +227,13 @@
 void    tTwoPole_setResonance(tTwoPole* const ft, float frequency, float radius, int normalize)
 {
     _tTwoPole* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
     
+    float sampleRate = leaf->sampleRate;
+    float twoPiTimesInvSampleRate = leaf->twoPiTimesInvSampleRate;
+    
     if (frequency < 0.0f)   frequency = 0.0f;
-    if (frequency > (leaf.sampleRate * 0.49f))   frequency = leaf.sampleRate * 0.49f;
+    if (frequency > (sampleRate * 0.49f))   frequency = sampleRate * 0.49f;
     if (radius < 0.0f)      radius = 0.0f;
     if (radius >= 1.0f)     radius = 0.999999f;
     
@@ -236,13 +242,13 @@
     f->normalize = normalize;
     
     f->a2 = radius * radius;
-    f->a1 =  -2.0f * radius * cosf(frequency * leaf.twoPiTimesInvSampleRate);
+    f->a1 =  -2.0f * radius * cosf(frequency * twoPiTimesInvSampleRate);
     
     if ( normalize )
     {
         // Normalize the filter gain ... not terribly efficient.
-        float real = 1 - radius + (f->a2 - radius) * cosf(2 * frequency * leaf.twoPiTimesInvSampleRate);
-        float imag = (f->a2 - radius) * sinf(2 * frequency * leaf.twoPiTimesInvSampleRate);
+        float real = 1 - radius + (f->a2 - radius) * cosf(2 * frequency * twoPiTimesInvSampleRate);
+        float imag = (f->a2 - radius) * sinf(2 * frequency * twoPiTimesInvSampleRate);
         f->b0 = sqrtf( powf(real, 2) + powf(imag, 2) );
     }
 }
@@ -264,23 +270,26 @@
 void     tTwoPoleSampleRateChanged (tTwoPole* const ft)
 {
     _tTwoPole* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
     
+    float twoPiTimesInvSampleRate = leaf->twoPiTimesInvSampleRate;
+    
     f->a2 = f->radius * f->radius;
-    f->a1 =  -2.0f * f->radius * cosf(f->frequency * leaf.twoPiTimesInvSampleRate);
+    f->a1 =  -2.0f * f->radius * cosf(f->frequency * twoPiTimesInvSampleRate);
     
     if ( f->normalize )
     {
         // Normalize the filter gain ... not terribly efficient.
-        float real = 1 - f->radius + (f->a2 - f->radius) * cosf(2 * f->frequency * leaf.twoPiTimesInvSampleRate);
-        float imag = (f->a2 - f->radius) * sinf(2 * f->frequency * leaf.twoPiTimesInvSampleRate);
+        float real = 1 - f->radius + (f->a2 - f->radius) * cosf(2 * f->frequency * twoPiTimesInvSampleRate);
+        float imag = (f->a2 - f->radius) * sinf(2 * f->frequency * twoPiTimesInvSampleRate);
         f->b0 = sqrtf( powf(real, 2) + powf(imag, 2) );
     }
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OneZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tOneZero_init(tOneZero* const ft, float theZero)
+void    tOneZero_init(tOneZero* const ft, float theZero, LEAF* const leaf)
 {
-    tOneZero_initToPool(ft, theZero, &leaf.mempool);
+    tOneZero_initToPool(ft, theZero, &leaf->mempool);
 }
 
 void    tOneZero_initToPool     (tOneZero* const ft, float theZero, tMempool* const mp)
@@ -354,12 +363,13 @@
 float   tOneZero_getPhaseDelay(tOneZero* const ft, float frequency )
 {
     _tOneZero* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
     
     if ( frequency <= 0.0f) frequency = 0.05f;
     
     f->frequency = frequency;
     
-    float omegaT = 2 * PI * frequency * leaf.invSampleRate;
+    float omegaT = 2 * PI * frequency * leaf->invSampleRate;
     float real = 0.0, imag = 0.0;
     
     real += f->b0;
@@ -382,9 +392,9 @@
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tTwoZero_init(tTwoZero* const ft)
+void    tTwoZero_init(tTwoZero* const ft, LEAF* const leaf)
 {
-    tTwoZero_initToPool(ft, &leaf.mempool);
+    tTwoZero_initToPool(ft, &leaf->mempool);
 }
 
 void    tTwoZero_initToPool     (tTwoZero* const ft, tMempool* const mp)
@@ -421,6 +431,7 @@
 void    tTwoZero_setNotch(tTwoZero* const ft, float freq, float radius)
 {
     _tTwoZero* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
     
     // Should also deal with frequency being > half sample rate / nyquist. See STK
     if (freq < 0.0f)    freq = 0.0f;
@@ -430,7 +441,7 @@
     f->radius = radius;
     
     f->b2 = radius * radius;
-    f->b1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION
+    f->b1 = -2.0f * radius * cosf(freq * leaf->twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION
     
     // Normalize the filter gain. From STK.
     if ( f->b1 > 0.0f ) // Maximum at z = 0.
@@ -476,9 +487,9 @@
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PoleZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void   tPoleZero_init(tPoleZero* const pzf)
+void   tPoleZero_init(tPoleZero* const pzf, LEAF* const leaf)
 {
-    tPoleZero_initToPool(pzf, &leaf.mempool);
+    tPoleZero_initToPool(pzf, &leaf->mempool);
 }
 
 void    tPoleZero_initToPool        (tPoleZero* const pzf, tMempool* const mp)
@@ -590,9 +601,9 @@
 }
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ BiQuad Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tBiQuad_init(tBiQuad* const ft)
+void    tBiQuad_init(tBiQuad* const ft, LEAF* const leaf)
 {
-    tBiQuad_initToPool(ft, &leaf.mempool);
+    tBiQuad_initToPool(ft, &leaf->mempool);
 }
 
 void    tBiQuad_initToPool     (tBiQuad* const ft, tMempool* const mp)
@@ -639,9 +650,11 @@
 void    tBiQuad_setResonance(tBiQuad* const ft, float freq, float radius, int normalize)
 {
     _tBiQuad* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
     
     if (freq < 0.0f)    freq = 0.0f;
-    if (freq > (leaf.sampleRate * 0.49f))   freq = leaf.sampleRate * 0.49f;
+    if (freq > (leaf->sampleRate * 0.49f))
+        freq = leaf->sampleRate * 0.49f;
     if (radius < 0.0f)  radius = 0.0f;
     if (radius >= 1.0f)  radius = 1.0f;
     
@@ -650,7 +663,7 @@
     f->normalize = normalize;
     
     f->a2 = radius * radius;
-    f->a1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate);
+    f->a1 = -2.0f * radius * cosf(freq * leaf->twoPiTimesInvSampleRate);
     
     if (normalize)
     {
@@ -663,13 +676,15 @@
 void    tBiQuad_setNotch(tBiQuad* const ft, float freq, float radius)
 {
     _tBiQuad* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
     
     if (freq < 0.0f)    freq = 0.0f;
-    if (freq > (leaf.sampleRate * 0.49f))   freq = leaf.sampleRate * 0.49f;
+    if (freq > (leaf->sampleRate * 0.49f))
+        freq = leaf->sampleRate * 0.49f;
     if (radius < 0.0f)  radius = 0.0f;
     
     f->b2 = radius * radius;
-    f->b1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION
+    f->b1 = -2.0f * radius * cosf(freq * leaf->twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION
     
     // Does not attempt to normalize filter gain.
 }
@@ -731,8 +746,10 @@
 void    tBiQuadSampleRateChanged(tBiQuad* const ft)
 {
     _tBiQuad* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
+    
     f->a2 = f->radius * f->radius;
-    f->a1 = -2.0f * f->radius * cosf(f->frequency * leaf.twoPiTimesInvSampleRate);
+    f->a1 = -2.0f * f->radius * cosf(f->frequency * leaf->twoPiTimesInvSampleRate);
     
     if (f->normalize)
     {
@@ -744,9 +761,9 @@
 
 // Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanf
 // is calculated when frequency changes.
-void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q)
+void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q, LEAF* const leaf)
 {
-    tSVF_initToPool     (svff, type, freq, Q, &leaf.mempool);
+    tSVF_initToPool     (svff, type, freq, Q, &leaf->mempool);
 
     // or maybe this?
     /*
@@ -760,6 +777,8 @@
     _tMempool* m = *mp;
     _tSVF* svf = *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), m);
     svf->mempool = m;
+    
+    LEAF* leaf = svf->mempool->leaf;
 
     svf->type = type;
 
@@ -767,7 +786,7 @@
     svf->ic2eq = 0;
     svf->Q = Q;
     svf->cutoff = freq;
-    svf->g = tanf(PI * freq * leaf.invSampleRate);
+    svf->g = tanf(PI * freq * leaf->invSampleRate);
     svf->k = 1.0f/Q;
     svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
     svf->a2 = svf->g*svf->a1;
@@ -841,8 +860,10 @@
 void     tSVF_setFreq(tSVF* const svff, float freq)
 {
     _tSVF* svf = *svff;
+    LEAF* leaf = svf->mempool->leaf;
+    
     svf->cutoff = freq;
-    svf->g = tanf(PI * freq * leaf.invSampleRate);
+    svf->g = tanf(PI * freq * leaf->invSampleRate);
     svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
     svf->a2 = svf->g * svf->a1;
     svf->a3 = svf->g * svf->a2;
@@ -862,8 +883,10 @@
 void    tSVF_setFreqAndQ(tSVF* const svff, float freq, float Q)
 {
     _tSVF* svf = *svff;
+    LEAF* leaf = svf->mempool->leaf;
+    
     svf->k = 1.0f/Q;
-    svf->g = tanf(PI * freq * leaf.invSampleRate);
+    svf->g = tanf(PI * freq * leaf->invSampleRate);
     svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
     svf->a2 = svf->g * svf->a1;
     svf->a3 = svf->g * svf->a2;
@@ -870,9 +893,9 @@
 }
 
 // Efficient version of tSVF where frequency is set based on 12-bit integer input for lookup in tanh wavetable.
-void   tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q)
+void   tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q, LEAF* const leaf)
 {
-    tEfficientSVF_initToPool(svff, type, input, Q, &leaf.mempool);
+    tEfficientSVF_initToPool(svff, type, input, Q, &leaf->mempool);
 }
 
 void    tEfficientSVF_initToPool    (tEfficientSVF* const svff, SVFType type, uint16_t input, float Q, tMempool* const mp)
@@ -941,9 +964,9 @@
 }
 
 /* Highpass */
-void    tHighpass_init(tHighpass* const ft, float freq)
+void    tHighpass_init(tHighpass* const ft, float freq, LEAF* const leaf)
 {
-    tHighpass_initToPool(ft, freq, &leaf.mempool);
+    tHighpass_initToPool(ft, freq, &leaf->mempool);
 }
 
 void    tHighpass_initToPool    (tHighpass* const ft, float freq, tMempool* const mp)
@@ -952,7 +975,9 @@
     _tHighpass* f = *ft = (_tHighpass*) mpool_calloc(sizeof(_tHighpass), m);
     f->mempool = m;
     
-    f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate));
+    LEAF* leaf = f->mempool->leaf;
+    
+    f->R = (1.0f - (freq * leaf->twoPiTimesInvSampleRate));
     f->ys = 0.0f;
     f->xs = 0.0f;
     
@@ -969,8 +994,10 @@
 void     tHighpass_setFreq(tHighpass* const ft, float freq)
 {
     _tHighpass* f = *ft;
+    LEAF* leaf = f->mempool->leaf;
+    
     f->frequency = freq;
-    f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate));
+    f->R = (1.0f - (freq * leaf->twoPiTimesInvSampleRate));
     
 }
 
@@ -992,12 +1019,14 @@
 void tHighpassSampleRateChanged(tHighpass* const ft)
 {
     _tHighpass* f = *ft;
-    f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf.invSampleRate));
+    LEAF* leaf = f->mempool->leaf;
+    
+    f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf->invSampleRate));
 }
 
-void tButterworth_init(tButterworth* const ft, int N, float f1, float f2)
+void tButterworth_init(tButterworth* const ft, int N, float f1, float f2, LEAF* const leaf)
 {
-    tButterworth_initToPool(ft, N, f1, f2, &leaf.mempool);
+    tButterworth_initToPool(ft, N, f1, f2, &leaf->mempool);
 }
 
 void    tButterworth_initToPool     (tButterworth* const ft, int N, float f1, float f2, tMempool* const mp)
@@ -1075,9 +1104,9 @@
     }
 }
 
-void    tFIR_init(tFIR* const firf, float* coeffs, int numTaps)
+void    tFIR_init(tFIR* const firf, float* coeffs, int numTaps, LEAF* const leaf)
 {
-    tFIR_initToPool(firf, coeffs, numTaps, &leaf.mempool);
+    tFIR_initToPool(firf, coeffs, numTaps, &leaf->mempool);
 }
 
 void    tFIR_initToPool     (tFIR* const firf, float* coeffs, int numTaps, tMempool* const mp)
@@ -1117,9 +1146,9 @@
 /// translated from a Gen~ port of the Supercollider code that I believe was made by Rodrigo Costanzo and which I got from PA Tremblay - JS
 
 
-void    tMedianFilter_init           (tMedianFilter* const f, int size)
+void    tMedianFilter_init           (tMedianFilter* const f, int size, LEAF* const leaf)
 {
-    tMedianFilter_initToPool(f, size, &leaf.mempool);
+    tMedianFilter_initToPool(f, size, &leaf->mempool);
 }
 
 void    tMedianFilter_initToPool     (tMedianFilter* const mf, int size, tMempool* const mp)
@@ -1191,9 +1220,9 @@
 
 /////
 
-void    tVZFilter_init           (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth)
+void    tVZFilter_init  (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth, LEAF* const leaf)
 {
-    tVZFilter_initToPool(vf, type, freq, bandWidth, &leaf.mempool);
+    tVZFilter_initToPool(vf, type, freq, bandWidth, &leaf->mempool);
 }
 
 void    tVZFilter_initToPool     (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth, tMempool* const mp)
@@ -1202,6 +1231,8 @@
     _tVZFilter* f = *vf = (_tVZFilter*) mpool_alloc(sizeof(_tVZFilter), m);
     f->mempool = m;
     
+    LEAF* leaf = f->mempool->leaf;
+    
     f->fc   = freq;
     f->type = type;
     f->G    = ONE_OVER_SQRT2;
@@ -1210,8 +1241,8 @@
     f->m    = 0.0f;
     f->s1 = 0.0f;
     f->s2 = 0.0f;
-    f->sr = leaf.sampleRate;
-    f->inv_sr = leaf.invSampleRate;
+    f->sr = leaf->sampleRate;
+    f->inv_sr = leaf->invSampleRate;
     tVZFilter_calcCoeffs(vf);
 }
 
@@ -1437,14 +1468,18 @@
 void   tVZFilter_setFreq           (tVZFilter* const vf, float freq)
 {
     _tVZFilter* f = *vf;
-    f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate);
+    LEAF* leaf = f->mempool->leaf;
+    
+    f->fc = LEAF_clip(0.0f, freq, 0.5f * leaf->sampleRate);
     tVZFilter_calcCoeffs(vf);
 }
 void   tVZFilter_setFreqAndBandwidth           (tVZFilter* const vf, float freq, float bw)
 {
     _tVZFilter* f = *vf;
+    LEAF* leaf = f->mempool->leaf;
+    
     f->B = LEAF_clip(0.0f,bw, 100.0f);
-    f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate);
+    f->fc = LEAF_clip(0.0f, freq, 0.5f * leaf->sampleRate);
     tVZFilter_calcCoeffs(vf);
 }
 
@@ -1483,9 +1518,9 @@
 
 
 
-void    tDiodeFilter_init           (tDiodeFilter* const vf, float cutoff, float resonance)
+void    tDiodeFilter_init           (tDiodeFilter* const vf, float cutoff, float resonance, LEAF* const leaf)
 {
-    tDiodeFilter_initToPool(vf, cutoff, resonance, &leaf.mempool);
+    tDiodeFilter_initToPool(vf, cutoff, resonance, &leaf->mempool);
 }
 
 void    tDiodeFilter_initToPool     (tDiodeFilter* const vf, float cutoff, float resonance, tMempool* const mp)
@@ -1494,8 +1529,10 @@
      _tDiodeFilter* f = *vf = (_tDiodeFilter*) mpool_alloc(sizeof(_tDiodeFilter), m);
      f->mempool = m;
     
+    LEAF* leaf = f->mempool->leaf;
+    
      // initialization (the resonance factor is between 0 and 8 according to the article)
-     f->f = (float)tan((double)(PI * cutoff/leaf.sampleRate));
+     f->f = (float)tan((double)(PI * cutoff/leaf->sampleRate));
      f->r = (7.f * resonance + 0.5f);
      f->Vt = 0.5f;
      f->n = 1.836f;
@@ -1603,7 +1640,9 @@
 void    tDiodeFilter_setFreq     (tDiodeFilter* const vf, float cutoff)
 {
      _tDiodeFilter* f = *vf;
-     f->f = tanf(PI * LEAF_clip(10.0f, cutoff, 20000.0f)*leaf.invSampleRate);
+    LEAF* leaf = f->mempool->leaf;
+    
+     f->f = tanf(PI * LEAF_clip(10.0f, cutoff, 20000.0f) * leaf->invSampleRate);
 }
 
 
--- a/leaf/Src/leaf-instruments.c
+++ b/leaf/Src/leaf-instruments.c
@@ -18,9 +18,9 @@
 
 // ----------------- COWBELL ----------------------------//
 
-void t808Cowbell_init(t808Cowbell* const cowbellInst, int useStick)
+void t808Cowbell_init(t808Cowbell* const cowbellInst, int useStick, LEAF* const leaf)
 {
-    t808Cowbell_initToPool(cowbellInst, useStick, &leaf.mempool);
+    t808Cowbell_initToPool(cowbellInst, useStick, &leaf->mempool);
 }
 
 void        t808Cowbell_initToPool      (t808Cowbell* const cowbellInst, int useStick, tMempool* const mp)
@@ -143,9 +143,9 @@
 
 // ----------------- HIHAT ----------------------------//
 
-void t808Hihat_init(t808Hihat* const hihatInst)
+void t808Hihat_init(t808Hihat* const hihatInst, LEAF* const leaf)
 {
-    t808Hihat_initToPool(hihatInst, &leaf.mempool);
+    t808Hihat_initToPool(hihatInst, &leaf->mempool);
 }
 
 void    t808Hihat_initToPool  (t808Hihat* const hihatInst, tMempool* const mp)
@@ -311,9 +311,9 @@
 
 // ----------------- SNARE ----------------------------//
 
-void t808Snare_init (t808Snare* const snareInst)
+void t808Snare_init (t808Snare* const snareInst, LEAF* const leaf)
 {
-    t808Snare_initToPool(snareInst, &leaf.mempool);
+    t808Snare_initToPool(snareInst, &leaf->mempool);
 }
 
 void    t808Snare_initToPool    (t808Snare* const snareInst, tMempool* const mp)
@@ -458,9 +458,9 @@
 
 // ----------------- KICK ----------------------------//
 
-void t808Kick_init (t808Kick* const kickInst)
+void t808Kick_init (t808Kick* const kickInst, LEAF* const leaf)
 {
-    t808Kick_initToPool(kickInst, &leaf.mempool);
+    t808Kick_initToPool(kickInst, &leaf->mempool);
 }
 
 void t808Kick_initToPool (t808Kick* const kickInst, tMempool* const mp)
--- a/leaf/Src/leaf-math.c
+++ b/leaf/Src/leaf-math.c
@@ -439,7 +439,7 @@
     }
 }
 
-void LEAF_generate_sawtooth(float* buffer, float basefreq, int size)
+void LEAF_generate_sawtooth(float* buffer, float basefreq, int size, LEAF* const leaf)
 {
     int harmonic = 1;
     float phase = 0.0f;
@@ -446,7 +446,7 @@
     float freq = harmonic * basefreq;
     float amp;
     
-    while (freq < (leaf.sampleRate * 0.5))
+    while (freq < (leaf->sampleRate * 0.5))
     {
         amp = 1.0f / harmonic;
         for (int i = 0; i < size; i++)
@@ -461,7 +461,7 @@
 }
 
 
-void LEAF_generate_triangle(float* buffer, float basefreq, int size)
+void LEAF_generate_triangle(float* buffer, float basefreq, int size, LEAF* const leaf)
 {
     int harmonic = 1;
     float phase = 0.0f;
@@ -471,7 +471,7 @@
     int count = 0;
     float mult = 1.0f;
     
-    while (freq < (leaf.sampleRate * 0.5))
+    while (freq < (leaf->sampleRate * 0.5))
     {
         amp = 1.0f / (float)(harmonic * harmonic);
         
@@ -490,7 +490,7 @@
     }
 }
 
-void LEAF_generate_square(float* buffer, float basefreq, int size)
+void LEAF_generate_square(float* buffer, float basefreq, int size, LEAF* const leaf)
 {
     int harmonic = 1;
     float phase = 0.0f;
@@ -497,7 +497,7 @@
     float freq = harmonic * basefreq;
     float amp = 1.0f;
     
-    while (freq < (leaf.sampleRate * 0.5))
+    while (freq < (leaf->sampleRate * 0.5))
     {
         amp = 1.0f / (float)(harmonic);
         
--- a/leaf/Src/leaf-mempool.c
+++ b/leaf/Src/leaf-mempool.c
@@ -52,7 +52,7 @@
  * private function
  */
 static inline size_t mpool_align(size_t size);
-static inline mpool_node_t* create_node(char* block_location, mpool_node_t* next, mpool_node_t* prev, size_t size);
+static inline mpool_node_t* create_node(char* block_location, mpool_node_t* next, mpool_node_t* prev, size_t size, size_t header_size);
 static inline void delink_node(mpool_node_t* node);
 
 /**
@@ -60,13 +60,13 @@
  */
 void mpool_create (char* memory, size_t size, _tMempool* pool)
 {
-    leaf.header_size = mpool_align(sizeof(mpool_node_t));
+    pool->leaf->header_size = mpool_align(sizeof(mpool_node_t));
     
     pool->mpool = (char*)memory;
     pool->usize  = 0;
     pool->msize  = size;
     
-    pool->head = create_node(pool->mpool, NULL, NULL, pool->msize-leaf.header_size);
+    pool->head = create_node(pool->mpool, NULL, NULL, pool->msize - pool->leaf->header_size, pool->leaf->header_size);
     
     /*
     for (int i = 0; i < pool->head->size; i++)
@@ -77,11 +77,11 @@
     //is zeroing out the memory necessary? This takes a long time on large pools - JS
 }
 
-void leaf_pool_init(char* memory, size_t size)
+void leaf_pool_init(LEAF* const leaf, char* memory, size_t size)
 {
-    mpool_create(memory, size, &leaf._internal_mempool);
+    mpool_create(memory, size, &leaf->_internal_mempool);
     
-    leaf.mempool = &leaf._internal_mempool;
+    leaf->mempool = &leaf->_internal_mempool;
 }
 
 /**
@@ -94,11 +94,11 @@
     {
         if ((pool->msize - pool->usize) > asize)
         {
-            LEAF_internalErrorCallback(LEAFMempoolFragmentation);
+            LEAF_internalErrorCallback(pool->leaf, LEAFMempoolFragmentation);
         }
         else
         {
-            LEAF_internalErrorCallback(LEAFMempoolOverrun);
+            LEAF_internalErrorCallback(pool->leaf, LEAFMempoolOverrun);
         }
         return NULL;
     }
@@ -118,11 +118,11 @@
         {
             if ((pool->msize - pool->usize) > asize)
             {
-                LEAF_internalErrorCallback(LEAFMempoolFragmentation);
+                LEAF_internalErrorCallback(pool->leaf, LEAFMempoolFragmentation);
             }
             else
             {
-                LEAF_internalErrorCallback(LEAFMempoolOverrun);
+                LEAF_internalErrorCallback(pool->leaf, LEAFMempoolOverrun);
             }
             return NULL;
         }
@@ -132,14 +132,14 @@
     mpool_node_t* new_node;
     size_t leftover = node_to_alloc->size - size_to_alloc;
     node_to_alloc->size = size_to_alloc;
-    if (leftover > leaf.header_size)
+    if (leftover > pool->leaf->header_size)
     {
         long offset = (char*) node_to_alloc - (char*) pool->mpool;
-        offset += leaf.header_size + node_to_alloc->size;
+        offset += pool->leaf->header_size + node_to_alloc->size;
         new_node = create_node(&pool->mpool[offset],
                                node_to_alloc->next,
                                node_to_alloc->prev,
-                               leftover - leaf.header_size);
+                               leftover - pool->leaf->header_size, pool->leaf->header_size);
     }
     else
     {
@@ -159,9 +159,9 @@
     // Remove the allocated node from the free list
     delink_node(node_to_alloc);
     
-    pool->usize += leaf.header_size + node_to_alloc->size;
+    pool->usize += pool->leaf->header_size + node_to_alloc->size;
     
-    if (leaf.clearOnAllocation > 0)
+    if (pool->leaf->clearOnAllocation > 0)
     {
         char* new_pool = (char*)node_to_alloc->pool;
         for (int i = 0; i < node_to_alloc->size; i++) new_pool[i] = 0;
@@ -182,11 +182,11 @@
     {
         if ((pool->msize - pool->usize) > asize)
         {
-            LEAF_internalErrorCallback(LEAFMempoolFragmentation);
+            LEAF_internalErrorCallback(pool->leaf, LEAFMempoolFragmentation);
         }
         else
         {
-            LEAF_internalErrorCallback(LEAFMempoolOverrun);
+            LEAF_internalErrorCallback(pool->leaf, LEAFMempoolOverrun);
         }
         return NULL;
     }
@@ -206,11 +206,11 @@
         {
             if ((pool->msize - pool->usize) > asize)
             {
-                LEAF_internalErrorCallback(LEAFMempoolFragmentation);
+                LEAF_internalErrorCallback(pool->leaf, LEAFMempoolFragmentation);
             }
             else
             {
-                LEAF_internalErrorCallback(LEAFMempoolOverrun);
+                LEAF_internalErrorCallback(pool->leaf, LEAFMempoolOverrun);
             }
             return NULL;
         }
@@ -220,14 +220,14 @@
     mpool_node_t* new_node;
     size_t leftover = node_to_alloc->size - size_to_alloc;
     node_to_alloc->size = size_to_alloc;
-    if (leftover > leaf.header_size)
+    if (leftover > pool->leaf->header_size)
     {
         long offset = (char*) node_to_alloc - (char*) pool->mpool;
-        offset += leaf.header_size + node_to_alloc->size;
+        offset += pool->leaf->header_size + node_to_alloc->size;
         new_node = create_node(&pool->mpool[offset],
                                node_to_alloc->next,
                                node_to_alloc->prev,
-                               leftover - leaf.header_size);
+                               leftover - pool->leaf->header_size, pool->leaf->header_size);
     }
     else
     {
@@ -247,7 +247,7 @@
     // Remove the allocated node from the free list
     delink_node(node_to_alloc);
     
-    pool->usize += leaf.header_size + node_to_alloc->size;
+    pool->usize += pool->leaf->header_size + node_to_alloc->size;
     // Format the new pool
     char* new_pool = (char*)node_to_alloc->pool;
     for (int i = 0; i < node_to_alloc->size; i++) new_pool[i] = 0;
@@ -255,18 +255,18 @@
     return node_to_alloc->pool;
 }
 
-char* leaf_alloc(size_t size)
+char* leaf_alloc(LEAF* const leaf, size_t size)
 {
     //printf("alloc %i\n", size);
-    char* block = mpool_alloc(size, &leaf._internal_mempool);
+    char* block = mpool_alloc(size, &leaf->_internal_mempool);
     
     return block;
 }
 
-char* leaf_calloc(size_t size)
+char* leaf_calloc(LEAF* const leaf, size_t size)
 {
     //printf("alloc %i\n", size);
-    char* block = mpool_calloc(size, &leaf._internal_mempool);
+    char* block = mpool_calloc(size, &leaf->_internal_mempool);
 
     return block;
 }
@@ -275,9 +275,9 @@
 {
     //if (ptr < pool->mpool || ptr >= pool->mpool + pool->msize)
     // Get the node at the freed space
-    mpool_node_t* freed_node = (mpool_node_t*) (ptr - leaf.header_size);
+    mpool_node_t* freed_node = (mpool_node_t*) (ptr - pool->leaf->header_size);
     
-    pool->usize -= leaf.header_size + freed_node->size;
+    pool->usize -= pool->leaf->header_size + freed_node->size;
     
     // Check each node in the list against the newly freed one to see if it's adjacent in memory
     mpool_node_t* other_node = pool->head;
@@ -287,15 +287,15 @@
         if ((long) other_node < (long) pool->mpool ||
             (long) other_node >= (((long) pool->mpool) + pool->msize))
         {
-            LEAF_internalErrorCallback(LEAFInvalidFree);
+            LEAF_internalErrorCallback(pool->leaf, LEAFInvalidFree);
             return;
         }
         next_node = other_node->next;
         // Check if a node is directly after the freed node
-        if (((long) freed_node) + (leaf.header_size + freed_node->size) == (long) other_node)
+        if (((long) freed_node) + (pool->leaf->header_size + freed_node->size) == (long) other_node)
         {
             // Increase freed node's size
-            freed_node->size += leaf.header_size + other_node->size;
+            freed_node->size += pool->leaf->header_size + other_node->size;
             // If we are merging with the head, move the head forward
             if (other_node == pool->head) pool->head = pool->head->next;
             // Delink the merged node
@@ -303,10 +303,10 @@
         }
         
         // Check if a node is directly before the freed node
-        else if (((long) other_node) + (leaf.header_size + other_node->size) == (long) freed_node)
+        else if (((long) other_node) + (pool->leaf->header_size + other_node->size) == (long) freed_node)
         {
             // Increase the merging node's size
-            other_node->size += leaf.header_size + freed_node->size;
+            other_node->size += pool->leaf->header_size + freed_node->size;
             
             if (other_node != pool->head)
             {
@@ -339,9 +339,9 @@
     //    for (int i = 0; i < freed_node->size; i++) freed_pool[i] = 0;
 }
 
-void leaf_free(char* ptr)
+void leaf_free(LEAF* const leaf, char* ptr)
 {
-    mpool_free(ptr, &leaf._internal_mempool);
+    mpool_free(ptr, &leaf->_internal_mempool);
 }
 
 size_t mpool_get_size(_tMempool* pool)
@@ -354,19 +354,19 @@
     return pool->usize;
 }
 
-size_t leaf_pool_get_size(void)
+size_t leaf_pool_get_size(LEAF* const leaf)
 {
-    return mpool_get_size(&leaf._internal_mempool);
+    return mpool_get_size(&leaf->_internal_mempool);
 }
 
-size_t leaf_pool_get_used(void)
+size_t leaf_pool_get_used(LEAF* const leaf)
 {
-    return mpool_get_used(&leaf._internal_mempool);
+    return mpool_get_used(&leaf->_internal_mempool);
 }
 
-char* leaf_pool_get_pool(void)
+char* leaf_pool_get_pool(LEAF* const leaf)
 {
-    char* buff = leaf._internal_mempool.mpool;
+    char* buff = leaf->_internal_mempool.mpool;
     
     return buff;
 }
@@ -378,10 +378,10 @@
     return (size + (MPOOL_ALIGN_SIZE - 1)) & ~(MPOOL_ALIGN_SIZE - 1);
 }
 
-static inline mpool_node_t* create_node(char* block_location, mpool_node_t* next, mpool_node_t* prev, size_t size)
+static inline mpool_node_t* create_node(char* block_location, mpool_node_t* next, mpool_node_t* prev, size_t size, size_t header_size)
 {
     mpool_node_t* node = (mpool_node_t*)block_location;
-    node->pool = block_location + leaf.header_size;
+    node->pool = block_location + header_size;
     node->next = next;
     node->prev = prev;
     node->size = size;
@@ -408,14 +408,16 @@
     node->prev = NULL;
 }
 
-void tMempool_init(tMempool* const mp, char* memory, size_t size)
+void tMempool_init(tMempool* const mp, char* memory, size_t size, LEAF* const leaf)
 {
-    tMempool_initToPool(mp, memory, size, &leaf.mempool);
+    tMempool_initToPool(mp, memory, size, &leaf->mempool);
 }
 
 void tMempool_free(tMempool* const mp)
 {
-    tMempool_freeFromPool(mp, &leaf.mempool);
+    _tMempool* m = *mp;
+
+    mpool_free((char*)m, m->mempool);
 }
 
 void    tMempool_initToPool     (tMempool* const mp, char* memory, size_t size, tMempool* const mem)
@@ -424,12 +426,4 @@
     _tMempool* m = *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), mm);
     
     mpool_create (memory, size, m);
-}
-
-void    tMempool_freeFromPool   (tMempool* const mp, tMempool* const mem)
-{
-    _tMempool* mm = *mem;
-    _tMempool* m = *mp;
-    
-    mpool_free((char*)m, mm);
 }
--- a/leaf/Src/leaf-midi.c
+++ b/leaf/Src/leaf-midi.c
@@ -20,9 +20,9 @@
 /* Stack */
 //====================================================================================
 
-void tStack_init(tStack* const stack)
+void tStack_init(tStack* const stack, LEAF* const leaf)
 {
-    tStack_initToPool(stack, &leaf.mempool);
+    tStack_initToPool(stack, &leaf->mempool);
 }
 
 void    tStack_initToPool           (tStack* const stack, tMempool* const mp)
@@ -256,9 +256,9 @@
 
 
 // POLY
-void tPoly_init(tPoly* const polyh, int maxNumVoices)
+void tPoly_init(tPoly* const polyh, int maxNumVoices, LEAF* const leaf)
 {
-    tPoly_initToPool(polyh, maxNumVoices, &leaf.mempool);
+    tPoly_initToPool(polyh, maxNumVoices, &leaf->mempool);
 }
 
 void    tPoly_initToPool            (tPoly* const polyh, int maxNumVoices, tMempool* const mp)
@@ -612,9 +612,9 @@
 
 
 // SIMPLE POLY
-void tSimplePoly_init(tSimplePoly* const polyh, int maxNumVoices)
+void tSimplePoly_init(tSimplePoly* const polyh, int maxNumVoices, LEAF* const leaf)
 {
-    tSimplePoly_initToPool(polyh, maxNumVoices, &leaf.mempool);
+    tSimplePoly_initToPool(polyh, maxNumVoices, &leaf->mempool);
 }
 
 void    tSimplePoly_initToPool            (tSimplePoly* const polyh, int maxNumVoices, tMempool* const mp)
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -17,9 +17,9 @@
 #endif
 
 // WaveTable
-void    tTable_init(tTable* const cy, float* waveTable, int size)
+void    tTable_init(tTable* const cy, float* waveTable, int size, LEAF* const leaf)
 {
-    tTable_initToPool(cy, waveTable, size, &leaf.mempool);
+    tTable_initToPool(cy, waveTable, size, &leaf->mempool);
 }
 
 void    tTable_initToPool(tTable* const cy, float* waveTable, int size, tMempool* const mp)
@@ -44,11 +44,12 @@
 void     tTable_setFreq(tTable* const cy, float freq)
 {
     _tTable* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
     if (!isfinite(freq)) return;
     
     c->freq = freq;
-    c->inc = freq * leaf.invSampleRate;
+    c->inc = freq * leaf->invSampleRate;
 }
 
 float   tTable_tick(tTable* const cy)
@@ -81,14 +82,15 @@
 void     tTableSampleRateChanged(tTable* const cy)
 {
     _tTable* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
 }
 
 // Cycle
-void    tCycle_init(tCycle* const cy)
+void    tCycle_init(tCycle* const cy, LEAF* const leaf)
 {
-    tCycle_initToPool(cy, &leaf.mempool);
+    tCycle_initToPool(cy, &leaf->mempool);
 }
 
 void    tCycle_initToPool   (tCycle* const cy, tMempool* const mp)
@@ -111,12 +113,13 @@
 void     tCycle_setFreq(tCycle* const cy, float freq)
 {
     _tCycle* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
     if (!isfinite(freq)) return;
     
     c->freq  = freq;
 
-    c->inc = freq * leaf.invSampleRate;
+    c->inc = freq * leaf->invSampleRate;
 }
 
 //need to check bounds and wrap table properly to allow through-zero FM
@@ -149,15 +152,16 @@
 void     tCycleSampleRateChanged (tCycle* const cy)
 {
     _tCycle* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
 }
 
 //========================================================================
 /* Triangle */
-void   tTriangle_init(tTriangle* const cy)
+void   tTriangle_init(tTriangle* const cy, LEAF* const leaf)
 {
-    tTriangle_initToPool(cy, &leaf.mempool);
+    tTriangle_initToPool(cy, &leaf->mempool);
 }
 
 void    tTriangle_initToPool    (tTriangle* const cy, tMempool* const mp)
@@ -181,10 +185,11 @@
 void tTriangle_setFreq(tTriangle* const cy, float freq)
 {
     _tTriangle* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
     c->freq  = freq;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
     
     c->w = c->freq * INV_20;
     for (c->oct = 0; c->w > 2.0f; c->oct++)
@@ -218,15 +223,16 @@
 void     tTriangleSampleRateChanged (tTriangle* const cy)
 {
     _tTriangle* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
 }
 
 //========================================================================
 /* Square */
-void   tSquare_init(tSquare* const cy)
+void   tSquare_init(tSquare* const cy, LEAF* const leaf)
 {
-    tSquare_initToPool(cy, &leaf.mempool);
+    tSquare_initToPool(cy, &leaf->mempool);
 }
 
 void    tSquare_initToPool  (tSquare* const cy, tMempool* const mp)
@@ -250,10 +256,11 @@
 void    tSquare_setFreq(tSquare* const cy, float freq)
 {
     _tSquare* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
 
     c->freq  = freq;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
     
     c->w = c->freq * INV_20;
     for (c->oct = 0; c->w > 2.0f; c->oct++)
@@ -286,15 +293,16 @@
 void     tSquareSampleRateChanged (tSquare* const cy)
 {
     _tSquare* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
 }
 
 //=====================================================================
 // Sawtooth
-void    tSawtooth_init(tSawtooth* const cy)
+void    tSawtooth_init(tSawtooth* const cy, LEAF* const leaf)
 {
-    tSawtooth_initToPool(cy, &leaf.mempool);
+    tSawtooth_initToPool(cy, &leaf->mempool);
 }
 
 void    tSawtooth_initToPool    (tSawtooth* const cy, tMempool* const mp)
@@ -318,10 +326,11 @@
 void    tSawtooth_setFreq(tSawtooth* const cy, float freq)
 {
     _tSawtooth* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
     c->freq  = freq;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
     
     c->w = c->freq * INV_20;
     for (c->oct = 0; c->w > 2.0f; c->oct++)
@@ -354,16 +363,17 @@
 void     tSawtoothSampleRateChanged (tSawtooth* const cy)
 {
     _tSawtooth* c = *cy;
+    LEAF* leaf = c->mempool->leaf;
     
-    c->inc = c->freq * leaf.invSampleRate;
+    c->inc = c->freq * leaf->invSampleRate;
 }
 
 //==============================================================================
 
 /* tTri: Anti-aliased Triangle waveform. */
-void    tTri_init          (tTri* const osc)
+void    tTri_init          (tTri* const osc, LEAF* const leaf)
 {
-    tTri_initToPool(osc, &leaf.mempool);
+    tTri_initToPool(osc, &leaf->mempool);
 }
 
 void    tTri_initToPool    (tTri* const osc, tMempool* const mp)
@@ -421,9 +431,10 @@
 void    tTri_setFreq       (tTri* const osc, float freq)
 {
     _tTri* c = *osc;
+    LEAF* leaf = c->mempool->leaf;
     
     c->freq  = freq;
-    c->inc = freq * leaf.invSampleRate;
+    c->inc = freq * leaf->invSampleRate;
 }
 
 void    tTri_setSkew       (tTri* const osc, float skew)
@@ -436,9 +447,9 @@
 //==============================================================================
 
 /* tPulse: Anti-aliased pulse waveform. */
-void    tPulse_init        (tPulse* const osc)
+void    tPulse_init        (tPulse* const osc, LEAF* const leaf)
 {
-    tPulse_initToPool(osc, &leaf.mempool);
+    tPulse_initToPool(osc, &leaf->mempool);
 }
 
 void    tPulse_initToPool  (tPulse* const osc, tMempool* const mp)
@@ -481,9 +492,10 @@
 void    tPulse_setFreq     (tPulse* const osc, float freq)
 {
     _tPulse* c = *osc;
+    LEAF* leaf = c->mempool->leaf;
     
     c->freq  = freq;
-    c->inc = freq * leaf.invSampleRate;
+    c->inc = freq * leaf->invSampleRate;
 }
 
 void    tPulse_setWidth    (tPulse* const osc, float width)
@@ -496,9 +508,9 @@
 //==============================================================================
 
 /* tSawtooth: Anti-aliased Sawtooth waveform. */
-void    tSaw_init          (tSaw* const osc)
+void    tSaw_init          (tSaw* const osc, LEAF* const leaf)
 {
-    tSaw_initToPool(osc, &leaf.mempool);
+    tSaw_initToPool(osc, &leaf->mempool);
 }
 
 void    tSaw_initToPool    (tSaw* const osc, tMempool* const mp)
@@ -537,10 +549,11 @@
 void    tSaw_setFreq       (tSaw* const osc, float freq)
 {
     _tSaw* c = *osc;
+    LEAF* leaf = c->mempool->leaf;
     
     c->freq  = freq;
     
-    c->inc = freq * leaf.invSampleRate;
+    c->inc = freq * leaf->invSampleRate;
 }
 
 //========================================================================
@@ -548,13 +561,14 @@
 void     tPhasorSampleRateChanged (tPhasor* const ph)
 {
     _tPhasor* p = *ph;
+    LEAF* leaf = p->mempool->leaf;
     
-    p->inc = p->freq * leaf.invSampleRate;
+    p->inc = p->freq * leaf->invSampleRate;
 };
 
-void    tPhasor_init(tPhasor* const ph)
+void    tPhasor_init(tPhasor* const ph, LEAF* const leaf)
 {
-    tPhasor_initToPool(ph, &leaf.mempool);
+    tPhasor_initToPool(ph, &leaf->mempool);
 }
 
 void    tPhasor_initToPool  (tPhasor* const ph, tMempool* const mp)
@@ -578,10 +592,11 @@
 void    tPhasor_setFreq(tPhasor* const ph, float freq)
 {
     _tPhasor* p = *ph;
+    LEAF* leaf = p->mempool->leaf;
 
     p->freq  = freq;
     
-    p->inc = freq * leaf.invSampleRate;
+    p->inc = freq * leaf->invSampleRate;
 }
 
 float   tPhasor_tick(tPhasor* const ph)
@@ -602,9 +617,9 @@
 }
 
 /* Noise */
-void    tNoise_init(tNoise* const ns, NoiseType type)
+void    tNoise_init(tNoise* const ns, NoiseType type, LEAF* const leaf)
 {
-    tNoise_initToPool(ns, type, &leaf.mempool);
+    tNoise_initToPool(ns, type, &leaf->mempool);
 }
 
 void    tNoise_initToPool   (tNoise* const ns, NoiseType type, tMempool* const mp)
@@ -612,9 +627,10 @@
     _tMempool* m = *mp;
     _tNoise* n = *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), m);
     n->mempool = m;
+    LEAF* leaf = n->mempool->leaf;
     
     n->type = type;
-    n->rand = leaf.random;
+    n->rand = leaf->random;
 }
 
 void    tNoise_free (tNoise* const ns)
@@ -653,9 +669,9 @@
     
 }
 
-void    tNeuron_init(tNeuron* const nr)
+void    tNeuron_init(tNeuron* const nr, LEAF* const leaf)
 {
-    tNeuron_initToPool(nr, &leaf.mempool);
+    tNeuron_initToPool(nr, &leaf->mempool);
 }
 
 void    tNeuron_initToPool  (tNeuron* const nr, tMempool* const mp)
@@ -871,9 +887,9 @@
 
 //----------------------------------------------------------------------------------------------------------
 
-void tMBPulse_init(tMBPulse* const osc)
+void tMBPulse_init(tMBPulse* const osc, LEAF* const leaf)
 {
-    tMBPulse_initToPool(osc, &leaf.mempool);
+    tMBPulse_initToPool(osc, &leaf->mempool);
 }
                           
 void tMBPulse_initToPool(tMBPulse* const osc, tMempool* const pool)
@@ -901,6 +917,7 @@
 float tMBPulse_tick(tMBPulse* const osc)
 {
     _tMBPulse* c = *osc;
+    LEAF* leaf = c->mempool->leaf;
     
     int    j, k;
     float  freq, syncin;
@@ -919,7 +936,7 @@
     if (c->_init) {
         p = 0.0f;
         
-        w = freq / leaf.sampleRate;
+        w = freq / leaf->sampleRate;
         if (w < 1e-5f) w = 1e-5f;
         if (w > 0.5f) w = 0.5f;
         b = 0.5f * (1.0f + c->waveform );
@@ -940,7 +957,7 @@
     //    a = 0.2 + 0.8 * vco->_port [FILT];
     a = 0.5f; // when a = 1, LPfilter is disabled
     
-    t = freq / leaf.sampleRate;
+    t = freq / leaf->sampleRate;
     if (t < 1e-5f) t = 1e-5f;
     if (t > 0.5f) t = 0.5f;
     dw = (t - w) ;
@@ -1083,9 +1100,9 @@
 
 //----------------------------------------------------------------------------------------------------------
 
-void tMBTriangle_init(tMBTriangle* const osc)
+void tMBTriangle_init(tMBTriangle* const osc, LEAF* const leaf)
 {
-    tMBTriangle_initToPool(osc, &leaf.mempool);
+    tMBTriangle_initToPool(osc, &leaf->mempool);
 }
 
 void tMBTriangle_initToPool(tMBTriangle* const osc, tMempool* const pool)
@@ -1113,6 +1130,7 @@
 float tMBTriangle_tick(tMBTriangle* const osc)
 {
     _tMBTriangle* c = *osc;
+    LEAF* leaf = c->mempool->leaf;
     
     int    j, k;
     float  freq, syncin;
@@ -1130,7 +1148,7 @@
     if (c->_init) {
         //        w = (exp2ap (freq[1] + vco->_port[OCTN] + vco->_port[TUNE] + expm[1] * vco->_port[EXPG] + 8.03136)
         //                + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE;
-        w = freq / leaf.sampleRate;
+        w = freq / leaf->sampleRate;
         if (w < 1e-5f) w = 1e-5f;
         if (w > 0.5f) w = 0.5f;
         b = 0.5f * (1.0f + c->waveform);
@@ -1147,7 +1165,7 @@
     //    a = 0.2 + 0.8 * vco->_port [FILT];
     a = 0.5f; // when a = 1, LPfilter is disabled
     
-    t = freq / leaf.sampleRate;
+    t = freq / leaf->sampleRate;
     if (t < 1e-5f) t = 1e-5f;
     if (t > 0.5f) t = 0.5f;
     dw = (t - w) ;
@@ -1294,9 +1312,9 @@
 
 //----------------------------------------------------------------------------------------------------------
 
-void tMBSaw_init(tMBSaw* const osc)
+void tMBSaw_init(tMBSaw* const osc, LEAF* const leaf)
 {
-    tMBSaw_initToPool(osc, &leaf.mempool);
+    tMBSaw_initToPool(osc, &leaf->mempool);
 }
 
 void tMBSaw_initToPool(tMBSaw* const osc, tMempool* const pool)
@@ -1323,6 +1341,7 @@
 float tMBSaw_tick(tMBSaw* const osc)
 {
     _tMBSaw* c = *osc;
+    LEAF* leaf = c->mempool->leaf;
     
     int    j;
     float  freq, syncin;
@@ -1337,7 +1356,7 @@
     
     if (c->_init) {
         p = 0.5f;
-        w = freq / leaf.sampleRate;
+        w = freq / leaf->sampleRate;
         if (w < 1e-5f) w = 1e-5f;
         if (w > 0.5f) w = 0.5f;
         /* if we valued alias-free startup over low startup time, we could do:
@@ -1349,7 +1368,7 @@
     //a = 0.2 + 0.8 * vco->_port [FILT];
     a = 0.5f; // when a = 1, LPfilter is disabled
     
-    t = freq / leaf.sampleRate;
+    t = freq / leaf->sampleRate;
     if (t < 1e-5f) t = 1e-5f;
     if (t > 0.5f) t = 0.5f;
     dw = (t - w); // n= 1
--- a/leaf/Src/leaf-physical.c
+++ b/leaf/Src/leaf-physical.c
@@ -17,9 +17,9 @@
 #endif
 
 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tPluck ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
-void    tPluck_init         (tPluck* const pl, float lowestFrequency)
+void    tPluck_init         (tPluck* const pl, float lowestFrequency, LEAF* const leaf)
 {
-    tPluck_initToPool(pl, lowestFrequency, &leaf.mempool);
+    tPluck_initToPool(pl, lowestFrequency, &leaf->mempool);
 }
 
 void    tPluck_initToPool    (tPluck* const pl, float lowestFrequency, tMempool* const mp)
@@ -27,6 +27,7 @@
     _tMempool* m = *mp;
     _tPluck* p = *pl = (_tPluck*) mpool_alloc(sizeof(_tPluck), m);
     p->mempool = m;
+    LEAF* leaf = p->mempool->leaf;
     
     if ( lowestFrequency <= 0.0f )  lowestFrequency = 10.0f;
     
@@ -36,7 +37,7 @@
     
     tOneZero_initToPool(&p->loopFilter, 0.0f, mp);
     
-    tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp);
+    tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf->sampleRate * 2, mp);
     tAllpassDelay_clear(&p->delayLine);
     
     tPluck_setFrequency(pl, 220.0f);
@@ -105,11 +106,12 @@
 void    tPluck_setFrequency  (tPluck* const pl, float frequency )
 {
     _tPluck* p = *pl;
+    LEAF* leaf = p->mempool->leaf;
     
     if ( frequency <= 0.0f )   frequency = 0.001f;
     
     // Delay = length - filter delay.
-    float delay = ( leaf.sampleRate / frequency ) - tOneZero_getPhaseDelay(&p->loopFilter, frequency );
+    float delay = ( leaf->sampleRate / frequency ) - tOneZero_getPhaseDelay(&p->loopFilter, frequency );
     
     tAllpassDelay_setDelay(&p->delayLine, delay );
     
@@ -132,9 +134,9 @@
 }
 
 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tKarplusStrong ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
-void    tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency)
+void    tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency, LEAF* const leaf)
 {
-    tKarplusStrong_initToPool(pl, lowestFrequency, &leaf.mempool);
+    tKarplusStrong_initToPool(pl, lowestFrequency, &leaf->mempool);
 }
 
 void    tKarplusStrong_initToPool   (tKarplusStrong* const pl, float lowestFrequency, tMempool* const mp)
@@ -142,13 +144,14 @@
     _tMempool* m = *mp;
     _tKarplusStrong* p = *pl = (_tKarplusStrong*) mpool_alloc(sizeof(_tKarplusStrong), m);
     p->mempool = m;
+    LEAF* leaf = p->mempool->leaf;
     
     if ( lowestFrequency <= 0.0f )  lowestFrequency = 8.0f;
     
-    tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp);
+    tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf->sampleRate * 2, mp);
     tAllpassDelay_clear(&p->delayLine);
     
-    tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf.sampleRate * 2, mp);
+    tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf->sampleRate * 2, mp);
     tLinearDelay_clear(&p->combDelay);
     
     tOneZero_initToPool(&p->filter, 0.0f, mp);
@@ -251,11 +254,12 @@
 void    tKarplusStrong_setFrequency  (tKarplusStrong* const pl, float frequency )
 {
     _tKarplusStrong* p = *pl;
+    LEAF* leaf = p->mempool->leaf;
     
     if ( frequency <= 0.0f )   frequency = 0.001f;
     
     p->lastFrequency = frequency;
-    p->lastLength = leaf.sampleRate / p->lastFrequency;
+    p->lastLength = leaf->sampleRate / p->lastFrequency;
     float delay = p->lastLength - 0.5f;
     tAllpassDelay_setDelay(&p->delayLine, delay);
     
@@ -270,14 +274,15 @@
 }
 
 // Set the stretch "factor" of the string (0.0 - 1.0).
-void    tKarplusStrong_setStretch         (tKarplusStrong* const pl, float stretch )
+void    tKarplusStrong_setStretch         (tKarplusStrong* const pl, float stretch)
 {
     _tKarplusStrong* p = *pl;
+    LEAF* leaf = p->mempool->leaf;
     
     p->stretching = stretch;
     float coefficient;
     float freq = p->lastFrequency * 2.0f;
-    float dFreq = ( (0.5f * leaf.sampleRate) - freq ) * 0.25f;
+    float dFreq = ( (0.5f * leaf->sampleRate) - freq ) * 0.25f;
     float temp = 0.5f + (stretch * 0.5f);
     if ( temp > 0.9999f ) temp = 0.9999f;
     
@@ -288,7 +293,7 @@
         tBiQuad_setB0(&p->biquad[i], coefficient);
         tBiQuad_setB2(&p->biquad[i], 1.0f);
         
-        coefficient = -2.0f * temp * cosf(TWO_PI * freq / leaf.sampleRate);
+        coefficient = -2.0f * temp * cosf(TWO_PI * freq / leaf->sampleRate);
         tBiQuad_setA1(&p->biquad[i], coefficient);
         tBiQuad_setB1(&p->biquad[i], coefficient);
         
@@ -346,9 +351,9 @@
 
 void    tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, float dampFreq,
                                  float decay, float targetLev, float levSmoothFactor,
-                                 float levStrength, int levMode)
+                                 float levStrength, int levMode, LEAF* const leaf)
 {
-    tSimpleLivingString_initToPool(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf.mempool);
+    tSimpleLivingString_initToPool(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf->mempool);
 }
 
 void    tSimpleLivingString_initToPool  (tSimpleLivingString* const pl, float freq, float dampFreq,
@@ -358,9 +363,10 @@
     _tMempool* m = *mp;
     _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) mpool_alloc(sizeof(_tSimpleLivingString), m);
     p->mempool = m;
+    LEAF* leaf = p->mempool->leaf;
     
     p->curr=0.0f;
-    tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
+    tExpSmooth_initToPool(&p->wlSmooth, leaf->sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
     tSimpleLivingString_setFreq(pl, freq);
     tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp);
     tLinearDelay_clear(&p->delayLine);
@@ -387,10 +393,11 @@
 void     tSimpleLivingString_setFreq(tSimpleLivingString* const pl, float freq)
 {
     _tSimpleLivingString* p = *pl;
+    LEAF* leaf = p->mempool->leaf;
     
     if (freq<20) freq=20;
     else if (freq>10000) freq=10000;
-    p->waveLengthInSamples = leaf.sampleRate/freq;
+    p->waveLengthInSamples = leaf->sampleRate/freq;
     tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
 }
 
@@ -463,9 +470,9 @@
 
 void    tLivingString_init(tLivingString* const pl, float freq, float pickPos, float prepIndex,
                            float dampFreq, float decay, float targetLev, float levSmoothFactor,
-                           float levStrength, int levMode)
+                           float levStrength, int levMode, LEAF* const leaf)
 {
-    tLivingString_initToPool(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf.mempool);
+    tLivingString_initToPool(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf->mempool);
 }
 
 void    tLivingString_initToPool    (tLivingString* const pl, float freq, float pickPos, float prepIndex,
@@ -475,9 +482,10 @@
     _tMempool* m = *mp;
     _tLivingString* p = *pl = (_tLivingString*) mpool_alloc(sizeof(_tLivingString), m);
     p->mempool = m;
+    LEAF* leaf = p->mempool->leaf;
     
     p->curr=0.0f;
-    tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
+    tExpSmooth_initToPool(&p->wlSmooth, leaf->sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
     tLivingString_setFreq(pl, freq);
     p->freq = freq;
     tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01f, mp); // smoother for pick position
@@ -530,9 +538,11 @@
 void     tLivingString_setFreq(tLivingString* const pl, float freq)
 {    // NOTE: It is faster to set wavelength in samples directly
     _tLivingString* p = *pl;
+    LEAF* leaf = p->mempool->leaf;
+    
     if (freq<20.f) freq=20.f;
     else if (freq>10000.f) freq=10000.f;
-    p->waveLengthInSamples = leaf.sampleRate/freq;
+    p->waveLengthInSamples = leaf->sampleRate/freq;
     tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
 }
 
@@ -655,9 +665,9 @@
 
 void    tComplexLivingString_init(tComplexLivingString* const pl, float freq, float pickPos, float prepPos, float prepIndex,
                            float dampFreq, float decay, float targetLev, float levSmoothFactor,
-                           float levStrength, int levMode)
+                           float levStrength, int levMode, LEAF* const leaf)
 {
-    tComplexLivingString_initToPool(pl, freq, pickPos, prepPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf.mempool);
+    tComplexLivingString_initToPool(pl, freq, pickPos, prepPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf->mempool);
 }
 
 void    tComplexLivingString_initToPool    (tComplexLivingString* const pl, float freq, float pickPos, float prepPos, float prepIndex,
@@ -667,9 +677,10 @@
     _tMempool* m = *mp;
     _tComplexLivingString* p = *pl = (_tComplexLivingString*) mpool_alloc(sizeof(_tComplexLivingString), m);
     p->mempool = m;
+    LEAF* leaf = p->mempool->leaf;
 
     p->curr=0.0f;
-    tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
+    tExpSmooth_initToPool(&p->wlSmooth, leaf->sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
     tComplexLivingString_setFreq(pl, freq);
     p->freq = freq;
     tExpSmooth_initToPool(&p->pickPosSmooth, pickPos, 0.01f, mp); // smoother for pick position
@@ -697,8 +708,8 @@
     tOnePole_initToPool(&p->nutFilter, dampFreq, mp);
     tOnePole_initToPool(&p->prepFilterU, dampFreq, mp);
     tOnePole_initToPool(&p->prepFilterL, dampFreq, mp);
-    tHighpass_initToPool(&p->DCblockerU,13, mp);
-    tHighpass_initToPool(&p->DCblockerL,13, mp);
+    tHighpass_initToPool(&p->DCblockerU, 13, mp);
+    tHighpass_initToPool(&p->DCblockerL, 13, mp);
     p->decay=decay;
     p->prepIndex = prepIndex;
     tFeedbackLeveler_initToPool(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode, mp);
@@ -734,9 +745,11 @@
 void     tComplexLivingString_setFreq(tComplexLivingString* const pl, float freq)
 {    // NOTE: It is faster to set wavelength in samples directly
     _tComplexLivingString* p = *pl;
+    LEAF* leaf = p->mempool->leaf;
+    
     if (freq<20.0f) freq=20.0f;
     else if (freq>10000.0f) freq=10000.0f;
-    p->waveLengthInSamples = leaf.sampleRate/freq;
+    p->waveLengthInSamples = leaf->sampleRate/freq;
     tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples);
 }
 
@@ -892,9 +905,9 @@
 ///Reed Table model
 //default values from STK are 0.6 offset and -0.8 slope
 
-void    tReedTable_init      (tReedTable* const pm, float offset, float slope)
+void    tReedTable_init      (tReedTable* const pm, float offset, float slope, LEAF* const leaf)
 {
-    tReedTable_initToPool(pm, offset, slope, &leaf.mempool);
+    tReedTable_initToPool(pm, offset, slope, &leaf->mempool);
 }
 
 void    tReedTable_initToPool   (tReedTable* const pm, float offset, float slope, tMempool* const mp)
--- a/leaf/Src/leaf-reverb.c
+++ b/leaf/Src/leaf-reverb.c
@@ -19,9 +19,9 @@
 #endif
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PRCReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
-void    tPRCReverb_init(tPRCReverb* const rev, float t60)
+void    tPRCReverb_init(tPRCReverb* const rev, float t60, LEAF* const leaf)
 {
-    tPRCReverb_initToPool(rev, t60, &leaf.mempool);
+    tPRCReverb_initToPool(rev, t60, &leaf->mempool);
 }
 
 void    tPRCReverb_initToPool   (tPRCReverb* const rev, float t60, tMempool* const mp)
@@ -29,6 +29,7 @@
     _tMempool* m = *mp;
     _tPRCReverb* r = *rev = (_tPRCReverb*) mpool_alloc(sizeof(_tPRCReverb), m);
     r->mempool = m;
+    LEAF* leaf = r->mempool->leaf;
     
     if (t60 <= 0.0f) t60 = 0.001f;
     
@@ -35,7 +36,7 @@
     r->inv_441 = 1.0f/44100.0f;
     
     int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate.
-    double scaler = leaf.sampleRate * r->inv_441;
+    double scaler = leaf->sampleRate * r->inv_441;
     
     int delay, i;
     if (scaler != 1.0f)
@@ -84,12 +85,13 @@
 void    tPRCReverb_setT60(tPRCReverb* const rev, float t60)
 {
     _tPRCReverb* r = *rev;
+    LEAF* leaf = r->mempool->leaf;
     
     if ( t60 <= 0.0f ) t60 = 0.001f;
     
     r->t60 = t60;
     
-    r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / t60 ));
+    r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf->invSampleRate / t60 ));
     
 }
 
@@ -136,13 +138,15 @@
 void     tPRCReverbSampleRateChanged (tPRCReverb* const rev)
 {
     _tPRCReverb* r = *rev;
-    r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / r->t60 ));
+    LEAF* leaf = r->mempool->leaf;
+    
+    r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf->invSampleRate / r->t60 ));
 }
 
 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
-void    tNReverb_init(tNReverb* const rev, float t60)
+void    tNReverb_init(tNReverb* const rev, float t60, LEAF* const leaf)
 {
-    tNReverb_initToPool(rev, t60, &leaf.mempool);
+    tNReverb_initToPool(rev, t60, &leaf->mempool);
 }
 
 void    tNReverb_initToPool     (tNReverb* const rev, float t60, tMempool* const mp)
@@ -150,6 +154,7 @@
     _tMempool* m = *mp;
     _tNReverb* r = *rev = (_tNReverb*) mpool_alloc(sizeof(_tNReverb), m);
     r->mempool = m;
+    LEAF* leaf = r->mempool->leaf;
     
     if (t60 <= 0.0f) t60 = 0.001f;
     
@@ -156,7 +161,7 @@
     r->inv_441 = 1.0f/44100.0f;
     
     int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.
-    double scaler = leaf.sampleRate / 25641.0f;
+    double scaler = leaf->sampleRate / 25641.0f;
     
     int delay, i;
     
@@ -174,7 +179,7 @@
     {
         tLinearDelay_initToPool(&r->combDelays[i], lengths[i], lengths[i] * 2, mp);
         tLinearDelay_clear(&r->combDelays[i]);
-        r->combCoeffs[i] = powf(10.0f, (-3.0f * (float)lengths[i] * leaf.invSampleRate / t60));
+        r->combCoeffs[i] = powf(10.0f, (-3.0f * (float)lengths[i] * leaf->invSampleRate / t60));
     }
     
     for ( i=0; i<8; i++ )
@@ -209,12 +214,13 @@
 void    tNReverb_setT60(tNReverb* const rev, float t60)
 {
     _tNReverb* r = *rev;
+    LEAF* leaf = r->mempool->leaf;
     
     if (t60 <= 0.0f)           t60 = 0.001f;
     
     r->t60 = t60;
     
-    for (int i=0; i<6; i++)   r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 ));
+    for (int i=0; i<6; i++)   r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf->invSampleRate / t60 ));
     
 }
 
@@ -351,7 +357,9 @@
 void     tNReverbSampleRateChanged (tNReverb* const rev)
 {
     _tNReverb* r = *rev;
-    for (int i=0; i<6; i++)   r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 ));
+    LEAF* leaf = r->mempool->leaf;
+    
+    for (int i=0; i<6; i++)   r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf->invSampleRate / r->t60 ));
 }
 
 // ======================================DATTORRO=========================================
@@ -362,9 +370,9 @@
 float       in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f };
 
 
-void    tDattorroReverb_init              (tDattorroReverb* const rev)
+void    tDattorroReverb_init              (tDattorroReverb* const rev, LEAF* const leaf)
 {
-    tDattorroReverb_initToPool(rev, &leaf.mempool);
+    tDattorroReverb_initToPool(rev, &leaf->mempool);
 }
 
 void    tDattorroReverb_initToPool        (tDattorroReverb* const rev, tMempool* const mp)
@@ -372,10 +380,11 @@
     _tMempool* m = *mp;
     _tDattorroReverb* r = *rev = (_tDattorroReverb*) mpool_alloc(sizeof(_tDattorroReverb), m);
     r->mempool = m;
+    LEAF* leaf = r->mempool->leaf;
     
     r->size_max = 2.0f;
     r->size = 1.f;
-    r->t = r->size * leaf.sampleRate * 0.001f;
+    r->t = r->size * leaf->sampleRate * 0.001f;
     r->frozen = 0;
     // INPUT
     tTapeDelay_initToPool(&r->in_delay, 0.f, SAMP(200.f), mp);
@@ -763,9 +772,10 @@
 void    tDattorroReverb_setSize           (tDattorroReverb* const rev, float size)
 {
     _tDattorroReverb* r = *rev;
+    LEAF* leaf = r->mempool->leaf;
     
     r->size = LEAF_clip(0.01f, size*r->size_max, r->size_max);
-    r->t = r->size * leaf.sampleRate * 0.001f;
+    r->t = r->size * leaf->sampleRate * 0.001f;
     
     /*
      for (int i = 0; i < 4; i++)
--- a/leaf/Src/leaf-sampling.c
+++ b/leaf/Src/leaf-sampling.c
@@ -24,9 +24,9 @@
 
 //==============================================================================
 
-void  tBuffer_init (tBuffer* const sb, uint32_t length)
+void  tBuffer_init (tBuffer* const sb, uint32_t length, LEAF* const leaf)
 {
-    tBuffer_initToPool(sb, length, &leaf.mempool);
+    tBuffer_initToPool(sb, length, &leaf->mempool);
 }
 
 void  tBuffer_initToPool (tBuffer* const sb, uint32_t length, tMempool* const mp)
@@ -166,9 +166,9 @@
 
 static void attemptStartEndChange(tSampler* const sp);
 
-void tSampler_init(tSampler* const sp, tBuffer* const b)
+void tSampler_init(tSampler* const sp, tBuffer* const b, LEAF* const leaf)
 {
-    tSampler_initToPool(sp, b, &leaf.mempool);
+    tSampler_initToPool(sp, b, &leaf->mempool);
 }
 
 void tSampler_initToPool(tSampler* const sp, tBuffer* const b, tMempool* const mp)
@@ -239,6 +239,7 @@
 float tSampler_tick        (tSampler* const sp)
 {
     _tSampler* p = *sp;
+    LEAF* leaf = p->mempool->leaf;
     
     attemptStartEndChange(sp);
     
@@ -451,7 +452,7 @@
             p->idx = myEnd;
         }
         float ticksToEnd = rev ? ((idx - myStart) * p->iinc) : ((myEnd - idx) * p->iinc);
-        if (ticksToEnd < (0.007f * leaf.sampleRate))
+        if (ticksToEnd < (0.007f * leaf->sampleRate))
         {
             tRamp_setDest(&p->gain, 0.f);
             p->active = -1;
@@ -755,9 +756,9 @@
 
 //==============================================================================
 
-void    tAutoSampler_init   (tAutoSampler* const as, tBuffer* const b)
+void    tAutoSampler_init   (tAutoSampler* const as, tBuffer* const b, LEAF* const leaf)
 {
-    tAutoSampler_initToPool(as, b, &leaf.mempool);
+    tAutoSampler_initToPool(as, b, &leaf->mempool);
 }
 
 void    tAutoSampler_initToPool (tAutoSampler* const as, tBuffer* const b, tMempool* const mp)
@@ -878,9 +879,9 @@
 
 
 
-void tMBSampler_init(tMBSampler* const sp, tBuffer* const b)
+void tMBSampler_init(tMBSampler* const sp, tBuffer* const b, LEAF* const leaf)
 {
-    tMBSampler_initToPool(sp, b, &leaf.mempool);
+    tMBSampler_initToPool(sp, b, &leaf->mempool);
 }
 
 void tMBSampler_initToPool(tMBSampler* const sp, tBuffer* const b, tMempool* const mp)
--- a/leaf/Src/leaf.c
+++ b/leaf/Src/leaf.c
@@ -18,58 +18,56 @@
 
 #endif
 
-LEAF leaf;
-
-void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void))
-
+void LEAF_init(LEAF* const leaf, float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void))
 {
-    leaf_pool_init(memory, memorysize);
+    leaf->_internal_mempool.leaf = leaf;
+    leaf_pool_init(leaf, memory, memorysize);
     
-    leaf.sampleRate = sr;
+    leaf->sampleRate = sr;
 
-    leaf.blockSize = blocksize;
+    leaf->blockSize = blocksize;
     
-    leaf.invSampleRate = 1.0f/sr;
+    leaf->invSampleRate = 1.0f/sr;
     
-    leaf.twoPiTimesInvSampleRate = leaf.invSampleRate * TWO_PI;
+    leaf->twoPiTimesInvSampleRate = leaf->invSampleRate * TWO_PI;
 
-    leaf.random = random;
+    leaf->random = random;
     
-    leaf.clearOnAllocation = 0;
+    leaf->clearOnAllocation = 0;
     
-    leaf.errorCallback = &LEAF_defaultErrorCallback;
+    leaf->errorCallback = &LEAF_defaultErrorCallback;
     
     for (int i = 0; i < LEAFErrorNil; ++i)
-        leaf.errorState[i] = 0;
+        leaf->errorState[i] = 0;
 }
 
 
 #define LEAFSampleRateChanged(THIS) leaf.THIS.sampleRateChanged(&leaf.THIS)
 
-void LEAF_setSampleRate(float sampleRate)
+void LEAF_setSampleRate(LEAF* const leaf, float sampleRate)
 {
-    leaf.sampleRate = sampleRate;
-    leaf.invSampleRate = 1.0f/sampleRate;
+    leaf->sampleRate = sampleRate;
+    leaf->invSampleRate = 1.0f/sampleRate;
 }
 
-float LEAF_getSampleRate()
+float LEAF_getSampleRate(LEAF* const leaf)
 {
-    return leaf.sampleRate;
+    return leaf->sampleRate;
 }
 
-void LEAF_defaultErrorCallback(LEAFErrorType whichone)
+void LEAF_defaultErrorCallback(LEAF* const leaf, LEAFErrorType whichone)
 {
     // Not sure what this should do if anything
     // Maybe fine as a placeholder
 }
 
-void LEAF_internalErrorCallback(LEAFErrorType whichone)
+void LEAF_internalErrorCallback(LEAF* const leaf, LEAFErrorType whichone)
 {
-    leaf.errorState[whichone] = 1;
-    leaf.errorCallback(whichone);
+    leaf->errorState[whichone] = 1;
+    leaf->errorCallback(leaf, whichone);
 }
 
-void LEAF_setErrorCallback(void (*callback)(LEAFErrorType))
+void LEAF_setErrorCallback(LEAF* const leaf, void (*callback)(LEAF* const, LEAFErrorType))
 {
-    leaf.errorCallback = callback;
+    leaf->errorCallback = callback;
 }
--- a/leaf/leaf.h
+++ b/leaf/leaf.h
@@ -126,33 +126,33 @@
      @param memorySize The size of the memory that will make up the default LEAF mempool.
      @param random A pointer to a random number function. Should return a float >= 0 and < 1.
      */
-    void        LEAF_init            (float sampleRate, int blockSize, char* memory, size_t memorySize, float(*random)(void));
+    void        LEAF_init            (LEAF* const leaf, float sampleRate, int blockSize, char* memory, size_t memorySize, float(*random)(void));
     
     //! Set the sample rate of LEAF.
     /*!
      @param sampleRate The new audio sample rate.
      */
-    void        LEAF_setSampleRate   (float sampleRate);
+    void        LEAF_setSampleRate   (LEAF* const leaf, float sampleRate);
     
     //! Get the sample rate of LEAF.
     /*!
      @return The current sample rate as a float.
      */
-    float       LEAF_getSampleRate   (void);
+    float       LEAF_getSampleRate   (LEAF* const leaf);
     
     //! The default callback function for LEAF errors.
     /*!
      @param errorType The type of the error that has occurred.
      */
-    void        LEAF_defaultErrorCallback(LEAFErrorType errorType);
+    void        LEAF_defaultErrorCallback(LEAF* const leaf, LEAFErrorType errorType);
     
-    void        LEAF_internalErrorCallback(LEAFErrorType whichone);
+    void        LEAF_internalErrorCallback(LEAF* const leaf, LEAFErrorType whichone);
     
     //! Set the callback function for LEAF errors.
     /*!
      @param callback A pointer to the callback function.
      */
-    void LEAF_setErrorCallback(void (*callback)(LEAFErrorType));
+    void LEAF_setErrorCallback(LEAF* const leaf, void (*callback)(LEAF* const, LEAFErrorType));
     
     /*! @} */