mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
add PhraseEditor::note_len
This commit is contained in:
parent
826cc5902b
commit
de1eb6ef97
3 changed files with 30 additions and 29 deletions
|
|
@ -66,6 +66,8 @@ pub struct PhraseEditor<E: Engine> {
|
||||||
_engine: PhantomData<E>,
|
_engine: PhantomData<E>,
|
||||||
/// Phrase being played
|
/// Phrase being played
|
||||||
pub phrase: Option<Arc<RwLock<Phrase>>>,
|
pub phrase: Option<Arc<RwLock<Phrase>>>,
|
||||||
|
/// Length of note that will be inserted, in pulses
|
||||||
|
pub note_len: usize,
|
||||||
/// The full piano keys are rendered to this buffer
|
/// The full piano keys are rendered to this buffer
|
||||||
pub keys: Buffer,
|
pub keys: Buffer,
|
||||||
/// The full piano roll is rendered to this buffer
|
/// The full piano roll is rendered to this buffer
|
||||||
|
|
@ -223,6 +225,7 @@ impl<E: Engine> PhraseEditor<E> {
|
||||||
Self {
|
Self {
|
||||||
_engine: Default::default(),
|
_engine: Default::default(),
|
||||||
phrase: None,
|
phrase: None,
|
||||||
|
note_len: 24,
|
||||||
notes_in: Arc::new(RwLock::new([false;128])),
|
notes_in: Arc::new(RwLock::new([false;128])),
|
||||||
notes_out: Arc::new(RwLock::new([false;128])),
|
notes_out: Arc::new(RwLock::new([false;128])),
|
||||||
keys: keys_vert(),
|
keys: keys_vert(),
|
||||||
|
|
|
||||||
|
|
@ -53,26 +53,14 @@ impl Handle<Tui> for PhrasePool<Tui> {
|
||||||
self.mode = None;
|
self.mode = None;
|
||||||
},
|
},
|
||||||
key!(KeyCode::Up) => match focus {
|
key!(KeyCode::Up) => match focus {
|
||||||
PhraseLengthFocus::Bar => {
|
PhraseLengthFocus::Bar => { *length += 4 * PPQ },
|
||||||
*length += 4 * PPQ
|
PhraseLengthFocus::Beat => { *length += PPQ },
|
||||||
},
|
PhraseLengthFocus::Tick => { *length += 1 },
|
||||||
PhraseLengthFocus::Beat => {
|
|
||||||
*length += PPQ
|
|
||||||
},
|
|
||||||
PhraseLengthFocus::Tick => {
|
|
||||||
*length += 1
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
key!(KeyCode::Down) => match focus {
|
key!(KeyCode::Down) => match focus {
|
||||||
PhraseLengthFocus::Bar => {
|
PhraseLengthFocus::Bar => { *length = length.saturating_sub(4 * PPQ) },
|
||||||
*length = length.saturating_sub(4 * PPQ)
|
PhraseLengthFocus::Beat => { *length = length.saturating_sub(PPQ) },
|
||||||
},
|
PhraseLengthFocus::Tick => { *length = length.saturating_sub(1) },
|
||||||
PhraseLengthFocus::Beat => {
|
|
||||||
*length = length.saturating_sub(PPQ)
|
|
||||||
},
|
|
||||||
PhraseLengthFocus::Tick => {
|
|
||||||
*length = length.saturating_sub(1)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
_ => return Ok(Some(true))
|
_ => return Ok(Some(true))
|
||||||
}
|
}
|
||||||
|
|
@ -98,11 +86,10 @@ impl Handle<Tui> for PhrasePool<Tui> {
|
||||||
impl Handle<Tui> for PhraseEditor<Tui> {
|
impl Handle<Tui> for PhraseEditor<Tui> {
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
match from.event() {
|
match from.event() {
|
||||||
key!(KeyCode::Char('`')) => {
|
key!(KeyCode::Char('`')) => { self.mode = !self.mode; },
|
||||||
self.mode = !self.mode;
|
|
||||||
},
|
|
||||||
key!(KeyCode::Enter) => { self.entered = true; },
|
key!(KeyCode::Enter) => { self.entered = true; },
|
||||||
key!(KeyCode::Esc) => { self.entered = false; },
|
key!(KeyCode::Esc) => { self.entered = false; },
|
||||||
|
|
||||||
key!(KeyCode::Up) => match self.entered {
|
key!(KeyCode::Up) => match self.entered {
|
||||||
true => { self.note_axis.point_dec(); },
|
true => { self.note_axis.point_dec(); },
|
||||||
false => { self.note_axis.start_dec(); },
|
false => { self.note_axis.start_dec(); },
|
||||||
|
|
@ -119,9 +106,18 @@ impl Handle<Tui> for PhraseEditor<Tui> {
|
||||||
true => { self.time_axis.point_inc(); },
|
true => { self.time_axis.point_inc(); },
|
||||||
false => { self.time_axis.start_inc(); },
|
false => { self.time_axis.start_inc(); },
|
||||||
},
|
},
|
||||||
_ => {
|
key!(KeyCode::Char(',')) => match self.entered {
|
||||||
return Ok(None)
|
true => {},
|
||||||
}
|
false => {},
|
||||||
|
},
|
||||||
|
key!(KeyCode::Char('.')) => match self.entered {
|
||||||
|
true => {},
|
||||||
|
false => {},
|
||||||
|
},
|
||||||
|
key!(KeyCode::Char('a')) => if self.entered {},
|
||||||
|
key!(KeyCode::Char('i')) => if self.entered {},
|
||||||
|
|
||||||
|
_ => { return Ok(None) }
|
||||||
}
|
}
|
||||||
return Ok(Some(true))
|
return Ok(Some(true))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,9 @@ impl Content for PhrasePool<Tui> {
|
||||||
impl Content for PhraseEditor<Tui> {
|
impl Content for PhraseEditor<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
let Self { focused, entered, time_axis, note_axis, keys, phrase, buffer, .. } = self;
|
let Self {
|
||||||
|
focused, entered, time_axis, note_axis, keys, phrase, buffer, note_len, ..
|
||||||
|
} = self;
|
||||||
let offset = Self::H_KEYS_OFFSET as u16;
|
let offset = Self::H_KEYS_OFFSET as u16;
|
||||||
let keys = CustomWidget::new(|_|Ok(Some([32u16,4u16])), move|to: &mut TuiOutput|{
|
let keys = CustomWidget::new(|_|Ok(Some([32u16,4u16])), move|to: &mut TuiOutput|{
|
||||||
if to.area().h() >= 2 {
|
if to.area().h() >= 2 {
|
||||||
|
|
@ -120,8 +122,8 @@ impl Content for PhraseEditor<Tui> {
|
||||||
}
|
}
|
||||||
if *focused {
|
if *focused {
|
||||||
if *entered {
|
if *entered {
|
||||||
lower_left = "[Esc] Exit edit mode [A]ppend [I]nsert".to_string();
|
lower_left = "[Esc] Exit edit mode [A]ppend [S]et".to_string();
|
||||||
lower_right = format!("[,.] Length: ?? {lower_right}");
|
lower_right = format!("[,.] Length: {} {lower_right}", ppq_to_name(*note_len));
|
||||||
} else {
|
} else {
|
||||||
lower_left = "[Enter] Edit notes".to_string();
|
lower_left = "[Enter] Edit notes".to_string();
|
||||||
lower_right = format!("[,.] {lower_right}");
|
lower_right = format!("[,.] {lower_right}");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue