ref: 97ad97258b4fd2631ccc3ff840505402fbce4638
parent: 3e8b48269bcafe4574c93ada7f67f3a7652b2479
author: mulshine <mulshine@princeton.edu>
date: Fri Feb 1 11:25:15 EST 2019
Fixed BackAndForth.
--- a/LEAF/Inc/leaf-sample.h
+++ b/LEAF/Inc/leaf-sample.h
@@ -80,6 +80,7 @@
float iinc;
int8_t dir;
int8_t flip;
+ int8_t bnf;
int32_t start;
int32_t end;
--- a/LEAF/Src/leaf-sample.c
+++ b/LEAF/Src/leaf-sample.c
@@ -120,8 +120,10 @@
p->idx = 0.f;
p->inc = 1.f;
p->iinc = 1.f;
+
p->dir = 1;
p->flip = 1;
+ p->bnf = 1;
p->mode = Normal;
@@ -148,7 +150,7 @@
float* buff = p->samp->buff;
- int dir = p->dir * p->flip;
+ int dir = p->bnf * p->dir * p->flip;
int idx;
float alpha;
@@ -269,13 +271,18 @@
}
else // == BackAndForth
{
- if ((idx <= start) || (idx >= end))
+ if (p->idx < start)
{
- p->dir = -p->dir;
- p->idx += (p->dir * p->flip * p->inc);
+ p->bnf = -p->bnf;
+ p->idx = start;
}
+ else if (p->idx > end)
+ {
+ p->bnf = -p->bnf;
+ p->idx = end;
+ }
}
-
+
g1 = 1.f - g2;
sample = sample * g1 + cfxsample * g2;
--- a/LEAF_JUCEPlugin/Source/MyTest.cpp
+++ b/LEAF_JUCEPlugin/Source/MyTest.cpp
@@ -27,13 +27,11 @@
tBuffer_init(&sample, leaf.sampleRate * 2);
tSampler_init(&player, &sample);
- tSampler_setMode(&player, Loop);
+ tSampler_setMode(&player, BackAndForth);
leaf_pool_report();
- tBuffer_record(&sample);
-
- tSampler_play(&player);
+ tBuffer_record(&sample);
}
int timer = 0;
@@ -45,7 +43,7 @@
return tSampler_tick(&player);
}
-bool lastState = false;
+bool lastState = false, lastPlayState = false;
void LEAFTest_block (void)
{
float val = getSliderValue("rate");
@@ -77,7 +75,16 @@
tBuffer_record(&sample);
}
- lastState = state;
+ lastState = state;
+
+ state = getButtonState("play");
+
+ if (state && !lastPlayState)
+ {
+ tSampler_play(&player);
+ }
+
+ lastPlayState = state;
}
void LEAFTest_controllerInput (int cnum, float cval)