samples in main

This commit is contained in:
🪞👃🪞 2024-06-29 16:29:20 +03:00
parent 15f71d0973
commit fad0caef88
3 changed files with 30 additions and 45 deletions

View file

@ -11,7 +11,7 @@ mod transport;
pub use self::track::Track;
pub use self::launcher::{Launcher, Scene};
pub use self::sequencer::{Sequencer, Phrase};
pub use self::chain::{Chain, Sampler, Plugin};
pub use self::chain::{Chain, Plugin, Sampler, Sample, Voice};
pub use self::looper::Looper;
pub use self::mixer::Mixer;

View file

@ -16,10 +16,10 @@ impl Voice {
}
pub struct Sample {
name: String,
start: usize,
end: usize,
channels: Vec<Vec<f32>>,
pub name: String,
pub start: usize,
pub end: usize,
pub channels: Vec<Vec<f32>>,
}
impl Sample {
fn new (name: &str) -> Arc<Self> {
@ -41,49 +41,15 @@ pub struct Sampler {
}
impl Sampler {
pub fn new (name: &str) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
pub fn new (
name: &str,
samples: Option<BTreeMap<u7, Arc<Sample>>>,
) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
let (client, _) = Client::new(name, ClientOptions::NO_START_SERVER)?;
DynamicDevice::new(render, handle, Self::process, Self {
name: name.into(),
cursor: (0, 0),
samples: BTreeMap::from([
(u7::from_int_lossy(35), Sample {
name: "Kick 1".into(),
start: 0,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(36).into(), Sample {
name: "Kick 2".into(),
start: 0,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(38).into(), Sample {
name: "Snare 1".into(),
start: 0,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(40).into(), Sample {
name: "Snare 2".into(),
start: 50000,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(42).into(), Sample {
name: "HH Closed".into(),
start: 0,
end: 50000,
channels: vec![],
}.into()),
(u7::from_int_lossy(46).into(), Sample {
name: "HH Open".into(),
start: 0,
end: 25000,
channels: vec![]
}.into()),
]),
samples: samples.unwrap_or(BTreeMap::new()),
voices: vec![],
midi_in: client.register_port("midi", ::jack::MidiIn::default())?,
audio_ins: vec![

View file

@ -34,7 +34,26 @@ fn main () -> Result<(), Box<dyn Error>> {
Track::new("Kick", &timebase, Some(vec![
//Plugin::lv2("Kick/ChowKick", "file:///home/user/.lv2/ChowKick.lv2", &[1, 1, 0, 2])?.boxed(),
Sampler::new("Sampler")?.boxed(),
Sampler::new("Sampler", Some(BTreeMap::from([
(u7::from_int_lossy(35), Sample {
name: "Kick 1".into(), start: 0, end: 100000, channels: vec![],
}.into()),
(u7::from_int_lossy(36).into(), Sample {
name: "Kick 2".into(), start: 0, end: 100000, channels: vec![],
}.into()),
(u7::from_int_lossy(38).into(), Sample {
name: "Snare 1".into(), start: 0, end: 100000, channels: vec![],
}.into()),
(u7::from_int_lossy(40).into(), Sample {
name: "Snare 2".into(), start: 50000, end: 100000, channels: vec![],
}.into()),
(u7::from_int_lossy(42).into(), Sample {
name: "HH Closed".into(), start: 0, end: 50000, channels: vec![],
}.into()),
(u7::from_int_lossy(46).into(), Sample {
name: "HH Open".into(), start: 0, end: 25000, channels: vec![]
}.into()),
])))?.boxed(),
]), Some(vec![
Phrase::new("HelloKick", ppq * 4, Some(BTreeMap::from([
( ppq * 0, vec![MidiMessage::NoteOn { key: 36.into(), vel: 100.into() }] ),