mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
redraw editor sooner
This commit is contained in:
parent
9cbe805c46
commit
059b4c0aa8
4 changed files with 30 additions and 81 deletions
|
|
@ -137,13 +137,10 @@ impl<E: Engine> FocusGrid<SequencerFocus> for Sequencer<E> {
|
|||
fn update_focus (&mut self) {
|
||||
let focused = *self.focused();
|
||||
if let Some(transport) = self.transport.as_ref() {
|
||||
transport.write().unwrap().focused =
|
||||
focused == SequencerFocus::Transport
|
||||
transport.write().unwrap().focused = focused == SequencerFocus::Transport
|
||||
}
|
||||
self.phrases.write().unwrap().focused =
|
||||
focused == SequencerFocus::PhrasePool;
|
||||
self.editor.focused =
|
||||
focused == SequencerFocus::PhraseEditor;
|
||||
self.phrases.write().unwrap().focused = focused == SequencerFocus::PhrasePool;
|
||||
self.editor.focused = focused == SequencerFocus::PhraseEditor;
|
||||
}
|
||||
}
|
||||
impl<E: Engine> PhrasePool<E> {
|
||||
|
|
@ -157,31 +154,21 @@ impl<E: Engine> PhrasePool<E> {
|
|||
mode: None,
|
||||
}
|
||||
}
|
||||
pub fn phrase (&self) -> &Arc<RwLock<Phrase>> {
|
||||
&self.phrases[self.phrase]
|
||||
}
|
||||
pub fn index_of (&self, phrase: &Phrase) -> Option<usize> {
|
||||
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 len (&self) -> usize { self.phrases.len() }
|
||||
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 select_next (&mut self) { self.phrase = self.index_after(self.phrase) }
|
||||
pub fn index_before (&self, index: usize) -> usize {
|
||||
index.overflowing_sub(1).0.min(self.len() - 1)
|
||||
}
|
||||
pub fn index_after (&self, index: usize) -> usize {
|
||||
(index + 1) % self.len()
|
||||
}
|
||||
pub fn select_prev (&mut self) {
|
||||
self.phrase = self.index_before(self.phrase)
|
||||
}
|
||||
pub fn select_next (&mut self) {
|
||||
self.phrase = self.index_after(self.phrase)
|
||||
pub fn index_of (&self, phrase: &Phrase) -> Option<usize> {
|
||||
for i in 0..self.phrases.len() {
|
||||
if *self.phrases[i].read().unwrap() == *phrase { return Some(i) }
|
||||
}
|
||||
return None
|
||||
}
|
||||
pub fn append_new (&mut self, name: Option<&str>, color: Option<Color>) {
|
||||
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))) }
|
||||
}
|
||||
impl std::cmp::PartialEq for Phrase {
|
||||
fn eq (&self, other: &Self) -> bool {
|
||||
self.uuid == other.uuid
|
||||
}
|
||||
fn eq (&self, other: &Self) -> bool { self.uuid == other.uuid }
|
||||
}
|
||||
impl Eq for Phrase {}
|
||||
impl<E: Engine> PhrasePlayer<E> {
|
||||
|
|
@ -333,15 +318,9 @@ impl<E: Engine> PhrasePlayer<E> {
|
|||
now: 0,
|
||||
}
|
||||
}
|
||||
pub fn toggle_monitor (&mut self) {
|
||||
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_monitor (&mut self) { self.monitoring = !self.monitoring; }
|
||||
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
|
||||
pub struct PhraseLength<E: Engine> {
|
||||
|
|
@ -357,32 +336,14 @@ pub struct PhraseLength<E: Engine> {
|
|||
}
|
||||
impl<E: Engine> PhraseLength<E> {
|
||||
pub fn new (pulses: usize, focus: Option<PhraseLengthFocus>) -> Self {
|
||||
Self {
|
||||
_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())
|
||||
Self { _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()) }
|
||||
}
|
||||
#[derive(Copy,Clone)]
|
||||
pub enum PhraseLengthFocus {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue