Skip to content

Commit

Permalink
only allow one seq event per index
Browse files Browse the repository at this point in the history
we don't want to be ticking the same network more than once every sample

also reset when the event is added
  • Loading branch information
tomara-x committed May 19, 2024
1 parent 39befd4 commit 77e138a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ impl AudioNode for Seq {
) -> Frame<Self::Sample, Self::Outputs> {
// triggered, add an event
if input[0] != 0. {
// remove existing events for that index
self.events.retain(|&x| x.0 != input[1] as usize);
// reset the net
if let Some(network) = self.nets.get_mut(input[1] as usize) {
network.reset();
}
// push the new event
self.events.push((
input[1] as usize,
(input[2] * 44100.).round() as usize,
Expand All @@ -83,7 +90,6 @@ impl AudioNode for Seq {
if let Some(network) = self.nets.get_mut(i.0) {
network.tick(&[], &mut buffer);
out[0] += buffer[0];
if i.2 == 1 { network.reset(); }
}
i.2 -= 1;
} else {
Expand Down

0 comments on commit 77e138a

Please sign in to comment.