mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-08-07 22:17:07 +02:00
placebo
This commit is contained in:
parent
3ae2467acc
commit
94c1f83ef2
13 changed files with 277 additions and 124 deletions
|
|
@ -1,17 +1,36 @@
|
|||
use crate::core::*;
|
||||
use super::*;
|
||||
pub struct LauncherGrid<'a> {
|
||||
state: &'a Launcher,
|
||||
buf: &'a mut Buffer,
|
||||
area: Rect,
|
||||
focused: bool,
|
||||
pub struct SceneGrid<'a> {
|
||||
pub buf: &'a mut Buffer,
|
||||
pub area: Rect,
|
||||
pub name: &'a str,
|
||||
pub focused: bool,
|
||||
pub scenes: &'a[Scene],
|
||||
pub tracks: &'a[Track],
|
||||
pub cursor: &'a(usize, usize),
|
||||
}
|
||||
impl<'a> LauncherGrid<'a> {
|
||||
pub fn new (state: &'a Launcher, buf: &'a mut Buffer, area: Rect, focused: bool) -> Self {
|
||||
Self { state, buf, area, focused }
|
||||
impl<'a> SceneGrid<'a> {
|
||||
pub fn new (
|
||||
buf: &'a mut Buffer,
|
||||
area: Rect,
|
||||
name: &'a str,
|
||||
focused: bool,
|
||||
scenes: &'a[Scene],
|
||||
tracks: &'a[Track],
|
||||
cursor: &'a(usize, usize),
|
||||
) -> Self {
|
||||
Self {
|
||||
buf,
|
||||
area,
|
||||
name,
|
||||
focused,
|
||||
scenes,
|
||||
tracks,
|
||||
cursor,
|
||||
}
|
||||
}
|
||||
pub fn draw (&mut self) -> Usually<Rect> {
|
||||
self.area.height = self.state.scenes.len() as u16 + 2;
|
||||
self.area.height = self.scenes.len() as u16 + 2;
|
||||
let style = Some(Style::default().green().dim());
|
||||
if self.focused {
|
||||
let Rect { x, y, width, height } = self.area;
|
||||
|
|
@ -24,9 +43,9 @@ impl<'a> LauncherGrid<'a> {
|
|||
if x >= self.area.x + self.area.width {
|
||||
break
|
||||
}
|
||||
self.separator_v(x, i == self.state.cursor.0);
|
||||
self.separator_v(x, i == self.cursor.0);
|
||||
x = x + w;
|
||||
self.separator_v(x, i == self.state.cursor.0);
|
||||
self.separator_v(x, i == self.cursor.0);
|
||||
}
|
||||
let (mut x, y) = (self.area.x, self.area.y);
|
||||
for (i, title) in columns.iter().enumerate() {
|
||||
|
|
@ -34,7 +53,7 @@ impl<'a> LauncherGrid<'a> {
|
|||
break
|
||||
}
|
||||
title.blit(
|
||||
self.buf, x+1, y, Some(self.highlight(i == self.state.cursor.0).bold())
|
||||
self.buf, x+1, y, Some(self.highlight(i == self.cursor.0).bold())
|
||||
);
|
||||
if i == 0 {
|
||||
self.scenes(x+1, y + 1);
|
||||
|
|
@ -49,8 +68,8 @@ impl<'a> LauncherGrid<'a> {
|
|||
}
|
||||
|
||||
fn column_names (&self) -> Vec<&'a str> {
|
||||
let mut column_names = vec![self.state.name.as_str()];
|
||||
for track in self.state.tracks.iter() {
|
||||
let mut column_names = vec![self.name];
|
||||
for track in self.tracks.iter() {
|
||||
column_names.push(track.name.as_str());
|
||||
}
|
||||
column_names
|
||||
|
|
@ -63,23 +82,23 @@ impl<'a> LauncherGrid<'a> {
|
|||
fn scenes (&mut self, x: u16, y: u16) -> u16 {
|
||||
let mut index = 0usize;
|
||||
loop {
|
||||
if index >= self.state.scenes.len() {
|
||||
if index >= self.scenes.len() {
|
||||
break
|
||||
}
|
||||
if y + index as u16 >= self.area.height {
|
||||
break
|
||||
}
|
||||
if let Some(scene) = self.state.scenes.get(index) {
|
||||
if let Some(scene) = self.scenes.get(index) {
|
||||
let style = Some(self.highlight(
|
||||
(0 == self.state.cursor.0) && (index + 1 == self.state.cursor.1)
|
||||
(0 == self.cursor.0) && (index + 1 == self.cursor.1)
|
||||
).bold());
|
||||
"⯈".blit(self.buf, x, y + index as u16, style);
|
||||
scene.name.blit(self.buf, x+1, y + index as u16, style);
|
||||
}
|
||||
index = index + 1;
|
||||
}
|
||||
let hi = (0 == self.state.cursor.0) &&
|
||||
(self.state.scenes.len() + 1 == self.state.cursor.1);
|
||||
let hi = (0 == self.cursor.0) &&
|
||||
(self.scenes.len() + 1 == self.cursor.1);
|
||||
"+Add scene…".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||
self.highlight(true)
|
||||
} else {
|
||||
|
|
@ -91,20 +110,20 @@ impl<'a> LauncherGrid<'a> {
|
|||
fn clips (&mut self, x: u16, y: u16, track: usize) -> u16 {
|
||||
let mut index = 0;
|
||||
loop {
|
||||
if index >= self.state.scenes.len() {
|
||||
if index >= self.scenes.len() {
|
||||
break
|
||||
}
|
||||
if y + index as u16 >= self.area.height {
|
||||
break
|
||||
}
|
||||
if let Some(scene) = self.state.scenes.get(index) {
|
||||
let hi = (track + 1 == self.state.cursor.0) &&
|
||||
(index + 1 == self.state.cursor.1);
|
||||
if let Some(scene) = self.scenes.get(index) {
|
||||
let hi = (track + 1 == self.cursor.0) &&
|
||||
(index + 1 == self.cursor.1);
|
||||
let style = Some(self.highlight(hi));
|
||||
let clip = scene.clips.get(track);
|
||||
let index = index as u16;
|
||||
let label = if let Some(Some(clip)) = clip {
|
||||
let track = self.state.tracks[track].sequencer.state();
|
||||
let track = self.tracks[track].sequencer.state();
|
||||
let phrase = track.phrases.get(*clip);
|
||||
if let Some(phrase) = phrase {
|
||||
format!("⯈{}", phrase.name)
|
||||
|
|
@ -118,8 +137,8 @@ impl<'a> LauncherGrid<'a> {
|
|||
}
|
||||
index = index + 1;
|
||||
}
|
||||
let hi = (track + 1 == self.state.cursor.0) &&
|
||||
(self.state.scenes.len() + 1 == self.state.cursor.1);
|
||||
let hi = (track + 1 == self.cursor.0) &&
|
||||
(self.scenes.len() + 1 == self.cursor.1);
|
||||
" + Add clip".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||
self.highlight(true)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::core::*;
|
||||
use crate::layout::*;
|
||||
use crate::device::*;
|
||||
mod grid;
|
||||
pub use self::grid::*; mod handle;
|
||||
pub use self::handle::*;
|
||||
mod grid; pub use self::grid::*;
|
||||
mod handle; pub use self::handle::*;
|
||||
mod scene; pub use self::scene::*;
|
||||
pub struct Launcher {
|
||||
name: String,
|
||||
timebase: Arc<Timebase>,
|
||||
|
|
@ -20,28 +20,6 @@ pub struct Launcher {
|
|||
view: LauncherView,
|
||||
modal: Option<Box<dyn Modal<Self>>>,
|
||||
}
|
||||
pub enum LauncherView {
|
||||
Tracks,
|
||||
Sequencer,
|
||||
Chains
|
||||
}
|
||||
impl LauncherView {
|
||||
fn is_tracks (&self) -> bool {
|
||||
match self { Self::Tracks => true, _ => false }
|
||||
}
|
||||
}
|
||||
pub struct Scene {
|
||||
name: String,
|
||||
clips: Vec<Option<usize>>,
|
||||
}
|
||||
impl Scene {
|
||||
pub fn new (name: impl AsRef<str>, clips: impl AsRef<[Option<usize>]>) -> Self {
|
||||
Self {
|
||||
name: name.as_ref().into(),
|
||||
clips: clips.as_ref().iter().map(|x|x.clone()).collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Launcher {
|
||||
pub fn new (
|
||||
name: &str,
|
||||
|
|
@ -144,7 +122,7 @@ impl Launcher {
|
|||
}
|
||||
}
|
||||
impl DynamicDevice<Launcher> {
|
||||
pub fn connect (self, midi_in: &str, audio_outs: &[&str]) -> Usually<Self> {
|
||||
pub fn connect (&self, midi_in: &str, audio_outs: &[&str]) -> Usually<&Self> {
|
||||
{
|
||||
let state = &self.state();
|
||||
let (client, _status) = Client::new(
|
||||
|
|
@ -197,16 +175,26 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
|
|||
frame: state.current_frame
|
||||
}.render(buf, area)?.height;
|
||||
|
||||
y = y + LauncherGrid::new(
|
||||
state, buf, Rect { x, y, width, height: height/3 }, state.view.is_tracks()
|
||||
).draw()?.height;
|
||||
y = y + crate::device::launcher::SceneGrid {
|
||||
buf,
|
||||
area: Rect { x, y, width, height },
|
||||
name: &state.name,
|
||||
focused: state.view.is_tracks(),
|
||||
scenes: &state.scenes,
|
||||
tracks: &state.tracks,
|
||||
cursor: &state.cursor
|
||||
}.draw()?.height;
|
||||
|
||||
y = y + draw_section_chains(
|
||||
state, buf, Rect { x, y, width, height: height/3 }
|
||||
state,
|
||||
buf,
|
||||
Rect { x, y, width, height: height/3 }
|
||||
)?.height;
|
||||
|
||||
y = y + draw_section_sequencer(
|
||||
state, buf, Rect { x, y, width, height: height - y }
|
||||
state,
|
||||
buf,
|
||||
Rect { x, y, width, height: height - y }
|
||||
)?.height;
|
||||
|
||||
area.height = y;
|
||||
|
|
@ -262,14 +250,11 @@ fn draw_section_sequencer (state: &Launcher, buf: &mut Buffer, area: Rect) -> Us
|
|||
}
|
||||
fn draw_section_chains (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let style = Some(Style::default().green().dim());
|
||||
match state.view {
|
||||
LauncherView::Chains => {
|
||||
let Rect { x, y, width, height} = area;
|
||||
lozenge_left(buf, x, y, height, style);
|
||||
lozenge_right(buf, x + width - 1, y, height, style);
|
||||
},
|
||||
_ => {},
|
||||
};
|
||||
if state.view.is_chains() {
|
||||
let Rect { x, y, width, height} = area;
|
||||
lozenge_left(buf, x, y, height, style);
|
||||
lozenge_right(buf, x + width - 1, y, height, style);
|
||||
}
|
||||
let chain = state.chain();
|
||||
let _ = if let Some(chain) = &chain {
|
||||
let (_, plugins) = crate::device::chain::draw_as_row(
|
||||
|
|
@ -281,3 +266,16 @@ fn draw_section_chains (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usual
|
|||
};
|
||||
Ok(area)
|
||||
}
|
||||
pub enum LauncherView {
|
||||
Tracks,
|
||||
Sequencer,
|
||||
Chains
|
||||
}
|
||||
impl LauncherView {
|
||||
fn is_chains (&self) -> bool {
|
||||
match self { Self::Chains => true, _ => false }
|
||||
}
|
||||
fn is_tracks (&self) -> bool {
|
||||
match self { Self::Tracks => true, _ => false }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
src/device/launcher/scene.rs
Normal file
13
src/device/launcher/scene.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
pub struct Scene {
|
||||
pub name: String,
|
||||
pub clips: Vec<Option<usize>>,
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
pub fn new (name: impl AsRef<str>, clips: impl AsRef<[Option<usize>]>) -> Self {
|
||||
Self {
|
||||
name: name.as_ref().into(),
|
||||
clips: clips.as_ref().iter().map(|x|x.clone()).collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,8 +127,8 @@ pub fn lanes (
|
|||
phrase.contains_note_on(u7::from_int_lossy(note_b as u8), a, b),
|
||||
) {
|
||||
(true, true) => ("█", wh),
|
||||
(false, true) => ("▄", wh),
|
||||
(true, false) => ("▀", wh),
|
||||
(false, true) => ("▀", wh),
|
||||
(true, false) => ("▄", wh),
|
||||
(false, false) => ("·", bw),
|
||||
};
|
||||
let y = y + height.saturating_sub(index+2) as u16;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue