wip: big mixer view on scene list focus

This commit is contained in:
🪞👃🪞 2024-07-04 16:08:12 +03:00
parent 8d11ae87c0
commit 9a6e7ab3b4
4 changed files with 142 additions and 102 deletions

View file

@ -114,7 +114,7 @@ pub fn main_thread (
terminal.draw(|frame|{
let area = frame.size();
let buffer = frame.buffer_mut();
device.lock().unwrap().render(buffer, area).expect("Failed to render content.");
device.lock().unwrap().render(buffer, area).expect("Failed to render content");
}).expect("Failed to render frame");
if exited.fetch_and(true, Ordering::Relaxed) {
@ -125,6 +125,7 @@ pub fn main_thread (
}))
}
/// Spawn thread that listens for user input
pub fn input_thread (
exited: &Arc<AtomicBool>,

View file

@ -27,17 +27,15 @@ pub fn main () -> Usually<()> {
state.scenes = vec![
Scene::new("Intro", vec![None, Some(0), None, None]),
Scene::new("Hook", vec![Some(0), Some(0), None, None]),
Scene::new("Verse", vec![None, Some(0), None, None]),
Scene::new("Chorus", vec![None, Some(0), None, None]),
Scene::new("Bridge", vec![None, Some(0), None, None]),
Scene::new("Verse", vec![Some(1), Some(0), None, None]),
Scene::new("Chorus", vec![Some(0), Some(0), None, None]),
Scene::new("Bridge", vec![Some(2), Some(0), None, None]),
Scene::new("Outro", vec![None, Some(0), None, None]),
];
let jack = jack_run("tek", &app)?;
let client = jack.as_client();
let timebase = &state.timebase;
let ppq = timebase.ppq() as usize;
state.tracks[0].sequence = Some(0);
state.tracks[1].sequence = Some(0);
state.track_cursor = 1;
state.scene_cursor = 1;
state.note_start = 12;

View file

@ -10,7 +10,7 @@ pub mod plugin;
pub use self::layout::*;
pub use self::transport::TransportView;
pub use self::grid::SceneGridView;
pub use self::chain::{ChainView, ChainViewMode};
pub use self::chain::ChainView;
pub use self::sequencer::SequencerView;
use crate::{render, App, core::*};
@ -40,22 +40,56 @@ render!(App |self, buf, area| {
if self.track_cursor > 0 {
let track = self.tracks.get(self.track_cursor - 1).unwrap();
let track = self.tracks
.get(self.track_cursor - 1)
.unwrap();
ChainView { focused: self.section == 1, track: Some(track) }
ChainView {
focused: self.section == 1,
track: Some(track),
vertical: false,
}
.render(buf, Rect { x, y: y + height - height / 3 - 1, width, height: height / 3 })?.height;
SequencerView {
let phrase = self.phrase_id()
.map(|id|track.phrases.get(id))
.flatten();
let seq_area = SequencerView {
focused: self.section == 2,
ppq: self.timebase.ppq() as usize,
now: self.timebase.frames_pulses(self.playhead as f64) as usize,
phrase: track.phrases.get(0),
phrase: phrase,
time_cursor: self.time_cursor,
time_start: self.time_start,
time_zoom: self.time_zoom,
note_cursor: self.note_cursor,
note_start: self.note_start,
}.render(buf, Rect { x, y, width, height: height - height / 3 })?;
if phrase.is_none() && self.section == 2 {
let label = format!("[ENTER] Create new clip: {}", track.name);
let x = x + seq_area.width / 2 - (label.len() / 2) as u16;
let y = y + seq_area.height / 2;
label.blit(buf, x, y, Some(Style::default().white()));
}
} else {
let mut x = x;
for track in self.tracks.iter() {
track.name.blit(buf, x + 1, y, Some(Style::default().white().bold()));
x = x + ChainView {
focused: self.section == 1,
track: Some(track),
vertical: true,
}
.render(buf, Rect { x, y: y + 1, width, height: height / 3 })?
.width
.max(track.name.len() as u16);
}
}
if let Some(ref modal) = self.modal {

View file

@ -2,16 +2,10 @@ use crate::core::*;
use crate::view::*;
use crate::model::*;
pub enum ChainViewMode {
Hidden,
Compact,
Row,
Column,
}
pub struct ChainView<'a> {
pub focused: bool,
pub track: Option<&'a Track>,
pub focused: bool,
pub track: Option<&'a Track>,
pub vertical: bool,
}
impl<'a> Render for ChainView<'a> {
@ -33,7 +27,11 @@ impl<'a> Render for ChainView<'a> {
}
lozenge_left(buf, x, y, height, style);
let (area, _plugins) = if let Some(ref chain) = self.track {
self.draw_as_row(buf, area, style)?
if self.vertical {
self.draw_as_column(buf, area, style)?
} else {
self.draw_as_row(buf, area, style)?
}
} else {
(area, vec![])
};
@ -98,91 +96,93 @@ impl<'a> ChainView<'a> {
Ok((Rect { x: area.x, y: area.y, width: x, height: h }, frames))
}
}
pub fn draw_as_column (
&self, buf: &mut Buffer, area: Rect, selected: Option<Style>
) -> Usually<(Rect, Vec<Rect>)> {
let Rect { x, mut y, width, height } = area;
let mut w = 0u16;
let mut frames = vec![];
let track = self.track.as_ref().unwrap();
for (i, device) in track.devices.iter().enumerate() {
//let midi_ins = device.midi_ins()?;
//let midi_outs = device.midi_outs()?;
//let audio_ins = device.audio_ins()?;
//let audio_outs = device.audio_outs()?;
let device = device.state.lock().unwrap();
//let style_midi = Style::default().black().bold().on_green();
//let style_audio = Style::default().black().bold().on_red();
//y = y + midi_ins.len() as u16;
let frame = device.render(buf, Rect {
x, y, width, height: height.saturating_sub(y)
})?;
frames.push(frame);
w = w.max(frame.width);
y = y + frame.height;
//y = y - midi_ins.len() as u16;
//for port in midi_ins.iter() {
//buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {} ", port.name()?), style_midi);
//y = y + 1;
//}
//y = y - audio_ins.len() as u16;
//for port in audio_ins.iter() {
//buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {} ", port.name()?), style_audio);
//y = y + 1;
//}
//y = y + frame.height - 1;
//y = y + midi_outs.len() as u16;
//for port in midi_outs.iter() {
//buf.set_string(x + 2, y, &format!(" <o> MIDI {} ", port.name()?), style_midi);
//y = y + 1;
//}
//y = y + audio_outs.len() as u16;
//for port in audio_outs.iter() {
//buf.set_string(x + 2, y, &format!(" <o> Audio {} ", port.name()?), style_audio);
//y = y + 1;
//}
}
draw_box_styled(buf, frames[track.device], selected);
Ok((Rect { x, y: area.y, width: w, height: y - area.y }, frames))
pub fn draw_as_column (
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;
//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;
//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, " 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 (area, areas) = Column::draw(buf, area, &state.items, 0)?;
let mut w = 0u16;
let mut frames = vec![];
for device in state.devices.iter() {
let midi_ins = device.midi_ins()?;
let midi_outs = device.midi_outs()?;
let audio_ins = device.audio_ins()?;
let audio_outs = device.audio_outs()?;
let device = device.state.lock().unwrap();
let style_midi = Style::default().black().bold().on_green();
let style_audio = Style::default().black().bold().on_red();
y = y + midi_ins.len() as u16;
let frame = device.render(buf, Rect {
x, y, width, height: height.saturating_sub(y)
})?;
frames.push(frame);
w = w.max(frame.width);
y = y - midi_ins.len() as u16;
for port in midi_ins.iter() {
buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {} ", port.name()?), style_midi);
y = y + 1;
}
y = y - audio_ins.len() as u16;
for port in audio_ins.iter() {
buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {} ", port.name()?), style_audio);
y = y + 1;
}
y = y + frame.height - 1;
y = y + midi_outs.len() as u16;
for port in midi_outs.iter() {
buf.set_string(x + 2, y, &format!(" <o> MIDI {} ", port.name()?), style_midi);
y = y + 1;
}
y = y + audio_outs.len() as u16;
for port in audio_outs.iter() {
buf.set_string(x + 2, y, &format!(" <o> Audio {} ", port.name()?), style_audio);
y = y + 1;
}
//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,
//}))
}
draw_box_styled(buf, frames[state.device], selected);
Ok(area)
}
//pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
@ -212,3 +212,10 @@ pub fn draw_as_column (
//};
//Ok(result)
//}
//pub enum ChainViewMode {
//Hidden,
//Compact,
//Row,
//Column,
//}