Skip to content

Commit

Permalink
reset a net when triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
tomara-x committed May 14, 2024
1 parent cef2ffb commit e57295b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,36 @@ impl AudioNode for Reset {
buffer.into()
}
}

/// reset network when triggered
/// - input 0: reset the net when non-zero
/// - output 0: output from the net
#[derive(Default, Clone)]
pub struct TrigReset { net: Net32 }

impl TrigReset {
pub fn new(net: Net32) -> Self {
TrigReset { net }
}
}

impl AudioNode for TrigReset {
const ID: u64 = 1113;
type Sample = f32;
type Inputs = U1;
type Outputs = U1;
type Setting = ();

#[inline]
fn tick(
&mut self,
input: &Frame<Self::Sample, Self::Inputs>,
) -> Frame<Self::Sample, Self::Outputs> {
let mut buffer = [0.];
if input[0] != 0. {
self.net.reset();
}
self.net.tick(&[], &mut buffer);
buffer.into()
}
}
21 changes: 21 additions & 0 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,27 @@ pub fn process(
}
}
}
} else if op == "trig_reset()" {
let op_changed = access.op_changed_query.get(*id).unwrap().0;
let lost = access.lost_wh_query.get(*id).unwrap().0;
let mut changed = false;
let mut input = None;
for hole in holes {
if let Ok(wh) = white_hole_query.get(*hole) {
if wh.link_types == (0, 1) { input = Some(wh.bh_parent); }
if wh.open { changed = true; }
}
}
if changed || lost || op_changed {
if let Some(input) = input {
let net = access.net_query.get(input).unwrap().0.clone();
if net.inputs() == 0 && net.outputs() == 1 {
let output = &mut access.net_query.get_mut(*id).unwrap().0;
*output = Net32::wrap(Box::new(An(TrigReset::new(net))));
lt_to_open = Some(0);
}
}
}
} else if op == "seq()" || op == "select()" {
let op_changed = access.op_changed_query.get(*id).unwrap().0;
let lost = access.lost_wh_query.get(*id).unwrap().0;
Expand Down

0 comments on commit e57295b

Please sign in to comment.