mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
bye chain
This commit is contained in:
parent
316fe45b2a
commit
2601592d17
8 changed files with 115 additions and 164 deletions
|
|
@ -1,4 +1,3 @@
|
|||
pub mod chain;
|
||||
pub mod focus;
|
||||
pub mod mixer;
|
||||
pub mod plugin;
|
||||
|
|
@ -334,3 +333,75 @@ fn rename (_: &mut App) -> Usually<bool> { Ok(true) }
|
|||
//s.sequencer_mut().map(|s|s.monitoring = !s.monitoring);
|
||||
//Ok(true)
|
||||
//}
|
||||
//use crate::{core::*, model::*};
|
||||
//use super::focus::*;
|
||||
|
||||
//pub fn handle (state: &mut Chain, event: &AppEvent) -> Usually<bool> {
|
||||
//Ok(handle_focus(state, event, keymap!(Chain {
|
||||
//[Up, NONE, "focus_up", "focus row above",
|
||||
//|s: &mut Chain|s.handle_focus(&FocusEvent::Backward)],
|
||||
//[Down, NONE, "focus_down", "focus row below",
|
||||
//|s: &mut Chain|s.handle_focus(&FocusEvent::Forward)],
|
||||
//[Enter, NONE, "focus_down", "focus row below",
|
||||
//|s: &mut Chain|s.handle_focus(&FocusEvent::Inward)],
|
||||
//[Esc, NONE, "focus_down", "focus row below",
|
||||
//|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)
|
||||
//}
|
||||
|
||||
//impl Focus for Chain {
|
||||
//fn unfocus (&mut self) {
|
||||
//self.focused = false
|
||||
//}
|
||||
//fn focused (&self) -> Option<&Box<dyn Device>> {
|
||||
//match self.focused {
|
||||
//true => self.items.get(self.focus),
|
||||
//false => None
|
||||
//}
|
||||
//}
|
||||
//fn focused_mut (&mut self) -> Option<&mut Box<dyn Device>> {
|
||||
//match self.focused {
|
||||
//true => self.items.get_mut(self.focus),
|
||||
//false => None
|
||||
//}
|
||||
//}
|
||||
//fn handle_focus (&mut self, event: &FocusEvent) -> Usually<bool> {
|
||||
//Ok(match event {
|
||||
//FocusEvent::Backward => {
|
||||
//if self.focus == 0 {
|
||||
//self.focus = self.items.len();
|
||||
//}
|
||||
//self.focus = self.focus - 1;
|
||||
//true
|
||||
//},
|
||||
//FocusEvent::Forward => {
|
||||
//self.focus = self.focus + 1;
|
||||
//if self.focus >= self.items.len() {
|
||||
//self.focus = 0;
|
||||
//}
|
||||
//true
|
||||
//},
|
||||
//FocusEvent::Inward => {
|
||||
//self.focused = true;
|
||||
//self.items[self.focus].handle(&AppEvent::Focus)?;
|
||||
//true
|
||||
//},
|
||||
//FocusEvent::Outward => {
|
||||
//if self.focused {
|
||||
//self.focused = false;
|
||||
//self.items[self.focus].handle(&AppEvent::Blur)?;
|
||||
//true
|
||||
//} else {
|
||||
//false
|
||||
//}
|
||||
//},
|
||||
//})
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
use crate::{core::*, model::*};
|
||||
use super::focus::*;
|
||||
|
||||
pub fn handle (state: &mut Chain, event: &AppEvent) -> Usually<bool> {
|
||||
Ok(handle_focus(state, event, keymap!(Chain {
|
||||
[Up, NONE, "focus_up", "focus row above",
|
||||
|s: &mut Chain|s.handle_focus(&FocusEvent::Backward)],
|
||||
[Down, NONE, "focus_down", "focus row below",
|
||||
|s: &mut Chain|s.handle_focus(&FocusEvent::Forward)],
|
||||
[Enter, NONE, "focus_down", "focus row below",
|
||||
|s: &mut Chain|s.handle_focus(&FocusEvent::Inward)],
|
||||
[Esc, NONE, "focus_down", "focus row below",
|
||||
|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)
|
||||
}
|
||||
|
||||
impl Focus for Chain {
|
||||
fn unfocus (&mut self) {
|
||||
self.focused = false
|
||||
}
|
||||
fn focused (&self) -> Option<&Box<dyn Device>> {
|
||||
match self.focused {
|
||||
true => self.items.get(self.focus),
|
||||
false => None
|
||||
}
|
||||
}
|
||||
fn focused_mut (&mut self) -> Option<&mut Box<dyn Device>> {
|
||||
match self.focused {
|
||||
true => self.items.get_mut(self.focus),
|
||||
false => None
|
||||
}
|
||||
}
|
||||
fn handle_focus (&mut self, event: &FocusEvent) -> Usually<bool> {
|
||||
Ok(match event {
|
||||
FocusEvent::Backward => {
|
||||
if self.focus == 0 {
|
||||
self.focus = self.items.len();
|
||||
}
|
||||
self.focus = self.focus - 1;
|
||||
true
|
||||
},
|
||||
FocusEvent::Forward => {
|
||||
self.focus = self.focus + 1;
|
||||
if self.focus >= self.items.len() {
|
||||
self.focus = 0;
|
||||
}
|
||||
true
|
||||
},
|
||||
FocusEvent::Inward => {
|
||||
self.focused = true;
|
||||
self.items[self.focus].handle(&AppEvent::Focus)?;
|
||||
true
|
||||
},
|
||||
FocusEvent::Outward => {
|
||||
if self.focused {
|
||||
self.focused = false;
|
||||
self.items[self.focus].handle(&AppEvent::Blur)?;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ pub struct App {
|
|||
pub time_cursor: usize,
|
||||
}
|
||||
|
||||
process!(App |self, client, scope| {
|
||||
process!(App |self, _client, scope| {
|
||||
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
||||
self.playing = Some(transport.state);
|
||||
self.playhead = transport.pos.frame() as usize;
|
||||
|
|
@ -208,9 +208,6 @@ impl App {
|
|||
self.scenes.get_mut(id).map(|t|(id, t))
|
||||
} }
|
||||
}
|
||||
pub fn chain (&self) -> Option<&Chain> {
|
||||
Some(&self.track()?.1.chain)
|
||||
}
|
||||
pub fn phrase_id (&self) -> Option<usize> {
|
||||
let (track_id, _) = self.track()?;
|
||||
let (_, scene) = self.scene()?;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
pub mod chain;
|
||||
pub mod looper;
|
||||
pub mod mixer;
|
||||
pub mod phrase;
|
||||
|
|
@ -10,7 +9,6 @@ pub mod track;
|
|||
pub use self::phrase::Phrase;
|
||||
pub use self::scene::Scene;
|
||||
pub use self::track::Track;
|
||||
pub use self::chain::Chain;
|
||||
pub use self::sampler::{Sampler, Sample};
|
||||
pub use self::mixer::Mixer;
|
||||
pub use self::plugin::{Plugin, PluginKind, lv2::LV2Plugin};
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
use crate::{core::*, view::*};
|
||||
|
||||
pub struct Chain {
|
||||
pub name: String,
|
||||
pub focused: bool,
|
||||
pub focus: usize,
|
||||
pub items: Vec<Box<dyn Device>>,
|
||||
pub view: ChainViewMode,
|
||||
pub adding: bool,
|
||||
}
|
||||
render!(Chain = crate::view::chain::render);
|
||||
handle!(Chain = crate::control::chain::handle);
|
||||
process!(Chain);
|
||||
impl Chain {
|
||||
pub fn new (name: &str, items: Option<Vec<Box<dyn Device>>>) -> Usually<Self> {
|
||||
Ok(Self {
|
||||
name: name.into(),
|
||||
focused: false,
|
||||
focus: 0,
|
||||
items: items.unwrap_or_else(||vec![]),
|
||||
view: ChainViewMode::Column,
|
||||
adding: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl PortList for Chain {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
if let Some(device) = self.items.get(0) {
|
||||
device.midi_ins()
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
if let Some(device) = self.items.get(self.items.len().saturating_sub(1)) {
|
||||
device.audio_outs()
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process (_: &mut Chain, _: &Client, _: &ProcessScope) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
|
|
@ -18,7 +18,9 @@ pub struct Track {
|
|||
/// Red keys on piano roll.
|
||||
pub notes_on: Vec<bool>,
|
||||
/// Device chain
|
||||
pub chain: Chain,
|
||||
pub devices: Vec<Box<dyn Device>>,
|
||||
/// Device selector
|
||||
pub device: usize,
|
||||
}
|
||||
|
||||
impl Track {
|
||||
|
|
@ -30,14 +32,15 @@ impl Track {
|
|||
) -> Usually<Self> {
|
||||
Ok(Self {
|
||||
name: name.to_string(),
|
||||
chain: Chain::new(&name, devices)?,
|
||||
midi_out: jack.register_port(name, MidiOut)?,
|
||||
notes_on: vec![],
|
||||
monitoring: false,
|
||||
recording: false,
|
||||
overdub: true,
|
||||
sequence: None,
|
||||
phrases: phrases.unwrap_or_else(||vec![])
|
||||
phrases: phrases.unwrap_or_else(||vec![]),
|
||||
devices: devices.unwrap_or_else(||vec![]),
|
||||
device: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ render!(App |self, buf, area| {
|
|||
let track = self.tracks.get(self.track_cursor - 1);
|
||||
y = y + ChainView {
|
||||
focused: self.section == 1,
|
||||
chain: track.map(|t|&t.chain),
|
||||
chain: track,
|
||||
}.render(buf, Rect { x, y, width, height: height / 3 })?.height;
|
||||
|
||||
y = y + SequencerView {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub enum ChainViewMode {
|
|||
|
||||
pub struct ChainView<'a> {
|
||||
pub focused: bool,
|
||||
pub chain: Option<&'a Chain>,
|
||||
pub chain: Option<&'a Track>,
|
||||
}
|
||||
|
||||
impl<'a> Render for ChainView<'a> {
|
||||
|
|
@ -34,12 +34,12 @@ impl<'a> Render for ChainView<'a> {
|
|||
}
|
||||
|
||||
pub fn draw_as_row (
|
||||
state: &Chain, buf: &mut Buffer, area: Rect, style: Option<Style>
|
||||
state: &Track, buf: &mut Buffer, area: Rect, style: Option<Style>
|
||||
) -> Usually<(Rect, Vec<Rect>)> {
|
||||
let Rect { mut x, y, width, height } = area;
|
||||
let mut h = 3u16;
|
||||
let mut frames = vec![];
|
||||
for (i, device) in state.items.iter().enumerate() {
|
||||
for (i, device) in state.devices.iter().enumerate() {
|
||||
let x2 = 0u16;
|
||||
let _y2 = 1u16;
|
||||
//for port in device.midi_ins()?.iter() {
|
||||
|
|
@ -74,39 +74,11 @@ pub fn draw_as_row (
|
|||
let label = "[Add device…]";
|
||||
label.blit(buf, x + 1, area.y + 1, Some(Style::default().dim()));
|
||||
x = x + 1 + label.len() as u16 + 1;
|
||||
Ok((Rect { x: area.x, y: area.y, width, height: h }, frames))
|
||||
}
|
||||
|
||||
pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
|
||||
-> Usually<Rect>
|
||||
{
|
||||
let Rect { x, y, .. } = area;
|
||||
let selected = Some(if state.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
});
|
||||
let result = match state.view {
|
||||
ChainViewMode::Hidden => Rect { x, y, width: 0, height: 0 },
|
||||
ChainViewMode::Compact => {
|
||||
let area = Rect { x, y, width: (state.name.len() + 4) as u16, height: 3 };
|
||||
buf.set_string(area.x + 2, area.y + 1, &state.name, Style::default());
|
||||
draw_box_styled(buf, area, selected)
|
||||
},
|
||||
ChainViewMode::Row => {
|
||||
draw_box_styled(buf, area, selected);
|
||||
let (area, _) = Row::draw(buf, area, &state.items, 0)?;
|
||||
area
|
||||
},
|
||||
ChainViewMode::Column => {
|
||||
draw_as_column(state, buf, area, selected)?
|
||||
},
|
||||
};
|
||||
Ok(result)
|
||||
Ok((Rect { x: area.x, y: area.y, width: x, height: h }, frames))
|
||||
}
|
||||
|
||||
pub fn draw_as_column (
|
||||
state: &Chain, buf: &mut Buffer, area: Rect, selected: Option<Style>
|
||||
state: &Track, buf: &mut Buffer, area: Rect, selected: Option<Style>
|
||||
) -> Usually<Rect> {
|
||||
//let area = Rect { x, y, width: 40, height: 30 };
|
||||
//let mut y = area.y;
|
||||
|
|
@ -150,7 +122,7 @@ pub fn draw_as_column (
|
|||
//let (area, areas) = Column::draw(buf, area, &state.items, 0)?;
|
||||
let mut w = 0u16;
|
||||
let mut frames = vec![];
|
||||
for device in state.items.iter() {
|
||||
for device in state.devices.iter() {
|
||||
let style_midi = Style::default().black().bold().on_green();
|
||||
let style_audio = Style::default().black().bold().on_red();
|
||||
let midi_ins = device.midi_ins()?;
|
||||
|
|
@ -185,6 +157,34 @@ pub fn draw_as_column (
|
|||
y = y + 1;
|
||||
}
|
||||
}
|
||||
draw_box_styled(buf, frames[state.focus], selected);
|
||||
draw_box_styled(buf, frames[state.device], selected);
|
||||
Ok(area)
|
||||
}
|
||||
|
||||
//pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
|
||||
//-> Usually<Rect>
|
||||
//{
|
||||
//let Rect { x, y, .. } = area;
|
||||
//let selected = Some(if state.focused {
|
||||
//Style::default().green().not_dim()
|
||||
//} else {
|
||||
//Style::default().green().dim()
|
||||
//});
|
||||
//let result = match state.view {
|
||||
//ChainViewMode::Hidden => Rect { x, y, width: 0, height: 0 },
|
||||
//ChainViewMode::Compact => {
|
||||
//let area = Rect { x, y, width: (state.name.len() + 4) as u16, height: 3 };
|
||||
//buf.set_string(area.x + 2, area.y + 1, &state.name, Style::default());
|
||||
//draw_box_styled(buf, area, selected)
|
||||
//},
|
||||
//ChainViewMode::Row => {
|
||||
//draw_box_styled(buf, area, selected);
|
||||
//let (area, _) = Row::draw(buf, area, &state.items, 0)?;
|
||||
//area
|
||||
//},
|
||||
//ChainViewMode::Column => {
|
||||
//draw_as_column(state, buf, area, selected)?
|
||||
//},
|
||||
//};
|
||||
//Ok(result)
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue