fbpr: styles

This commit is contained in:
🪞👃🪞 2024-12-04 18:55:19 +01:00
parent 59d4da1b22
commit d652feb705

View file

@ -21,24 +21,19 @@ pub struct PhraseView<'a> {
impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
fn from (state: &'a T) -> Self {
let editor = state.editor();
let height = editor.size.h();
let note_point = editor.note_point.load(Ordering::Relaxed);
let mut note_lo = editor.note_lo.load(Ordering::Relaxed);
let mut note_hi = 127.min(note_lo + height + 1);
if note_point < note_lo {
note_lo = note_point;
editor.note_lo.store(note_lo, Ordering::Relaxed);
}
let mut note_hi = 127.min(note_lo + height + 1);
if note_point > note_hi {
note_lo += note_point - note_hi;
note_hi = note_point;
editor.note_lo.store(note_lo, Ordering::Relaxed);
}
Self {
focused: state.editor_focused(),
entered: state.editor_entered(),
@ -86,7 +81,6 @@ impl<'a> Content for PhraseView<'a> {
let lower_left = format!(
"{note_lo} {note_lo_name}"
);
let mut lower_right = format!(
@ -137,7 +131,9 @@ impl<'a> Content for PhraseView<'a> {
})
})
).fill_x()
).fill_x().bg(Color::Rgb(40, 50, 30)).border(Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(if *focused{
).fill_x()
.bg(Color::Rgb(40, 50, 30))
.border(Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(if *focused{
Color::Rgb(100, 110, 40)
} else {
Color::Rgb(70, 80, 50)
@ -148,9 +144,9 @@ impl<'a> Content for PhraseView<'a> {
//if let Some(_) = phrase {
//let now = now.get() as usize; // TODO FIXME: self.now % phrase.read().unwrap().length;
//let time_clamp = time_clamp;
//for x in 0..(time_clamp/time_scale).saturating_sub(*time_start) {
//let this_step = time_start + (x + 0) * time_scale;
//let next_step = time_start + (x + 1) * time_scale;
//for x in 0..(time_clamp/time_zoom).saturating_sub(*time_start) {
//let this_step = time_start + (x + 0) * time_zoom;
//let next_step = time_start + (x + 1) * time_zoom;
//let x = to.area().x() + x as u16;
//let active = this_step <= now && now < next_step;
//let character = if active { "|" } else { "·" };
@ -239,7 +235,6 @@ impl PhraseViewMode {
//let source_y = (note_hi - y) % source.height.max(1);
if source_x < source.width && source_y < source.height {
let target_cell = target.get_mut(target_x, target_y);
target_cell.set_char('x');
if let Some(source_cell) = source.get(source_x, source_y) {
*target_cell = source_cell.clone();
}
@ -251,7 +246,7 @@ impl PhraseViewMode {
}
}
fn blit_keys (&self, to: &mut TuiOutput, note_hi: usize, note_lo: usize) {
let style = Some(Style::default().fg(Color::White).bg(Color::Rgb(0, 0, 0)));
let style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0)));
match self {
Self::PianoHorizontal { .. } => {
let [x0, y0, _, h] = to.area().xywh();
@ -281,22 +276,27 @@ impl PhraseViewMode {
to: &mut TuiOutput,
time_point: usize,
time_start: usize,
time_scale: usize,
time_zoom: usize,
note_point: usize,
note_len: usize,
note_hi: usize,
note_lo: usize,
) {
let style = Some(Style::default().fg(Color::Rgb(0,255,0)));
match self {
Self::PianoHorizontal { .. } => {
let [x0, y0, w, h] = to.area().xywh();
let [x0, y0, w, _] = to.area().xywh();
for (y, note) in (note_lo..note_hi).rev().enumerate() {
if note == note_point {
for x in 0..w {
let time_1 = time_start + x as usize * time_scale;
let time_2 = time_1 + time_scale;
let time_1 = time_start + x as usize * time_zoom;
let time_2 = time_1 + time_zoom;
if time_1 <= time_point && time_point < time_2 {
to.blit(&"", x0 + x as u16, y0 + y as u16, None);
to.blit(&"", x0 + x as u16, y0 + y as u16, style);
let tail = note_len as u16 / time_zoom as u16;
for x_tail in (x0 + x + 1)..(x0 + x + tail) {
to.blit(&"", x_tail, y0 + y as u16, style);
}
break
}
}
@ -347,6 +347,7 @@ impl PhraseViewMode {
//'·'
//});
//cell.set_fg(Color::Rgb(48, 64, 56));
let style = Style::default().fg(Color::Rgb(255, 255, 255));
let mut notes_on = [false;128];
for (y, _) in (127..0).enumerate() {
for (x, _) in (0..phrase.length).step_by(time_zoom).enumerate() {
@ -364,6 +365,7 @@ impl PhraseViewMode {
cell.set_fg(Color::Rgb(255, 255, 255));
cell.set_bg(Color::Rgb(0, 0, 0));
cell.set_char('▄');
cell.set_style(style);
} else {
cell.set_char('x');
}
@ -372,7 +374,9 @@ impl PhraseViewMode {
match event {
MidiMessage::NoteOn { key, .. } => {
let note = key.as_int() as usize;
target.get_mut(x, 127 - note).unwrap().set_char('█');
let cell = target.get_mut(x, 127 - note).unwrap();
cell.set_char('█');
cell.set_style(style);
notes_on[note] = true
},
MidiMessage::NoteOff { key, .. } => {