redraw editor sooner

This commit is contained in:
🪞👃🪞 2024-10-21 02:28:45 +03:00
parent 9cbe805c46
commit 059b4c0aa8
4 changed files with 30 additions and 81 deletions

View file

@ -138,8 +138,12 @@ impl<E: Engine> Arranger<E> {
Ok(Some(true)) Ok(Some(true))
} }
/// Focus the editor with the current phrase /// Focus the editor with the current phrase
pub fn show_phrase (&mut self) {
self.editor.show(self.arrangement.phrase().as_ref());
}
/// Focus the editor with the current phrase
pub fn edit_phrase (&mut self) { pub fn edit_phrase (&mut self) {
self.editor.phrase = self.arrangement.phrase().clone(); self.show_phrase();
self.focus(ArrangerFocus::PhraseEditor); self.focus(ArrangerFocus::PhraseEditor);
} }
/// Rename the selected track, scene, or clip /// Rename the selected track, scene, or clip
@ -237,7 +241,6 @@ impl<E: Engine> Arrangement<E> {
ArrangementFocus::Clip(_, _) => self.phrase_del(), ArrangementFocus::Clip(_, _) => self.phrase_del(),
_ => {} _ => {}
} }
self.show_phrase()
} }
pub fn increment (&mut self) { pub fn increment (&mut self) {
match self.selected { match self.selected {
@ -246,7 +249,6 @@ impl<E: Engine> Arrangement<E> {
ArrangementFocus::Clip(_, _) => self.phrase_next(), ArrangementFocus::Clip(_, _) => self.phrase_next(),
_ => {} _ => {}
} }
self.show_phrase()
} }
pub fn decrement (&mut self) { pub fn decrement (&mut self) {
match self.selected { match self.selected {
@ -255,7 +257,6 @@ impl<E: Engine> Arrangement<E> {
ArrangementFocus::Clip(_, _) => self.phrase_prev(), ArrangementFocus::Clip(_, _) => self.phrase_prev(),
_ => {} _ => {}
} }
self.show_phrase()
} }
pub fn is_first_row (&self) -> bool { pub fn is_first_row (&self) -> bool {
let selected = self.selected; let selected = self.selected;
@ -279,28 +280,24 @@ impl<E: Engine> Arrangement<E> {
ArrangementViewMode::Horizontal => self.track_prev(), ArrangementViewMode::Horizontal => self.track_prev(),
_ => self.scene_prev(), _ => self.scene_prev(),
}; };
self.show_phrase();
} }
pub fn go_down (&mut self) { pub fn go_down (&mut self) {
match self.mode { match self.mode {
ArrangementViewMode::Horizontal => self.track_next(), ArrangementViewMode::Horizontal => self.track_next(),
_ => self.scene_next(), _ => self.scene_next(),
}; };
self.show_phrase();
} }
pub fn go_left (&mut self) { pub fn go_left (&mut self) {
match self.mode { match self.mode {
ArrangementViewMode::Horizontal => self.scene_prev(), ArrangementViewMode::Horizontal => self.scene_prev(),
_ => self.track_prev(), _ => self.track_prev(),
}; };
self.show_phrase();
} }
pub fn go_right (&mut self) { pub fn go_right (&mut self) {
match self.mode { match self.mode {
ArrangementViewMode::Horizontal => self.scene_next(), ArrangementViewMode::Horizontal => self.scene_next(),
_ => self.track_next(), _ => self.track_next(),
}; };
self.show_phrase();
} }
pub fn move_back (&mut self) { pub fn move_back (&mut self) {
match self.selected { match self.selected {
@ -442,16 +439,6 @@ impl<E: Engine> Arrangement<E> {
.map(|track|self.tracks.get_mut(track)) .map(|track|self.tracks.get_mut(track))
.flatten() .flatten()
} }
pub fn show_phrase (&mut self) {
let (scene, track) = (self.selected.scene(), self.selected.track());
if let (Some(scene_index), Some(track_index)) = (scene, track) {
let scene = self.scenes.get(scene_index);
let track = self.tracks.get_mut(track_index);
if let (Some(scene), Some(track)) = (scene, track) {
track.player.phrase = scene.clips[track_index].clone()
}
}
}
pub fn phrase (&self) -> Option<Arc<RwLock<Phrase>>> { pub fn phrase (&self) -> Option<Arc<RwLock<Phrase>>> {
self.scene()?.clips.get(self.selected.track()?)?.clone() self.scene()?.clips.get(self.selected.track()?)?.clone()
} }

View file

@ -68,6 +68,7 @@ impl Arranger<Tui> {
}, },
_ => return self.arrangement.handle(from) _ => return self.arrangement.handle(from)
} }
self.show_phrase();
Ok(Some(true)) Ok(Some(true))
} }
} }

View file

@ -137,13 +137,10 @@ impl<E: Engine> FocusGrid<SequencerFocus> for Sequencer<E> {
fn update_focus (&mut self) { fn update_focus (&mut self) {
let focused = *self.focused(); let focused = *self.focused();
if let Some(transport) = self.transport.as_ref() { if let Some(transport) = self.transport.as_ref() {
transport.write().unwrap().focused = transport.write().unwrap().focused = focused == SequencerFocus::Transport
focused == SequencerFocus::Transport
} }
self.phrases.write().unwrap().focused = self.phrases.write().unwrap().focused = focused == SequencerFocus::PhrasePool;
focused == SequencerFocus::PhrasePool; self.editor.focused = focused == SequencerFocus::PhraseEditor;
self.editor.focused =
focused == SequencerFocus::PhraseEditor;
} }
} }
impl<E: Engine> PhrasePool<E> { impl<E: Engine> PhrasePool<E> {
@ -157,31 +154,21 @@ impl<E: Engine> PhrasePool<E> {
mode: None, mode: None,
} }
} }
pub fn phrase (&self) -> &Arc<RwLock<Phrase>> { pub fn len (&self) -> usize { self.phrases.len() }
&self.phrases[self.phrase] pub fn phrase (&self) -> &Arc<RwLock<Phrase>> { &self.phrases[self.phrase] }
} pub fn select_prev (&mut self) { self.phrase = self.index_before(self.phrase) }
pub fn index_of (&self, phrase: &Phrase) -> Option<usize> { pub fn select_next (&mut self) { self.phrase = self.index_after(self.phrase) }
for i in 0..self.phrases.len() {
if *self.phrases[i].read().unwrap() == *phrase {
return Some(i)
}
}
return None
}
pub fn len (&self) -> usize {
self.phrases.len()
}
pub fn index_before (&self, index: usize) -> usize { pub fn index_before (&self, index: usize) -> usize {
index.overflowing_sub(1).0.min(self.len() - 1) index.overflowing_sub(1).0.min(self.len() - 1)
} }
pub fn index_after (&self, index: usize) -> usize { pub fn index_after (&self, index: usize) -> usize {
(index + 1) % self.len() (index + 1) % self.len()
} }
pub fn select_prev (&mut self) { pub fn index_of (&self, phrase: &Phrase) -> Option<usize> {
self.phrase = self.index_before(self.phrase) for i in 0..self.phrases.len() {
} if *self.phrases[i].read().unwrap() == *phrase { return Some(i) }
pub fn select_next (&mut self) { }
self.phrase = self.index_after(self.phrase) return None
} }
pub fn append_new (&mut self, name: Option<&str>, color: Option<Color>) { pub fn append_new (&mut self, name: Option<&str>, color: Option<Color>) {
let mut phrase = Phrase::default(); let mut phrase = Phrase::default();
@ -312,9 +299,7 @@ impl Default for Phrase {
fn default () -> Self { Self::new("(empty)", false, 0, None, Some(Color::Rgb(0, 0, 0))) } fn default () -> Self { Self::new("(empty)", false, 0, None, Some(Color::Rgb(0, 0, 0))) }
} }
impl std::cmp::PartialEq for Phrase { impl std::cmp::PartialEq for Phrase {
fn eq (&self, other: &Self) -> bool { fn eq (&self, other: &Self) -> bool { self.uuid == other.uuid }
self.uuid == other.uuid
}
} }
impl Eq for Phrase {} impl Eq for Phrase {}
impl<E: Engine> PhrasePlayer<E> { impl<E: Engine> PhrasePlayer<E> {
@ -333,15 +318,9 @@ impl<E: Engine> PhrasePlayer<E> {
now: 0, now: 0,
} }
} }
pub fn toggle_monitor (&mut self) { pub fn toggle_monitor (&mut self) { self.monitoring = !self.monitoring; }
self.monitoring = !self.monitoring; pub fn toggle_record (&mut self) { self.recording = !self.recording; }
} pub fn toggle_overdub (&mut self) { self.overdub = !self.overdub; }
pub fn toggle_record (&mut self) {
self.recording = !self.recording;
}
pub fn toggle_overdub (&mut self) {
self.overdub = !self.overdub;
}
} }
/// Displays and edits phrase length /// Displays and edits phrase length
pub struct PhraseLength<E: Engine> { pub struct PhraseLength<E: Engine> {
@ -357,32 +336,14 @@ pub struct PhraseLength<E: Engine> {
} }
impl<E: Engine> PhraseLength<E> { impl<E: Engine> PhraseLength<E> {
pub fn new (pulses: usize, focus: Option<PhraseLengthFocus>) -> Self { pub fn new (pulses: usize, focus: Option<PhraseLengthFocus>) -> Self {
Self { Self { _engine: Default::default(), ppq: PPQ, bpb: 4, pulses, focus }
_engine: Default::default(),
ppq: PPQ,
bpb: 4,
pulses,
focus
}
}
pub fn bars (&self) -> usize {
self.pulses / (self.bpb * self.ppq)
}
pub fn beats (&self) -> usize {
(self.pulses % (self.bpb * self.ppq)) / self.ppq
}
pub fn ticks (&self) -> usize {
self.pulses % self.ppq
}
pub fn bars_string (&self) -> String {
format!("{}", self.bars())
}
pub fn beats_string (&self) -> String {
format!("{}", self.beats())
}
pub fn ticks_string (&self) -> String {
format!("{:>02}", self.ticks())
} }
pub fn bars (&self) -> usize { self.pulses / (self.bpb * self.ppq) }
pub fn beats (&self) -> usize { (self.pulses % (self.bpb * self.ppq)) / self.ppq }
pub fn ticks (&self) -> usize { self.pulses % self.ppq }
pub fn bars_string (&self) -> String { format!("{}", self.bars()) }
pub fn beats_string (&self) -> String { format!("{}", self.beats()) }
pub fn ticks_string (&self) -> String { format!("{:>02}", self.ticks()) }
} }
#[derive(Copy,Clone)] #[derive(Copy,Clone)]
pub enum PhraseLengthFocus { pub enum PhraseLengthFocus {

View file

@ -153,7 +153,7 @@ impl Content for PhraseEditor<Tui> {
) )
} }
} }
impl PhraseEditor<Tui> { impl<E: Engine> PhraseEditor<E> {
const H_KEYS_OFFSET: usize = 5; const H_KEYS_OFFSET: usize = 5;
pub fn put (&mut self) { pub fn put (&mut self) {
if let (Some(phrase), Some(time), Some(note)) = ( if let (Some(phrase), Some(time), Some(note)) = (