mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +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>>>,
|
samples: Arc<Mutex<Vec<Sample>>>,
|
||||||
selected_sample: usize,
|
selected_sample: usize,
|
||||||
selected_column: 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 {
|
impl Sampler {
|
||||||
|
|
@ -22,23 +36,21 @@ impl Sampler {
|
||||||
];
|
];
|
||||||
let samples = Arc::new(Mutex::new(samples));
|
let samples = Arc::new(Mutex::new(samples));
|
||||||
let input = client.register_port("trigger", ::jack::MidiIn::default())?;
|
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(),
|
name: name.into(),
|
||||||
input,
|
input,
|
||||||
selected_sample: 0,
|
selected_sample: 0,
|
||||||
selected_column: 0,
|
selected_column: 0,
|
||||||
samples,
|
samples,
|
||||||
|
midi_ins: vec![],
|
||||||
|
audio_ins: vec![],
|
||||||
|
audio_outs: vec![],
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process (
|
pub fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||||
state: &mut Sampler,
|
let mut samples = self.samples.lock().unwrap();
|
||||||
_: &Client,
|
for event in self.input.iter(scope) {
|
||||||
scope: &ProcessScope,
|
|
||||||
) -> Control {
|
|
||||||
let mut samples = state.samples.lock().unwrap();
|
|
||||||
for event in state.input.iter(scope) {
|
|
||||||
let len = 3.min(event.bytes.len());
|
let len = 3.min(event.bytes.len());
|
||||||
let mut data = [0; 3];
|
let mut data = [0; 3];
|
||||||
data[..len].copy_from_slice(&event.bytes[..len]);
|
data[..len].copy_from_slice(&event.bytes[..len]);
|
||||||
|
|
@ -66,17 +78,33 @@ pub fn process (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Control::Continue
|
Control::Continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_sample (&mut self, path: &str) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Sample {
|
impl PortList for Sampler {
|
||||||
port: Port<AudioOut>,
|
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||||
name: String,
|
let mut ports = vec![];
|
||||||
rate: u32,
|
for port in self.audio_ins.iter() {
|
||||||
gain: f64,
|
ports.push(port.name()?);
|
||||||
channels: u8,
|
}
|
||||||
data: Vec<Vec<f32>>,
|
Ok(ports)
|
||||||
trigger: (u8, u8),
|
}
|
||||||
playing: Option<usize>,
|
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 {
|
impl Sample {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue