remove old transport device

This commit is contained in:
🪞👃🪞 2024-07-02 21:21:16 +03:00
parent f5da2e6dad
commit a7344f8a72
4 changed files with 59 additions and 146 deletions

View file

@ -9,7 +9,8 @@ pub struct Chain {
pub focused: bool, pub focused: bool,
pub focus: usize, pub focus: usize,
pub items: Vec<Box<dyn Device>>, pub items: Vec<Box<dyn Device>>,
pub view: ChainView pub view: ChainView,
pub adding: bool,
} }
pub enum ChainView { pub enum ChainView {
@ -26,7 +27,8 @@ impl Chain {
focused: false, focused: false,
focus: 0, focus: 0,
items: items.unwrap_or_else(||vec![]), items: items.unwrap_or_else(||vec![]),
view: ChainView::Column view: ChainView::Column,
adding: false
})) }))
} }
} }
@ -61,7 +63,7 @@ pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
} else { } else {
Style::default().green().dim() Style::default().green().dim()
}); });
Ok(match state.view { let result = match state.view {
ChainView::Hidden => Rect { x, y, width: 0, height: 0 }, ChainView::Hidden => Rect { x, y, width: 0, height: 0 },
ChainView::Compact => { ChainView::Compact => {
let area = Rect { x, y, width: (state.name.len() + 4) as u16, height: 3 }; let area = Rect { x, y, width: (state.name.len() + 4) as u16, height: 3 };
@ -76,45 +78,8 @@ pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
ChainView::Column => { ChainView::Column => {
draw_as_column(state, buf, area, selected)? draw_as_column(state, buf, area, selected)?
}, },
}) };
//let area = Rect { x, y, width: 40, height: 30 }; Ok(result)
//let mut y = area.y;
//buf.set_string(area.x, y, "│", Style::default().black());
//buf.set_string(area.x + area.width - 1, y, "│", Style::default().black());
//buf.set_string(area.x + 2, y, "Input...", Style::default().dim());
//let mut x = 0u16;
//for (i, device) in state.items.iter().enumerate() {
//let result = device.render(buf, Rect {
//x: area.x,
//y,
//width: area.width,
//height: 21//area.height.saturating_sub(y)
//})?;
//if i == state.focus {
//if state.focused {
//draw_box_styled(buf, result, Some(Style::default().green().not_dim()))
//} else {
//draw_box_styled_dotted(buf, result, Some(Style::default().green().dim()))
//};
//};
////let result = Rect { x: 0, y: 0, width: result.width, height: 21 };
//x = x.max(result.width);
//y = y + result.height;
////y = y + 1;
//buf.set_string(area.x, y, "│", Style::default().black());
//buf.set_string(area.x + area.width - 1, y, "│", Style::default().black());
//buf.set_string(area.x + 2, y, " Patch in ┐ │ └ Patch out", Style::default().dim());
//y = y + 1;
////buf.set_string(area.x, y, format!("{y}---BOT---"), Style::default().red());
////buf.set_string(area.x + area.width - 1, area.y + 1, "│", Style::default().black());
////buf.set_string(area.x + 2, y, "Patch...", Style::default().dim());
//}
//Ok(draw_box(buf, Rect {
//x: area.x,
//y: area.y,
//width: area.width,
//height: y - area.y,
//}))
} }
pub fn draw_as_row ( pub fn draw_as_row (
@ -124,7 +89,7 @@ pub fn draw_as_row (
let mut h = 0u16; let mut h = 0u16;
let mut frames = vec![]; let mut frames = vec![];
for (i, device) in state.items.iter().enumerate() { for (i, device) in state.items.iter().enumerate() {
let mut x2 = 1u16; let mut x2 = 0u16;
let mut y2 = 1u16; let mut y2 = 1u16;
//for port in device.midi_ins()?.iter() { //for port in device.midi_ins()?.iter() {
//port.blit(buf, x, y + y2, Some(Style::default())); //port.blit(buf, x, y + y2, Some(Style::default()));
@ -170,6 +135,44 @@ pub fn draw_as_row (
pub fn draw_as_column ( pub fn draw_as_column (
state: &Chain, buf: &mut Buffer, area: Rect, selected: Option<Style> state: &Chain, buf: &mut Buffer, area: Rect, selected: Option<Style>
) -> Usually<Rect> { ) -> Usually<Rect> {
//let area = Rect { x, y, width: 40, height: 30 };
//let mut y = area.y;
//buf.set_string(area.x, y, "│", Style::default().black());
//buf.set_string(area.x + area.width - 1, y, "│", Style::default().black());
//buf.set_string(area.x + 2, y, "Input...", Style::default().dim());
//let mut x = 0u16;
//for (i, device) in state.items.iter().enumerate() {
//let result = device.render(buf, Rect {
//x: area.x,
//y,
//width: area.width,
//height: 21//area.height.saturating_sub(y)
//})?;
//if i == state.focus {
//if state.focused {
//draw_box_styled(buf, result, Some(Style::default().green().not_dim()))
//} else {
//draw_box_styled_dotted(buf, result, Some(Style::default().green().dim()))
//};
//};
////let result = Rect { x: 0, y: 0, width: result.width, height: 21 };
//x = x.max(result.width);
//y = y + result.height;
////y = y + 1;
//buf.set_string(area.x, y, "│", Style::default().black());
//buf.set_string(area.x + area.width - 1, y, "│", Style::default().black());
//buf.set_string(area.x + 2, y, " Patch in ┐ │ └ Patch out", Style::default().dim());
//y = y + 1;
////buf.set_string(area.x, y, format!("{y}---BOT---"), Style::default().red());
////buf.set_string(area.x + area.width - 1, area.y + 1, "│", Style::default().black());
////buf.set_string(area.x + 2, y, "Patch...", Style::default().dim());
//}
//Ok(draw_box(buf, Rect {
//x: area.x,
//y: area.y,
//width: area.width,
//height: y - area.y,
//}))
let Rect { x, mut y, width, height } = area; let Rect { x, mut y, width, height } = area;
//let (area, areas) = Column::draw(buf, area, &state.items, 0)?; //let (area, areas) = Column::draw(buf, area, &state.items, 0)?;
let mut w = 0u16; let mut w = 0u16;
@ -264,7 +267,7 @@ impl Focus for Chain {
} }
pub fn handle (state: &mut Chain, event: &AppEvent) -> Usually<bool> { pub fn handle (state: &mut Chain, event: &AppEvent) -> Usually<bool> {
handle_focus(state, event, keymap!(Chain { Ok(handle_focus(state, event, keymap!(Chain {
[Up, NONE, "focus_up", "focus row above", [Up, NONE, "focus_up", "focus row above",
|s: &mut Chain|s.handle_focus(&FocusEvent::Backward)], |s: &mut Chain|s.handle_focus(&FocusEvent::Backward)],
[Down, NONE, "focus_down", "focus row below", [Down, NONE, "focus_down", "focus row below",
@ -272,6 +275,13 @@ pub fn handle (state: &mut Chain, event: &AppEvent) -> Usually<bool> {
[Enter, NONE, "focus_down", "focus row below", [Enter, NONE, "focus_down", "focus row below",
|s: &mut Chain|s.handle_focus(&FocusEvent::Inward)], |s: &mut Chain|s.handle_focus(&FocusEvent::Inward)],
[Esc, NONE, "focus_down", "focus row below", [Esc, NONE, "focus_down", "focus row below",
|s: &mut Chain|s.handle_focus(&FocusEvent::Outward)] |s: &mut Chain|s.handle_focus(&FocusEvent::Outward)],
})) }))? || handle_keymap(state, event, keymap!(Chain {
[Char('a'), NONE, "add_device", "add a device", add_device]
}))?)
}
fn add_device (state: &mut Chain) -> Usually<bool> {
state.adding = true;
Ok(true)
} }

View file

@ -185,8 +185,8 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
use crate::device::transport::*; use crate::device::transport::*;
draw_play_stop(buf, x + 1, y, &state.playing); draw_play_stop(buf, x + 1, y, &state.playing);
draw_rec(buf, x + 12, y, state.sequencer().map(|s|s.recording).unwrap_or(false)); draw_rec(buf, x + 12, y, state.sequencer().map(|s|s.recording).unwrap_or(false));
draw_mon(buf, x + 19, y, state.sequencer().map(|s|s.monitoring).unwrap_or(false)); draw_dub(buf, x + 19, y, state.sequencer().map(|s|s.overdub).unwrap_or(false));
draw_dub(buf, x + 26, y, state.sequencer().map(|s|s.overdub).unwrap_or(false)); draw_mon(buf, x + 26, y, state.sequencer().map(|s|s.monitoring).unwrap_or(false));
draw_bpm(buf, x + 33, y, state.timebase.bpm() as usize); draw_bpm(buf, x + 33, y, state.timebase.bpm() as usize);
draw_timer(buf, x + width - 1, y, &state.timebase, state.current_frame); draw_timer(buf, x + width - 1, y, &state.timebase, state.current_frame);
} }
@ -259,23 +259,5 @@ fn draw_section_chains (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usual
} else { } else {
vec![] vec![]
}; };
//match state.view {
//LauncherView::Chains => {
//draw_box_styled(buf, Rect { height: 18, ..area }, style);
//},
//_ => {},
//};
//draw_highlight(buf, &Some(area), match state.view {
//LauncherView::Chains => Style::default().green().dim(),
//_ => Style::default().dim()
//});
//if let Some(chain) = &chain {
//if let Some(plugin) = plugins.get(chain.focus) {
//draw_highlight(buf, &Some(*plugin), match state.view {
//LauncherView::Chains => Style::default().green().not_dim(),
//_ => Style::default().green().dim()
//});
//}
//}
Ok(area) Ok(area)
} }

View file

@ -4,4 +4,4 @@ mod looper; pub use self::looper::Looper;
mod mixer; pub use self::mixer::Mixer; mod mixer; pub use self::mixer::Mixer;
mod sequencer; pub use self::sequencer::{Sequencer, Phrase}; mod sequencer; pub use self::sequencer::{Sequencer, Phrase};
mod track; pub use self::track::Track; mod track; pub use self::track::Track;
mod transport; pub use self::transport::Transport; mod transport;

View file

@ -66,82 +66,3 @@ pub fn draw_bpm (buf: &mut Buffer, x: u16, y: u16, bpm: usize) {
"1/16" "1/16"
.blit(buf, x + 29, y, Some(style.bold())); .blit(buf, x + 29, y, Some(style.bold()));
} }
pub struct Transport {
name: String,
/// Holds info about bpm
timebase: Arc<Timebase>,
transport: ::jack::Transport,
}
impl Transport {
pub fn new (name: &str, timebase: &Arc<Timebase>) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
let (client, _) = Client::new(name, ClientOptions::NO_START_SERVER)?;
let transport = client.transport();
DynamicDevice::new(render, handle, process, Self {
name: name.into(), timebase: timebase.clone(), transport
}).activate(client)
}
pub fn play_from_start_or_stop_and_rewind (&mut self) {
}
pub fn play_or_pause (&mut self) -> Result<(), Box<dyn Error>> {
match self.transport.query_state()? {
TransportState::Stopped => self.play(),
TransportState::Rolling => self.stop(),
_ => Ok(())
}
}
pub fn play (&mut self) -> Result<(), Box<dyn Error>> {
Ok(self.transport.start()?)
}
pub fn stop (&mut self) -> Result<(), Box<dyn Error>> {
Ok(self.transport.stop()?)
}
pub fn timebase (&self) -> Arc<Timebase> {
self.timebase.clone()
}
}
pub fn process (_: &mut Transport, _: &Client, _: &ProcessScope) -> Control {
Control::Continue
}
pub fn handle (_: &mut Transport, _: &AppEvent) -> Usually<bool> {
Ok(false)
}
pub fn render (state: &Transport, buf: &mut Buffer, mut area: Rect)
-> Usually<Rect>
{
//area.x = area.width.saturating_sub(80) / 2;
//area.width = area.width.min(80);
area.height = 3;
draw_box(buf, area);
let label = Style::default().white().not_dim();
let border = Style::default().gray().dim();
let mut x = 2;
for button in [
"PLAY",
"STOP",
"REC",
"DUB",
&format!("BPM {:03}.{:03}",
state.timebase.bpm() / 1000.0,
state.timebase.bpm() % 1000.0,
),
"0.0+00",
"0:00.000",
].iter() {
buf.set_string(area.x + x, area.y + 1, button, label);
x = x + button.len() as u16 + 1;
buf.set_string(area.x + x, area.y + 1, "", border);
x = x + 2;
}
Ok(area)
}