reenabling phrase editing

This commit is contained in:
🪞👃🪞 2024-12-02 02:44:52 +01:00
parent 37d4a42a83
commit 82a326d6f8
6 changed files with 95 additions and 77 deletions

View file

@ -1,25 +1,23 @@
use crate::*;
pub struct PhraseView<'a> {
pub(crate) focused: bool,
pub(crate) entered: bool,
pub(crate) phrase: &'a Option<Arc<RwLock<Phrase>>>,
pub(crate) buffer: &'a BigBuffer,
pub(crate) note_len: usize,
pub(crate) now: &'a Arc<Pulse>,
focused: bool,
entered: bool,
phrase: &'a Option<Arc<RwLock<Phrase>>>,
buffer: &'a BigBuffer,
note_len: usize,
now: &'a Arc<Pulse>,
size: &'a Measure<Tui>,
width: usize,
height: usize,
size: &'a Measure<Tui>,
note_point: usize,
note_range: (usize, usize),
note_names: (&'a str, &'a str),
pub(crate) time_start: usize,
pub(crate) time_point: usize,
pub(crate) time_clamp: usize,
pub(crate) time_scale: usize,
time_start: usize,
time_point: usize,
time_clamp: usize,
time_scale: usize,
}
impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
@ -52,8 +50,6 @@ impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
now: &editor.now,
size: &editor.size,
width,
height,
note_point,
note_range: (note_lo, note_hi),
@ -234,33 +230,7 @@ const NTH_OCTAVE: [&'static str; 11] = [
];
impl PhraseEditorModel {
pub fn put (&mut self) {
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();
let start = time;
let end = (start + self.note_len) % phrase.length;
phrase.notes[time].push(MidiMessage::NoteOn { key, vel });
phrase.notes[end].push(MidiMessage::NoteOff { key, vel });
self.buffer = Self::redraw(&phrase);
}
}
/// Select which pattern to display. This pre-renders it to the buffer at full resolution.
pub fn show (&mut self, phrase: Option<Arc<RwLock<Phrase>>>) {
if let Some(phrase) = phrase {
self.phrase = Some(phrase.clone());
self.time_clamp.store(phrase.read().unwrap().length, Ordering::Relaxed);
self.buffer = Self::redraw(&*phrase.read().unwrap());
} else {
self.phrase = None;
self.time_clamp.store(0, Ordering::Relaxed);
self.buffer = Default::default();
}
}
fn redraw (phrase: &Phrase) -> BigBuffer {
pub(crate) fn redraw (phrase: &Phrase) -> BigBuffer {
let mut buf = BigBuffer::new(usize::MAX.min(phrase.length), 65);
Self::fill_seq_bg(&mut buf, phrase.length, phrase.ppq);
Self::fill_seq_fg(&mut buf, &phrase);
@ -319,10 +289,10 @@ impl PhraseEditorModel {
break
}
if let Some(block) = half_block(
notes_on[y as usize * 2],
notes_on[y as usize * 2 + 1],
notes_on[127 - (y as usize * 2)],
notes_on[127 - (y as usize * 2 + 1)],
) {
buf.get_mut(x, y).map(|cell|{
buf.get_mut(x, 64 - y).map(|cell|{
cell.set_char(block);
cell.set_fg(Color::White);
});