rgb highlights

This commit is contained in:
🪞👃🪞 2024-07-06 23:25:43 +03:00
parent 6724f3848d
commit f9fa24de0d
5 changed files with 203 additions and 109 deletions

View file

@ -88,6 +88,9 @@ impl Sampler {
for index in 0..scope.n_frames() as usize {
if let Some(frame) = voice.next() {
for (channel, sample) in frame.iter().enumerate() {
//self.buffer[channel % channel_count][index] = (
//(self.buffer[channel % channel_count][index] + sample * self.output_gain) / 2.0
//);
self.buffer[channel % channel_count][index] += sample * self.output_gain;
}
} else {

View file

@ -33,6 +33,7 @@ render!(App |self, buf, area| {
buf,
area: Rect { x, y, width, height: height / 3 },
focused: self.section == 0,
entered: self.entered,
scenes: &self.scenes,
tracks: &self.tracks,
cursor: &(self.track_cursor, self.scene_cursor),
@ -42,6 +43,7 @@ render!(App |self, buf, area| {
buf,
area: Rect { x, y, width, height: height / 3 },
focused: self.section == 0,
entered: self.entered,
scenes: &self.scenes,
tracks: &self.tracks,
cursor: &(self.track_cursor, self.scene_cursor),
@ -68,7 +70,7 @@ render!(App |self, buf, area| {
phrase,
focused: self.section == 2,
ppq: self.timebase.ppq() as usize,
now: self.timebase.pulse_to_frame(self.playhead as f64) as usize,
now: self.timebase.frame_to_pulse(self.playhead as f64) as usize,
time_cursor: self.time_cursor,
time_start: self.time_start,
time_zoom: self.time_zoom,
@ -107,3 +109,18 @@ render!(App |self, buf, area| {
Ok(area)
});
pub fn fill_bg (buf: &mut Buffer, area: Rect, color: Color) {
let Rect { x, y, width, height } = area;
for y in y..y+height {
if y >= buf.area.height {
break
}
for x in x..x+width {
if x >= buf.area.width {
break
}
buf.get_mut(x, y).set_bg(color);
}
}
}

View file

@ -25,6 +25,11 @@ impl<'a> Render for ChainView<'a> {
Some(Style::default().dim().bold())
);
}
fill_bg(buf, area, if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
});
lozenge_left(buf, x, y, height, style);
let (area, _plugins) = if self.track.is_some() {
if self.vertical {

View file

@ -1,131 +1,95 @@
use crate::core::*;
use crate::model::*;
use crate::view::*;
pub struct SceneGridViewHorizontal<'a> {
pub buf: &'a mut Buffer,
pub area: Rect,
pub scenes: &'a[Scene],
pub tracks: &'a[Track],
pub cursor: &'a(usize, usize),
pub focused: bool
}
impl<'a> SceneGridViewHorizontal<'a> {
pub fn size (&self) -> (u16, u16) {
let (mut w, mut h) = (4, 2);
w = w + self.longest_track_name();
w = w + self.scenes.len() as u16 * 10;
h = h + self.tracks.len();
(w as u16, h as u16)
}
fn longest_track_name (&self) -> u16 {
let mut w = 3u16;
for track in self.tracks.iter() {
w = w.max(track.name.len() as u16);
}
w
}
pub fn draw (&mut self) -> Usually<Rect> {
//let (w, h) = self.size_horizontal();
//self.area.x = self.area.x + self.area.width.saturating_sub(w) / 2;
self.area.height = self.tracks.len() as u16 + 2;
//self.area.width = w;
let style = Some(Style::default().green().dim());
let Rect { x, y, width, height } = self.area;
if self.focused {
lozenge_left(self.buf, x, y, height, style);
lozenge_right(self.buf, x + width - 1, y, height, style);
}
let style = Some(Style::default().bold().not_dim().white());
"Mix".blit(self.buf, x + 1, y, style);
let mut x2 = 0;
let style = Some(Style::default().bold());
for (i, track) in self.tracks.iter().enumerate() {
let label = format!(" {:8} [R] [D] [M] ", &track.name);
label.blit(self.buf, x + 1, y + 1 + i as u16, style);
x2 = x2.max(label.len() as u16 + 1);
}
"".blit(self.buf, x + x2, y, style);
for y in y+1..y+height-1 {
"".blit(self.buf, x + x2, y, style);
}
//"╵".blit(self.buf, x + x2, y+height-1, style);
x2 = x2 + 1;
for scene in self.scenes.iter() {
let mut x3 = 10.max(scene.name.len() as u16);
scene.name.blit(self.buf, x + x2, y, Some(Style::default().bold()));
for (i, clip) in scene.clips.iter().enumerate() {
if let Some(clip) = clip {
if let Some(phrase) = self.tracks[i].phrases.get(*clip) {
let label = format!("{}", &phrase.name);
label.blit(self.buf, x + x2, y + 1 + i as u16, None);
x3 = x3.max(label.len() as u16)
}
}
}
x2 = x2 + x3;
"".blit(self.buf, x + x2, y, style);
for y in y+1..y+height-1 {
"".blit(self.buf, x + x2, y, style);
}
//"╵".blit(self.buf, x + x2, y+height-1, style);
x2 = x2 + 1;
}
if self.focused {
HELP.blit(self.buf, x + 2, y + height - 1, Some(Style::default().dim()));
}
Ok(self.area)
}
}
pub struct SceneGridViewVertical<'a> {
pub buf: &'a mut Buffer,
pub area: Rect,
pub scenes: &'a[Scene],
pub tracks: &'a[Track],
pub cursor: &'a(usize, usize),
pub focused: bool
pub focused: bool,
pub entered: bool,
}
impl<'a> SceneGridViewVertical<'a> {
pub fn size (&self) -> (u16, u16) {
unimplemented!();
}
pub fn draw (&mut self) -> Usually<Rect> {
let width = self.area.width.min(4 + HELP.len() as u16);
self.area.height = self.scenes.len() as u16 + 2;
//self.area.x = self.area.x + self.area.width.saturating_sub(width) / 2;
self.area.height = self.scenes.len() as u16 + 3;
let Rect { x, y, width, height } = self.area;
let style = Some(Style::default().green().dim());
if self.focused {
let Rect { x, y, width, height } = self.area;
fill_bg(&mut self.buf, self.area, if self.focused && self.entered {
Color::Rgb(25, 60, 15)
} else if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
});
if self.focused && self.entered {
lozenge_left(self.buf, x, y, height, style);
lozenge_right(self.buf, x + width - 1, y, height, style);
}
let bg_color = if self.focused && self.entered {
Color::Rgb(30, 75, 25)
} else if self.focused {
Color::Rgb(25, 60, 15)
} else {
Color::Rgb(20, 45, 5)
};
let columns = self.track_names();
let mut x = self.area.x;
let mut x2 = x;
for (i, w) in self.track_widths().iter().enumerate() {
if x >= self.area.x + self.area.width {
let focus_column = i == self.cursor.0;
if x2 >= x + width {
break
}
self.separator_v(x, i == self.cursor.0);
x = x + w;
self.separator_v(x, i == self.cursor.0);
//self.separator_v(x2, focus_column);
if focus_column {
fill_bg(
&mut self.buf,
Rect { x: x2, y, width: *w, height },
bg_color
);
}
x2 = x2 + w;
//self.separator_v(x2, focus_column);
}
let (mut x, y) = (self.area.x, self.area.y);
let (mut x2, y2) = (x, y);
for (i, title) in columns.iter().enumerate() {
if x >= self.area.x + self.area.width {
let focus_column = i == self.cursor.0;
if x2 >= x + width {
break
}
let style = Some(highlight(self.focused, i == self.cursor.0).bold());
title.blit(self.buf, x+1, y, style);
let style = Some(highlight(self.focused, focus_column).bold());
let w = (title.len() as u16).max(10);
fill_bg(
&mut self.buf,
Rect { x: x2, y: if self.cursor.1 == 0 {
y2
} else {
y2 + 1 + self.cursor.1 as u16
}, width: w + 3, height: 1 },
bg_color
);
if i == 0 {
self.scenes(x+1, y + 1);
self.scenes(x2+1, y2+2);
} else if i < columns.len() {
self.clips(x+1, y + 1, i - 1);
}
let w = (title.len() as u16).max(10) + 3;
x = x + w;
self.clips(x2+1, y2+2, i - 1);
};
title.blit(self.buf, x2+1, y2, style);
x2 = x2 + w + 3;
}
fill_bg(
&mut self.buf,
Rect { x: x2, y: if self.cursor.1 == 0 {
y2
} else {
y2 + 1 + self.cursor.1 as u16
}, width: width - x2, height: 1 },
bg_color
);
if self.focused {
HELP.blit(self.buf, self.area.x + 2, self.area.y + self.area.height - 1, Some(Style::default().dim()));
HELP.blit(self.buf, x + 2, y + height - 1, Some(Style::default().dim()));
}
Ok(self.area)
}
@ -156,7 +120,7 @@ impl<'a> SceneGridViewVertical<'a> {
self.scene(x, y + index as u16, index);
index = index + 1;
}
index as u16
longest_scene_name(&self.scenes)
}
fn scene (&mut self, x: u16, y: u16, index: usize) {
@ -172,6 +136,7 @@ impl<'a> SceneGridViewVertical<'a> {
fn clips (&mut self, x: u16, y: u16, track: usize) -> u16 {
let mut index = 0;
let mut width = 10;
loop {
if index >= self.scenes.len() {
break
@ -179,13 +144,13 @@ impl<'a> SceneGridViewVertical<'a> {
if y + index as u16 >= self.area.height {
break
}
self.clip(x, y, track, index);
width = 10.max(self.clip(x, y, track, index));
index = index + 1;
}
index as u16
width
}
fn clip (&mut self, x: u16, y: u16, track: usize, index: usize) {
fn clip (&mut self, x: u16, y: u16, track: usize, index: usize) -> u16 {
if let Some(scene) = self.scenes.get(index) {
let hi = (track + 1 == self.cursor.0) &&
(index + 1 == self.cursor.1);
@ -202,6 +167,9 @@ impl<'a> SceneGridViewVertical<'a> {
format!(" ·········")
};
label.blit(self.buf, x, y + index, style);
label.len() as u16
} else {
0u16
}
}
@ -211,16 +179,96 @@ impl<'a> SceneGridViewVertical<'a> {
"".blit(self.buf, x, y, style);
}
}
fn longest_scene_name (&self) -> u16 {
let mut w = 3u16;
for scene in self.scenes.iter() {
w = w.max(scene.name.len() as u16);
}
w
}
}
pub struct SceneGridViewHorizontal<'a> {
pub buf: &'a mut Buffer,
pub area: Rect,
pub scenes: &'a[Scene],
pub tracks: &'a[Track],
pub cursor: &'a(usize, usize),
pub focused: bool,
pub entered: bool,
}
impl<'a> SceneGridViewHorizontal<'a> {
pub fn size (&self) -> (u16, u16) {
let w = (4 + longest_track_name(&self.tracks) + self.scenes.len() as u16 * 10) as u16;
let h = (2 + self.tracks.len()) as u16;
(w, h)
}
pub fn draw (&mut self) -> Usually<Rect> {
self.area.height = self.tracks.len() as u16 * 2 + 2;
let style = Some(Style::default().green().dim());
let Rect { x, y, width, height } = self.area;
fill_bg(&mut self.buf, self.area, if self.focused && self.entered {
Color::Rgb(25, 60, 15)
} else if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
});
if self.focused && self.entered {
lozenge_left(self.buf, x, y, height, style);
lozenge_right(self.buf, x + width - 1, y, height, style);
}
let mut x2 = 0;
self.draw_tracks(&mut x2);
x2 = x2 + 1;
self.draw_scenes(&mut x2);
if self.focused {
HELP.blit(self.buf, x + 2, y + height - 1, Some(Style::default().dim()));
}
Ok(self.area)
}
fn draw_tracks (&mut self, x2: &mut u16) {
let style = Some(Style::default().bold().not_dim().white());
let Rect { x, y, height, .. } = self.area;
"Mix".blit(self.buf, x + 1, y, style);
let style = Some(Style::default().bold());
for (i, track) in self.tracks.iter().enumerate() {
let y2 = y + 1 + i as u16 * 2;
let label = format!(" {:8}", &track.name);
label.blit(self.buf, x + 1, y2, style);
"RDM".blit(self.buf, x + 10, y2, Some(Style::default().dim()));
" 0.0dB".blit(self.buf, x + 15, y2, Some(Style::default().dim()));
*x2 = (*x2).max(label.len() as u16 + 13);
}
"".blit(self.buf, x + *x2, y, style);
for y in y+1..y+height-1 {
"".blit(self.buf, x + *x2, y, style);
}
//"╵".blit(self.buf, x + x2, y+height-1, style);
}
fn draw_scenes (&mut self, x2: &mut u16) {
let Rect { x, y, height, .. } = self.area;
let bold = Some(Style::default().bold());
let sep = Some(Style::default().dim());
for scene in self.scenes.iter() {
let mut x3 = scene.name.len() as u16;
scene.name.blit(self.buf, x + *x2, y, bold);
for (i, clip) in scene.clips.iter().enumerate() {
if let Some(clip) = clip {
if let Some(phrase) = self.tracks[i].phrases.get(*clip) {
let y2 = y + 1 + i as u16 * 2;
let label = format!("{}", &phrase.name);
label.blit(self.buf, x + *x2, y2, None);
x3 = x3.max(label.len() as u16)
}
}
}
*x2 = *x2 + x3;
"".blit(self.buf, x + *x2, y, sep);
for y in y+1..y+height-1 {
"".blit(self.buf, x + *x2, y, sep);
}
"".blit(self.buf, x + *x2, y+height-1, sep);
*x2 = *x2 + 1;
}
}
}
const HELP: &'static str = "[C-t] Add track [C-a] Add scene [v] Show/hide track";
fn highlight (focused: bool, highlight: bool) -> Style {
@ -234,3 +282,19 @@ fn highlight (focused: bool, highlight: bool) -> Style {
Style::default()
}
}
fn longest_track_name (tracks: &[Track]) -> u16 {
let mut w = 3u16;
for track in tracks.iter() {
w = w.max(track.name.len() as u16);
}
w
}
fn longest_scene_name (scenes: &[Scene]) -> u16 {
let mut w = 3u16;
for scene in scenes.iter() {
w = w.max(scene.name.len() as u16);
}
w
}

View file

@ -27,6 +27,11 @@ impl<'a> Render for SequencerView<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Rect { x, y, width, height } = area;
let style = Some(Style::default().green().dim());
fill_bg(buf, area, if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
});
if self.focused {
lozenge_left(buf, x, y, height, style);
lozenge_right(buf, x + width - 1, y, height, style);