mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: refactor into crates
This commit is contained in:
parent
96e17e7f7c
commit
5ae99b4ada
87 changed files with 2281 additions and 2217 deletions
0
crates/tek_chain/src/bin/mod.rs
Normal file
0
crates/tek_chain/src/bin/mod.rs
Normal file
49
crates/tek_chain/src/chain.rs
Normal file
49
crates/tek_chain/src/chain.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use crate::*;
|
||||
|
||||
/// A sequencer track.
|
||||
#[derive(Debug)]
|
||||
pub struct Chain {
|
||||
pub name: String,
|
||||
/// Device chain
|
||||
pub devices: Vec<JackDevice>,
|
||||
/// Device selector
|
||||
pub device: usize,
|
||||
}
|
||||
|
||||
impl Chain {
|
||||
pub fn new (name: &str) -> Usually<Self> {
|
||||
Ok(Self {
|
||||
name: name.to_string(),
|
||||
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)
|
||||
}
|
||||
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> {
|
||||
self.devices.push(device);
|
||||
let index = self.devices.len() - 1;
|
||||
Ok(&mut self.devices[index])
|
||||
}
|
||||
}
|
||||
|
||||
58
crates/tek_chain/src/chain_view.rs
Normal file
58
crates/tek_chain/src/chain_view.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use crate::*;
|
||||
use tek_core::Direction;
|
||||
|
||||
pub struct ChainView<'a> {
|
||||
pub track: 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 {
|
||||
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 (area, areas) = self.direction
|
||||
.split_focus(0, track.devices.as_slice(), if self.focused {
|
||||
Style::default().green().dim()
|
||||
} else {
|
||||
Style::default().dim()
|
||||
})
|
||||
.render_areas(buf, area)?;
|
||||
if self.focused && self.entered {
|
||||
Corners(Style::default().green().not_dim()).draw(buf, areas[0])?;
|
||||
}
|
||||
Ok(area)
|
||||
} else {
|
||||
let Rect { x, y, width, height } = area;
|
||||
let label = "No track 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()))?;
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
8
crates/tek_chain/src/lib.rs
Normal file
8
crates/tek_chain/src/lib.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
pub(crate) use tek_core::*;
|
||||
pub(crate) use tek_core::ratatui::prelude::*;
|
||||
pub(crate) use tek_jack::*;
|
||||
pub(crate) use std::sync::RwLockWriteGuard;
|
||||
submod! {
|
||||
chain
|
||||
chain_view
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue