mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
remove FixedAxis and ScaledAxis
This commit is contained in:
parent
54057afad8
commit
286dec0f40
6 changed files with 223 additions and 290 deletions
|
|
@ -8,24 +8,36 @@ pub struct PhraseView<'a> {
|
|||
pub(crate) keys: &'a Buffer,
|
||||
pub(crate) buffer: &'a BigBuffer,
|
||||
pub(crate) note_len: usize,
|
||||
pub(crate) note_axis: &'a RwLock<FixedAxis<usize>>,
|
||||
pub(crate) time_axis: &'a RwLock<ScaledAxis<usize>>,
|
||||
pub(crate) now: &'a Arc<Pulse>,
|
||||
|
||||
pub(crate) note_start: &'a AtomicUsize,
|
||||
pub(crate) note_point: &'a AtomicUsize,
|
||||
pub(crate) note_clamp: &'a AtomicUsize,
|
||||
|
||||
pub(crate) time_start: &'a AtomicUsize,
|
||||
pub(crate) time_point: &'a AtomicUsize,
|
||||
pub(crate) time_clamp: &'a AtomicUsize,
|
||||
pub(crate) time_scale: &'a AtomicUsize,
|
||||
}
|
||||
|
||||
impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
|
||||
fn from (state: &'a T) -> Self {
|
||||
Self {
|
||||
focused: state.editor_focused(),
|
||||
entered: state.editor_entered(),
|
||||
note_len: state.editor().note_len,
|
||||
phrase: &state.editor().phrase,
|
||||
size: &state.editor().size,
|
||||
keys: &state.editor().keys,
|
||||
buffer: &state.editor().buffer,
|
||||
note_axis: &state.editor().note_axis,
|
||||
time_axis: &state.editor().time_axis,
|
||||
now: &state.editor().now
|
||||
focused: state.editor_focused(),
|
||||
entered: state.editor_entered(),
|
||||
note_len: state.editor().note_len,
|
||||
phrase: &state.editor().phrase,
|
||||
size: &state.editor().size,
|
||||
keys: &state.editor().keys,
|
||||
buffer: &state.editor().buffer,
|
||||
now: &state.editor().now,
|
||||
note_start: &state.editor().note_start,
|
||||
note_point: &state.editor().note_point,
|
||||
note_clamp: &state.editor().note_clamp,
|
||||
time_start: &state.editor().time_start,
|
||||
time_point: &state.editor().time_point,
|
||||
time_clamp: &state.editor().time_clamp,
|
||||
time_scale: &state.editor().time_scale,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,13 +45,14 @@ impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
|
|||
impl<'a> Content for PhraseView<'a> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let Self {
|
||||
focused, entered, phrase, size, keys, buffer, note_len, note_axis, time_axis, now
|
||||
} = self;
|
||||
let FixedAxis { start: note_start, point: note_point, clamp: note_clamp }
|
||||
= *note_axis.read().unwrap();
|
||||
let ScaledAxis { start: time_start, point: time_point, clamp: time_clamp, scale: time_scale }
|
||||
= *time_axis.read().unwrap();
|
||||
let Self { focused, entered, phrase, size, keys, buffer, note_len, now, .. } = self;
|
||||
let note_start = self.note_start.load(Ordering::Relaxed);
|
||||
let note_point = self.note_point.load(Ordering::Relaxed);
|
||||
let note_clamp = self.note_clamp.load(Ordering::Relaxed);
|
||||
let time_start = self.time_start.load(Ordering::Relaxed);
|
||||
let time_point = self.time_point.load(Ordering::Relaxed);
|
||||
let time_clamp = self.time_clamp.load(Ordering::Relaxed);
|
||||
let time_scale = self.time_scale.load(Ordering::Relaxed);
|
||||
//let color = Color::Rgb(0,255,0);
|
||||
//let color = phrase.as_ref().map(|p|p.read().unwrap().color.base.rgb).unwrap_or(color);
|
||||
let keys = CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_w(5))), move|to: &mut TuiOutput|{
|
||||
|
|
@ -57,11 +70,8 @@ impl<'a> Content for PhraseView<'a> {
|
|||
let area = to.area();
|
||||
let h = area.h() as usize;
|
||||
size.set_wh(area.w(), h);
|
||||
let mut axis = note_axis.write().unwrap();
|
||||
if let Some(point) = axis.point {
|
||||
if point.saturating_sub(axis.start) > (h * 2).saturating_sub(1) {
|
||||
axis.start += 2;
|
||||
}
|
||||
if note_point.saturating_sub(note_start) > (h * 2).saturating_sub(1) {
|
||||
self.note_start.store(note_start + 2, Ordering::Relaxed);
|
||||
}
|
||||
Ok(if to.area().h() >= 2 {
|
||||
let area = to.area();
|
||||
|
|
@ -82,14 +92,12 @@ impl<'a> Content for PhraseView<'a> {
|
|||
let cursor = CustomWidget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{
|
||||
Ok(if *focused && *entered {
|
||||
let area = to.area();
|
||||
if let (Some(time), Some(note)) = (time_point, note_point) {
|
||||
let x1 = area.x() + (time / time_scale) as u16;
|
||||
let x2 = x1 + (note_len / time_scale) as u16;
|
||||
let y = area.y() + note.saturating_sub(note_start) as u16 / 2;
|
||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||
for x in x1..x2 {
|
||||
to.blit(&c, x, y, Some(Style::default().fg(Color::Rgb(0,255,0))));
|
||||
}
|
||||
let x1 = area.x() + (time_point / time_scale) as u16;
|
||||
let x2 = x1 + (note_len / time_scale) as u16;
|
||||
let y = area.y() + note_point.saturating_sub(note_start) as u16 / 2;
|
||||
let c = if note_point % 2 == 0 { "▀" } else { "▄" };
|
||||
for x in x1..x2 {
|
||||
to.blit(&c, x, y, Some(Style::default().fg(Color::Rgb(0,255,0))));
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
@ -100,8 +108,7 @@ impl<'a> Content for PhraseView<'a> {
|
|||
move|to: &mut TuiOutput|{
|
||||
if let Some(_) = phrase {
|
||||
let now = now.get() as usize; // TODO FIXME: self.now % phrase.read().unwrap().length;
|
||||
let time_clamp = time_clamp
|
||||
.expect("time_axis of sequencer expected to be clamped");
|
||||
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;
|
||||
|
|
@ -136,7 +143,7 @@ impl<'a> Content for PhraseView<'a> {
|
|||
//);
|
||||
if *focused && *entered {
|
||||
lower_right = format!("┤Note: {} {}├─{lower_right}",
|
||||
note_axis.read().unwrap().point.unwrap(),
|
||||
note_point,
|
||||
pulses_to_name(*note_len));
|
||||
//lower_right = format!("Note: {} (+{}:{}|{}) {upper_right}",
|
||||
//pulses_to_name(*note_len),
|
||||
|
|
@ -206,11 +213,9 @@ const NTH_OCTAVE: [&'static str; 11] = [
|
|||
|
||||
impl PhraseEditorModel {
|
||||
pub fn put (&mut self) {
|
||||
if let (Some(phrase), Some(time), Some(note)) = (
|
||||
&self.phrase,
|
||||
self.time_axis.read().unwrap().point,
|
||||
self.note_axis.read().unwrap().point,
|
||||
) {
|
||||
if let Some(phrase) = &self.phrase {
|
||||
let time = self.time_point.load(Ordering::Relaxed);
|
||||
let note = self.note_point.load(Ordering::Relaxed);
|
||||
let mut phrase = phrase.write().unwrap();
|
||||
let key: u7 = u7::from((127 - note) as u8);
|
||||
let vel: u7 = 100.into();
|
||||
|
|
@ -225,11 +230,11 @@ impl PhraseEditorModel {
|
|||
pub fn show (&mut self, phrase: Option<Arc<RwLock<Phrase>>>) {
|
||||
if let Some(phrase) = phrase {
|
||||
self.phrase = Some(phrase.clone());
|
||||
self.time_axis.write().unwrap().clamp = Some(phrase.read().unwrap().length);
|
||||
self.time_clamp.store(phrase.read().unwrap().length, Ordering::Relaxed);
|
||||
self.buffer = Self::redraw(&*phrase.read().unwrap());
|
||||
} else {
|
||||
self.phrase = None;
|
||||
self.time_axis.write().unwrap().clamp = Some(0);
|
||||
self.time_clamp.store(0, Ordering::Relaxed);
|
||||
self.buffer = Default::default();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue