mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-11 14:16:42 +01:00
and it once again compiles
This commit is contained in:
parent
6dd4caeb42
commit
430c51e305
31 changed files with 466 additions and 694 deletions
168
crates/tek_mixer/src/track.rs
Normal file
168
crates/tek_mixer/src/track.rs
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
use crate::*;
|
||||
use tek_core::edn;
|
||||
#[cfg(feature = "standalone_devices")]
|
||||
use tek_sampler::*;
|
||||
#[cfg(feature = "standalone_devices")]
|
||||
use tek_plugin::*;
|
||||
|
||||
/// A sequencer track.
|
||||
#[derive(Debug)]
|
||||
pub struct Track {
|
||||
pub name: String,
|
||||
/// Inputs and outputs of 1st and last device
|
||||
pub ports: JackPorts,
|
||||
/// Device chain
|
||||
pub devices: Vec<JackDevice>,
|
||||
/// Device selector
|
||||
pub device: usize,
|
||||
}
|
||||
|
||||
handle!(Track |self, event| handle_keymap(self, event, KEYMAP_CHAIN));
|
||||
|
||||
render!(Track |self, buf, area| TrackView {
|
||||
chain: Some(&self),
|
||||
direction: tek_core::Direction::Right,
|
||||
focused: true,
|
||||
entered: true,
|
||||
//pub channels: u8,
|
||||
//pub input_ports: Vec<Port<AudioIn>>,
|
||||
//pub pre_gain_meter: f64,
|
||||
//pub gain: f64,
|
||||
//pub insert_ports: Vec<Port<AudioOut>>,
|
||||
//pub return_ports: Vec<Port<AudioIn>>,
|
||||
//pub post_gain_meter: f64,
|
||||
//pub post_insert_meter: f64,
|
||||
//pub level: f64,
|
||||
//pub pan: f64,
|
||||
//pub output_ports: Vec<Port<AudioOut>>,
|
||||
//pub post_fader_meter: f64,
|
||||
//pub route: String,
|
||||
}.render(buf, area));
|
||||
|
||||
impl Track {
|
||||
|
||||
pub fn new (name: &str) -> Usually<Self> {
|
||||
Ok(Self {
|
||||
name: name.to_string(),
|
||||
ports: JackPorts::default(),
|
||||
devices: vec![],
|
||||
device: 0,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_device_mut (&self, i: usize) -> Option<RwLockWriteGuard<Box<dyn Device>>> {
|
||||
self.devices.get(i).map(|d|d.state.write().unwrap())
|
||||
}
|
||||
pub fn device_mut (&self) -> Option<RwLockWriteGuard<Box<dyn Device>>> {
|
||||
self.get_device_mut(self.device)
|
||||
}
|
||||
/// Add a device to the end of the chain.
|
||||
pub fn append_device (&mut self, device: JackDevice) -> Usually<&mut JackDevice> {
|
||||
self.devices.push(device);
|
||||
let index = self.devices.len() - 1;
|
||||
Ok(&mut self.devices[index])
|
||||
}
|
||||
//pub fn connect_first_device (&self) -> Usually<()> {
|
||||
//if let (Some(port), Some(device)) = (&self.midi_out, self.devices.get(0)) {
|
||||
//device.client.as_client().connect_ports(&port, &device.midi_ins()?[0])?;
|
||||
//}
|
||||
//Ok(())
|
||||
//}
|
||||
//pub fn connect_last_device (&self, app: &Track) -> Usually<()> {
|
||||
//Ok(match self.devices.get(self.devices.len().saturating_sub(1)) {
|
||||
//Some(device) => {
|
||||
//app.audio_out(0).map(|left|device.connect_audio_out(0, &left)).transpose()?;
|
||||
//app.audio_out(1).map(|right|device.connect_audio_out(1, &right)).transpose()?;
|
||||
//()
|
||||
//},
|
||||
//None => ()
|
||||
//})
|
||||
//}
|
||||
|
||||
pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Self> {
|
||||
let mut _gain = 0.0f64;
|
||||
let mut track = Self::new("")?;
|
||||
#[allow(unused_mut)]
|
||||
let mut devices: Vec<JackDevice> = vec![];
|
||||
edn!(edn in args {
|
||||
Edn::Map(map) => {
|
||||
if let Some(Edn::Str(n)) = map.get(&Edn::Key(SYM_NAME)) {
|
||||
track.name = n.to_string();
|
||||
}
|
||||
if let Some(Edn::Double(g)) = map.get(&Edn::Key(SYM_GAIN)) {
|
||||
_gain = f64::from(*g);
|
||||
}
|
||||
},
|
||||
Edn::List(args) => match args.get(0) {
|
||||
// Add a sampler device to the track
|
||||
Some(Edn::Symbol(SYM_SAMPLER)) => {
|
||||
#[cfg(feature = "standalone_devices")]
|
||||
devices.push(Sampler::from_edn(&args[1..])?);
|
||||
#[cfg(not(feature = "standalone_devices"))]
|
||||
panic!(
|
||||
"unsupported in track {}: {:?}; tek_mixer not compiled with feature \"sampler\"",
|
||||
&track.name,
|
||||
args.get(0).unwrap()
|
||||
)
|
||||
},
|
||||
// Add a LV2 plugin to the track.
|
||||
Some(Edn::Symbol(SYM_LV2)) => {
|
||||
#[cfg(feature = "standalone_devices")]
|
||||
devices.push(LV2Plugin::from_edn(&args[1..])?);
|
||||
#[cfg(not(feature = "standalone_devices"))]
|
||||
panic!(
|
||||
"unsupported in track {}: {:?}; tek_mixer not compiled with feature \"plugin\"",
|
||||
&track.name,
|
||||
args.get(0).unwrap()
|
||||
)
|
||||
},
|
||||
None =>
|
||||
panic!("empty list track {}", &track.name),
|
||||
_ =>
|
||||
panic!("unexpected in track {}: {:?}", &track.name, args.get(0).unwrap())
|
||||
},
|
||||
_ => {}
|
||||
});
|
||||
for device in devices {
|
||||
track.add_device(device);
|
||||
}
|
||||
Ok(track)
|
||||
}
|
||||
|
||||
pub fn add_device (&mut self, device: JackDevice) {
|
||||
self.devices.push(device);
|
||||
}
|
||||
}
|
||||
|
||||
const SYM_NAME: &'static str = ":name";
|
||||
const SYM_GAIN: &'static str = ":gain";
|
||||
const SYM_SAMPLER: &'static str = "sampler";
|
||||
const SYM_LV2: &'static str = "lv2";
|
||||
|
||||
/// Key bindings for chain section.
|
||||
pub const KEYMAP_CHAIN: &'static [KeyBinding<Track>] = keymap!(Track {
|
||||
[Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut Track| {
|
||||
Ok(true)
|
||||
}],
|
||||
[Down, NONE, "chain_cursor_down", "move cursor down", |_: &mut Track| {
|
||||
Ok(true)
|
||||
}],
|
||||
[Left, NONE, "chain_cursor_left", "move cursor left", |app: &mut Track| {
|
||||
//if let Some(track) = app.arranger.track_mut() {
|
||||
//track.device = track.device.saturating_sub(1);
|
||||
//return Ok(true)
|
||||
//}
|
||||
Ok(false)
|
||||
}],
|
||||
[Right, NONE, "chain_cursor_right", "move cursor right", |app: &mut Track| {
|
||||
//if let Some(track) = app.arranger.track_mut() {
|
||||
//track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
|
||||
//return Ok(true)
|
||||
//}
|
||||
Ok(false)
|
||||
}],
|
||||
[Char('`'), NONE, "chain_mode_switch", "switch the display mode", |app: &mut Track| {
|
||||
//app.chain_mode = !app.chain_mode;
|
||||
Ok(true)
|
||||
}],
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue