-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make ParamValues reusable between backends
Extract the ParamValues type from the VST3 backend into a reusable type in the sync module. ParamValues is now effectively an MPSC channel for param changes.
- Loading branch information
Showing
5 changed files
with
76 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod bitset; | ||
pub mod float; | ||
pub mod params; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::sync::atomic::Ordering; | ||
|
||
use super::bitset::{self, AtomicBitset}; | ||
use super::float::AtomicF64; | ||
use crate::{ParamInfo, ParamValue}; | ||
|
||
pub struct ParamValues { | ||
values: Vec<AtomicF64>, | ||
dirty: AtomicBitset, | ||
} | ||
|
||
impl ParamValues { | ||
pub fn new(params: &[ParamInfo]) -> ParamValues { | ||
ParamValues { | ||
values: params.iter().map(|p| AtomicF64::new(p.default)).collect(), | ||
dirty: AtomicBitset::with_len(params.len()), | ||
} | ||
} | ||
|
||
pub fn set(&self, index: usize, value: ParamValue) { | ||
self.values[index].store(value, Ordering::Relaxed); | ||
self.dirty.set(index, Ordering::Release); | ||
} | ||
|
||
pub fn poll(&self) -> ParamChanges { | ||
ParamChanges { | ||
values: &self.values, | ||
iter: self.dirty.drain(Ordering::Acquire), | ||
} | ||
} | ||
} | ||
|
||
pub struct ParamChanges<'a> { | ||
values: &'a [AtomicF64], | ||
iter: bitset::Drain<'a>, | ||
} | ||
|
||
impl<'a> Iterator for ParamChanges<'a> { | ||
type Item = (usize, ParamValue); | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if let Some(index) = self.iter.next() { | ||
Some((index, self.values[index].load(Ordering::Relaxed))) | ||
} else { | ||
None | ||
} | ||
} | ||
} |