mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-10-08 18:56:42 +02:00
colorize; show editor
This commit is contained in:
parent
9a50ce6613
commit
ea74aba7b7
3 changed files with 79 additions and 60 deletions
|
|
@ -283,7 +283,7 @@ impl PianoHorizontal {
|
||||||
let mut range = MidiSelection::from((12, true));
|
let mut range = MidiSelection::from((12, true));
|
||||||
range.time_axis = size.0.clone();
|
range.time_axis = size.0.clone();
|
||||||
range.note_axis = size.1.clone();
|
range.note_axis = size.1.clone();
|
||||||
let piano = Self { keys_width: 5, size, range, ..Default::default() };
|
let piano = Self { keys_width: 4, size, range, ..Default::default() };
|
||||||
piano.redraw();
|
piano.redraw();
|
||||||
piano
|
piano
|
||||||
}
|
}
|
||||||
|
|
@ -320,17 +320,7 @@ impl MidiViewer for PianoHorizontal {
|
||||||
}
|
}
|
||||||
/// Draw the piano roll into the buffer.
|
/// Draw the piano roll into the buffer.
|
||||||
fn redraw (&self) {
|
fn redraw (&self) {
|
||||||
*self.buffer.write() = self.clip.map_inner(|clip|{
|
*self.buffer.write() = redraw_piano(&self)
|
||||||
let buf_size = self.buffer_size(&clip);
|
|
||||||
let mut buffer = BigBuffer::from(buf_size);
|
|
||||||
let time_zoom = self.get_time_zoom().max(1);
|
|
||||||
self.time_len().store(clip.length, Relaxed);
|
|
||||||
let note_len = self.get_note_len();
|
|
||||||
let note_pos = self.get_note_pos();
|
|
||||||
let time_pos = self.get_time_pos();
|
|
||||||
draw_piano_fg(&mut buffer, &clip, time_zoom);
|
|
||||||
buffer
|
|
||||||
}).unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -535,17 +535,21 @@ impl<T: HasClip + HasEditor
|
||||||
} else if let Some(clip) = self.clip() {
|
} else if let Some(clip) = self.clip() {
|
||||||
let editor = MidiEditor {
|
let editor = MidiEditor {
|
||||||
mode: PianoHorizontal {
|
mode: PianoHorizontal {
|
||||||
keys_width: 5,
|
keys_width: 4,
|
||||||
range: MidiSelection {
|
range: MidiSelection {
|
||||||
time_len: Arc::new(96usize.into()),
|
time_len: Arc::new(96usize.into()),
|
||||||
time_zoom: Arc::new(1usize.into()),
|
time_zoom: Arc::new(1usize.into()),
|
||||||
note_axis: Arc::new(12usize.into()),
|
note_axis: Arc::new(12usize.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
size: Sizer(
|
||||||
|
Arc::new(16usize.into()),
|
||||||
|
Arc::new(6usize.into()),
|
||||||
|
),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
size: Sizer(
|
size: Sizer(
|
||||||
Arc::new(16usize.into()),
|
Arc::new(20usize.into()),
|
||||||
Arc::new(6usize.into()),
|
Arc::new(6usize.into()),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
@ -638,7 +642,9 @@ impl<T> MidiClipControl for T where T: HasClip
|
||||||
) -> Perhaps<MidiClipCmd> {
|
) -> Perhaps<MidiClipCmd> {
|
||||||
Ok(self.clip_mut().map(|mut clip|if clip.is_none() {
|
Ok(self.clip_mut().map(|mut clip|if clip.is_none() {
|
||||||
*clip = Some(Arc::new(RwLock::new(MidiClip {
|
*clip = Some(Arc::new(RwLock::new(MidiClip {
|
||||||
ppq: 24, length: 96,
|
ppq: 24,
|
||||||
|
length: 96,
|
||||||
|
color: ItemTheme::random(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})));
|
})));
|
||||||
None // TODO undo
|
None // TODO undo
|
||||||
|
|
|
||||||
113
src/tek_view.rs
113
src/tek_view.rs
|
|
@ -607,45 +607,6 @@ impl OctaveVertical {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view_editor_clip_status (editor: &MidiEditor) -> impl Draw<Tui> + '_ {
|
|
||||||
let (
|
|
||||||
_color, name, length, looped
|
|
||||||
) = if let Some(clip) = editor.mode.clip.read().as_ref().map(|p|p.read()) {
|
|
||||||
(clip.color, clip.name.clone(), clip.length, clip.looped)
|
|
||||||
} else {
|
|
||||||
(ItemTheme::G[64], String::new().into(), 0, false)
|
|
||||||
};
|
|
||||||
south!(
|
|
||||||
east(button_2("f2", "name ", false), fg(Rgb(255, 255, 255), format!("{name} "))
|
|
||||||
.origin_e().full_w()).origin_w().full_w(),
|
|
||||||
east(button_2("l", "ength ", false), fg(Rgb(255, 255, 255), format!("{length} ")).origin_e().full_w())
|
|
||||||
.origin_w().full_w(),
|
|
||||||
east(button_2("r", "epeat ", false), fg(Rgb(255, 255, 255), format!("{looped} ")).origin_e().full_w())
|
|
||||||
.origin_w().full_w(),
|
|
||||||
).exact_w(20)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view_editor_edit_status (editor: &MidiEditor) -> impl Draw<Tui> + '_ {
|
|
||||||
let (_color, length) = if let Some(clip) = editor.mode.clip.read().as_ref().map(|p|p.read()) {
|
|
||||||
(clip.color, clip.length)
|
|
||||||
} else { (ItemTheme::G[64], 0) };
|
|
||||||
let time_pos = editor.get_time_pos();
|
|
||||||
let time_zoom = editor.get_time_zoom();
|
|
||||||
let time_lock = if editor.get_time_lock() { "[lock]" } else { " " };
|
|
||||||
let note_pos = editor.get_note_pos();
|
|
||||||
let note_name = format!("{:4}", note_pitch_to_name(note_pos));
|
|
||||||
let note_pos = format!("{:>3}", note_pos);
|
|
||||||
let note_len = format!("{:>4}", editor.get_note_len());
|
|
||||||
south!(
|
|
||||||
east(button_2("t", "ime ", false),
|
|
||||||
fg(Rgb(255, 255, 255), format!("{length} /{time_zoom} +{time_pos} ")).origin_e().full_w()).origin_w().full_w(),
|
|
||||||
east(button_2("z", "lock ", false),
|
|
||||||
fg(Rgb(255, 255, 255), format!("{time_lock}")).origin_e().full_w()).origin_w().full_w(),
|
|
||||||
east(button_2("x", "note ", false),
|
|
||||||
fg(Rgb(255, 255, 255), format!("{note_name} {note_pos} {note_len}")).origin_e().full_w()).origin_w().full_w(),
|
|
||||||
).exact_w(20)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Draw<Tui> for MidiEditor {
|
impl Draw<Tui> for MidiEditor {
|
||||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||||
self.autoscroll();
|
self.autoscroll();
|
||||||
|
|
@ -1197,18 +1158,66 @@ pub fn view_scene_name <'a> (
|
||||||
} else {
|
} else {
|
||||||
Scene::DEFAULT_HEIGHT as u16
|
Scene::DEFAULT_HEIGHT as u16
|
||||||
};
|
};
|
||||||
let a = east!("·s", index, " ", fg(g(255), bold(true, &scene.name))).align_w().full_w();
|
let a = east!("·s", index, " ", fg(g(255), bold(true, &scene.name))).align_nw().full_w();
|
||||||
let s = select.scene() == Some(index) && editing;
|
let s = select.scene() == Some(index) && editing;
|
||||||
let b = when(s, south(
|
let b = when(s, south(editor.map(view_clip_info), editor.map(view_edit_info)).full_wh().align_se());
|
||||||
editor.map(view_editor_clip_status),
|
|
||||||
editor.map(view_editor_edit_status)
|
|
||||||
).full_wh().align_se());
|
|
||||||
let c = if select.scene() == Some(index) {
|
let c = if select.scene() == Some(index) {
|
||||||
scene.color.light.term
|
scene.color.light.term
|
||||||
} else {
|
} else {
|
||||||
scene.color.base.term
|
scene.color.base.term
|
||||||
};
|
};
|
||||||
bg(c, south(a, b).align_nw().exact_h(h))
|
bg(c, above(a, b.push_y(1)).align_nw().exact_h(h))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_clip_info (editor: &MidiEditor) -> impl Draw<Tui> + '_ {
|
||||||
|
let (
|
||||||
|
_color, name, length, looped
|
||||||
|
) = if let Some(clip) = editor.mode.clip.read().as_ref().map(|p|p.read()) {
|
||||||
|
(clip.color, clip.name.clone(), clip.length, clip.looped)
|
||||||
|
} else {
|
||||||
|
(ItemTheme::G[64], String::new().into(), 0, false)
|
||||||
|
};
|
||||||
|
south!(
|
||||||
|
south(
|
||||||
|
button_2("f", "name ", false),
|
||||||
|
fg_bg(Rgb(255, 255, 255), Rgb(16, 16, 16), format!("{name} ").origin_e().pad_w(1).full_w())
|
||||||
|
).origin_w().full_w(),
|
||||||
|
east(
|
||||||
|
button_2("l", "ength ", false),
|
||||||
|
fg(Rgb(255, 255, 255), format!("{length} ")).origin_e().full_w()
|
||||||
|
).origin_w().full_w(),
|
||||||
|
east(
|
||||||
|
button_2("r", "epeat ", false),
|
||||||
|
fg(Rgb(255, 255, 255), format!("{looped} ")).origin_e().full_w()
|
||||||
|
).origin_w().full_w(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_edit_info (editor: &MidiEditor) -> impl Draw<Tui> + '_ {
|
||||||
|
let (_color, length) = if let Some(clip) = editor.mode.clip.read().as_ref().map(|p|p.read()) {
|
||||||
|
(clip.color, clip.length)
|
||||||
|
} else { (ItemTheme::G[64], 0) };
|
||||||
|
let time_pos = editor.get_time_pos();
|
||||||
|
let time_zoom = editor.get_time_zoom();
|
||||||
|
let time_lock = if editor.get_time_lock() { "[lock]" } else { " " };
|
||||||
|
let note_pos = editor.get_note_pos();
|
||||||
|
let note_name = format!("{:4}", note_pitch_to_name(note_pos));
|
||||||
|
let note_pos = format!("{:>3}", note_pos);
|
||||||
|
let note_len = format!("{:>4}", editor.get_note_len());
|
||||||
|
south!(
|
||||||
|
east(
|
||||||
|
button_2("t", "ime ", false),
|
||||||
|
fg(Rgb(255, 255, 255), format!("{length} /{time_zoom} +{time_pos} ")).origin_e().pad_w(1).full_w()
|
||||||
|
).origin_w().full_w(),
|
||||||
|
east(
|
||||||
|
button_2("z", "lock ", false),
|
||||||
|
fg(Rgb(255, 255, 255), format!("{time_lock}")).origin_e().full_w()
|
||||||
|
).origin_w().full_w(),
|
||||||
|
south(
|
||||||
|
button_2("x", "note ", false),
|
||||||
|
fg_bg(Rgb(255, 255, 255), Rgb(16, 16, 16), format!("{note_name} {note_pos} {note_len}").origin_e().full_w())
|
||||||
|
).origin_w().full_w(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view_scene_name_theme (scene: &Scene, track_index: usize) -> (Arc<str>, ItemTheme) {
|
pub fn view_scene_name_theme (scene: &Scene, track_index: usize) -> (Arc<str>, ItemTheme) {
|
||||||
|
|
@ -1458,6 +1467,20 @@ pub fn view_wrap <'a> (bg: Color, fg: Color, content: impl Draw<Tui>)
|
||||||
east(left, west(right, fg_bg(fg, bg, content)))
|
east(left, west(right, fg_bg(fg, bg, content)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn redraw_piano (state: &PianoHorizontal) -> BigBuffer {
|
||||||
|
state.clip.map_inner(|clip|{
|
||||||
|
let mut buffer = BigBuffer::from(state.buffer_size(&clip));
|
||||||
|
let time_zoom = state.get_time_zoom().max(1);
|
||||||
|
state.time_len().store(clip.length, Relaxed);
|
||||||
|
let note_len = state.get_note_len();
|
||||||
|
let note_pos = state.get_note_pos();
|
||||||
|
let time_pos = state.get_time_pos();
|
||||||
|
draw_piano_bg(&mut buffer, &clip, time_zoom, note_len, note_pos, time_pos);
|
||||||
|
draw_piano_fg(&mut buffer, &clip, time_zoom);
|
||||||
|
buffer
|
||||||
|
}).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Draw the piano roll background.
|
/// Draw the piano roll background.
|
||||||
pub fn draw_piano_bg (
|
pub fn draw_piano_bg (
|
||||||
buf: &mut BigBuffer,
|
buf: &mut BigBuffer,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue