wip: fixing some assumptions

This commit is contained in:
🪞👃🪞 2024-08-06 16:43:04 +03:00
parent 5ae99b4ada
commit 2a60808239
11 changed files with 73 additions and 125 deletions

View file

@ -24,26 +24,27 @@ impl Chain {
pub fn device_mut (&self) -> Option<RwLockWriteGuard<Box<dyn Device>>> {
self.get_device_mut(self.device)
}
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: &App) -> 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 add_device (&mut self, device: JackDevice) -> Usually<&mut JackDevice> {
/// 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: &App) -> 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 => ()
//})
//}
}

View file

@ -2,39 +2,26 @@ use crate::*;
use tek_core::Direction;
pub struct ChainView<'a> {
pub track: Option<&'a Chain>,
pub chain: Option<&'a Chain>,
pub direction: Direction,
pub focused: bool,
pub entered: bool,
}
impl<'a> ChainView<'a> {
pub fn horizontal (app: &'a App) -> Self {
Self::new(app, Direction::Right)
}
pub fn vertical (app: &'a App) -> Self {
Self::new(app, Direction::Down)
}
pub fn new (app: &'a App, direction: Direction) -> Self {
Self {
direction,
entered: app.entered,
focused: app.section == AppFocus::Chain,
track: app.arranger.track()
}
}
}
impl<'a> Render for ChainView<'a> {
fn render (&self, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
if let Some(track) = self.track {
if let Some(chain) = self.chain {
match self.direction {
Direction::Down => area.width = area.width.min(40),
Direction::Right => area.width = area.width.min(10),
}
fill_bg(buf, area, Nord::bg_lo(self.focused, self.entered));
let devices: Vec<&(dyn Render + Send + Sync)> = chain.devices.as_slice()
.iter()
.map(|d|d as &(dyn Render + Send + Sync))
.collect();
let (area, areas) = self.direction
.split_focus(0, track.devices.as_slice(), if self.focused {
.split_focus(0, devices.as_slice(), if self.focused {
Style::default().green().dim()
} else {
Style::default().dim()
@ -46,7 +33,7 @@ impl<'a> Render for ChainView<'a> {
Ok(area)
} else {
let Rect { x, y, width, height } = area;
let label = "No track selected";
let label = "No chain selected";
let x = x + (width - label.len() as u16) / 2;
let y = y + height / 2;
label.blit(buf, x, y, Some(Style::default().dim().bold()))?;
@ -55,4 +42,19 @@ impl<'a> Render for ChainView<'a> {
}
}
//impl<'a> ChainView<'a> {
//pub fn horizontal (app: &'a App) -> Self {
//Self::new(app, Direction::Right)
//}
//pub fn vertical (app: &'a App) -> Self {
//Self::new(app, Direction::Down)
//}
//pub fn new (app: &'a App, direction: Direction) -> Self {
//Self {
//direction,
//entered: app.entered,
//focused: app.section == AppFocus::Chain,
//chain: app.arranger.chain()
//}
//}
//}