mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
pre generate grayscale palettes
This commit is contained in:
parent
cfa3cad5cb
commit
ee28d431bd
7 changed files with 16 additions and 12 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1519,6 +1519,7 @@ version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"better-panic",
|
"better-panic",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
"konst",
|
||||||
"palette",
|
"palette",
|
||||||
"rand",
|
"rand",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,7 @@ impl MidiEditor {
|
||||||
pub fn clip_status (&self) -> impl Content<TuiOut> + '_ {
|
pub fn clip_status (&self) -> impl Content<TuiOut> + '_ {
|
||||||
let (color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
|
let (color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
|
||||||
(clip.color, clip.name.clone(), clip.length, clip.looped)
|
(clip.color, clip.name.clone(), clip.length, clip.looped)
|
||||||
} else {
|
} else { (ItemPalette::G[64], String::new().into(), 0, false) };
|
||||||
(ItemPalette::from(Tui::g(64)), String::new().into(), 0, false)
|
|
||||||
};
|
|
||||||
row!(
|
row!(
|
||||||
FieldV(color, "Edit", format!("{name} ({length})")),
|
FieldV(color, "Edit", format!("{name} ({length})")),
|
||||||
FieldV(color, "Loop", looped.to_string())
|
FieldV(color, "Loop", looped.to_string())
|
||||||
|
|
@ -143,9 +141,7 @@ impl MidiEditor {
|
||||||
pub fn edit_status (&self) -> impl Content<TuiOut> + '_ {
|
pub fn edit_status (&self) -> impl Content<TuiOut> + '_ {
|
||||||
let (color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
|
let (color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
|
||||||
(clip.color, clip.length)
|
(clip.color, clip.length)
|
||||||
} else {
|
} else { (ItemPalette::G[64], 0) };
|
||||||
(ItemPalette::from(Tui::g(64)), 0)
|
|
||||||
};
|
|
||||||
let time_pos = self.time_pos();
|
let time_pos = self.time_pos();
|
||||||
let time_zoom = self.time_zoom().get();
|
let time_zoom = self.time_zoom().get();
|
||||||
let time_lock = if self.time_lock().get() { "[lock]" } else { " " };
|
let time_lock = if self.time_lock().get() { "[lock]" } else { " " };
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ pub trait HasPlayClip: HasClock {
|
||||||
fn next_status (&self) -> impl Content<TuiOut> {
|
fn next_status (&self) -> impl Content<TuiOut> {
|
||||||
let mut time: Arc<str> = String::from("--.-.--").into();
|
let mut time: Arc<str> = String::from("--.-.--").into();
|
||||||
let mut name: Arc<str> = String::from("").into();
|
let mut name: Arc<str> = String::from("").into();
|
||||||
let mut color = ItemPalette::from(Tui::g(64));
|
let mut color = ItemPalette::G[64];
|
||||||
let clock = self.clock();
|
let clock = self.clock();
|
||||||
if let Some((t, Some(clip))) = self.next_clip() {
|
if let Some((t, Some(clip))) = self.next_clip() {
|
||||||
let clip = clip.read().unwrap();
|
let clip = clip.read().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,7 @@ impl PianoHorizontal {
|
||||||
buffer: RwLock::new(Default::default()).into(),
|
buffer: RwLock::new(Default::default()).into(),
|
||||||
point: MidiPointModel::default(),
|
point: MidiPointModel::default(),
|
||||||
clip: clip.cloned(),
|
clip: clip.cloned(),
|
||||||
color: clip.as_ref()
|
color: clip.as_ref().map(|p|p.read().unwrap().color).unwrap_or(ItemPalette::G[64]),
|
||||||
.map(|p|p.read().unwrap().color)
|
|
||||||
.unwrap_or(ItemPalette::from(ItemColor::from(Tui::g(64)))),
|
|
||||||
};
|
};
|
||||||
piano.redraw();
|
piano.redraw();
|
||||||
piano
|
piano
|
||||||
|
|
@ -270,7 +268,7 @@ impl MidiViewer for PianoHorizontal {
|
||||||
fn set_clip (&mut self, clip: Option<&Arc<RwLock<MidiClip>>>) {
|
fn set_clip (&mut self, clip: Option<&Arc<RwLock<MidiClip>>>) {
|
||||||
*self.clip_mut() = clip.cloned();
|
*self.clip_mut() = clip.cloned();
|
||||||
self.color = clip.map(|p|p.read().unwrap().color)
|
self.color = clip.map(|p|p.read().unwrap().color)
|
||||||
.unwrap_or(ItemPalette::from(ItemColor::from(Tui::g(64))));
|
.unwrap_or(ItemPalette::G[64]);
|
||||||
self.redraw();
|
self.redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1107,7 +1107,7 @@ trait HasScenes: HasSelection + HasEditor + Send + Sync {
|
||||||
}
|
}
|
||||||
fn scene_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
fn scene_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
||||||
(move||{
|
(move||{
|
||||||
let last_color = Arc::new(RwLock::new(ItemPalette::from(Color::Rgb(0, 0, 0))));
|
let last_color = Arc::new(RwLock::new(ItemPalette::G[0]));
|
||||||
let selected = self.selected().scene();
|
let selected = self.selected().scene();
|
||||||
let iter = ||self.scenes_sizes(self.is_editing(), 2, 15);
|
let iter = ||self.scenes_sizes(self.is_editing(), 2, 15);
|
||||||
Map::new(iter, move|(_, scene, y1, y2), i| {
|
Map::new(iter, move|(_, scene, y1, y2), i| {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ rand = "0.8.5"
|
||||||
crossterm = "0.28.1"
|
crossterm = "0.28.1"
|
||||||
ratatui = { version = "0.29.0", features = [ "unstable-widget-ref", "underline-color" ] }
|
ratatui = { version = "0.29.0", features = [ "unstable-widget-ref", "underline-color" ] }
|
||||||
better-panic = "0.3.0"
|
better-panic = "0.3.0"
|
||||||
|
konst = { version = "0.3.16", features = [ "rust_1_83" ] }
|
||||||
|
|
||||||
tek_edn = { path = "../edn" }
|
tek_edn = { path = "../edn" }
|
||||||
tek_input = { path = "../input" }
|
tek_input = { path = "../input" }
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,14 @@ impl ItemColor {
|
||||||
pub darkest: ItemColor,
|
pub darkest: ItemColor,
|
||||||
}
|
}
|
||||||
impl ItemPalette {
|
impl ItemPalette {
|
||||||
|
pub const G: [Self;256] = {
|
||||||
|
let mut builder = konst::ArrayBuilder::new();
|
||||||
|
let mut index = 0;
|
||||||
|
while !builder.is_full() {
|
||||||
|
builder.push(ItemPalette::G[index]);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
};
|
||||||
pub fn random () -> Self { ItemColor::random().into() }
|
pub fn random () -> Self { ItemColor::random().into() }
|
||||||
pub fn random_near (color: Self, distance: f32) -> Self {
|
pub fn random_near (color: Self, distance: f32) -> Self {
|
||||||
color.base.mix(ItemColor::random(), distance).into()
|
color.base.mix(ItemColor::random(), distance).into()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue