wip: redraw sequencer

This commit is contained in:
🪞👃🪞 2024-10-18 20:59:44 +03:00
parent ec9352e0f8
commit b52aa3fc80
2 changed files with 24 additions and 29 deletions

View file

@ -115,31 +115,11 @@ impl Handle<Tui> for PhraseEditor<Tui> {
false => {},
},
key!(KeyCode::Char('a')) => if self.entered {
if let (Some(phrase), Some(time), Some(note)) = (
&self.phrase,
self.time_axis.point,
self.note_axis.point,
) {
let mut phrase = phrase.write().unwrap();
let key: u7 = u7::from((127 - note) as u8);
let vel: u7 = 100.into();
phrase.notes[time].push(MidiMessage::NoteOn { key, vel });
phrase.notes[time + self.note_len].push(MidiMessage::NoteOff { key, vel });
self.time_axis.point = Some(time + self.note_len);
}
self.put();
self.time_axis.point = self.time_axis.point.map(|time|time + self.note_len);
},
key!(KeyCode::Char('s')) => if self.entered {
if let (Some(phrase), Some(time), Some(note)) = (
&self.phrase,
self.time_axis.point,
self.note_axis.point,
) {
let mut phrase = phrase.write().unwrap();
let key: u7 = u7::from((127 - note) as u8);
let vel: u7 = 100.into();
phrase.notes[time].push(MidiMessage::NoteOn { key, vel });
phrase.notes[time + self.note_len].push(MidiMessage::NoteOff { key, vel });
}
self.put();
},
_ => { return Ok(None) }

View file

@ -155,21 +155,36 @@ impl Content for PhraseEditor<Tui> {
}
impl PhraseEditor<Tui> {
const H_KEYS_OFFSET: usize = 5;
pub fn put (&mut self) {
if let (Some(phrase), Some(time), Some(note)) = (
&self.phrase,
self.time_axis.point,
self.note_axis.point,
) {
let mut phrase = phrase.write().unwrap();
let key: u7 = u7::from((127 - note) as u8);
let vel: u7 = 100.into();
phrase.notes[time].push(MidiMessage::NoteOn { key, vel });
phrase.notes[time + self.note_len].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());
let width = usize::MAX.min(phrase.read().unwrap().length);
let mut buffer = BigBuffer::new(width, 64);
let phrase = phrase.read().unwrap();
Self::fill_seq_bg(&mut buffer, phrase.length, phrase.ppq);
Self::fill_seq_fg(&mut buffer, &phrase);
self.buffer = buffer;
self.buffer = Self::redraw(&*phrase.read().unwrap());
} else {
self.phrase = None;
self.buffer = Default::default();
}
}
fn redraw (phrase: &Phrase) -> BigBuffer {
let mut buf = BigBuffer::new(usize::MAX.min(phrase.length), 64);
Self::fill_seq_bg(&mut buf, phrase.length, phrase.ppq);
Self::fill_seq_fg(&mut buf, &phrase);
buf
}
fn fill_seq_bg (buf: &mut BigBuffer, length: usize, ppq: usize) {
for x in 0..buf.width {
if x as usize >= length {