shithub: leaf

Download patch

ref: b0cf3f1d2e39f686651aca1129c7be482c877216
parent: 97ad97258b4fd2631ccc3ff840505402fbce4638
author: mulshine <mulshine@princeton.edu>
date: Fri Feb 1 11:38:04 EST 2019

Retriggering is smooth.

--- a/LEAF/Inc/leaf-sample.h
+++ b/LEAF/Inc/leaf-sample.h
@@ -88,6 +88,7 @@
         uint32_t cfxlen;
     
         Mode mode;
+        int retrigger;
         
         int active;
 
--- a/LEAF/Src/leaf-sample.c
+++ b/LEAF/Src/leaf-sample.c
@@ -256,7 +256,11 @@
     
     if (p->mode == Normal)
     {
-        if (numsamps == 0) p->active = 0;
+        if (numsamps < (0.007f * leaf.sampleRate))
+        {
+            tRamp_setDest(&p->gain, 0.f);
+            p->active = -1;
+        }
     }
     else if (p->mode == Loop ) // == Normal or Loop
     {
@@ -293,7 +297,28 @@
     {
         if (tRamp_sample(&p->gain) <= 0.00001f)
         {
-            p->active = 0;
+            if (p->retrigger == 1)
+            {
+                p->active = 1;
+                p->retrigger = 0;
+                tRamp_setDest(&p->gain, 1.f);
+                
+                if (p->dir > 0)
+                {
+                    if (p->flip > 0)    p->idx = p->start;
+                    else                p->idx = p->end;
+                }
+                else
+                {
+                    if (p->flip > 0)    p->idx = p->end;
+                    else                p->idx = p->start;
+                }
+            }
+            else
+            {
+                p->active = 0;
+            }
+            
         }
     }
     
@@ -321,21 +346,31 @@
 
 void tSampler_play         (tSampler* const p)
 {
-    p->active = 1;
-    
-    if (p->dir > 0)
+    if (p->active != 0)
     {
-        if (p->flip > 0)    p->idx = p->start;
-        else                p->idx = p->end;
+        p->active = -1;
+        p->retrigger = 1;
+        
+        tRamp_setDest(&p->gain, 0.f);
     }
     else
     {
-        if (p->flip > 0)    p->idx = p->end;
-        else                p->idx = p->start;
+        p->active = 1;
+        p->retrigger = 0;
+        
+        tRamp_setDest(&p->gain, 1.f);
+        
+        if (p->dir > 0)
+        {
+            if (p->flip > 0)    p->idx = p->start;
+            else                p->idx = p->end;
+        }
+        else
+        {
+            if (p->flip > 0)    p->idx = p->end;
+            else                p->idx = p->start;
+        }
     }
-    
-    tRamp_setVal(&p->gain, 0.f);
-    tRamp_setDest(&p->gain, 1.f);
 }
 
 void tSampler_stop         (tSampler* const p)
--- a/LEAF_JUCEPlugin/Source/MyTest.cpp
+++ b/LEAF_JUCEPlugin/Source/MyTest.cpp
@@ -27,7 +27,7 @@
     tBuffer_init(&sample, leaf.sampleRate * 2);
     
     tSampler_init(&player, &sample);
-    tSampler_setMode(&player, BackAndForth);
+    tSampler_setMode(&player, Normal);
     
     leaf_pool_report();