mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
impl PortList for Sampler
This commit is contained in:
parent
9351887ae6
commit
1038e24ceb
1 changed files with 83 additions and 55 deletions
|
|
@ -11,6 +11,20 @@ pub struct Sampler {
|
|||
samples: Arc<Mutex<Vec<Sample>>>,
|
||||
selected_sample: usize,
|
||||
selected_column: usize,
|
||||
midi_ins: Vec<Port<MidiIn>>,
|
||||
audio_ins: Vec<Port<AudioIn>>,
|
||||
audio_outs: Vec<Port<AudioOut>>,
|
||||
}
|
||||
|
||||
pub struct Sample {
|
||||
port: Port<AudioOut>,
|
||||
name: String,
|
||||
rate: u32,
|
||||
gain: f64,
|
||||
channels: u8,
|
||||
data: Vec<Vec<f32>>,
|
||||
trigger: (u8, u8),
|
||||
playing: Option<usize>,
|
||||
}
|
||||
|
||||
impl Sampler {
|
||||
|
|
@ -22,23 +36,21 @@ impl Sampler {
|
|||
];
|
||||
let samples = Arc::new(Mutex::new(samples));
|
||||
let input = client.register_port("trigger", ::jack::MidiIn::default())?;
|
||||
Ok(DynamicDevice::new(render, handle, process, Self {
|
||||
Ok(DynamicDevice::new(render, handle, Self::process, Self {
|
||||
name: name.into(),
|
||||
input,
|
||||
selected_sample: 0,
|
||||
selected_column: 0,
|
||||
samples,
|
||||
midi_ins: vec![],
|
||||
audio_ins: vec![],
|
||||
audio_outs: vec![],
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process (
|
||||
state: &mut Sampler,
|
||||
_: &Client,
|
||||
scope: &ProcessScope,
|
||||
) -> Control {
|
||||
let mut samples = state.samples.lock().unwrap();
|
||||
for event in state.input.iter(scope) {
|
||||
pub fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
let mut samples = self.samples.lock().unwrap();
|
||||
for event in self.input.iter(scope) {
|
||||
let len = 3.min(event.bytes.len());
|
||||
let mut data = [0; 3];
|
||||
data[..len].copy_from_slice(&event.bytes[..len]);
|
||||
|
|
@ -66,17 +78,33 @@ pub fn process (
|
|||
}
|
||||
}
|
||||
Control::Continue
|
||||
}
|
||||
|
||||
fn load_sample (&mut self, path: &str) {}
|
||||
}
|
||||
|
||||
pub struct Sample {
|
||||
port: Port<AudioOut>,
|
||||
name: String,
|
||||
rate: u32,
|
||||
gain: f64,
|
||||
channels: u8,
|
||||
data: Vec<Vec<f32>>,
|
||||
trigger: (u8, u8),
|
||||
playing: Option<usize>,
|
||||
impl PortList for Sampler {
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_ins.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_outs.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.midi_ins.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
}
|
||||
|
||||
impl Sample {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue