mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
move pool to tek_midi; implement some Default
This commit is contained in:
parent
bb52555183
commit
1aa0551931
17 changed files with 779 additions and 775 deletions
|
|
@ -14,7 +14,6 @@ pub(crate) use ::tek_tui::{
|
|||
|
||||
pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicUsize, Ordering::Relaxed}};
|
||||
pub(crate) use std::fs::File;
|
||||
pub(crate) use std::ops::Deref;
|
||||
pub(crate) use std::path::PathBuf;
|
||||
pub(crate) use std::error::Error;
|
||||
pub(crate) use std::ffi::OsString;
|
||||
|
|
|
|||
|
|
@ -9,13 +9,31 @@ pub struct Sampler {
|
|||
pub recording: Option<(usize, Arc<RwLock<Sample>>)>,
|
||||
pub unmapped: Vec<Arc<RwLock<Sample>>>,
|
||||
pub voices: Arc<RwLock<Vec<Voice>>>,
|
||||
pub midi_in: JackPort<MidiIn>,
|
||||
pub midi_in: Option<JackPort<MidiIn>>,
|
||||
pub audio_ins: Vec<JackPort<AudioIn>>,
|
||||
pub input_meter: Vec<f32>,
|
||||
pub audio_outs: Vec<JackPort<AudioOut>>,
|
||||
pub buffer: Vec<Vec<f32>>,
|
||||
pub output_gain: f32
|
||||
}
|
||||
impl Default for Sampler {
|
||||
fn default () -> Self {
|
||||
Self {
|
||||
midi_in: None,
|
||||
audio_ins: vec![],
|
||||
input_meter: vec![0.0;2],
|
||||
audio_outs: vec![],
|
||||
jack: Default::default(),
|
||||
name: "tek_sampler".to_string(),
|
||||
mapped: [const { None };128],
|
||||
unmapped: vec![],
|
||||
voices: Arc::new(RwLock::new(vec![])),
|
||||
buffer: vec![vec![0.0;16384];2],
|
||||
output_gain: 1.,
|
||||
recording: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Sampler {
|
||||
pub fn new (
|
||||
jack: &Arc<RwLock<JackConnection>>,
|
||||
|
|
@ -26,24 +44,16 @@ impl Sampler {
|
|||
) -> Usually<Self> {
|
||||
let name = name.as_ref();
|
||||
Ok(Self {
|
||||
midi_in: JackPort::<MidiIn>::new(jack, format!("M/{name}"), midi_from)?,
|
||||
midi_in: Some(JackPort::<MidiIn>::new(jack, format!("M/{name}"), midi_from)?),
|
||||
audio_ins: vec![
|
||||
JackPort::<AudioIn>::new(jack, &format!("L/{name}"), audio_from[0])?,
|
||||
JackPort::<AudioIn>::new(jack, &format!("R/{name}"), audio_from[1])?,
|
||||
],
|
||||
input_meter: vec![0.0;2],
|
||||
audio_outs: vec![
|
||||
JackPort::<AudioOut>::new(jack, &format!("{name}/L"), audio_to[0])?,
|
||||
JackPort::<AudioOut>::new(jack, &format!("{name}/R"), audio_to[1])?,
|
||||
],
|
||||
jack: jack.clone(),
|
||||
name: name.into(),
|
||||
mapped: [const { None };128],
|
||||
unmapped: vec![],
|
||||
voices: Arc::new(RwLock::new(vec![])),
|
||||
buffer: vec![vec![0.0;16384];2],
|
||||
output_gain: 1.,
|
||||
recording: None,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
pub fn cancel_recording (&mut self) {
|
||||
|
|
@ -112,18 +122,20 @@ impl Sampler {
|
|||
/// Create [Voice]s from [Sample]s in response to MIDI input.
|
||||
pub fn process_midi_in (&mut self, scope: &ProcessScope) {
|
||||
let Sampler { midi_in, mapped, voices, .. } = self;
|
||||
for RawMidi { time, bytes } in midi_in.port.iter(scope) {
|
||||
if let LiveEvent::Midi { message, .. } = LiveEvent::parse(bytes).unwrap() {
|
||||
match message {
|
||||
MidiMessage::NoteOn { ref key, ref vel } => {
|
||||
if let Some(ref sample) = mapped[key.as_int() as usize] {
|
||||
voices.write().unwrap().push(Sample::play(sample, time as usize, vel));
|
||||
if let Some(ref midi_in) = midi_in {
|
||||
for RawMidi { time, bytes } in midi_in.port.iter(scope) {
|
||||
if let LiveEvent::Midi { message, .. } = LiveEvent::parse(bytes).unwrap() {
|
||||
match message {
|
||||
MidiMessage::NoteOn { ref key, ref vel } => {
|
||||
if let Some(ref sample) = mapped[key.as_int() as usize] {
|
||||
voices.write().unwrap().push(Sample::play(sample, time as usize, vel));
|
||||
}
|
||||
},
|
||||
MidiMessage::Controller { controller, value } => {
|
||||
// TODO
|
||||
}
|
||||
},
|
||||
MidiMessage::Controller { controller, value } => {
|
||||
// TODO
|
||||
_ => {}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue