mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
store updated phrase length; enter/exit phrase editor
This commit is contained in:
parent
ff342963a1
commit
d29dd56198
3 changed files with 42 additions and 34 deletions
|
|
@ -168,15 +168,17 @@ impl<E: Engine> PhrasePool<E> {
|
|||
}
|
||||
pub fn append_new (&mut self, name: Option<&str>, color: Option<Color>) {
|
||||
let mut phrase = Phrase::default();
|
||||
phrase.name = String::from(name.unwrap_or("(no name)"));
|
||||
phrase.color = color.unwrap_or_else(random_color);
|
||||
phrase.name = String::from(name.unwrap_or("(no name)"));
|
||||
phrase.color = color.unwrap_or_else(random_color);
|
||||
phrase.length = 4 * PPQ;
|
||||
self.phrases.push(Arc::new(RwLock::new(phrase)));
|
||||
self.phrase = self.phrases.len() - 1;
|
||||
}
|
||||
pub fn insert_new (&mut self, name: Option<&str>, color: Option<Color>) {
|
||||
let mut phrase = Phrase::default();
|
||||
phrase.name = String::from(name.unwrap_or("(no name)"));
|
||||
phrase.color = color.unwrap_or_else(random_color);
|
||||
phrase.name = String::from(name.unwrap_or("(no name)"));
|
||||
phrase.color = color.unwrap_or_else(random_color);
|
||||
phrase.length = 4 * PPQ;
|
||||
self.phrases.insert(self.phrase + 1, Arc::new(RwLock::new(phrase)));
|
||||
self.phrase += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,12 +44,14 @@ impl Handle<Tui> for PhrasePool<Tui> {
|
|||
}
|
||||
},
|
||||
Some(PhrasePoolMode::Length(phrase, ref mut length, ref mut focus)) => {
|
||||
let mut phrase = self.phrases[phrase].write().unwrap();
|
||||
match from.event() {
|
||||
key!(KeyCode::Left) => { focus.prev() },
|
||||
key!(KeyCode::Right) => { focus.next() },
|
||||
key!(KeyCode::Esc) => { self.mode = None; },
|
||||
key!(KeyCode::Enter) => { self.mode = None; },
|
||||
key!(KeyCode::Enter) => {
|
||||
self.phrases[phrase].write().unwrap().length = *length;
|
||||
self.mode = None;
|
||||
},
|
||||
key!(KeyCode::Up) => match focus {
|
||||
PhraseLengthFocus::Bar => {
|
||||
*length += 4 * PPQ
|
||||
|
|
@ -99,6 +101,8 @@ impl Handle<Tui> for PhraseEditor<Tui> {
|
|||
key!(KeyCode::Char('`')) => {
|
||||
self.mode = !self.mode;
|
||||
},
|
||||
key!(KeyCode::Enter) => { self.entered = true; },
|
||||
key!(KeyCode::Esc) => { self.entered = false; },
|
||||
key!(KeyCode::Up) => match self.entered {
|
||||
true => { self.note_axis.point_dec(); },
|
||||
false => { self.note_axis.start_dec(); },
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ impl Content for PhrasePool<Tui> {
|
|||
let Phrase { ref name, color, length, .. } = *phrase.read().unwrap();
|
||||
|
||||
let row1 = lay!(format!(" {i}").align_w().fill_x(),
|
||||
if let Some(PhrasePoolMode::Length(phrase, length, focus)) = self.mode {
|
||||
if let Some(PhrasePoolMode::Length(phrase, new_length, focus)) = self.mode {
|
||||
if self.focused && i == phrase {
|
||||
PhraseLength::new(length, Some(focus))
|
||||
PhraseLength::new(new_length, Some(focus))
|
||||
} else {
|
||||
PhraseLength::new(length, None)
|
||||
}
|
||||
|
|
@ -71,25 +71,25 @@ impl Content for PhrasePool<Tui> {
|
|||
impl Content for PhraseEditor<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let field_bg = Color::Rgb(28, 35, 25);
|
||||
let toolbar = Stack::down(move|add|{
|
||||
//let name = format!("{:>9}", self.name.read().unwrap().as_str());
|
||||
//add(&col!("Track:", TuiStyle::bg(name.as_str(), field_bg)))?;
|
||||
if let Some(phrase) = &self.phrase {
|
||||
let phrase = phrase.read().unwrap();
|
||||
let length = format!("{}q{}p", phrase.length / PPQ, phrase.length % PPQ);
|
||||
let length = format!("{:>9}", &length);
|
||||
let loop_on = format!("{:>9}", if phrase.loop_on { "on" } else { "off" });
|
||||
let loop_start = format!("{:>9}", phrase.loop_start);
|
||||
let loop_end = format!("{:>9}", phrase.loop_length);
|
||||
add(&"")?;
|
||||
add(&col!("Length:", TuiStyle::bg(length.as_str(), field_bg)))?;
|
||||
add(&col!("Loop:", TuiStyle::bg(loop_on.as_str(), field_bg)))?;
|
||||
add(&col!("L. start:", TuiStyle::bg(loop_start.as_str(), field_bg)))?;
|
||||
add(&col!("L. length:", TuiStyle::bg(loop_end.as_str(), field_bg)))?;
|
||||
}
|
||||
Ok(())
|
||||
}).min_x(10);
|
||||
//let field_bg = Color::Rgb(28, 35, 25);
|
||||
//let toolbar = Stack::down(move|add|{
|
||||
////let name = format!("{:>9}", self.name.read().unwrap().as_str());
|
||||
////add(&col!("Track:", TuiStyle::bg(name.as_str(), field_bg)))?;
|
||||
//if let Some(phrase) = &self.phrase {
|
||||
//let phrase = phrase.read().unwrap();
|
||||
//let length = format!("{}q{}p", phrase.length / PPQ, phrase.length % PPQ);
|
||||
//let length = format!("{:>9}", &length);
|
||||
//let loop_on = format!("{:>9}", if phrase.loop_on { "on" } else { "off" });
|
||||
//let loop_start = format!("{:>9}", phrase.loop_start);
|
||||
//let loop_end = format!("{:>9}", phrase.loop_length);
|
||||
//add(&"")?;
|
||||
//add(&col!("Length:", TuiStyle::bg(length.as_str(), field_bg)))?;
|
||||
//add(&col!("Loop:", TuiStyle::bg(loop_on.as_str(), field_bg)))?;
|
||||
//add(&col!("L. start:", TuiStyle::bg(loop_start.as_str(), field_bg)))?;
|
||||
//add(&col!("L. length:", TuiStyle::bg(loop_end.as_str(), field_bg)))?;
|
||||
//}
|
||||
//Ok(())
|
||||
//}).min_x(10);
|
||||
let piano_roll = lay!(
|
||||
// keys
|
||||
CustomWidget::new(|_|Ok(Some([32u16,4u16])), |to: &mut TuiOutput|{
|
||||
|
|
@ -137,12 +137,14 @@ impl Content for PhraseEditor<Tui> {
|
|||
}).fill_x(),
|
||||
// note cursor
|
||||
CustomWidget::new(|_|Ok(Some([1u16,1u16])), |to: &mut TuiOutput|{
|
||||
let area = to.area();
|
||||
if let (Some(time), Some(note)) = (self.time_axis.point, self.note_axis.point) {
|
||||
let x = area.x() + Self::H_KEYS_OFFSET as u16 + time as u16;
|
||||
let y = area.y() + 1 + note as u16 / 2;
|
||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||
to.blit(&c, x, y, self.style_focus());
|
||||
if self.entered {
|
||||
let area = to.area();
|
||||
if let (Some(time), Some(note)) = (self.time_axis.point, self.note_axis.point) {
|
||||
let x = area.x() + Self::H_KEYS_OFFSET as u16 + time as u16;
|
||||
let y = area.y() + 1 + note as u16 / 2;
|
||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||
to.blit(&c, x, y, self.style_focus());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}),
|
||||
|
|
@ -158,7 +160,7 @@ impl Content for PhraseEditor<Tui> {
|
|||
))
|
||||
}),
|
||||
);
|
||||
let content = row!(toolbar, piano_roll)
|
||||
let content = row!(piano_roll)
|
||||
.fill_x()
|
||||
.bg(Color::Rgb(40, 50, 30))
|
||||
.border(Lozenge(Style::default()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue